/** * initialize the config variables * * @return void * @access private */ private function _initVariables() { // retrieve serialised settings require_once "CRM/Core/BAO/Setting.php"; $variables = array(); CRM_Core_BAO_Setting::retrieve($variables); // if settings are not available, go down the full path if (empty($variables)) { // Step 1. get system variables with their hardcoded defaults $variables = get_object_vars($this); // Step 2. get default values (with settings file overrides if // available - handled in CRM_Core_Config_Defaults) require_once 'CRM/Core/Config/Defaults.php'; CRM_Core_Config_Defaults::setValues($variables); // retrieve directory and url preferences also require_once 'CRM/Core/BAO/Preferences.php'; CRM_Core_BAO_Preferences::retrieveDirectoryAndURLPreferences($defaults); // add component specific settings $this->componentRegistry->addConfig($this); // serialise settings CRM_Core_BAO_Setting::add($variables); } $urlArray = array('userFrameworkResourceURL', 'imageUploadURL'); $dirArray = array('uploadDir', 'customFileUploadDir'); foreach ($variables as $key => $value) { if (in_array($key, $urlArray)) { $value = CRM_Utils_File::addTrailingSlash($value, '/'); } else { if (in_array($key, $dirArray)) { $value = CRM_Utils_File::addTrailingSlash($value); if (CRM_Utils_File::createDir($value, false) === false) { // seems like we could not create the directories // settings might have changed, lets suppress a message for now // so we can make some more progress and let the user fix their settings // for now we assign it to a know value // CRM-4949 $value = $this->templateCompileDir; $url = CRM_Utils_System::url('civicrm/admin/setting/path', 'reset=1'); CRM_Core_Session::setStatus(ts('%1 has an incorrect directory path. Please go to the <a href="%2">path setting page</a> and correct it.', array(1 => $key, 2 => $url)) . '<br/>'); } } else { if ($key == 'lcMessages') { // reset the templateCompileDir to locale-specific and make sure it exists if (substr($this->templateCompileDir, -1 * strlen($value) - 1, -1) != $value) { $this->templateCompileDir .= CRM_Utils_File::addTrailingSlash($value); CRM_Utils_File::createDir($this->templateCompileDir); } } } } $this->{$key} = $value; } if ($this->userFrameworkResourceURL) { // we need to do this here so all blocks also load from an ssl server if (isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) != 'off') { CRM_Utils_System::mapConfigToSSL(); } $rrb = parse_url($this->userFrameworkResourceURL); // dont use absolute path if resources are stored on a different server // CRM-4642 $this->resourceBase = $this->userFrameworkResourceURL; if (isset($_SERVER['HTTP_HOST'])) { $this->resourceBase = $rrb['host'] == $_SERVER['HTTP_HOST'] ? $rrb['path'] : $this->userFrameworkResourceURL; } } if (!$this->customFileUploadDir) { $this->customFileUploadDir = $this->uploadDir; } if ($this->mapProvider) { $this->geocodeMethod = 'CRM_Utils_Geocode_' . $this->mapProvider; } }
/** * Function to retrieve the settings values from db * * @return array $defaults * @static */ static function retrieve(&$defaults) { require_once "CRM/Core/DAO/Domain.php"; $domain = new CRM_Core_DAO_Domain(); $domain->selectAdd(); if (CRM_Utils_Array::value('q', $_GET) == 'civicrm/upgrade') { $domain->selectAdd('config_backend'); } 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; } $skipVars = array('dsn', 'templateCompileDir', 'userFrameworkDSN', 'userFrameworkBaseURL', 'userFrameworkClass', 'userHookClass', 'userPermissionClass', 'userFrameworkURLVar', 'newBaseURL', 'newBaseDir', 'newSiteName', 'configAndLogDir', 'qfKey', 'gettextResourceDir', 'cleanURL', 'locale_custom_strings', 'localeCustomStrings'); foreach ($skipVars as $skip) { if (array_key_exists($skip, $defaults)) { unset($defaults[$skip]); } } // since language field won't be present before upgrade. if (CRM_Utils_Array::value('q', $_GET) == 'civicrm/upgrade') { return; } // 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(); // for logging purposes, pass the userID to the db if ($session->get('userID')) { CRM_Core_DAO::executeQuery('SET @civicrm_user_id = %1', array(1 => array($session->get('userID'), 'Integer'))); } // on multi-lang sites based on request and civicrm_uf_match if ($multiLang) { require_once 'CRM/Utils/Request.php'; $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; } else { $lcMessagesRequest = null; } if (!$lcMessagesRequest) { $lcMessagesSession = $session->get('lcMessages'); if (in_array($lcMessagesSession, array_keys($languageLimit))) { $lcMessages = $lcMessagesSession; } else { $lcMessagesSession = null; } } if ($lcMessagesRequest) { require_once 'CRM/Core/DAO/UFMatch.php'; $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')) { require_once 'CRM/Core/DAO/UFMatch.php'; $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; // if unset and the install is so configured, try to inherit the language from the hosting CMS if ($lcMessages === null and CRM_Utils_Array::value('inheritLocale', $defaults)) { // FIXME: On multilanguage installs, CRM_Utils_System::getUFLocale() in many cases returns nothing if $dbLocale is not set $dbLocale = $multiLang ? "_{$defaults['lcMessages']}" : ''; require_once 'CRM/Utils/System.php'; $lcMessages = CRM_Utils_System::getUFLocale(); require_once 'CRM/Core/BAO/CustomOption.php'; if ($domain->locales and !in_array($lcMessages, explode(CRM_Core_BAO_CustomOption::VALUE_SEPERATOR, $domain->locales))) { $lcMessages = null; } } if ($lcMessages) { // update config lcMessages - CRM-5027 fixed. $defaults['lcMessages'] = $lcMessages; } else { // if a single-lang site or the above didn't yield a result, use default $lcMessages = $defaults['lcMessages']; } // 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 require_once 'CRM/Core/BAO/Preferences.php'; CRM_Core_BAO_Preferences::retrieveDirectoryAndURLPreferences($defaults); } }