1
gppetersen
Adding menu highlighting and a hook for bread-crumbs
  • 2004/12/3 4:15

  • gppetersen

  • Just popping in

  • Posts: 3

  • Since: 2004/11/23


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 hope this is the right 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.

limitations:
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 system_block_mainmenu.html
// TODO: use the language file for 'Home'
$block['modules'][0]['name'] = 'Home';
$block['modules'][0]['directory'] = '';
if ($gpcurrentmenu == ""){
$block['modules'][0]['current'] = 1;
}else{
$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'] = $modules[$i]->getVar('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/' . $modules[$i]->getVar('dirname');
// GPP set/clear .current if this is [not]where we are.
if ($block['modules'][$i]['directory'] == $gpcurrentmenu){
$block['modules'][$i]['current'] = 1;
}else{
$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' => XOOPS_URL.'/modules/'.$modules[$i]->getVar('dirname').'/'.$sublink['url']);
}else{
$block['modules'][$i]['sublinks'][] = array('current' => 0, 'name' => $sublink['name'], 'url' => XOOPS_URL.'/modules/'.$modules[$i]->getVar('dirname').'/'.$sublink['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;
}



system_block_mainmenu.html:






xoops.css:
#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.

2
jayrex
Re: Adding menu highlighting and a hook for bread-crumbs
  • 2004/12/15 13:28

  • jayrex

  • Just popping in

  • Posts: 13

  • Since: 2004/12/15


this seems like exactly the thing i'm looking for

but could you please give a little more indication on how i can display a breadcrumb using this code? that would help a lot, thanx!

3
jayrex
Re: Adding menu highlighting and a hook for bread-crumbs
  • 2004/12/15 13:28

  • jayrex

  • Just popping in

  • Posts: 13

  • Since: 2004/12/15


this seems like exactly the thing i'm looking for

but could you please give a little more indication on how i can display a breadcrumb using this code? that would help a lot, thanx!

edit: woops, something went wrong, sorry for the double post, my bad.

4
gppetersen
Re: Adding menu highlighting and a hook for bread-crumbs
  • 2004/12/16 6:05

  • gppetersen

  • Just popping in

  • Posts: 3

  • Since: 2004/11/23


The best solution would be create a new block for the breadcrumb.
But, if you don't need the side menu, you could use a different system_block_mainmenu.html and the menu block will make a bread crumb.
WTF is up with the preview here ???
(warning I'm thinking off the top of my head and haven't tried this code:)





5
jayrex
Re: Adding menu highlighting and a hook for bread-crumbs
  • 2004/12/29 13:39

  • jayrex

  • Just popping in

  • Posts: 13

  • Since: 2004/12/15


thanks a lot, gppetersen

i'm very busy with other stuff at the moment, but i'll definitely try it as soon as i can

cheers!

6
jayrex
Re: Adding menu highlighting and a hook for bread-crumbs
  • 2004/12/30 10:43

  • jayrex

  • Just popping in

  • Posts: 13

  • Since: 2004/12/15


it doesnt work and i'm afraid i'm too big a xoopsn00b to understand why

i updated system_blocks.php (Only the function b_system_main_show())

and then tried adding the code of your last post in a template (maybe that isn't what you meant?).

7
DogTags
Re: Adding menu highlighting and a hook for bread-crumbs
  • 2005/4/30 14:14

  • DogTags

  • Just popping in

  • Posts: 50

  • Since: 2004/12/4


Did this get fixed/working?

Would love to have breadcrumb capability

8
LazyBadger
Re: Adding menu highlighting and a hook for bread-crumbs

Did you update module System after editing system_blocks.php ?!

9
LazyBadger
Re: Adding menu highlighting and a hook for bread-crumbs

Quote:

gppetersen wrote:
This is a hack to allow the current menu and sub menu selection to be high-lighted.

Just dirty thinking...
If you define current as string (f.e "0|1"), you can have slightly modified CSS after it, and use instead of current
td#mainmenu pair like
td#mainmenu0
td#mainmenu1
and have CSS-classes in template changed with smarty-var accordinly

BTW - I'll try your idea in my new theme

10
DogTags
Re: Adding menu highlighting and a hook for bread-crumbs
  • 2005/4/30 21:47

  • DogTags

  • Just popping in

  • Posts: 50

  • Since: 2004/12/4


Where is this found?

system_block_mainmenu.html

xoops 2.0.10

Many thanks

Login

Who's Online

304 user(s) are online (113 user(s) are browsing Support Forums)


Members: 0


Guests: 304


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Nov 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits