I use XOOPS 2.05
I have been adapting iMenu for my purposes, but have come across problems right near the end of my struggles which I cannot seem to fix. I have managed fine to adapt the admin section and the menu to display submenus as you can see at
http://www.chillout.org.uk.
However, I am having difficulties in making the sub menu items hide properly. I am going for a very simple approach, just basing it on the module rather than a full heirachical database-driven solution.
index.php
<?php function b_imenu_show($options) { global $xoopsDB,$xoopsUser; $myts =& MyTextSanitizer::getInstance(); $block = array(); $group = is_object($xoopsUser) ? $xoopsUser->getGroups() : array(XOOPS_GROUP_ANONYMOUS); $result = $xoopsDB->query("SELECT groups, link, submenu, title, target FROM ".$xoopsDB->prefix("imenu")." WHERE hide=0 ORDER BY weight ASC"); while ( $myrow = $xoopsDB->fetchArray($result) ) { $title = $myts->makeTboxData4Show($myrow["title"]); if ( !XOOPS_USE_MULTIBYTES ) { if (strlen($myrow['title']) >= $options[0]) { $title = $myts->makeTboxData4Show(substr($myrow['title'],0,($options[0]-1)))."..."; } } $groups = explode(" ",$myrow['groups']); if (count(array_intersect($group,$groups)) > 0) { $imenu['title'] = $title; $imenu['target'] = $myrow['target']; $imenu['link'] = $myrow['link']; $linkaddr = explode("/", $imenu['link']); $linkmodule = $linkaddr[2]; $path = getenv('REQUEST_URI'); $var1 = explode(".", $path); $var2 = explode("/", $var1[0]); $presentmodule = $var2[2]; $imenu['submenu'] = $myrow['submenu']; if (eregi("^[([a-z0-9]+)]$", $myrow['link'], $moduledir)) { $module_handler = & xoops_gethandler( 'module' ); $module =& $module_handler->getByDirname($moduledir[1]); if ( is_object( $module ) && $module->getVar( 'isactive' ) ) { $imenu['link'] = XOOPS_URL."/modules/".$moduledir[1]; } } if ($presentmodule == $linkmodule) {$submenushow = "1"; $xoopsTpl->assign('submenushow', $submenushow);} $block['contents'][] = $imenu; } } return $block; } function b_imenu_edit($options) { $form = _IM_IMENU_CHARS." <input type='text' name='options[]' value='".$options[0]."' /> "._IM_IMENU_LENGTH.""; return $form; } ?>
imenu_block.html
le="color: #000000"><?php <table cellspacing="0"> <tr> <td id="mainmenu"> <{assign var="submenushow" value="0"}> <!-- start module menu loop --> <{foreach item=imenu from=$block.contents}> <{if (($imenu.link != "") AND ($imenu.submenu =="0"))}> <a class="menuMain" href="<{$imenu.link}>" target="<{$imenu.target}>"><{$imenu.title}></a> <{elseif (($imenu.link != "") AND ($imenu.submenu =="1") )}> <a class="menuSub" href="<{$imenu.link}>" target="<{$imenu.target}>"><{$imenu.title}></a> <{/if}> <{/foreach}> <!-- end module menu loop --> </td> </tr> </table>
Basically i picked out the /modulename/ part of the REQUEST_URI and then took the same bit out of the links. Then the idea is that if they are the same, I would make the variable $submenushow = 1 and in the smarty template, I would say <{if $submenushow == 1}> then display the sub menu item, else dont. Simple in concept, but I am not sure if I have done this bit correctly.
The problem arises when I try and use the code
le="color: #000000"><?php if ($presentmodule == $linkmodule) {$submenushow = "1"; $xoopsTpl->assign('submenushow', $submenushow);}
I get:
Quote:
Fatal error: Call to a member function on a non-object in /home/chillout/public_html/modules/iMenu/blocks/imenu.php on line 37
Furthermore, when I use
le="color: #000000"><?php <{elseif (($imenu.link != "") AND ($imenu.submenu =="1") AND ($submenushow == 1))}> <a class="menuSub" href="<{$imenu.link}>" target="<{$imenu.target}>"><{$imenu.title}></a>
I get Quote:
Fatal error: Call to a member function on a non-object in /home/chillout/public_html/modules/iMenu/blocks/imenu.php on line 37
So I think there is an error in my coding in both of these files. Please can someone who is better at PHP help me. Thanks.
(my site may look fine because I have commented these tricky bits out to maintain functionality for now).
Simon