Qual: Make some refactoring to prepare speed enhancement in menu loading.
This commit is contained in:
parent
54ff3ba28b
commit
d418dddc50
@ -431,116 +431,45 @@ class Menubase
|
||||
* @param type_user 0=Internal,1=External,2=All
|
||||
* @param mainmenu Value for mainmenu that defined top menu
|
||||
* @param menu_handler Name of menu_handler used (auguria, eldy...)
|
||||
* @param tabMenu If array with menu entries already loaded, we put this array here (in most cases, it's empty)
|
||||
* @return array Return array with menu entries for top menu
|
||||
* TODO Mutualize menuTopCharger and menuLeftCharger
|
||||
*/
|
||||
function menuTopCharger($mainmenu, $myleftmenu, $type_user, $menu_handler, &$tabMenu=array())
|
||||
function menuTopCharger($mainmenu, $myleftmenu, $type_user, $menu_handler, &$tabMenu=null)
|
||||
{
|
||||
global $langs, $user, $conf;
|
||||
global $leftmenu,$rights; // To export to dol_eval function
|
||||
|
||||
|
||||
$leftmenu=$myleftmenu; // To export to dol_eval function
|
||||
|
||||
// Load datas into tabMenu
|
||||
/*if (sizeof($tabMenu) == 0)
|
||||
if (sizeof($tabMenu) == 0)
|
||||
{
|
||||
$this->menuLoad($leftmenu, $type_user, $menu_handler, $tabMenu);
|
||||
//var_dump($tabMenu);
|
||||
$this->menuLoad($leftmenu, $type_user, $menu_handler, $tabMenu);
|
||||
}
|
||||
else
|
||||
|
||||
$newTabMenu=array();
|
||||
$i=0;
|
||||
foreach($tabMenu as $val)
|
||||
{
|
||||
// TODO Just try to find menutopid from tabMenu and mainmenu
|
||||
$this->menuLoad($leftmenu, $type_user, $menu_handler, $tabMenu);
|
||||
}*/
|
||||
if ($val[9]=='top')
|
||||
{
|
||||
|
||||
$newTabMenu[$i]['rowid']=$val[0];
|
||||
$newTabMenu[$i]['fk_menu']=$val[1];
|
||||
$newTabMenu[$i]['url']=$val[2];
|
||||
$newTabMenu[$i]['titre']=$val[3];
|
||||
$newTabMenu[$i]['right']=$val[4];
|
||||
$newTabMenu[$i]['atarget']=$val[5];
|
||||
$newTabMenu[$i]['leftmenu']=$val[6];
|
||||
$newTabMenu[$i]['enabled']=$val[7];
|
||||
$newTabMenu[$i]['mainmenu']=$val[8];
|
||||
$newTabMenu[$i]['type']=$val[9];
|
||||
$newTabMenu[$i]['lang']=$val[10];
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$tabMenu=array();
|
||||
|
||||
$sql = "SELECT m.rowid, m.mainmenu, m.titre, m.url, m.langs, m.perms, m.enabled, m.target";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."menu as m";
|
||||
$sql.= " WHERE m.entity = ".$conf->entity;
|
||||
$sql.= " AND m.menu_handler in('".$menu_handler."','all')";
|
||||
if ($type_user == 0) $sql.= " AND m.usertype in (0,2)";
|
||||
if ($type_user == 1) $sql.= " AND m.usertype in (1,2)";
|
||||
// If type_user == 2, no test requires
|
||||
$sql.= " AND m.type = 'top'";
|
||||
$sql.= " ORDER BY m.position";
|
||||
|
||||
dol_syslog("Menubase::menuTopCharger sql=".$sql);
|
||||
$resql = $this->db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
$numa = $this->db->num_rows($resql);
|
||||
|
||||
$a = 0;
|
||||
$b = 0;
|
||||
$oldrowid=0;
|
||||
while ($a < $numa)
|
||||
{
|
||||
$objm = $this->db->fetch_object($resql);
|
||||
|
||||
// Define $chaine
|
||||
$chaine="";
|
||||
$title=$langs->trans($objm->titre);
|
||||
if ($title == $objm->titre) // Translation not found
|
||||
{
|
||||
if (! empty($objm->langs)) // If there is a dedicated translation file
|
||||
{
|
||||
$langs->load($objm->langs);
|
||||
}
|
||||
|
||||
if (preg_match("/\//",$objm->titre)) // To manage translation when title is string1/string2
|
||||
{
|
||||
$tab_titre = explode("/",$objm->titre);
|
||||
$chaine = $langs->trans($tab_titre[0])."/".$langs->trans($tab_titre[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
$chaine = $langs->trans($objm->titre);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$chaine=$title;
|
||||
}
|
||||
//print "x".$objm->titre."-".$chaine;
|
||||
|
||||
// Define $right
|
||||
$perms = true;
|
||||
if ($objm->perms)
|
||||
{
|
||||
$perms = verifCond($objm->perms);
|
||||
}
|
||||
|
||||
// Define $enabled
|
||||
$enabled = true;
|
||||
if ($objm->enabled)
|
||||
{
|
||||
$enabled = verifCond($objm->enabled);
|
||||
}
|
||||
|
||||
$tabMenu[$b]['rowid'] = $objm->rowid;
|
||||
$tabMenu[$b]['mainmenu'] = $objm->mainmenu;
|
||||
$tabMenu[$b]['titre'] = $chaine; // Title
|
||||
$tabMenu[$b]['url'] = $objm->url;
|
||||
$tabMenu[$b]['atarget'] = $objm->target;
|
||||
if (! isset($tabMenu[$b]['right'])) $tabMenu[$b]['right'] = $perms;
|
||||
else $tabMenu[$b]['right'] = ($tabMenu[$b]['right'] && $perms);
|
||||
if (! isset($tabMenu[$b]['enabled'])) $tabMenu[$b]['enabled'] = $enabled;
|
||||
else $tabMenu[$b]['enabled'] = ($tabMenu[$b]['enabled'] && $enabled);
|
||||
$tabMenu[$b]['lang'] = $objm->langs;
|
||||
|
||||
//var_dump($tabMenu);
|
||||
$b++;
|
||||
$a++;
|
||||
}
|
||||
$this->db->free($resql);
|
||||
}
|
||||
else
|
||||
{
|
||||
dol_print_error($this->db);
|
||||
}
|
||||
|
||||
return $tabMenu;
|
||||
return $newTabMenu;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -553,7 +482,7 @@ class Menubase
|
||||
* @param $tabMenu If array with menu entries already loaded, we put this array here (in most cases, it's empty)
|
||||
* @return array Menu array for particular mainmenu value or full tabArray
|
||||
*/
|
||||
function menuLeftCharger($newmenu, $mainmenu, $myleftmenu, $type_user, $menu_handler, &$tabMenu=array())
|
||||
function menuLeftCharger($newmenu, $mainmenu, $myleftmenu, $type_user, $menu_handler, &$tabMenu=null)
|
||||
{
|
||||
global $langs, $user, $conf; // To export to dol_eval function
|
||||
global $leftmenu,$rights; // To export to dol_eval function
|
||||
@ -566,14 +495,9 @@ class Menubase
|
||||
if (sizeof($tabMenu) == 0)
|
||||
{
|
||||
$this->menuLoad($leftmenu, $type_user, $menu_handler, $tabMenu);
|
||||
//var_dump($tabMenu);
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO Just try to find menutopid from tabMenu and mainmenu
|
||||
$this->menuLoad($leftmenu, $type_user, $menu_handler, $tabMenu);
|
||||
}
|
||||
|
||||
//var_dump($tabMenu);
|
||||
|
||||
// Define menutopid
|
||||
$menutopid='';
|
||||
foreach($tabMenu as $val)
|
||||
@ -691,7 +615,8 @@ class Menubase
|
||||
else $tabMenu[$b][7] = ($tabMenu[$b][7] && $enabled);
|
||||
$tabMenu[$b][8] = $menu['mainmenu'];
|
||||
$tabMenu[$b][9] = $menu['type'];
|
||||
|
||||
$tabMenu[$b][10] = $menu['langs'];
|
||||
|
||||
$b++;
|
||||
$a++;
|
||||
}
|
||||
|
||||
@ -43,46 +43,40 @@ function print_smartphone_menu($db,$atarget,$type_user,$limitmenuto)
|
||||
|
||||
$menutop = new Menubase($db,'smartphone','top');
|
||||
$menuleft = new Menubase($db,'smartphone','left');
|
||||
$tabMenu = $menutop->menuTopCharger('', '', $type_user, 'smartphone');
|
||||
$numTabMenu = count($tabMenu);
|
||||
|
||||
/*$newmenu = new Menu();
|
||||
$leftmenu = $menuleft->menuLeftCharger($newmenu,'','',($user->societe_id?1:0),'smartphone');
|
||||
$menus = $leftmenu->liste;
|
||||
var_dump($menus);
|
||||
*/
|
||||
$newTabMenu = $menutop->menuTopCharger('', '', $type_user, 'smartphone');
|
||||
$numTabMenu = count($newTabMenu);
|
||||
|
||||
print_start_menu_array();
|
||||
for($i=0; $i<$numTabMenu; $i++)
|
||||
{
|
||||
if ($tabMenu[$i]['enabled'] == true)
|
||||
if ($newTabMenu[$i]['enabled'] == true)
|
||||
{
|
||||
if ($tabMenu[$i]['right'] == true) // Is allowed
|
||||
if ($newTabMenu[$i]['right'] == true) // Is allowed
|
||||
{
|
||||
// Define url
|
||||
if (preg_match("/^(http:\/\/|https:\/\/)/i",$tabMenu[$i]['url']))
|
||||
if (preg_match("/^(http:\/\/|https:\/\/)/i",$newTabMenu[$i]['url']))
|
||||
{
|
||||
$url = dol_buildpath($tabMenu[$i]['url'],1);
|
||||
$url = dol_buildpath($newTabMenu[$i]['url'],1);
|
||||
$url=preg_replace('/&.*/i','',$url);
|
||||
}
|
||||
else
|
||||
{
|
||||
$menus='';
|
||||
|
||||
if ($limitmenuto != 'top')
|
||||
if ($limitmenuto > 0)
|
||||
{
|
||||
$newmenu = new Menu();
|
||||
$leftmenu = $menuleft->menuLeftCharger($newmenu,$tabMenu[$i]['mainmenu'],'',($user->societe_id?1:0),'smartphone');
|
||||
$leftmenu = $menuleft->menuLeftCharger($newmenu,$newTabMenu[$i]['mainmenu'],'',($user->societe_id?1:0),'smartphone');
|
||||
$menus = $leftmenu->liste;
|
||||
//var_dump($menus);
|
||||
}
|
||||
|
||||
print_start_menu_entry();
|
||||
|
||||
if (is_array($menus) && !empty($menus))
|
||||
if (is_array($menus) && !empty($menus) && $limitmenuto > 0)
|
||||
{
|
||||
$title=$tabMenu[$i]['titre'];
|
||||
// To remove & and special chars: $title=dol_string_unaccent(dol_string_nospecial(dol_html_entity_decode($tabMenu[$i]['titre'],ENT_QUOTES,'UTF-8'),'',array('&')));
|
||||
$title=$newTabMenu[$i]['titre'];
|
||||
// To remove & and special chars: $title=dol_string_unaccent(dol_string_nospecial(dol_html_entity_decode($newTabMenu[$i]['titre'],ENT_QUOTES,'UTF-8'),'',array('&')));
|
||||
print_text_menu_entry($title);
|
||||
|
||||
$num = count($menus);
|
||||
@ -127,12 +121,12 @@ function print_smartphone_menu($db,$atarget,$type_user,$limitmenuto)
|
||||
}
|
||||
else
|
||||
{
|
||||
$url=dol_buildpath($tabMenu[$i]['url'],1);
|
||||
$url=dol_buildpath($newTabMenu[$i]['url'],1);
|
||||
$url=preg_replace('/&.*/i','',$url);
|
||||
|
||||
print '<a href="'.$url.'"'.($tabMenu[$i]['atarget']?" target='".$tabMenu[$i]['atarget']."'":($atarget?" target=$atarget":'')).'>';
|
||||
$title=$tabMenu[$i]['titre'];
|
||||
// To remove & and special chars: $title=dol_string_unaccent(dol_string_nospecial(dol_html_entity_decode($tabMenu[$i]['titre'],ENT_QUOTES,'UTF-8'),'',array('&')));
|
||||
print '<a href="'.$url.'"'.($newTabMenu[$i]['atarget']?" target='".$newTabMenu[$i]['atarget']."'":($atarget?" target=$atarget":'')).'>';
|
||||
$title=$newTabMenu[$i]['titre'];
|
||||
// To remove & and special chars: $title=dol_string_unaccent(dol_string_nospecial(dol_html_entity_decode($newTabMenu[$i]['titre'],ENT_QUOTES,'UTF-8'),'',array('&')));
|
||||
print_text_menu_entry($title);
|
||||
print '</a>';
|
||||
}
|
||||
|
||||
@ -45,43 +45,43 @@ function print_auguria_menu($db,$atarget,$type_user)
|
||||
$_SESSION["leftmenuopened"]="";
|
||||
|
||||
$menuArbo = new Menubase($db,'auguria','top');
|
||||
$tabMenu = $menuArbo->menuTopCharger($_SESSION['mainmenu'], '', $type_user, 'auguria');
|
||||
$newTabMenu = $menuArbo->menuTopCharger($_SESSION['mainmenu'], '', $type_user, 'auguria');
|
||||
|
||||
print_start_menu_array_auguria();
|
||||
|
||||
for($i=0; $i<count($tabMenu); $i++)
|
||||
for($i=0; $i<count($newTabMenu); $i++)
|
||||
{
|
||||
if ($tabMenu[$i]['enabled'] == true)
|
||||
if ($newTabMenu[$i]['enabled'] == true)
|
||||
{
|
||||
$idsel=(empty($tabMenu[$i]['mainmenu'])?'none':$tabMenu[$i]['mainmenu']);
|
||||
if ($tabMenu[$i]['right'] == true) // Is allowed
|
||||
$idsel=(empty($newTabMenu[$i]['mainmenu'])?'none':$newTabMenu[$i]['mainmenu']);
|
||||
if ($newTabMenu[$i]['right'] == true) // Is allowed
|
||||
{
|
||||
// Define url
|
||||
if (preg_match("/^(http:\/\/|https:\/\/)/i",$tabMenu[$i]['url']))
|
||||
if (preg_match("/^(http:\/\/|https:\/\/)/i",$newTabMenu[$i]['url']))
|
||||
{
|
||||
$url = $tabMenu[$i]['url'];
|
||||
$url = $newTabMenu[$i]['url'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$url=dol_buildpath($tabMenu[$i]['url'],1);
|
||||
$url=dol_buildpath($newTabMenu[$i]['url'],1);
|
||||
if (! preg_match('/\?/',$url)) $url.='?';
|
||||
else $url.='&';
|
||||
if (! preg_match('/mainmenu/i',$url) || ! preg_match('/leftmenu/i',$url))
|
||||
{
|
||||
$url.='mainmenu='.$tabMenu[$i]['mainmenu'].'&leftmenu=&';
|
||||
$url.='mainmenu='.$newTabMenu[$i]['mainmenu'].'&leftmenu=&';
|
||||
}
|
||||
$url.="idmenu=".$tabMenu[$i]['rowid'];
|
||||
$url.="idmenu=".$newTabMenu[$i]['rowid'];
|
||||
}
|
||||
|
||||
// Define the class (top menu selected or not)
|
||||
if (! empty($_SESSION['idmenu']) && $tabMenu[$i]['rowid'] == $_SESSION['idmenu']) $classname='class="tmenusel"';
|
||||
else if (! empty($_SESSION['mainmenu']) && $tabMenu[$i]['mainmenu'] == $_SESSION['mainmenu']) $classname='class="tmenusel"';
|
||||
if (! empty($_SESSION['idmenu']) && $newTabMenu[$i]['rowid'] == $_SESSION['idmenu']) $classname='class="tmenusel"';
|
||||
else if (! empty($_SESSION['mainmenu']) && $newTabMenu[$i]['mainmenu'] == $_SESSION['mainmenu']) $classname='class="tmenusel"';
|
||||
else $classname='class="tmenu"';
|
||||
|
||||
print_start_menu_entry_auguria($idsel);
|
||||
print '<div class="mainmenu '.$idsel.'"><span class="mainmenu_'.$idsel.'" id="mainmenuspan_'.$idsel.'"></span></div>';
|
||||
print '<a '.$classname.' id="mainmenua_'.$idsel.'" href="'.$url.'"'.($tabMenu[$i]['atarget']?" target='".$tabMenu[$i]['atarget']."'":($atarget?" target=$atarget":"")).'>';
|
||||
print_text_menu_entry_auguria($tabMenu[$i]['titre']);
|
||||
print '<a '.$classname.' id="mainmenua_'.$idsel.'" href="'.$url.'"'.($newTabMenu[$i]['atarget']?" target='".$newTabMenu[$i]['atarget']."'":($atarget?" target=$atarget":"")).'>';
|
||||
print_text_menu_entry_auguria($newTabMenu[$i]['titre']);
|
||||
print '</a>';
|
||||
print_end_menu_entry_auguria();
|
||||
}
|
||||
@ -92,7 +92,7 @@ function print_auguria_menu($db,$atarget,$type_user)
|
||||
print_start_menu_entry_auguria($idsel);
|
||||
print '<div class="mainmenu '.$idsel.'"><span class="mainmenu_'.$idsel.'" id="mainmenuspan_'.$idsel.'"></span></div>';
|
||||
print '<a class="tmenudisabled" id="mainmenua_'.$idsel.'" href="#">';
|
||||
print_text_menu_entry_auguria($tabMenu[$i]['titre']);
|
||||
print_text_menu_entry_auguria($newTabMenu[$i]['titre']);
|
||||
print '</a>';
|
||||
print_end_menu_entry_auguria();
|
||||
}
|
||||
|
||||
@ -436,44 +436,44 @@ function print_eldy_menu($db,$atarget,$type_user)
|
||||
|
||||
$menuArbo = new Menubase($db,'eldy','top');
|
||||
|
||||
$tabMenu = $menuArbo->menuTopCharger($_SESSION['mainmenu'],'',$type_user,'eldy');
|
||||
$newTabMenu = $menuArbo->menuTopCharger($_SESSION['mainmenu'],'',$type_user,'eldy');
|
||||
|
||||
for($i=0; $i<count($tabMenu); $i++)
|
||||
for($i=0; $i<count($newTabMenu); $i++)
|
||||
{
|
||||
if ($tabMenu[$i]['enabled'] == true)
|
||||
if ($newTabMenu[$i]['enabled'] == true)
|
||||
{
|
||||
//var_dump($tabMenu[$i]);
|
||||
//var_dump($newTabMenu[$i]);
|
||||
|
||||
$idsel=(empty($tabMenu[$i]['mainmenu'])?'none':$tabMenu[$i]['mainmenu']);
|
||||
if ($tabMenu[$i]['right'] == true) // Is allowed
|
||||
$idsel=(empty($newTabMenu[$i]['mainmenu'])?'none':$newTabMenu[$i]['mainmenu']);
|
||||
if ($newTabMenu[$i]['right'] == true) // Is allowed
|
||||
{
|
||||
if (preg_match("/^(http:\/\/|https:\/\/)/i",$tabMenu[$i]['url']))
|
||||
if (preg_match("/^(http:\/\/|https:\/\/)/i",$newTabMenu[$i]['url']))
|
||||
{
|
||||
$url = $tabMenu[$i]['url'];
|
||||
$url = $newTabMenu[$i]['url'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$url=dol_buildpath($tabMenu[$i]['url'],1);
|
||||
$url=dol_buildpath($newTabMenu[$i]['url'],1);
|
||||
if (! preg_match('/\?/',$url)) $url.='?';
|
||||
else $url.='&';
|
||||
if (! preg_match('/mainmenu/i',$url) || ! preg_match('/leftmenu/i',$url))
|
||||
{
|
||||
$url.='mainmenu='.$tabMenu[$i]['mainmenu'].'&leftmenu=&';
|
||||
$url.='mainmenu='.$newTabMenu[$i]['mainmenu'].'&leftmenu=&';
|
||||
}
|
||||
$url.="idmenu=".$tabMenu[$i]['rowid'];
|
||||
$url.="idmenu=".$newTabMenu[$i]['rowid'];
|
||||
}
|
||||
|
||||
// Define the class (top menu selected or not)
|
||||
if (! empty($_SESSION['idmenu']) && $tabMenu[$i]['rowid'] == $_SESSION['idmenu']) $classname='class="tmenusel"';
|
||||
else if (! empty($_SESSION['mainmenu']) && $tabMenu[$i]['mainmenu'] == $_SESSION['mainmenu']) $classname='class="tmenusel"';
|
||||
if (! empty($_SESSION['idmenu']) && $newTabMenu[$i]['rowid'] == $_SESSION['idmenu']) $classname='class="tmenusel"';
|
||||
else if (! empty($_SESSION['mainmenu']) && $newTabMenu[$i]['mainmenu'] == $_SESSION['mainmenu']) $classname='class="tmenusel"';
|
||||
else $classname='class="tmenu"';
|
||||
|
||||
print_start_menu_entry($idsel);
|
||||
print '<a class="tmenuimage" href="'.$url.'"'.($tabMenu[$i]['atarget']?" target='".$tabMenu[$i]['atarget']."'":($atarget?" target=$atarget":"")).'>';
|
||||
print '<a class="tmenuimage" href="'.$url.'"'.($newTabMenu[$i]['atarget']?" target='".$newTabMenu[$i]['atarget']."'":($atarget?" target=$atarget":"")).'>';
|
||||
print '<div class="'.$id.' '.$idsel.'"><span class="'.$id.' tmenuimage" id="mainmenuspan_'.$idsel.'"></span></div>';
|
||||
print '</a>';
|
||||
print '<a '.$classname.' id="mainmenua_'.$idsel.'" href="'.$url.'"'.($tabMenu[$i]['atarget']?" target='".$tabMenu[$i]['atarget']."'":($atarget?" target=$atarget":"")).'>';
|
||||
print_text_menu_entry($tabMenu[$i]['titre']);
|
||||
print '<a '.$classname.' id="mainmenua_'.$idsel.'" href="'.$url.'"'.($newTabMenu[$i]['atarget']?" target='".$newTabMenu[$i]['atarget']."'":($atarget?" target=$atarget":"")).'>';
|
||||
print_text_menu_entry($newTabMenu[$i]['titre']);
|
||||
print '</a>';
|
||||
print_end_menu_entry();
|
||||
}
|
||||
@ -484,7 +484,7 @@ function print_eldy_menu($db,$atarget,$type_user)
|
||||
print_start_menu_entry($idsel);
|
||||
print '<div class="'.$id.' '.$idsel.'"><span class="'.$id.' tmenuimage" id="mainmenuspan_'.$idsel.'"></span></div>';
|
||||
print '<a class="tmenudisabled" id="mainmenua_'.$idsel.'" href="#">';
|
||||
print_text_menu_entry($tabMenu[$i]['titre']);
|
||||
print_text_menu_entry($newTabMenu[$i]['titre']);
|
||||
print '</a>';
|
||||
print_end_menu_entry();
|
||||
}
|
||||
|
||||
@ -57,8 +57,8 @@ if (!isset($conf->global->MAIN_INFO_SOCIETE_NOM) || empty($conf->global->MAIN_IN
|
||||
// If smartphone mode, we do no show main page, we show only menu
|
||||
if (preg_match('/^smartphone/',$conf->smart_menu) && isset($conf->browser->phone))
|
||||
{
|
||||
$limitmenu=GETPOST('limitmenuto')?GETPOST('limitmenuto'):'top';
|
||||
$limitmenu=''; // A virer
|
||||
$limitmenuto=GETPOST('limitmenuto')?GETPOST('limitmenuto'):0;
|
||||
$limitmenuto=1; // A virer
|
||||
|
||||
// Load the smartphone menu manager
|
||||
$result=@include_once(DOL_DOCUMENT_ROOT ."/includes/menus/smartphone/".$conf->smart_menu);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user