Пример #1
0
    /**
     * Renders the text.
     *
     * @return string
     */
    public function __toString()
    {
        try {
            if (XenForo_Application::getOptions()->cacheBbCodeTree && !empty($this->_cache['contentType']) && !empty($this->_cache['contentId'])) {
                $tree = null;
                if (!empty($this->_cache['cache']) && !empty($this->_cache['cacheVersion']) && $this->_cache['cacheVersion'] == XenForo_Application::getOptions()->bbCodeCacheVersion) {
                    if (is_array($this->_cache['cache'])) {
                        $tree = $this->_cache['cache'];
                    } else {
                        $tree = @unserialize($this->_cache['cache']);
                    }
                }
                if (!$tree) {
                    try {
                        // need to update
                        $tree = $this->_parser->parse($this->_text);
                        $this->_cache['cache'] = $tree;
                        $this->_cache['cacheVersion'] = XenForo_Application::getOptions()->bbCodeCacheVersion;
                        $uniqueId = $this->_cache['contentType'] . '-' . $this->_cache['contentId'];
                        if (empty(self::$_cacheWritten[$uniqueId])) {
                            XenForo_Application::getDb()->query('
								INSERT INTO xf_bb_code_parse_cache
									(content_type, content_id, parse_tree, cache_version, cache_date)
								VALUES (?, ?, ?, ?, ?)
								ON DUPLICATE KEY UPDATE parse_tree = VALUES(parse_tree),
									cache_version = VALUES(cache_version),
									cache_date = VALUES(cache_date)
							', array($this->_cache['contentType'], $this->_cache['contentId'], serialize($tree), $this->_cache['cacheVersion'], XenForo_Application::$time));
                            self::$_cacheWritten[$uniqueId] = true;
                        }
                    } catch (Exception $e) {
                        return $this->_parser->render($this->_text, $this->_extraStates);
                    }
                }
                return $this->_parser->render($tree, $this->_extraStates);
            } else {
                return $this->_parser->render($this->_text, $this->_extraStates);
            }
        } catch (Exception $e) {
            XenForo_Error::logException($e, false, "BB code to string error:");
            return '';
        }
    }
Пример #2
0
 public static function renderGalleryComment(XenForo_BbCode_Parser $parser, &$message)
 {
     if (XenForo_Application::getOptions()->sonnbXG_extraBbcode) {
         self::$_tags = array_merge(self::$_tags, array('img', 'media'));
     }
     $message = preg_replace(array('/(\\[url\\]\\[url\\])/i', '/(\\[\\/url\\]\\[\\/url\\])/i'), array('[url]', '[/url]'), $message);
     $message = XenForo_Helper_String::censorString($message);
     $message = self::linkTaggedPlainText($message);
     $tags = $parser->parse($message);
     if (!empty($tags)) {
         $tags = self::_processTags($tags);
     }
     $extraStates = array('stopLineBreakConversion' => 1);
     $message = new XenForo_BbCode_TextWrapper($tags, $parser, $extraStates);
     return $message;
 }