Started work on submitting this for 1.1. There is one problem - there are a lot of different places where parse_bbc() is used. Controllers are easy because I can just add a method (or a bunch of methods) to the Action controller. It's all of the model/helper/*subs files with functions that make it hard.
There is no DIC variable so containing it somewhere means either adding a generic one or adding a variable for each of the 4 parsers plus codes. I am not a fan of using functions or a class with static methods.
I did a test of Display.controller.php to see if what I copied would work. It does. Here's what I did.
Display.controller.php
public function parseMessageBody($message, $smileys_enabled)
{
global $modSettings, $context;
// If the load average is too high, don't parse the BBC.
if (!empty($modSettings['bbc']) && $modSettings['current_load'] >= $modSettings['bbc'])
{
$context['disabled_parse_bbc'] = true;
return $message;
}
if (empty($modSettings['enableBBC']))
{
if ($smileys_enabled)
{
$smiley_parser = $this->getSmileyParser();
$smiley_parser->parse($message);
}
return $message;
}
$bbc_parser = $this->getBBCParser();
$message = $bbc_parser->parse($message);
if ($smileys_enabled)
{
$smiley_parser = $this->getSmileyParser();
$smiley_parser->parse($message);
}
return $message;
}
Action.controller.php
public function getBBCCodes()
{
global $modSettings;
if ($this->_bbc_codes === null)
{
$disabled = array();
if (!empty($modSettings['disabledBBC']))
{
$temp = explode(',', strtolower($modSettings['disabledBBC']));
foreach ($temp as $tag)
$disabled[trim($tag)] = true;
}
require_once(SUBSDIR . '/BBC/Codes.class.php');
$this->_bbc_codes = new \BBC\Codes(array(), $disabled);
}
return $this->_bbc_codes;
}
public function getBBCParser()
{
if ($this->_bbc_parser === null)
{
require_once(SUBSDIR . '/BBC/BBCParser.class.php');
$this->_bbc_parser = new \BBC\BBCParser($this->getBBCCodes(), $this->getAutolinkParser());
}
return $this->_bbc_parser;
}
public function getAutolinkParser()
{
if ($this->_autolink_parser === null)
{
require_once(SUBSDIR . '/BBC/Autolink.class.php');
$this->_autolink_parser = new \BBC\Autolink($this->getBBCCodes());
}
return $this->_autolink_parser;
}
public function getSmileyParser()
{
if ($this->_smiley_parser === null)
{
require_once(SUBSDIR . '/BBC/SmileyParser.class.php');
$this->_smiley_parser = new \BBC\SmileyParser;
}
return $this->_smiley_parser;
}
public function getHtmlParser()
{
if ($this->_html_parser === null)
{
require_once(SUBSDIR . '/BBC/HtmlParser.class.php');
$this->_html_parser = new \BBC\HtmlParser;
}
return $this->_html_parser;
}
I would prefer to put that in a DIC with a closure so you can change it with ease.