View Full Version : Greentext
Kybyrian
02-05-2012, 03:00 AM
Thought it would be pretty cool after hearing out a couple requests, but I have no real idea how to go about doing it. Cutting to the chase, greentext *chan style.
Text after a ">" at the beginning of a line would turn all the text after it until a line break green.
>exactly like
this
I understand BBCode could do a job like this pretty simply, but we were looking for something automatic.
Would appreciate any help on this.
Simon Lloyd
02-05-2012, 03:03 AM
Do you mean in each post?
Kybyrian
02-05-2012, 03:33 AM
Do you mean in each post?
Yeah, this would happen any time somebody makes a post with > at the beginning of a line.
Simon Lloyd
02-05-2012, 03:53 AM
I'm no expert but i think you'll need to create a plugin maybe using the hook postdata_save and use some kind of replace function or maybe regex to match any line that starts with >
So the replace function COULD look like this$text= str_ireplace( '>*' , '<span style="font-color:green;">'/>*/'</span>', $text);
--------------- Added 1328418603 at 1328418603 ---------------
Or maybe in PCRE format$string='>*';
$string = preg_replace('/>*/i', '<span style="font-color:green;">'/>*/'</span>', $string); I'm a real novice when it comes to REGEX so maybe this will get someone's attention and they'll be able to tweak it for you :)
Kybyrian
02-05-2012, 08:37 AM
I managed to get this, stemming somewhat off of yours and hitting up regex and using the hook location postbit_display_complete.
$pattern = htmlspecialchars('/>.*/');
$replacement = '<span style="color:green">text</span>';
$this->post['message'] = preg_replace($pattern, $replacement, $this->post['message']);
This replaces anything after > on one line with the green word "text".
It seems I can perfectly call the text, but I cannot change its color. If I try to input "<span style=\"color:green\">$pattern</span>"; or any such thing in, it simply returns />.*/ instead of the actual text that regex defines. This occurs even when I place the regex itself in the span tags.
Simon Lloyd
02-05-2012, 05:57 PM
Thats beacue in your REGEX (and im no expert!) you are replacing > with '<span style="color:green">text</span>' and not '<span style="color:green">/>*/</span>'
What i mean to say you need to replace >* (so > and wildcard) with >* but wrapped in the span, as it is your replacing it with the word "text" in green :)
Have you tried:
$replacement = '<span style="color:green">$pattern</span>';
or some variation with or without more single quotes?
Kybyrian
02-05-2012, 07:31 PM
Yeah, I've actually tried that. It wasn't returning the text in the regex. I went a different route and got a working code. Thanks for you help, though, it gave me my starting point. :)
$pattern = htmlspecialchars('/(>.*)/');
$replacement = '<span style="color:#789922">$1</span>';
$this->post['message'] = preg_replace($pattern, $replacement, $this->post['message']);
Simon Lloyd
02-05-2012, 07:33 PM
Ah yes, i remember that now "$1", glad i got you started :)
Zakalway
02-19-2013, 05:55 AM
This works great, except it shows up as regular plain text when quoted.
Any way to make it appear as green text in quotes?
Never mind; it shows up fine in quotes. It just doesn't show up in reply previews.
itsRahul
04-05-2015, 02:27 PM
sorry for the bump, but this does not seem to be working when I added a plugin to postbit_display_complete. is there something that needs to be changed to make it applicable to vb5?
it just doesn't modify the post at all
$pattern = htmlspecialchars('/(>.*)/');
$replacement = '<span style="color:#789922">$1</span>';
$this->post['message'] = preg_replace($pattern, $replacement, $this->post['message']);
Lynne
04-05-2015, 05:10 PM
No vB4 plugin code will work in vB5 because there is no plugin system in vB5. The hook system is not the same as the plugin system at all.
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.