Exemplo n.º 1
0
 static function get($path)
 {
     // return null if menu rebuild
     $config =& CRM_Core_Config::singleton();
     $params = array();
     $args = explode('/', $path);
     $elements = array();
     while (!empty($args)) {
         $string = implode('/', $args);
         $string = CRM_Core_DAO::escapeString($string);
         $elements[] = "'{$string}'";
         array_pop($args);
     }
     $queryString = implode(', ', $elements);
     $domainID = CRM_Core_Config::domainID();
     $domainWhereClause = " AND domain_id = {$domainID} ";
     if ($path == 'civicrm/upgrade' && !CRM_Core_DAO::checkFieldExists('civicrm_menu', 'domain_id')) {
         //domain_id wouldn't be available for earlier version of
         //3.0 and therefore can't be used as part of query for
         //upgrade case
         $domainWhereClause = "";
     }
     $query = "\n( \n  SELECT * \n  FROM     civicrm_menu \n  WHERE    path in ( {$queryString} )\n           {$domainWhereClause}\n  ORDER BY length(path) DESC\n  LIMIT    1 \n)\n";
     if ($path != 'navigation') {
         $query .= "\nUNION ( \n  SELECT *\n  FROM   civicrm_menu \n  WHERE  path IN ( 'navigation' )\n         {$domainWhereClause}\n)\n";
     }
     require_once "CRM/Core/DAO/Menu.php";
     $menu =& new CRM_Core_DAO_Menu();
     $menu->query($query);
     self::$_menuCache = array();
     $menuPath = null;
     while ($menu->fetch()) {
         self::$_menuCache[$menu->path] = array();
         CRM_Core_DAO::storeValues($menu, self::$_menuCache[$menu->path]);
         foreach (self::$_serializedElements as $element) {
             self::$_menuCache[$menu->path][$element] = unserialize($menu->{$element});
             if (strpos($path, $menu->path) !== false) {
                 $menuPath =& self::$_menuCache[$menu->path];
             }
         }
     }
     // *FIXME* : hack for 2.1 -> 2.2 upgrades.
     if ($path == 'civicrm/upgrade') {
         $menuPath['page_callback'] = 'CRM_Upgrade_Page_Upgrade';
         $menuPath['access_arguments'][0][] = 'administer CiviCRM';
         $menuPath['access_callback'] = array('CRM_Core_Permission', 'checkMenu');
     }
     $i18n =& CRM_Core_I18n::singleton();
     $i18n->localizeTitles($menuPath);
     return $menuPath;
 }
Exemplo n.º 2
0
 static function get($path)
 {
     // return null if menu rebuild
     $config = CRM_Core_Config::singleton();
     $params = array();
     $args = explode('/', $path);
     $elements = array();
     while (!empty($args)) {
         $string = implode('/', $args);
         $string = CRM_Core_DAO::escapeString($string);
         $elements[] = "'{$string}'";
         array_pop($args);
     }
     $queryString = implode(', ', $elements);
     $domainID = CRM_Core_Config::domainID();
     $domainWhereClause = " AND domain_id = {$domainID} ";
     if ($config->isUpgradeMode() && !CRM_Core_DAO::checkFieldExists('civicrm_menu', 'domain_id')) {
         //domain_id wouldn't be available for earlier version of
         //3.0 and therefore can't be used as part of query for
         //upgrade case
         $domainWhereClause = "";
     }
     $query = "\n(\n  SELECT *\n  FROM     civicrm_menu\n  WHERE    path in ( {$queryString} )\n           {$domainWhereClause}\n  ORDER BY length(path) DESC\n  LIMIT    1\n)\n";
     if ($path != 'navigation') {
         $query .= "\nUNION (\n  SELECT *\n  FROM   civicrm_menu\n  WHERE  path IN ( 'navigation' )\n         {$domainWhereClause}\n)\n";
     }
     $menu = new CRM_Core_DAO_Menu();
     $menu->query($query);
     self::$_menuCache = array();
     $menuPath = NULL;
     while ($menu->fetch()) {
         self::$_menuCache[$menu->path] = array();
         CRM_Core_DAO::storeValues($menu, self::$_menuCache[$menu->path]);
         foreach (self::$_serializedElements as $element) {
             self::$_menuCache[$menu->path][$element] = unserialize($menu->{$element});
             if (strpos($path, $menu->path) !== FALSE) {
                 $menuPath =& self::$_menuCache[$menu->path];
             }
         }
     }
     if (strstr($path, 'report/instance')) {
         $args = explode('/', $path);
         if (is_numeric(end($args))) {
             $menuPath['path'] .= '/' . end($args);
         }
     }
     // *FIXME* : hack for 2.1 -> 2.2 upgrades.
     if ($path == 'civicrm/upgrade') {
         $menuPath['page_callback'] = 'CRM_Upgrade_Page_Upgrade';
         $menuPath['access_arguments'][0][] = 'administer CiviCRM';
         $menuPath['access_callback'] = array('CRM_Core_Permission', 'checkMenu');
     }
     // *FIXME* : hack for 4.1 -> 4.2 upgrades.
     if (preg_match('/^civicrm\\/(upgrade\\/)?queue\\//', $path)) {
         CRM_Queue_Menu::alter($path, $menuPath);
     }
     // Part of upgrade framework but not run inside main upgrade because it deletes data
     // Once we have another example of a 'cleanup' we should generalize the clause below so it grabs string
     // which follows upgrade/ and checks for existence of a function in Cleanup class.
     if ($path == 'civicrm/upgrade/cleanup425') {
         $menuPath['page_callback'] = array('CRM_Upgrade_Page_Cleanup', 'cleanup425');
         $menuPath['access_arguments'][0][] = 'administer CiviCRM';
         $menuPath['access_callback'] = array('CRM_Core_Permission', 'checkMenu');
     }
     if (!empty($menuPath)) {
         $i18n = CRM_Core_I18n::singleton();
         $i18n->localizeTitles($menuPath);
     }
     return $menuPath;
 }