Annotation of /mambo/branches/4.5.3h/modules/mod_mainmenu.php
Parent Directory
|
Revision Log
Revision 22 - (view) (download)
| 1 : | root | 1 | <?php |
| 2 : | /** | ||
| 3 : | * @version $Id: mod_mainmenu.php,v 1.2 2005/08/02 08:21:53 akede Exp $ | ||
| 4 : | * @package Mambo | ||
| 5 : | * @copyright (C) 2000 - 2005 Miro International Pty Ltd | ||
| 6 : | * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL | ||
| 7 : | * Mambo is Free Software | ||
| 8 : | */ | ||
| 9 : | |||
| 10 : | /** ensure this file is being included by a parent file */ | ||
| 11 : | defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' ); | ||
| 12 : | |||
| 13 : | if (!defined( '_MOS_MAINMENU_MODULE' )) { | ||
| 14 : | /** ensure that functions are declared only once */ | ||
| 15 : | define( '_MOS_MAINMENU_MODULE', 1 ); | ||
| 16 : | |||
| 17 : | /** | ||
| 18 : | * Utility function for writing a menu link | ||
| 19 : | */ | ||
| 20 : | function mosGetMenuLink( $mitem, $level=0, &$params ) { | ||
| 21 : | global $Itemid, $mosConfig_live_site, $mainframe; | ||
| 22 : | $txt = ''; | ||
| 23 : | |||
| 24 : | switch ($mitem->type) { | ||
| 25 : | case 'separator': | ||
| 26 : | case 'component_item_link': | ||
| 27 : | break; | ||
| 28 : | case 'content_item_link': | ||
| 29 : | $temp = split("&task=view&id=", $mitem->link); | ||
| 30 : | $mitem->link .= '&Itemid='. $mainframe->getItemid($temp[1]); | ||
| 31 : | break; | ||
| 32 : | case 'url': | ||
| 33 : | if ( eregi( 'index.php\?', $mitem->link ) ) { | ||
| 34 : | if ( !eregi( 'Itemid=', $mitem->link ) ) { | ||
| 35 : | $mitem->link .= '&Itemid='. $mitem->id; | ||
| 36 : | } | ||
| 37 : | } | ||
| 38 : | break; | ||
| 39 : | case 'content_typed': | ||
| 40 : | default: | ||
| 41 : | $mitem->link .= '&Itemid='. $mitem->id; | ||
| 42 : | break; | ||
| 43 : | } | ||
| 44 : | |||
| 45 : | // Active Menu highlighting | ||
| 46 : | $current_itemid = $Itemid; | ||
| 47 : | if ( !$current_itemid ) { | ||
| 48 : | $id = ''; | ||
| 49 : | } else if ( $current_itemid == $mitem->id ) { | ||
| 50 : | $id = 'id="active_menu'. $params->get( 'class_sfx' ) .'"'; | ||
| 51 : | } else { | ||
| 52 : | $id = ''; | ||
| 53 : | } | ||
| 54 : | |||
| 55 : | $mitem->link = ampReplace( $mitem->link ); | ||
| 56 : | |||
| 57 : | if ( strcasecmp( substr( $mitem->link,0,4 ), 'http' ) ) { | ||
| 58 : | $mitem->link = sefRelToAbs( $mitem->link ); | ||
| 59 : | } | ||
| 60 : | |||
| 61 : | $menuclass = 'mainlevel'. $params->get( 'class_sfx' ); | ||
| 62 : | if ($level > 0) { | ||
| 63 : | $menuclass = 'sublevel'. $params->get( 'class_sfx'); | ||
| 64 : | } | ||
| 65 : | |||
| 66 : | switch ($mitem->browserNav) { | ||
| 67 : | // cases are slightly different | ||
| 68 : | case 1: | ||
| 69 : | // open in a new window | ||
| 70 : | $txt = '<a href="'. $mitem->link .'" target="_blank" class="'. $menuclass .'" '. $id .'>'. $mitem->name .'</a>'; | ||
| 71 : | break; | ||
| 72 : | |||
| 73 : | case 2: | ||
| 74 : | // open in a popup window | ||
| 75 : | $txt = "<a href=\"#\" onclick=\"javascript: window.open('". $mitem->link ."', '', 'toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=780,height=550'); return false\" class=\"$menuclass\" ". $id .">". $mitem->name ."</a>\n"; | ||
| 76 : | break; | ||
| 77 : | |||
| 78 : | case 3: | ||
| 79 : | // don't link it | ||
| 80 : | $txt = '<span class="'. $menuclass .'" '. $id .'>'. $mitem->name .'</span>'; | ||
| 81 : | break; | ||
| 82 : | |||
| 83 : | default: // formerly case 2 | ||
| 84 : | // open in parent window | ||
| 85 : | $txt = '<a href="'. $mitem->link .'" class="'. $menuclass .'" '. $id .'>'. $mitem->name .'</a>'; | ||
| 86 : | break; | ||
| 87 : | } | ||
| 88 : | |||
| 89 : | if ( $params->get( 'menu_images' ) ) { | ||
| 90 : | $menu_params = new stdClass(); | ||
| 91 : | $menu_params =& new mosParameters( $mitem->params ); | ||
| 92 : | $menu_image = $menu_params->def( 'menu_image', -1 ); | ||
| 93 : | if ( ( $menu_image <> '-1' ) && $menu_image ) { | ||
| 94 : | $image = '<img src="'. $mosConfig_live_site .'/images/stories/'. $menu_image .'" border="0" alt="'. $mitem->name .'"/>'; | ||
| 95 : | if ( $params->get( 'menu_images_align' ) ) { | ||
| 96 : | $txt = $txt .' '. $image; | ||
| 97 : | } else { | ||
| 98 : | $txt = $image .' '. $txt; | ||
| 99 : | } | ||
| 100 : | } | ||
| 101 : | } | ||
| 102 : | |||
| 103 : | return $txt; | ||
| 104 : | } | ||
| 105 : | |||
| 106 : | /** | ||
| 107 : | * Vertically Indented Menu | ||
| 108 : | */ | ||
| 109 : | function mosShowVIMenu( &$params ) { | ||
| 110 : | global $database, $my, $cur_template, $Itemid; | ||
| 111 : | global $mosConfig_absolute_path, $mosConfig_live_site, $mosConfig_shownoauth; | ||
| 112 : | |||
| 113 : | /* If a user has signed in, get their user type */ | ||
| 114 : | $intUserType = 0; | ||
| 115 : | if($my->gid){ | ||
| 116 : | switch ($my->usertype) { | ||
| 117 : | case 'Super Administrator': | ||
| 118 : | $intUserType = 0; | ||
| 119 : | break; | ||
| 120 : | case 'Administrator': | ||
| 121 : | $intUserType = 1; | ||
| 122 : | break; | ||
| 123 : | case 'Editor': | ||
| 124 : | $intUserType = 2; | ||
| 125 : | break; | ||
| 126 : | case 'Registered': | ||
| 127 : | $intUserType = 3; | ||
| 128 : | break; | ||
| 129 : | case 'Author': | ||
| 130 : | $intUserType = 4; | ||
| 131 : | break; | ||
| 132 : | case 'Publisher': | ||
| 133 : | $intUserType = 5; | ||
| 134 : | break; | ||
| 135 : | case 'Manager': | ||
| 136 : | $intUserType = 6; | ||
| 137 : | break; | ||
| 138 : | } | ||
| 139 : | } else { | ||
| 140 : | /* user isn't logged in so make their usertype 0 */ | ||
| 141 : | $intUserType = 0; | ||
| 142 : | } | ||
| 143 : | |||
| 144 : | if ($mosConfig_shownoauth) { | ||
| 145 : | $sql = "SELECT m.* FROM #__menu AS m" | ||
| 146 : | . "\nWHERE menutype='". $params->get( 'menutype' ) ."' AND published='1'" | ||
| 147 : | . "\nORDER BY parent,ordering"; | ||
| 148 : | } else { | ||
| 149 : | $sql = "SELECT m.* FROM #__menu AS m" | ||
| 150 : | . "\nWHERE menutype='". $params->get( 'menutype' ) ."' AND published='1' AND access <= '$my->gid'" | ||
| 151 : | . "\nORDER BY parent,ordering"; | ||
| 152 : | } | ||
| 153 : | $database->setQuery( $sql ); | ||
| 154 : | $rows = $database->loadObjectList( 'id' ); | ||
| 155 : | |||
| 156 : | // indent icons | ||
| 157 : | switch ( $params->get( 'indent_image' ) ) { | ||
| 158 : | case '1': | ||
| 159 : | // Default images | ||
| 160 : | $imgpath = $mosConfig_live_site .'/images/M_images'; | ||
| 161 : | for ( $i = 1; $i < 7; $i++ ) { | ||
| 162 : | $img[$i] = '<img src="'. $imgpath .'/indent'. $i .'.png" alt="" />'; | ||
| 163 : | } | ||
| 164 : | break; | ||
| 165 : | case '2': | ||
| 166 : | // Use Params | ||
| 167 : | $imgpath = $mosConfig_live_site .'/images/M_images'; | ||
| 168 : | for ( $i = 1; $i < 7; $i++ ) { | ||
| 169 : | if ( $params->get( 'indent_image'. $i ) == '-1' ) { | ||
| 170 : | $img[$i] = NULL; | ||
| 171 : | } else { | ||
| 172 : | $img[$i] = '<img src="'. $imgpath .'/'. $params->get( 'indent_image'. $i ) .'" alt="" />'; | ||
| 173 : | } | ||
| 174 : | } | ||
| 175 : | break; | ||
| 176 : | case '3': | ||
| 177 : | // None | ||
| 178 : | for ( $i = 1; $i < 7; $i++ ) { | ||
| 179 : | $img[$i] = NULL; | ||
| 180 : | } | ||
| 181 : | break; | ||
| 182 : | default: | ||
| 183 : | // Template | ||
| 184 : | $imgpath = $mosConfig_live_site .'/templates/'. $cur_template .'/images'; | ||
| 185 : | for ( $i = 1; $i < 7; $i++ ) { | ||
| 186 : | $img[$i] = '<img src="'. $imgpath .'/indent'. $i .'.png" alt="" />'; | ||
| 187 : | } | ||
| 188 : | break; | ||
| 189 : | } | ||
| 190 : | |||
| 191 : | $indents = array( | ||
| 192 : | // block prefix / item prefix / item suffix / block suffix | ||
| 193 : | array( '<table width="100%" border="0" cellpadding="0" cellspacing="0">', '<tr align="left"><td>' , '</td></tr>', '</table>' ), | ||
| 194 : | array( '', '<div style="padding-left: 4px">'. $img[1] , '</div>', '' ), | ||
| 195 : | array( '', '<div style="padding-left: 8px">'. $img[2] , '</div>', '' ), | ||
| 196 : | array( '', '<div style="padding-left: 12px">'. $img[3] , '</div>', '' ), | ||
| 197 : | array( '', '<div style="padding-left: 16px">'. $img[4] , '</div>', '' ), | ||
| 198 : | array( '', '<div style="padding-left: 20px">'. $img[5] , '</div>', '' ), | ||
| 199 : | array( '', '<div style="padding-left: 24px">'. $img[6] , '</div>', '' ), | ||
| 200 : | ); | ||
| 201 : | |||
| 202 : | // establish the hierarchy of the menu | ||
| 203 : | $children = array(); | ||
| 204 : | // first pass - collect children | ||
| 205 : | foreach ($rows as $v ) { | ||
| 206 : | $pt = $v->parent; | ||
| 207 : | $list = @$children[$pt] ? $children[$pt] : array(); | ||
| 208 : | array_push( $list, $v ); | ||
| 209 : | $children[$pt] = $list; | ||
| 210 : | } | ||
| 211 : | |||
| 212 : | // second pass - collect 'open' menus | ||
| 213 : | $open = array( $Itemid ); | ||
| 214 : | $count = 20; // maximum levels - to prevent runaway loop | ||
| 215 : | $id = $Itemid; | ||
| 216 : | while (--$count) { | ||
| 217 : | if (isset($rows[$id]) && $rows[$id]->parent > 0) { | ||
| 218 : | $id = $rows[$id]->parent; | ||
| 219 : | $open[] = $id; | ||
| 220 : | } else { | ||
| 221 : | break; | ||
| 222 : | } | ||
| 223 : | } | ||
| 224 : | mosRecurseVIMenu( 0, 0, $children, $open, $indents, $params ); | ||
| 225 : | |||
| 226 : | } | ||
| 227 : | |||
| 228 : | /** | ||
| 229 : | * Utility function to recursively work through a vertically indented | ||
| 230 : | * hierarchial menu | ||
| 231 : | */ | ||
| 232 : | function mosRecurseVIMenu( $id, $level, &$children, &$open, &$indents, &$params ) { | ||
| 233 : | global $Itemid; | ||
| 234 : | if (@$children[$id]) { | ||
| 235 : | $n = min( $level, count( $indents )-1 ); | ||
| 236 : | |||
| 237 : | echo "\n".$indents[$n][0]; | ||
| 238 : | foreach ($children[$id] as $row) { | ||
| 239 : | |||
| 240 : | echo "\n".$indents[$n][1]; | ||
| 241 : | |||
| 242 : | echo mosGetMenuLink( $row, $level, $params ); | ||
| 243 : | |||
| 244 : | // show menu with menu expanded - submenus visible | ||
| 245 : | if ( !$params->get( 'expand_menu' ) ) { | ||
| 246 : | if ( in_array( $row->id, $open )) { | ||
| 247 : | mosRecurseVIMenu( $row->id, $level+1, $children, $open, $indents, $params ); | ||
| 248 : | } | ||
| 249 : | } else { | ||
| 250 : | mosRecurseVIMenu( $row->id, $level+1, $children, $open, $indents, $params ); | ||
| 251 : | } | ||
| 252 : | echo $indents[$n][2]; | ||
| 253 : | } | ||
| 254 : | echo "\n".$indents[$n][3]; | ||
| 255 : | } | ||
| 256 : | } | ||
| 257 : | |||
| 258 : | /** | ||
| 259 : | * Draws a horizontal 'flat' style menu (very simple case) | ||
| 260 : | */ | ||
| 261 : | function mosShowHFMenu( &$params, $style=0 ) { | ||
| 262 : | global $database, $my, $cur_template, $Itemid; | ||
| 263 : | global $mosConfig_absolute_path, $mosConfig_shownoauth; | ||
| 264 : | |||
| 265 : | if ($mosConfig_shownoauth) { | ||
| 266 : | $sql = "SELECT m.* FROM #__menu AS m" | ||
| 267 : | . "\nWHERE menutype='". $params->get( 'menutype' ) ."' AND published='1' AND parent='0'" | ||
| 268 : | . "\nORDER BY ordering"; | ||
| 269 : | } else { | ||
| 270 : | $sql = "SELECT m.* FROM #__menu AS m" | ||
| 271 : | . "\nWHERE menutype='". $params->get( 'menutype' ) ."' AND published='1' AND access <= '$my->gid' AND parent='0'" | ||
| 272 : | . "\nORDER BY ordering"; | ||
| 273 : | } | ||
| 274 : | $database->setQuery( $sql ); | ||
| 275 : | |||
| 276 : | $rows = $database->loadObjectList( 'id' ); | ||
| 277 : | |||
| 278 : | $links = array(); | ||
| 279 : | foreach ($rows as $row) { | ||
| 280 : | $links[] = mosGetMenuLink( $row, 0, $params ); | ||
| 281 : | } | ||
| 282 : | |||
| 283 : | $menuclass = 'mainlevel'. $params->get( 'class_sfx' ); | ||
| 284 : | if (count( $links )) { | ||
| 285 : | switch ($style) { | ||
| 286 : | case 1: | ||
| 287 : | echo '<ul id="'. $menuclass .'">'; | ||
| 288 : | foreach ($links as $link) { | ||
| 289 : | echo '<li>' . $link . '</li>'; | ||
| 290 : | } | ||
| 291 : | echo '</ul>'; | ||
| 292 : | break; | ||
| 293 : | default: | ||
| 294 : | echo '<table width="100%" border="0" cellpadding="0" cellspacing="1">'; | ||
| 295 : | echo '<tr>'; | ||
| 296 : | echo '<td nowrap="nowrap">'; | ||
| 297 : | echo '<span class="'. $menuclass .'"> '. $params->get( 'end_spacer' ) .' </span>'; | ||
| 298 : | echo implode( '<span class="'. $menuclass .'"> '. $params->get( 'spacer' ) .' </span>', $links ); | ||
| 299 : | echo '<span class="'. $menuclass .'"> '. $params->get( 'end_spacer' ) .' </span>'; | ||
| 300 : | echo '</td></tr>'; | ||
| 301 : | echo '</table>'; | ||
| 302 : | break; | ||
| 303 : | } | ||
| 304 : | } | ||
| 305 : | } | ||
| 306 : | } | ||
| 307 : | $params->def( 'menutype', 'mainmenu' ); | ||
| 308 : | $params->def( 'class_sfx', '' ); | ||
| 309 : | $params->def( 'menu_images', 0 ); | ||
| 310 : | $params->def( 'menu_images_align', 0 ); | ||
| 311 : | $params->def( 'expand_menu', 0 ); | ||
| 312 : | $params->def( 'indent_image', 0 ); | ||
| 313 : | $params->def( 'indent_image1', 'indent1.png' ); | ||
| 314 : | $params->def( 'indent_image2', 'indent2.png' ); | ||
| 315 : | $params->def( 'indent_image3', 'indent3.png' ); | ||
| 316 : | $params->def( 'indent_image4', 'indent4.png' ); | ||
| 317 : | $params->def( 'indent_image5', 'indent5.png' ); | ||
| 318 : | $params->def( 'indent_image6', 'indent.png' ); | ||
| 319 : | $params->def( 'spacer', '' ); | ||
| 320 : | $params->def( 'end_spacer', '' ); | ||
| 321 : | |||
| 322 : | $menu_style = $params->get( 'menu_style', 'vert_indent' ); | ||
| 323 : | |||
| 324 : | switch ( $menu_style ) { | ||
| 325 : | case 'list_flat': | ||
| 326 : | mosShowHFMenu( $params, 1 ); | ||
| 327 : | break; | ||
| 328 : | |||
| 329 : | case 'horiz_flat': | ||
| 330 : | mosShowHFMenu( $params, 0 ); | ||
| 331 : | break; | ||
| 332 : | |||
| 333 : | default: | ||
| 334 : | mosShowVIMenu( $params ); | ||
| 335 : | break; | ||
| 336 : | } | ||
| 337 : | ?> |
| ViewVC Help | |
| Powered by ViewVC 1.0.0 |
Web Hosting provided by Network Redux.

