Update menu.php

This commit is contained in:
Momchil Bozhinov
2021-02-23 20:37:48 +02:00
parent 3fdbf8e27a
commit a052656a4b

View File

@@ -27,9 +27,7 @@
class Menu class Menu
{ {
public $html=array(); public $html=array();
public $name='';
public $title='Error'; public $title='Error';
public $path='';
public $first_key=array(); public $first_key=array();
function __construct($_REALPATH,$uri) function __construct($_REALPATH,$uri)
@@ -37,10 +35,7 @@ class Menu
$realpath_public=$_REALPATH.'/public/'; # /usr/home/web/cp/clonos/public/ $realpath_public=$_REALPATH.'/public/'; # /usr/home/web/cp/clonos/public/
$lang = new Locale($realpath_public); $lang = new Locale($realpath_public);
$menu_config = Config::$menu; $menu_config = Config::$menu;
if(!empty($menu_config)){ $this->first_key = array_key_first($menu_config);
reset($menu_config);
$this->first_key=key($menu_config);
}
if(getenv('APPLICATION_ENV') != 'development'){ if(getenv('APPLICATION_ENV') != 'development'){
unset($menu_config['sqlite']); unset($menu_config['sqlite']);
@@ -51,19 +46,16 @@ class Menu
//$qstr=trim($_SERVER['REQUEST_URI'],'/'); //$qstr=trim($_SERVER['REQUEST_URI'],'/');
$qstr=''; $qstr='';
$uri_chunks=Utils::gen_uri_chunks($uri); $uri_chunks=Utils::gen_uri_chunks($uri);
if(isset($uri_chunks[0])) if(isset($uri_chunks[0])){
$qstr=trim($uri_chunks[0],'/'); $qstr=trim($uri_chunks[0],'/');
$this->path=$qstr; //$_MENU_PATH }
if(!empty($menu_config))foreach($menu_config as $key=>$val){ if(!empty($menu_config))foreach($menu_config as $link=>$val){
$mname=$lang->translate($val['name']); $mname=$lang->translate($val['name']);
$mtitle=$lang->translate($val['title']); $mtitle=$lang->translate($val['title']);
$link=$key;
$sel=''; $sel='';
if($qstr==$key){ if($qstr==$link){
$sel=' class="sel"'; $sel=' class="sel"';
$this->title=$mtitle; //$_TITLE $this->title=$mtitle; //$_TITLE
$this->name=$mname; //$_MENU_NAME
} }
$icon='empty'; $icon='empty';
@@ -72,8 +64,7 @@ class Menu
$this->html.=' <li><a href="/'.$link.'/" title="'.$mtitle.'"'.$sel.'>'.$span.'<span class="mtxt">'.$mname.'</span></a>'; $this->html.=' <li><a href="/'.$link.'/" title="'.$mtitle.'"'.$sel.'>'.$span.'<span class="mtxt">'.$mname.'</span></a>';
if(!empty($val['submenu'])){ if(!empty($val['submenu'])){
$this->html.= PHP_EOL.' <ul class="submenu">'.PHP_EOL; $this->html.= PHP_EOL.' <ul class="submenu">'.PHP_EOL;
foreach($val['submenu'] as $k=>$s) foreach($val['submenu'] as $k=>$s){
{
$sname=$lang->translate($s['name']); $sname=$lang->translate($s['name']);
$stitle=$lang->translate($s['title']); $stitle=$lang->translate($s['title']);
@@ -83,7 +74,6 @@ class Menu
if($qstr==$sl){ if($qstr==$sl){
$ssel=' class="sel"'; $ssel=' class="sel"';
$this->title=$stitle; $this->title=$stitle;
$this->name=$sname;
} }
$this->html.= ' <li><a href="/'.$slink.'/" title="'.$stitle.'"'.$ssel.'>'.$sname.'</a></li>'.PHP_EOL; $this->html.= ' <li><a href="/'.$slink.'/" title="'.$stitle.'"'.$ssel.'>'.$sname.'</a></li>'.PHP_EOL;
} }
@@ -96,8 +86,9 @@ class Menu
if($this->title=='Error'){ if($this->title=='Error'){
$other_titles = Config::$other_titles; $other_titles = Config::$other_titles;
if(isset($other_titles[$qstr])) if(isset($other_titles[$qstr])){
$this->title=$lang->translate($other_titles[$qstr]); $this->title=$lang->translate($other_titles[$qstr]);
} }
} }
} }
}