mirror of
https://github.com/e107inc/e107.git
synced 2025-08-01 20:30:39 +02:00
Even more smarter page navigation menu;
Introduced e107::getAddon(); Upcoming addon class naming standards discussion
This commit is contained in:
@@ -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
|
||||
|
@@ -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)
|
||||
{
|
||||
|
@@ -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) ;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@@ -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 "<h3>Compiled</h3>";
|
||||
$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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
?>
|
@@ -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');
|
||||
|
||||
?>
|
Reference in New Issue
Block a user