bbPress

Simple, fast, elegant

bbPress Plugin Browser »

Spoiler Tags (0.4)

Download

Version: 0.4

Other Versions

Last Updated: 2008-10-31

Requires bbPress Version: 0.9 or higher

Compatible up to: 1.0

Author Homepage »

Plugin Homepage »

Donate to this plugin »

Average Rating

5 stars
4 stars
3 stars
2 stars
1 star
(1)

Your Rating

Authors ipstenu, _ck_

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!

Tags: ,

  1. 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.

    Posted: 1 year ago #
  2. _ck_

    Moderator

    With a slight change in your regex you can also support bbcode too. Let me know if you need help with the pattern.

    Posted: 1 year ago #
  3. _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.

    Posted: 1 year ago #
  4. _ck_

    Moderator

    The easiest way to change it for bbcode is to change the regex pattern to look for either character, ie. [\<\[]spoiler[\>\]](.*)[\<\[]\/spoiler[\>\]]
    (untested)

    Posted: 1 year ago #
  5. 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 ;)

    Posted: 1 year ago #
  6. 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 :)

    Posted: 1 year ago #
  7. _ck_

    Moderator

    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)

    Posted: 1 year ago #
  8. 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.

    Posted: 1 year ago #
  9. _ck_

    Moderator

    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);
    Posted: 1 year ago #
  10. 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!

    Posted: 1 year ago #

RSS feed for this topic

Add a Comment

You must log in to post.

Code is Poetry.