Jump to content
ryan

Module: BBCode Text Formatter

Recommended Posts

We already have Markdown and Textile text formatters, so I thought we should have BBCode too. BBCode is a good text formatter to use when you'll be outputting untrusted user-supplied input. I think it's also a little simpler and more widely understood than Markdown and Textile, since it is used by many forums (including the ProcessWire forum, before we switched to IP.Board). More about the BBCode format can be found here: http://en.wikipedia.org/wiki/BBCode

This module uses the NBBC Library to handle BBCode parsing. I selected this one because it seems to be really well documented and also includes it's own set of smileys, for those that like that sort of thing. :rolleyes:

To install, clone it from the TextformatterBBCode GitHub page or download the ZIP file.

  • Like 1

Share this post


Link to post
Share on other sites

Nice addition - could be very useful for user comment fields.

You can still type bbcode into these forums too by the way, just the editor makes it a little pointless really.

Share this post


Link to post
Share on other sites

So if you can't use this in a field set as TinyMCE (or CKEditor) how would one place/use the BBCode from Flickr for example?

Share this post


Link to post
Share on other sites
So if you can't use this in a field set as TinyMCE (or CKEditor) how would one place/use the BBCode from Flickr for example?

Not sure I understand the question. What BBCode from Flickr? :)

Share this post


Link to post
Share on other sites

Ah yes. Flickr has a way to embed an image elsewhere - there's a share icon on most images. You can either use html code or bbcode.

I'm thinking that it's an ok way to thread Flickr images through a blog post for example.

Share this post


Link to post
Share on other sites

Interesting. I guess I'm not familiar with that Flickr BBCode. Can you post an example? I'm betting we can get Hanna code to make it happen. 

Share this post


Link to post
Share on other sites

On Flickr you can either choose HTML embed code or BBCode.

Here's a BBCode example:

[url=

    ][img]http://farm6.staticflickr.com/5506/9061328126_bac63857c2_z.jpg[/img][/url]
[url=

    ]Pike reflection[/url] by [url=http://www.flickr.com/people/sparth/]sparth[/url], on Flickr

Here's the HTML example:

<a href="

    " title="Pike reflection by sparth, on Flickr"><img src="http://farm6.staticflickr.com/5506/9061328126_bac63857c2_z.jpg" width="640" height="426" alt="Pike reflection"></a>

I had that thought as well about using Hanna Code for this but couldn't figure out how to a) get that image url out of that BBCode and b) get around TinyMCE stripping it out completely.

Share this post


Link to post
Share on other sites
Hanna code probably wouldn't work here looking at the code. We could write a Hanna code to do it, but you'd have to specify the href and src differently, like this:
[[flickr href="

    Pike reflection" src="http://farm6.staticflickr.com/5506/9061328126_bac63857c2_z.jpg"]]
It would be easy to make a Hanna code to do this, but of course you couldn't copy/paste a BBCode directly from Flickr using that method. So that kind of defeats the convenience purpose. You also probably don't want to apply the existing BBCode text formatter because it'll strip out your HTML. A new textformatter would be needed, that does nothing but convert BBCode without stripping HTML. Or, you could simply do this before outputting your $body field:
$body = $page->body;
if(strpos($body, '[url=') !== false) {
  $body = preg_replace(
    '{\[url=(.+?)\]\[img\](.+?)\[/img\]\[/url\]}', 
    '<a href="$1"><img src="$2" alt=""></a>', 
    $body);
}
echo $body;  

Not sure how we'd determine attributes like title, alt, width and height (or if you even need it). I'm guessing that would have to use an oEmbed service like the TextformatterVideoEmbed module does. 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...