/** * Does the actual bbcode replacement * * @access protected * @param string Current bbcode to parse * @param string [Optional] Option text * @param string [Optional for single tag bbcodes] Content text * @return string Converted text */ protected function _bbcodeToHtml($_bbcode, $option = '', $content = '') { //----------------------------------------- // Strip the optional quote delimiters //----------------------------------------- $option = str_replace('"', '"', $option); $option = str_replace(''', "'", $option); $option = trim($option, '"' . "'"); //----------------------------------------- // Stop CSS injection //----------------------------------------- if ($option) { //----------------------------------------- // Cut off for entities in option // @see http://community.invisionpower.com/tracker/issue-19958-acronym/ //----------------------------------------- $option = IPSText::UNhtmlspecialchars($option); $option = str_replace('!', '!', $option); $option = IPSText::decodeNamedHtmlEntities($option); if (strpos($option, ';') !== false) { $option = substr($option, 0, strpos($option, ';')); } $charSet = IPS_DOC_CHAR_SET == 'ISO-8859-1' ? 'ISO-8859-15' : IPS_DOC_CHAR_SET; $option = @htmlentities($option, ENT_NOQUOTES, $charSet); $option = str_replace('!', '!', $option); } $option = str_replace('"', '"', $option); $option = str_replace("'", ''', $option); //----------------------------------------- // Swapping option/content? //----------------------------------------- if ($_bbcode['bbcode_switch_option']) { $_tmp = $content; $content = $option; $option = $_tmp; } //----------------------------------------- // Replace //----------------------------------------- $replaceCode = $_bbcode['bbcode_replace']; $replaceCode = str_replace('{base_url}', $this->settings['board_url'] . '/index.php?', $replaceCode); $replaceCode = str_replace('{image_url}', $this->settings['img_url'], $replaceCode); preg_match('/\\{text\\.(.+?)\\}/i', $replaceCode, $matches); if (is_array($matches) and count($matches)) { $replaceCode = str_replace($matches[0], $this->lang->words[$matches[1]], $replaceCode); } $replaceCode = str_replace('{option}', $option, $replaceCode); $replaceCode = str_replace('{content}', $content, $replaceCode); //----------------------------------------- // Fix linebreaks in textareas //----------------------------------------- if (stripos($replaceCode, "<textarea") !== false) { $replaceCode = str_replace('<br />', "", $replaceCode); $replaceCode = str_replace("\r", "", $replaceCode); $replaceCode = str_replace("\n", "<br />", $replaceCode); } return $replaceCode; }