listPages();
if(is_array($tmp))
{
$ns->tablerender($tmp['title'], $tmp['text']);
require_once(FOOTERF);
exit;
}
}
else
{
$e107CorePage->processViewPage();
require_once(HEADERF);
echo $e107CorePage->showPage();
require_once(FOOTERF);
exit;
}
/* EOF */
class pageClass
{
public $bullet; /* bullet image */
public $pageText; /* main text of selected page, not parsed */
public $multipageFlag; /* flag - true if multiple page page, false if not */
public $pageTitles; /* array containing page titles */
public $pageID; /* id number of page to be displayed */
public $pageSelected; /* selected page of multiple page page */
public $pageToRender; /* parsed page to be sent to screen */
public $debug; /* temp debug flag */
public $title; /* title of page, it if has one (as defined in [newpage=title] tag */
public $page; /* page DB data */
public $batch; /* shortcode batch object */
public $template; /* current template array */
protected $authorized; /* authorized status */
public $cacheString; /* current page cache string */
public $cacheTitleString; /* current page title and comment flag cache string */
public $cacheData = null; /* cache data */
function __construct($debug=FALSE)
{
/* constructor */
$tmp = explode(".", e_QUERY);
$this->pageID = intval($tmp[0]);
$this->pageSelected = (isset($tmp[1]) ? intval($tmp[1]) : 0);
$this->pageTitles = array();
$this->bullet = '';
// TODO nq_ (no query) cache string
$this->cacheString = 'page_'.$this->pageID.'_'.$this->pageSelected;
$this->cacheTitleString = 'page-t_'.$this->pageID.'_'.$this->pageSelected;
if(defined('BULLET'))
{
$this->bullet = '';
}
elseif(file_exists(THEME.'images/bullet2.gif'))
{
$this->bullet = '';
}
$this->debug = $debug;
if($this->debug)
{
$this->debug = "PageID ".$this->pageID."
";
$this->debug .= "pageSelected ".$this->pageSelected."
";
}
}
// TODO template for page list
function listPages()
{
$sql = e107::getDb();
if(!e107::getPref('listPages', false))
{
message_handler("MESSAGE", LAN_PAGE_1);
}
else
{
if(!$sql->db_Select("page", "*", "page_theme='' AND page_class IN (".USERCLASS_LIST.") "))
{
$text = LAN_PAGE_2;
}
else
{
$pageArray = $sql->db_getList();
foreach($pageArray as $page)
{
$url = e107::getUrl()->create('page/view', $page, 'allow=page_id,page_sef');
$text .= $this->bullet." ".$page['page_title']."
";
}
e107::getRender()->tablerender(LAN_PAGE_11, $text,"cpage_list");
}
}
}
function processViewPage()
{
if($this->checkCache())
{
return;
}
$sql = e107::getDb();
$query = "SELECT p.*, u.user_id, u.user_name, user_login FROM #page AS p
LEFT JOIN #user AS u ON p.page_author = u.user_id
WHERE p.page_id=".intval($this->pageID); // REMOVED AND p.page_class IN (".USERCLASS_LIST.") - permission check is done later
if(!$sql->db_Select_gen($query))
{
$ret['title'] = LAN_PAGE_12; // ***** CHANGED
$ret['sub_title'] = '';
$ret['text'] = LAN_PAGE_3;
$ret['comments'] = '';
$ret['rating'] = '';
$ret['np'] = '';
$ret['err'] = TRUE;
$ret['cachecontrol'] = false;
$this->authorized = 'nf';
$this->template = e107::getCoreTemplate('page', 'default');
$this->batch = e107::getScBatch('page')->setParserVars(new e_vars($ret))->setScVar('page', array());
define("e_PAGETITLE", $ret['title']);
return;
}
$this->page = $sql->db_Fetch();
$this->template = e107::getCoreTemplate('page', vartrue($this->page['page_template'], 'default'));
if(empty($this->template)) $this->template = e107::getCoreTemplate('page', 'default');
$this->batch = e107::getScBatch('page');
$this->pageText = $this->page['page_text'];
$this->pageCheckPerms($this->page['page_class'], $this->page['page_password'], $this->page['page_title']);
if($this->debug)
{
echo "pageText ".$this->pageText."
";
}
$this->parsePage();
$pagenav = $rating = $comments = '';
if($this->authorized === true)
{
$pagenav = $this->pageIndex();
$rating = $this->pageRating($this->page['page_rating_flag']);
$comments = $this->pageComment($this->page['page_comment_flag']);
}
$ret['title'] = $this->page['page_title'];
$ret['sub_title'] = $this->title;
$ret['text'] = $this->pageToRender;
$ret['np'] = $pagenav;
$ret['rating'] = $rating;
$ret['comments'] = $comments;
$ret['err'] = FALSE;
$ret['cachecontrol'] = (isset($this->page['page_password']) && !$this->page['page_password'] && $this->authorized === true); // Don't cache password protected pages
$this->batch->setParserVars(new e_vars($ret))->setScVar('page', $this->page);
define('e_PAGETITLE', eHelper::formatMetaTitle($ret['title']));
define('META_DESCRIPTION', $this->page['page_metadscr']);
define('META_KEYWORDS', $this->page['page_metakeys']);
//return $ret;
}
public function checkCache()
{
$e107cache = e107::getCache();
$cacheData = $e107cache->retrieve($this->cacheString);
if(false !== $cacheData)
{
$this->cacheData = array();
$this->cacheData['PAGE'] = $cacheData;
list($pagetitle, $comment_flag, $meta_keys, $meta_dscr) = explode("^^^",$e107cache->retrieve($this->cacheTitleString), 4);
$this->cacheData['TITLE'] = $pagetitle;
$this->cacheData['COMMENT_FLAG'] = $comment_flag;
$this->cacheData['META_KEYS'] = $meta_keys;
$this->cacheData['META_DSCR'] = $meta_dscr;
}
}
public function setCache($data, $title, $comment_flag)
{
$e107cache = e107::getCache();
$e107cache->set($this->cacheString, $data);
$e107cache->set($this->cacheTitleString, $title."^^^".$this->page['page_comment_flag']."^^^".$this->page['page_metakeys']."^^^".$this->page['page_metadscr']);
}
public function renderCache()
{
$comments = '';
if($this->cacheData['COMMENT_FLAG'])
{
$vars = new e_vars(array('comments' => $this->pageComment(true)));
$comments = e107::getScBatch('page')->setParserVars($vars)->cpagecomments();
}
define('e_PAGETITLE', eHelper::formatMetaTitle($this->cacheData['TITLE']));
define('META_DESCRIPTION', $this->cacheData['META_DSCR']);
define('META_KEYWORDS', $this->cacheData['META_KEYS']);
if($this->debug)
{
echo "Reading page from cache
";
}
return str_replace('[[PAGECOMMENTS]]', $comments, $this->cacheData['PAGE']);
}
public function showPage()
{
if(null !== $this->cacheData)
{
return $this->renderCache();
}
if(true === $this->authorized)
{
$vars = $this->batch->getParserVars();
$template = str_replace('{PAGECOMMENTS}', '[[PAGECOMMENTS]]', $this->template['start'].$this->template['body'].$this->template['end']);
$ret = $this->renderPage($template);
if(!empty($this->template['page']))
{
$ret = str_replace(array('{PAGE}', '{PAGECOMMENTS}'), array($ret, '[[PAGECOMMENTS]]'), $this->template['page']);
}
$ret = e107::getParser()->parseTemplate($ret, true, $this->batch);
if($vars->cachecontrol) $this->setCache($ret, $this->batch->sc_cpagetitle(), $this->page['page_comment_flag']);
return str_replace('[[PAGECOMMENTS]]', $this->batch->cpagecomments(), $ret);
}
$extend = new e_vars;
$vars = $this->batch->getParserVars();
// reset batch data
$this->batch->setParserVars(null)->setScVar('page', array());
// copy some data
$extend->title = $vars->title;
$extend->message = e107::getMessage()->render();
switch ($this->authorized)
{
case 'class':
$extend->text = LAN_PAGE_6;
$template = $this->template['start'].$this->template['restricted'].$this->template['end'];
break;
case 'pw':
$frm = e107::getForm();
$extend->caption = LAN_PAGE_8;
$extend->label = LAN_PAGE_9;
$extend->password = $frm->password('page_pw');
$extend->icon = e_IMAGE_ABS.'generic/password.png';
$extend->submit = $frm->submit('submit_page_pw', LAN_PAGE_10);
// FIXME - add form open/close e_form methods
$extend->form_open = '
"; print_r($pages); echo ""; echo "pageCount ".$pageCount."
"; print_r($this->pageTitles); echo ""; } } } function pageIndex() { // Use always nextprev shortcode (with a special default 'page' tempalte) $titles = implode("|",$this->pageTitles); $total_items = count($this->pageTitles); //$parms = $total_items.",1,".$this->pageSelected.",".e_SELF."?".$this->pageID.".[FROM],,$titles"; $row = $this->page; $row['page'] = '--FROM--'; $url = rawurlencode(e107::getUrl()->create('page/view', $row, 'allow=page_id,page_title,page_sef,page')); $parms = 'nonavcount&bullet='.rawurlencode($this->bullet.' ').'&caption=&'.'pagetitle='.rawurlencode($titles).'&tmpl_prefix='.deftrue('PAGE_NEXTPREV_TMPL', 'page').'&total='.$total_items.'&amount=1¤t='.$this->pageSelected.'&url='.$url; $itext = ($total_items) ? e107::getParser()->parseTemplate("{NEXTPREV={$parms}}") : ""; return $itext; } // FIXME most probably will fail when cache enabled function pageRating($page_rating_flag) { if($page_rating_flag) { return "
"; if ($ratearray = $rater->getrating("page", $this->pageID)) { if ($ratearray[2] == "") { $ratearray[2] = 0; } $rate_text .= "\n"; $rate_text .= " ".$ratearray[1].".".$ratearray[2]." - ".$ratearray[0]." "; $rate_text .= ($ratearray[0] == 1 ? "vote" : "votes"); } else { $rating .= LAN_PAGE_dl_13; } $rate_text .= " | "; if (!$rater->checkrated("page", $this->pageID) && USER) { $rate_text .= $rater->rateselect(" ".LAN_PAGE_4."", "page", $this->pageID); } else if(!USER) { $rate_text .= " "; } else { $rate_text .= LAN_PAGE_5; } $rate_text .= " |