diff --git a/e107_handlers/e107_class.php b/e107_handlers/e107_class.php index ec060bc4a..64f951c45 100644 --- a/e107_handlers/e107_class.php +++ b/e107_handlers/e107_class.php @@ -1640,7 +1640,42 @@ class e107 return self::getRegistry('admin/ui/dispatcher'); } + /** + * Retrieves config() from addons such as e_url.php, e_cron.php, e_sitelink.php + * FIXME ASAP extremely bad standard e.g. e_sitelink.php -> plugin_sitelinks. Should be e_sitelinks.php -> plugin_sitelinks or e_sitelink.php -> plugin_sitelink + * FIXME override from e.g. core/override/addons/ + * + * @param string $pluginName e.g. faq, page + * @param string $addonName eg. e_cron, e_url, e_module + * @param mixed $className [optional] true - use default name, false - no object is returned (include only), any string will be used as class name + * @return none + */ + public static function getAddon($pluginName, $addonName, $className = true) + { + $filename = $addonName; // e.g. 'e_cron'; + + // fixme, temporary adding 's' to className, should be core fixed, better naming + if(true === $className) $className = $pluginName.'_'.substr($addonName, 2).'s'; // remove 'e_' + $elist = self::getPref($filename.'_list'); + if(!isset($elist[$pluginName])) return null; + + // TODO override check comes here + $path = e_PLUGIN.$pluginName.'/'.$filename.'.php'; + // e.g. include e_module, e_meta etc + if(false === $className) return include_once($path); + + if(!class_exists($className, false)) + { + include_once($path); + } + + if(!class_exists($className, false)) + { + return null; + } + return new $className; + } /** * Retrieves config() from addons such as e_url.php, e_cron.php, e_sitelink.php diff --git a/e107_handlers/sitelinks_class.php b/e107_handlers/sitelinks_class.php index 60a5f01aa..e2c560ea7 100644 --- a/e107_handlers/sitelinks_class.php +++ b/e107_handlers/sitelinks_class.php @@ -1490,7 +1490,10 @@ class e_navigation */ public function isActive($data='') { - $dbLink = e_HTTP. e107::getParser()->replaceConstants($data['link_url'], TRUE, TRUE);; + // already checked by compile() or external source + if(isset($data['link_active'])) return $data['link_active']; + + $dbLink = e_HTTP. e107::getParser()->replaceConstants($data['link_url'], TRUE, TRUE); if(E107_DBG_PATH) { diff --git a/e107_plugins/page/e_shortcode.php b/e107_plugins/page/e_shortcode.php index 8a88ed63d..4a9828d4e 100644 --- a/e107_plugins/page/e_shortcode.php +++ b/e107_plugins/page/e_shortcode.php @@ -14,17 +14,18 @@ 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. { - require_once(e_PLUGIN."page/e_sitelink.php"); - - $links = new page_sitelinks; + // FIXME sitelink class should be page_sitelink + $links = e107::getAddon('page', 'e_sitelink', 'page_sitelinks'); $data = $links->pageNav($parm); - $template = e107::getCoreTemplate('page','nav'); + $template = e107::getCoreTemplate('page','nav'); + if(isset($data['title']) && !vartrue($template['noAutoTitle'])) + { + $data = $data['body']; + } return e107::getNav()->render($data, $template) ; } } - -?> \ No newline at end of file diff --git a/e107_plugins/page/e_sitelink.php b/e107_plugins/page/e_sitelink.php index b21c4185e..22cf86744 100644 --- a/e107_plugins/page/e_sitelink.php +++ b/e107_plugins/page/e_sitelink.php @@ -38,15 +38,32 @@ class page_sitelinks // include plugin-folder in the name. $sql = e107::getDb(); $sublinks = array(); - $arr = array(); + $arr = array(); + + // find the chapter if required + if(vartrue($options['page']) && !vartrue($options['chapter'])) + { + $options['chapter'] = $sql->retrieve('page', 'page_chapter', 'page_id='.intval($options['page'])); + } $query = "SELECT * FROM #page WHERE "; - $query .= vartrue($options['chapter']) ? "page_chapter = ".intval($options['chapter']) : 1; + if(vartrue($options['chapter'])) + { + $query .= "page_chapter = ".intval($options['chapter']); + } + elseif(vartrue($options['book'])) + { + $query .= "page_chapter IN (SELECT chapter_id FROM #page_chapters WHERE chapter_parent=".intval($options['book']).")"; + } + else + { + $query .= 1; + } $query .= " ORDER BY page_order"; - // $query .= vartrue($options['limit']) ? " LIMIT ".intval($options['limit']) : ""; $data = $sql->retrieve($query, true); $_pdata = array(); + foreach($data as $row) { $pid = $row['page_chapter']; @@ -60,29 +77,35 @@ class page_sitelinks // include plugin-folder in the name. 'link_order' => $row['page_order'], 'link_parent' => $row['page_chapter'], 'link_open' => '', - 'link_class' => intval($row['page_class']) + 'link_class' => intval($row['page_class']), + 'link_active' => ($options['page'] && $row['page_id'] == $options['page']), ); } - - // $filter = vartrue($options['book']) ? "chapter_id = ".intval($options['book']) : 1; $filter = 1; if(vartrue($options['chapter'])) { //$filter = "chapter_id > ".intval($options['chapter']); + $title = $sql->retrieve('page_chapters', 'chapter_name', 'chapter_id='.intval($options['chapter'])); $outArray = array(); - return e107::getNav()->compile($_pdata, $outArray, $options['chapter']); + if(!$title) return e107::getNav()->compile($_pdata, $outArray, $options['chapter']); + return array('title' => $title, 'body' => e107::getNav()->compile($_pdata, $outArray, $options['chapter'])); } + $parent = 0; + $title = false; if(vartrue($options['book'])) { - $filter = "chapter_id > ".intval($options['book']); + // XXX discuss the idea here + //$filter = "chapter_id > ".intval($options['book']); + $filter = "chapter_parent = ".intval($options['book']); + $parent = intval($options['book']); + $title = $sql->retrieve('page_chapters', 'chapter_name', 'chapter_id='.intval($options['book'])); } $books = $sql->retrieve("SELECT * FROM #page_chapters WHERE ".$filter." ORDER BY chapter_order ASC" , true); - foreach($books as $row) { @@ -100,31 +123,17 @@ class page_sitelinks // include plugin-folder in the name. 'link_parent' => $row['chapter_parent'], 'link_open' => '', 'link_class' => 0, - 'link_sub' => varset($sublinks[$row['chapter_id']]) + 'link_sub' => varset($sublinks[$row['chapter_id']]), + 'link_active' => false, ); - - $parent = vartrue($options['book']) ? intval($row['chapter_parent']) : 0; } - - // print_a($arr); - // echo "

Compiled

"; $outArray = array(); $ret = e107::getNav()->compile($arr, $outArray, $parent); - - // print_a($ret); - - - // $mes = e107::getMessage(); - // $mes->addDebug( print_a($ret,true)); - return $ret; + if(!$title) return $ret; + return array('title' => $title, 'body' => $ret); } - } - - - -?> \ No newline at end of file diff --git a/e107_plugins/page/page_navigation_menu.php b/e107_plugins/page/page_navigation_menu.php index 12a0f9210..968fbd2d2 100644 --- a/e107_plugins/page/page_navigation_menu.php +++ b/e107_plugins/page/page_navigation_menu.php @@ -12,7 +12,7 @@ if (!defined('e107_INIT')) { exit; } $template = e107::getCoreTemplate('page','nav'); -// auto mode - detect the current location +### Auto mode - detect the current location if(empty($parm)) { $request = e107::getRegistry('core/pages/request'); @@ -37,8 +37,18 @@ if(empty($parm)) if($parm) $parm = http_build_query($parm); } -$text = e107::getParser()->parseTemplate("{PAGE_NAVIGATION={$parm}}", true); +### Retrieve +$links = e107::getAddon('page', 'e_sitelink', 'page_sitelinks'); +$data = $links->pageNav($parm); +if(isset($data['title']) && !vartrue($template['noAutoTitle'])) +{ + // use chapter title + $template['caption'] = $data['title']; + $data = $data['body']; +} +$text = e107::getNav()->render($data, $template) ; +### Render e107::getRender()->tablerender($template['caption'], $text, 'page-navigation-menu'); ?> \ No newline at end of file