1
0
mirror of https://github.com/e107inc/e107.git synced 2025-07-29 02:40:25 +02:00

Support for class attribute. {NAVIGATION: class=xxxx}

Class value in navigation template: {NAV_CLASS}
Navigation shortcodes now in their own file.
This commit is contained in:
Cameron
2020-12-27 12:46:37 -08:00
parent 6ed9ad3e0d
commit 71c5be17ea
3 changed files with 353 additions and 320 deletions

View File

@@ -0,0 +1,336 @@
<?php
/**
* Navigation Shortcodes
*
* @todo SEF
*/
class navigation_shortcodes extends e_shortcode
{
public $template;
public $counter;
public $active;
public $depth = 0;
public $navClass;
function sc_nav_class($parm = null)
{
return $this->navClass;
}
/**
*
* @return string 'active' on the active link.
* @example {LINK_ACTIVE}
*/
function sc_link_active($parm = '')
{
if($this->active == true)
{
return 'active';
}
// check if it's the first link.. (eg. anchor mode) and nothing activated.
return ($this->counter == 1) ? 'active' : '';
}
/**
* Return the primary_id number for the current link
*
* @return integer
*/
function sc_link_id($parm = null)
{
return (int) $this->var['link_id'];
}
function sc_link_depth($parm = null)
{
unset($parm);
return isset($this->var['link_depth']) ? (int) $this->var['link_depth'] : $this->depth;
}
function setDepth($val)
{
$this->depth = (int) $val;
}
/**
* Return the name of the current link
*
* @return string
* @example {LINK_NAME}
*/
function sc_link_name($parm = null)
{
if(empty($this->var['link_name']))
{
return null;
}
if(strpos($this->var['link_name'], 'submenu.') === 0) // BC Fix.
{
list($tmp, $tmp2, $link) = explode('.', $this->var['link_name'], 3);
unset($tmp, $tmp2);
}
else
{
$link = $this->var['link_name'];
}
return e107::getParser()->toHTML($link, false, 'defs');
}
/**
* Return the parent of the current link
*
* @return integer
*/
function sc_link_parent($parm = null)
{
return (int) $this->var['link_parent'];
}
function sc_link_identifier($parm = null)
{
return isset($this->var['link_identifier']) ? $this->var['link_identifier'] : '';
}
/**
* Return the URL of the current link
*
* @return string
*/
function sc_link_url($parm = null)
{
$tp = e107::getParser();
if(!empty($this->var['link_owner']) && !empty($this->var['link_sefurl']))
{
return e107::url($this->var['link_owner'], $this->var['link_sefurl']);
}
if(strpos($this->var['link_url'], e_HTTP) === 0)
{
$url = "{e_BASE}" . substr($this->var['link_url'], strlen(e_HTTP));
}
elseif($this->var['link_url'][0] !== "{" && strpos($this->var['link_url'], "://") === false)
{
$url = "{e_BASE}" . $this->var['link_url']; // Add e_BASE to links like: 'news.php' or 'contact.php'
}
else
{
$url = $this->var['link_url'];
}
$url = $tp->replaceConstants($url, 'full', true);
if(strpos($url, "{") !== false)
{
$url = $tp->parseTemplate($url, true); // BC Fix shortcode in URL support - dynamic urls for multilanguage.
}
return $url;
}
/*
function sc_link_sub_oversized($parm='')
{
$count = count($this->var['link_sub']);
if(!empty($parm) && $count > $parm)
{
return 'oversized';
}
return $count;
}
*/
/**
* Returns only the anchor target in the URL if one is found.
*
* @param array $parm
* @return null|string
*/
function sc_link_target($parm = null)
{
if(strpos($this->var['link_url'], '#') !== false)
{
list($tmp, $segment) = explode('#', $this->var['link_url'], 2);
return '#' . $segment;
}
return '#';
}
function sc_link_open($parm = '')
{
$type = $this->var['link_open'] ? (int) $this->var['link_open'] : 0;
### 0 - same window, 1 - target blank, 4 - 600x400 popup, 5 - 800x600 popup
### TODO - JS popups (i.e. bootstrap)
switch($type)
{
case 1:
return ' target="_blank"';
break;
case 4:
return " onclick=\"open_window('" . $this->var['link_url'] . "',600,400); return false;\"";
break;
case 5:
return " onclick=\"open_window('" . $this->var['link_url'] . "',800,600); return false;\"";
break;
}
return '';
}
/**
* @deprecated - Use {LINK_ICON} instead.
*/
function sc_link_image($parm = '')
{
trigger_error('<b>{LINK_IMAGE} is deprecated. Use {LINK_ICON} instead</b>', E_USER_DEPRECATED); // NO LAN
return $this->sc_link_icon($parm);
}
/**
* Return the link icon of the current link
*
* @return string
*/
function sc_link_icon($parm = '')
{
$tp = e107::getParser();
if(empty($this->var['link_button']))
{
return '';
}
// if($icon = $tp->toGlyph($this->var['link_button']))
// {
// return $icon;
// }
// else
{
//$path = e107::getParser()->replaceConstants($this->var['link_button'], 'full', TRUE);
return $tp->toIcon($this->var['link_button'], array('fw' => true, 'space' => ' ', 'legacy' => "{e_IMAGE}icons/"));
// return "<img class='icon' src='".$path."' alt='' />";
}
}
/**
* Return the link description of the current link
*
* @return string
*/
function sc_link_description($parm = '')
{
$toolTipEnabled = e107::pref('core', 'linkpage_screentip', false);
if($toolTipEnabled == false || empty($this->var['link_description']))
{
return null;
}
return e107::getParser()->toAttribute($this->var['link_description']);
}
/**
* Return the parsed sublinks of the current link
*
* @return string
*/
function sc_link_sub($parm = '')
{
if(empty($this->var['link_sub']))
{
return false;
}
if(is_string($this->var['link_sub'])) // html override option.
{
// e107::getDebug()->log($this->var);
return $this->var['link_sub'];
}
$this->depth++;
// Assume it's an array.
$startTemplate = !empty($this->var['link_sub'][0]['link_sub']) && isset($this->template['submenu_lowerstart']) ? $this->template['submenu_lowerstart'] : $this->template['submenu_start'];
$endTemplate = !empty($this->var['link_sub'][0]['link_sub']) && isset($this->template['submenu_lowerstart']) ? $this->template['submenu_lowerend'] : $this->template['submenu_end'];
$text = e107::getParser()->parseTemplate(str_replace('{LINK_SUB}', '', $startTemplate), true, $this);
foreach($this->var['link_sub'] as $val)
{
$active = (e107::getNav()->isActive($val, $this->activeSubFound, true)) ? "_active" : "";
$this->setVars($val); // isActive is allowed to alter data
$tmpl = !empty($val['link_sub']) ? varset($this->template['submenu_loweritem' . $active]) : varset($this->template['submenu_item' . $active]);
$text .= e107::getParser()->parseTemplate($tmpl, true, $this);
if($active)
{
$this->activeSubFound = true;
}
}
$text .= e107::getParser()->parseTemplate(str_replace('{LINK_SUB}', '', $endTemplate), true, $this);
return $text;
}
/**
* Return a generated anchor for the current link.
*
* @param unused
* @return string - a generated anchor for the current link.
* @example {LINK_ANCHOR}
*/
function sc_link_anchor($parm = '')
{
return $this->var['link_name'] ? '#' . e107::getForm()->name2id($this->var['link_name']) : '';
}
}

View File

@@ -1,13 +1,13 @@
<?php
/**
* @param null $parm
* @param string ['type'] main|side|footer|alt|alt5|alt6 (the data)
* @param string ['layout'] main|side|footer|alt|alt5|alt6| or custom template key. (the template)
* @return string
*/
function navigation_shortcode($parm=null)
/**
* @param null $parm
* @param string ['type'] main|side|footer|alt|alt5|alt6 (the data)
* @param string ['layout'] main|side|footer|alt|alt5|alt6| or custom template key. (the template)
* @return string
*/
function navigation_shortcode($parm=null)
{
$types = array(
'main' => 1,
@@ -45,9 +45,9 @@
$nav = e107::getNav();
$template = e107::getCoreTemplate('navigation', $tmpl);
$data = $nav->initData($category,$parm);
$data = $nav->initData($category, $parm);
return $nav->render($data, $template);
return $nav->render($data, $template, $parm);
}

View File

@@ -1632,7 +1632,7 @@ i.e-cat_users-32{ background-position: -555px 0; width: 32px; height: 32px; }
/**
* TODO Cache
*/
public function render($data, $template, $useCache = true)
public function render($data, $template, $opts = array())
{
if(empty($data) || empty($template) || !is_array($template))
{
@@ -1641,7 +1641,13 @@ i.e-cat_users-32{ background-position: -555px 0; width: 32px; height: 32px; }
/** @var navigation_shortcodes $sc */
$sc = e107::getScBatch('navigation');
$sc->template = $template;
$sc->template = $template;
if(!empty($opts['class']))
{
$sc->navClass = $opts['class'];
}
$head = e107::getParser()->parseTemplate($template['start'],true);
$foot = e107::getParser()->parseTemplate($template['end'],true);
$ret = "";
@@ -1923,312 +1929,3 @@ i.e-cat_users-32{ background-position: -555px 0; width: 32px; height: 32px; }
return false;
}
}
/**
* Navigation Shortcodes
* @todo SEF
*/
class navigation_shortcodes extends e_shortcode
{
public $template;
public $counter;
public $active;
public $depth = 0;
/**
*
* @return string 'active' on the active link.
* @example {LINK_ACTIVE}
*/
function sc_link_active($parm='')
{
if($this->active == true)
{
return 'active';
}
// check if it's the first link.. (eg. anchor mode) and nothing activated.
return ($this->counter ==1) ? 'active' : '';
}
/**
* Return the primary_id number for the current link
* @return integer
*/
function sc_link_id($parm=null)
{
return (int) $this->var['link_id'];
}
function sc_link_depth($parm=null)
{
unset($parm);
return isset($this->var['link_depth']) ? (int) $this->var['link_depth'] : $this->depth;
}
function setDepth($val)
{
$this->depth = (int) $val;
}
/**
* Return the name of the current link
* @return string
* @example {LINK_NAME}
*/
function sc_link_name($parm=null)
{
if(empty($this->var['link_name']))
{
return null;
}
if(strpos($this->var['link_name'], 'submenu.') === 0) // BC Fix.
{
list($tmp,$tmp2,$link) = explode('.',$this->var['link_name'],3);
unset($tmp,$tmp2);
}
else
{
$link = $this->var['link_name'];
}
return e107::getParser()->toHTML($link, false,'defs');
}
/**
* Return the parent of the current link
* @return integer
*/
function sc_link_parent($parm=null)
{
return (int) $this->var['link_parent'];
}
function sc_link_identifier($parm=null)
{
return isset($this->var['link_identifier']) ? $this->var['link_identifier'] : '';
}
/**
* Return the URL of the current link
* @return string
*/
function sc_link_url($parm=null)
{
$tp = e107::getParser();
if(!empty($this->var['link_owner']) && !empty($this->var['link_sefurl']))
{
return e107::url($this->var['link_owner'],$this->var['link_sefurl']);
}
if(strpos($this->var['link_url'], e_HTTP) === 0)
{
$url = "{e_BASE}".substr($this->var['link_url'], strlen(e_HTTP));
}
elseif($this->var['link_url'][0] !== "{" && strpos($this->var['link_url'],"://")===false)
{
$url = "{e_BASE}".$this->var['link_url']; // Add e_BASE to links like: 'news.php' or 'contact.php'
}
else
{
$url = $this->var['link_url'];
}
$url = $tp->replaceConstants($url, 'full', TRUE);
if(strpos($url,"{") !== false)
{
$url = $tp->parseTemplate($url, TRUE); // BC Fix shortcode in URL support - dynamic urls for multilanguage.
}
return $url;
}
/*
function sc_link_sub_oversized($parm='')
{
$count = count($this->var['link_sub']);
if(!empty($parm) && $count > $parm)
{
return 'oversized';
}
return $count;
}
*/
/**
* Returns only the anchor target in the URL if one is found.
* @param array $parm
* @return null|string
*/
function sc_link_target($parm=null)
{
if(strpos($this->var['link_url'],'#')!==false)
{
list($tmp,$segment) = explode('#',$this->var['link_url'],2);
return '#'.$segment;
}
return '#';
}
function sc_link_open($parm = '')
{
$type = $this->var['link_open'] ? (int) $this->var['link_open'] : 0;
### 0 - same window, 1 - target blank, 4 - 600x400 popup, 5 - 800x600 popup
### TODO - JS popups (i.e. bootstrap)
switch($type)
{
case 1:
return ' target="_blank"';
break;
case 4:
return " onclick=\"open_window('".$this->var['link_url']."',600,400); return false;\"";
break;
case 5:
return " onclick=\"open_window('".$this->var['link_url']."',800,600); return false;\"";
break;
}
return '';
}
/**
* @deprecated - Use {LINK_ICON} instead.
*/
function sc_link_image($parm='')
{
trigger_error('<b>{LINK_IMAGE} is deprecated. Use {LINK_ICON} instead</b>', E_USER_DEPRECATED); // NO LAN
return $this->sc_link_icon($parm);
}
/**
* Return the link icon of the current link
* @return string
*/
function sc_link_icon($parm='')
{
$tp = e107::getParser();
if (empty($this->var['link_button']))
{
return '';
}
// if($icon = $tp->toGlyph($this->var['link_button']))
// {
// return $icon;
// }
// else
{
//$path = e107::getParser()->replaceConstants($this->var['link_button'], 'full', TRUE);
return $tp->toIcon($this->var['link_button'],array('fw'=>true, 'space'=>' ', 'legacy'=>"{e_IMAGE}icons/"));
// return "<img class='icon' src='".$path."' alt='' />";
}
}
/**
* Return the link description of the current link
* @return string
*/
function sc_link_description($parm='')
{
$toolTipEnabled = e107::pref('core', 'linkpage_screentip', false);
if($toolTipEnabled == false || empty($this->var['link_description']))
{
return null;
}
return e107::getParser()->toAttribute($this->var['link_description']);
}
/**
* Return the parsed sublinks of the current link
* @return string
*/
function sc_link_sub($parm='')
{
if(empty($this->var['link_sub']))
{
return false;
}
if(is_string($this->var['link_sub'])) // html override option.
{
// e107::getDebug()->log($this->var);
return $this->var['link_sub'];
}
$this->depth++;
// Assume it's an array.
$startTemplate = !empty($this->var['link_sub'][0]['link_sub']) && isset($this->template['submenu_lowerstart']) ? $this->template['submenu_lowerstart'] : $this->template['submenu_start'];
$endTemplate = !empty($this->var['link_sub'][0]['link_sub']) && isset($this->template['submenu_lowerstart']) ? $this->template['submenu_lowerend'] : $this->template['submenu_end'];
$text = e107::getParser()->parseTemplate(str_replace('{LINK_SUB}', '', $startTemplate), true, $this);
foreach($this->var['link_sub'] as $val)
{
$active = (e107::getNav()->isActive($val, $this->activeSubFound, true)) ? "_active" : "";
$this->setVars($val); // isActive is allowed to alter data
$tmpl = !empty($val['link_sub']) ? varset($this->template['submenu_loweritem'.$active]) : varset($this->template['submenu_item'.$active]);
$text .= e107::getParser()->parseTemplate($tmpl, TRUE, $this);
if($active)
{
$this->activeSubFound = true;
}
}
$text .= e107::getParser()->parseTemplate(str_replace('{LINK_SUB}', '', $endTemplate), true, $this);
return $text;
}
/**
* Return a generated anchor for the current link.
* @param unused
* @return string - a generated anchor for the current link.
* @example {LINK_ANCHOR}
*/
function sc_link_anchor($parm='')
{
return $this->var['link_name'] ? '#'.e107::getForm()->name2id($this->var['link_name']) : '';
}
}