Exemple #1
0
 /**
  * Retrieve the settings values from db.
  *
  * @param $defaults
  *
  * @return array
  */
 public static function retrieve(&$defaults)
 {
     $domain = new CRM_Core_DAO_Domain();
     //we are initializing config, really can't use, CRM-7863
     $urlVar = 'q';
     if (defined('CIVICRM_UF') && CIVICRM_UF == 'Joomla') {
         $urlVar = 'task';
     }
     if (CRM_Core_Config::isUpgradeMode()) {
         $domain->selectAdd('config_backend');
     } elseif (CRM_Utils_Array::value($urlVar, $_GET) == 'admin/modules/list/confirm') {
         $domain->selectAdd('config_backend', 'locales');
     } else {
         $domain->selectAdd('config_backend, locales, locale_custom_strings');
     }
     $domain->id = CRM_Core_Config::domainID();
     $domain->find(TRUE);
     if ($domain->config_backend) {
         $defaults = unserialize($domain->config_backend);
         if ($defaults === FALSE || !is_array($defaults)) {
             $defaults = array();
             return FALSE;
         }
         $skipVars = self::skipVars();
         foreach ($skipVars as $skip) {
             if (array_key_exists($skip, $defaults)) {
                 unset($defaults[$skip]);
             }
         }
         // check if there are any locale strings
         if ($domain->locale_custom_strings) {
             $defaults['localeCustomStrings'] = unserialize($domain->locale_custom_strings);
         } else {
             $defaults['localeCustomStrings'] = NULL;
         }
         // are we in a multi-language setup?
         $multiLang = $domain->locales ? TRUE : FALSE;
         // set the current language
         $lcMessages = NULL;
         $session = CRM_Core_Session::singleton();
         // on multi-lang sites based on request and civicrm_uf_match
         if ($multiLang) {
             $lcMessagesRequest = CRM_Utils_Request::retrieve('lcMessages', 'String', $this);
             $languageLimit = array();
             if (array_key_exists('languageLimit', $defaults) && is_array($defaults['languageLimit'])) {
                 $languageLimit = $defaults['languageLimit'];
             }
             if (in_array($lcMessagesRequest, array_keys($languageLimit))) {
                 $lcMessages = $lcMessagesRequest;
                 //CRM-8559, cache navigation do not respect locale if it is changed, so reseting cache.
                 CRM_Core_BAO_Cache::deleteGroup('navigation');
             } else {
                 $lcMessagesRequest = NULL;
             }
             if (!$lcMessagesRequest) {
                 $lcMessagesSession = $session->get('lcMessages');
                 if (in_array($lcMessagesSession, array_keys($languageLimit))) {
                     $lcMessages = $lcMessagesSession;
                 } else {
                     $lcMessagesSession = NULL;
                 }
             }
             if ($lcMessagesRequest) {
                 $ufm = new CRM_Core_DAO_UFMatch();
                 $ufm->contact_id = $session->get('userID');
                 if ($ufm->find(TRUE)) {
                     $ufm->language = $lcMessages;
                     $ufm->save();
                 }
                 $session->set('lcMessages', $lcMessages);
             }
             if (!$lcMessages and $session->get('userID')) {
                 $ufm = new CRM_Core_DAO_UFMatch();
                 $ufm->contact_id = $session->get('userID');
                 if ($ufm->find(TRUE) && in_array($ufm->language, array_keys($languageLimit))) {
                     $lcMessages = $ufm->language;
                 }
                 $session->set('lcMessages', $lcMessages);
             }
         }
         global $dbLocale;
         // try to inherit the language from the hosting CMS
         if (!empty($defaults['inheritLocale'])) {
             // FIXME: On multilanguage installs, CRM_Utils_System::getUFLocale() in many cases returns nothing if $dbLocale is not set
             $dbLocale = $multiLang ? "_{$defaults['lcMessages']}" : '';
             $lcMessages = CRM_Utils_System::getUFLocale();
             if ($domain->locales and !in_array($lcMessages, explode(CRM_Core_DAO::VALUE_SEPARATOR, $domain->locales))) {
                 $lcMessages = NULL;
             }
         }
         if (empty($lcMessages)) {
             //CRM-11993 - if a single-lang site, use default
             $lcMessages = CRM_Utils_Array::value('lcMessages', $defaults);
         }
         // set suffix for table names - use views if more than one language
         $dbLocale = $multiLang ? "_{$lcMessages}" : '';
         // FIXME: an ugly hack to fix CRM-4041
         global $tsLocale;
         $tsLocale = $lcMessages;
         // FIXME: as bad aplace as any to fix CRM-5428
         // (to be moved to a sane location along with the above)
         if (function_exists('mb_internal_encoding')) {
             mb_internal_encoding('UTF-8');
         }
     }
     // dont add if its empty
     if (!empty($defaults)) {
         // retrieve directory and url preferences also
         CRM_Core_BAO_Setting::retrieveDirectoryAndURLPreferences($defaults);
         // Pickup enabled-components from settings table if found.
         $enableComponents = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'enable_components', NULL, array());
         if (!empty($enableComponents)) {
             $defaults['enableComponents'] = $enableComponents;
             // Lookup component IDs. Note: Do *not* instantiate components.
             // Classloading may not be fully setup yet.
             $components = CRM_Core_Component::getComponentIDs();
             $enabledComponentIDs = array();
             foreach ($defaults['enableComponents'] as $name) {
                 $enabledComponentIDs[] = $components[$name];
             }
             $defaults['enableComponentIDs'] = $enabledComponentIDs;
         }
     }
 }
 /**
  * @param $item
  *
  * @return bool|mixed
  * @throws Exception
  */
 public static function checkMenuItem(&$item)
 {
     if (!array_key_exists('access_callback', $item)) {
         CRM_Core_Error::backtrace();
         CRM_Core_Error::fatal();
     }
     // if component_id is present, ensure it is enabled
     if (isset($item['component_id']) && $item['component_id']) {
         if (!isset(Civi::$statics[__CLASS__]['componentNameId'])) {
             Civi::$statics[__CLASS__]['componentNameId'] = array_flip(CRM_Core_Component::getComponentIDs());
         }
         $componentName = Civi::$statics[__CLASS__]['componentNameId'][$item['component_id']];
         $config = CRM_Core_Config::singleton();
         if (is_array($config->enableComponents) && in_array($componentName, $config->enableComponents)) {
             // continue with process
         } else {
             return FALSE;
         }
     }
     // the following is imitating drupal 6 code in includes/menu.inc
     if (empty($item['access_callback']) || is_numeric($item['access_callback'])) {
         return (bool) $item['access_callback'];
     }
     // check whether the following Ajax requests submitted the right key
     // FIXME: this should be integrated into ACLs proper
     if (CRM_Utils_Array::value('page_type', $item) == 3) {
         if (!CRM_Core_Key::validate($_REQUEST['key'], $item['path'])) {
             return FALSE;
         }
     }
     // check if callback is for checkMenu, if so optimize it
     if (is_array($item['access_callback']) && $item['access_callback'][0] == 'CRM_Core_Permission' && $item['access_callback'][1] == 'checkMenu') {
         $op = CRM_Utils_Array::value(1, $item['access_arguments'], 'and');
         return self::checkMenu($item['access_arguments'][0], $op);
     } else {
         return call_user_func_array($item['access_callback'], $item['access_arguments']);
     }
 }