1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-12 17:44:37 +02:00

Issue #5473 - Optional sub-level navigation for plugins.

This commit is contained in:
camer0n
2025-04-18 18:10:51 -07:00
parent 65df4da999
commit d696a12672
5 changed files with 199 additions and 158 deletions

View File

@@ -296,31 +296,31 @@ $ADMIN_TEMPLATE['menu']['start'] = '
$ADMIN_TEMPLATE['menu']['button'] = '
<li>
<a class="link{LINK_CLASS}" {LINK_DATA} href="{LINK_URL}" {ID}{ONCLICK}><span class="e-tip" data-placement="right" title="{LINK_TEXT}">{LINK_IMAGE}</span><span class="sidebar-toggle-panel">&nbsp;{LINK_TEXT}{LINK_BADGE}</span></a>
<a class="link{LINK_CLASS}" {LINK_DATA} href="{LINK_URL}" {ID}{ONCLICK}><span class="e-tip" data-placement="right" title="{LINK_TEXT}">{LINK_IMAGE}</span><span class="sidebar-toggle-panel"> {LINK_TEXT}{LINK_BADGE}</span></a>
{SUB_MENU}
</li>
';
$ADMIN_TEMPLATE['menu']['button_active'] = '
<li class="active">
<a class="link-active{LINK_CLASS}" {LINK_DATA} href="{LINK_URL}" {ID}{ONCLICK}><span class="e-tip" data-placement="right" title="{LINK_TEXT}">{LINK_IMAGE}</span><span class="sidebar-toggle-panel">&nbsp;{LINK_TEXT}{LINK_BADGE}</span></a>
<a class="link-active{LINK_CLASS}" {LINK_DATA} href="{LINK_URL}" {ID}{ONCLICK}><span class="e-tip" data-placement="right" title="{LINK_TEXT}">{LINK_IMAGE}</span><span class="sidebar-toggle-panel"> {LINK_TEXT}{LINK_BADGE}</span></a>
{SUB_MENU}
</li>
';
$ADMIN_TEMPLATE['menu']['start_sub'] = '
<ul class="plugin-navigation-sub{SUB_CLASS}" {SUB_ID}>
<ul class="plugin-navigation-sub nav nav-pills nav-stacked nav-second-level collapse" id="sub-{LINK_ID}">
';
$ADMIN_TEMPLATE['menu']['button_sub'] = '
<li>
<a class="link" href="{LINK_URL}">&nbsp;{LINK_TEXT}{LINK_BADGE}</a>
{SUB_MENU}
<a class="link{LINK_CLASS}" {LINK_DATA} href="{LINK_URL}" {ID}><span class="e-tip" data-placement="right" title="{LINK_TEXT}">{LINK_IMAGE}</span><span class="sidebar-toggle-panel"> {LINK_TEXT}{LINK_BADGE}</span></a>
</li>
';
$ADMIN_TEMPLATE['menu']['button_active_sub'] = '
<li>
<a class="link-active" href="{LINK_URL}">&nbsp;{LINK_TEXT}{LINK_BADGE}</a>
{SUB_MENU}
<li class="active">
<a class="link-active{LINK_CLASS}" {LINK_DATA} href="{LINK_URL}" {ID}><span class="e-tip" data-placement="right" title="{LINK_TEXT}">{LINK_IMAGE}</span><span class="sidebar-toggle-panel"> {LINK_TEXT}{LINK_BADGE}</span></a>
</li>
';

View File

@@ -1570,169 +1570,206 @@ class e_admin_dispatcher
* Generic Admin Menu Generator
* @return string
*/
public function renderMenu()
{
public function renderMenu()
{
$tp = e107::getParser();
$var = array();
$selected = false;
foreach($this->adminMenu as $key => $val)
foreach ($this->adminMenu as $key => $val)
{
if(isset($val['perm']) && $val['perm']!=='' && !getperms($val['perm']))
if (isset($val['perm']) && $val['perm'] !== '' && !getperms($val['perm']))
{
continue;
}
$tmp = explode('/', trim($key, '/'), 3);
$isSubItem = count($tmp) === 3;
// sync with mode/route access
if(!$this->hasModeAccess($tmp[0]) || !$this->hasRouteAccess($tmp[0].'/'.varset($tmp[1])))
if ($isSubItem)
{
$parentKey = $tmp[0].'/'.$tmp[1];
if (!$this->hasModeAccess($tmp[0]) || !$this->hasRouteAccess($parentKey))
{
continue;
}
}
else
{
if (!$this->hasModeAccess($tmp[0]) || !$this->hasRouteAccess($tmp[0].'/'.varset($tmp[1])))
{
continue;
}
}
// custom 'selected' check
if(isset($val['selected']) && $val['selected'])
if (isset($val['selected']) && $val['selected'])
{
$selected = $val['selected'] === true ? $key : $val['selected'];
}
foreach ($val as $k=>$v)
$processedItem = $this->processMenuItem($val, $key, $tmp);
$processedItem['link_id'] = str_replace('/', '-', $key);
if ($isSubItem)
{
switch($k)
$parentKey = $tmp[0].'/'.$tmp[1];
if (!isset($var[$parentKey]))
{
case 'caption':
$k2 = 'text';
$v = defset($v, $v);
break;
case 'url':
$k2 = 'link';
$qry = (isset($val['query'])) ? $val['query'] : '?mode='.$tmp[0].'&amp;action='.$tmp[1];
$v = $tp->replaceConstants($v, 'abs').$qry;
break;
case 'uri':
$k2 = 'link';
$v = $tp->replaceConstants($v, 'abs');
if(!empty($v) && ($v === e_REQUEST_URI))
$var[$parentKey] = array(
'text' => 'Unknown',
'image_src' => e_navigation::guessMenuIcon($parentKey),
'link_id' => str_replace('/', '-', $parentKey) // Add link_id for parent
);
}
$var[$parentKey]['sub'][$tmp[2]] = $processedItem;
}
else
{
$selected = $key;
$var[$key] = $processedItem;
}
}
break;
case 'badge': // array('value'=> int, 'type'=>'warning');
$k2 = 'badge';
$v = (array) $v;
break;
case 'icon':
$k2 = 'image_src';
$v = (string) $v.'.glyph';
break;
default:
$k2 = $k;
break;
}
// Access check done above
// if($val['perm']!= null) // check perms
// {
// if(getperms($val['perm']))
// {
// $var[$key][$k2] = $v;
// }
// }
// else
// Handle links and collapse attributes
foreach ($var as $key => &$item)
{
$var[$key][$k2] = $v;
}
}
// guess an icon.
if(!isset($var[$key]['image_src']))
if (!empty($item['sub']))
{
$var[$key]['image_src'] = e_navigation::guessMenuIcon($key);
}
// TODO slide down menu options?
if(!vartrue($var[$key]['link']))
$item['link'] = '#';
$item['link_data'] = [
'data-toggle' => 'collapse',
'data-target' => '#sub-' . $item['link_id'],
'role' => 'button'
];
if ($selected === $key || strpos($selected, $key . '/') === 0)
{
$var[$key]['link'] = e_REQUEST_SELF.'?mode='.$tmp[0].'&amp;action='.$tmp[1]; // FIXME - URL based on $modes, remove url key
$item['link_data']['aria-expanded'] = 'true';
}
if(varset($val['tab']))
}
elseif (!isset($item['link']))
{
$var[$key]['link'] .= '&amp;tab=' .$val['tab'];
$tmp = explode('/', trim($key, '/'), 3);
$item['link'] = e_REQUEST_SELF.'?mode='.$tmp[0].'&action='.($tmp[1] ?? 'main');
}
}
/*$var[$key]['text'] = $val['caption'];
$var[$key]['link'] = (vartrue($val['url']) ? $tp->replaceConstants($val['url'], 'abs') : e_SELF).'?mode='.$tmp[0].'&action='.$tmp[1];
$var[$key]['perm'] = $val['perm']; */
if(!empty($val['modal']))
{
$var[$key]['link_class'] = ' e-modal';
if(!empty($val['modal-caption']))
{
$var[$key]['link_data'] = ['data-modal-caption' => $val['modal-caption']];
}
}
if(!empty($val['class']))
{
$var[$key]['link_class'] ?? '';
$var[$key]['link_class'] .= ' '.$val['class'];
}
}
if(empty($var))
if (empty($var))
{
return '';
}
// Debug $var
e107::getMessage()->addInfo(print_a($var, true));
$request = $this->getRequest();
if(!$selected)
if (!$selected)
{
$selected = $request->getMode() . '/' . $request->getAction();
if (isset($_GET['sub']) && !empty($_GET['sub']))
{
$selected .= '/' . $_GET['sub'];
}
}
$selected = vartrue($this->adminMenuAliases[$selected], $selected);
$icon = '';
if(!empty($this->adminMenuIcon))
if (!empty($this->adminMenuIcon))
{
$icon = e107::getParser()->toIcon($this->adminMenuIcon);
}
elseif(deftrue('e_CURRENT_PLUGIN'))
elseif (deftrue('e_CURRENT_PLUGIN'))
{
$icon = e107::getPlug()->load(e_CURRENT_PLUGIN)->getIcon(24);
}
$toggle = "<span class='e-toggle-sidebar'><!-- --></span>";
$var['_extras_'] = array('icon'=> $icon, 'return'=>true);
$var['_extras_'] = array('icon' => $icon, 'return' => true);
// $var['_icon_'] = $icon;
return $toggle . e107::getNav()->admin($this->menuTitle, $selected, $var);
}
return e107::getNav()->admin($this->menuTitle, $selected, $var);
private function processMenuItem($val, $key, $tmp)
{
$tp = e107::getParser();
$item = array();
foreach ($val as $k => $v)
{
switch ($k)
{
case 'caption':
$k2 = 'text';
$v = defset($v, $v);
break;
case 'url':
$k2 = 'link';
$qry = (isset($val['query'])) ? $val['query'] : '?mode='.$tmp[0].'&mp;action='.($tmp[1] ?? 'main').(isset($tmp[2]) ? '&sub='.$tmp[2] : '');
$v = $tp->replaceConstants($v, 'abs').$qry;
break;
case 'uri':
$k2 = 'link';
$v = $tp->replaceConstants($v, 'abs');
if (!empty($v) && ($v === e_REQUEST_URI))
{
$GLOBALS['selected'] = $key;
}
break;
case 'badge':
$k2 = 'badge';
$v = (array) $v;
break;
case 'icon':
$k2 = 'image_src';
$v = (string) $v . '.glyph'; // Ensure .glyph suffix
break;
default:
$k2 = $k;
break;
}
$item[$k2] = $v;
}
if (!isset($item['image_src']))
{
$item['image_src'] = e_navigation::guessMenuIcon($key); // Includes .glyph
}
if (!vartrue($item['link']))
{
$item['link'] = e_REQUEST_SELF.'?mode='.$tmp[0].'&amp;action='.($tmp[1] ?? 'main').(isset($tmp[2]) ? '&sub='.$tmp[2] : '');
}
if (varset($val['tab']))
{
$item['link'] .= '&amp;tab=' .$val['tab'];
}
if (!empty($val['modal']))
{
$item['link_class'] = ' e-modal';
if (!empty($val['modal-caption']))
{
$item['link_data'] = array_merge($item['link_data'] ?? [], ['data-modal-caption' => $val['modal-caption']]);
}
}
if (!empty($val['class']))
{
$var[$key]['link_class'] ?? '';
$var[$key]['link_class'] .= ' '.$val['class'];
}
return $item;
}
/**
* Render Help Text in <ul> format. XXX TODO
@@ -4910,7 +4947,7 @@ class e_admin_controller_ui extends e_admin_controller
* @param mixed $qryField Specific query field(s) to filter.
* @param mixed $isfilter Determines if a specific filter is applied.
* @param mixed $handleAction Custom action handler for the search process.
* @return string
* @return string|false
*/
public function _modifyListQrySearch(string|null $listQry, string $searchTerm, string $filterOptions, string $tablePath, string $tableFrom, string|null $primaryName, $raw, $orderField, $qryAsc, $forceFrom, int $qryFrom, $forceTo, int $perPage, $qryField, $isfilter, $handleAction)
{

View File

@@ -1432,7 +1432,7 @@ i.e-cat_users-32{ background-position: -555px 0; width: 32px; height: 32px; }
$temp = varset($tmpl[$tmplateKey]);
}
$replace['LINK_ID'] = $e107_vars[$act]['link_id'] ?? $rid;
$replace['LINK_TEXT'] = str_replace(" ", "&nbsp;", varset($e107_vars[$act]['text']));
$replace['LINK_DESCRIPTION'] = varset($e107_vars[$act]['description']);
@@ -1476,7 +1476,7 @@ i.e-cat_users-32{ background-position: -555px 0; width: 32px; height: 32px; }
$dataTmp = array();
foreach($e107_vars[$act]['link_data'] as $k=>$v)
{
$dataTmp[] = $k.'="'.$v.'"';
$dataTmp[] = $k.'="'.$v.'"'; // eg. data-toggle="modal" or data-target="#myModal"
}
$replace['LINK_DATA'] = implode(" ", $dataTmp); // $e107_vars[$act]['link_data']
@@ -1499,9 +1499,11 @@ i.e-cat_users-32{ background-position: -555px 0; width: 32px; height: 32px; }
if(!empty($e107_vars[$act]['sub']))
{
$replace['SUB_ID'] = $id ? " id='eplug-nav-{$rid}-sub'" : '';
$replace['LINK_CLASS'] = ' '.varset($e107_vars[$act]['link_class'], 'e-expandit');
$replace['LINK_CLASS'] = ' '.varset($e107_vars[$act]['link_class'], ''); // e-expandit removed.
$replace['SUB_CLASS'] = ' '.varset($e107_vars[$act]['sub_class'], 'e-hideme e-expandme');
$replace['SUB_MENU'] = $tp->parseTemplate($START_SUB, false, $replace);
$replace['SUB_MENU'] .= $this->admin(false, $active_page, $e107_vars[$act]['sub'], $tmpl, true, (isset($e107_vars[$act]['sort']) ? $e107_vars[$act]['sort'] : $sortlist));
$replace['SUB_MENU'] .= isset($tmpl['end_sub']) ? $tmpl['end_sub'] : '';

View File

@@ -46,9 +46,12 @@ class plugin_blank_admin extends e_admin_dispatcher
*/
protected $adminMenu = array(
'main/list' => array('caption'=> 'Manage', 'perm' => '0'),
'main/create' => array('caption'=> LAN_CREATE, 'perm' => '0'),
'main/prefs' => array('caption'=> 'Settings', 'perm' => '0'),
'main/custom' => array('caption'=> 'Custom Page', 'perm' => '0')
'main/create' => array('caption'=> 'LAN_CREATE', 'perm' => '0'),
'main/prefs' => array('caption'=> 'Settings', 'perm' => '0', 'icon'=>'fa-cog'),
'main/custom' => array('caption'=> 'Custom Pages', 'perm' => '0', 'icon'=>'fa-asterisk'),
'main/custom/sub1' => array('caption' => 'Custom Page 1', 'perm' => '0', 'icon' => ''),
'main/custom/sub2' => array('caption' => 'Custom Page 2', 'perm' => '0', 'icon' => ''),
);
/**

View File

@@ -1574,10 +1574,9 @@ thead th, thead tr, .table > thead > tr > th { border-bottom: 0; border-left:0;
div.admin-left-panel .nav-pills > li > a > span > i { font-size:16px; opacity: 0; width:0; }
div.admin-left-panel .nav-pills > li > a:not(.text-primary):not(.text-success):not(.text-info):not(.text-warning):not(.text-danger):not(.text-muted) > span > i {
color: rgba(255,255,255,0.5);
font-size: 16px;
opacity: 0;
width: 0;
}
div.admin-left-panel .nav-pills > li.active > a > span > i { color:white !important }
div.admin-left-panel-collapsed .nav-pills > li > a > span > i { opacity: 1; padding-left: 2px; }
div.admin-left-panel-collapsed .nav-pills > li.active > a { background:none; }
div.admin-left-panel-collapsed .nav-header.sidebar-toggle-panel { display: none; }