Changeset View
Changeset View
Standalone View
Standalone View
branches/5.2.x/core/units/helpers/page_helper.php
Show All 11 Lines | |||||
* See http://www.in-portal.org/license for copyright notices and details. | * See http://www.in-portal.org/license for copyright notices and details. | ||||
*/ | */ | ||||
defined('FULL_PATH') or die('restricted access!'); | defined('FULL_PATH') or die('restricted access!'); | ||||
class PageHelper extends kHelper { | class PageHelper extends kHelper { | ||||
/** | /** | ||||
* Content block cache per page. | |||||
* | |||||
* @var array | |||||
*/ | |||||
protected $contentBlockCache = array(); | |||||
/** | |||||
* Returns page info | * Returns page info | ||||
* | * | ||||
* @param int $page_id | * @param int $page_id | ||||
* @return Array | * @return Array | ||||
*/ | */ | ||||
function getPageInfo($page_id) | function getPageInfo($page_id) | ||||
{ | { | ||||
list ($user_id, $history_permission) = $this->getHistoryPermissionAndUser($page_id); | list ($user_id, $history_permission) = $this->getHistoryPermissionAndUser($page_id); | ||||
▲ Show 20 Lines • Show All 388 Lines • ▼ Show 20 Line(s) | |||||
* @param int $num | * @param int $num | ||||
* | * | ||||
* @return bool | * @return bool | ||||
*/ | */ | ||||
public function loadContentBlock(&$content_block, &$page, $num) | public function loadContentBlock(&$content_block, &$page, $num) | ||||
{ | { | ||||
$page_id = $page->GetID(); | $page_id = $page->GetID(); | ||||
// Load all content blocks at once during regular page visits. | |||||
if ( !EDITING_MODE && !$this->Application->GetVar('preview') ) { | if ( !EDITING_MODE && !$this->Application->GetVar('preview') ) { | ||||
$revision_clause = 'pr.RevisionNumber = ' . $page->GetDBField('LiveRevisionNumber') . ' AND pr.IsDraft = 0'; | if ( !isset($this->contentBlockCache[$page_id]) ) { | ||||
$where_clause = array( | |||||
$content_block->TableName . '.PageId = ' . $page_id, | |||||
'pr.RevisionNumber = ' . $page->GetDBField('LiveRevisionNumber'), | |||||
'pr.IsDraft = 0', | |||||
); | |||||
$sql = $content_block->GetSelectSQL() . ' | |||||
WHERE (' . implode(') AND (', $where_clause) . ')'; | |||||
$this->contentBlockCache[$page_id] = $this->Conn->Query($sql, 'ContentNum'); | |||||
} | |||||
if ( isset($this->contentBlockCache[$page_id][$num]) ) { | |||||
$content_block->LoadFromHash($this->contentBlockCache[$page_id][$num]); | |||||
} | } | ||||
else { | else { | ||||
$revision_clause = $this->getRevsionWhereClause($page_id, $page->GetDBField('LiveRevisionNumber'), 'pr.'); | $content_block->Clear(); | ||||
} | |||||
return $content_block->isLoaded(); | |||||
} | } | ||||
// Load each content block individually with fallback to draft version, when editing content. | |||||
$where_clause = array( | |||||
$content_block->TableName . '.PageId = ' . $page_id, | |||||
$content_block->TableName . '.ContentNum = ' . $num, | |||||
$this->getRevsionWhereClause($page_id, $page->GetDBField('LiveRevisionNumber'), 'pr.'), | |||||
); | |||||
$sql = $content_block->GetSelectSQL() . ' | $sql = $content_block->GetSelectSQL() . ' | ||||
WHERE (' . $content_block->TableName . '.PageId = ' . $page_id . ') AND (' . $content_block->TableName . '.ContentNum = ' . $num . ') AND (' . $revision_clause . ') | WHERE (' . implode(') AND (', $where_clause) . ') | ||||
ORDER BY pr.IsDraft DESC, pr.RevisionNumber DESC'; | ORDER BY pr.IsDraft DESC, pr.RevisionNumber DESC'; | ||||
$content_data = $this->Conn->GetRow($sql); | $content_data = $this->Conn->GetRow($sql); | ||||
$content_block->LoadFromHash($content_data); | $content_block->LoadFromHash($content_data); | ||||
return $content_block->isLoaded(); | return $content_block->isLoaded(); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 46 Lines • Show Last 20 Lines |