| 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 |
define('MENU_IS_ROOT', 0x0001);
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
define('MENU_VISIBLE_IN_TREE', 0x0002);
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
define('MENU_VISIBLE_IN_BREADCRUMB', 0x0004);
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
define('MENU_LINKS_TO_PARENT', 0x0008);
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
define('MENU_MODIFIED_BY_ADMIN', 0x0020);
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
define('MENU_CREATED_BY_ADMIN', 0x0040);
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
define('MENU_IS_LOCAL_TASK', 0x0080);
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
define('MENU_NORMAL_ITEM', MENU_VISIBLE_IN_TREE | MENU_VISIBLE_IN_BREADCRUMB);
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
define('MENU_CALLBACK', MENU_VISIBLE_IN_BREADCRUMB);
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
define('MENU_SUGGESTED_ITEM', MENU_VISIBLE_IN_BREADCRUMB | 0x0010);
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
define('MENU_LOCAL_TASK', MENU_IS_LOCAL_TASK);
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
define('MENU_DEFAULT_LOCAL_TASK', MENU_IS_LOCAL_TASK | MENU_LINKS_TO_PARENT);
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
define('MENU_FOUND', 1);
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
define('MENU_NOT_FOUND', 2);
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
define('MENU_ACCESS_DENIED', 3);
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
define('MENU_SITE_OFFLINE', 4);
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
define('MENU_MAX_PARTS', 8);
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
define('MENU_MAX_DEPTH', 9);
|
| 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 |
function menu_get_ancestors($parts) {
|
| 254 |
$number_parts = count($parts);
|
| 255 |
$ancestors = array();
|
| 256 |
$length = $number_parts - 1;
|
| 257 |
$end = (1 << $number_parts) - 1;
|
| 258 |
$masks = variable_get('menu_masks', array());
|
| 259 |
|
| 260 |
foreach ($masks as $i) {
|
| 261 |
if ($i > $end) {
|
| 262 |
|
| 263 |
continue;
|
| 264 |
}
|
| 265 |
elseif ($i < (1 << $length)) {
|
| 266 |
|
| 267 |
--$length;
|
| 268 |
}
|
| 269 |
$current = '';
|
| 270 |
for ($j = $length; $j >= 0; $j--) {
|
| 271 |
if ($i & (1 << $j)) {
|
| 272 |
$current .= $parts[$length - $j];
|
| 273 |
}
|
| 274 |
|
| 275 |
$current .= '%';
|
| 276 |
|
| 277 |
if ($j) {
|
| 278 |
$current .= '/';
|
| 279 |
}
|
| 280 |
}
|
| 281 |
$ancestors[] = $current;
|
| 282 |
}
|
| 283 |
return $ancestors;
|
| 284 |
}
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
function menu_unserialize($data, $map) {
|
| 307 |
if ($data = unserialize($data)) {
|
| 308 |
foreach ($data as $k => $v) {
|
| 309 |
if (is_int($v)) {
|
| 310 |
$data[$k] = isset($map[$v]) ? $map[$v] : '';
|
| 311 |
}
|
| 312 |
}
|
| 313 |
return $data;
|
| 314 |
}
|
| 315 |
|
| 316 |
return array();
|
| 317 |
|
| 318 |
}
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
function menu_set_item($path, $router_item) {
|
| 334 |
menu_get_item($path, $router_item);
|
| 335 |
}
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
function menu_get_item($path = NULL, $router_item = NULL) {
|
| 353 |
$router_items = &drupal_static(__FUNCTION__);
|
| 354 |
if (!isset($path)) {
|
| 355 |
$path = $_GET['q'];
|
| 356 |
}
|
| 357 |
if (isset($router_item)) {
|
| 358 |
$router_items[$path] = $router_item;
|
| 359 |
}
|
| 360 |
if (!isset($router_items[$path])) {
|
| 361 |
$original_map = arg(NULL, $path);
|
| 362 |
$parts = array_slice($original_map, 0, MENU_MAX_PARTS);
|
| 363 |
$ancestors = menu_get_ancestors($parts);
|
| 364 |
$router_item = db_select('menu_router')
|
| 365 |
->fields('menu_router')
|
| 366 |
->condition('path', $ancestors, 'IN')
|
| 367 |
->orderBy('fit', 'DESC')
|
| 368 |
->range(0, 1)
|
| 369 |
->addTag('menu_get_item')
|
| 370 |
->execute()->fetchAssoc();
|
| 371 |
if ($router_item) {
|
| 372 |
$map = _menu_translate($router_item, $original_map);
|
| 373 |
if ($map === FALSE) {
|
| 374 |
$router_items[$path] = FALSE;
|
| 375 |
return FALSE;
|
| 376 |
}
|
| 377 |
if ($router_item['access']) {
|
| 378 |
$router_item['map'] = $map;
|
| 379 |
$router_item['page_arguments'] = array_merge(menu_unserialize($router_item['page_arguments'], $map), array_slice($map, $router_item['number_parts']));
|
| 380 |
}
|
| 381 |
}
|
| 382 |
$router_items[$path] = $router_item;
|
| 383 |
}
|
| 384 |
return $router_items[$path];
|
| 385 |
}
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
function menu_execute_active_handler($path = NULL) {
|
| 391 |
if (_menu_site_is_offline()) {
|
| 392 |
return MENU_SITE_OFFLINE;
|
| 393 |
}
|
| 394 |
|
| 395 |
|
| 396 |
if (variable_get('menu_rebuild_needed', FALSE) || !variable_get('menu_masks', array())) {
|
| 397 |
menu_rebuild();
|
| 398 |
}
|
| 399 |
if ($router_item = menu_get_item($path)) {
|
| 400 |
if ($router_item['access']) {
|
| 401 |
if (drupal_function_exists($router_item['page_callback'])) {
|
| 402 |
return call_user_func_array($router_item['page_callback'], $router_item['page_arguments']);
|
| 403 |
}
|
| 404 |
}
|
| 405 |
|
| 406 |
return MENU_ACCESS_DENIED;
|
| 407 |
|
| 408 |
}
|
| 409 |
return MENU_NOT_FOUND;
|
| 410 |
}
|
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
function _menu_load_objects(&$item, &$map) {
|
| 427 |
if ($load_functions = $item['load_functions']) {
|
| 428 |
|
| 429 |
if ($load_functions_unserialized = unserialize($load_functions)) {
|
| 430 |
$load_functions = $load_functions_unserialized;
|
| 431 |
}
|
| 432 |
$path_map = $map;
|
| 433 |
foreach ($load_functions as $index => $function) {
|
| 434 |
if ($function) {
|
| 435 |
$value = isset($path_map[$index]) ? $path_map[$index] : '';
|
| 436 |
if (is_array($function)) {
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
list($function, $args) = each($function);
|
| 442 |
$load_functions[$index] = $function;
|
| 443 |
|
| 444 |
|
| 445 |
foreach ($args as $i => $arg) {
|
| 446 |
if ($arg === '%index') {
|
| 447 |
|
| 448 |
|
| 449 |
$args[$i] = $index;
|
| 450 |
}
|
| 451 |
if ($arg === '%map') {
|
| 452 |
|
| 453 |
|
| 454 |
|
| 455 |
$args[$i] = &$map;
|
| 456 |
}
|
| 457 |
if (is_int($arg)) {
|
| 458 |
$args[$i] = isset($path_map[$arg]) ? $path_map[$arg] : '';
|
| 459 |
}
|
| 460 |
}
|
| 461 |
array_unshift($args, $value);
|
| 462 |
$return = call_user_func_array($function, $args);
|
| 463 |
}
|
| 464 |
|
| 465 |
$return = $function($value);
|
| 466 |
|
| 467 |
|
| 468 |
if ($return === FALSE) {
|
| 469 |
$item['access'] = FALSE;
|
| 470 |
$map = FALSE;
|
| 471 |
return FALSE;
|
| 472 |
}
|
| 473 |
$map[$index] = $return;
|
| 474 |
}
|
| 475 |
}
|
| 476 |
$item['load_functions'] = $load_functions;
|
| 477 |
}
|
| 478 |
return TRUE;
|
| 479 |
}
|
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
|
| 489 |
|
| 490 |
|
| 491 |
function _menu_check_access(&$item, $map) {
|
| 492 |
|
| 493 |
|
| 494 |
$callback = empty($item['access_callback']) ? 0 : trim($item['access_callback']);
|
| 495 |
|
| 496 |
if (is_numeric($callback)) {
|
| 497 |
$item['access'] = (bool)$callback;
|
| 498 |
}
|
| 499 |
|
| 500 |
$arguments = menu_unserialize($item['access_arguments'], $map);
|
| 501 |
|
| 502 |
|
| 503 |
if ($callback == 'user_access') {
|
| 504 |
$item['access'] = (count($arguments) == 1) ? user_access($arguments[0]) : user_access($arguments[0], $arguments[1]);
|
| 505 |
}
|
| 506 |
elseif (drupal_function_exists($callback)) {
|
| 507 |
$item['access'] = call_user_func_array($callback, $arguments);
|
| 508 |
}
|
| 509 |
|
| 510 |
}
|
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
|
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
|
| 524 |
|
| 525 |
|
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
function _menu_item_localize(&$item, $map, $link_translate = FALSE) {
|
| 538 |
$callback = $item['title_callback'];
|
| 539 |
$item['localized_options'] = $item['options'];
|
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
|
| 545 |
|
| 546 |
if (!$link_translate || ($item['title'] == $item['link_title'])) {
|
| 547 |
|
| 548 |
|
| 549 |
if ($callback == 't') {
|
| 550 |
if (empty($item['title_arguments'])) {
|
| 551 |
$item['title'] = t($item['title']);
|
| 552 |
}
|
| 553 |
|
| 554 |
$item['title'] = t($item['title'], menu_unserialize($item['title_arguments'], $map));
|
| 555 |
|
| 556 |
}
|
| 557 |
elseif ($callback && drupal_function_exists($callback)) {
|
| 558 |
if (empty($item['title_arguments'])) {
|
| 559 |
$item['title'] = $callback($item['title']);
|
| 560 |
}
|
| 561 |
|
| 562 |
$item['title'] = call_user_func_array($callback, menu_unserialize($item['title_arguments'], $map));
|
| 563 |
|
| 564 |
|
| 565 |
if ($callback == 'check_plain') {
|
| 566 |
$item['localized_options']['html'] = TRUE;
|
| 567 |
}
|
| 568 |
}
|
| 569 |
}
|
| 570 |
elseif ($link_translate) {
|
| 571 |
$item['title'] = $item['link_title'];
|
| 572 |
}
|
| 573 |
|
| 574 |
|
| 575 |
if (!empty($item['description'])) {
|
| 576 |
$original_description = $item['description'];
|
| 577 |
$item['description'] = t($item['description']);
|
| 578 |
if ($link_translate && isset($item['options']['attributes']['title']) && $item['options']['attributes']['title'] == $original_description) {
|
| 579 |
$item['localized_options']['attributes']['title'] = $item['description'];
|
| 580 |
}
|
| 581 |
}
|
| 582 |
}
|
| 583 |
|
| 584 |
|
| 585 |
|
| 586 |
|
| 587 |
|
| 588 |
|
| 589 |
|
| 590 |
|
| 591 |
|
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
|
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
|
| 602 |
|
| 603 |
|
| 604 |
|
| 605 |
|
| 606 |
|
| 607 |
|
| 608 |
|
| 609 |
|
| 610 |
|
| 611 |
|
| 612 |
|
| 613 |
function _menu_translate(&$router_item, $map, $to_arg = FALSE) {
|
| 614 |
if ($to_arg) {
|
| 615 |
|
| 616 |
_menu_link_map_translate($map, $router_item['to_arg_functions']);
|
| 617 |
}
|
| 618 |
|
| 619 |
|
| 620 |
$path_map = $map;
|
| 621 |
if (!_menu_load_objects($router_item, $map)) {
|
| 622 |
|
| 623 |
$router_item['access'] = FALSE;
|
| 624 |
return FALSE;
|
| 625 |
}
|
| 626 |
|
| 627 |
|
| 628 |
$link_map = explode('/', $router_item['path']);
|
| 629 |
for ($i = 0; $i < $router_item['number_parts']; $i++) {
|
| 630 |
if ($link_map[$i] == '%') {
|
| 631 |
$link_map[$i] = $path_map[$i];
|
| 632 |
}
|
| 633 |
}
|
| 634 |
$router_item['href'] = implode('/', $link_map);
|
| 635 |
$router_item['options'] = array();
|
| 636 |
_menu_check_access($router_item, $map);
|
| 637 |
|
| 638 |
|
| 639 |
if ($router_item['access']) {
|
| 640 |
_menu_item_localize($router_item, $map);
|
| 641 |
}
|
| 642 |
|
| 643 |
return $map;
|
| 644 |
}
|
| 645 |
|
| 646 |
|
| 647 |
|
| 648 |
|
| 649 |
|
| 650 |
|
| 651 |
|
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
|
| 656 |
function _menu_link_map_translate(&$map, $to_arg_functions) {
|
| 657 |
if ($to_arg_functions) {
|
| 658 |
$to_arg_functions = unserialize($to_arg_functions);
|
| 659 |
foreach ($to_arg_functions as $index => $function) {
|
| 660 |
|
| 661 |
$arg = $function(!empty($map[$index]) ? $map[$index] : '', $map, $index);
|
| 662 |
if (!empty($map[$index]) || isset($arg)) {
|
| 663 |
$map[$index] = $arg;
|
| 664 |
}
|
| 665 |
|
| 666 |
unset($map[$index]);
|
| 667 |
|
| 668 |
}
|
| 669 |
}
|
| 670 |
}
|
| 671 |
|
| 672 |
function menu_tail_to_arg($arg, $map, $index) {
|
| 673 |
return implode('/', array_slice($map, $index));
|
| 674 |
}
|
| 675 |
|
| 676 |
|
| 677 |
|
| 678 |
|
| 679 |
|
| 680 |
|
| 681 |
|
| 682 |
|
| 683 |
|
| 684 |
|
| 685 |
|
| 686 |
|
| 687 |
|
| 688 |
|
| 689 |
|
| 690 |
|
| 691 |
function _menu_link_translate(&$item) {
|
| 692 |
$item['options'] = unserialize($item['options']);
|
| 693 |
if ($item['external']) {
|
| 694 |
$item['access'] = 1;
|
| 695 |
$map = array();
|
| 696 |
$item['href'] = $item['link_path'];
|
| 697 |
$item['title'] = $item['link_title'];
|
| 698 |
$item['localized_options'] = $item['options'];
|
| 699 |
}
|
| 700 |
|
| 701 |
$map = explode('/', $item['link_path']);
|
| 702 |
_menu_link_map_translate($map, $item['to_arg_functions']);
|
| 703 |
$item['href'] = implode('/', $map);
|
| 704 |
|
| 705 |
|
| 706 |
if (strpos($item['href'], '%') !== FALSE) {
|
| 707 |
$item['access'] = FALSE;
|
| 708 |
return FALSE;
|
| 709 |
}
|
| 710 |
|
| 711 |
if (!isset($item['access'])) {
|
| 712 |
if (!_menu_load_objects($item, $map)) {
|
| 713 |
|
| 714 |
$item['access'] = FALSE;
|
| 715 |
return FALSE;
|
| 716 |
}
|
| 717 |
_menu_check_access($item, $map);
|
| 718 |
}
|
| 719 |
|
| 720 |
if ($item['access']) {
|
| 721 |
_menu_item_localize($item, $map, TRUE);
|
| 722 |
}
|
| 723 |
|
| 724 |
|
| 725 |
|
| 726 |
|
| 727 |
|
| 728 |
if (!empty($item['options']['alter'])) {
|
| 729 |
drupal_alter('translated_menu_link', $item, $map);
|
| 730 |
}
|
| 731 |
|
| 732 |
return $map;
|
| 733 |
}
|
| 734 |
|
| 735 |
|
| 736 |
|
| 737 |
|
| 738 |
|
| 739 |
|
| 740 |
|
| 741 |
|
| 742 |
|
| 743 |
|
| 744 |
|
| 745 |
|
| 746 |
|
| 747 |
|
| 748 |
|
| 749 |
|
| 750 |
|
| 751 |
|
| 752 |
|
| 753 |
|
| 754 |
|
| 755 |
|
| 756 |
|
| 757 |
|
| 758 |
|
| 759 |
|
| 760 |
|
| 761 |
function menu_get_object($type = 'node', $position = 1, $path = NULL) {
|
| 762 |
$router_item = menu_get_item($path);
|
| 763 |
if (isset($router_item['load_functions'][$position]) && !empty($router_item['map'][$position]) && $router_item['load_functions'][$position] == $type . '_load') {
|
| 764 |
return $router_item['map'][$position];
|
| 765 |
}
|
| 766 |
}
|
| 767 |
|
| 768 |
|
| 769 |
|
| 770 |
|
| 771 |
|
| 772 |
|
| 773 |
|
| 774 |
|
| 775 |
|
| 776 |
|
| 777 |
|
| 778 |
|
| 779 |
|
| 780 |
function menu_tree($menu_name) {
|
| 781 |
$menu_output = &drupal_static(__FUNCTION__, array());
|
| 782 |
|
| 783 |
if (!isset($menu_output[$menu_name])) {
|
| 784 |
$tree = menu_tree_page_data($menu_name);
|
| 785 |
$menu_output[$menu_name] = menu_tree_output($tree);
|
| 786 |
}
|
| 787 |
return $menu_output[$menu_name];
|
| 788 |
}
|
| 789 |
|
| 790 |
|
| 791 |
|
| 792 |
|
| 793 |
|
| 794 |
|
| 795 |
|
| 796 |
|
| 797 |
|
| 798 |
function menu_tree_output($tree) {
|
| 799 |
$output = '';
|
| 800 |
$items = array();
|
| 801 |
|
| 802 |
|
| 803 |
|
| 804 |
foreach ($tree as $data) {
|
| 805 |
if (!$data['link']['hidden']) {
|
| 806 |
$items[] = $data;
|
| 807 |
}
|
| 808 |
}
|
| 809 |
|
| 810 |
$num_items = count($items);
|
| 811 |
foreach ($items as $i => $data) {
|
| 812 |
$extra_class = array();
|
| 813 |
if ($i == 0) {
|
| 814 |
$extra_class[] = 'first';
|
| 815 |
}
|
| 816 |
if ($i == $num_items - 1) {
|
| 817 |
$extra_class[] = 'last';
|
| 818 |
}
|
| 819 |
$extra_class = implode(' ', $extra_class);
|
| 820 |
$link = theme('menu_item_link', $data['link']);
|
| 821 |
if ($data['below']) {
|
| 822 |
$output .= theme('menu_item', $link, $data['link']['has_children'], menu_tree_output($data['below']), $data['link']['in_active_trail'], $extra_class);
|
| 823 |
}
|
| 824 |
|
| 825 |
$output .= theme('menu_item', $link, $data['link']['has_children'], '', $data['link']['in_active_trail'], $extra_class);
|
| 826 |
|
| 827 |
}
|
| 828 |
return $output ? theme('menu_tree', $output) : '';
|
| 829 |
}
|
| 830 |
|
| 831 |
|
| 832 |
|
| 833 |
|
| 834 |
|
| 835 |
|
| 836 |
|
| 837 |
|
| 838 |
|
| 839 |
|
| 840 |
|
| 841 |
|
| 842 |
|
| 843 |
|
| 844 |
|
| 845 |
|
| 846 |
function menu_tree_all_data($menu_name, $item = NULL) {
|
| 847 |
$tree = &drupal_static(__FUNCTION__, array());
|
| 848 |
|
| 849 |
|
| 850 |
$mlid = isset($item['mlid']) ? $item['mlid'] : 0;
|
| 851 |
|
| 852 |
$cid = 'links:' . $menu_name . ':all-cid:' . $mlid;
|
| 853 |
|
| 854 |
if (!isset($tree[$cid])) {
|
| 855 |
|
| 856 |
$cache = cache_get($cid, 'cache_menu');
|
| 857 |
if ($cache && isset($cache->data)) {
|
| 858 |
|
| 859 |
|
| 860 |
$cache = cache_get($cache->data, 'cache_menu');
|
| 861 |
if ($cache && isset($cache->data)) {
|
| 862 |
$data = $cache->data;
|
| 863 |
}
|
| 864 |
}
|
| 865 |
|
| 866 |
if (!isset($data)) {
|
| 867 |
|
| 868 |
$query = db_select('menu_links', 'ml', array('fetch' => PDO::FETCH_ASSOC));
|
| 869 |
$query->leftJoin('menu_router', 'm', 'm.path = ml.router_path');
|
| 870 |
$query->fields('ml');
|
| 871 |
$query->fields('m', array(
|
| 872 |
'load_functions',
|
| 873 |
'to_arg_functions',
|
| 874 |
'access_callback',
|
| 875 |
'access_arguments',
|
| 876 |
'page_callback',
|
| 877 |
'page_arguments',
|
| 878 |
'title',
|
| 879 |
'title_callback',
|
| 880 |
'title_arguments',
|
| 881 |
'type',
|
| 882 |
'description',
|
| 883 |
));
|
| 884 |
for ($i = 1; $i <= MENU_MAX_DEPTH; $i++) {
|
| 885 |
$query->orderBy('p' . $i, 'ASC');
|
| 886 |
}
|
| 887 |
$query->condition('ml.menu_name', $menu_name);
|
| 888 |
|
| 889 |
if ($mlid) {
|
| 890 |
|
| 891 |
|
| 892 |
$args = array(0);
|
| 893 |
for ($i = 1; $i < MENU_MAX_DEPTH; $i++) {
|
| 894 |
$args[] = $item["p$i"];
|
| 895 |
}
|
| 896 |
$args = array_unique($args);
|
| 897 |
$query->condition('ml.plid', $args, 'IN');
|
| 898 |
$parents = $args;
|
| 899 |
$parents[] = $item['mlid'];
|
| 900 |
}
|
| 901 |
|
| 902 |
|
| 903 |
$parents = array();
|
| 904 |
|
| 905 |
|
| 906 |
|
| 907 |
|
| 908 |
$data['tree'] = menu_tree_data($query->execute(), $parents);
|
| 909 |
$data['node_links'] = array();
|
| 910 |
menu_tree_collect_node_links($data['tree'], $data['node_links']);
|
| 911 |
|
| 912 |
$tree_cid = _menu_tree_cid($menu_name, $data);
|
| 913 |
if (!cache_get($tree_cid, 'cache_menu')) {
|
| 914 |
cache_set($tree_cid, $data, 'cache_menu');
|
| 915 |
}
|
| 916 |
|
| 917 |
cache_set($cid, $tree_cid, 'cache_menu');
|
| 918 |
}
|
| 919 |
|
| 920 |
menu_tree_check_access($data['tree'], $data['node_links']);
|
| 921 |
$tree[$cid] = $data['tree'];
|
| 922 |
}
|
| 923 |
|
| 924 |
return $tree[$cid];
|
| 925 |
}
|
| 926 |
|
| 927 |
|
| 928 |
|
| 929 |
|
| 930 |
|
| 931 |
|
| 932 |
|
| 933 |
|
| 934 |
|
| 935 |
|
| 936 |
|
| 937 |
|
| 938 |
|
| 939 |
|
| 940 |
|
| 941 |
|
| 942 |
function menu_tree_page_data($menu_name) {
|
| 943 |
$tree = &drupal_static(__FUNCTION__, array());
|
| 944 |
|
| 945 |
|
| 946 |
if ($item = menu_get_item()) {
|
| 947 |
|
| 948 |
$cid = 'links:' . $menu_name . ':page-cid:' . $item['href'] . ':' . (int)$item['access'];
|
| 949 |
|
| 950 |
if (!isset($tree[$cid])) {
|
| 951 |
|
| 952 |
$cache = cache_get($cid, 'cache_menu');
|
| 953 |
if ($cache && isset($cache->data)) {
|
| 954 |
|
| 955 |
|
| 956 |
$cache = cache_get($cache->data, 'cache_menu');
|
| 957 |
if ($cache && isset($cache->data)) {
|
| 958 |
$data = $cache->data;
|
| 959 |
}
|
| 960 |
}
|
| 961 |
|
| 962 |
if (!isset($data)) {
|
| 963 |
|
| 964 |
if ($item['access']) {
|
| 965 |
|
| 966 |
$args[] = $item['href'];
|
| 967 |
if (drupal_is_front_page()) {
|
| 968 |
$args[] = '<front>';
|
| 969 |
}
|
| 970 |
$parents = db_select('menu_links')
|
| 971 |
->fields('menu_links', array(
|
| 972 |
'p1',
|
| 973 |
'p2',
|
| 974 |
'p3',
|
| 975 |
'p4',
|
| 976 |
'p5',
|
| 977 |
'p6',
|
| 978 |
'p7',
|
| 979 |
'p8',
|
| 980 |
))
|
| 981 |
->condition('menu_name', $menu_name)
|
| 982 |
->condition('link_path', $args, 'IN')
|
| 983 |
->execute()->fetchAssoc();
|
| 984 |
|
| 985 |
if (empty($parents)) {
|
| 986 |
|
| 987 |
|
| 988 |
$parents = db_select('menu_links')
|
| 989 |
->fields('menu_links', array(
|
| 990 |
'p1',
|
| 991 |
'p2',
|
| 992 |
'p3',
|
| 993 |
'p4',
|
| 994 |
'p5',
|
| 995 |
'p6',
|
| 996 |
'p7',
|
| 997 |
'p8',
|
| 998 |
))
|
| 999 |
->condition('menu_name', $menu_name)
|
| 1000 |
->condition('link_path', $item['tab_root'])
|
| 1001 |
->execute()->fetchAssoc();
|
| 1002 |
}
|
| 1003 |
|
| 1004 |
$parents[] = '0';
|
| 1005 |
|
| 1006 |
|
| 1007 |
$args = $parents = array_unique(array_values($parents));
|
| 1008 |
$expanded = variable_get('menu_expanded', array());
|
| 1009 |
|
| 1010 |
if (in_array($menu_name, $expanded)) {
|
| 1011 |
|
| 1012 |
|
| 1013 |
|
| 1014 |
$result = db_select('menu_links', NULL, array('fetch' => PDO::FETCH_ASSOC))
|
| 1015 |
->fields('menu_links', array('mlid'))
|
| 1016 |
->condition('menu_name', $menu_name)
|
| 1017 |
->condition('expanded', 1)
|
| 1018 |
->condition('has_children', 1)
|
| 1019 |
->condition('plid', $args, 'IN')
|
| 1020 |
->condition('mlid', $args, 'NOT IN')
|
| 1021 |
->execute();
|
| 1022 |
$num_rows = FALSE;
|
| 1023 |
foreach ($result as $item) {
|
| 1024 |
$args[] = $item['mlid'];
|
| 1025 |
$num_rows = TRUE;
|
| 1026 |
}
|
| 1027 |
} while ($num_rows);
|
| 1028 |
}
|
| 1029 |
}
|
| 1030 |
|
| 1031 |
|
| 1032 |
$args = array(0);
|
| 1033 |
$parents = array();
|
| 1034 |
|
| 1035 |
|
| 1036 |
|
| 1037 |
|
| 1038 |
$query = db_select('menu_links', 'ml', array('fetch' => PDO::FETCH_ASSOC));
|
| 1039 |
$query->leftJoin('menu_router', 'm', 'm.path = ml.router_path');
|
| 1040 |
$query->fields('ml');
|
| 1041 |
$query->fields('m', array(
|
| 1042 |
'load_functions',
|
| 1043 |
'to_arg_functions',
|
| 1044 |
'access_callback',
|
| 1045 |
'access_arguments',
|
| 1046 |
'page_callback',
|
| 1047 |
'page_arguments',
|
| 1048 |
'title',
|
| 1049 |
'title_callback',
|
| 1050 |
'title_arguments',
|
| 1051 |
'type',
|
| 1052 |
'description',
|
| 1053 |
));
|
| 1054 |
for ($i = 1; $i <= MENU_MAX_DEPTH; $i++) {
|
| 1055 |
$query->orderBy('p' . $i, 'ASC');
|
| 1056 |
}
|
| 1057 |
$query->condition('ml.menu_name', $menu_name);
|
| 1058 |
$query->condition('ml.plid', $args, 'IN');
|
| 1059 |
$data['tree'] = menu_tree_data($query->execute(), $parents);
|
| 1060 |
$data['node_links'] = array();
|
| 1061 |
menu_tree_collect_node_links($data['tree'], $data['node_links']);
|
| 1062 |
|
| 1063 |
$tree_cid = _menu_tree_cid($menu_name, $data);
|
| 1064 |
if (!cache_get($tree_cid, 'cache_menu')) {
|
| 1065 |
cache_set($tree_cid, $data, 'cache_menu');
|
| 1066 |
}
|
| 1067 |
|
| 1068 |
cache_set($cid, $tree_cid, 'cache_menu');
|
| 1069 |
}
|
| 1070 |
|
| 1071 |
menu_tree_check_access($data['tree'], $data['node_links']);
|
| 1072 |
$tree[$cid] = $data['tree'];
|
| 1073 |
}
|
| 1074 |
return $tree[$cid];
|
| 1075 |
}
|
| 1076 |
|
| 1077 |
return array();
|
| 1078 |
}
|
| 1079 |
|
| 1080 |
|
| 1081 |
|
| 1082 |
|
| 1083 |
function _menu_tree_cid($menu_name, $data) {
|
| 1084 |
return 'links:' . $menu_name . ':tree-data:' . md5(serialize($data));
|
| 1085 |
}
|
| 1086 |
|
| 1087 |
|
| 1088 |
|
| 1089 |
|
| 1090 |
|
| 1091 |
|
| 1092 |
|
| 1093 |
|
| 1094 |
|
| 1095 |
function menu_tree_collect_node_links(&$tree, &$node_links) {
|
| 1096 |
foreach ($tree as $key => $v) {
|
| 1097 |
if ($tree[$key]['link']['router_path'] == 'node/%') {
|
| 1098 |
$nid = substr($tree[$key]['link']['link_path'], 5);
|
| 1099 |
if (is_numeric($nid)) {
|
| 1100 |
$node_links[$nid][$tree[$key]['link']['mlid']] = &$tree[$key]['link'];
|
| 1101 |
$tree[$key]['link']['access'] = FALSE;
|
| 1102 |
}
|
| 1103 |
}
|
| 1104 |
if ($tree[$key]['below']) {
|
| 1105 |
menu_tree_collect_node_links($tree[$key]['below'], $node_links);
|
| 1106 |
}
|
| 1107 |
}
|
| 1108 |
}
|
| 1109 |
|
| 1110 |
|
| 1111 |
|
| 1112 |
|
| 1113 |
|
| 1114 |
|
| 1115 |
|
| 1116 |
|
| 1117 |
|
| 1118 |
|
| 1119 |
function menu_tree_check_access(&$tree, $node_links = array()) {
|
| 1120 |
|
| 1121 |
if ($node_links) {
|
| 1122 |
$nids = array_keys($node_links);
|
| 1123 |
$select = db_select('node');
|
| 1124 |
$select->addField('node', 'nid');
|
| 1125 |
$select->condition('status', 1);
|
| 1126 |
$select->condition('nid', $nids, 'IN');
|
| 1127 |
$select->addTag('node_access');
|
| 1128 |
$nids = $select->execute()->fetchCol();
|
| 1129 |
foreach ($nids as $nid) {
|
| 1130 |
foreach ($node_links[$nid] as $mlid => $link) {
|
| 1131 |
$node_links[$nid][$mlid]['access'] = TRUE;
|
| 1132 |
}
|
| 1133 |
}
|
| 1134 |
}
|
| 1135 |
_menu_tree_check_access($tree);
|
| 1136 |
return;
|
| 1137 |
}
|
| 1138 |
|
| 1139 |
|
| 1140 |
|
| 1141 |
|
| 1142 |
function _menu_tree_check_access(&$tree) {
|
| 1143 |
$new_tree = array();
|
| 1144 |
foreach ($tree as $key => $v) {
|
| 1145 |
$item = &$tree[$key]['link'];
|
| 1146 |
_menu_link_translate($item);
|
| 1147 |
if ($item['access']) {
|
| 1148 |
if ($tree[$key]['below']) {
|
| 1149 |
_menu_tree_check_access($tree[$key]['below']);
|
| 1150 |
}
|
| 1151 |
|
| 1152 |
|
| 1153 |
|
| 1154 |
$new_tree[(50000 + $item['weight']) . ' ' . $item['title'] . ' ' . $item['mlid']] = $tree[$key];
|
| 1155 |
}
|
| 1156 |
}
|
| 1157 |
|
| 1158 |
ksort($new_tree);
|
| 1159 |
$tree = $new_tree;
|
| 1160 |
}
|
| 1161 |
|
| 1162 |
|
| 1163 |
|
| 1164 |
|
| 1165 |
|
| 1166 |
|
| 1167 |
|
| 1168 |
|
| 1169 |
|
| 1170 |
|
| 1171 |
|
| 1172 |
|
| 1173 |
|
| 1174 |
|
| 1175 |
function menu_tree_data($result = NULL, $parents = array(), $depth = 1) {
|
| 1176 |
list(, $tree) = _menu_tree_data($result, $parents, $depth);
|
| 1177 |
return $tree;
|
| 1178 |
}
|
| 1179 |
|
| 1180 |
|
| 1181 |
|
| 1182 |
|
| 1183 |
|
| 1184 |
|
| 1185 |
|
| 1186 |
|
| 1187 |
function _menu_tree_data($result, $parents, $depth, $previous_element = '') {
|
| 1188 |
$remnant = NULL;
|
| 1189 |
$tree = array();
|
| 1190 |
foreach ($result as $item) {
|
| 1191 |
|
| 1192 |
|
| 1193 |
$item['in_active_trail'] = in_array($item['mlid'], $parents);
|
| 1194 |
|
| 1195 |
if ($item['depth'] > $depth) {
|
| 1196 |
|
| 1197 |
list($item, $below) = _menu_tree_data($result, $parents, $item['depth'], $item);
|
| 1198 |
if ($previous_element) {
|
| 1199 |
$tree[$previous_element['mlid']] = array(
|
| 1200 |
'link' => $previous_element,
|
| 1201 |
'below' => $below,
|
| 1202 |
|
| 1203 |
}
|
| 1204 |
|
| 1205 |
$tree = $below;
|
| 1206 |
|
| 1207 |
|
| 1208 |
if (!isset($item) || $item['depth'] < $depth) {
|
| 1209 |
return array($item, $tree);
|
| 1210 |
}
|
| 1211 |
|
| 1212 |
$previous_element = $item;
|
| 1213 |
}
|
| 1214 |
|
| 1215 |
elseif ($item['depth'] == $depth) {
|
| 1216 |
if ($previous_element) {
|
| 1217 |
|
| 1218 |
$tree[$previous_element['mlid']] = array(
|
| 1219 |
'link' => $previous_element,
|
| 1220 |
'below' => FALSE,
|
| 1221 |
|
| 1222 |
}
|
| 1223 |
|
| 1224 |
$previous_element = $item;
|
| 1225 |
}
|
| 1226 |
|
| 1227 |
|
| 1228 |
$remnant = $item;
|
| 1229 |
break;
|
| 1230 |
|
| 1231 |
}
|
| 1232 |
if ($previous_element) {
|
| 1233 |
|
| 1234 |
$tree[$previous_element['mlid']] = array(
|
| 1235 |
'link' => $previous_element,
|
| 1236 |
'below' => FALSE,
|
| 1237 |
|
| 1238 |
}
|
| 1239 |
return array($remnant, $tree);
|
| 1240 |
}
|
| 1241 |
|
| 1242 |
|
| 1243 |
|
| 1244 |
|
| 1245 |
|
| 1246 |
|
| 1247 |
function theme_menu_item_link($link) {
|
| 1248 |
if (empty($link['localized_options'])) {
|
| 1249 |
$link['localized_options'] = array();
|
| 1250 |
}
|
| 1251 |
|
| 1252 |
return l($link['title'], $link['href'], $link['localized_options']);
|
| 1253 |
}
|
| 1254 |
|
| 1255 |
|
| 1256 |
|
| 1257 |
|
| 1258 |
|
| 1259 |
|
| 1260 |
function theme_menu_tree($tree) {
|
| 1261 |
return '<ul class="menu">' . $tree . '</ul>';
|
| 1262 |
}
|
| 1263 |
|
| 1264 |
|
| 1265 |
|
| 1266 |
|
| 1267 |
|
| 1268 |
|
| 1269 |
|
| 1270 |
|
| 1271 |
|
| 1272 |
|
| 1273 |
|
| 1274 |
|
| 1275 |
|
| 1276 |
|
| 1277 |
|
| 1278 |
|
| 1279 |
|
| 1280 |
|
| 1281 |
|
| 1282 |
|
| 1283 |
|
| 1284 |
|
| 1285 |
|
| 1286 |
|
| 1287 |
|
| 1288 |
function theme_menu_item($link, $has_children, $menu = '', $in_active_trail = FALSE, $extra_class = NULL) {
|
| 1289 |
$class = ($menu ? 'expanded' : ($has_children ? 'collapsed' : 'leaf'));
|
| 1290 |
if (!empty($extra_class)) {
|
| 1291 |
$class .= ' ' . $extra_class;
|
| 1292 |
}
|
| 1293 |
if ($in_active_trail) {
|
| 1294 |
$class .= ' active-trail';
|
| 1295 |
}
|
| 1296 |
return '<li class="' . $class . '">' . $link . $menu . "</li>\n";
|
| 1297 |
}
|
| 1298 |
|
| 1299 |
|
| 1300 |
|
| 1301 |
|
| 1302 |
|
| 1303 |
|
| 1304 |
function theme_menu_local_task($link, $active = FALSE) {
|
| 1305 |
return '<li ' . ($active ? 'class="active" ' : '') . '>' . $link . "</li>\n";
|
| 1306 |
}
|
| 1307 |
|
| 1308 |
|
| 1309 |
|
| 1310 |
|
| 1311 |
function drupal_help_arg($arg = array()) {
|
| 1312 |
|
| 1313 |
return $arg + array('', '', '', '', '', '', '', '', '', '', '', '');
|
| 1314 |
}
|
| 1315 |
|
| 1316 |
|
| 1317 |
|
| 1318 |
|
| 1319 |
function menu_get_active_help() {
|
| 1320 |
$output = '';
|
| 1321 |
$router_path = menu_tab_root_path();
|
| 1322 |
|
| 1323 |
if (!$router_path) {
|
| 1324 |
return '';
|
| 1325 |
}
|
| 1326 |
|
| 1327 |
$arg = drupal_help_arg(arg(NULL));
|
| 1328 |
$empty_arg = drupal_help_arg();
|
| 1329 |
|
| 1330 |
foreach (module_implements('help') as $module) {
|
| 1331 |
$function = $module . '_help';
|
| 1332 |
|
| 1333 |
if ($help = $function($router_path, $arg)) {
|
| 1334 |
$output .= $help . "\n";
|
| 1335 |
}
|
| 1336 |
|
| 1337 |
|
| 1338 |
if ($arg[0] == "admin" && user_access('access administration pages') && module_exists('help') && $function('admin/help#' . $arg[2], $empty_arg) && $help) {
|
| 1339 |
$output .= theme("more_help_link", url('admin/help/' . $arg[2]));
|
| 1340 |
}
|
| 1341 |
}
|
| 1342 |
return $output;
|
| 1343 |
}
|
| 1344 |
|
| 1345 |
|
| 1346 |
|
| 1347 |
|
| 1348 |
function menu_get_names() {
|
| 1349 |
$names = &drupal_static(__FUNCTION__);
|
| 1350 |
|
| 1351 |
if (empty($names)) {
|
| 1352 |
$names = db_select('menu_links')
|
| 1353 |
->distinct()
|
| 1354 |
->fields('menu_links', 'menu_name')
|
| 1355 |
->orderBy('menu_name')
|
| 1356 |
->execute()->fetchCol();
|
| 1357 |
}
|
| 1358 |
return $names;
|
| 1359 |
}
|
| 1360 |
|
| 1361 |
|
| 1362 |
|
| 1363 |
|
| 1364 |
function menu_list_system_menus() {
|
| 1365 |
return array('navigation' => 'Navigation', 'management' => 'Management', 'user-menu' => 'User menu', 'main-menu' => 'Main menu', 'secondary-menu' => 'Secondary menu');
|
| 1366 |
}
|
| 1367 |
|
| 1368 |
|
| 1369 |
|
| 1370 |
|
| 1371 |
function menu_main_menu() {
|
| 1372 |
return menu_navigation_links(variable_get('menu_main_links_source', 'main-menu'));
|
| 1373 |
}
|
| 1374 |
|
| 1375 |
|
| 1376 |
|
| 1377 |
|
| 1378 |
function menu_secondary_menu() {
|
| 1379 |
|
| 1380 |
|
| 1381 |
|
| 1382 |
if (variable_get('menu_secondary_links_source', 'user-menu') == variable_get('menu_main_links_source', 'main-menu')) {
|
| 1383 |
return menu_navigation_links(variable_get('menu_main_links_source', 'main-menu'), 1);
|
| 1384 |
}
|
| 1385 |
|
| 1386 |
return menu_navigation_links(variable_get('menu_secondary_links_source', 'user-menu'), 0);
|
| 1387 |
|
| 1388 |
}
|
| 1389 |
|
| 1390 |
|
| 1391 |
|
| 1392 |
|
| 1393 |
|
| 1394 |
|
| 1395 |
|
| 1396 |
|
| 1397 |
|
| 1398 |
|
| 1399 |
|
| 1400 |
function menu_navigation_links($menu_name, $level = 0) {
|
| 1401 |
|
| 1402 |
if (empty($menu_name)) {
|
| 1403 |
return array();
|
| 1404 |
}
|
| 1405 |
|
| 1406 |
|
| 1407 |
$tree = menu_tree_page_data($menu_name);
|
| 1408 |
|
| 1409 |
|
| 1410 |
while ($level-- > 0 && $tree) {
|
| 1411 |
|
| 1412 |
while ($item = array_shift($tree)) {
|
| 1413 |
if ($item['link']['in_active_trail']) {
|
| 1414 |
|
| 1415 |
$tree = empty($item['below']) ? array() : $item['below'];
|
| 1416 |
break;
|
| 1417 |
}
|
| 1418 |
}
|
| 1419 |
}
|
| 1420 |
|
| 1421 |
|
| 1422 |
$links = array();
|
| 1423 |
foreach ($tree as $item) {
|
| 1424 |
if (!$item['link']['hidden']) {
|
| 1425 |
$class = '';
|
| 1426 |
$l = $item['link']['localized_options'];
|
| 1427 |
$l['href'] = $item['link']['href'];
|
| 1428 |
$l['title'] = $item['link']['title'];
|
| 1429 |
if ($item['link']['in_active_trail']) {
|
| 1430 |
$class = ' active-trail';
|
| 1431 |
}
|
| 1432 |
|
| 1433 |
$links['menu-' . $item['link']['mlid'] . $class] = $l;
|
| 1434 |
}
|
| 1435 |
}
|
| 1436 |
return $links;
|
| 1437 |
}
|
| 1438 |
|
| 1439 |
|
| 1440 |
|
| 1441 |
|
| 1442 |
|
| 1443 |
|
| 1444 |
|
| 1445 |
|
| 1446 |
|
| 1447 |
|
| 1448 |
|
| 1449 |
|
| 1450 |
|
| 1451 |
function menu_local_tasks($level = 0, $return_root = FALSE) {
|
| 1452 |
$tabs = &drupal_static(__FUNCTION__);
|
| 1453 |
$root_path = &drupal_static(__FUNCTION__ . ':root_path');
|
| 1454 |
|
| 1455 |
if (!isset($tabs)) {
|
| 1456 |
$tabs = array();
|
| 1457 |
|
| 1458 |
$router_item = menu_get_item();
|
| 1459 |
if (!$router_item || !$router_item['access']) {
|
| 1460 |
return '';
|
| 1461 |
}
|
| 1462 |
|
| 1463 |
$result = db_select('menu_router', NULL, array('fetch' => PDO::FETCH_ASSOC))
|
| 1464 |
->fields('menu_router')
|
| 1465 |
->condition('tab_root', $router_item['tab_root'])
|
| 1466 |
->orderBy('weight')
|
| 1467 |
->orderBy('title')
|
| 1468 |
->execute();
|
| 1469 |
$map = arg();
|
| 1470 |
$children = array();
|
| 1471 |
$tasks = array();
|
| 1472 |
$root_path = $router_item['path'];
|
| 1473 |
|
| 1474 |
foreach ($result as $item) {
|
| 1475 |
_menu_translate($item, $map, TRUE);
|
| 1476 |
if ($item['tab_parent']) {
|
| 1477 |
|
| 1478 |
$children[$item['tab_parent']][$item['path']] = $item;
|
| 1479 |
}
|
| 1480 |
|
| 1481 |
$tasks[$item['path']] = $item;
|
| 1482 |
}
|
| 1483 |
|
| 1484 |
|
| 1485 |
$path = $router_item['path'];
|
| 1486 |
|
| 1487 |
|
| 1488 |
$depth = 1001;
|
| 1489 |
while (isset($children[$path])) {
|
| 1490 |
$tabs_current = '';
|
| 1491 |
$next_path = '';
|
| 1492 |
$count = 0;
|
| 1493 |
foreach ($children[$path] as $item) {
|
| 1494 |
if ($item['access']) {
|
| 1495 |
$count++;
|
| 1496 |
|
| 1497 |
if ($item['type'] == MENU_DEFAULT_LOCAL_TASK) {
|
| 1498 |
|
| 1499 |
for ($p = $item['tab_parent']; $tasks[$p]['type'] == MENU_DEFAULT_LOCAL_TASK; $p = $tasks[$p]['tab_parent']);
|
| 1500 |
$link = theme('menu_item_link', array('href' => $tasks[$p]['href']) + $item);
|
| 1501 |
$tabs_current .= theme('menu_local_task', $link, TRUE);
|
| 1502 |
$next_path = $item['path'];
|
| 1503 |
}
|
| 1504 |
|
| 1505 |
$link = theme('menu_item_link', $item);
|
| 1506 |
$tabs_current .= theme('menu_local_task', $link);
|
| 1507 |
|
| 1508 |
}
|
| 1509 |
}
|
| 1510 |
$path = $next_path;
|
| 1511 |
$tabs[$depth]['count'] = $count;
|
| 1512 |
$tabs[$depth]['output'] = $tabs_current;
|
| 1513 |
$depth++;
|
| 1514 |
}
|
| 1515 |
|
| 1516 |
|
| 1517 |
$parent = $router_item['tab_parent'];
|
| 1518 |
$path = $router_item['path'];
|
| 1519 |
$current = $router_item;
|
| 1520 |
$depth = 1000;
|
| 1521 |
while (isset($children[$parent])) {
|
| 1522 |
$tabs_current = '';
|
| 1523 |
$next_path = '';
|
| 1524 |
$next_parent = '';
|
| 1525 |
$count = 0;
|
| 1526 |
foreach ($children[$parent] as $item) {
|
| 1527 |
if ($item['access']) {
|
| 1528 |
$count++;
|
| 1529 |
if ($item['type'] == MENU_DEFAULT_LOCAL_TASK) {
|
| 1530 |
|
| 1531 |
for ($p = $item['tab_parent']; $tasks[$p]['type'] == MENU_DEFAULT_LOCAL_TASK; $p = $tasks[$p]['tab_parent']);
|
| 1532 |
$link = theme('menu_item_link', array('href' => $tasks[$p]['href']) + $item);
|
| 1533 |
if ($item['path'] == $router_item['path']) {
|
| 1534 |
$root_path = $tasks[$p]['path'];
|
| 1535 |
}
|
| 1536 |
}
|
| 1537 |
|
| 1538 |
$link = theme('menu_item_link', $item);
|
| 1539 |
|
| 1540 |
|
| 1541 |
if ($item['path'] == $path) {
|
| 1542 |
$tabs_current .= theme('menu_local_task', $link, TRUE);
|
| 1543 |
$next_path = $item['tab_parent'];
|
| 1544 |
if (isset($tasks[$next_path])) {
|
| 1545 |
$next_parent = $tasks[$next_path]['tab_parent'];
|
| 1546 |
}
|
| 1547 |
}
|
| 1548 |
|
| 1549 |
$tabs_current .= theme('menu_local_task', $link);
|
| 1550 |
|
| 1551 |
}
|
| 1552 |
}
|
| 1553 |
$path = $next_path;
|
| 1554 |
$parent = $next_parent;
|
| 1555 |
$tabs[$depth]['count'] = $count;
|
| 1556 |
$tabs[$depth]['output'] = $tabs_current;
|
| 1557 |
$depth--;
|
| 1558 |
}
|
| 1559 |
|
| 1560 |
ksort($tabs);
|
| 1561 |
|
| 1562 |
$tabs = array_values($tabs);
|
| 1563 |
}
|
| 1564 |
|
| 1565 |
if ($return_root) {
|
| 1566 |
return $root_path;
|
| 1567 |
}
|
| 1568 |
|
| 1569 |
|
| 1570 |
return (isset($tabs[$level]) && $tabs[$level]['count'] > 1) ? $tabs[$level]['output'] : '';
|
| 1571 |
|
| 1572 |
}
|
| 1573 |
|
| 1574 |
|
| 1575 |
|
| 1576 |
|
| 1577 |
function menu_primary_local_tasks() {
|
| 1578 |
return menu_local_tasks(0);
|
| 1579 |
}
|
| 1580 |
|
| 1581 |
|
| 1582 |
|
| 1583 |
|
| 1584 |
function menu_secondary_local_tasks() {
|
| 1585 |
return menu_local_tasks(1);
|
| 1586 |
}
|
| 1587 |
|
| 1588 |
|
| 1589 |
|
| 1590 |
|
| 1591 |
function menu_tab_root_path() {
|
| 1592 |
return menu_local_tasks(0, TRUE);
|
| 1593 |
}
|
| 1594 |
|
| 1595 |
|
| 1596 |
|
| 1597 |
|
| 1598 |
|
| 1599 |
|
| 1600 |
function theme_menu_local_tasks() {
|
| 1601 |
$output = '';
|
| 1602 |
|
| 1603 |
if ($primary = menu_primary_local_tasks()) {
|
| 1604 |
$output .= "<ul class=\"tabs primary\">\n" . $primary . "</ul>\n";
|
| 1605 |
}
|
| 1606 |
if ($secondary = menu_secondary_local_tasks()) {
|
| 1607 |
$output .= "<ul class=\"tabs secondary\">\n" . $secondary . "</ul>\n";
|
| 1608 |
}
|
| 1609 |
|
| 1610 |
return $output;
|
| 1611 |
}
|
| 1612 |
|
| 1613 |
|
| 1614 |
|
| 1615 |
|
| 1616 |
function menu_set_active_menu_names($menu_names = NULL) {
|
| 1617 |
$active = &drupal_static(__FUNCTION__);
|
| 1618 |
|
| 1619 |
if (isset($menu_names) && is_array($menu_names)) {
|
| 1620 |
$active = $menu_names;
|
| 1621 |
}
|
| 1622 |
elseif (!isset($active)) {
|
| 1623 |
$active = variable_get('menu_default_active_menus', array('management', 'navigation', 'user-menu', 'main-menu'));
|
| 1624 |
}
|
| 1625 |
return $active;
|
| 1626 |
}
|
| 1627 |
|
| 1628 |
|
| 1629 |
|
| 1630 |
|
| 1631 |
function menu_get_active_menu_names() {
|
| 1632 |
return menu_set_active_menu_names();
|
| 1633 |
}
|
| 1634 |
|
| 1635 |
|
| 1636 |
|
| 1637 |
|
| 1638 |
|
| 1639 |
|
| 1640 |
|
| 1641 |
|
| 1642 |
|
| 1643 |
|
| 1644 |
|
| 1645 |
function menu_set_active_item($path) {
|
| 1646 |
$_GET['q'] = $path;
|
| 1647 |
}
|
| 1648 |
|
| 1649 |
|
| 1650 |
|
| 1651 |
|
| 1652 |
function menu_set_active_trail($new_trail = NULL) {
|
| 1653 |
$trail = &drupal_static(__FUNCTION__);
|
| 1654 |
|
| 1655 |
if (isset($new_trail)) {
|
| 1656 |
$trail = $new_trail;
|
| 1657 |
}
|
| 1658 |
elseif (!isset($trail)) {
|
| 1659 |
$trail = array();
|
| 1660 |
$trail[] = array('title' => t('Home'), 'href' => '<front>', 'localized_options' => array(), 'type' => 0);
|
| 1661 |
$item = menu_get_item();
|
| 1662 |
|
| 1663 |
|
| 1664 |
if ($item['tab_parent']) {
|
| 1665 |
|
| 1666 |
|
| 1667 |
|
| 1668 |
|
| 1669 |
$parts = explode('/', $item['tab_root']);
|
| 1670 |
$args = arg();
|
| 1671 |
|
| 1672 |
foreach ($parts as $index => $part) {
|
| 1673 |
if ($part == '%') {
|
| 1674 |
$parts[$index] = $args[$index];
|
| 1675 |
}
|
| 1676 |
}
|
| 1677 |
|
| 1678 |
$root_item = menu_get_item(implode('/', $parts));
|
| 1679 |
if ($root_item && $root_item['access']) {
|
| 1680 |
$item = $root_item;
|
| 1681 |
}
|
| 1682 |
}
|
| 1683 |
$menu_names = menu_get_active_menu_names();
|
| 1684 |
$curr = FALSE;
|
| 1685 |
|
| 1686 |
if ($menu_names) {
|
| 1687 |
$query = db_select('menu_links', 'ml');
|
| 1688 |
$query->fields('ml', array('menu_name'));
|
| 1689 |
$query->condition('ml.link_path', $item['href']);
|
| 1690 |
$query->condition('ml.menu_name', $menu_names, 'IN');
|
| 1691 |
$result = $query->execute();
|
| 1692 |
$found = array();
|
| 1693 |
foreach ($result as $menu) {
|
| 1694 |
$found[] = $menu->menu_name;
|
| 1695 |
}
|
| 1696 |
|
| 1697 |
$name = current(array_intersect($menu_names, $found));
|
| 1698 |
if ($name !== FALSE) {
|
| 1699 |
$tree = menu_tree_page_data($name);
|
| 1700 |
list($key, $curr) = each($tree);
|
| 1701 |
}
|
| 1702 |
}
|
| 1703 |
|
| 1704 |
while ($curr) {
|
| 1705 |
|
| 1706 |
if ($curr['link']['href'] == $item['href']) {
|
| 1707 |
$trail[] = $curr['link'];
|
| 1708 |
$curr = FALSE;
|
| 1709 |
}
|
| 1710 |
|
| 1711 |
|
| 1712 |
if ($curr['link']['in_active_trail']) {
|
| 1713 |
$trail[] = $curr['link'];
|
| 1714 |
$tree = $curr['below'] ? $curr['below'] : array();
|
| 1715 |
}
|
| 1716 |
list($key, $curr) = each($tree);
|
| 1717 |
|
| 1718 |
}
|
| 1719 |
|
| 1720 |
|
| 1721 |
$last = count($trail) - 1;
|
| 1722 |
if ($trail[$last]['href'] != $item['href'] && !(bool)($item['type'] & MENU_IS_LOCAL_TASK) && !drupal_is_front_page()) {
|
| 1723 |
$trail[] = $item;
|
| 1724 |
}
|
| 1725 |
}
|
| 1726 |
return $trail;
|
| 1727 |
}
|
| 1728 |
|
| 1729 |
|
| 1730 |
|
| 1731 |
|
| 1732 |
function menu_get_active_trail() {
|
| 1733 |
return menu_set_active_trail();
|
| 1734 |
}
|
| 1735 |
|
| 1736 |
|
| 1737 |
|
| 1738 |
|
| 1739 |
function menu_get_active_breadcrumb() {
|
| 1740 |
$breadcrumb = array();
|
| 1741 |
|
| 1742 |
|
| 1743 |
if (drupal_is_front_page()) {
|
| 1744 |
return $breadcrumb;
|
| 1745 |
}
|
| 1746 |
|
| 1747 |
$item = menu_get_item();
|
| 1748 |
if ($item && $item['access']) {
|
| 1749 |
$active_trail = menu_get_active_trail();
|
| 1750 |
|
| 1751 |
foreach ($active_trail as $parent) {
|
| 1752 |
$breadcrumb[] = l($parent['title'], $parent['href'], $parent['localized_options']);
|
| 1753 |
}
|
| 1754 |
$end = end($active_trail);
|
| 1755 |
|
| 1756 |
|
| 1757 |
if ($item['href'] == $end['href'] || ($item['type'] == MENU_DEFAULT_LOCAL_TASK && $end['href'] != '<front>')) {
|
| 1758 |
array_pop($breadcrumb);
|
| 1759 |
}
|
| 1760 |
}
|
| 1761 |
return $breadcrumb;
|
| 1762 |
}
|
| 1763 |
|
| 1764 |
|
| 1765 |
|
| 1766 |
|
| 1767 |
function menu_get_active_title() {
|
| 1768 |
$active_trail = menu_get_active_trail();
|
| 1769 |
|
| 1770 |
foreach (array_reverse($active_trail) as $item) {
|
| 1771 |
if (!(bool)($item['type'] & MENU_IS_LOCAL_TASK)) {
|
| 1772 |
return $item['title'];
|
| 1773 |
}
|
| 1774 |
}
|
| 1775 |
}
|
| 1776 |
|
| 1777 |
|
| 1778 |
|
| 1779 |
|
| 1780 |
|
| 1781 |
|
| 1782 |
|
| 1783 |
|
| 1784 |
|
| 1785 |
|
| 1786 |
|
| 1787 |
|
| 1788 |
|
| 1789 |
|
| 1790 |
function menu_link_load($mlid) {
|
| 1791 |
if (is_numeric($mlid)) {
|
| 1792 |
$query = db_select('menu_links', 'ml');
|
| 1793 |
$query->leftJoin('menu_router', 'm', 'm.path = ml.router_path');
|
| 1794 |
$query->fields('ml');
|
| 1795 |
$query->fields('m');
|
| 1796 |
$query->condition('ml.mlid', $mlid);
|
| 1797 |
if ($item = $query->execute()->fetchAssoc()) {
|
| 1798 |
_menu_link_translate($item);
|
| 1799 |
return $item;
|
| 1800 |
}
|
| 1801 |
}
|
| 1802 |
return FALSE;
|
| 1803 |
}
|
| 1804 |
|
| 1805 |
|
| 1806 |
|
| 1807 |
|
| 1808 |
function menu_cache_clear($menu_name = 'navigation') {
|
| 1809 |
$cache_cleared = &drupal_static(__FUNCTION__, array());
|
| 1810 |
|
| 1811 |
if (empty($cache_cleared[$menu_name])) {
|
| 1812 |
cache_clear_all('links:' . $menu_name . ':', 'cache_menu', TRUE);
|
| 1813 |
$cache_cleared[$menu_name] = 1;
|
| 1814 |
}
|
| 1815 |
elseif ($cache_cleared[$menu_name] == 1) {
|
| 1816 |
register_shutdown_function('cache_clear_all', 'links:' . $menu_name . ':', 'cache_menu', TRUE);
|
| 1817 |
$cache_cleared[$menu_name] = 2;
|
| 1818 |
}
|
| 1819 |
}
|
| 1820 |
|
| 1821 |
|
| 1822 |
|
| 1823 |
|
| 1824 |
|
| 1825 |
function menu_cache_clear_all() {
|
| 1826 |
cache_clear_all('*', 'cache_menu', TRUE);
|
| 1827 |
}
|
| 1828 |
|
| 1829 |
|
| 1830 |
|
| 1831 |
|
| 1832 |
|
| 1833 |
|
| 1834 |
|
| 1835 |
|
| 1836 |
|
| 1837 |
|
| 1838 |
|
| 1839 |
function menu_rebuild() {
|
| 1840 |
variable_del('menu_rebuild_needed');
|
| 1841 |
list($menu, $masks) = menu_router_build();
|
| 1842 |
_menu_router_save($menu, $masks);
|
| 1843 |
_menu_navigation_links_rebuild($menu);
|
| 1844 |
menu_cache_clear_all();
|
| 1845 |
|
| 1846 |
_menu_clear_page_cache();
|
| 1847 |
if (defined('MAINTENANCE_MODE')) {
|
| 1848 |
variable_set('menu_rebuild_needed', TRUE);
|
| 1849 |
}
|
| 1850 |
}
|
| 1851 |
|
| 1852 |
|
| 1853 |
|
| 1854 |
|
| 1855 |
function menu_router_build() {
|
| 1856 |
|
| 1857 |
|
| 1858 |
$callbacks = array();
|
| 1859 |
foreach (module_implements('menu') as $module) {
|
| 1860 |
$router_items = call_user_func($module . '_menu');
|
| 1861 |
if (isset($router_items) && is_array($router_items)) {
|
| 1862 |
foreach (array_keys($router_items) as $path) {
|
| 1863 |
$router_items[$path]['module'] = $module;
|
| 1864 |
}
|
| 1865 |
$callbacks = array_merge($callbacks, $router_items);
|
| 1866 |
}
|
| 1867 |
}
|
| 1868 |
|
| 1869 |
drupal_alter('menu', $callbacks);
|
| 1870 |
list($menu, $masks) = _menu_router_build($callbacks);
|
| 1871 |
_menu_router_cache($menu);
|
| 1872 |
|
| 1873 |
return array($menu, $masks);
|
| 1874 |
}
|
| 1875 |
|
| 1876 |
|
| 1877 |
|
| 1878 |
|
| 1879 |
function _menu_router_cache($new_menu = NULL) {
|
| 1880 |
$menu = &drupal_static(__FUNCTION__);
|
| 1881 |
|
| 1882 |
if (isset($new_menu)) {
|
| 1883 |
$menu = $new_menu;
|
| 1884 |
}
|
| 1885 |
return $menu;
|
| 1886 |
}
|
| 1887 |
|
| 1888 |
|
| 1889 |
|
| 1890 |
|
| 1891 |
function menu_get_router() {
|
| 1892 |
|
| 1893 |
$menu = _menu_router_cache();
|
| 1894 |
if (empty($menu)) {
|
| 1895 |
list($menu, $masks) = menu_router_build();
|
| 1896 |
}
|
| 1897 |
return $menu;
|
| 1898 |
}
|
| 1899 |
|
| 1900 |
|
| 1901 |
|
| 1902 |
|
| 1903 |
function _menu_link_build($item) {
|
| 1904 |
if ($item['type'] == MENU_CALLBACK) {
|
| 1905 |
$item['hidden'] = -1;
|
| 1906 |
}
|
| 1907 |
elseif ($item['type'] == MENU_SUGGESTED_ITEM) {
|
| 1908 |
$item['hidden'] = 1;
|
| 1909 |
}
|
| 1910 |
|
| 1911 |
|
| 1912 |
$item['module'] = 'system';
|
| 1913 |
|
| 1914 |
'menu_name' => 'navigation',
|
| 1915 |
'link_title' => $item['title'],
|
| 1916 |
'link_path' => $item['path'],
|
| 1917 |
'hidden' => 0,
|
| 1918 |
'options' => empty($item['description']) ? array() : array('attributes' => array('title' => $item['description'])),
|
| 1919 |
);
|
| 1920 |
return $item;
|
| 1921 |
}
|
| 1922 |
|
| 1923 |
|
| 1924 |
|
| 1925 |
|
| 1926 |
function _menu_navigation_links_rebuild($menu) {
|
| 1927 |
|
| 1928 |
$menu_links = array();
|
| 1929 |
foreach ($menu as $path => $item) {
|
| 1930 |
if ($item['_visible']) {
|
| 1931 |
$menu_links[$path] = $item;
|
| 1932 |
$sort[$path] = $item['_number_parts'];
|
| 1933 |
}
|
| 1934 |
}
|
| 1935 |
if ($menu_links) {
|
| 1936 |
|
| 1937 |
array_multisort($sort, SORT_NUMERIC, $menu_links);
|
| 1938 |
|
| 1939 |
foreach ($menu_links as $item) {
|
| 1940 |
$existing_item = db_select('menu_links')
|
| 1941 |
->fields('menu_links', array(
|
| 1942 |
'mlid',
|
| 1943 |
'menu_name',
|
| 1944 |
'plid',
|
| 1945 |
'customized',
|
| 1946 |
'has_children',
|
| 1947 |
'updated',
|
| 1948 |
))
|
| 1949 |
->condition('link_path', $item['path'])
|
| 1950 |
->condition('module', 'system')
|
| 1951 |
->execute()->fetchAssoc();
|
| 1952 |
if ($existing_item) {
|
| 1953 |
$item['mlid'] = $existing_item['mlid'];
|
| 1954 |
|
| 1955 |
if (empty($item['menu_name']) || ($item['menu_name'] == $existing_item['menu_name'])) {
|
| 1956 |
$item['menu_name'] = $existing_item['menu_name'];
|
| 1957 |
$item['plid'] = $existing_item['plid'];
|
| 1958 |
}
|
| 1959 |
|
| 1960 |
|
| 1961 |
$item['plid'] = 0;
|
| 1962 |
|
| 1963 |
$item['has_children'] = $existing_item['has_children'];
|
| 1964 |
$item['updated'] = $existing_item['updated'];
|
| 1965 |
}
|
| 1966 |
if (!$existing_item || !$existing_item['customized']) {
|
| 1967 |
$item = _menu_link_build($item);
|
| 1968 |
menu_link_save($item);
|
| 1969 |
}
|
| 1970 |
}
|
| 1971 |
}
|
| 1972 |
$paths = array_keys($menu);
|
| 1973 |
|
| 1974 |
$result = db_select('menu_links', NULL, array('fetch' => PDO::FETCH_ASSOC))
|
| 1975 |
->fields('menu_links', array(
|
| 1976 |
'link_path',
|
| 1977 |
'mlid',
|
| 1978 |
'router_path',
|
| 1979 |
'updated',
|
| 1980 |
))
|
| 1981 |
->condition(db_or()
|
| 1982 |
->condition('updated', 1)
|
| 1983 |
->condition(db_and()
|
| 1984 |
->condition('router_path', $paths, 'NOT IN')
|
| 1985 |
->condition('external', 0)
|
| 1986 |
->condition('customized', 1)
|
| 1987 |
)
|
| 1988 |
)
|
| 1989 |
->execute();
|
| 1990 |
foreach ($result as $item) {
|
| 1991 |
$router_path = _menu_find_router_path($item['link_path']);
|
| 1992 |
if (!empty($router_path) && ($router_path != $item['router_path'] || $item['updated'])) {
|
| 1993 |
|
| 1994 |
|
| 1995 |
$updated = $item['updated'] && $router_path != $item['link_path'];
|
| 1996 |
db_update('menu_links')
|
| 1997 |
->fields(array(
|
| 1998 |
'router_path' => $router_path,
|
| 1999 |
'updated' => (int) $updated,
|
| 2000 |
))
|
| 2001 |
->condition('mlid', $item['mlid'])
|
| 2002 |
->execute();
|
| 2003 |
}
|
| 2004 |
}
|
| 2005 |
|
| 2006 |
$result = db_select('menu_links')
|
| 2007 |
->fields('menu_links')
|
| 2008 |
->condition('router_path', $paths, 'NOT IN')
|
| 2009 |
->condition('external', 0)
|
| 2010 |
->condition('updated', 0)
|
| 2011 |
->condition('customized', 0)
|
| 2012 |
->orderBy('depth', 'DESC')
|
| 2013 |
->execute();
|
| 2014 |
|
| 2015 |
|
| 2016 |
foreach ($result as $item) {
|
| 2017 |
_menu_delete_item($item, TRUE);
|
| 2018 |
}
|
| 2019 |
}
|
| 2020 |
|
| 2021 |
|
| 2022 |
|
| 2023 |
|
| 2024 |
|
| 2025 |
|
| 2026 |
|
| 2027 |
|
| 2028 |
|
| 2029 |
function menu_link_delete($mlid, $path = NULL) {
|
| 2030 |
if (isset($mlid)) {
|
| 2031 |
_menu_delete_item(db_query("SELECT * FROM {menu_links} WHERE mlid = :mlid", array(':mlid' => $mlid))->fetchAssoc());
|
| 2032 |
}
|
| 2033 |
|
| 2034 |
$result = db_query("SELECT * FROM {menu_links} WHERE link_path = :link_path", array(':link_path' => $path));
|
| 2035 |
foreach ($result as $link) {
|
| 2036 |
_menu_delete_item($link);
|
| 2037 |
}
|
| 2038 |
|
| 2039 |
}
|
| 2040 |
|
| 2041 |
|
| 2042 |
|
| 2043 |
|
| 2044 |
|
| 2045 |
|
| 2046 |
|
| 2047 |
|
| 2048 |
|
| 2049 |
function _menu_delete_item($item, $force = FALSE) {
|
| 2050 |
$item = is_object($item) ? get_object_vars($item) : $item;
|
| 2051 |
if ($item && ($item['module'] != 'system' || $item['updated'] || $force)) {
|
| 2052 |
|
| 2053 |
if ($item['has_children']) {
|
| 2054 |
$result = db_query("SELECT mlid FROM {menu_links} WHERE plid = :plid", array(':plid' => $item['mlid']));
|
| 2055 |
foreach ($result as $m) {
|
| 2056 |
$child = menu_link_load($m->mlid);
|
| 2057 |
$child['plid'] = $item['plid'];
|
| 2058 |
menu_link_save($child);
|
| 2059 |
}
|
| 2060 |
}
|
| 2061 |
db_delete('menu_links')->condition('mlid', $item['mlid'])->execute();
|
| 2062 |
|
| 2063 |
|
| 2064 |
_menu_update_parental_status($item);
|
| 2065 |
menu_cache_clear($item['menu_name']);
|
| 2066 |
_menu_clear_page_cache();
|
| 2067 |
}
|
| 2068 |
}
|
| 2069 |
|
| 2070 |
|
| 2071 |
|
| 2072 |
|
| 2073 |
|
| 2074 |
|
| 2075 |
|
| 2076 |
|
| 2077 |
|
| 2078 |
|
| 2079 |
|
| 2080 |
|
| 2081 |
|
| 2082 |
|
| 2083 |
|
| 2084 |
|
| 2085 |
|
| 2086 |
|
| 2087 |
function menu_link_save(&$item) {
|
| 2088 |
|
| 2089 |
drupal_alter('menu_link', $item);
|
| 2090 |
|
| 2091 |
|
| 2092 |
|
| 2093 |
$item['external'] = (menu_path_is_external($item['link_path']) || $item['link_path'] == '<front>') ? 1 : 0;
|
| 2094 |
|
| 2095 |
|
| 2096 |
'menu_name' => 'navigation',
|
| 2097 |
'weight' => 0,
|
| 2098 |
'link_title' => '',
|
| 2099 |
'hidden' => 0,
|
| 2100 |
'has_children' => 0,
|
| 2101 |
'expanded' => 0,
|
| 2102 |
'options' => array(),
|
| 2103 |
'module' => 'menu',
|
| 2104 |
'customized' => 0,
|
| 2105 |
'updated' => 0,
|
| 2106 |
);
|
| 2107 |
$existing_item = FALSE;
|
| 2108 |
if (isset($item['mlid'])) {
|
| 2109 |
if ($existing_item = db_query("SELECT * FROM {menu_links} WHERE mlid = :mlid", array(':mlid' => $item['mlid']))->fetchAssoc()) {
|
| 2110 |
$existing_item['options'] = unserialize($existing_item['options']);
|
| 2111 |
}
|
| 2112 |
}
|
| 2113 |
|
| 2114 |
if (isset($item['plid'])) {
|
| 2115 |
if ($item['plid']) {
|
| 2116 |
$parent = db_query("SELECT * FROM {menu_links} WHERE mlid = :mlid", array(':mlid' => $item['plid']))->fetchAssoc();
|
| 2117 |
}
|
| 2118 |
|
| 2119 |
|
| 2120 |
$parent = FALSE;
|
| 2121 |
|
| 2122 |
}
|
| 2123 |
|
| 2124 |
$query = db_select('menu_links');
|
| 2125 |
|
| 2126 |
|
| 2127 |
if ($item['module'] == 'system') {
|
| 2128 |
$query->condition('module', 'system');
|
| 2129 |
}
|
| 2130 |
|
| 2131 |
|
| 2132 |
$query->condition('menu_name', $item['menu_name']);
|
| 2133 |
|
| 2134 |
|
| 2135 |
|
| 2136 |
$parent_path = $item['link_path'];
|
| 2137 |
|
| 2138 |
$parent = FALSE;
|
| 2139 |
$parent_path = substr($parent_path, 0, strrpos($parent_path, '/'));
|
| 2140 |
$new_query = clone $query;
|
| 2141 |
$new_query->condition('link_path', $parent_path);
|
| 2142 |
|
| 2143 |
if ($new_query->countQuery()->execute()->fetchField() == 1) {
|
| 2144 |
$parent = $new_query->fields('menu_links')->execute()->fetchAssoc();
|
| 2145 |
}
|
| 2146 |
} while ($parent === FALSE && $parent_path);
|
| 2147 |
|
| 2148 |
if ($parent !== FALSE) {
|
| 2149 |
$item['menu_name'] = $parent['menu_name'];
|
| 2150 |
}
|
| 2151 |
$menu_name = $item['menu_name'];
|
| 2152 |
|
| 2153 |
|
| 2154 |
if (empty($parent['mlid']) || $parent['hidden'] < 0) {
|
| 2155 |
$item['plid'] = 0;
|
| 2156 |
}
|
| 2157 |
|
| 2158 |
$item['plid'] = $parent['mlid'];
|
| 2159 |
|
| 2160 |
|
| 2161 |
if (!$existing_item) {
|
| 2162 |
$item['mlid'] = db_insert('menu_links')
|
| 2163 |
->fields(array(
|
| 2164 |
'menu_name' => $item['menu_name'],
|
| 2165 |
'plid' => $item['plid'],
|
| 2166 |
'link_path' => $item['link_path'],
|
| 2167 |
'hidden' => $item['hidden'],
|
| 2168 |
'external' => $item['external'],
|
| 2169 |
'has_children' => $item['has_children'],
|
| 2170 |
'expanded' => $item['expanded'],
|
| 2171 |
'weight' => $item['weight'],
|
| 2172 |
'module' => $item['module'],
|
| 2173 |
'link_title' => $item['link_title'],
|
| 2174 |
'options' => serialize($item['options']),
|
| 2175 |
'customized' => $item['customized'],
|
| 2176 |
'updated' => $item['updated'],
|
| 2177 |
))
|
| 2178 |
->execute();
|
| 2179 |
}
|
| 2180 |
|
| 2181 |
if (!$item['plid']) {
|
| 2182 |
$item['p1'] = $item['mlid'];
|
| 2183 |
for ($i = 2; $i <= MENU_MAX_DEPTH; $i++) {
|
| 2184 |
$item["p$i"] = 0;
|
| 2185 |
}
|
| 2186 |
$item['depth'] = 1;
|
| 2187 |
}
|
| 2188 |
|
| 2189 |
|
| 2190 |
if ($item['has_children'] && $existing_item) {
|
| 2191 |
$limit = MENU_MAX_DEPTH - menu_link_children_relative_depth($existing_item) - 1;
|
| 2192 |
}
|
| 2193 |
|
| 2194 |
$limit = MENU_MAX_DEPTH - 1;
|
| 2195 |
|
| 2196 |
if ($parent['depth'] > $limit) {
|
| 2197 |
return FALSE;
|
| 2198 |
}
|
| 2199 |
$item['depth'] = $parent['depth'] + 1;
|
| 2200 |
_menu_link_parents_set($item, $parent);
|
| 2201 |
|
| 2202 |
|
| 2203 |
if ($existing_item && ($item['plid'] != $existing_item['plid'] || $menu_name != $existing_item['menu_name'])) {
|
| 2204 |
_menu_link_move_children($item, $existing_item);
|
| 2205 |
}
|
| 2206 |
|
| 2207 |
if (empty($item['router_path']) || !$existing_item || ($existing_item['link_path'] != $item['link_path'])) {
|
| 2208 |
if ($item['external']) {
|
| 2209 |
$item['router_path'] = '';
|
| 2210 |
}
|
| 2211 |
|
| 2212 |
|
| 2213 |
$item['parts'] = explode('/', $item['link_path'], MENU_MAX_PARTS);
|
| 2214 |
$item['router_path'] = _menu_find_router_path($item['link_path']);
|
| 2215 |
|
| 2216 |
}
|
| 2217 |
|
| 2218 |
|
| 2219 |
|
| 2220 |
|
| 2221 |
|
| 2222 |
if (!$existing_item || (array_intersect_assoc($item, $existing_item)) != $existing_item) {
|
| 2223 |
db_update('menu_links')
|
| 2224 |
->fields(array(
|
| 2225 |
'menu_name' => $item['menu_name'],
|
| 2226 |
'plid' => $item['plid'],
|
| 2227 |
'link_path' => $item['link_path'],
|
| 2228 |
'router_path' => $item['router_path'],
|
| 2229 |
'hidden' => $item['hidden'],
|
| 2230 |
'external' => $item['external'],
|
| 2231 |
'has_children' => $item['has_children'],
|
| 2232 |
'expanded' => $item['expanded'],
|
| 2233 |
'weight' => $item['weight'],
|
| 2234 |
'depth' => $item['depth'],
|
| 2235 |
'p1' => $item['p1'],
|
| 2236 |
'p2' => $item['p2'],
|
| 2237 |
'p3' => $item['p3'],
|
| 2238 |
'p4' => $item['p4'],
|
| 2239 |
'p5' => $item['p5'],
|
| 2240 |
'p6' => $item['p6'],
|
| 2241 |
'p7' => $item['p7'],
|
| 2242 |
'p8' => $item['p8'],
|
| 2243 |
'p9' => $item['p9'],
|
| 2244 |
'module' => $item['module'],
|
| 2245 |
'link_title' => $item['link_title'],
|
| 2246 |
'options' => serialize($item['options']),
|
| 2247 |
'customized' => $item['customized'],
|
| 2248 |
))
|
| 2249 |
->condition('mlid', $item['mlid'])
|
| 2250 |
->execute();
|
| 2251 |
|
| 2252 |
_menu_update_parental_status($item);
|
| 2253 |
menu_cache_clear($menu_name);
|
| 2254 |
if ($existing_item && $menu_name != $existing_item['menu_name']) {
|
| 2255 |
menu_cache_clear($existing_item['menu_name']);
|
| 2256 |
}
|
| 2257 |
|
| 2258 |
_menu_clear_page_cache();
|
| 2259 |
}
|
| 2260 |
return $item['mlid'];
|
| 2261 |
}
|
| 2262 |
|
| 2263 |
|
| 2264 |
|
| 2265 |
|
| 2266 |
function _menu_clear_page_cache() {
|
| 2267 |
$cache_cleared = &drupal_static(__FUNCTION__, 0);
|
| 2268 |
|
| 2269 |
|
| 2270 |
|
| 2271 |
if ($cache_cleared == 0) {
|
| 2272 |
cache_clear_all();
|
| 2273 |
|
| 2274 |
_menu_set_expanded_menus();
|
| 2275 |
$cache_cleared = 1;
|
| 2276 |
}
|
| 2277 |
elseif ($cache_cleared == 1) {
|
| 2278 |
register_shutdown_function('cache_clear_all');
|
| 2279 |
|
| 2280 |
register_shutdown_function('_menu_set_expanded_menus');
|
| 2281 |
$cache_cleared = 2;
|
| 2282 |
}
|
| 2283 |
}
|
| 2284 |
|
| 2285 |
|
| 2286 |
|
| 2287 |
|
| 2288 |
function _menu_set_expanded_menus() {
|
| 2289 |
$names = db_query("SELECT menu_name FROM {menu_links} WHERE expanded <> 0 GROUP BY menu_name")->fetchCol();
|
| 2290 |
variable_set('menu_expanded', $names);
|
| 2291 |
}
|
| 2292 |
|
| 2293 |
|
| 2294 |
|
| 2295 |
|
| 2296 |
|
| 2297 |
|
| 2298 |
|
| 2299 |
|
| 2300 |
|
| 2301 |
|
| 2302 |
function _menu_find_router_path($link_path) {
|
| 2303 |
|
| 2304 |
$menu = _menu_router_cache();
|
| 2305 |
|
| 2306 |
$router_path = $link_path;
|
| 2307 |
$parts = explode('/', $link_path, MENU_MAX_PARTS);
|
| 2308 |
$ancestors = menu_get_ancestors($parts);
|
| 2309 |
|
| 2310 |
if (empty($menu)) {
|
| 2311 |
|
| 2312 |
$router_path = (string) db_select('menu_router')
|
| 2313 |
->fields('menu_router', array('path'))
|
| 2314 |
->condition('path', $ancestors, 'IN')
|
| 2315 |
->orderBy('fit', 'DESC')
|
| 2316 |
->range(0, 1)
|
| 2317 |
->execute()->fetchField();
|
| 2318 |
}
|
| 2319 |
elseif (!isset($menu[$router_path])) {
|
| 2320 |
|
| 2321 |
$ancestors[] = '';
|
| 2322 |
foreach ($ancestors as $key => $router_path) {
|
| 2323 |
if (isset($menu[$router_path])) {
|
| 2324 |
|
| 2325 |
break;
|
| 2326 |
}
|
| 2327 |
}
|
| 2328 |
|
| 2329 |
|
| 2330 |
}
|
| 2331 |
return $router_path;
|
| 2332 |
}
|
| 2333 |
|
| 2334 |
|
| 2335 |
|
| 2336 |
|
| 2337 |
|
| 2338 |
|
| 2339 |
|
| 2340 |
|
| 2341 |
|
| 2342 |
|
| 2343 |
|
| 2344 |
|
| 2345 |
|
| 2346 |
|
| 2347 |
|
| 2348 |
|
| 2349 |
function menu_link_maintain($module, $op, $link_path, $link_title) {
|
| 2350 |
|
| 2351 |
case 'insert':
|
| 2352 |
|
| 2353 |
'link_title' => $link_title,
|
| 2354 |
'link_path' => $link_path,
|
| 2355 |
'module' => $module,
|
| 2356 |
);
|
| 2357 |
return menu_link_save($menu_link);
|
| 2358 |
break;
|
| 2359 |
case 'update':
|
| 2360 |
db_update('menu_links')
|
| 2361 |
->fields(array('link_title' => $link_title))
|
| 2362 |
->condition('link_path', $link_path)
|
| 2363 |
->condition('customized', 0)
|
| 2364 |
->condition('module', $module)
|
| 2365 |
->execute();
|
| 2366 |
$result = db_select('menu_links')
|
| 2367 |
->fields('menu_links', array('menu_name'))
|
| 2368 |
->condition('link_path', $link_path)
|
| 2369 |
->condition('customized', 0)
|
| 2370 |
->condition('module', $module)
|
| 2371 |
->groupBy('menu_name')
|
| 2372 |
->execute()->fetchCol();
|
| 2373 |
foreach ($result as $menu_name) {
|
| 2374 |
menu_cache_clear($menu_name);
|
| 2375 |
}
|
| 2376 |
break;
|
| 2377 |
case 'delete':
|
| 2378 |
menu_link_delete(NULL, $link_path);
|
| 2379 |
break;
|
| 2380 |
}
|
| 2381 |
}
|
| 2382 |
|
| 2383 |
|
| 2384 |
|
| 2385 |
|
| 2386 |
|
| 2387 |
|
| 2388 |
|
| 2389 |
|
| 2390 |
|
| 2391 |
|
| 2392 |
|
| 2393 |
|
| 2394 |
|
| 2395 |
function menu_link_children_relative_depth($item) {
|
| 2396 |
$query = db_select('menu_links');
|
| 2397 |
$query->addField('menu_links', 'depth');
|
| 2398 |
$query->condition('menu_name', $item['menu_name']);
|
| 2399 |
$query->orderBy('depth', 'DESC');
|
| 2400 |
$query->range(0, 1);
|
| 2401 |
|
| 2402 |
$i = 1;
|
| 2403 |
$p = 'p1';
|
| 2404 |
while ($i <= MENU_MAX_DEPTH && $item[$p]) {
|
| 2405 |
$query->condition($p, $item[$p]);
|
| 2406 |
$p = 'p' . ++$i;
|
| 2407 |
}
|
| 2408 |
|
| 2409 |
$max_depth = $query->execute()->fetchField();
|
| 2410 |
|
| 2411 |
return ($max_depth > $item['depth']) ? $max_depth - $item['depth'] : 0;
|
| 2412 |
}
|
| 2413 |
|
| 2414 |
|
| 2415 |
|
| 2416 |
|
| 2417 |
|
| 2418 |
|
| 2419 |
|
| 2420 |
function _menu_link_move_children($item, $existing_item) {
|
| 2421 |
$query = db_update('menu_links');
|
| 2422 |
|
| 2423 |
$query->fields(array('menu_name' => $item['menu_name']));
|
| 2424 |
|
| 2425 |
$p = 'p1';
|
| 2426 |
for ($i = 1; $i <= $item['depth']; $p = 'p' . ++$i) {
|
| 2427 |
$query->fields(array($p => $item[$p]));
|
| 2428 |
}
|
| 2429 |
$j = $existing_item['depth'] + 1;
|
| 2430 |
while ($i <= MENU_MAX_DEPTH && $j <= MENU_MAX_DEPTH) {
|
| 2431 |
$query->expression('p' . $i++, 'p' . $j++);
|
| 2432 |
}
|
| 2433 |
while ($i <= MENU_MAX_DEPTH) {
|
| 2434 |
$query->fields(array('p' . $i++ => 0));
|
| 2435 |
}
|
| 2436 |
|
| 2437 |
$shift = $item['depth'] - $existing_item['depth'];
|
| 2438 |
if ($shift < 0) {
|
| 2439 |
$query->expression('depth', 'depth - :depth', array(':depth' => -$shift));
|
| 2440 |
}
|
| 2441 |
elseif ($shift > 0) {
|
| 2442 |
$query->expression('depth', 'depth + :depth', array(':depth' => $shift));
|
| 2443 |
}
|
| 2444 |
|
| 2445 |
$query->condition('menu_name', $existing_item['menu_name']);
|
| 2446 |
$p = 'p1';
|
| 2447 |
for ($i = 1; $i <= MENU_MAX_DEPTH && $existing_item[$p]; $p = 'p' . ++$i) {
|
| 2448 |
$query->condition($p, $existing_item[$p]);
|
| 2449 |
}
|
| 2450 |
|
| 2451 |
$query->execute();
|
| 2452 |
|
| 2453 |
|
| 2454 |
_menu_update_parental_status($existing_item, TRUE);
|
| 2455 |
}
|
| 2456 |
|
| 2457 |
|
| 2458 |
|
| 2459 |
|
| 2460 |
function _menu_update_parental_status($item, $exclude = FALSE) {
|
| 2461 |
|
| 2462 |
if ($item['plid']) {
|
| 2463 |
|
| 2464 |
$query = db_select('menu_links');
|
| 2465 |
$query->addField('menu_links', 'mlid');
|
| 2466 |
$query->condition('menu_name', $item['menu_name']);
|
| 2467 |
$query->condition('hidden', 0);
|
| 2468 |
$query->condition('plid', $item['plid']);
|
| 2469 |
$query->range(0, 1);
|
| 2470 |
if ($exclude) {
|
| 2471 |
$query->condition('mlid', $item['mlid'], '<>');
|
| 2472 |
}
|
| 2473 |
$parent_has_children = ((bool) $query->execute()->fetchField()) ? 1 : 0;
|
| 2474 |
db_update('menu_links')
|
| 2475 |
->fields(array('has_children' => $parent_has_children))
|
| 2476 |
->condition('mlid', $item['plid'])
|
| 2477 |
->execute();
|
| 2478 |
}
|
| 2479 |
}
|
| 2480 |
|
| 2481 |
|
| 2482 |
|
| 2483 |
|
| 2484 |
function _menu_link_parents_set(&$item, $parent) {
|
| 2485 |
$i = 1;
|
| 2486 |
while ($i < $item['depth']) {
|
| 2487 |
$p = 'p' . $i++;
|
| 2488 |
$item[$p] = $parent[$p];
|
| 2489 |
}
|
| 2490 |
$p = 'p' . $i++;
|
| 2491 |
|
| 2492 |
$item[$p] = $item['mlid'];
|
| 2493 |
while ($i <= MENU_MAX_DEPTH) {
|
| 2494 |
$p = 'p' . $i++;
|
| 2495 |
$item[$p] = 0;
|
| 2496 |
}
|
| 2497 |
}
|
| 2498 |
|
| 2499 |
|
| 2500 |
|
| 2501 |
|
| 2502 |
function _menu_router_build($callbacks) {
|
| 2503 |
|
| 2504 |
|
| 2505 |
$menu = array();
|
| 2506 |
$masks = array();
|
| 2507 |
foreach ($callbacks as $path => $item) {
|
| 2508 |
$load_functions = array();
|
| 2509 |
$to_arg_functions = array();
|
| 2510 |
$fit = 0;
|
| 2511 |
$move = FALSE;
|
| 2512 |
|
| 2513 |
$parts = explode('/', $path, MENU_MAX_PARTS);
|
| 2514 |
$number_parts = count($parts);
|
| 2515 |
|
| 2516 |
|
| 2517 |
$slashes = $number_parts - 1;
|
| 2518 |
|
| 2519 |
foreach ($parts as $k => $part) {
|
| 2520 |
$match = FALSE;
|
| 2521 |
|
| 2522 |
|
| 2523 |
|
| 2524 |
if (preg_match('/^%(|[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)$/', $part, $matches)) {
|
| 2525 |
if (empty($matches[1])) {
|
| 2526 |
$match = TRUE;
|
| 2527 |
$load_functions[$k] = NULL;
|
| 2528 |
}
|
| 2529 |
|
| 2530 |
if (drupal_function_exists($matches[1] . '_to_arg')) {
|
| 2531 |
$to_arg_functions[$k] = $matches[1] . '_to_arg';
|
| 2532 |
$load_functions[$k] = NULL;
|
| 2533 |
$match = TRUE;
|
| 2534 |
}
|
| 2535 |
if (drupal_function_exists($matches[1] . '_load')) {
|
| 2536 |
$function = $matches[1] . '_load';
|
| 2537 |
|
| 2538 |
|
| 2539 |
|
| 2540 |
$load_functions[$k] = isset($item['load arguments']) ? array($function => $item['load arguments']) : $function;
|
| 2541 |
$match = TRUE;
|
| 2542 |
}
|
| 2543 |
|
| 2544 |
}
|
| 2545 |
if ($match) {
|
| 2546 |
$parts[$k] = '%';
|
| 2547 |
}
|
| 2548 |
|
| 2549 |
$fit |= 1 << ($slashes - $k);
|
| 2550 |
|
| 2551 |
}
|
| 2552 |
if ($fit) {
|
| 2553 |
$move = TRUE;
|
| 2554 |
}
|
| 2555 |
|
| 2556 |
|
| 2557 |
$fit = (1 << $number_parts) - 1;
|
| 2558 |
|
| 2559 |
$masks[$fit] = 1;
|
| 2560 |
$item['load_functions'] = empty($load_functions) ? '' : serialize($load_functions);
|
| 2561 |
$item['to_arg_functions'] = empty($to_arg_functions) ? '' : serialize($to_arg_functions);
|
| 2562 |
|
| 2563 |
'title' => '',
|
| 2564 |
'weight' => 0,
|
| 2565 |
'type' => MENU_NORMAL_ITEM,
|
| 2566 |
'_number_parts' => $number_parts,
|
| 2567 |
'_parts' => $parts,
|
| 2568 |
'_fit' => $fit,
|
| 2569 |
);
|
| 2570 |
|
| 2571 |
'_visible' => (bool)($item['type'] & MENU_VISIBLE_IN_BREADCRUMB),
|
| 2572 |
'_tab' => (bool)($item['type'] & MENU_IS_LOCAL_TASK),
|
| 2573 |
);
|
| 2574 |
if ($move) {
|
| 2575 |
$new_path = implode('/', $item['_parts']);
|
| 2576 |
$menu[$new_path] = $item;
|
| 2577 |
$sort[$new_path] = $number_parts;
|
| 2578 |
}
|
| 2579 |
|
| 2580 |
$menu[$path] = $item;
|
| 2581 |
$sort[$path] = $number_parts;
|
| 2582 |
|
| 2583 |
}
|
| 2584 |
array_multisort($sort, SORT_NUMERIC, $menu);
|
| 2585 |
|
| 2586 |
foreach ($menu as $path => $v) {
|
| 2587 |
$item = &$menu[$path];
|
| 2588 |
if (!$item['_tab']) {
|
| 2589 |
|
| 2590 |
$item['tab_parent'] = '';
|
| 2591 |
$item['tab_root'] = $path;
|
| 2592 |
}
|
| 2593 |
for ($i = $item['_number_parts'] - 1; $i; $i--) {
|
| 2594 |
$parent_path = implode('/', array_slice($item['_parts'], 0, $i));
|
| 2595 |
if (isset($menu[$parent_path])) {
|
| 2596 |
|
| 2597 |
$parent = $menu[$parent_path];
|
| 2598 |
|
| 2599 |
if (!isset($item['tab_parent'])) {
|
| 2600 |
|
| 2601 |
$item['tab_parent'] = $parent_path;
|
| 2602 |
}
|
| 2603 |
if (!isset($item['tab_root']) && !$parent['_tab']) {
|
| 2604 |
$item['tab_root'] = $parent_path;
|
| 2605 |
}
|
| 2606 |
|
| 2607 |
|
| 2608 |
|
| 2609 |
if (($item['type'] == MENU_DEFAULT_LOCAL_TASK) && !isset($item['access callback']) && isset($parent['access callback'])) {
|
| 2610 |
$item['access callback'] = $parent['access callback'];
|
| 2611 |
if (!isset($item['access arguments']) && isset($parent['access arguments'])) {
|
| 2612 |
$item['access arguments'] = $parent['access arguments'];
|
| 2613 |
}
|
| 2614 |
}
|
| 2615 |
|
| 2616 |
if (!isset($item['page callback']) && isset($parent['page callback'])) {
|
| 2617 |
$item['page callback'] = $parent['page callback'];
|
| 2618 |
if (!isset($item['page arguments']) && isset($parent['page arguments'])) {
|
| 2619 |
$item['page arguments'] = $parent['page arguments'];
|
| 2620 |
}
|
| 2621 |
}
|
| 2622 |
}
|
| 2623 |
}
|
| 2624 |
if (!isset($item['access callback']) && isset($item['access arguments'])) {
|
| 2625 |
|
| 2626 |
$item['access callback'] = 'user_access';
|
| 2627 |
}
|
| 2628 |
if (!isset($item['access callback']) || empty($item['page callback'])) {
|
| 2629 |
$item['access callback'] = 0;
|
| 2630 |
}
|
| 2631 |
if (is_bool($item['access callback'])) {
|
| 2632 |
$item['access callback'] = intval($item['access callback']);
|
| 2633 |
}
|
| 2634 |
|
| 2635 |
|
| 2636 |
'access arguments' => array(),
|
| 2637 |
'access callback' => '',
|
| 2638 |
'page arguments' => array(),
|
| 2639 |
'page callback' => '',
|
| 2640 |
'block callback' => '',
|
| 2641 |
'title arguments' => array(),
|
| 2642 |
'title callback' => 't',
|
| 2643 |
'description' => '',
|
| 2644 |
'position' => '',
|
| 2645 |
'tab_parent' => '',
|
| 2646 |
'tab_root' => $path,
|
| 2647 |
'path' => $path,
|
| 2648 |
);
|
| 2649 |
}
|
| 2650 |
|
| 2651 |
|
| 2652 |
$masks = array_keys($masks);
|
| 2653 |
rsort($masks);
|
| 2654 |
|
| 2655 |
return array($menu, $masks);
|
| 2656 |
}
|
| 2657 |
|
| 2658 |
|
| 2659 |
|
| 2660 |
|
| 2661 |
function _menu_router_save($menu, $masks) {
|
| 2662 |
|
| 2663 |
db_delete('menu_router')->execute();
|
| 2664 |
|
| 2665 |
|
| 2666 |
$insert = db_insert('menu_router')
|
| 2667 |
->fields(array(
|
| 2668 |
'path',
|
| 2669 |
'load_functions',
|
| 2670 |
'to_arg_functions',
|
| 2671 |
'access_callback',
|
| 2672 |
'access_arguments',
|
| 2673 |
'page_callback',
|
| 2674 |
'page_arguments',
|
| 2675 |
'fit',
|
| 2676 |
'number_parts',
|
| 2677 |
'tab_parent',
|
| 2678 |
'tab_root',
|
| 2679 |
'title',
|
| 2680 |
'title_callback',
|
| 2681 |
'title_arguments',
|
| 2682 |
'type',
|
| 2683 |
'block_callback',
|
| 2684 |
'description',
|
| 2685 |
'position',
|
| 2686 |
'weight',
|
| 2687 |
));
|
| 2688 |
|
| 2689 |
foreach ($menu as $path => $item) {
|
| 2690 |
|
| 2691 |
$insert->values(array(
|
| 2692 |
'path' => $item['path'],
|
| 2693 |
'load_functions' => $item['load_functions'],
|
| 2694 |
'to_arg_functions' => $item['to_arg_functions'],
|
| 2695 |
'access_callback' => $item['access callback'],
|
| 2696 |
'access_arguments' => serialize($item['access arguments']),
|
| 2697 |
'page_callback' => $item['page callback'],
|
| 2698 |
'page_arguments' => serialize($item['page arguments']),
|
| 2699 |
'fit' => $item['_fit'],
|
| 2700 |
'number_parts' => $item['_number_parts'],
|
| 2701 |
'tab_parent' => $item['tab_parent'],
|
| 2702 |
'tab_root' => $item['tab_root'],
|
| 2703 |
'title' => $item['title'],
|
| 2704 |
'title_callback' => $item['title callback'],
|
| 2705 |
'title_arguments' => ($item['title arguments'] ? serialize($item['title arguments']) : ''),
|
| 2706 |
'type' => $item['type'],
|
| 2707 |
'block_callback' => $item['block callback'],
|
| 2708 |
'description' => $item['description'],
|
| 2709 |
'position' => $item['position'],
|
| 2710 |
'weight' => $item['weight'],
|
| 2711 |
));
|
| 2712 |
}
|
| 2713 |
|
| 2714 |
$insert->execute();
|
| 2715 |
|
| 2716 |
variable_set('menu_masks', $masks);
|
| 2717 |
|
| 2718 |
return $menu;
|
| 2719 |
}
|
| 2720 |
|
| 2721 |
|
| 2722 |
|
| 2723 |
|
| 2724 |
function menu_path_is_external($path) {
|
| 2725 |
$colonpos = strpos($path, ':');
|
| 2726 |
return $colonpos !== FALSE && !preg_match('![/?#]!', substr($path, 0, $colonpos)) && filter_xss_bad_protocol($path, FALSE) == check_plain($path);
|
| 2727 |
}
|
| 2728 |
|
| 2729 |
|
| 2730 |
|
| 2731 |
|
| 2732 |
|
| 2733 |
|
| 2734 |
|
| 2735 |
|
| 2736 |
|
| 2737 |
|
| 2738 |
|
| 2739 |
|
| 2740 |
function _menu_site_is_offline() {
|
| 2741 |
|
| 2742 |
if (variable_get('site_offline', 0)) {
|
| 2743 |
|
| 2744 |
if (user_access('administer site configuration')) {
|
| 2745 |
|
| 2746 |
|
| 2747 |
|
| 2748 |
if (drupal_get_normal_path($_GET['q']) != 'admin/config/development/maintenance') {
|
| 2749 |
drupal_set_message(t('Operating in maintenance mode. <a href="@url">Go online.</a>', array('@url' => url('admin/config/development/maintenance'))), 'status', FALSE);
|
| 2750 |
}
|
| 2751 |
}
|
| 2752 |
|
| 2753 |
|
| 2754 |
if (user_is_anonymous()) {
|
| 2755 |
return $_GET['q'] != 'user' && $_GET['q'] != 'user/login';
|
| 2756 |
}
|
| 2757 |
|
| 2758 |
require_once DRUPAL_ROOT . '/' . drupal_get_path('module', 'user') . '/user.pages.inc';
|
| 2759 |
user_logout();
|
| 2760 |
|
| 2761 |
}
|
| 2762 |
return FALSE;
|
| 2763 |
}
|
| 2764 |
|
| 2765 |
|
| 2766 |
|
| 2767 |
|
| 2768 |
|
| 2769 |
|
| 2770 |
|
| 2771 |
|
| 2772 |
function menu_valid_path($form_item) {
|
| 2773 |
global $menu_admin;
|
| 2774 |
$item = array();
|
| 2775 |
$path = $form_item['link_path'];
|
| 2776 |
|
| 2777 |
$menu_admin = TRUE;
|
| 2778 |
if ($path == '<front>' || menu_path_is_external($path)) {
|
| 2779 |
$item = array('access' => TRUE);
|
| 2780 |
}
|
| 2781 |
elseif (preg_match('/\/\%/', $path)) {
|
| 2782 |
|
| 2783 |
if ($item = db_query("SELECT * FROM {menu_router} where path = :path", array(':path' => $path))->fetchAssoc()) {
|
| 2784 |
$item['link_path'] = $form_item['link_path'];
|
| 2785 |
$item['link_title'] = $form_item['link_title'];
|
| 2786 |
$item['external'] = FALSE;
|
| 2787 |
$item['options'] = '';
|
| 2788 |
_menu_link_translate($item);
|
| 2789 |
}
|
| 2790 |
}
|
| 2791 |
|
| 2792 |
$item = menu_get_item($path);
|
| 2793 |
|
| 2794 |
$menu_admin = FALSE;
|
| 2795 |
return $item && $item['access'];
|
| 2796 |
}
|
| 2797 |
|
| 2798 |
|
| 2799 |
|
| 2800 |
|
| 2801 |
|