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,36 +296,36 @@ $ADMIN_TEMPLATE['menu']['start'] = '
$ADMIN_TEMPLATE['menu']['button'] = ' $ADMIN_TEMPLATE['menu']['button'] = '
<li> <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} {SUB_MENU}
</li> </li>
'; ';
$ADMIN_TEMPLATE['menu']['button_active'] = ' $ADMIN_TEMPLATE['menu']['button_active'] = '
<li class="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} {SUB_MENU}
</li> </li>
'; ';
$ADMIN_TEMPLATE['menu']['start_sub'] = ' $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'] = ' $ADMIN_TEMPLATE['menu']['button_sub'] = '
<li> <li>
<a class="link" href="{LINK_URL}">&nbsp;{LINK_TEXT}{LINK_BADGE}</a> <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>
{SUB_MENU} </li>
</li>
'; ';
$ADMIN_TEMPLATE['menu']['button_active_sub'] = ' $ADMIN_TEMPLATE['menu']['button_active_sub'] = '
<li> <li class="active">
<a class="link-active" href="{LINK_URL}">&nbsp;{LINK_TEXT}{LINK_BADGE}</a> <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>
{SUB_MENU} </li>
</li>
'; ';
$ADMIN_TEMPLATE['menu']['end_sub'] = ' $ADMIN_TEMPLATE['menu']['end_sub'] = '
</ul> </ul>
'; ';
$ADMIN_TEMPLATE['menu']['end'] = ' $ADMIN_TEMPLATE['menu']['end'] = '

View File

@@ -1570,169 +1570,206 @@ class e_admin_dispatcher
* Generic Admin Menu Generator * Generic Admin Menu Generator
* @return string * @return string
*/ */
public function renderMenu() public function renderMenu()
{ {
$tp = e107::getParser(); $tp = e107::getParser();
$var = array(); $var = array();
$selected = false; $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; continue;
} }
$tmp = explode('/', trim($key, '/'), 3); $tmp = explode('/', trim($key, '/'), 3);
$isSubItem = count($tmp) === 3;
// sync with mode/route access if ($isSubItem)
if(!$this->hasModeAccess($tmp[0]) || !$this->hasRouteAccess($tmp[0].'/'.varset($tmp[1]))) {
{ $parentKey = $tmp[0].'/'.$tmp[1];
continue; 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'];
$selected = $val['selected'] === true ? $key : $val['selected']; }
}
foreach ($val as $k=>$v) $processedItem = $this->processMenuItem($val, $key, $tmp);
{ $processedItem['link_id'] = str_replace('/', '-', $key);
switch($k)
{
case 'caption':
$k2 = 'text';
$v = defset($v, $v);
break; if ($isSubItem)
{
$parentKey = $tmp[0].'/'.$tmp[1];
if (!isset($var[$parentKey]))
{
$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
{
$var[$key] = $processedItem;
}
}
case 'url': // Handle links and collapse attributes
$k2 = 'link'; foreach ($var as $key => &$item)
$qry = (isset($val['query'])) ? $val['query'] : '?mode='.$tmp[0].'&amp;action='.$tmp[1]; {
$v = $tp->replaceConstants($v, 'abs').$qry; if (!empty($item['sub']))
break; {
$item['link'] = '#';
$item['link_data'] = [
'data-toggle' => 'collapse',
'data-target' => '#sub-' . $item['link_id'],
'role' => 'button'
];
if ($selected === $key || strpos($selected, $key . '/') === 0)
{
$item['link_data']['aria-expanded'] = 'true';
}
}
elseif (!isset($item['link']))
{
$tmp = explode('/', trim($key, '/'), 3);
$item['link'] = e_REQUEST_SELF.'?mode='.$tmp[0].'&action='.($tmp[1] ?? 'main');
}
}
case 'uri': if (empty($var))
$k2 = 'link'; {
$v = $tp->replaceConstants($v, 'abs'); return '';
}
if(!empty($v) && ($v === e_REQUEST_URI)) // Debug $var
{ e107::getMessage()->addInfo(print_a($var, true));
$selected = $key;
}
break; $request = $this->getRequest();
if (!$selected)
{
$selected = $request->getMode() . '/' . $request->getAction();
if (isset($_GET['sub']) && !empty($_GET['sub']))
{
$selected .= '/' . $_GET['sub'];
}
}
$selected = vartrue($this->adminMenuAliases[$selected], $selected);
$icon = '';
case 'badge': // array('value'=> int, 'type'=>'warning'); if (!empty($this->adminMenuIcon))
$k2 = 'badge'; {
$v = (array) $v; $icon = e107::getParser()->toIcon($this->adminMenuIcon);
break; }
elseif (deftrue('e_CURRENT_PLUGIN'))
{
$icon = e107::getPlug()->load(e_CURRENT_PLUGIN)->getIcon(24);
}
case 'icon': $toggle = "<span class='e-toggle-sidebar'><!-- --></span>";
$k2 = 'image_src';
$v = (string) $v.'.glyph';
break;
default: $var['_extras_'] = array('icon' => $icon, 'return' => true);
$k2 = $k;
break;
}
return $toggle . e107::getNav()->admin($this->menuTitle, $selected, $var);
}
// Access check done above private function processMenuItem($val, $key, $tmp)
// if($val['perm']!= null) // check perms {
// { $tp = e107::getParser();
// if(getperms($val['perm'])) $item = array();
// {
// $var[$key][$k2] = $v;
// }
// }
// else
{
$var[$key][$k2] = $v;
}
} foreach ($val as $k => $v)
{
switch ($k)
{
case 'caption':
$k2 = 'text';
$v = defset($v, $v);
break;
// guess an icon. case 'url':
if(!isset($var[$key]['image_src'])) $k2 = 'link';
{ $qry = (isset($val['query'])) ? $val['query'] : '?mode='.$tmp[0].'&mp;action='.($tmp[1] ?? 'main').(isset($tmp[2]) ? '&sub='.$tmp[2] : '');
$var[$key]['image_src'] = e_navigation::guessMenuIcon($key); $v = $tp->replaceConstants($v, 'abs').$qry;
} break;
// TODO slide down menu options?
if(!vartrue($var[$key]['link']))
{
$var[$key]['link'] = e_REQUEST_SELF.'?mode='.$tmp[0].'&amp;action='.$tmp[1]; // FIXME - URL based on $modes, remove url key
}
case 'uri':
if(varset($val['tab'])) $k2 = 'link';
{ $v = $tp->replaceConstants($v, 'abs');
$var[$key]['link'] .= '&amp;tab=' .$val['tab']; if (!empty($v) && ($v === e_REQUEST_URI))
} {
$GLOBALS['selected'] = $key;
}
break;
/*$var[$key]['text'] = $val['caption']; case 'badge':
$var[$key]['link'] = (vartrue($val['url']) ? $tp->replaceConstants($val['url'], 'abs') : e_SELF).'?mode='.$tmp[0].'&action='.$tmp[1]; $k2 = 'badge';
$var[$key]['perm'] = $val['perm']; */ $v = (array) $v;
if(!empty($val['modal'])) break;
{
$var[$key]['link_class'] = ' e-modal';
if(!empty($val['modal-caption']))
{
$var[$key]['link_data'] = ['data-modal-caption' => $val['modal-caption']];
}
} case 'icon':
$k2 = 'image_src';
$v = (string) $v . '.glyph'; // Ensure .glyph suffix
break;
if(!empty($val['class'])) 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'] ?? '';
$var[$key]['link_class'] .= ' '.$val['class']; $var[$key]['link_class'] .= ' '.$val['class'];
} }
}
if(empty($var))
{
return '';
}
$request = $this->getRequest();
if(!$selected)
{
$selected = $request->getMode() . '/' . $request->getAction();
}
$selected = vartrue($this->adminMenuAliases[$selected], $selected);
$icon = '';
if(!empty($this->adminMenuIcon))
{
$icon = e107::getParser()->toIcon($this->adminMenuIcon);
}
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['_icon_'] = $icon;
return e107::getNav()->admin($this->menuTitle, $selected, $var);
}
return $item;
}
/** /**
* Render Help Text in <ul> format. XXX TODO * 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 $qryField Specific query field(s) to filter.
* @param mixed $isfilter Determines if a specific filter is applied. * @param mixed $isfilter Determines if a specific filter is applied.
* @param mixed $handleAction Custom action handler for the search process. * @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) 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]); $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_TEXT'] = str_replace(" ", "&nbsp;", varset($e107_vars[$act]['text']));
$replace['LINK_DESCRIPTION'] = varset($e107_vars[$act]['description']); $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(); $dataTmp = array();
foreach($e107_vars[$act]['link_data'] as $k=>$v) 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'] $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'])) if(!empty($e107_vars[$act]['sub']))
{ {
$replace['SUB_ID'] = $id ? " id='eplug-nav-{$rid}-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_CLASS'] = ' '.varset($e107_vars[$act]['sub_class'], 'e-hideme e-expandme');
$replace['SUB_MENU'] = $tp->parseTemplate($START_SUB, false, $replace); $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'] .= $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'] : ''; $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( protected $adminMenu = array(
'main/list' => array('caption'=> 'Manage', 'perm' => '0'), 'main/list' => array('caption'=> 'Manage', 'perm' => '0'),
'main/create' => array('caption'=> LAN_CREATE, 'perm' => '0'), 'main/create' => array('caption'=> 'LAN_CREATE', 'perm' => '0'),
'main/prefs' => array('caption'=> 'Settings', 'perm' => '0'), 'main/prefs' => array('caption'=> 'Settings', 'perm' => '0', 'icon'=>'fa-cog'),
'main/custom' => array('caption'=> 'Custom Page', 'perm' => '0') '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 > 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 { 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); 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 > 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-pills > li.active > a { background:none; }
div.admin-left-panel-collapsed .nav-header.sidebar-toggle-panel { display: none; } div.admin-left-panel-collapsed .nav-header.sidebar-toggle-panel { display: none; }