New BellaBuffs blanklinefix Function
I’ve modified the BellaBuffs (and as such, BellaBook) function which removes whitespace from the end of lines so that it now removes empty lines too (which it didn’t properly before). This solves the problem caused by members that have been approved all at once causing blank lines and thus undefined offset errors. Until I can upload the fixed version (tonight), open your copy of config.php and find:
// blank line fix stolen from bellabook
function blanklinefix($inputfile) {
$content = file_get_contents($inputfile);
if($content != FALSE) {
$fixed = ltrim(rtrim($content));
$handle = fopen($inputfile, "w+");
fwrite($handle, $fixed);
fseek($handle, 0);
}
}
REPLACE it with:
function blanklinefix($inputfile) {
$content = file($inputfile);
if (count($content) > 0) {
$content = array_diff(array_diff($content, array("")), array("n"));
$newContent = array();
foreach ($content as $line) {
$newContent[] = trim($line);
}
$newContent = implode("n", $newContent);
$handle = fopen($inputfile, "w+");
fwrite($handle, $newContent);
fseek($handle, 0);
}
}
If anyone could tell me why Made some further changes, trim() doesn’t seem to work and I’m having to rely on the two ‘side’ trims to achieve that affect I’d greatly appreciate it!trim() now works and I’ve corrected a couple of stupid mistakes that I should have spotted originally.
Munin said:
On 04 Oct at 7:35 pm
Hey there Jem! I’m a long-time reader, first-time commenter. =P I just wanted to say that you rock so freakin’ much for always taking care to correct your scripts (and others) and make sure they’re top security for users out there. So, this is just a little Thanks from me.
Jem said:
On 04 Oct at 8:02 pm
Thank you Munin, that’s really sweet of you to say :)
Mallory said:
On 04 Oct at 8:24 pm
You have an open code tag in your entry. Love the new layout!
Jem said:
On 04 Oct at 8:25 pm
Arse! Thanks for letting me know Mallory :)
Linda said:
On 04 Oct at 9:22 pm
Speaking of BellaBuffs … I downloaded it the other day and a few hours ago I gave the convert-from-enth script a try – I received the following error: “Undefined index in “…” on line 30″ on each line/for each member. I figured you might want to know and take a look at that :)
Jem said:
On 04 Oct at 9:24 pm
Thanks Linda – I’ll have a look and see what’s causing that when I get chance :)
banshee said:
On 04 Oct at 9:27 pm
:) Thanks for the fix, Jem! You’re a champ!
Julie said:
On 04 Oct at 10:39 pm
Oh great. :) I had been wondering what was causing this and I was too lazy to email you. P.S. Oh, your link colors changed. :whistle:
gemtiger said:
On 05 Oct at 1:47 am
Thanks Jem, I had noticed this while I was approving some members, but I had chalked it up to my incompetence at modifying PHP… can’t wait to give this a try, though!
Chans said:
On 05 Oct at 6:58 am
Thanks Jem! I’m setting Bellabuffs up to use with my new fanlisting so now I can implement the change before uploading it all :)
Loadx said:
On 05 Oct at 7:41 am
the array_diff looks so redundant..i could be wrong but what about. function trimmit(&$value){ $value = trim($value); } array_walk($content, ‘trimmit’);
Jem said:
On 05 Oct at 7:47 am
Tried something very similar and it removed the whitespace (well, ltrim(rtrim()) did – no idea why trim() isn’t working in that particular function as it should) but it didn’t remove completely blank lines, which was the problem.
Chans said:
On 05 Oct at 9:25 am
Ooh Jem, I forgot to say I really like the new layout (and favicon) but in IE the logo moves up and down rather than staying fixed (like in FF). I only noticed it now because I normally don’t use IE ;)
Jem said:
On 05 Oct at 9:45 am
@Chans: I know, it’s because IE is super poop and doesn’t support fixed backgrounds on anything other than the body element. I’ll fix it.. eventually.
Dave said:
On 05 Oct at 10:38 am
Hey Jem – I’m not a big user of PHP but first glance i’m wondering why if (count($inputfile) > 0) { is used and not if (count($content) > 0) {? $content is an array of lines from file() yeah? You said you’re just removing whitespace from the end of lines – wont rtrim() alone be alright, Jem?
Jem said:
On 05 Oct at 10:44 am
@Dave: it should be count($content) – I was going to do something else with the $inputfile before loading it into the array and must have forgotten to change it back after I decided against it (well spotted!) I do need the function to remove whitespace at the beginning of lines “just in case” too, it’s just a quickly put together post so I wasn’t being incredibly specific :)
Chans said:
On 05 Oct at 2:53 pm
Should have known you already knew about the fixed background problem in IE. Actually come to think of it I should have known it’s IE fault hehe.
Adrianne said:
On 06 Oct at 1:56 am
Hi Jem! Thanks so much for the fix! I’ll let my friends know about this one (they’ve been really loving Bellabuffs since I introduced them to the script :) ). I know this is off topic, but have you ever considered opening a site directory of fanlistings that use Bellabuffs? I know the question is kind of redundant, but this is just out of curiosity. Or maybe a site similar already exists and I just didn’t know about it… :) Thanks again!
Deanne Bianca said:
On 06 Oct at 8:42 am
Thanks for trying to fix all errors in BellaBuffs, Jem! ILY xD
Julie said:
On 06 Oct at 3:12 pm
Adrianne: the BellaBuffs fanlisting has a small directory which I hope to see growing. :)