| [ Index ] |
PHP Cross Reference of Joomla 1.5.26 DE |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * @version $Id: legacy.php 14401 2010-01-26 14:10:00Z louis $ 4 * @package Joomla 5 * @copyright Copyright (C) 2005 - 2010 Open Source Matters. All rights reserved. 6 * @license 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('_JEXEC') or die('Restricted access'); 16 17 /** 18 * Utility function for writing a menu link 19 */ 20 function mosGetMenuLink($mitem, $level = 0, & $params, $open = null) 21 { 22 global $Itemid; 23 $txt = ''; 24 //needed to break reference to prevent altering the actual menu item 25 $mitem = clone($mitem); 26 // Menu Link is a special type that is a link to another item 27 if ($mitem->type == 'menulink') 28 { 29 $menu = &JSite::getMenu(); 30 if ($tmp = $menu->getItem($mitem->query['Itemid'])) { 31 $name = $mitem->name; 32 $mid = $mitem->id; 33 $parent = $mitem->parent; 34 $mitem = clone($tmp); 35 $mitem->name = $name; 36 $mitem->mid = $mid; 37 $mitem->parent = $parent; 38 } else { 39 return; 40 } 41 } 42 43 switch ($mitem->type) 44 { 45 case 'separator' : 46 $mitem->browserNav = 3; 47 break; 48 49 case 'url' : 50 if (preg_match('#index.php\?#i', $mitem->link)) { 51 if (!preg_match('#Itemid=#i', $mitem->link)) { 52 $mitem->link .= '&Itemid='.$mitem->id; 53 } 54 } 55 break; 56 57 default : 58 $mitem->link = 'index.php?Itemid='.$mitem->id; 59 break; 60 } 61 62 // Active Menu highlighting 63 $current_itemid = intval( $Itemid ); 64 if (!$current_itemid) { 65 $id = ''; 66 } else { 67 if ($current_itemid == $mitem->id) { 68 $id = 'id="active_menu' . $params->get('class_sfx') . '"'; 69 } else { 70 if ($params->get('activate_parent') && isset ($open) && in_array($mitem->id, $open)) { 71 $id = 'id="active_menu' . $params->get('class_sfx') . '"'; 72 } else { 73 if ($mitem->type == 'url' && ItemidContained($mitem->link, $current_itemid)) { 74 $id = 'id="active_menu' . $params->get('class_sfx') . '"'; 75 } else { 76 $id = ''; 77 } 78 } 79 } 80 } 81 82 if ($params->get('full_active_id')) 83 { 84 // support for `active_menu` of 'Link - Url' if link is relative 85 if ($id == '' && $mitem->type == 'url' && strpos($mitem->link, 'http') === false) { 86 $url = array(); 87 if(strpos($mitem->link, '&') !== false) 88 { 89 $mitem->link = str_replace('&','&',$mitem->link); 90 } 91 92 parse_str($mitem->link, $url); 93 if (isset ($url['Itemid'])) { 94 if ($url['Itemid'] == $current_itemid) { 95 $id = 'id="active_menu' . $params->get('class_sfx') . '"'; 96 } 97 } 98 } 99 } 100 101 // replace & with amp; for xhtml compliance 102 $menu_params = new stdClass(); 103 $menu_params = new JParameter($mitem->params); 104 $menu_secure = $menu_params->def('secure', 0); 105 106 if (strcasecmp(substr($mitem->link, 0, 4), 'http')) { 107 $mitem->url = JRoute::_($mitem->link, true, $menu_secure); 108 } else { 109 $mitem->url = $mitem->link; 110 } 111 112 $menuclass = 'mainlevel' . $params->get('class_sfx'); 113 if ($level > 0) { 114 $menuclass = 'sublevel' . $params->get('class_sfx'); 115 } 116 117 // replace & with amp; for xhtml compliance 118 // remove slashes from excaped characters 119 $mitem->name = stripslashes(htmlspecialchars($mitem->name)); 120 121 switch ($mitem->browserNav) 122 { 123 // cases are slightly different 124 case 1 : 125 // open in a new window 126 $txt = '<a href="' . $mitem->url . '" target="_blank" class="' . $menuclass . '" ' . $id . '>' . $mitem->name . '</a>'; 127 break; 128 129 case 2 : 130 // open in a popup window 131 $txt = "<a href=\"#\" onclick=\"javascript: window.open('" . $mitem->url . "', '', '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"; 132 break; 133 134 case 3 : 135 // don't link it 136 $txt = '<span class="' . $menuclass . '" ' . $id . '>' . $mitem->name . '</span>'; 137 break; 138 139 default : // formerly case 2 140 // open in parent window 141 $txt = '<a href="' . $mitem->url . '" class="' . $menuclass . '" ' . $id . '>' . $mitem->name . '</a>'; 142 break; 143 } 144 145 if ($params->get('menu_images')) 146 { 147 $menu_params = new stdClass(); 148 $menu_params = new JParameter($mitem->params); 149 150 $menu_image = $menu_params->def('menu_image', -1); 151 if (($menu_image <> '-1') && $menu_image) { 152 $image = '<img src="'.JURI::base(true).'/images/stories/' . $menu_image . '" border="0" alt="' . $mitem->name . '"/>'; 153 if ($params->get('menu_images_align')) { 154 $txt = $txt . ' ' . $image; 155 } else { 156 $txt = $image . ' ' . $txt; 157 } 158 } 159 } 160 161 return $txt; 162 } 163 164 /** 165 * Vertically Indented Menu 166 */ 167 function mosShowVIMenu(& $params) 168 { 169 global $mainframe, $Itemid; 170 171 $template = $mainframe->getTemplate(); 172 $menu =& JSite::getMenu(); 173 $user =& JFactory::getUser(); 174 175 // indent icons 176 switch ($params->get('indent_image')) { 177 case '1' : 178 { 179 // Default images 180 $imgpath = JURI::base(true).'/images/M_images'; 181 for ($i = 1; $i < 7; $i++) { 182 $img[$i] = '<img src="' . $imgpath . '/indent' . $i . '.png" alt="" />'; 183 } 184 } 185 break; 186 187 case '2' : 188 { 189 // Use Params 190 $imgpath = JURI::base(true).'/images/M_images'; 191 for ($i = 1; $i < 7; $i++) { 192 if ($params->get('indent_image' . $i) == '-1') { 193 $img[$i] = NULL; 194 } else { 195 $img[$i] = '<img src="' . $imgpath . '/' . $params->get('indent_image' . $i) . '" alt="" />'; 196 } 197 } 198 } 199 break; 200 201 case '3' : 202 { 203 // None 204 for ($i = 1; $i < 7; $i++) { 205 $img[$i] = NULL; 206 } 207 } 208 break; 209 210 default : 211 { 212 // Template 213 $imgpath = JURI::base(true).'/templates/' . $template . '/images'; 214 for ($i = 1; $i < 7; $i++) { 215 $img[$i] = '<img src="' . $imgpath . '/indent' . $i . '.png" alt="" />'; 216 } 217 } 218 } 219 220 $indents = array ( 221 // block prefix / item prefix / item suffix / block suffix 222 array ( 223 '<table width="100%" border="0" cellpadding="0" cellspacing="0">', 224 '<tr ><td>', 225 '</td></tr>', 226 '</table>' 227 ), 228 array ( 229 '', 230 '<div style="padding-left: 4px">' . $img[1], 231 '</div>', 232 '' 233 ), 234 array ( 235 '', 236 '<div style="padding-left: 8px">' . $img[2], 237 '</div>', 238 '' 239 ), 240 array ( 241 '', 242 '<div style="padding-left: 12px">' . $img[3], 243 '</div>', 244 '' 245 ), 246 array ( 247 '', 248 '<div style="padding-left: 16px">' . $img[4], 249 '</div>', 250 '' 251 ), 252 array ( 253 '', 254 '<div style="padding-left: 20px">' . $img[5], 255 '</div>', 256 '' 257 ), 258 array ( 259 '', 260 '<div style="padding-left: 24px">' . $img[6], 261 '</div>', 262 '' 263 ), 264 265 ); 266 267 // establish the hierarchy of the menu 268 $children = array (); 269 270 //get menu items 271 $rows = $menu->getItems('menutype', $params->get('menutype')); 272 273 // first pass - collect children 274 $cacheIndex = array(); 275 if(is_array($rows) && count($rows)) { 276 foreach ($rows as $index => $v) { 277 if ($v->access <= $user->get('aid')) { 278 $pt = $v->parent; 279 $list = @ $children[$pt] ? $children[$pt] : array (); 280 array_push($list, $v); 281 $children[$pt] = $list; 282 } 283 $cacheIndex[$v->id] = $index; 284 } 285 } 286 287 // second pass - collect 'open' menus 288 $open = array ( 289 $Itemid 290 ); 291 $count = 20; // maximum levels - to prevent runaway loop 292 $id = $Itemid; 293 294 while (-- $count) 295 { 296 if (isset($cacheIndex[$id])) { 297 $index = $cacheIndex[$id]; 298 if (isset ($rows[$index]) && $rows[$index]->parent > 0) { 299 $id = $rows[$index]->parent; 300 $open[] = $id; 301 } else { 302 break; 303 } 304 } 305 } 306 307 mosRecurseVIMenu(0, 0, $children, $open, $indents, $params); 308 } 309 310 /** 311 * Utility function to recursively work through a vertically indented 312 * hierarchial menu 313 */ 314 function mosRecurseVIMenu($id, $level, & $children, & $open, & $indents, & $params) 315 { 316 if (@ $children[$id]) { 317 $n = min($level, count($indents) - 1); 318 319 echo "\n" . $indents[$n][0]; 320 foreach ($children[$id] as $row) { 321 322 echo "\n" . $indents[$n][1]; 323 324 echo mosGetMenuLink($row, $level, $params, $open); 325 326 // show menu with menu expanded - submenus visible 327 if (!$params->get('expand_menu')) { 328 if (in_array($row->id, $open)) { 329 mosRecurseVIMenu($row->id, $level +1, $children, $open, $indents, $params); 330 } 331 } else { 332 mosRecurseVIMenu($row->id, $level +1, $children, $open, $indents, $params); 333 } 334 echo $indents[$n][2]; 335 } 336 echo "\n" . $indents[$n][3]; 337 } 338 } 339 340 /** 341 * Draws a horizontal 'flat' style menu (very simple case) 342 */ 343 function mosShowHFMenu(& $params, $style = 0) 344 { 345 $menu = & JSite::getMenu(); 346 $user = & JFactory::getUser(); 347 348 //get menu items 349 $rows = $menu->getItems('menutype', $params->get('menutype')); 350 351 $links = array (); 352 if(is_array($rows) && count($rows)) { 353 foreach ($rows as $row) 354 { 355 if ($row->access <= $user->get('aid', 0)) { 356 $links[] = mosGetMenuLink($row, 0, $params); 357 } 358 } 359 } 360 361 $menuclass = 'mainlevel' . $params->get('class_sfx'); 362 $lang =& JFactory::getLanguage(); 363 364 if (count($links)) 365 { 366 switch ($style) 367 { 368 case 1 : 369 echo '<ul id="' . $menuclass . '">'; 370 foreach ($links as $link) { 371 echo '<li>' . $link . '</li>'; 372 } 373 echo '</ul>'; 374 break; 375 376 default : 377 $spacer_start = $params->get('spacer'); 378 $spacer_end = $params->get('end_spacer'); 379 380 echo '<table width="100%" border="0" cellpadding="0" cellspacing="1">'; 381 echo '<tr>'; 382 echo '<td nowrap="nowrap">'; 383 384 if ($spacer_end) { 385 echo '<span class="' . $menuclass . '"> ' . $spacer_end . ' </span>'; 386 } 387 388 if ($spacer_start) { 389 $html = '<span class="' . $menuclass . '"> ' . $spacer_start . ' </span>'; 390 echo implode($html, $links); 391 } else { 392 echo implode('', $links); 393 } 394 395 if ($spacer_end) { 396 echo '<span class="' . $menuclass . '"> ' . $spacer_end . ' </span>'; 397 } 398 399 echo '</td>'; 400 echo '</tr>'; 401 echo '</table>'; 402 break; 403 } 404 } 405 } 406 407 /** 408 * Search for Itemid in link 409 */ 410 function ItemidContained($link, $Itemid) 411 { 412 $link = str_replace('&', '&', $link); 413 $temp = explode("&", $link); 414 $linkItemid = ""; 415 foreach ($temp as $value) { 416 $temp2 = explode("=", $value); 417 if ($temp2[0] == "Itemid") { 418 $linkItemid = $temp2[1]; 419 break; 420 } 421 } 422 if ($linkItemid != "" && $linkItemid == $Itemid) { 423 return true; 424 } else { 425 return false; 426 } 427 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Wed Mar 28 15:54:07 2012 | Cross-referenced by PHPXref 0.7.1 |