PDA

View Full Version : Stripping text...


Palmer ofShinra
02-28-2002, 06:05 AM
Well... we use the notorious code over on our forums.... which a sizable number of people love

And an equal number hate.

So to cater to both sides... I'm making a tiny hack to let people turn it off.

Basically... what I need... is whatever little snippet of code it is that will strip

[glow=color] and out of posts before parsing.

Mind you, it has to compensate for 'color' being most anything.

I'm sure it has something to do with regexes... and those still hurt my head.

So umm... help?

Admin
02-28-2002, 09:55 AM
Where is the glow code defined? From the CP or directly in the code?

Reeve of shinra
02-28-2002, 12:32 PM
Glow was added as a vb tag through the the CP....
We are using the one listed in the thread by Ozone over at vb.com.

Reeve of shinra
02-28-2002, 12:35 PM
actually here's the link, its the first post.

http://www.vbulletin.com/forum/showthread.php?threadid=24595

Thanks!

Palmer ofShinra
03-03-2002, 06:24 AM
I don't see how the code is defined mattering at all...

All I need is the commands to remove and from the message body...

Then i'll slide it into bbcodeparse2 and have it triggered by the user option being set.

I have a very clumsy kludge in place at the moment, which siomply skips parsing the glow code specifically.

But then that leaves the unparsed code in the post, which looks bad.

Admin
03-03-2002, 08:49 AM
This should work:
$text = preg_replace("#\[(/{0,1})glow(=[^\]]*){0,1}\]#i", "", $test);

Yup:
<?php

$text = 'blbla some more and blbla';

echo preg_replace("#\\[(/?)glow(=[^\\]]*)?\\]#i", "", $text);

?>

Palmer ofShinra
03-04-2002, 10:31 AM
Thanks... except it doesn't seem to be working.

I put this line into the bbcodeparse2 function in functions.php
if ($bbuserinfo[disablecodes]) {
$bbcode = preg_replace("#\[(/?)glow(=[^\]]*)?\]#i", "", $bbcode);
}
DIsablecodes is a new user option field I added and I know it works because my previous kludge works (just badly)

But for some reason, the above line (even using the other regex... you have 2 different regexes in your post) fails to have any effect whatsoever.

I hate regexes

Admin
03-04-2002, 11:23 AM
Did you globalize $bbuserinfo in bbcodeparse2()?

Palmer ofShinra
03-05-2002, 04:29 AM
Yeah... because a different snippet of code using that same bbuserinfo field DOES work...

However, it leaves the unparsed code visible in the post, as shown in the attachment.

if ($bbuserinfo[disablecodes]) {
$disablesql="WHERE candisable=0";
} else {
$disablesql="";
}

THAT code works, and in the end produces the effect shown in the attachment... namely that certain codes aren't pulled from the DB and thus not parsed.

However, this code does nothing

if ($bbuserinfo[disablecodes]) {
$bbcode = preg_replace("/(\[)(glow)(])(\r\n)*([^\"]*)(\[\/glow\])/siU", "", $bbcode);
}

// #\[(/{0,1})glow(=[^\]]*){0,1}\]#i
// #\[(/?)glow(=[^\]]*)?\]#i

(the 2 comment lines are other regexes that didn't work as well)

The line is inserted into the function just before this:
$bbcodes=$DB_site->query("SELECT bbcodetag,bbcodereplacement,twoparams FROM bbcode $disablesql");

while($bbregex=$DB_site->fetch_array($bbcodes)) {

Admin
03-05-2002, 02:07 PM
if ($bbuserinfo[disablecodes]) {
$bbcode = preg_replace("/\\[(\\/?)glow(=[^\\]]*)?\\]/siU", "", $bbcode);
}
vBulletin removes some \ so \] became ] which ruined the regex.

Palmer ofShinra
03-06-2002, 07:41 AM
*nods knowingly and wonders what he's supposed to do with this information now*