[ Index ] |
|
Code source de Joomla 1.0.13 |
1 <?php 2 /** 3 * @version $Id: mod_mainmenu.php 5943 2006-12-06 13:23:38Z predator $ 4 * @package Joomla 5 * @copyright Copyright (C) 2005 Open Source Matters. All rights reserved. 6 * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php 7 * Joomla! is free software. This version may have been modified pursuant 8 * to the GNU General Public License, and as distributed it includes or 9 * is derivative of works licensed under the GNU General Public License or 10 * other free or open source software licenses. 11 * See COPYRIGHT.php for copyright notices and details. 12 */ 13 14 // no direct access 15 defined( '_VALID_MOS' ) or die( 'Restricted access' ); 16 17 if (!defined( '_MOS_MAINMENU_MODULE' )) { 18 /** ensure that functions are declared only once */ 19 define( '_MOS_MAINMENU_MODULE', 1 ); 20 21 /** 22 * Utility function for writing a menu link 23 */ 24 function mosGetMenuLink( $mitem, $level=0, &$params, $open=null ) { 25 global $Itemid, $mosConfig_live_site, $mainframe; 26 27 $txt = ''; 28 29 switch ($mitem->type) { 30 case 'separator': 31 case 'component_item_link': 32 break; 33 34 case 'url': 35 if ( eregi( 'index.php\?', $mitem->link ) && !eregi( 'http', $mitem->link ) && !eregi( 'https', $mitem->link ) ) { 36 if ( !eregi( 'Itemid=', $mitem->link ) ) { 37 $mitem->link .= '&Itemid='. $mitem->id; 38 } 39 } 40 break; 41 42 case 'content_item_link': 43 case 'content_typed': 44 // load menu params 45 $menuparams = new mosParameters( $mitem->params, $mainframe->getPath( 'menu_xml', $mitem->type ), 'menu' ); 46 47 $unique_itemid = $menuparams->get( 'unique_itemid', 1 ); 48 49 if ( $unique_itemid ) { 50 $mitem->link .= '&Itemid='. $mitem->id; 51 } else { 52 $temp = split('&task=view&id=', $mitem->link); 53 54 if ( $mitem->type == 'content_typed' ) { 55 $mitem->link .= '&Itemid='. $mainframe->getItemid($temp[1], 1, 0); 56 } else { 57 $mitem->link .= '&Itemid='. $mainframe->getItemid($temp[1], 0, 1); 58 } 59 } 60 break; 61 62 default: 63 $mitem->link .= '&Itemid='. $mitem->id; 64 break; 65 } 66 67 // Active Menu highlighting 68 $current_itemid = $Itemid; 69 if ( !$current_itemid ) { 70 $id = ''; 71 } else if ( $current_itemid == $mitem->id ) { 72 $id = 'id="active_menu'. $params->get( 'class_sfx' ) .'"'; 73 } else if( $params->get( 'activate_parent' ) && isset( $open ) && in_array( $mitem->id, $open ) ) { 74 $id = 'id="active_menu'. $params->get( 'class_sfx' ) .'"'; 75 } else { 76 $id = ''; 77 } 78 79 if ( $params->get( 'full_active_id' ) ) { 80 // support for `active_menu` of 'Link - Component Item' 81 if ( $id == '' && $mitem->type == 'component_item_link' ) { 82 parse_str( $mitem->link, $url ); 83 if ( $url['Itemid'] == $current_itemid ) { 84 $id = 'id="active_menu'. $params->get( 'class_sfx' ) .'"'; 85 } 86 } 87 88 // support for `active_menu` of 'Link - Url' if link is relative 89 if ( $id == '' && $mitem->type == 'url' && strpos( 'http', $mitem->link ) === false) { 90 parse_str( $mitem->link, $url ); 91 if ( isset( $url['Itemid'] ) ) { 92 if ( $url['Itemid'] == $current_itemid ) { 93 $id = 'id="active_menu'. $params->get( 'class_sfx' ) .'"'; 94 } 95 } 96 } 97 } 98 99 // replace & with amp; for xhtml compliance 100 $mitem->link = ampReplace( $mitem->link ); 101 102 // run through SEF convertor 103 $mitem->link = sefRelToAbs( $mitem->link ); 104 105 $menuclass = 'mainlevel'. $params->get( 'class_sfx' ); 106 if ($level > 0) { 107 $menuclass = 'sublevel'. $params->get( 'class_sfx'); 108 } 109 110 // replace & with amp; for xhtml compliance 111 // remove slashes from excaped characters 112 $mitem->name = stripslashes( ampReplace($mitem->name) ); 113 114 switch ($mitem->browserNav) { 115 // cases are slightly different 116 case 1: 117 // open in a new window 118 $txt = '<a href="'. $mitem->link .'" target="_blank" class="'. $menuclass .'" '. $id .'>'. $mitem->name .'</a>'; 119 break; 120 121 case 2: 122 // open in a popup window 123 $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"; 124 break; 125 126 case 3: 127 // don't link it 128 $txt = '<span class="'. $menuclass .'" '. $id .'>'. $mitem->name .'</span>'; 129 break; 130 131 default: 132 // open in parent window 133 $txt = '<a href="'. $mitem->link .'" class="'. $menuclass .'" '. $id .'>'. $mitem->name .'</a>'; 134 break; 135 } 136 137 if ( $params->get( 'menu_images' ) ) { 138 $menu_params = new stdClass(); 139 $menu_params = new mosParameters( $mitem->params ); 140 $menu_image = $menu_params->def( 'menu_image', -1 ); 141 if ( ( $menu_image != '-1' ) && $menu_image ) { 142 $image = '<img src="'. $mosConfig_live_site .'/images/stories/'. $menu_image .'" border="0" alt="'. $mitem->name .'"/>'; 143 if ( $params->get( 'menu_images_align' ) ) { 144 $txt = $txt .' '. $image; 145 } else { 146 $txt = $image .' '. $txt; 147 } 148 } 149 } 150 151 return $txt; 152 } 153 154 /** 155 * Vertically Indented Menu 156 */ 157 function mosShowVIMenu( &$params ) { 158 global $database, $my, $cur_template, $Itemid; 159 global $mosConfig_absolute_path, $mosConfig_live_site, $mosConfig_shownoauth; 160 161 /* If a user has signed in, get their user type */ 162 $intUserType = 0; 163 if($my->gid){ 164 switch ($my->usertype) { 165 case 'Super Administrator': 166 $intUserType = 0; 167 break; 168 169 case 'Administrator': 170 $intUserType = 1; 171 break; 172 173 case 'Editor': 174 $intUserType = 2; 175 break; 176 177 case 'Registered': 178 $intUserType = 3; 179 break; 180 181 case 'Author': 182 $intUserType = 4; 183 break; 184 185 case 'Publisher': 186 $intUserType = 5; 187 break; 188 189 case 'Manager': 190 $intUserType = 6; 191 break; 192 } 193 } else { 194 /* user isn't logged in so make their usertype 0 */ 195 $intUserType = 0; 196 } 197 198 $and = ''; 199 if ( !$mosConfig_shownoauth ) { 200 $and = "\n AND access <= " . (int) $my->gid; 201 } 202 $sql = "SELECT m.*" 203 . "\n FROM #__menu AS m" 204 . "\n WHERE menutype = " . $database->Quote( $params->get( 'menutype' ) ) 205 . "\n AND published = 1" 206 . $and 207 . "\n ORDER BY parent, ordering"; 208 $database->setQuery( $sql ); 209 $rows = $database->loadObjectList( 'id' ); 210 211 // indent icons 212 switch ( $params->get( 'indent_image' ) ) { 213 case '1': 214 // Default images 215 $imgpath = $mosConfig_live_site .'/images/M_images'; 216 for ( $i = 1; $i < 7; $i++ ) { 217 $img[$i] = '<img src="'. $imgpath .'/indent'. $i .'.png" alt="" />'; 218 } 219 break; 220 221 case '2': 222 // Use Params 223 $imgpath = $mosConfig_live_site .'/images/M_images'; 224 for ( $i = 1; $i < 7; $i++ ) { 225 if ( $params->get( 'indent_image'. $i ) == '-1' ) { 226 $img[$i] = NULL; 227 } else { 228 $img[$i] = '<img src="'. $imgpath .'/'. $params->get( 'indent_image'. $i ) .'" alt="" />'; 229 } 230 } 231 break; 232 233 case '3': 234 // None 235 for ( $i = 1; $i < 7; $i++ ) { 236 $img[$i] = NULL; 237 } 238 break; 239 240 default: 241 // Template 242 $imgpath = $mosConfig_live_site .'/templates/'. $cur_template .'/images'; 243 for ( $i = 1; $i < 7; $i++ ) { 244 $img[$i] = '<img src="'. $imgpath .'/indent'. $i .'.png" alt="" />'; 245 } 246 break; 247 } 248 249 $indents = array( 250 // block prefix / item prefix / item suffix / block suffix 251 array( '<table width="100%" border="0" cellpadding="0" cellspacing="0">', '<tr align="left"><td>' , '</td></tr>', '</table>' ), 252 array( '', '<div style="padding-left: 4px">'. $img[1] , '</div>', '' ), 253 array( '', '<div style="padding-left: 8px">'. $img[2] , '</div>', '' ), 254 array( '', '<div style="padding-left: 12px">'. $img[3] , '</div>', '' ), 255 array( '', '<div style="padding-left: 16px">'. $img[4] , '</div>', '' ), 256 array( '', '<div style="padding-left: 20px">'. $img[5] , '</div>', '' ), 257 array( '', '<div style="padding-left: 24px">'. $img[6] , '</div>', '' ), 258 ); 259 260 // establish the hierarchy of the menu 261 $children = array(); 262 // first pass - collect children 263 foreach ($rows as $v ) { 264 $pt = $v->parent; 265 $list = @$children[$pt] ? $children[$pt] : array(); 266 array_push( $list, $v ); 267 $children[$pt] = $list; 268 } 269 270 // second pass - collect 'open' menus 271 $open = array( $Itemid ); 272 $count = 20; // maximum levels - to prevent runaway loop 273 $id = $Itemid; 274 275 while (--$count) { 276 if (isset($rows[$id]) && $rows[$id]->parent > 0) { 277 $id = $rows[$id]->parent; 278 $open[] = $id; 279 } else { 280 break; 281 } 282 } 283 mosRecurseVIMenu( 0, 0, $children, $open, $indents, $params ); 284 285 } 286 287 /** 288 * Utility function to recursively work through a vertically indented 289 * hierarchial menu 290 */ 291 function mosRecurseVIMenu( $id, $level, &$children, &$open, &$indents, &$params ) { 292 if (@$children[$id]) { 293 $n = min( $level, count( $indents )-1 ); 294 295 echo "\n".$indents[$n][0]; 296 foreach ($children[$id] as $row) { 297 298 echo "\n".$indents[$n][1]; 299 300 echo mosGetMenuLink( $row, $level, $params, $open ); 301 302 // show menu with menu expanded - submenus visible 303 if ( !$params->get( 'expand_menu' ) ) { 304 if ( in_array( $row->id, $open )) { 305 mosRecurseVIMenu( $row->id, $level+1, $children, $open, $indents, $params ); 306 } 307 } else { 308 mosRecurseVIMenu( $row->id, $level+1, $children, $open, $indents, $params ); 309 } 310 echo $indents[$n][2]; 311 } 312 echo "\n".$indents[$n][3]; 313 } 314 } 315 316 /** 317 * Draws a horizontal 'flat' style menu (very simple case) 318 */ 319 function mosShowHFMenu( &$params, $style=0 ) { 320 global $database, $my, $cur_template, $Itemid; 321 global $mosConfig_absolute_path, $mosConfig_shownoauth; 322 323 $and = ''; 324 if ( !$mosConfig_shownoauth ) { 325 $and = "\n AND access <= " . (int) $my->gid; 326 } 327 $sql = "SELECT m.*" 328 . "\n FROM #__menu AS m" 329 . "\n WHERE menutype = " . $database->Quote( $params->get( 'menutype' ) ) 330 . "\n AND published = 1" 331 . $and 332 . "\n AND parent = 0" 333 . "\n ORDER BY ordering" 334 ; 335 $database->setQuery( $sql ); 336 $rows = $database->loadObjectList( 'id' ); 337 338 $links = array(); 339 foreach ($rows as $row) { 340 $links[] = mosGetMenuLink( $row, 0, $params ); 341 } 342 343 $menuclass = 'mainlevel'. $params->get( 'class_sfx' ); 344 if (count( $links )) { 345 switch ($style) { 346 case 1: 347 echo '<ul id="'. $menuclass .'">'; 348 foreach ($links as $link) { 349 echo '<li>' . $link . '</li>'; 350 } 351 echo '</ul>'; 352 break; 353 354 default: 355 $spacer_start = $params->get( 'spacer' ); 356 $spacer_end = $params->get( 'end_spacer' ); 357 358 echo '<table width="100%" border="0" cellpadding="0" cellspacing="1">'; 359 echo '<tr>'; 360 echo '<td nowrap="nowrap">'; 361 362 if ( $spacer_end ) { 363 echo '<span class="'. $menuclass .'"> '. $spacer_end .' </span>'; 364 } 365 366 if ( $spacer_start ) { 367 $html = '<span class="'. $menuclass .'"> '. $spacer_start .' </span>'; 368 echo implode( $html, $links ); 369 } else { 370 echo implode( '', $links ); 371 } 372 373 if ( $spacer_end ) { 374 echo '<span class="'. $menuclass .'"> '. $spacer_end .' </span>'; 375 } 376 377 echo '</td>'; 378 echo '</tr>'; 379 echo '</table>'; 380 break; 381 } 382 } 383 } 384 } 385 386 $params->def('menutype', 'mainmenu'); 387 $params->def('class_sfx', ''); 388 $params->def('menu_images', 0); 389 $params->def('menu_images_align', 0); 390 $params->def('expand_menu', 0); 391 $params->def('activate_parent', 0); 392 $params->def('indent_image', 0); 393 $params->def('indent_image1', 'indent1.png'); 394 $params->def('indent_image2', 'indent2.png'); 395 $params->def('indent_image3', 'indent3.png'); 396 $params->def('indent_image4', 'indent4.png'); 397 $params->def('indent_image5', 'indent5.png'); 398 $params->def('indent_image6', 'indent.png'); 399 $params->def('spacer', ''); 400 $params->def('end_spacer', ''); 401 $params->def('full_active_id', 0); 402 403 switch ( $params->get( 'menu_style', 'vert_indent' ) ) { 404 case 'list_flat': 405 mosShowHFMenu( $params, 1 ); 406 break; 407 408 case 'horiz_flat': 409 mosShowHFMenu( $params, 0 ); 410 break; 411 412 default: 413 mosShowVIMenu( $params ); 414 break; 415 } 416 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Wed Nov 21 14:43:32 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |