| 1 | <?php |
| 2 | /* |
| 3 | +--------------------------------------------------------------------+ |
| 4 | | Copyright CiviCRM LLC. All rights reserved. | |
| 5 | | | |
| 6 | | This work is published under the GNU AGPLv3 license with some | |
| 7 | | permitted exceptions and without any warranty. For full license | |
| 8 | | and copyright information, see https://civicrm.org/licensing | |
| 9 | +--------------------------------------------------------------------+ |
| 10 | */ |
| 11 | |
| 12 | /** |
| 13 | * This file contains the various menus of the CiviCRM module |
| 14 | * |
| 15 | * @package CRM |
| 16 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
| 17 | */ |
| 18 | |
| 19 | require_once 'CRM/Core/I18n.php'; |
| 20 | |
| 21 | /** |
| 22 | * Class CRM_Core_Menu. |
| 23 | */ |
| 24 | class CRM_Core_Menu { |
| 25 | |
| 26 | /** |
| 27 | * The list of menu items. |
| 28 | * |
| 29 | * @var array |
| 30 | */ |
| 31 | public static $_items = NULL; |
| 32 | |
| 33 | /** |
| 34 | * The list of permissioned menu items. |
| 35 | * |
| 36 | * @var array |
| 37 | */ |
| 38 | public static $_permissionedItems = NULL; |
| 39 | |
| 40 | public static $_serializedElements = array( |
| 41 | 'access_arguments', |
| 42 | 'access_callback', |
| 43 | 'page_arguments', |
| 44 | 'page_callback', |
| 45 | 'breadcrumb', |
| 46 | ); |
| 47 | |
| 48 | public static $_menuCache = NULL; |
| 49 | const MENU_ITEM = 1; |
| 50 | |
| 51 | /** |
| 52 | * This function fetches the menu items from xml and xmlMenu hooks. |
| 53 | * |
| 54 | * @param bool $fetchFromXML |
| 55 | * Fetch the menu items from xml and not from cache. |
| 56 | * |
| 57 | * @return array |
| 58 | */ |
| 59 | public static function &xmlItems($fetchFromXML = FALSE) { |
| 60 | if (!self::$_items || $fetchFromXML) { |
| 61 | $config = CRM_Core_Config::singleton(); |
| 62 | |
| 63 | // We needs this until Core becomes a component |
| 64 | $coreMenuFilesNamespace = 'CRM_Core_xml_Menu'; |
| 65 | $coreMenuFilesPath = str_replace('_', DIRECTORY_SEPARATOR, $coreMenuFilesNamespace); |
| 66 | global $civicrm_root; |
| 67 | $files = CRM_Utils_File::getFilesByExtension($civicrm_root . DIRECTORY_SEPARATOR . $coreMenuFilesPath, 'xml'); |
| 68 | |
| 69 | // Grab component menu files |
| 70 | $files = array_merge($files, |
| 71 | CRM_Core_Component::xmlMenu() |
| 72 | ); |
| 73 | |
| 74 | // lets call a hook and get any additional files if needed |
| 75 | CRM_Utils_Hook::xmlMenu($files); |
| 76 | |
| 77 | self::$_items = array(); |
| 78 | foreach ($files as $file) { |
| 79 | self::read($file, self::$_items); |
| 80 | } |
| 81 | |
| 82 | CRM_Utils_Hook::alterMenu(self::$_items); |
| 83 | } |
| 84 | |
| 85 | return self::$_items; |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * Read menu. |
| 90 | * |
| 91 | * @param string $name |
| 92 | * File name |
| 93 | * @param array $menu |
| 94 | * An alterable list of menu items. |
| 95 | * |
| 96 | * @throws Exception |
| 97 | */ |
| 98 | public static function read($name, &$menu) { |
| 99 | $xml = simplexml_load_string(file_get_contents($name)); |
| 100 | self::readXML($xml, $menu); |
| 101 | } |
| 102 | |
| 103 | /** |
| 104 | * @param SimpleXMLElement $xml |
| 105 | * An XML document defining a list of menu items. |
| 106 | * @param array $menu |
| 107 | * An alterable list of menu items. |
| 108 | */ |
| 109 | public static function readXML($xml, &$menu) { |
| 110 | $config = CRM_Core_Config::singleton(); |
| 111 | foreach ($xml->item as $item) { |
| 112 | if (!(string ) $item->path) { |
| 113 | CRM_Core_Error::debug('i', $item); |
| 114 | CRM_Core_Error::fatal(); |
| 115 | } |
| 116 | $path = (string ) $item->path; |
| 117 | $menu[$path] = array(); |
| 118 | unset($item->path); |
| 119 | |
| 120 | if ($item->ids_arguments) { |
| 121 | $ids = array(); |
| 122 | foreach (array('json' => 'json', 'html' => 'html', 'exception' => 'exceptions') as $tag => $attr) { |
| 123 | $ids[$attr] = array(); |
| 124 | foreach ($item->ids_arguments->{$tag} as $value) { |
| 125 | $ids[$attr][] = (string) $value; |
| 126 | } |
| 127 | } |
| 128 | $menu[$path]['ids_arguments'] = $ids; |
| 129 | unset($item->ids_arguments); |
| 130 | } |
| 131 | |
| 132 | foreach ($item as $key => $value) { |
| 133 | $key = (string ) $key; |
| 134 | $value = (string ) $value; |
| 135 | if (strpos($key, '_callback') && |
| 136 | strpos($value, '::') |
| 137 | ) { |
| 138 | // FIXME Remove the rewrite at this level. Instead, change downstream call_user_func*($value) |
| 139 | // to call_user_func*(Civi\Core\Resolver::singleton()->get($value)). |
| 140 | $value = explode('::', $value); |
| 141 | } |
| 142 | elseif ($key == 'access_arguments') { |
| 143 | // FIXME Move the permission parser to its own class (or *maybe* CRM_Core_Permission). |
| 144 | if (strpos($value, ',') || |
| 145 | strpos($value, ';') |
| 146 | ) { |
| 147 | if (strpos($value, ',')) { |
| 148 | $elements = explode(',', $value); |
| 149 | $op = 'and'; |
| 150 | } |
| 151 | else { |
| 152 | $elements = explode(';', $value); |
| 153 | $op = 'or'; |
| 154 | } |
| 155 | $items = array(); |
| 156 | foreach ($elements as $element) { |
| 157 | $items[] = $element; |
| 158 | } |
| 159 | $value = array($items, $op); |
| 160 | } |
| 161 | else { |
| 162 | $value = array(array($value), 'and'); |
| 163 | } |
| 164 | } |
| 165 | elseif ($key == 'is_public' || $key == 'is_ssl') { |
| 166 | $value = ($value == 'true' || $value == 1) ? 1 : 0; |
| 167 | } |
| 168 | $menu[$path][$key] = $value; |
| 169 | } |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | /** |
| 174 | * This function defines information for various menu items. |
| 175 | * |
| 176 | * @param bool $fetchFromXML |
| 177 | * Fetch the menu items from xml and not from cache. |
| 178 | * |
| 179 | * @return array |
| 180 | */ |
| 181 | public static function &items($fetchFromXML = FALSE) { |
| 182 | return self::xmlItems($fetchFromXML); |
| 183 | } |
| 184 | |
| 185 | /** |
| 186 | * Is array true (whatever that means!). |
| 187 | * |
| 188 | * @param array $values |
| 189 | * |
| 190 | * @return bool |
| 191 | */ |
| 192 | public static function isArrayTrue(&$values) { |
| 193 | foreach ($values as $name => $value) { |
| 194 | if (!$value) { |
| 195 | return FALSE; |
| 196 | } |
| 197 | } |
| 198 | return TRUE; |
| 199 | } |
| 200 | |
| 201 | /** |
| 202 | * Fill menu values. |
| 203 | * |
| 204 | * @param array $menu |
| 205 | * @param string $path |
| 206 | * |
| 207 | * @throws Exception |
| 208 | */ |
| 209 | public static function fillMenuValues(&$menu, $path) { |
| 210 | $fieldsToPropagate = array( |
| 211 | 'access_callback', |
| 212 | 'access_arguments', |
| 213 | 'page_callback', |
| 214 | 'page_arguments', |
| 215 | 'is_ssl', |
| 216 | ); |
| 217 | $fieldsPresent = array(); |
| 218 | foreach ($fieldsToPropagate as $field) { |
| 219 | $fieldsPresent[$field] = CRM_Utils_Array::value($field, $menu[$path]) !== NULL ? TRUE : FALSE; |
| 220 | } |
| 221 | |
| 222 | $args = explode('/', $path); |
| 223 | while (!self::isArrayTrue($fieldsPresent) && !empty($args)) { |
| 224 | |
| 225 | array_pop($args); |
| 226 | $parentPath = implode('/', $args); |
| 227 | |
| 228 | foreach ($fieldsToPropagate as $field) { |
| 229 | if (!$fieldsPresent[$field]) { |
| 230 | if (CRM_Utils_Array::value($field, CRM_Utils_Array::value($parentPath, $menu)) !== NULL) { |
| 231 | $fieldsPresent[$field] = TRUE; |
| 232 | $menu[$path][$field] = $menu[$parentPath][$field]; |
| 233 | } |
| 234 | } |
| 235 | } |
| 236 | } |
| 237 | |
| 238 | if (self::isArrayTrue($fieldsPresent)) { |
| 239 | return; |
| 240 | } |
| 241 | |
| 242 | $messages = array(); |
| 243 | foreach ($fieldsToPropagate as $field) { |
| 244 | if (!$fieldsPresent[$field]) { |
| 245 | $messages[] = ts("Could not find %1 in path tree", |
| 246 | array(1 => $field) |
| 247 | ); |
| 248 | } |
| 249 | } |
| 250 | CRM_Core_Error::fatal("'$path': " . implode(', ', $messages)); |
| 251 | } |
| 252 | |
| 253 | /** |
| 254 | * We use this function to. |
| 255 | * |
| 256 | * 1. Compute the breadcrumb |
| 257 | * 2. Compute local tasks value if any |
| 258 | * 3. Propagate access argument, access callback, page callback to the menu item |
| 259 | * 4. Build the global navigation block |
| 260 | * |
| 261 | * @param array $menu |
| 262 | */ |
| 263 | public static function build(&$menu) { |
| 264 | foreach ($menu as $path => $menuItems) { |
| 265 | self::buildBreadcrumb($menu, $path); |
| 266 | self::fillMenuValues($menu, $path); |
| 267 | self::fillComponentIds($menu, $path); |
| 268 | self::buildReturnUrl($menu, $path); |
| 269 | |
| 270 | // add add page_type if not present |
| 271 | if (!isset($menu[$path]['page_type'])) { |
| 272 | $menu[$path]['page_type'] = 0; |
| 273 | } |
| 274 | } |
| 275 | |
| 276 | self::buildAdminLinks($menu); |
| 277 | } |
| 278 | |
| 279 | /** |
| 280 | * This function recomputes menu from xml and populates civicrm_menu. |
| 281 | * |
| 282 | * @param bool $truncate |
| 283 | */ |
| 284 | public static function store($truncate = TRUE) { |
| 285 | // first clean up the db |
| 286 | if ($truncate) { |
| 287 | $query = 'TRUNCATE civicrm_menu'; |
| 288 | CRM_Core_DAO::executeQuery($query); |
| 289 | } |
| 290 | $menuArray = self::items($truncate); |
| 291 | |
| 292 | self::build($menuArray); |
| 293 | |
| 294 | $daoFields = CRM_Core_DAO_Menu::fields(); |
| 295 | |
| 296 | foreach ($menuArray as $path => $item) { |
| 297 | $menu = new CRM_Core_DAO_Menu(); |
| 298 | $menu->path = $path; |
| 299 | $menu->domain_id = CRM_Core_Config::domainID(); |
| 300 | |
| 301 | $menu->find(TRUE); |
| 302 | |
| 303 | if (!CRM_Core_Config::isUpgradeMode() || |
| 304 | CRM_Core_BAO_SchemaHandler::checkIfFieldExists('civicrm_menu', 'module_data', FALSE) |
| 305 | ) { |
| 306 | // Move unrecognized fields to $module_data. |
| 307 | $module_data = array(); |
| 308 | foreach (array_keys($item) as $key) { |
| 309 | if (!isset($daoFields[$key])) { |
| 310 | $module_data[$key] = $item[$key]; |
| 311 | unset($item[$key]); |
| 312 | } |
| 313 | } |
| 314 | |
| 315 | $menu->module_data = serialize($module_data); |
| 316 | } |
| 317 | |
| 318 | $menu->copyValues($item); |
| 319 | |
| 320 | foreach (self::$_serializedElements as $element) { |
| 321 | if (!isset($item[$element]) || |
| 322 | $item[$element] == 'null' |
| 323 | ) { |
| 324 | $menu->$element = NULL; |
| 325 | } |
| 326 | else { |
| 327 | $menu->$element = serialize($item[$element]); |
| 328 | } |
| 329 | } |
| 330 | |
| 331 | $menu->save(); |
| 332 | } |
| 333 | } |
| 334 | |
| 335 | /** |
| 336 | * Build admin links. |
| 337 | * |
| 338 | * @param array $menu |
| 339 | */ |
| 340 | public static function buildAdminLinks(&$menu) { |
| 341 | $values = array(); |
| 342 | |
| 343 | foreach ($menu as $path => $item) { |
| 344 | if (empty($item['adminGroup'])) { |
| 345 | continue; |
| 346 | } |
| 347 | |
| 348 | $query = !empty($item['path_arguments']) ? str_replace(',', '&', $item['path_arguments']) . '&reset=1' : 'reset=1'; |
| 349 | |
| 350 | $value = array( |
| 351 | 'title' => $item['title'], |
| 352 | 'desc' => CRM_Utils_Array::value('desc', $item), |
| 353 | 'id' => strtr($item['title'], array( |
| 354 | '(' => '_', |
| 355 | ')' => '', |
| 356 | ' ' => '', |
| 357 | ',' => '_', |
| 358 | '/' => '_', |
| 359 | )), |
| 360 | 'url' => CRM_Utils_System::url($path, $query, |
| 361 | FALSE, |
| 362 | NULL, |
| 363 | TRUE, |
| 364 | FALSE, |
| 365 | // forceBackend; CRM-14439 work-around; acceptable for now because we don't display breadcrumbs on frontend |
| 366 | TRUE |
| 367 | ), |
| 368 | 'icon' => CRM_Utils_Array::value('icon', $item), |
| 369 | 'extra' => CRM_Utils_Array::value('extra', $item), |
| 370 | ); |
| 371 | if (!array_key_exists($item['adminGroup'], $values)) { |
| 372 | $values[$item['adminGroup']] = array(); |
| 373 | $values[$item['adminGroup']]['fields'] = array(); |
| 374 | } |
| 375 | $weight = CRM_Utils_Array::value('weight', $item, 0); |
| 376 | $values[$item['adminGroup']]['fields']["{weight}.{$item['title']}"] = $value; |
| 377 | $values[$item['adminGroup']]['component_id'] = $item['component_id']; |
| 378 | } |
| 379 | |
| 380 | foreach ($values as $group => $dontCare) { |
| 381 | $values[$group]['perColumn'] = round(count($values[$group]['fields']) / 2); |
| 382 | ksort($values[$group]); |
| 383 | } |
| 384 | |
| 385 | $menu['admin'] = array('breadcrumb' => $values); |
| 386 | } |
| 387 | |
| 388 | /** |
| 389 | * Get admin links. |
| 390 | * |
| 391 | * @return null |
| 392 | */ |
| 393 | public static function &getAdminLinks() { |
| 394 | $links = self::get('admin'); |
| 395 | |
| 396 | if (!$links || |
| 397 | !isset($links['breadcrumb']) |
| 398 | ) { |
| 399 | return NULL; |
| 400 | } |
| 401 | |
| 402 | $values = &$links['breadcrumb']; |
| 403 | return $values; |
| 404 | } |
| 405 | |
| 406 | /** |
| 407 | * Get the breadcrumb for a given path. |
| 408 | * |
| 409 | * @param array $menu |
| 410 | * An array of all the menu items. |
| 411 | * @param string $path |
| 412 | * Path for which breadcrumb is to be build. |
| 413 | * |
| 414 | * @return array |
| 415 | * The breadcrumb for this path |
| 416 | */ |
| 417 | public static function buildBreadcrumb(&$menu, $path) { |
| 418 | $crumbs = array(); |
| 419 | |
| 420 | $pathElements = explode('/', $path); |
| 421 | array_pop($pathElements); |
| 422 | |
| 423 | $currentPath = NULL; |
| 424 | while ($newPath = array_shift($pathElements)) { |
| 425 | $currentPath = $currentPath ? ($currentPath . '/' . $newPath) : $newPath; |
| 426 | |
| 427 | // when we come across breadcrumb which involves ids, |
| 428 | // we should skip now and later on append dynamically. |
| 429 | if (isset($menu[$currentPath]['skipBreadcrumb'])) { |
| 430 | continue; |
| 431 | } |
| 432 | |
| 433 | // add to crumb, if current-path exists in params. |
| 434 | if (array_key_exists($currentPath, $menu) && |
| 435 | isset($menu[$currentPath]['title']) |
| 436 | ) { |
| 437 | $urlVar = !empty($menu[$currentPath]['path_arguments']) ? '&' . $menu[$currentPath]['path_arguments'] : ''; |
| 438 | $crumbs[] = array( |
| 439 | 'title' => $menu[$currentPath]['title'], |
| 440 | 'url' => CRM_Utils_System::url($currentPath, |
| 441 | 'reset=1' . $urlVar, |
| 442 | // absolute |
| 443 | FALSE, |
| 444 | // fragment |
| 445 | NULL, |
| 446 | // htmlize |
| 447 | TRUE, |
| 448 | // frontend |
| 449 | FALSE, |
| 450 | // forceBackend; CRM-14439 work-around; acceptable for now because we don't display breadcrumbs on frontend |
| 451 | TRUE |
| 452 | ), |
| 453 | ); |
| 454 | } |
| 455 | } |
| 456 | $menu[$path]['breadcrumb'] = $crumbs; |
| 457 | |
| 458 | return $crumbs; |
| 459 | } |
| 460 | |
| 461 | /** |
| 462 | * @param $menu |
| 463 | * @param $path |
| 464 | */ |
| 465 | public static function buildReturnUrl(&$menu, $path) { |
| 466 | if (!isset($menu[$path]['return_url'])) { |
| 467 | list($menu[$path]['return_url'], $menu[$path]['return_url_args']) = self::getReturnUrl($menu, $path); |
| 468 | } |
| 469 | } |
| 470 | |
| 471 | /** |
| 472 | * @param $menu |
| 473 | * @param $path |
| 474 | * |
| 475 | * @return array |
| 476 | */ |
| 477 | public static function getReturnUrl(&$menu, $path) { |
| 478 | if (!isset($menu[$path]['return_url'])) { |
| 479 | $pathElements = explode('/', $path); |
| 480 | array_pop($pathElements); |
| 481 | |
| 482 | if (empty($pathElements)) { |
| 483 | return array(NULL, NULL); |
| 484 | } |
| 485 | $newPath = implode('/', $pathElements); |
| 486 | |
| 487 | return self::getReturnUrl($menu, $newPath); |
| 488 | } |
| 489 | else { |
| 490 | return array( |
| 491 | CRM_Utils_Array::value('return_url', |
| 492 | $menu[$path] |
| 493 | ), |
| 494 | CRM_Utils_Array::value('return_url_args', |
| 495 | $menu[$path] |
| 496 | ), |
| 497 | ); |
| 498 | } |
| 499 | } |
| 500 | |
| 501 | /** |
| 502 | * @param $menu |
| 503 | * @param $path |
| 504 | */ |
| 505 | public static function fillComponentIds(&$menu, $path) { |
| 506 | static $cache = array(); |
| 507 | |
| 508 | if (array_key_exists('component_id', $menu[$path])) { |
| 509 | return; |
| 510 | } |
| 511 | |
| 512 | $args = explode('/', $path); |
| 513 | |
| 514 | if (count($args) > 1) { |
| 515 | $compPath = $args[0] . '/' . $args[1]; |
| 516 | } |
| 517 | else { |
| 518 | $compPath = $args[0]; |
| 519 | } |
| 520 | |
| 521 | $componentId = NULL; |
| 522 | |
| 523 | if (array_key_exists($compPath, $cache)) { |
| 524 | $menu[$path]['component_id'] = $cache[$compPath]; |
| 525 | } |
| 526 | else { |
| 527 | if (CRM_Utils_Array::value('component', CRM_Utils_Array::value($compPath, $menu))) { |
| 528 | $componentId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Component', |
| 529 | $menu[$compPath]['component'], |
| 530 | 'id', 'name' |
| 531 | ); |
| 532 | } |
| 533 | $menu[$path]['component_id'] = $componentId ? $componentId : NULL; |
| 534 | $cache[$compPath] = $menu[$path]['component_id']; |
| 535 | } |
| 536 | } |
| 537 | |
| 538 | /** |
| 539 | * @param $path string |
| 540 | * Path of menu item to retrieve. |
| 541 | * |
| 542 | * @return array |
| 543 | * Menu entry array. |
| 544 | */ |
| 545 | public static function get($path) { |
| 546 | // return null if menu rebuild |
| 547 | $config = CRM_Core_Config::singleton(); |
| 548 | |
| 549 | $args = explode('/', $path); |
| 550 | |
| 551 | $elements = array(); |
| 552 | while (!empty($args)) { |
| 553 | $string = implode('/', $args); |
| 554 | $string = CRM_Core_DAO::escapeString($string); |
| 555 | $elements[] = "'{$string}'"; |
| 556 | array_pop($args); |
| 557 | } |
| 558 | |
| 559 | $queryString = implode(', ', $elements); |
| 560 | $domainID = CRM_Core_Config::domainID(); |
| 561 | |
| 562 | $query = " |
| 563 | ( |
| 564 | SELECT * |
| 565 | FROM civicrm_menu |
| 566 | WHERE path in ( $queryString ) |
| 567 | AND domain_id = $domainID |
| 568 | ORDER BY length(path) DESC |
| 569 | LIMIT 1 |
| 570 | ) |
| 571 | "; |
| 572 | |
| 573 | if ($path != 'navigation') { |
| 574 | $query .= " |
| 575 | UNION ( |
| 576 | SELECT * |
| 577 | FROM civicrm_menu |
| 578 | WHERE path IN ( 'navigation' ) |
| 579 | AND domain_id = $domainID |
| 580 | ) |
| 581 | "; |
| 582 | } |
| 583 | |
| 584 | $menu = new CRM_Core_DAO_Menu(); |
| 585 | $menu->query($query); |
| 586 | |
| 587 | self::$_menuCache = array(); |
| 588 | $menuPath = NULL; |
| 589 | while ($menu->fetch()) { |
| 590 | self::$_menuCache[$menu->path] = array(); |
| 591 | CRM_Core_DAO::storeValues($menu, self::$_menuCache[$menu->path]); |
| 592 | |
| 593 | // Move module_data into main item. |
| 594 | if (isset(self::$_menuCache[$menu->path]['module_data'])) { |
| 595 | CRM_Utils_Array::extend(self::$_menuCache[$menu->path], |
| 596 | CRM_Utils_String::unserialize(self::$_menuCache[$menu->path]['module_data'])); |
| 597 | unset(self::$_menuCache[$menu->path]['module_data']); |
| 598 | } |
| 599 | |
| 600 | // Unserialize other elements. |
| 601 | foreach (self::$_serializedElements as $element) { |
| 602 | self::$_menuCache[$menu->path][$element] = CRM_Utils_String::unserialize($menu->$element); |
| 603 | |
| 604 | if (strpos($path, $menu->path) !== FALSE) { |
| 605 | $menuPath = &self::$_menuCache[$menu->path]; |
| 606 | } |
| 607 | } |
| 608 | } |
| 609 | |
| 610 | if (strstr($path, 'report/instance')) { |
| 611 | $args = explode('/', $path); |
| 612 | if (is_numeric(end($args))) { |
| 613 | $menuPath['path'] .= '/' . end($args); |
| 614 | } |
| 615 | } |
| 616 | |
| 617 | // *FIXME* : hack for 4.1 -> 4.2 upgrades. |
| 618 | if (preg_match('/^civicrm\/(upgrade\/)?queue\//', $path)) { |
| 619 | CRM_Queue_Menu::alter($path, $menuPath); |
| 620 | } |
| 621 | |
| 622 | // Part of upgrade framework but not run inside main upgrade because it deletes data |
| 623 | // Once we have another example of a 'cleanup' we should generalize the clause below so it grabs string |
| 624 | // which follows upgrade/ and checks for existence of a function in Cleanup class. |
| 625 | if ($path == 'civicrm/upgrade/cleanup425') { |
| 626 | $menuPath['page_callback'] = array('CRM_Upgrade_Page_Cleanup', 'cleanup425'); |
| 627 | $menuPath['access_arguments'][0][] = 'administer CiviCRM'; |
| 628 | $menuPath['access_callback'] = array('CRM_Core_Permission', 'checkMenu'); |
| 629 | } |
| 630 | |
| 631 | if (!empty($menuPath)) { |
| 632 | $i18n = CRM_Core_I18n::singleton(); |
| 633 | $i18n->localizeTitles($menuPath); |
| 634 | } |
| 635 | return $menuPath; |
| 636 | } |
| 637 | |
| 638 | /** |
| 639 | * @param $pathArgs |
| 640 | * |
| 641 | * @return mixed |
| 642 | */ |
| 643 | public static function getArrayForPathArgs($pathArgs) { |
| 644 | if (!is_string($pathArgs)) { |
| 645 | return; |
| 646 | } |
| 647 | $args = array(); |
| 648 | |
| 649 | $elements = explode(',', $pathArgs); |
| 650 | foreach ($elements as $keyVal) { |
| 651 | list($key, $val) = explode('=', $keyVal, 2); |
| 652 | $arr[$key] = $val; |
| 653 | } |
| 654 | |
| 655 | if (array_key_exists('urlToSession', $arr)) { |
| 656 | $urlToSession = array(); |
| 657 | |
| 658 | $params = explode(';', $arr['urlToSession']); |
| 659 | $count = 0; |
| 660 | foreach ($params as $keyVal) { |
| 661 | list($urlToSession[$count]['urlVar'], |
| 662 | $urlToSession[$count]['sessionVar'], |
| 663 | $urlToSession[$count]['type'], |
| 664 | $urlToSession[$count]['default'] |
| 665 | ) = explode(':', $keyVal); |
| 666 | $count++; |
| 667 | } |
| 668 | $arr['urlToSession'] = $urlToSession; |
| 669 | } |
| 670 | return $arr; |
| 671 | } |
| 672 | |
| 673 | } |