X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FCore%2FBAO%2FConfigSetting.php;h=48be9c9b49d5fabff31738734880f996cbe1c51f;hb=af321125666c7444accea956adaad22395fcd4c9;hp=3d728a0d875c6809dd8f05c00322f4a805bcf6b5;hpb=fdfd59ccd77f9b06547204a505b67e35bf6596d7;p=civicrm-core.git diff --git a/CRM/Core/BAO/ConfigSetting.php b/CRM/Core/BAO/ConfigSetting.php index 3d728a0d87..48be9c9b49 100644 --- a/CRM/Core/BAO/ConfigSetting.php +++ b/CRM/Core/BAO/ConfigSetting.php @@ -1,7 +1,7 @@ delete('CRM_Core_Config'); @@ -60,16 +59,15 @@ class CRM_Core_BAO_ConfigSetting { } /** - * Function to add civicrm settings - * - * @params array $params associated array of civicrm variables + * Add civicrm settings * - * @param $params + * @param array $params + * Associated array of civicrm variables. * * @return null * @static */ - static function add(&$params) { + public static function add(&$params) { self::fixParams($params); // also set a template url so js files can use this @@ -79,8 +77,8 @@ class CRM_Core_BAO_ConfigSetting { str_replace( 'CIVI_BASE_TEMPLATE', '', - $params['civiRelativeURL'] - ); + $params['civiRelativeURL'] + ); // also add the version number for use by template / js etc $params['civiVersion'] = CRM_Utils_System::version(); @@ -143,16 +141,15 @@ class CRM_Core_BAO_ConfigSetting { } /** - * Function to fix civicrm setting variables - * - * @params array $params associated array of civicrm variables + * Fix civicrm setting variables * - * @param $params + * @param array $params + * Associated array of civicrm variables. * * @return null * @static */ - static function fixParams(&$params) { + public static function fixParams(&$params) { // in our old civicrm.settings.php we were using ISO code for country and // province limit, now we have changed it to use ids @@ -177,15 +174,17 @@ class CRM_Core_BAO_ConfigSetting { } /** - * Function to format the array containing before inserting in db + * Format the array containing before inserting in db * - * @param array $params associated array of civicrm variables(submitted) - * @param array $values associated array of civicrm variables stored in db + * @param array $params + * Associated array of civicrm variables(submitted). + * @param array $values + * Associated array of civicrm variables stored in db. * * @return null * @static */ - static function formatParams(&$params, &$values) { + public static function formatParams(&$params, &$values) { if (empty($params) || !is_array($params) ) { @@ -202,14 +201,14 @@ class CRM_Core_BAO_ConfigSetting { } /** - * Function to retrieve the settings values from db + * Retrieve the settings values from db * * @param $defaults * * @return array $defaults * @static */ - static function retrieve(&$defaults) { + public static function retrieve(&$defaults) { $domain = new CRM_Core_DAO_Domain(); //we are initializing config, really can't use, CRM-7863 @@ -317,19 +316,16 @@ class CRM_Core_BAO_ConfigSetting { $dbLocale = $multiLang ? "_{$defaults['lcMessages']}" : ''; $lcMessages = CRM_Utils_System::getUFLocale(); if ($domain->locales and !in_array($lcMessages, explode(CRM_Core_DAO::VALUE_SEPARATOR, - $domain->locales - ))) { + $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 = CRM_Utils_Array::value( 'lcMessages', $defaults ); + 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 @@ -369,7 +365,7 @@ class CRM_Core_BAO_ConfigSetting { /** * @return array */ - static function getConfigSettings() { + public static function getConfigSettings() { $config = CRM_Core_Config::singleton(); $url = $dir = $siteName = $siteRoot = NULL; @@ -383,11 +379,23 @@ class CRM_Core_BAO_ConfigSetting { // lets use imageUploadDir since we dont mess around with its values // in the config object, lets kep it a bit generic since folks // might have different values etc - $dir = preg_replace( - '|civicrm/templates_c/.*$|', - '', - $config->templateCompileDir - ); + + //CRM-15365 - Fix preg_replace to handle backslash for Windows File Paths + if (DIRECTORY_SEPARATOR == '\\') { + $dir = preg_replace( + '|civicrm[/\\\\]templates_c[/\\\\].*$|', + '', + $config->templateCompileDir + ); + } + else { + $dir = preg_replace( + '|civicrm/templates_c/.*$|', + '', + $config->templateCompileDir + ); + } + $siteRoot = preg_replace( '|/media/civicrm/.*$|', '', @@ -404,11 +412,23 @@ class CRM_Core_BAO_ConfigSetting { // lets use imageUploadDir since we dont mess around with its values // in the config object, lets kep it a bit generic since folks // might have different values etc - $dir = preg_replace( - '|civicrm/templates_c/.*$|', - '', - $config->templateCompileDir - ); + + //CRM-15365 - Fix preg_replace to handle backslash for Windows File Paths + if (DIRECTORY_SEPARATOR == '\\') { + $dir = preg_replace( + '|civicrm[/\\\\]templates_c[/\\\\].*$|', + '', + $config->templateCompileDir + ); + } + else { + $dir = preg_replace( + '|civicrm/templates_c/.*$|', + '', + $config->templateCompileDir + ); + } + $siteRoot = preg_replace( '|/wp-content/plugins/files/civicrm/.*$|', '', @@ -425,18 +445,29 @@ class CRM_Core_BAO_ConfigSetting { // lets use imageUploadDir since we dont mess around with its values // in the config object, lets kep it a bit generic since folks // might have different values etc - $dir = preg_replace( - '|/files/civicrm/.*$|', - '/files/', - $config->imageUploadDir - ); + + //CRM-15365 - Fix preg_replace to handle backslash for Windows File Paths + if (DIRECTORY_SEPARATOR == '\\') { + $dir = preg_replace( + '|[/\\\\]files[/\\\\]civicrm[/\\\\].*$|', + '\\\\files\\\\', + $config->imageUploadDir + ); + } + else { + $dir = preg_replace( + '|/files/civicrm/.*$|', + '/files/', + $config->imageUploadDir + ); + } $matches = array(); if (preg_match( - '|/sites/([\w\.\-\_]+)/|', - $config->imageUploadDir, - $matches - )) { + '|/sites/([\w\.\-\_]+)/|', + $config->imageUploadDir, + $matches + )) { $siteName = $matches[1]; if ($siteName) { $siteName = "/sites/$siteName/"; @@ -448,22 +479,30 @@ class CRM_Core_BAO_ConfigSetting { } } - return array($url, $dir, $siteName, $siteRoot); } -/** - * Return likely default settings - * @return array site settings - * -$url, - * - $dir Base Directory - * - $siteName - * - $siteRoot - */ - static function getBestGuessSettings() { + /** + * Return likely default settings + * @return array site settings + * -$url, + * - $dir Base Directory + * - $siteName + * - $siteRoot + */ + public static function getBestGuessSettings() { $config = CRM_Core_Config::singleton(); + + //CRM-15365 - Fix preg_replace to handle backslash for Windows File Paths + if (DIRECTORY_SEPARATOR == '\\') { + $needle = 'civicrm[/\\\\]templates_c[/\\\\].*$'; + } + else { + $needle = 'civicrm/templates_c/.*$'; + } + $dir = preg_replace( - '|civicrm/templates_c/.*$|', + "|$needle|", '', $config->templateCompileDir ); @@ -478,7 +517,7 @@ class CRM_Core_BAO_ConfigSetting { * @return string * @throws Exception */ - static function doSiteMove($defaultValues = array() ) { + public static function doSiteMove($defaultValues = array()) { $moveStatus = ts('Beginning site move process...') . '
'; // get the current and guessed values list($oldURL, $oldDir, $oldSiteName, $oldSiteRoot) = self::getConfigSettings(); @@ -568,7 +607,8 @@ WHERE option_group_id = ( FROM civicrm_option_group WHERE name = %3 ) '; - $params = array(1 => array($from, 'String'), + $params = array( + 1 => array($from, 'String'), 2 => array($to, 'String'), 3 => array($option, 'String'), ); @@ -577,7 +617,9 @@ WHERE option_group_id = ( } } - $moveStatus .= ts('Directory and Resource URLs have been updated in the moved database to reflect current site location.') . '
'; + $moveStatus .= + ts('Directory and Resource URLs have been updated in the moved database to reflect current site location.') . + '
'; $config = CRM_Core_Config::singleton(); @@ -612,15 +654,16 @@ WHERE option_group_id = ( } /** - * takes a componentName and enables it in the config + * Takes a componentName and enables it in the config * Primarily used during unit testing * - * @param string $componentName name of the component to be enabled, needs to be valid + * @param string $componentName + * Name of the component to be enabled, needs to be valid. * * @return boolean - true if valid component name and enabling succeeds, else false * @static */ - static function enableComponent($componentName) { + public static function enableComponent($componentName) { $config = CRM_Core_Config::singleton(); if (in_array($componentName, $config->enableComponents)) { // component is already enabled @@ -642,9 +685,11 @@ WHERE option_group_id = ( return TRUE; } - static function disableComponent($componentName) { + public static function disableComponent($componentName) { $config = CRM_Core_Config::singleton(); - if (!in_array($componentName, $config->enableComponents) || !array_key_exists($componentName, CRM_Core_Component::getComponents())) { + if (!in_array($componentName, $config->enableComponents) || + !array_key_exists($componentName, CRM_Core_Component::getComponents()) + ) { // post-condition satisified return TRUE; } @@ -683,20 +728,30 @@ WHERE option_group_id = ( /** * @return array */ - static function skipVars() { + public static function skipVars() { return array( - 'dsn', 'templateCompileDir', + 'dsn', + 'templateCompileDir', 'userFrameworkDSN', 'userFramework', - 'userFrameworkBaseURL', 'userFrameworkClass', 'userHookClass', - 'userPermissionClass', 'userFrameworkURLVar', 'userFrameworkVersion', - 'newBaseURL', 'newBaseDir', 'newSiteName', 'configAndLogDir', - 'qfKey', 'gettextResourceDir', 'cleanURL', - 'locale_custom_strings', 'localeCustomStrings', + 'userFrameworkBaseURL', + 'userFrameworkClass', + 'userHookClass', + 'userPermissionClass', + 'userFrameworkURLVar', + 'userFrameworkVersion', + 'newBaseURL', + 'newBaseDir', + 'newSiteName', + 'configAndLogDir', + 'qfKey', + 'gettextResourceDir', + 'cleanURL', + 'locale_custom_strings', + 'localeCustomStrings', 'autocompleteContactSearch', 'autocompleteContactReference', 'checksumTimeout', ); } } -