diff --git a/e107_core/shortcodes/batch/page_shortcodes.php b/e107_core/shortcodes/batch/page_shortcodes.php index ccd2c86fa..e1c3b85a3 100644 --- a/e107_core/shortcodes/batch/page_shortcodes.php +++ b/e107_core/shortcodes/batch/page_shortcodes.php @@ -15,12 +15,15 @@ if (!defined('e107_INIT')) { exit; } * * Shortcodes for custom page display */ + + +// XXX FIXME All shortcodes should return a value from $this->var. + class cpage_shortcodes extends e_shortcode { // var $var; // parsed DB values private $chapterData = array(); - // Works in 'magic' mode, so setting it breaks everything - //public $page = array(); + // Grab all book/chapter data. function __construct() { @@ -34,11 +37,19 @@ class cpage_shortcodes extends e_shortcode } } + - // Return data for a specific chapter-id + // Set Chapter. // @see chapter_menu.php + public function setChapter($id) + { + $this->var['page_chapter'] = intval($id); + } + + // Return data for a specific chapter-id - XXX @SecretR - without $page defined above, this will return nothing. All $this->var need to be replaced with $this->var function getChapter() { - $id = $this->page['page_chapter']; + + $id = $this->var['page_chapter']; if(vartrue($this->chapterData[$id]['chapter_id']) && $this->chapterData[$id]['chapter_parent'] > 0) { @@ -49,10 +60,13 @@ class cpage_shortcodes extends e_shortcode // Return data for a specific book-id - function getBook() + function getBook($cid='') { - $pid = $this->page['page_chapter']; - $cid = $this->chapterData[$pid]['chapter_parent']; + if(empty($cid)) + { + $pid = $this->var['page_chapter']; + $cid = $this->chapterData[$pid]['chapter_parent']; + } $row = $this->chapterData[$cid]; @@ -71,38 +85,38 @@ class cpage_shortcodes extends e_shortcode function sc_cpagetitle($parm='') { - return e107::getParser()->toHTML($this->getParserVars()->title, true, 'TITLE'); + return e107::getParser()->toHTML($this->var['page_title'], true, 'TITLE'); } function sc_cpagesubtitle() { - $subtitle = $this->getParserVars()->sub_title; + $subtitle = $this->var['sub_title']; return $subtitle ? e107::getParser()->toHTML($subtitle, true, 'TITLE') : ''; } function sc_cpagebody($parm='') { - // already parsed - return $this->getParserVars()->text; + $text = $this->var['page_text']; + return $text ? e107::getParser()->toHTML($text, true, 'BODY') : ''; } function sc_cpageauthor($parm) { $parms = eHelper::scParams($parm); $author = ''; - $url = e107::getUrl()->create('user/profile/view', array('name' => $this->page['user_name'], 'id' => $this->page['user_id'])); + $url = e107::getUrl()->create('user/profile/view', array('name' => $this->var['user_name'], 'id' => $this->var['user_id'])); if(isset($parms['url'])) { return $url; } - if($this->page['page_author']) + if($this->var['page_author']) { // currently this field used as Real Name, no matter what the db name says - if($this->page['user_login'] && !isset($parms['user'])) $author = $this->page['user_login']; - elseif($this->page['user_name']) $author = preg_replace('/[^\w\pL\s]+/u', ' ', $this->page['user_name']); + if($this->var['user_login'] && !isset($parms['user'])) $author = $this->var['user_login']; + elseif($this->var['user_name']) $author = preg_replace('/[^\w\pL\s]+/u', ' ', $this->var['user_name']); } if(empty($author)) return ''; @@ -121,44 +135,50 @@ class cpage_shortcodes extends e_shortcode { if(empty($parm)) { - return e107::getDateConvert()->convert_date($this->page['page_datestamp'], 'long'); + return e107::getDateConvert()->convert_date($this->var['page_datestamp'], 'long'); } - return e107::getDateConvert()->convert_date($this->page['page_datestamp'], $parm); + return e107::getDateConvert()->convert_date($this->var['page_datestamp'], $parm); } function sc_cpageid() { - return $this->page['page_id']; + return $this->var['page_id']; } function sc_cpageanchor() { - $frm = e107::getForm(); - return $frm->name2id($this->page['page_title']); + return e107::getForm()->name2id($this->var['page_title']); } // Not a shortcode really, as it shouldn't be cached at all :/ function cpagecomments() { - $com = $this->getParserVars()->comments; + $com = $this->var['comments']; //if($parm && isset($com[$parm])) return $com[$parm]; return $com['comment'].$com['comment_form']; } function sc_cpagenav() { - return $this->getParserVars()->np; + return $this->var['np']; } function sc_cpagerating() { - return $this->getParserVars()->rating; + return $this->var['rating']; } function sc_cpagemessage() { return e107::getMessage()->render(); } + + function sc_cpagemenu() + { + $parm = $this->var['menu_name']; + return e107::getMenu()->renderMenu($parm, false, false, true); + + } /** * Auto-thumbnailing now allowed. @@ -206,9 +226,9 @@ class cpage_shortcodes extends e_shortcode function sc_cpageimage($parm = '') { list($num,$size) = explode("|",$parm); - if($this->page['page_images']) + if($this->var['page_images']) { - $img = explode(",",$this->page['page_images']); + $img = explode(",",$this->var['page_images']); } } @@ -233,7 +253,7 @@ class cpage_shortcodes extends e_shortcode return $url; } - if(trim($this->page['page_text']) == '') // Hide the button when there is no page content. (avoids templates with and without buttons) + if(trim($this->var['page_text']) == '') // Hide the button when there is no page content. (avoids templates with and without buttons) { return ""; } @@ -252,27 +272,27 @@ class cpage_shortcodes extends e_shortcode { $tp = e107::getParser(); // - return $tp->toHTML($this->page['menu_title'], true, 'TITLE'); + return $tp->toHTML($this->var['menu_title'], true, 'TITLE'); } function sc_cmenubody($parm='') { // print_a($this); - return e107::getParser()->toHTML($this->page['menu_text'], true, 'BODY'); + return e107::getParser()->toHTML($this->var['menu_text'], true, 'BODY'); } function sc_cmenuimage($parm='') { $tp = e107::getParser(); - - if($video = $tp->toVideo($this->page['menu_image'])) + + if($video = $tp->toVideo($this->var['menu_image'])) { return $video; } - $img = $tp->thumbUrl($this->page['menu_image']); + $img = $tp->thumbUrl($this->var['menu_image']); if($parm == 'url') { return $img; @@ -283,19 +303,19 @@ class cpage_shortcodes extends e_shortcode function sc_cmenuicon($parm='') { - return e107::getParser()->toIcon($this->page['menu_icon'], array('space'=>' ')); + return e107::getParser()->toIcon($this->var['menu_icon'], array('space'=>' ')); } function sc_cpageurl() { - $route = ($this->page['page_chapter'] == 0) ? 'page/view/other' : 'page/view'; - $urldata = $this->page; + $route = ($this->var['page_chapter'] == 0) ? 'page/view/other' : 'page/view'; + $urldata = $this->var; - if($this->page['page_chapter'] && $this->chapterData[$this->page['page_chapter']]) + if($this->var['page_chapter'] && $this->chapterData[$this->var['page_chapter']]) { - $chapter = $this->chapterData[$this->page['page_chapter']]; - $urldata = array_merge($this->page, $chapter); + $chapter = $this->chapterData[$this->var['page_chapter']]; + $urldata = array_merge($this->var, $chapter); $urldata['book_sef'] = $this->chapterData[$chapter['chapter_parent']]['chapter_sef']; } return e107::getUrl()->create($route, $urldata, array('allow' => 'page_sef,page_title,page_id,chapter_sef,book_sef')); @@ -303,12 +323,12 @@ class cpage_shortcodes extends e_shortcode function sc_cpagemetadiz() { - return $this->page['page_metadscr']; + return $this->var['page_metadscr']; } function sc_cpagesef() { - return vartrue($this->page['page_sef'],'page-no-sef'); + return vartrue($this->var['page_sef'],'page-no-sef'); } // -------------------- Book - specific to the current page. ------------------------- @@ -352,8 +372,11 @@ class cpage_shortcodes extends e_shortcode function sc_chapter_name() { + $tp = e107::getParser(); $row = $this->getChapter(); + + return $tp->toHtml($row['chapter_name'], false, 'TITLE'); } @@ -382,6 +405,26 @@ class cpage_shortcodes extends e_shortcode return $tp->toHtml($row['chapter_meta_description'], true, 'BODY'); } + function sc_chapter_url() + { + $tp = e107::getParser(); + $row = $this->getChapter(); + + $brow = $this->getBook($row['chapter_parent']); + $row['book_sef'] = vartrue($brow['chapter_sef'],"no-sef-found"); //$this->getBook(); + + return e107::getUrl()->create('page/chapter/index', $row,'allow=chapter_id,chapter_sef,book_sef') ; + + } + + function sc_chapter_button($options) + { + $text = vartrue($options['text'], LAN_READ_MORE); + $size = vartrue($options['size'], ""); + $inc = ($size) ? " btn-".$size : ""; + + return ''.$text.''; + } function sc_cpagerelated($array=array()) @@ -391,11 +434,10 @@ class cpage_shortcodes extends e_shortcode $array['types'] = 'page,news'; } - return e107::getForm()->renderRelated($array, $this->page['page_metakeys'], array('page'=>$this->page['page_id'])); + return e107::getForm()->renderRelated($array, $this->var['page_metakeys'], array('page'=>$this->var['page_id'])); } - } diff --git a/e107_core/shortcodes/single/menu.php b/e107_core/shortcodes/single/menu.php index ff8f12b4f..1523ecab7 100644 --- a/e107_core/shortcodes/single/menu.php +++ b/e107_core/shortcodes/single/menu.php @@ -6,6 +6,7 @@ if(!defined('e107_INIT')) function menu_shortcode($parm, $mode='') { + if(is_array($parm)) //v2.x format allowing for parms. {MENU: path=y&count=x} { list($plugin,$menu) = explode("/",$parm['path'],2); diff --git a/e107_core/templates/chapter_template.php b/e107_core/templates/chapter_template.php index fdb9451b4..aab00e60d 100644 --- a/e107_core/templates/chapter_template.php +++ b/e107_core/templates/chapter_template.php @@ -106,6 +106,15 @@ $CHAPTER_TEMPLATE['nav']['listPages'] = $CHAPTER_TEMPLATE['nav']['listChapters'] $CHAPTER_TEMPLATE['nav']['showPage'] = $CHAPTER_TEMPLATE['nav']['listChapters']; +// Used by e107_plugins/page/chapter_menu.php +$CHAPTER_TEMPLATE['panel']['listChapters']['start'] = "
"; +$CHAPTER_TEMPLATE['panel']['listChapters']['item'] = "

{CHAPTER_ICON}


{CHAPTER_DESCRIPTION}

"; +$CHAPTER_TEMPLATE['panel']['listChapters']['end'] = "
"; +$CHAPTER_TEMPLATE['panel']['listPages']['caption'] = "{CHAPTER_NAME}"; +$CHAPTER_TEMPLATE['panel']['listPages']['start'] = "
"; +$CHAPTER_TEMPLATE['panel']['listPages']['item'] = "{SETSTYLE=none}
{CPAGEMENU}
"; +$CHAPTER_TEMPLATE['panel']['listPages']['end'] = "
"; + ?> \ No newline at end of file diff --git a/e107_handlers/menu_class.php b/e107_handlers/menu_class.php index 5cd2780c7..f00b7348f 100644 --- a/e107_handlers/menu_class.php +++ b/e107_handlers/menu_class.php @@ -432,7 +432,7 @@ class e_menu { $template = e107::getCoreTemplate('menu',$page['menu_template']); $page_shortcodes = e107::getScBatch('page',null,'cpage'); - $page_shortcodes->page = $page; + $page_shortcodes->setVars($page); $head = $tp->parseTemplate($template['start'], true); $foot = $tp->parseTemplate($template['end'], true); diff --git a/e107_plugins/page/chapter_menu.php b/e107_plugins/page/chapter_menu.php new file mode 100644 index 000000000..37b63e70f --- /dev/null +++ b/e107_plugins/page/chapter_menu.php @@ -0,0 +1,47 @@ +retrieve("SELECT * FROM #page_chapters WHERE chapter_visibility IN (".USERCLASS_LIST.") AND chapter_template = 'panel' ".$insert. " LIMIT 24", true); + +$sc = e107::getScBatch('page', null, 'cpage'); + +echo $template['listChapters']['start']; + +foreach($data as $row) +{ + $sc->setVars($row); + + $sc->setChapter($row['chapter_id']); + $title = $tp->toHtml($row['chapter_name'],false,'TITLE'); // Used when tablerender style includes the caption. + $body = $tp->parseTemplate($template['listChapters']['item'], true, $sc); + + $ns->tablerender($title, $body, 'chapter-menu'); // check for $mode == 'page-menu' in tablestyle() if you need a simple 'echo' without rendering styles. +} + +echo $template['listChapters']['end']; + +?> \ No newline at end of file diff --git a/page.php b/page.php index b21195351..02b51e67b 100644 --- a/page.php +++ b/page.php @@ -93,9 +93,11 @@ class pageClass public $cacheData = null; /* cache data */ protected $chapterSef; /* authorized status */ protected $chapterParent; - + protected $chapterData = array(); + protected $displayAllMode = false; // set to True when no book/chapter/page has been defined by the url/query. + function __construct($debug=FALSE) { /* constructor */ @@ -146,8 +148,6 @@ class pageClass foreach($books as $row) { $id = $row['chapter_id']; - // $this->chapterSef[$id] = $row['chapter_sef']; - // $this->chapterParent[$id] = $row['chapter_parent']; $this->chapterData[$id] = $row; } @@ -215,6 +215,8 @@ class pageClass $tp = e107::getParser(); $frm = e107::getForm(); + $this->displayAllMode = true; + $text = ""; @@ -272,6 +274,8 @@ class pageClass } + + /** * Parse the Book/Chapter "listChapters' template */ @@ -287,9 +291,15 @@ class pageClass $layout = 'default'; } + if($this->displayAllMode === true) + { + $layout = e107::getPref('listBooksTemplate'); + } + + $error = array('listChapters' => array('start'=>"Chapter template not found: ".$layout)); $tml = e107::getCoreTemplate('chapter','', true, true); // always merge - $tmpl = varset($tml[$layout]); + $tmpl = varset($tml[$layout],$error ); $template = $tmpl['listChapters']; @@ -369,7 +379,15 @@ class pageClass // retrieve the template to use for this chapter. $row = $sql->retrieve('page_chapters','chapter_id,chapter_icon,chapter_name,chapter_parent, chapter_meta_description,chapter_template','chapter_id = '.intval($chapt).' LIMIT 1'); - $layout = vartrue($row['chapter_template'],'default'); + + if($this->displayAllMode === true) + { + $layout = e107::getPref('listBooksTemplate'); + } + else + { + $layout = vartrue($row['chapter_template'],'default'); + } $bookSef = $this->getSef($row['chapter_parent']); @@ -410,22 +428,24 @@ class pageClass $page['chapter_sef'] = $this->getSef($page['page_chapter']); // $chapter_sef; $page['book_sef'] = $bookSef; - $this->page = $page; - $this->batch->setVars(new e_vars($data))->setScVar('page', $this->page); + // $this->page = $page; + $this->batch->setVars($page); + // $this->batch->setVars(new e_vars($data))->setScVar('page', $this->page); + // $url = e107::getUrl()->create('page/view', $page, 'allow=page_id,page_sef,chapter_sef,book_sef'); // $text .= "
  • ".$tp->toHtml($page['page_title'])."
  • "; $text .= e107::getParser()->parseTemplate($template['item'], true, $this->batch); } - $text .= $tp->simpleParse($template['end'],$var); + $text .= $tp->simpleParse($template['end'], $var); // $caption = ($title !='')? $title: LAN_PAGE_11; // e107::getRender()->tablerender($caption, $text,"cpage_list"); } - $caption = $tp->simpleParse($template['caption'],$var); + $caption = $tp->simpleParse($template['caption'], $var); return array('caption'=>$caption, 'text'=> $text); } @@ -446,6 +466,9 @@ class pageClass if(!$sql->gen($query)) { + + /* + $ret['title'] = LAN_PAGE_12; // ***** CHANGED $ret['sub_title'] = ''; $ret['text'] = LAN_PAGE_3; @@ -454,11 +477,30 @@ class pageClass $ret['np'] = ''; $ret['err'] = TRUE; $ret['cachecontrol'] = false; + */ + + // ---------- New (to replace values above) ---- + + $this->page['page_title'] = LAN_PAGE_12; // ***** CHANGED + $this->page['sub_title'] = ''; + $this->page['page_text'] = LAN_PAGE_3; + $this->page['comments'] = ''; + $this->page['rating'] = ''; + $this->page['np'] = ''; + $this->page['err'] = TRUE; + $this->page['cachecontrol'] = false; + + // ------------------------------------- + $this->authorized = 'nf'; $this->template = e107::getCoreTemplate('page', 'default'); - $this->batch = e107::getScBatch('page',null,'cpage')->setVars(new e_vars($ret))->setScVar('page', array()); + // $this->batch = e107::getScBatch('page',null,'cpage')->setVars(new e_vars($ret))->setScVar('page', array()); ///FIXME Needs upgrading to setVars() array. (not using '$this->page') - define("e_PAGETITLE", $ret['title']); + $this->batch = e107::getScBatch('page',null,'cpage')->setVars($this->page); + + + + define("e_PAGETITLE", $this->page['page_title']); return; } @@ -467,6 +509,7 @@ class pageClass // setting override to true breaks default. $this->template = e107::getCoreTemplate('page', vartrue($this->page['page_template'], 'default'), true, true); + if(!$this->template) { // switch to default @@ -498,7 +541,7 @@ class pageClass $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; @@ -507,8 +550,23 @@ class pageClass $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->setVars(new e_vars($ret))->setScVar('page', $this->page); // Removed in favour of $this->var (cross-compatible with menus and other parts of e107 that use the same shortcodes) + + // ---- New --- - + $this->page['page_text'] = $this->pageToRender; + $this->page['np'] = $pagenav; + $this->page['rating'] = $rating; + $this->page['comments'] = $comments; + $this->page['err'] = FALSE; + $this->page['cachecontrol'] = (isset($this->page['page_password']) && !$this->page['page_password'] && $this->authorized === true); + + // ----------------- + + + $this->batch->setVars($this->page); - $this->batch->setVars(new e_vars($ret))->setScVar('page', $this->page); define('e_PAGETITLE', eHelper::formatMetaTitle($ret['title'])); if($this->page['page_metadscr']) define('META_DESCRIPTION', eHelper::formatMetaDescription($this->page['page_metadscr'])); @@ -590,7 +648,7 @@ class pageClass $vars = $this->batch->getParserVars(); // reset batch data - $this->batch->setVars(null)->setScVar('page', array()); +// $this->batch->setVars(null)->setScVar('page', array()); // copy some data $extend->title = $vars->title; @@ -628,28 +686,25 @@ class pageClass public function renderPage($template, $vars = null) { + if(null === $vars) { $ret = e107::getParser()->parseTemplate($template, true, $this->batch); - $vars = $this->batch->getParserVars(); } else { $ret = e107::getParser()->simpleParse($template, $vars); } - // if(vartrue($this->template['noTableRender'])) //XXX Deprecated - use tablerender $mode instead. eg. cpage-templatename : echo $text; - // { - // return $ret; - // } - $mode = vartrue($this->template['tableRender'], 'cpage-'.$template); - $title = $vars->title; - return e107::getRender()->tablerender($title, $ret, $mode, true); + return e107::getRender()->tablerender($this->page['page_title'], $ret, $mode, true); + } - public function parsePage() + + + public function parsePage() //XXX FIXME Move to page_shortcodes. { $tp = e107::getParser(); e107::getBB()->setClass("page"); @@ -731,6 +786,8 @@ class pageClass e107::getBB()->clearClass(); } + + function pageIndex() { // Use always nextprev shortcode (with a special default 'page' tempalte) @@ -755,44 +812,6 @@ class pageClass if($page_rating_flag) { return "
    ".e107::getRate()->render("page", $this->pageID,array('label'=>LAN_PAGE_4))."
    "; - /* - - $rate_text = ''; // Notice removal - - require_once(e_HANDLER."rate_class.php"); - $rater = new rater; - $rate_text = "
    "; - - 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 .= "
    "; - */ } @@ -800,12 +819,14 @@ class pageClass // return $rate_text; } + + + function pageComment($page_comment_flag) { if($page_comment_flag) { - require_once(e_HANDLER."comment_class.php"); - $cobj = new comment; + $cobj = e107::getComment(); if (isset($_POST['commentsubmit'])) { @@ -818,6 +839,8 @@ class pageClass } } + + function pageCheckPerms($page_class, $page_password, $page_title=" ") { global $ns, $tp, $pref, $HEADER, $FOOTER, $sql; // $tp added - also $pref - used by footer @@ -867,11 +890,15 @@ class pageClass return false; } + + function getCookieName() { return e_COOKIE.'_page_'.$this->pageID; } + + function setPageCookie() { if(!$this->pageID || !vartrue($_POST['page_pw'])) return;