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