Mys 1.3.6 BBCode Bundle

Forum
Last Post
Threads / Messages

KittHaven

Member
Member
Joined
May 21, 2013
Messages
483
Points
28
Age
25
Location
Devon, UK
Mysidian Dollar
8,389
Hi! I have recently been experimenting with allowing some BBCode in my pet descriptions and I noticed that the BBCode bundle that comes with mysidia 1.3.6 isn't actually used so I fixed it up so it is!

First of all, download the BBCode.php file attached to this post. Once downloaded, move it into the bundles folder. If it asks to overwrite you can say yes, Just make sure it has capital BBC as that's what I use.

Next, open index.php in the root of your site directory. Find the line:

PHP:
$bundles->register("htmlpurifier", "bundles/htmlpurifier/", "HTMLPurifier.auto.php");

Underneath it put this:

PHP:
$bundles->register("bbcode", "bundles/", "BBCode.php");

Now to use your new bundle, you need to add a few things into the model. I'll be using one that I have made for my site, but the steps should be the same for most other places you'd want to use it.

At the top, underneath namespace Model/Domainmodel, put:

PHP:
use BBCode;

Underneath all the protected functions near the top, add:

PHP:
private $bbcode;

Inside the construct(), add:

Code:
, $bbcode = TRUE

I recommend adding it after the other things so you don't disturb what's already there.

For example:

PHP:
 public function __construct($cuid, $dto = NULL, $bbcode = TRUE){

Now actually inside the construct function, you want to put:

PHP:
if($bbcode) $this->bbcode = new BBCode;

I put it directly under the $mysidia = Registry::get("mysidia"); line.

And finally, to use your new BBCode, you can do this!

PHP:
public function getBBDescription(){
        if($this->bbcode) $converted = $this->bbcode->bbconvert($this->description);
        return $converted;
    }

2024-08-06 16_51_06-Bean Pets _ Viewing Custom_ Fluffy - Opera.png 2024-08-06 17_04_36-Bean Pets _ Editing Custom_ Fluffy - Opera.png

As an explanation, the pets on my site have a description ($this->description). The function getBBDescription is set up just in case I want to get the none BBCode version at any point (using getDescription). You can always just do it regularly, this is just how I've done it. $converted is the converted text and you use $this->bbcode->bbconvert($this->description); to send the description through the BBCode bundle and output the results!

Hopefully that was clear enough but if you need any help let me know and I can try to troubleshoot!

The included commands are below:

[b\]TEXT[/b] = bold
[i\]TEXT[/i] = italic
[u\]TEXT[/u] = underlined
[s\]TEXT[/s] = strikethrough
[sup]TEXT[/sup] = superscript
[sub]TEXT[/sub] = subscript
[img\]IMG_URL[/img] = regular image
[img=WIDTHxHEIGHT\]IMG_URL[/img] = image with specified height and width, at the top of the bbcode function I have provided a way to specify the maximum height and width that images are allowed to be
[img=WIDTH\]IMG_URL[/img] = image with just the width specified
[url\]TEXT[/url] = regular url
[urlsame\]URL[/urlsame] = url that opens in the same tab
[url\=URL]TEXT[/url] = url with different text
[urlsame=URL\]TEXT[/urlsame] = url with different text that opens in the same tab
[color=COLOUR\]TEXT[/COLOR] = colours the text
[colour=COLOUR]TEXT[/colour] = colours the text but with british english lol
[size=SIZE\]TEXT[/size] = changes text size
[left\]TEXT[/left]= left aligns text
[right\]TEXT[/right] = right aligns text
[center\]TEXT[/center] = center aligns text
:\hr: = adds a horizontal rule
:\br: = adds a line break
 

Attachments

  • BBCode.php
    2.4 KB · Views: 1
Last edited:

Similar threads

Users who are viewing this thread

  • Forum Contains New Posts
  • Forum Contains No New Posts

Forum statistics

Threads
4,290
Messages
33,174
Members
1,605
Latest member
thirddivision
BETA

Latest Threads

Latest Posts

Top