Skip to content

Commit

Permalink
Fix substition for menus title and urls
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Dec 9, 2017
1 parent 55b9921 commit e3dcff7
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 57 deletions.
14 changes: 9 additions & 5 deletions htdocs/core/class/menubase.class.php
Expand Up @@ -520,8 +520,8 @@ function menuLoad($mymainmenu, $myleftmenu, $type_user, $menu_handler, &$tabMenu
$sql.= " ORDER BY m.position, m.rowid";
//print $sql;

//$tmp1=microtime(true);
//print '>>> 1 0<br>';
//$tmp1=microtime(true);
//print '>>> 1 0<br>';
dol_syslog(get_class($this)."::menuLoad mymainmenu=".$mymainmenu." myleftmenu=".$myleftmenu." type_user=".$type_user." menu_handler=".$menu_handler." tabMenu size=".count($tabMenu)."", LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql)
Expand Down Expand Up @@ -558,7 +558,8 @@ function menuLoad($mymainmenu, $myleftmenu, $type_user, $menu_handler, &$tabMenu
// Define $title
if ($enabled)
{
$title = $langs->trans($menu['titre']);
$title = $langs->trans($menu['titre']); // If $menu['titre'] start with $, a dol_eval is done.
//var_dump($title.'-'.$menu['titre']);
if ($title == $menu['titre']) // Translation not found
{
if (! empty($menu['langs'])) // If there is a dedicated translation file
Expand All @@ -567,6 +568,9 @@ function menuLoad($mymainmenu, $myleftmenu, $type_user, $menu_handler, &$tabMenu
$langs->load($menu['langs']);
}

$substitarray = array('__LOGIN__' => $user->login, '__USER_ID__' => $user->id, '__USER_SUPERVISOR_ID__' => $user->fk_user);
$menu['titre'] = make_substitutions($menu['titre'], $substitarray);

if (preg_match("/\//",$menu['titre'])) // To manage translation when title is string1/string2
{
$tab_titre = explode("/",$menu['titre']);
Expand All @@ -584,8 +588,8 @@ function menuLoad($mymainmenu, $myleftmenu, $type_user, $menu_handler, &$tabMenu
$title = $langs->trans($menu['titre']);
}
}
//$tmp4=microtime(true);
//print '>>> 3 '.($tmp4 - $tmp3).'<br>';
//$tmp4=microtime(true);
//print '>>> 3 '.($tmp4 - $tmp3).'<br>';

// We complete tabMenu
$tabMenu[$b]['rowid'] = $menu['rowid'];
Expand Down
2 changes: 1 addition & 1 deletion htdocs/core/class/translate.class.php
Expand Up @@ -635,7 +635,7 @@ function trans($key, $param1='', $param2='', $param3='', $param4='', $maxsize=0)
}
else // Translation is not available
{
if ($key[0] == '$') { return dol_eval($key,1); }
//if ($key[0] == '$') { return dol_eval($key,1); }
return $this->getTradFromKey($key);
}
}
Expand Down
8 changes: 4 additions & 4 deletions htdocs/core/lib/functions.lib.php
Expand Up @@ -467,7 +467,7 @@ function GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NU
}

// Substitution variables for GETPOST (used to get final url with variable parameters or final default value with variable paramaters)
// Example of variables: __DAY__, __MONTH__, __YEAR__, __MYCOUNTRYID__, __USERID__, __ENTITYID__, ...
// Example of variables: __DAY__, __MONTH__, __YEAR__, __MYCOMPANY_COUNTRY_ID__, __USER_ID__, ...
// We do this only if var is a GET. If it is a POST, may be we want to post the text with vars as the setup text.
if (! is_array($out) && empty($_POST[$paramname]) && empty($noreplace))
{
Expand All @@ -485,19 +485,19 @@ function GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NU
elseif ($reg[1] == 'NEXT_DAY') { $tmp=dol_getdate(dol_now(), true); $tmp2=dol_get_next_day($tmp['mday'], $tmp['mon'], $tmp['year']); $newout = $tmp2['day']; }
elseif ($reg[1] == 'NEXT_MONTH') { $tmp=dol_getdate(dol_now(), true); $tmp2=dol_get_next_month($tmp['mday'], $tmp['mon'], $tmp['year']); $newout = $tmp2['month']; }
elseif ($reg[1] == 'NEXT_YEAR') { $tmp=dol_getdate(dol_now(), true); $newout = ($tmp['year'] + 1); }
elseif ($reg[1] == 'MYCOUNTRY_ID' || $reg[1] == 'MYCOUNTRYID')
elseif ($reg[1] == 'MYCOMPANY_COUNTRY_ID' || $reg[1] == 'MYCOUNTRY_ID' || $reg[1] == 'MYCOUNTRYID')
{
$newout = $mysoc->country_id;
}
elseif ($reg[1] == 'USER_ID' || $reg[1] == 'USERID')
{
$newout = $user->id;
}
elseif ($reg[1] == 'SUPERVISOR_ID' || $reg[1] == 'SUPERVISORID')
elseif ($reg[1] == 'USER_SUPERVISOR_ID' || $reg[1] == 'SUPERVISOR_ID' || $reg[1] == 'SUPERVISORID')
{
$newout = $user->fk_user;
}
elseif ($reg[1] == 'ENTITYID')
elseif ($reg[1] == 'ENTITY_ID' || $reg[1] == 'ENTITYID')
{
$newout = $conf->entity;
}
Expand Down
21 changes: 8 additions & 13 deletions htdocs/core/menus/standard/auguria.lib.php
Expand Up @@ -73,12 +73,9 @@ function print_auguria_menu($db,$atarget,$type_user,&$tabMenu,&$menu,$noout=0,$m
$showmode=dol_auguria_showmenu($type_user,$newTabMenu[$i],$listofmodulesforexternal);
if ($showmode == 1)
{
// $menu_array[$i]['url'] can be a relative url, a full external url or a dynamic value like '$conf->global->APARAM)
if (preg_match('/^\$conf->global->([^\?]+)/', $newTabMenu[$i]['url'], $reg))
{
$keyforsconst=$reg[1];
$newTabMenu[$i]['url'] = $conf->global->$keyforsconst;
}
$substitarray = array('__LOGIN__' => $user->login, '__USER_ID__' => $user->id, '__USER_SUPERVISOR_ID__' => $user->fk_user);
$substitarray['__USERID__'] = $user->id; // For backward compatibility
$newTabMenu[$i]['url'] = make_substitutions($newTabMenu[$i]['url'], $substitarray);

$url = $shorturl = $newTabMenu[$i]['url'];

Expand All @@ -105,11 +102,6 @@ function print_auguria_menu($db,$atarget,$type_user,&$tabMenu,&$menu,$noout=0,$m
if (DOL_URL_ROOT) $shorturl = preg_replace('/^'.preg_quote(DOL_URL_ROOT,'/').'/','',$shorturl);
}

$url=preg_replace('/__LOGIN__/',$user->login,$url);
$shorturl=preg_replace('/__LOGIN__/',$user->login,$shorturl);
$url=preg_replace('/__USERID__/',$user->id,$url);
$shorturl=preg_replace('/__USERID__/',$user->id,$shorturl);

// TODO Find a generic solution
if (preg_match('/search_project_user=__search_project_user__/', $shorturl))
{
Expand Down Expand Up @@ -511,10 +503,13 @@ function print_left_auguria_menu($db,$menu_array_before,$menu_array_after,&$tabM
}
}

// $menu_array[$i]['url'] can be a relative url, a full external url. We try substitution
$substitarray = array('__LOGIN__' => $user->login, '__USER_ID__' => $user->id, '__USER_SUPERVISOR_ID__' => $user->fk_user);
$substitarray['__USERID__'] = $user->id; // For backward compatibility
$menu_array[$i]['url'] = make_substitutions($menu_array[$i]['url'], $substitarray);

// Add mainmenu in GET url. This make to go back on correct menu even when using Back on browser.
$url=dol_buildpath($menu_array[$i]['url'],1);
$url=preg_replace('/__LOGIN__/',$user->login,$url);
$url=preg_replace('/__USERID__/',$user->id,$url);

if (! preg_match('/mainmenu=/i',$menu_array[$i]['url']))
{
Expand Down
12 changes: 8 additions & 4 deletions htdocs/core/menus/standard/auguria_menu.php
Expand Up @@ -157,9 +157,11 @@ function showmenu($mode, $moredata=null)
print '<li class="lilevel0">';
if ($val['enabled'] == 1)
{
$substitarray = array('__LOGIN__' => $user->login, '__USER_ID__' => $user->id, '__USER_SUPERVISOR_ID__' => $user->fk_user);
$substitarray['__USERID__'] = $user->id; // For backward compatibility
$val['url'] = make_substitutions($val['url'], $substitarray);

$relurl=dol_buildpath($val['url'],1);
$relurl=preg_replace('/__LOGIN__/',$user->login,$relurl);
$relurl=preg_replace('/__USERID__/',$user->id,$relurl);
$canonurl=preg_replace('/\?.*$/','',$val['url']);

print '<a class="alilevel0" href="#">';
Expand Down Expand Up @@ -233,9 +235,11 @@ function showmenu($mode, $moredata=null)

if ($showmenu) // Visible (option to hide when not allowed is off or allowed)
{
$substitarray = array('__LOGIN__' => $user->login, '__USER_ID__' => $user->id, '__USER_SUPERVISOR_ID__' => $user->fk_user);
$substitarray['__USERID__'] = $user->id; // For backward compatibility
$val2['url'] = make_substitutions($val2['url'], $substitarray);

$relurl2=dol_buildpath($val2['url'],1);
$relurl2=preg_replace('/__LOGIN__/',$user->login,$relurl2);
$relurl2=preg_replace('/__USERID__/',$user->id,$relurl2);
$canonurl2=preg_replace('/\?.*$/','',$val2['url']);
//var_dump($val2['url'].' - '.$canonurl2.' - '.$val2['level']);
if (in_array($canonurl2,array('/admin/index.php','/admin/tools/index.php','/core/tools.php'))) $relurl2='';
Expand Down
25 changes: 10 additions & 15 deletions htdocs/core/menus/standard/eldy.lib.php
Expand Up @@ -273,7 +273,6 @@ function print_eldy_menu($db,$atarget,$type_user,&$tabMenu,&$menu,$noout=0,$mode
$menu->add('/adherents/index.php?mainmenu=members&amp;leftmenu=', $langs->trans("MenuMembers"), 0, $showmode, $atarget, "members", '', 100, $id, $idsel, $classname);
}


// Show personalized menus
$menuArbo = new Menubase($db,'eldy');
$newTabMenu = $menuArbo->menuTopCharger('','',$type_user,'eldy',$tabMenu); // Return tabMenu with only top entries
Expand All @@ -286,6 +285,10 @@ function print_eldy_menu($db,$atarget,$type_user,&$tabMenu,&$menu,$noout=0,$mode
$showmode=isVisibleToUserType($type_user,$newTabMenu[$i],$listofmodulesforexternal);
if ($showmode == 1)
{
$substitarray = array('__LOGIN__' => $user->login, '__USER_ID__' => $user->id, '__USER_SUPERVISOR_ID__' => $user->fk_user);
$substitarray['__USERID__'] = $user->id; // For backward compatibility
$newTabMenu[$i]['url'] = make_substitutions($newTabMenu[$i]['url'], $substitarray);

// url = url from host, shorturl = relative path into dolibarr sources
$url = $shorturl = $newTabMenu[$i]['url'];
if (! preg_match("/^(http:\/\/|https:\/\/)/i",$newTabMenu[$i]['url'])) // Do not change url content for external links
Expand All @@ -301,10 +304,6 @@ function print_eldy_menu($db,$atarget,$type_user,&$tabMenu,&$menu,$noout=0,$mode
$shorturl = $url;
if (DOL_URL_ROOT) $shorturl = preg_replace('/^'.preg_quote(DOL_URL_ROOT,'/').'/','',$shorturl);
}
$url=preg_replace('/__LOGIN__/',$user->login,$url);
$shorturl=preg_replace('/__LOGIN__/',$user->login,$shorturl);
$url=preg_replace('/__USERID__/',$user->id,$url);
$shorturl=preg_replace('/__USERID__/',$user->id,$shorturl);

// Define the class (top menu selected or not)
if (! empty($_SESSION['idmenu']) && $newTabMenu[$i]['rowid'] == $_SESSION['idmenu']) $classname='class="tmenusel"';
Expand Down Expand Up @@ -1598,12 +1597,10 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu
}
}

// $menu_array[$i]['url'] can be a relative url, a full external url or a dynamic value like '$conf->global->APARAM)
if (preg_match('/^\$conf->global->([^\?]+)/', $menu_array[$i]['url'], $reg))
{
$keyforsconst=$reg[1];
$menu_array[$i]['url'] = $conf->global->$keyforsconst;
}
// $menu_array[$i]['url'] can be a relative url, a full external url. We try substitution
$substitarray = array('__LOGIN__' => $user->login, '__USER_ID__' => $user->id, '__USER_SUPERVISOR_ID__' => $user->fk_user);
$substitarray['__USERID__'] = $user->id; // For backward compatibility
$menu_array[$i]['url'] = make_substitutions($menu_array[$i]['url'], $substitarray);

$url = $shorturl = $menu_array[$i]['url'];

Expand All @@ -1626,11 +1623,8 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu
$url = dol_buildpath($url,1).($param?'?'.$param:'');
$shorturl = $shorturl.($param?'?'.$param:'');
}
//var_dump($url);

$url=preg_replace('/__LOGIN__/',$user->login,$url);
$shorturl=preg_replace('/__LOGIN__/',$user->login,$shorturl);
$url=preg_replace('/__USERID__/',$user->id,$url);
$shorturl=preg_replace('/__USERID__/',$user->id,$shorturl);

print '<!-- Process menu entry with mainmenu='.$menu_array[$i]['mainmenu'].', leftmenu='.$menu_array[$i]['leftmenu'].', level='.$menu_array[$i]['level'].' enabled='.$menu_array[$i]['enabled'].', position='.$menu_array[$i]['position'].' -->'."\n";

Expand All @@ -1656,6 +1650,7 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu
print '<div class="menu_top"></div>'."\n";
}
}

// Menu level > 0
if ($menu_array[$i]['level'] > 0)
{
Expand Down
12 changes: 8 additions & 4 deletions htdocs/core/menus/standard/eldy_menu.php
Expand Up @@ -165,9 +165,11 @@ function showmenu($mode, $moredata=null)

if ($val['enabled'] == 1)
{
$substitarray = array('__LOGIN__' => $user->login, '__USER_ID__' => $user->id, '__USER_SUPERVISOR_ID__' => $user->fk_user);
$substitarray['__USERID__'] = $user->id; // For backward compatibility
$val['url'] = make_substitutions($val['url'], $substitarray);

$relurl=dol_buildpath($val['url'],1);
$relurl=preg_replace('/__LOGIN__/',$user->login,$relurl);
$relurl=preg_replace('/__USERID__/',$user->id,$relurl);
$canonurl=preg_replace('/\?.*$/','',$val['url']);

print '<a class="alilevel0" href="#">';
Expand Down Expand Up @@ -243,9 +245,11 @@ function showmenu($mode, $moredata=null)

if ($showmenu) // Visible (option to hide when not allowed is off or allowed)
{
$substitarray = array('__LOGIN__' => $user->login, '__USER_ID__' => $user->id, '__USER_SUPERVISOR_ID__' => $user->fk_user);
$substitarray['__USERID__'] = $user->id; // For backward compatibility
$val2['url'] = make_substitutions($val2['url'], $substitarray);

$relurl2=dol_buildpath($val2['url'],1);
$relurl2=preg_replace('/__LOGIN__/',$user->login,$relurl2);
$relurl2=preg_replace('/__USERID__/',$user->id,$relurl2);
$canonurl2=preg_replace('/\?.*$/','',$val2['url']);
//var_dump($val2['url'].' - '.$canonurl2.' - '.$val2['level']);
if (in_array($canonurl2,array('/admin/index.php','/admin/tools/index.php','/core/tools.php'))) $relurl2='';
Expand Down
25 changes: 17 additions & 8 deletions htdocs/core/menus/standard/empty.php
Expand Up @@ -150,11 +150,13 @@ function showmenu($mode, $moredata=null)
print '<ul class="ulmenu" data-inset="true">';
print '<li class="lilevel0">';

$substitarray = array('__LOGIN__' => $user->login, '__USER_ID__' => $user->id, '__USER_SUPERVISOR_ID__' => $user->fk_user);
$substitarray['__USERID__'] = $user->id; // For backward compatibility
$val['url'] = make_substitutions($val['url'], $substitarray);

if ($val['enabled'] == 1)
{
$relurl=dol_buildpath($val['url'],1);
$relurl=preg_replace('/__LOGIN__/',$user->login,$relurl);
$relurl=preg_replace('/__USERID__/',$user->id,$relurl);
$canonurl=preg_replace('/\?.*$/','',$val['url']);

print '<a class="alilevel0" href="#">';
Expand Down Expand Up @@ -249,9 +251,11 @@ function showmenu($mode, $moredata=null)

if ($showmenu) // Visible (option to hide when not allowed is off or allowed)
{
$substitarray = array('__LOGIN__' => $user->login, '__USER_ID__' => $user->id, '__USER_SUPERVISOR_ID__' => $user->fk_user);
$substitarray['__USERID__'] = $user->id; // For backward compatibility
$val2['url'] = make_substitutions($val2['url'], $substitarray);

$relurl2=dol_buildpath($val2['url'],1);
$relurl2=preg_replace('/__LOGIN__/',$user->login,$relurl2);
$relurl2=preg_replace('/__USERID__/',$user->id,$relurl2);
$canonurl2=preg_replace('/\?.*$/','',$val2['url']);
//var_dump($val2['url'].' - '.$canonurl2.' - '.$val2['level']);
if (in_array($canonurl2,array('/admin/index.php','/admin/tools/index.php','/core/tools.php'))) $relurl2='';
Expand Down Expand Up @@ -447,11 +451,14 @@ function showmenu($mode, $moredata=null)
{
print '<ul class="ulmenu" data-inset="true">';
print '<li class="lilevel0">';
$substitarray = array('__LOGIN__' => $user->login, '__USER_ID__' => $user->id, '__USER_SUPERVISOR_ID__' => $user->fk_user);
$substitarray['__USERID__'] = $user->id; // For backward compatibility
$val['url'] = make_substitutions($val['url'], $substitarray);
if ($val['enabled'] == 1)
{
$relurl=dol_buildpath($val['url'],1);
$relurl=preg_replace('/__LOGIN__/',$user->login,$relurl);
$relurl=preg_replace('/__USERID__/',$user->id,$relurl);
print '<a href="#">'.$val['titre'].'</a>'."\n";
// Search submenu fot this entry
Expand All @@ -474,9 +481,11 @@ function showmenu($mode, $moredata=null)
}
foreach($submenu->liste as $key2 => $val2) // $val['url','titre','level','enabled'=0|1|2,'target','mainmenu','leftmenu'
{
$substitarray = array('__LOGIN__' => $user->login, '__USER_ID__' => $user->id, '__USER_SUPERVISOR_ID__' => $user->fk_user);
$substitarray['__USERID__'] = $user->id; // For backward compatibility
$val2['url'] = make_substitutions($val2['url'], $substitarray);
$relurl2=dol_buildpath($val2['url'],1);
$relurl2=preg_replace('/__LOGIN__/',$user->login,$relurl2);
$relurl2=preg_replace('/__USERID__/',$user->id,$relurl2);
//var_dump($val2);
print '<li><a href="'.$relurl2.'">'.$val2['titre'].'</a></li>'."\n";
}
Expand Down
2 changes: 1 addition & 1 deletion htdocs/core/modules/modExternalSite.class.php
Expand Up @@ -104,7 +104,7 @@ function __construct($db)
$this->menu[$r]=array(
'fk_menu'=>0,
'type'=>'top',
'titre'=>'$conf->global->EXTERNALSITE_LABEL',
'titre'=>'__[EXTERNALSITE_LABEL]__',
'mainmenu'=>'externalsite',
'url'=>'/externalsite/frames.php',
'langs'=>'other',
Expand Down
1 change: 0 additions & 1 deletion htdocs/externalsite/admin/externalsite.php
Expand Up @@ -54,7 +54,6 @@

$i+=dolibarr_set_const($db,'EXTERNALSITE_LABEL',trim($label),'chaine',0,'',$conf->entity);
$i+=dolibarr_set_const($db,'EXTERNALSITE_URL',trim($exturl),'chaine',0,'',$conf->entity);
//$i+=dolibarr_set_const($db,'EXTERNALSITE_LABEL',trim($_POST["EXTERNALSITE_LABEL"]),'chaine',0,'',$conf->entity);

if ($i >= 2)
{
Expand Down
1 change: 0 additions & 1 deletion htdocs/theme/md/style.css.php
Expand Up @@ -452,7 +452,6 @@
input[type=checkbox] { background-color: transparent; border: none; box-shadow: none; }
input[type=radio] { background-color: transparent; border: none; box-shadow: none; }
input[type=image] { background-color: transparent; border: none; box-shadow: none; }
input[type=text] { min-width: 20px; }
input:-webkit-autofill {
background-color: #FBFFEA !important;
background-image:none !important;
Expand Down

0 comments on commit e3dcff7

Please sign in to comment.