Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respect the cacheBbCodeTree flag #78

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 46 additions & 11 deletions net/xenapi/XenAPI/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -1259,7 +1259,7 @@ public function processRequest() {
}

// Try to grab the post from XenForo.
$post = $this->getXenAPI()->getPost($this->getRequest('post_id'), array(), $this->getUser());
$post = $this->getXenAPI()->getPost($this->getRequest('post_id'), array());
if ($post == NULL) {
// Could not find the post, throw error.
$this->throwError(19, 'post', $this->getRequest('post_id'));
Expand Down Expand Up @@ -1333,7 +1333,7 @@ public function processRequest() {
$this->throwError(1, 'post_id');
}

$post = $this->getXenAPI()->getPost($this->getRequest('post_id'), array(), $this->getUser());
$post = $this->getXenAPI()->getPost($this->getRequest('post_id'), array());
if ($post === NULL) {
// Could not find the post, throw error.
$this->throwError(19, 'post', $this->getRequest('post_id'));
Expand Down Expand Up @@ -4397,23 +4397,59 @@ public function canViewNode($user, $node, $permissions = NULL) {
return FALSE;
}

public function getParsedPost(XenForo_BbCode_Formatter_Base $formatter, array $post)
{
$bbCodeCacheVersion = XenForo_Application::getOptions()->bbCodeCacheVersion;
$parser = XenForo_BbCode_Parser::create($formatter);
if (XenForo_Application::getOptions()->cacheBbCodeTree)
{
$tree = null;

if (!empty($post['message_parsed']))
{
$tree = @unserialize($post['message_parsed']);
}

if (empty($tree))
{
$tree = $parser->parse($post['message']);

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(
'post', $post['post_id'],
serialize($tree), $bbCodeCacheVersion, XenForo_Application::$time
));
}

return $parser->render($tree);
}
else
{
return $parser->render($post['message']);
}
}

/**
* Returns the Post array of the $post_id parameter.
*/
public function getPost($post_id, $fetchOptions = array()) {
public function getPost($post_id, $fetchOptions = array(), $parsePost = null) {
$this->getModels()->checkModel('post', XenForo_Model::create('XenForo_Model_Post'));
$post = $this->getModels()->getModel('post')->getPostById($post_id, $fetchOptions);
if (!empty($fetchOptions['join'])) {
// Unset the thread values.
Post::stripThreadValues($post);
}

if ($post !== FALSE && $post !== NULL) {
if ($post !== FALSE && $post !== NULL && $parsePost) {
// Add HTML as well
$formatter = XenForo_BbCode_Formatter_Base::create();
$parser = new XenForo_BbCode_Parser($formatter);
$post['message_html'] = str_replace("\n", '', $parser->render($post['message']));

$post['message_html'] = str_replace("\n", '', $this->getParsedPost($formatter, $post));
$post['absolute_url'] = self::getBoardURL('posts', $post['post_id']);
} else {
$post = NULL;
Expand Down Expand Up @@ -4507,9 +4543,8 @@ public function getPosts($conditions = array(), $fetchOptions = array('limit' =>
if ($post !== FALSE && $post !== NULL) {
// Add HTML as well
$formatter = XenForo_BbCode_Formatter_Base::create();
$parser = new XenForo_BbCode_Parser($formatter);
$post['message_html'] = str_replace("\n", '', $parser->render($post['message']));

$parser = XenForo_BbCode_Parser::create($formatter);
$post['message_html'] = str_replace("\n", '', $this->getParsedPost($formatter, $post));
$post['absolute_url'] = self::getBoardURL('posts', $post['post_id']);
} else {
$post = NULL;
Expand All @@ -4529,7 +4564,7 @@ public function canViewPost($user, $post, $permissions = NULL) {
$post = $this->getPost($post['post_id'], array(
'permissionCombinationId' => $user->data['permission_combination_id'],
'join' => XenForo_Model_Post::FETCH_FORUM
));
), false);

// Unserialize the permissions.
$permissions = XenForo_Permission::unserializePermissions($post['node_permission_cache']);
Expand Down