From e1dae6ee40ac707f1f3d4fc70e3a6ca4a8b69b01 Mon Sep 17 00:00:00 2001 From: Cameron Date: Wed, 29 May 2013 15:33:39 -0700 Subject: [PATCH] Improvements for {PAGE_NAVIGATION} shortcode. {PAGE_CHAPTER_NAME} and {PAGE_CHAPTER_DESCRIPTION} added. --- e107_handlers/shortcode_handler.php | 2 +- e107_plugins/page/e_shortcode.php | 82 +++++++++++++++++++--- e107_plugins/page/page_navigation_menu.php | 1 + e107_themes/bootstrap/theme.php | 6 +- 4 files changed, 78 insertions(+), 13 deletions(-) diff --git a/e107_handlers/shortcode_handler.php b/e107_handlers/shortcode_handler.php index 5ca553fd7..7921f8c2f 100644 --- a/e107_handlers/shortcode_handler.php +++ b/e107_handlers/shortcode_handler.php @@ -790,7 +790,7 @@ class e_parse_shortcode return $matches[0]; } - if(preg_match('/^([A-Z]*):(.*)/', $matches[1], $newMatch)) + if(preg_match('/^([A-Z_]*):(.*)/', $matches[1], $newMatch)) { $code = $newMatch[1]; $parmStr = trim($newMatch[2]); diff --git a/e107_plugins/page/e_shortcode.php b/e107_plugins/page/e_shortcode.php index ac97ae780..8cf0591e3 100644 --- a/e107_plugins/page/e_shortcode.php +++ b/e107_plugins/page/e_shortcode.php @@ -12,29 +12,93 @@ if (!defined('e107_INIT')) { exit; } class page_shortcodes extends e_shortcode { - function sc_page_navigation($parm) // TODO when No $parm provided, auto-detect based on URL which book/chapters to display. + protected $request; + + function __construct() { - // FIXME sitelink class should be page_sitelink - $links = e107::getAddon('page', 'e_sitelink'); - $data = $links->pageNav($parm); + $this->request = e107::getRegistry('core/pages/request'); + + if(varset($this->request['action']) == 'listPages' && vartrue($this->request['id'])) + { + $this->var = e107::getDb()->retrieve('page_chapters','chapter_name, chapter_meta_description','chapter_id = '.intval($this->request['id']).' LIMIT 1'); + } + + } + + /** + * Page Navigation + * @example {PAGE_NAVIGATION: template=navdoc&auto=1} in your Theme template. + */ + function sc_page_navigation($parm='') // TODO when No $parm provided, auto-detect based on URL which book/chapters to display. + { + // $parm = eHelper::scParams($parm); - $template = e107::getCoreTemplate('page','nav'); + $template = e107::getCoreTemplate('page',vartrue($parm['template'],'nav'), true, true); // always merge + + $request = $this->request; + + if($request && is_array($request)) + { + switch ($request['action']) + { + case 'listChapters': + $parm['cbook'] = $request['id']; + break; + + case 'listPages': + $parm['cchapter'] = $request['id']; + break; + + case 'showPage': + $parm['cpage'] = $request['id']; + break; + } + } + + if($parm) + { + $parm = http_build_query($parm, null, '&'); + } + else + { + $parm = ''; + } + + + $links = e107::getAddon('page', 'e_sitelink'); + $data = $links->pageNav($parm); + + if(isset($data['title']) && !vartrue($template['noAutoTitle'])) { + // use chapter title + $template['caption'] = $data['title']; $data = $data['body']; - } - + } + + if(empty($data)){ return; } + return e107::getNav()->render($data, $template) ; - + } + function sc_page_chapter_name($parm='') + { + return e107::getParser()->toHtml($this->var['chapter_name']); + } + + + function sc_page_chapter_description($parm='') + { + return e107::getParser()->toHtml($this->var['chapter_meta_description'],true); + } /** * New in v2.x. eg. {CMENU=feature-1} Renders a menu called 'feature-1' as found in the e107_page table See admin Pages/Menus . */ - function sc_cmenu($parm='',$mode='') + function sc_cmenu($parm='') { return e107::getMenu()->renderMenu($parm, false); } diff --git a/e107_plugins/page/page_navigation_menu.php b/e107_plugins/page/page_navigation_menu.php index 5145ca908..5d5064a1e 100644 --- a/e107_plugins/page/page_navigation_menu.php +++ b/e107_plugins/page/page_navigation_menu.php @@ -11,6 +11,7 @@ if (!defined('e107_INIT')) { exit; } +//FIXME XXX - This menu should call the {PAGE_NAVIGATION} shortcode instead of duplicating its code and automatically display all links. $parm = eHelper::scParams($parm); diff --git a/e107_themes/bootstrap/theme.php b/e107_themes/bootstrap/theme.php index 17d716b99..8c9e26811 100644 --- a/e107_themes/bootstrap/theme.php +++ b/e107_themes/bootstrap/theme.php @@ -416,8 +416,8 @@ $HEADER['docs'] = <<
-

{e_PAGETITLE}

-

How to get started..

+

{PAGE_CHAPTER_NAME}

+

{PAGE_CHAPTER_DESCRIPTION}

@@ -430,7 +430,7 @@ $HEADER['docs'] = << {SETSTYLE=navdoc} - {PLUGIN=page/page_navigation_menu|template=navdoc&auto=1} + {PAGE_NAVIGATION: template=navdoc&auto=1} {SETSTYLE=doc}