public function testAttributes() { $parser = new JBBCode\Parser(); $builder = new JBBCode\CodeDefinitionBuilder('img', '<img src="{param}" height="{height}" alt="{alt}" />'); $parser->addCodeDefinition($builder->setUseOption(true)->setParseContent(false)->build()); $expected = 'Multiple <img src="http://jbbcode.com/img.png" height="50" alt="alt text" /> options.'; $code = 'Multiple [img height="50" alt="alt text"]http://jbbcode.com/img.png[/img] options.'; $parser->parse($code); $result = $parser->getAsHTML(); $this->assertEquals($expected, $result); $code = 'Multiple [img height=50 alt="alt text"]http://jbbcode.com/img.png[/img] options.'; $parser->parse($code); $result = $parser->getAsHTML(); $this->assertEquals($expected, $result); }
/** * parseBBcode * @return void */ public function parseBBcode() { $dom = new \DomDocument(); $dom->loadHTML($this->html); $finder = new \DomXPath($dom); $nodes = $finder->query("//*[contains(concat(' ', normalize-space(@class), ' '), ' cacheLogText ')]"); $parser = new JBBCode\Parser(); $parser->addCodeDefinitionSet(new JBBCode\DefaultCodeDefinitionSet()); foreach ($this->bbcode_colors as $color) { $builder = new JBBCode\CodeDefinitionBuilder($color, '<span style="color: ' . $color . ';">{param}</span>'); $parser->addCodeDefinition($builder->build()); } foreach ($nodes as $node) { $raw_log = $node->ownerDocument->saveHTML($node); $raw_log = trim(str_replace(array('<td class="cacheLogText" colspan="2">', '</td>'), '', $raw_log)); $log = preg_replace('/<br>$/', '', $raw_log); $parser->parse($log); $node->nodeValue = $parser->getAsHtml(); } //$smileyVisitor = new JBBCode\visitors\SmileyVisitor(); //$parser->accept($smileyVisitor); $this->html = htmlspecialchars_decode($dom->saveHtml()); $bbcodes = array_keys($this->bbcode_smileys); $images = array_values($this->bbcode_smileys); foreach ($images as $k => &$image) { $image = '<img src="../images/icons/' . $image . '" alt="' . $bbcodes[$k] . '" />'; } foreach ($bbcodes as &$bbcode) { $bbcode = '[' . $bbcode . ']'; } $this->html = str_replace($bbcodes, $images, $this->html); }
/** * Convert BBCode to HTML. * * @param string $bbcode * @return string */ public static function bbcode($bbcode) { $parser = new \JBBCode\Parser(); $parser->addCodeDefinitionSet(new \JBBCode\DefaultCodeDefinitionSet()); $builder = new \JBBCode\CodeDefinitionBuilder('quote', '<blockquote>{param}</blockquote>'); $parser->addCodeDefinition($builder->build()); $builder = new \JBBCode\CodeDefinitionBuilder('code', '<pre><code>{param}</code></pre>'); $builder->setParseContent(false); $parser->addCodeDefinition($builder->build()); $parser->parse($bbcode); $html = $parser->getAsHtml(); return Filters\HTMLFilter::clean($html); }
protected function addBbcodes($parser, $customBbcodes) { foreach ($customBbcodes as $name => $value) { $builder = new \JBBCode\CodeDefinitionBuilder($name, $value); $parser->addCodeDefinition($builder->build()); } }
public function __construct() { $youtube = new \YoutubeCodeDefinition(); array_push($this->definitions, $youtube); $image = new \ImageCodeDefinition(); array_push($this->definitions, $image); $ul = new \ULCodeDefinition(); array_push($this->definitions, $ul); $ol = new \OLCodeDefinition(); array_push($this->definitions, $ol); $table = new \TableCodeDefinition(); array_push($this->definitions, $table); $builder = new CodeDefinitionBuilder('s', '<span style="text-decoration: line-through">{param}</span>'); array_push($this->definitions, $builder->build()); $builder = new CodeDefinitionBuilder('sup', '<sup>{param}</sup>'); array_push($this->definitions, $builder->build()); $builder = new CodeDefinitionBuilder('sub', '<sub>{param}</sub>'); array_push($this->definitions, $builder->build()); $builder = new CodeDefinitionBuilder('code', '<pre>{param}</pre>'); array_push($this->definitions, $builder->build()); $builder = new CodeDefinitionBuilder('left', '<div class="text-left">{param}</div>'); array_push($this->definitions, $builder->build()); $builder = new CodeDefinitionBuilder('right', '<div class="text-right">{param}</div>'); array_push($this->definitions, $builder->build()); $builder = new CodeDefinitionBuilder('center', '<div class="text-center">{param}</div>'); array_push($this->definitions, $builder->build()); $builder = new \JBBCode\CodeDefinitionBuilder('quote', '<blockquote>{param}</blockquote>'); $builder->setUseOption(true); array_push($this->definitions, $builder->build()); $builder = new CodeDefinitionBuilder('size', '<span class="cj-font-size-{option}">{param}</span>'); $builder->setUseOption(true)->setParseContent(true); array_push($this->definitions, $builder->build()); $builder = new CodeDefinitionBuilder('attachment', '{CJATTACHMENT ["id": {option}]}'); $builder->setUseOption(true)->setParseContent(true); array_push($this->definitions, $builder->build()); // $builder = new \JBBCode\CodeDefinitionBuilder('font', '<span style="font-family: {option}">{param}</span>'); // $builder->setUseOption(true); // $builder->setOptionValidator($cssValidator); // array_push($this->definitions, $builder->build()); }
protected function processCommentBBCode($comment) { if ($this->_bbcode_processor === null) { $parser = new \JBBCode\Parser(); $definitions = array(); $builder = new \Foolz\FoolFuuka\Model\BBCode\Code(); array_push($definitions, $builder); $builder = new \JBBCode\CodeDefinitionBuilder('spoiler', '<span class="spoiler">{param}</span>'); array_push($definitions, $builder->build()); $builder = new \JBBCode\CodeDefinitionBuilder('sub', '<sub>{param}</sub>'); $builder->setNestLimit(1); array_push($definitions, $builder->build()); $builder = new \JBBCode\CodeDefinitionBuilder('sup', '<sup>{param}</sup>'); $builder->setNestLimit(1); array_push($definitions, $builder->build()); $builder = new \JBBCode\CodeDefinitionBuilder('eqn', '<script type="math/tex; mode=display">{param}</script>'); array_push($definitions, $builder->build()); $builder = new \JBBCode\CodeDefinitionBuilder('math', '<script type="math/tex">{param}</script>'); array_push($definitions, $builder->build()); $builder = new \JBBCode\CodeDefinitionBuilder('b', '<strong>{param}</strong>'); array_push($definitions, $builder->build()); $builder = new \JBBCode\CodeDefinitionBuilder('i', '<em>{param}</em>'); array_push($definitions, $builder->build()); $builder = new \JBBCode\CodeDefinitionBuilder('o', '<span class="overline">{param}</span>'); array_push($definitions, $builder->build()); $builder = new \JBBCode\CodeDefinitionBuilder('s', '<span class="strikethrough">{param}</span>'); array_push($definitions, $builder->build()); $builder = new \JBBCode\CodeDefinitionBuilder('u', '<span class="underline">{param}</span>'); array_push($definitions, $builder->build()); $definitions = Hook::forge('Foolz\\FoolFuuka\\Model\\Comment::processCommentBBCode#var.definitions')->setObject($this)->setParam('definitions', $definitions)->execute()->get($definitions); foreach ($definitions as $definition) { $parser->addCodeDefinition($definition); } $this->_bbcode_processor = $parser; } // work around for dealing with quotes in BBCode tags $comment = str_replace('"', '"', $comment); $comment = $this->_bbcode_processor->parse($comment)->getAsBBCode(); $comment = str_replace('"', '"', $comment); return $this->_bbcode_processor->parse($comment)->getAsHTML(); }
public function __construct() { parent::__construct(); $this->addCodeDefinitionSet(new JBBCode\DefaultCodeDefinitionSet()); $builder = new JBBCode\CodeDefinitionBuilder('sectioncode', '<pre class="brush: {option}; toolbar: false; first-line: 1; class-name: \'my_personnal_code\'">{param}</pre>'); $builder->setUseOption(true); $this->addCodeDefinition($builder->build()); $builder = new JBBCode\CodeDefinitionBuilder('code', '<pre class="brush: {option}; toolbar: false; first-line: 1; class-name: \'my_personnal_code\'">{param}</pre>'); $builder->setUseOption(true); $this->addCodeDefinition($builder->build()); $builder = new JBBCode\CodeDefinitionBuilder('image', '<img src="{option}" alt="{param}"/>'); $builder->setUseOption(true); $this->addCodeDefinition($builder->build()); $builder = new JBBCode\CodeDefinitionBuilder('size', '<span>{param}</span>'); $builder->setUseOption(true); $this->addCodeDefinition($builder->build()); $builder = new JBBCode\CodeDefinitionBuilder('font', '<span style="font-family={option}">{param}</span>'); $builder->setUseOption(true); $this->addCodeDefinition($builder->build()); $builder = new JBBCode\CodeDefinitionBuilder('internallink', '<a href="{option}" target="_self">{param}</a>'); $builder->setUseOption(true); $this->addCodeDefinition($builder->build()); $builder = new JBBCode\CodeDefinitionBuilder('legend', '<p class="code-legend">{param}</p>'); $this->addCodeDefinition($builder->build()); $builder = new JBBCode\CodeDefinitionBuilder('externalink', '<a href="{option}" target="_blank">{param}</a>'); $builder->setUseOption(true); $this->addCodeDefinition($builder->build()); $builder = new JBBCode\CodeDefinitionBuilder('zip', '<a href="{option}" target="_blank" class="ziplink resourcelink">{param}</a>'); $builder->setUseOption(true); $this->addCodeDefinition($builder->build()); $builder = new JBBCode\CodeDefinitionBuilder('pdf', '<a href="{option}" target="_blank" class="pdflink resourcelink">{param}</a>'); $builder->setUseOption(true); $this->addCodeDefinition($builder->build()); $builder = new JBBCode\CodeDefinitionBuilder('quote', '<blockquote><cite class="quoteFrom">{option}</cite>{param}</blockquote>'); $builder->setUseOption(true); $this->addCodeDefinition($builder->build()); $builder = new JBBCode\CodeDefinitionBuilder('becareful', '<becareful class="alert alert-warning">{param}</becareful>'); $this->addCodeDefinition($builder->build()); $builder = new JBBCode\CodeDefinitionBuilder('info', '<info class="alert alert-info">{param}</info>'); $this->addCodeDefinition($builder->build()); $builder = new JBBCode\CodeDefinitionBuilder('retourligne', '<br/>'); $this->addCodeDefinition($builder->build()); $builder = new JBBCode\CodeDefinitionBuilder('left', '<div align="left">{param}</div>'); $this->addCodeDefinition($builder->build()); $builder = new JBBCode\CodeDefinitionBuilder('leftedCode', '<div class="code-left">{param}</div>'); $this->addCodeDefinition($builder->build()); $builder = new JBBCode\CodeDefinitionBuilder('center', '<div align="center">{param}</div>'); $this->addCodeDefinition($builder->build()); $builder = new JBBCode\CodeDefinitionBuilder('justify', '<div align="justify">{param}</div>'); $this->addCodeDefinition($builder->build()); /* * ********** la suite est non implémentée à ce jour côté javascript !! ** */ $builder = new JBBCode\CodeDefinitionBuilder('section1', '<h2 class="section" id="{option}">{param}</h1>'); //$builder->setUseOption(true); $this->addCodeDefinition($builder->build()); $builder = new JBBCode\CodeDefinitionBuilder('section2', '<h3 class="section" >{param}</h2>'); $this->addCodeDefinition($builder->build()); $builder = new JBBCode\CodeDefinitionBuilder('section3', '<h4 class="section" >{param}</h2>'); $this->addCodeDefinition($builder->build()); $builder = new JBBCode\CodeDefinitionBuilder('p', '<p>{param}</p>'); $this->addCodeDefinition($builder->build()); $builder = new JBBCode\CodeDefinitionBuilder('ol', '<ol>{param}</ol>'); $this->addCodeDefinition($builder->build()); $builder = new JBBCode\CodeDefinitionBuilder('ul', '<ul>{param}</ul>'); $this->addCodeDefinition($builder->build()); $builder = new JBBCode\CodeDefinitionBuilder('li', '<li>{param}</li>'); $this->addCodeDefinition($builder->build()); $builder = new JBBCode\CodeDefinitionBuilder('youtube', '<iframe width="560" height="315" src="{param}" frameborder="0" allowfullscreen></iframe>'); $this->addCodeDefinition($builder->build()); $builder = new JBBCode\CodeDefinitionBuilder('video', '<iframe id="player" type="text/html" \\n\\ width="560" height="315" src="http://www.youtube.com/embed/{param}?enablejsapi=1" \\n\\ frameborder="0"></iframe>'); $this->addCodeDefinition($builder->build()); $builder = new JBBCode\CodeDefinitionBuilder('a', '<a href="{option}" target="_blank">{param}</a>'); $builder->setUseOption(true); $this->addCodeDefinition($builder->build()); $builder = new JBBCode\CodeDefinitionBuilder('table', '<table class="{option}">{param}</table>'); $builder->setUseOption(true); $this->addCodeDefinition($builder->build()); $builder = new JBBCode\CodeDefinitionBuilder('td', '<td>{param}</td>'); $this->addCodeDefinition($builder->build()); $builder = new JBBCode\CodeDefinitionBuilder('tr', '<tr>{param}</tr>'); $this->addCodeDefinition($builder->build()); }
public function __construct() { parent::__construct(); $this->addCodeDefinitionSet(new JBBCode\DefaultCodeDefinitionSet()); $builder = new JBBCode\CodeDefinitionBuilder('code', '<pre><code class="{option}">{param}</code></pre>'); $builder->setUseOption(true); $this->addCodeDefinition($builder->build()); $builder = new JBBCode\CodeDefinitionBuilder('image', '<img src="{option}" alt="{param}"/>'); $builder->setUseOption(true); $this->addCodeDefinition($builder->build()); $builder = new JBBCode\CodeDefinitionBuilder('size', '<span>{param}</span>'); $builder->setUseOption(true); $this->addCodeDefinition($builder->build()); $builder = new JBBCode\CodeDefinitionBuilder('font', '<span style="font-family={option}">{param}</span>'); $builder->setUseOption(true); $this->addCodeDefinition($builder->build()); $builder = new JBBCode\CodeDefinitionBuilder('internallink', '<a href="{option}" target="_self">{param}</a>'); $builder->setUseOption(true); $this->addCodeDefinition($builder->build()); $builder = new JBBCode\CodeDefinitionBuilder('legend', '<p class="code-legend">{param}</p>'); $this->addCodeDefinition($builder->build()); $builder = new JBBCode\CodeDefinitionBuilder('externalink', '<a href="{option}" target="_blank">{param}</a>'); $builder->setUseOption(true); $this->addCodeDefinition($builder->build()); $builder = new JBBCode\CodeDefinitionBuilder('zip', '<a href="{option}" target="_blank" class="ziplink resourcelink">{param}</a>'); $builder->setUseOption(true); $this->addCodeDefinition($builder->build()); $builder = new JBBCode\CodeDefinitionBuilder('pdf', '<a href="{option}" target="_blank" class="pdflink resourcelink">{param}</a>'); $builder->setUseOption(true); $this->addCodeDefinition($builder->build()); $builder = new JBBCode\CodeDefinitionBuilder('quote', '<blockquote><cite class="quoteFrom">{option}</cite>{param}</blockquote>'); $builder->setUseOption(true); $this->addCodeDefinition($builder->build()); $builder = new JBBCode\CodeDefinitionBuilder('becareful', '<becareful class="alert alert-warning">{param}</becareful>'); $this->addCodeDefinition($builder->build()); $builder = new JBBCode\CodeDefinitionBuilder('info', '<info class="alert alert-info">{param}</info>'); $this->addCodeDefinition($builder->build()); $builder = new JBBCode\CodeDefinitionBuilder('retourligne', '<br/>'); $this->addCodeDefinition($builder->build()); $builder = new JBBCode\CodeDefinitionBuilder('left', '<div align="left">{param}</div>'); $this->addCodeDefinition($builder->build()); $builder = new JBBCode\CodeDefinitionBuilder('leftedCode', '<div class="code-left">{param}</div>'); $this->addCodeDefinition($builder->build()); $builder = new JBBCode\CodeDefinitionBuilder('center', '<div align="center">{param}</div>'); $this->addCodeDefinition($builder->build()); $builder = new JBBCode\CodeDefinitionBuilder('justify', '<div align="justify">{param}</div>'); $this->addCodeDefinition($builder->build()); $builder = new JBBCode\CodeDefinitionBuilder('h2', '<h2 class="section">{param}</h1>'); //$builder->setUseOption(true); $this->addCodeDefinition($builder->build()); $builder = new JBBCode\CodeDefinitionBuilder('h3', '<h3 class="section" >{param}</h2>'); $this->addCodeDefinition($builder->build()); $builder = new JBBCode\CodeDefinitionBuilder('h4', '<h4 class="section" >{param}</h2>'); $this->addCodeDefinition($builder->build()); $builder = new JBBCode\CodeDefinitionBuilder('b', '<strong>{param}</strong>'); $this->addCodeDefinition($builder->build()); $builder = new JBBCode\CodeDefinitionBuilder('i', '<em>{param}</em>'); $this->addCodeDefinition($builder->build()); $builder = new JBBCode\CodeDefinitionBuilder('p', '<p>{param}</p>'); $this->addCodeDefinition($builder->build()); $builder = new JBBCode\CodeDefinitionBuilder('ol', '<ol>{param}</ol>'); $this->addCodeDefinition($builder->build()); $builder = new JBBCode\CodeDefinitionBuilder('list', '<ul>{param}</ul>'); $this->addCodeDefinition($builder->build()); $builder = new JBBCode\CodeDefinitionBuilder('list', '<ol>{param}</ol>'); $builder->setUseOption(true); $this->addCodeDefinition($builder->build()); $builder = new JBBCode\CodeDefinitionBuilder('*', '<li>{param}</li>'); $this->addCodeDefinition($builder->build()); $builder = new JBBCode\CodeDefinitionBuilder('li', '<li>{param}</li>'); $this->addCodeDefinition($builder->build()); $builder = new JBBCode\CodeDefinitionBuilder('youtube', '<iframe width="560" height="315" src="{param}" frameborder="0" allowfullscreen></iframe>'); $this->addCodeDefinition($builder->build()); $builder = new JBBCode\CodeDefinitionBuilder('video', '<iframe id="player" type="text/html" \\n\\ width="560" height="315" src="http://www.youtube.com/embed/{param}?enablejsapi=1" \\n\\ frameborder="0"></iframe>'); $this->addCodeDefinition($builder->build()); $builder = new JBBCode\CodeDefinitionBuilder('a', '<a href="{option}" target="_blank">{param}</a>'); $builder->setUseOption(true); $this->addCodeDefinition($builder->build()); $builder = new JBBCode\CodeDefinitionBuilder('table', '<table class="table table-striped">{param}</table>'); // $builder->setUseOption(true); $this->addCodeDefinition($builder->build()); $builder = new JBBCode\CodeDefinitionBuilder('td', '<td>{param}</td>'); $this->addCodeDefinition($builder->build()); $builder = new JBBCode\CodeDefinitionBuilder('tr', '<tr>{param}</tr>'); $this->addCodeDefinition($builder->build()); $builder = new JBBCode\CodeDefinitionBuilder('br', '<br/>'); $this->addCodeDefinition($builder->build()); $code = new JBBCode\codedefinitions\FileCodeDefinition(); $code->setUseOption(true); $this->addCodeDefinition($code); }
function markup(&$body, $track_cites = false) { global $board, $config, $markup_urls; $modifiers = extract_modifiers($body); $body = preg_replace('@<tinyboard (?!escape )([\\w\\s]+)>(.+?)</tinyboard>@us', '', $body); $body = preg_replace('@<(tinyboard) escape ([\\w\\s]+)>@i', '<$1 $2>', $body); if (isset($modifiers['raw html']) && $modifiers['raw html'] == '1') { return array(); } $body = str_replace("\r", '', $body); $body = utf8tohtml($body); if (mysql_version() < 50503) { $body = mb_encode_numericentity($body, array(0x10000, 0xffffff, 0, 0xffffff), 'UTF-8'); } $parser = new JBBCode\Parser(); foreach ($config['markup'] as $markup) { if (is_string($markup[1])) { $builder = new JBBCode\CodeDefinitionBuilder($markup[0], $markup[1]); if ($markup[2] == "option") { $builder->setUseOption(true); } else { if ($markup[2] == "false") { $builder->setParseContent(false); } } $parser->addCodeDefinition($builder->build()); } } foreach ($config['old_markup'] as $markup) { if (is_string($markup[1])) { $body = preg_replace($markup[0], $markup[1], $body); } elseif (is_callable($markup[1])) { $body = preg_replace_callback($markup[0], $markup[1], $body); } } $parser->addCodeDefinition($builder->build()); $parser->parse($body); $body = $parser->getAsHtml(); if ($config['markup_urls']) { $markup_urls = array(); $body = preg_replace_callback('/((?:https?:\\/\\/|ftp:\\/\\/|irc:\\/\\/)[^\\s<>()"]+?(?:\\([^\\s<>()"]*?\\)[^\\s<>()"]*?)*)((?:\\s|<|>|"|\\.||\\]|!|\\?|,|,|")*(?:[\\s<>()"]|$))/', 'markup_url', $body, -1, $num_links); if ($num_links > $config['max_links']) { error($config['error']['toomanylinks']); } } if ($config['markup_repair_tidy']) { $body = str_replace(' ', ' ', $body); } if ($config['auto_unicode']) { $body = unicodify($body); if ($config['markup_urls']) { foreach ($markup_urls as &$url) { $body = str_replace(unicodify($url), $url, $body); } } } $tracked_cites = array(); // Cites if (isset($board) && preg_match_all('/(^|\\s)?>>(\\d+?)([\\s,.)?]|$)/m', $body, $cites, PREG_SET_ORDER | PREG_OFFSET_CAPTURE)) { if (count($cites[0]) > $config['max_cites']) { error($config['error']['toomanycites']); } $skip_chars = 0; $body_tmp = $body; $search_cites = array(); foreach ($cites as $matches) { $search_cites[] = '`id` = ' . $matches[2][0]; } $search_cites = array_unique($search_cites); $query = query(sprintf('SELECT `thread`, `id` FROM ``posts_%s`` WHERE ' . implode(' OR ', $search_cites), $board['uri'])) or error(db_error()); $cited_posts = array(); while ($cited = $query->fetch(PDO::FETCH_ASSOC)) { $cited_posts[$cited['id']] = $cited['thread'] ? $cited['thread'] : false; } foreach ($cites as $matches) { $cite = $matches[2][0]; // preg_match_all is not multibyte-safe foreach ($matches as &$match) { $match[1] = mb_strlen(substr($body_tmp, 0, $match[1])); } if (isset($cited_posts[$cite])) { $replacement = '<a onclick="highlightReply(\'' . $cite . '\');" href="' . $config['root'] . $board['dir'] . $config['dir']['res'] . ($cited_posts[$cite] ? $cited_posts[$cite] : $cite) . '.html#' . $cite . '">' . '>>' . $cite . '</a>'; $body = mb_substr_replace($body, $matches[1][0] . $replacement . $matches[3][0], $matches[0][1] + $skip_chars, mb_strlen($matches[0][0])); $skip_chars += mb_strlen($matches[1][0] . $replacement . $matches[3][0]) - mb_strlen($matches[0][0]); if ($track_cites && $config['track_cites']) { $tracked_cites[] = array($board['uri'], $cite); } } } } // Cross-board linking if (preg_match_all('/(^|\\s)>>>\\/(' . $config['board_regex'] . 'f?)\\/(\\d+)?([\\s,.)?]|$)/um', $body, $cites, PREG_SET_ORDER | PREG_OFFSET_CAPTURE)) { if (count($cites[0]) > $config['max_cites']) { error($config['error']['toomanycross']); } $skip_chars = 0; $body_tmp = $body; if (isset($cited_posts)) { // Carry found posts from local board >>X links foreach ($cited_posts as $cite => $thread) { $cited_posts[$cite] = $config['root'] . $board['dir'] . $config['dir']['res'] . ($thread ? $thread : $cite) . '.html#' . $cite; } $cited_posts = array($board['uri'] => $cited_posts); } else { $cited_posts = array(); } $crossboard_indexes = array(); $search_cites_boards = array(); foreach ($cites as $matches) { $_board = $matches[2][0]; $cite = @$matches[3][0]; if (!isset($search_cites_boards[$_board])) { $search_cites_boards[$_board] = array(); } $search_cites_boards[$_board][] = $cite; } $tmp_board = $board['uri']; foreach ($search_cites_boards as $_board => $search_cites) { $clauses = array(); foreach ($search_cites as $cite) { if (!$cite || isset($cited_posts[$_board][$cite])) { continue; } $clauses[] = '`id` = ' . $cite; } $clauses = array_unique($clauses); if ($board['uri'] != $_board) { if (!openBoard($_board)) { continue; } // Unknown board } if (!empty($clauses)) { $cited_posts[$_board] = array(); $query = query(sprintf('SELECT `thread`, `id` FROM ``posts_%s`` WHERE ' . implode(' OR ', $clauses), $board['uri'])) or error(db_error()); while ($cite = $query->fetch(PDO::FETCH_ASSOC)) { $cited_posts[$_board][$cite['id']] = $config['root'] . $board['dir'] . $config['dir']['res'] . ($cite['thread'] ? $cite['thread'] : $cite['id']) . '.html#' . $cite['id']; } } $crossboard_indexes[$_board] = $config['root'] . $board['dir'] . $config['file_index']; } // Restore old board if ($board['uri'] != $tmp_board) { openBoard($tmp_board); } foreach ($cites as $matches) { $_board = $matches[2][0]; $cite = @$matches[3][0]; // preg_match_all is not multibyte-safe foreach ($matches as &$match) { $match[1] = mb_strlen(substr($body_tmp, 0, $match[1])); } if ($cite) { if (isset($cited_posts[$_board][$cite])) { $link = $cited_posts[$_board][$cite]; $replacement = '<a ' . ($_board == $board['uri'] ? 'onclick="highlightReply(\'' . $cite . '\');" ' : '') . 'href="' . $link . '">' . '>>>/' . $_board . '/' . $cite . '</a>'; $body = mb_substr_replace($body, $matches[1][0] . $replacement . $matches[4][0], $matches[0][1] + $skip_chars, mb_strlen($matches[0][0])); $skip_chars += mb_strlen($matches[1][0] . $replacement . $matches[4][0]) - mb_strlen($matches[0][0]); if ($track_cites && $config['track_cites']) { $tracked_cites[] = array($_board, $cite); } } } elseif (isset($crossboard_indexes[$_board])) { $replacement = '<a href="' . $crossboard_indexes[$_board] . '">' . '>>>/' . $_board . '/' . '</a>'; $body = mb_substr_replace($body, $matches[1][0] . $replacement . $matches[4][0], $matches[0][1] + $skip_chars, mb_strlen($matches[0][0])); $skip_chars += mb_strlen($matches[1][0] . $replacement . $matches[4][0]) - mb_strlen($matches[0][0]); } } } $tracked_cites = array_unique($tracked_cites, SORT_REGULAR); $body = preg_replace("/^\\s*>.*\$/m", '<span class="quote">$0</span>', $body); if ($config['strip_superfluous_returns']) { $body = preg_replace('/\\s+$/', '', $body); } $body = preg_replace("/\n/", '<br/>', $body); if ($config['markup_repair_tidy']) { $tidy = new tidy(); $body = str_replace("\t", '	', $body); $body = $tidy->repairString($body, array('doctype' => 'omit', 'bare' => true, 'literal-attributes' => true, 'indent' => false, 'show-body-only' => true, 'wrap' => 0, 'output-bom' => false, 'output-html' => true, 'newline' => 'LF', 'quiet' => true), 'utf8'); $body = str_replace("\n", '', $body); } // replace tabs with 8 spaces $body = str_replace("\t", ' ', $body); return $tracked_cites; }
/** * Gets html from bbcode. * * @param string $bbcode * @return string */ public function getHtmlFromBBCode($bbcode) { require_once APPLICATION_PATH . '/libraries/jbbcode/Parser.php'; $parser = new \JBBCode\Parser(); $parser->addCodeDefinitionSet(new \JBBCode\DefaultCodeDefinitionSet()); $builder = new \JBBCode\CodeDefinitionBuilder('quote', '<div class="quote">{param}</div>'); $parser->addCodeDefinition($builder->build()); $builder = new \JBBCode\CodeDefinitionBuilder('list', '<ul>{param}</ul>'); $parser->addCodeDefinition($builder->build()); $builder = new \JBBCode\CodeDefinitionBuilder('*', '<li>{param}</li>'); $parser->addCodeDefinition($builder->build()); $builder = new \JBBCode\CodeDefinitionBuilder('email', '<a href="mailto:{param}">{param}</a>'); $parser->addCodeDefinition($builder->build()); $builder = new \JBBCode\CodeDefinitionBuilder('img', '<img src="{param}" alt="Image">'); $parser->addCodeDefinition($builder->build()); $builder = new \JBBCode\CodeDefinitionBuilder('i', '<em>{param}</em>'); $parser->addCodeDefinition($builder->build()); $builder = new \JBBCode\CodeDefinitionBuilder('u', '<u>{param}</u>'); $parser->addCodeDefinition($builder->build()); $builder = new \JBBCode\CodeDefinitionBuilder('url', '<a href="{option}">{param}</a>'); $builder->setUseOption(true)->setOptionValidator(new \JBBCode\validators\UrlValidator()); $parser->addCodeDefinition($builder->build()); $builder = new \JBBCode\CodeDefinitionBuilder('code', '<pre class="code">{param}</pre>'); $builder->setParseContent(false); $parser->addCodeDefinition($builder->build()); $parser->parse($bbcode); return $parser->getAsHTML(); }
foreach (preg_split("/\\R/", $this->getContent($el)) as $line) { $result .= "> " . $line . "\n"; } return $result . "\n"; } } $parser = new JBBCode\Parser(); $builder = new JBBCode\CodeDefinitionBuilder('i', '/{param}/'); $parser->addCodeDefinition($builder->build()); $builder = new JBBCode\CodeDefinitionBuilder('u', '_{param}_'); $parser->addCodeDefinition($builder->build()); $builder = new JBBCode\CodeDefinitionBuilder('b', '*{param}*'); $parser->addCodeDefinition($builder->build()); $parser->addCodeDefinition(new QuoteWithOption()); $parser->addCodeDefinition(new QuoteWithoutOption()); $builder = new JBBCode\CodeDefinitionBuilder('code', '{param}'); $parser->addCodeDefinition($builder->build()); $builder = (new JBBCode\CodeDefinitionBuilder('color', '{param}'))->setUseOption(true); $parser->addCodeDefinition($builder->build()); $builder = (new JBBCode\CodeDefinitionBuilder('size', '{param}'))->setUseOption(true); $parser->addCodeDefinition($builder->build()); $parser->parse($message); $message = $parser->getAsHtml(); // build the informational table $message .= "{$phrase['subject']}: {$post_SUBJECT}\n"; $message .= "{$phrase['thread']}: {$post_TOPICTITLE} {$thread_url}\n"; $message .= "{$phrase['forum']} : {$post_FORUMPARENTS_laquo}{$post_FORUMNAME} {$forum_url}\n"; $message .= "{$phrase['actions']}:\n"; $message .= " Reply address in the AEGEE Forum: " . $reply_url . "\n"; $message .= " Post URL: " . $post_url . "\n"; $message .= " Info URL: " . $info_url . "\n\n";