Jeremy
in memoriam 1991-2020
I'll call myself a self-addicted BBCode programmer on XenForo. Many of you may use BB Code Manager, but I'm slowly reading and learning new items about XenForos BB Code System. I suggest you read the comprehensive guide on creating BB Codes, as I will not be touching upon them here.
Setting up a Parser: Using "Base"
XenForo using a static function called create() within the XenForo_BbCode_Formatter_Base class. Normal usage is done as this:
However, if I am creating "Base" we can use the following and get the same results:
Setting up a Parser: Using non-Base XenForo parsers
In addition, if I wanted to create an instance of XenForo_BbCode_Formatter_Text, I would use the following code (omitting the options here):
The create() method includes a small check to see if the $class parameter of create() (the first one) includes the underscore character ('_'). If it doesn't, it automatically adds, "XenForo_BbCode_Formatter_" to the beginning of $class. Meaning, the following code will allow you to set up a parser with less typing on your end:
As I continue read-throughs of BB Code classes & functions, I will continue to expand this list.
(Probably will be adding more tonight as well.)
Implementing an Image Count limit option
Thanks to ragtek for the initial tip, however, here's a more indepth (XenForo based) top on how to use XenForo_BbCode_Formatter_ImageCount to add a limit on the number of images and media within a single post in your add-on. This class extends XenForo_BbCode_Formatter_Base and makes 2 changes, ands 2 variables, and two functions. You gain a function to access each count variable added, getImageCount() and getMediaCount(), which can allow for your checking system. Here's an example using a fictional setting: myAddon_max_images_and_media.
Of course, these can be separated at will, but the idea is the same. You would of course handle the error in which ever way you choose.
Setting up a Parser: Using "Base"
XenForo using a static function called create() within the XenForo_BbCode_Formatter_Base class. Normal usage is done as this:
PHP:
$parser = new XenForo_BbCode_Formatter_Base::create('XenForo_BbCode_Formatter_Base', $optionsArray);
However, if I am creating "Base" we can use the following and get the same results:
PHP:
$parser = new XenForo_BbCode_Formatter_Base::create();
Setting up a Parser: Using non-Base XenForo parsers
In addition, if I wanted to create an instance of XenForo_BbCode_Formatter_Text, I would use the following code (omitting the options here):
PHP:
$parser = new XenForo_BbCode_Formatter_Base::create('XenForo_BbCode_Formatter_Text');
The create() method includes a small check to see if the $class parameter of create() (the first one) includes the underscore character ('_'). If it doesn't, it automatically adds, "XenForo_BbCode_Formatter_" to the beginning of $class. Meaning, the following code will allow you to set up a parser with less typing on your end:
PHP:
$parser = new XenForo_BbCode_Formatter_Base::create('Text');
As I continue read-throughs of BB Code classes & functions, I will continue to expand this list.

Implementing an Image Count limit option
Thanks to ragtek for the initial tip, however, here's a more indepth (XenForo based) top on how to use XenForo_BbCode_Formatter_ImageCount to add a limit on the number of images and media within a single post in your add-on. This class extends XenForo_BbCode_Formatter_Base and makes 2 changes, ands 2 variables, and two functions. You gain a function to access each count variable added, getImageCount() and getMediaCount(), which can allow for your checking system. Here's an example using a fictional setting: myAddon_max_images_and_media.
PHP:
$parser = new XenForo_Formatter_Base::create('ImageCount');
$parser->parse($message);
$count = XenForo_Application::get('options')->myAddon_max_images_and_media;
if(($parser->getImageCount() + $parser->getMediaCount()) > $count)
{
throw new XenForo_Exception(new XenForo_Phrase('myAddon_toomanymedia'), true);
}
Of course, these can be separated at will, but the idea is the same. You would of course handle the error in which ever way you choose.