With this plugin, users can spoiler bar text so it will show up hidden. Users will then have to highlight the text to see the spoilers.
As of v.3, thanks to ck, it has been updated to work with the BBCode plugin as well!
Version: 0.4
Last Updated: 2008-10-31
Requires bbPress Version: 0.9 or higher
Compatible up to: 1.0





With this plugin, users can spoiler bar text so it will show up hidden. Users will then have to highlight the text to see the spoilers.
As of v.3, thanks to ck, it has been updated to work with the BBCode plugin as well!
Please excuse the spazola here, I've never used SVN on my Windows box and, naturally, goofed it up badly. The .2 trunk has the correct documentation. No code is different between the two versions.
With a slight change in your regex you can also support bbcode too. Let me know if you need help with the pattern.
_ck_, sure! I haven't even looked at the BBCode since I've 'trained' my blog commenters on how to use HTML ;) I figured keeping it the same would be better for their non-techie heads.
The easiest way to change it for bbcode is to change the regex pattern to look for either character, ie. [\<\[]spoiler[\>\]](.*)[\<\[]\/spoiler[\>\]]
(untested)
Wouldn't I also have to change this bit?
function bb_spoiler( $matches )
{
$text = $matches[0];
$text = str_replace("<spoiler>", "", $text);
$text = str_replace("</spoiler>", "", $text);
return "<span class=\"spoiler\">$text</span>";
}
And naturally I'm not using BBcode so I can't easily test that myself. I suppose I could uglify it and make separate bbcode functions but I'll go play with regex cause that would be better ;)
Okay, I've made a .3 for someone with bbcode to test. When I run [spoiler]Test?[/spoiler] it gives me <span class="spoiler">[spoiler]Test?[/spoiler]</span> so ... er in theory?
The trunk is available for testing: http://plugins-svn.bbpress.org/spoiler-bar/trunk/spoiler-tags.php
If someone who uses BBcode would be so kind :)
No I think you missed my point.
You can make it respond to the bbcode itself and replace the bbcode with the proper html.
this is wrong:
<span class="spoiler">[spoiler]Test?[/spoiler]</span>
should just be:
<span class="spoiler">Test?</span>
Actually, the entire way your plugin works is overly complex.
You could do the whole thing with one preg_replace.
$content=preg_replace("|(\<\[]spoiler[\>\]])(.*)([\<\[]\/spoiler[\>\]])|simU","<span class='spoiler'>\\2</span>" , $content);
(untested)
No, I got the point, just not the code (that is the code I got is wrong). It's basically not parsing the [spoiler] as a valid tag.
And now that I look at it, if I use [\<\[] that leaves the door open for some silly person to do this and have it work:
<spoiler>neener![/spoiler]
While that's kinda okay, it's also kinda not (bad HTML among other things). The preg_replace solution has the same problem, while it's certainly simpler.
It's not bad HTML because neither tag can appear in the final HTML of the page that's presented to the browser. It's pseudo markup.
If you want to do it the long, slow way you can just add more rules to your str_replace.
I may have gotten the regex wrong for the bbcode. It's tricky to know which characters to escape and trying to do them as a character sequence may not work. may be easier to do it like (\<|\[) and change the backreference.
ie.
$content=preg_replace("@(\<|\[)spoiler(\>|\])(.*)(\<|\[)\/spoiler(\>|\])@simU","<span class='spoiler'>\\3</span>" , $content);Yeah I did it the long, slow way. In my head, bad pseudo-html is still bad form ;) Who knows, maybe the W3C will pick up spoiler tags one day!
You must log in to post.