#77 Adding menu highlighting and a hook for bread-crumbs

Grant Petersen

This is a hack to allow the current menu and sub menu
selection to be high-lighted.
It could also form the base for a breadcrumb block.

I have posted this to the Module hack reviews forum.

The idea is to add a .current var to the $blocks array
that is used by system_block_mainmenu.html.
Smarty logic can then be used to make the current
selection look different.

A bread crumb block could loop through the $blocks the
way system_block_mainmenu.html does and use only the
.current links to make a bread crumb trail.

If you have a module as your default page, the home
link will not be high lighted.

3 files are changed:
Changes required to modules/system/blocks/system_blocks.php
Changes required to system_block_mainmenu.html
Changes optional to /xoops.css to indicate the current
menu choice.

system_blocks.php: (Only the function b_system_main_show()
is changed. Here it is.)

// GPP added .current to module and sublink allow color
menu and bread crumbs
// NB:: requires changes to system_block_mainmenu.html!
function b_system_main_show()
/ GPP seems to generate the info for the menu
add $block[modules][$i][current] set if we are on
this page.
$blockmodules[$i][sublinks][$j][current] set if we
are using this sublink.
// Get the module path and any script name.
$gppath = pathinfo($_SERVER['PHP_SELF']);
$gpcurrentsub = $gppath['basename'];
$gpcurrentmenu = $gppath['dirname'];
// special case: home should be "" not "/"
if ($gpcurrentmenu == "/"){
$gpcurrentmenu = "";
// normal service resumes...
global $xoopsUser,$xoopsModule;
$block = array();
$block['lang_home'] = _MB_SYSTEM_HOME;
$block['lang_close'] = _CLOSE;
$module_handler =& xoops_gethandler('module');
$criteria = new CriteriaCompo(new Criteria('hasmain', 1));
$criteria->add(new Criteria('isactive', 1));
$criteria->add(new Criteria('weight', 0, '>'));
$modules =& $module_handler->getObjects($criteria, true);
$moduleperm_handler =& xoops_gethandler('groupperm');
$groups = is_object($xoopsUser) ?
$xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS;
$read_allowed =&
$moduleperm_handler->getItemIds('module_read', $groups);
// GPP add the home entry here not in
// TODO: use the language file for 'Home'
$block['modules'][0]['name'] = 'Home';
$block['modules'][0]['directory'] = '';
if ($gpcurrentmenu == ""){
$block['modules'][0]['current'] = 1;
$block['modules'][0]['current'] = 0;
$block['modules'][0]['sublinks'] = array();
// resume normal service
foreach (array_keys($modules) as $i) {
if (in_array($i, $read_allowed)) {
$block['modules'][$i]['name'] =
// GPP put the full path in dirname so we don't have to
add it in
// system_block_mainmenu.html and tests look better.
$block['modules'][$i]['directory'] = '/modules/' .
// GPP set/clear .current if this is [not]where we are.
if ($block['modules'][$i]['directory'] == $gpcurrentmenu){
$block['modules'][$i]['current'] = 1;
$block['modules'][$i]['current'] = 0;
$sublinks =& $modules[$i]->subLink();
if ((count($sublinks) > 0) && (!empty($xoopsModule)) &&
($i == $xoopsModule->getVar('mid'))) {
foreach($sublinks as $sublink){
// GPP add .current=[1|0] if we are [not]using this
link to the sublinks.
if ($sublink['url'] == $gpcurrentsub){
$block['modules'][$i]['sublinks'][] = array('current'
=> 1, 'name' => $sublink['name'], 'url' =>
$block['modules'][$i]['sublinks'][] = array('current'
=> 0, 'name' => $sublink['name'], 'url' =>
} else {
$block['modules'][$i]['sublinks'] = array();

/ GPP No more changes to system_blocks.php
Other files that are affected:
Changes required to system_block_mainmenu.html
Changes optional to xoops.css to indicate the current
menu choice.
return $block;



mainmenu a {text-align:left; display: block; margin:

0; padding: 4px;}

mainmenu a.menuTop {padding-left: 2px;}

mainmenu a.menuMain {padding-left: 4px; font-weight:

normal; background-color: #FFFFFF;}

mainmenu a.menuMainAct {padding-left: 4px;

font-weight: bold; background-color: #E0E0E0;}

mainmenu a.menuSub {padding-left: 10px; font-weight:

normal; background-color: #E0E0E0;}

mainmenu a.menuSubAct {padding-left: 10px;

font-weight: bold; background-color: #C0C0C0;}

Thanks - Grant.