mirror of
https://github.com/e107inc/e107.git
synced 2025-08-05 14:17:49 +02:00
Fix for dynamic menus. Simplified recursion. Lower-link template added and ready for active-link detection routine.
This commit is contained in:
@@ -11,14 +11,11 @@ function navigation_shortcode($parm='')
|
|||||||
|
|
||||||
$category = varset($types[$parm], 1);
|
$category = varset($types[$parm], 1);
|
||||||
$tmpl = vartrue($parm, 'main');
|
$tmpl = vartrue($parm, 'main');
|
||||||
|
|
||||||
//$data = e107::getNav()->getData($cat);
|
|
||||||
|
|
||||||
//return e107::getNav()->render($data, $tmpl);
|
|
||||||
$nav = e107::getNav();
|
$nav = e107::getNav();
|
||||||
|
|
||||||
$template = e107::getCoreTemplate('navigation', $tmpl);
|
$template = e107::getCoreTemplate('navigation', $tmpl);
|
||||||
$data = $nav->collection($category);
|
$data = $nav->initData($category);
|
||||||
|
// $data = $nav->collection($category);
|
||||||
|
|
||||||
return $nav->render($data, $template);
|
return $nav->render($data, $template);
|
||||||
}
|
}
|
||||||
|
@@ -63,7 +63,12 @@ $NAVIGATION_TEMPLATE['main']['submenu_item'] = '
|
|||||||
</li>
|
</li>
|
||||||
';
|
';
|
||||||
|
|
||||||
|
$NAVIGATION_TEMPLATE['main']['submenu_loweritem'] = '
|
||||||
|
<li role="menuitem" class="dropdown-submenu">
|
||||||
|
<a href="{LINK_URL}">{LINK_IMAGE}{LINK_NAME}</a>
|
||||||
|
{LINK_SUB}
|
||||||
|
</li>
|
||||||
|
';
|
||||||
|
|
||||||
$NAVIGATION_TEMPLATE['main']['submenu_item_active'] = '
|
$NAVIGATION_TEMPLATE['main']['submenu_item_active'] = '
|
||||||
<li role="menuitem" class="active">
|
<li role="menuitem" class="active">
|
||||||
|
@@ -557,13 +557,13 @@ class e_navigation
|
|||||||
* Structure: $data[category][parentId] = array(Link Data)
|
* Structure: $data[category][parentId] = array(Link Data)
|
||||||
* @var array DB data
|
* @var array DB data
|
||||||
*/
|
*/
|
||||||
var $data = null;
|
// var $data = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Structure: $indeces[flat][link_id] = link_parent; $indeces[ordered][link_id] = link_order
|
* Structure: $indeces[flat][link_id] = link_parent; $indeces[ordered][link_id] = link_order
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
var $indeces = null;
|
// var $indeces = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Structure $this->_md5cache[$category] = md5HASH
|
* Structure $this->_md5cache[$category] = md5HASH
|
||||||
@@ -1220,6 +1220,13 @@ class e_navigation
|
|||||||
return 'nomd5_sitelinks_';
|
return 'nomd5_sitelinks_';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// UNUSED
|
||||||
protected function retrieveAddon($id, $function, $orderStart = 0)
|
protected function retrieveAddon($id, $function, $orderStart = 0)
|
||||||
{
|
{
|
||||||
list($path, $method) = explode('::', $function);
|
list($path, $method) = explode('::', $function);
|
||||||
@@ -1254,6 +1261,7 @@ class e_navigation
|
|||||||
}
|
}
|
||||||
|
|
||||||
// FIXME syscache
|
// FIXME syscache
|
||||||
|
/*
|
||||||
protected function initData($category)
|
protected function initData($category)
|
||||||
{
|
{
|
||||||
$sql = e107::getDb('sqlSiteLinks');
|
$sql = e107::getDb('sqlSiteLinks');
|
||||||
@@ -1274,6 +1282,7 @@ class e_navigation
|
|||||||
$this->data[$category][$link['link_parent']][$link['link_id']] = $link;
|
$this->data[$category][$link['link_parent']][$link['link_id']] = $link;
|
||||||
$this->indeces['flat'][$link['link_id']] = $link['link_parent'];
|
$this->indeces['flat'][$link['link_id']] = $link['link_parent'];
|
||||||
$this->indeces['ordered'][$link['link_id']] = $link['link_order'];
|
$this->indeces['ordered'][$link['link_id']] = $link['link_order'];
|
||||||
|
|
||||||
if(!empty($link['link_function']))
|
if(!empty($link['link_function']))
|
||||||
{
|
{
|
||||||
$this->indeces['dynamic'][$link['link_id']] = $link['link_function'];
|
$this->indeces['dynamic'][$link['link_id']] = $link['link_function'];
|
||||||
@@ -1288,12 +1297,13 @@ class e_navigation
|
|||||||
|
|
||||||
// cache it
|
// cache it
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
/**
|
/**
|
||||||
* Retrive link data
|
* Retrive link data
|
||||||
* We retrieve ALWAYS the whole data if there is missing cached data
|
* We retrieve ALWAYS the whole data if there is missing cached data
|
||||||
* FIXME syscache
|
* FIXME syscache
|
||||||
*/
|
*/
|
||||||
|
/*
|
||||||
public function retrieve($category = 1, $parent = 0)
|
public function retrieve($category = 1, $parent = 0)
|
||||||
{
|
{
|
||||||
$cache = e107::getCache();
|
$cache = e107::getCache();
|
||||||
@@ -1321,7 +1331,7 @@ class e_navigation
|
|||||||
|
|
||||||
return $this->data[$category][$parent];
|
return $this->data[$category][$parent];
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
/**
|
/**
|
||||||
* Prepare site links data for the renderer
|
* Prepare site links data for the renderer
|
||||||
* @todo maybe some kind of dead loop protection
|
* @todo maybe some kind of dead loop protection
|
||||||
@@ -1335,6 +1345,7 @@ class e_navigation
|
|||||||
* @param bool $flat if true, sub-levels wont be processed
|
* @param bool $flat if true, sub-levels wont be processed
|
||||||
* @return array milti-level or flat navigation data
|
* @return array milti-level or flat navigation data
|
||||||
*/
|
*/
|
||||||
|
/*
|
||||||
public function collection($category = 1, $parent = 0, $flat = false)
|
public function collection($category = 1, $parent = 0, $flat = false)
|
||||||
{
|
{
|
||||||
$this->initData($category);
|
$this->initData($category);
|
||||||
@@ -1376,140 +1387,131 @@ class e_navigation
|
|||||||
|
|
||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
function render($data, $template, $useCache = true)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TODO Cache
|
||||||
|
*/
|
||||||
|
public function render($data, $template, $useCache = true)
|
||||||
{
|
{
|
||||||
if(empty($data) || empty($template) || !is_array($template)) return '';
|
if(empty($data) || empty($template) || !is_array($template)) return '';
|
||||||
|
|
||||||
$sc = e107::getScBatch('navigation');
|
$sc = e107::getScBatch('navigation');
|
||||||
$sc->template = $template;
|
$sc->template = $template;
|
||||||
|
|
||||||
$ret = $template['start'];
|
$ret = $template['start'];
|
||||||
|
|
||||||
|
|
||||||
foreach ($data as $_data)
|
foreach ($data as $_data)
|
||||||
{
|
{
|
||||||
$sc->setVars($_data);
|
$sc->setVars($_data);
|
||||||
$itemTmpl = count($_data['link_sub']) > 0 ? $template['item_submenu'] : $template['item'];
|
$active = ($this->isActive($_data)) ? "_active" : "";
|
||||||
|
$itemTmpl = count($_data['link_sub']) > 0 ? $template['item_submenu'.$active] : $template['item'.$active];
|
||||||
$ret .= e107::getParser()->parseTemplate($itemTmpl, TRUE);
|
$ret .= e107::getParser()->parseTemplate($itemTmpl, TRUE);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$ret .= $template['end'];
|
$ret .= $template['end'];
|
||||||
|
|
||||||
// FIXME $useCache
|
|
||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a standardized clean array structure for all links.
|
* --------------- CODE-EFFICIENT APPROACH -------------------------
|
||||||
|
* Less than 10 lines of code (once retrieve() is working)
|
||||||
|
* FIXME syscache
|
||||||
*/
|
*/
|
||||||
/*
|
public function initData($cat=1)
|
||||||
function getData($cat=1)
|
|
||||||
{
|
{
|
||||||
$sql = e107::getDb('sqlSiteLinks');
|
$sql = e107::getDb('sqlSiteLinks');
|
||||||
$ins = ($cat > 0) ? "link_category = ".intval($cat)." AND " : "";
|
$ins = ($cat > 0) ? "link_category = ".intval($cat)." AND " : "";
|
||||||
$query = "SELECT * FROM #links WHERE ".$ins." link_class IN (".USERCLASS_LIST.") ORDER BY link_order ASC";
|
$query = "SELECT * FROM #links WHERE ".$ins." link_class IN (".USERCLASS_LIST.") ORDER BY link_order,link_parent ASC";
|
||||||
|
|
||||||
$ret = array();
|
$ret = array();
|
||||||
|
$data = array();
|
||||||
|
|
||||||
if($sql->db_Select_gen($query))
|
// $data = $sql->retrieve($query,true); // FIXME $sql->retrieve() fails.
|
||||||
|
if($sql->gen($query))
|
||||||
{
|
{
|
||||||
while ($row = $sql->db_Fetch())
|
while ($row = $sql->db_Fetch())
|
||||||
{
|
|
||||||
|
|
||||||
if (isset($row['link_parent']) && $row['link_parent'] != 0)
|
|
||||||
{
|
|
||||||
$pid = $row['link_parent'];
|
|
||||||
// $ret[$id]['link_sub'][] = $row;
|
|
||||||
$sub['sub-'.$pid][] = $row;
|
|
||||||
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
$id = $row['link_id'];
|
$id = $row['link_id'];
|
||||||
$ret[$id] = $row;
|
$data [$id] = $row;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$outArray = array();
|
||||||
|
return $this->compile($data, $outArray);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compile Array Structure
|
||||||
|
*/
|
||||||
|
protected function compile(&$inArray, &$outArray, $pid = 0)
|
||||||
|
{
|
||||||
|
if(!is_array($inArray) || !is_array($outArray)){ return; }
|
||||||
|
|
||||||
|
foreach($inArray as $key => $val)
|
||||||
|
{
|
||||||
|
if($val['link_parent'] == $pid)
|
||||||
|
{
|
||||||
|
$val['link_sub'] = $this->isDynamic($val);
|
||||||
|
$this->compile($inArray, $val['link_sub'], $val['link_id']);
|
||||||
|
$outArray[] = $val;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $outArray;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check for Dynamic Function
|
||||||
|
*/
|
||||||
|
protected function isDynamic($row)
|
||||||
|
{
|
||||||
if(vartrue($row['link_function']))
|
if(vartrue($row['link_function']))
|
||||||
{
|
{
|
||||||
list($path,$method) = explode("::",$row['link_function']);
|
list($path,$method) = explode("::",$row['link_function']);
|
||||||
if(include_once(e_PLUGIN.$path."/e_sitelink.php"))
|
if(include_once(e_PLUGIN.$path."/e_sitelink.php"))
|
||||||
{
|
{
|
||||||
$class = $path."_sitelinks";
|
$class = $path."_sitelinks";
|
||||||
$sublinkArray = e107::callMethod($class,$method); //TODO Cache it.
|
if($sublinkArray = e107::callMethod($class,$method)) //TODO Cache it.
|
||||||
if(vartrue($sublinkArray))
|
|
||||||
{
|
{
|
||||||
$sub['sub-'.$id] = $sublinkArray;
|
return $sublinkArray;
|
||||||
//$ret[$id]['link_sub'] = $sublinkArray;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return array();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return $this->compile($ret, $sub);
|
|
||||||
|
|
||||||
return $ret;
|
|
||||||
|
|
||||||
}*/
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
function compile($ret, $sub)
|
|
||||||
{
|
|
||||||
$new = array();
|
|
||||||
|
|
||||||
foreach($ret as $k=>$v)
|
|
||||||
{
|
|
||||||
$new[$k] = $v;
|
|
||||||
$p = $v['link_id'];
|
|
||||||
if(isset($sub['sub-'.$p]))
|
|
||||||
{
|
|
||||||
$new[$k]['link_sub'] = $sub['sub-'.$p];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $new;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Render the Front-end Links. (and eventually the back-end too)
|
* TODO Active Link Detection;
|
||||||
* @param data array - see getData() above. Follows e107_links table format.
|
*
|
||||||
* @param template to use.
|
|
||||||
* TODO Support for side-menu templates and others.
|
|
||||||
*/
|
*/
|
||||||
/*
|
public function isActive($data='')
|
||||||
function render($data, $type = 'main')
|
|
||||||
{
|
{
|
||||||
$sc = e107::getScBatch('navigation');
|
return false;
|
||||||
$template = e107::getCoreTemplate('navigation', $type);
|
|
||||||
$sc->template = $template; // parse the template to the shortcodes. (sub menus)
|
|
||||||
|
|
||||||
$text = $template['start'];
|
|
||||||
|
|
||||||
foreach($data as $lnk)
|
|
||||||
{
|
|
||||||
$sc->setVars($lnk);
|
|
||||||
$item = varset($lnk['link_sub']) ? $template['item_submenu'] : $template['item'];
|
|
||||||
$text .= e107::getParser()->parseTemplate($item,TRUE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$text .= $template['end'];
|
|
||||||
|
|
||||||
return $text;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// TODO - 'active links', SEF etc.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// TODO SEF etc.
|
||||||
class navigation_shortcodes extends e_shortcode
|
class navigation_shortcodes extends e_shortcode
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -1548,7 +1550,9 @@ class navigation_shortcodes extends e_shortcode
|
|||||||
foreach($this->var['link_sub'] as $val)
|
foreach($this->var['link_sub'] as $val)
|
||||||
{
|
{
|
||||||
$this->setVars($val);
|
$this->setVars($val);
|
||||||
$text .= e107::getParser()->parseTemplate($this->template['submenu_item'], TRUE);
|
$active = (e107::getNav()->isActive($val)) ? "_active" : "";
|
||||||
|
$tmpl = (count($val['link_sub'])>0) ? $this->template['submenu_loweritem'] : $this->template['submenu_item'.$active];
|
||||||
|
$text .= e107::getParser()->parseTemplate($tmpl, TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
$text .= $this->template['submenu_end'];
|
$text .= $this->template['submenu_end'];
|
||||||
|
Reference in New Issue
Block a user