[^[]+)\[/img:{$this->seed}\]#",
function ($i) {
return "
";
},
$text
);
}
public function parseList($text)
{
$text = preg_replace("#\[list=\d+:{$this->seed}\]#", '', $text);
$text = preg_replace("#\[list(=.?)?:{$this->seed}\]#", "", $text);
$text = preg_replace("#\[/\*(:m)?:{$this->seed}\]\n?#", '', $text);
$text = str_replace("[*:{$this->seed}]", '- ', $text);
$text = str_replace("[/list:o:{$this->seed}]", '
', $text);
$text = str_replace("[/list:u:{$this->seed}]", '
', $text);
return $text;
}
public function parseCode($text)
{
return preg_replace_callback(
"#[\r|\n]*\[code:{$this->seed}\][\r|\n]*(.*?)[\r|\n]*\[/code:{$this->seed}\][\r|\n]*#s",
function ($c) {
return '' . str_replace('
', '', $c[1]) . '
';
},
$text
);
}
public function parseQuote($text)
{
$text = preg_replace("#\[quote="([^:]+)":{$this->seed}\]#", '\\1 wrote:
', $text);
$text = str_replace("[quote:{$this->seed}]", '', $text);
$text = str_replace("[/quote:{$this->seed}]", '
', $text);
return $text;
}
public function parseSimple($text)
{
// Parse all simple tags
foreach ($this->simple as $code => $tag) {
$text = str_replace("[{$code}:{$this->seed}]", "<{$tag}>", $text);
$text = str_replace("[/{$code}:{$this->seed}]", "{$tag}>", $text);
}
return $text;
}
public function parseAdvanced($text)
{
// Parse all advanced tags
foreach ($this->advanced as $code => $tags) {
$tags = explode('|', $tags);
$text = str_replace("[{$code}:{$this->seed}]", $tags[0], $text);
$text = str_replace("[/{$code}:{$this->seed}]", $tags[1], $text);
}
return $text;
}
public function parseColour($text)
{
$text = preg_replace("#\[color=([^:]+):{$this->seed}\]#", "", $text);
$text = str_replace("[/color:{$this->seed}]", '', $text);
return $text;
}
public function parseUrl($text)
{
$text = preg_replace("#\[url:{$this->seed}\](.+?)\[/url:{$this->seed}\]#", "\\1", $text);
$text = preg_replace("#\[url=(.+?):{$this->seed}\]#", "", $text);
$text = str_replace("[/url:{$this->seed}]", '', $text);
return $text;
}
public function purify($text)
{
$config = HTMLPurifier_Config::createDefault();
$config->set('Cache.SerializerPath', ROOT . 'cache/htmlpurifier');
$config->set('Attr.AllowedRel', ['nofollow']);
$config->set('HTML.Trusted', true);
$def = $config->getHTMLDefinition(true);
$def->addAttribute('img', 'src', 'Text');
$purifier = new HTMLPurifier($config);
return $purifier->purify($text);
}
public function parse()
{
// Get text
$text = $this->text;
$text = $this->parseCode($text);
$text = $this->parseList($text);
$text = $this->parseQuote($text);
$text = $this->parseAdvanced($text);
$text = $this->parseColour($text);
$text = $this->parseImage($text);
$text = $this->parseSimple($text);
$text = $this->parseUrl($text);
$text = Main::parseEmotes($text);
$text = str_replace("\n", '
', $text);
//$text = $this->purify($text);
return $text;
}
public function toEditor()
{
$text = $this->text;
$text = str_replace("[/*:m:{$this->seed}]", '', $text);
$text = preg_replace("#\[/list:[ou]:{$this->seed}\]#", '[/list]', $text);
$text = str_replace(":{$this->seed}]", ']', $text);
$text = preg_replace('#(.*?)#', '\\2', $text);
return html_entity_decode($text);
}
}