<?php
namespace BBC;
class ParserWrapper
{
protected $disabled = array();
protected $codes;
protected $bbc_parser;
protected $smiley_parser;
protected $html_parser;
protected $autolink_parser;
protected static $instance;
public static function getInstance()
{
}
protected function checkLoad()
{
global $modSettings, $context;
if (!empty($modSettings['bbc']) && $modSettings['current_load'] >= $modSettings['bbc'])
{
$context['disabled_parse_bbc'] = true;
return false;
}
return true;
}
protected function isEnabled()
{
return empty($modSettings['enableBBC']);
}
public function enableSmileys($toggle)
{
$this->smileys_enabled = (bool) $toggle;
return $this;
}
protected function getParsersByArea($area)
{
$parsers = array(
'bbc' => false,
'smiley' => false,
);
// First see if any hooks set a parser.
foreach ($parsers as $parser_type => &$parser)
{
call_integration_hook('integrate_' . $area . '_' . $parser_type . '_parser', array(&$parser, $this));
// If not, use the default one
if ($parser === false)
{
$parser = call_user_func(array($this, 'get' . ucfirst($parser_type) . 'Parser'));
}
}
return $parsers;
}
public function getMessageParsers()
{
return $this->getParsersByArea('message');
}
public function getSignatureParser()
{
return $this->getParsersByArea('signature');
}
public function getNewsParser()
{
return $this->getParsersByArea('news');
}
protected function parse($area, $string)
{
global $modSettings;
// If the load average is too high, don't parse the BBC.
if (!$this->checkLoad())
{
return $message;
}
$parsers = $this->getParsersByArea($area);
if (!$this->isEnabled())
{
if ($this->smileys_enabled)
{
$parsers['smiley']->parse($message);
}
return $message;
}
$message = $parsers['bbc']->parse($message);
if ($smileys_enabled)
{
$parsers['smiley']->parse($message);
}
return $message;
}
public function parseMessage($message, $smileys_enabled)
{
return $this->enableSmileys($smileys_enabled)->parse('message', $message);
}
public function parseSignature($signature, $smileys_enabled)
{
return $this->enableSmileys($smileys_enabled)->parse('signature', $signature);
}
public function parseNews($news)
{
return $this->enableSmileys(true)->parse('news', $news);
}
public function parseEmail($message)
{
return $this->enableSmileys(false)->parse('email', $message);
}
public function parseCustomFields($field)
{
return $this->enableSmileys(true)->parse('customfields', $field);
}
public function parsePoll($field)
{
return $this->enableSmileys(true)->parse('poll', $field);
}
public function parseAgreement($agreement)
{
return $this->enableSmileys(true)->parse('agreement', $agreement);
}
public function parsePM($message)
{
return $this->enableSmileys(true)->parse('pm', $message);
}
public function parseReport($report)
{
return $this->enableSmileys(true)->parse('report', $report);
}
// $modSettings['disabledBBC']
public function setDisabled(array $disabled)
{
foreach ($disabled as $tag)
{
$this->disabled[trim($tag)] = true;
}
return $this;
}
public function getCodes()
{
global $modSettings;
if ($this->codes === null)
{
require_once(SUBSDIR . '/BBC/Codes.class.php');
$this->codes = new \BBC\Codes(array(), $this->disabled);
}
return $this->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 haven't completed it yet (busy) but here is what I plan on doing to implement this before we add a DIC.