From 1b3168dcbc22e9ae05ad550964f3573649133369 Mon Sep 17 00:00:00 2001 From: Cameron Date: Thu, 26 Oct 2017 11:21:18 -0700 Subject: [PATCH] The {CHAPTER_MENUS} shortcode now accepts the 'template' parameter. Additional Custom Menu shortcodes/aliases added: {CMENU_TAB_ACTIVE} {CMENU_BUTTON_TEXT} {CMENU_BUTTON_URL} --- .../shortcodes/batch/page_shortcodes.php | 38 ++++++++--- e107_plugins/page/e_shortcode.php | 63 ++++++++++++++++--- 2 files changed, 82 insertions(+), 19 deletions(-) diff --git a/e107_core/shortcodes/batch/page_shortcodes.php b/e107_core/shortcodes/batch/page_shortcodes.php index 96076efdc..075a9190d 100644 --- a/e107_core/shortcodes/batch/page_shortcodes.php +++ b/e107_core/shortcodes/batch/page_shortcodes.php @@ -344,22 +344,42 @@ class cpage_shortcodes extends e_shortcode { $tp = e107::getParser(); - if($video = $tp->toVideo($this->var['menu_image'])) - { - return $video; - } - - if($parm == 'url') { - $img = $tp->thumbUrl($this->var['menu_image']); - return $img; + $img = ($tp->isVideo($this->var['menu_image'])) ? $tp->toVideo($this->var['menu_image'], array('thumb'=>'src')) : $tp->thumbUrl($this->var['menu_image']); + return $img; + } + + if($video = $tp->toVideo($this->var['menu_image'])) + { + return $video; } return $tp->toImage($this->var['menu_image'], $parm); - //return ""; } + + + function sc_cmenu_tab_active($parm=null) + { + if(!empty($this->var['cmenu_tab_active'])) + { + return 'active'; + } + + return null; + } + + function sc_cmenu_button_text($parm=null) + { + return (empty($this->var['menu_button_text'])) ? LAN_READ_MORE : $this->var['menu_button_text']; + } + + function sc_cmenu_button_url($parm=null) + { + return $this->sc_cmenuurl($parm); + } + function sc_cmenuicon($parm='') { diff --git a/e107_plugins/page/e_shortcode.php b/e107_plugins/page/e_shortcode.php index 66ac4d1c8..d2250e27f 100644 --- a/e107_plugins/page/e_shortcode.php +++ b/e107_plugins/page/e_shortcode.php @@ -133,19 +133,33 @@ class page_shortcodes extends e_shortcode * Render All visible Menus from a specific chapter. * @param null $parm * @example {CHAPTER_MENUS: name=chapter-sef-url} + * @example {CHAPTER_MENUS: name=chapter-sef-url&template=xxxxx} * @return string */ function sc_chapter_menus($parm=null) { $tp = e107::getParser(); - $query = "SELECT * FROM #page AS p LEFT JOIN #page_chapters as ch ON p.page_chapter=ch.chapter_id WHERE ch.chapter_visibility IN (" . USERCLASS_LIST . ") AND p.menu_class IN (" . USERCLASS_LIST . ") AND ch.chapter_sef = '" . $tp->filter($parm['name'],'str') . "' ORDER BY p.page_order ASC "; $text = ''; + $start = ''; - if(!$pageArray = e107::getDb()->retrieve($query, true)) + $sef = $tp->filter($parm['name'],'str'); + + $registry = 'e_shortcode/sc_chapter_menus/'.$sef; + + if(!$pageArray = e107::getRegistry($registry)) { - e107::getDebug()->log('{CHAPTER_MENUS: name='.$parm['name'].'} failed.
Query: '.$query); - return null; + $query = "SELECT * FROM #page AS p LEFT JOIN #page_chapters as ch ON p.page_chapter=ch.chapter_id WHERE ch.chapter_visibility IN (" . USERCLASS_LIST . ") AND p.menu_class IN (" . USERCLASS_LIST . ") AND ch.chapter_sef = '" . $sef . "' ORDER BY p.page_order ASC "; + + e107::getDebug()->log("Loading page Chapters"); + + if(!$pageArray = e107::getDb()->retrieve($query, true)) + { + e107::getDebug()->log('{CHAPTER_MENUS: name='.$parm['name'].'} failed.
Query: '.$query); + return null; + } + + e107::setRegistry($registry, $pageArray); } $template = e107::getCoreTemplate('menu',null,true,true); @@ -154,19 +168,48 @@ class page_shortcodes extends e_shortcode $sc->setVars($pageArray[0]); $tpl = varset($pageArray[0]['menu_template'],'default'); // use start template from first row. - $start = $tp->parseTemplate($template[$tpl]['start'],true,$sc); - - foreach($pageArray as $row) + if(!empty($parm['template'])) { - $tpl = varset($row['menu_template'],'default'); - $sc->setVars($row); - $text .= $tp->parseTemplate($template[$tpl]['body'],true,$sc); + $tpl = $parm['template']; + $start .= ""; + + if(empty($template[$tpl])) + { + e107::getDebug()->log('{CHAPTER_MENUS: '.http_build_query($parm).'} has an empty template.'); + } } + $active = varset($parm['active'],1); + + $start .= $tp->parseTemplate($template[$tpl]['start'],true,$sc); + + $c=1; + foreach($pageArray as $row) + { + $row['cmenu_tab_active'] = ($c === $active) ? true : false; + + if(empty($parm['template'])) + { + $tpl = varset($row['menu_template'],'default'); + } + + $sc->setVars($row); + + $text .= $tp->parseTemplate($template[$tpl]['body'],true,$sc); + $c++; + } + $end = $tp->parseTemplate($template[$tpl]['end'],true,$sc); + $end .= ""; + + if(!empty($parm['template'])) + { + $end .= ""; + } + if(!empty($text)) { return $start . $text . $end;