*/
class CRM_Admin_Form_Setting_Path extends CRM_Admin_Form_Setting {
+ protected $_settings = array(
+ 'uploadDir' => CRM_Core_BAO_Setting::DIRECTORY_PREFERENCES_NAME,
+ 'imageUploadDir' => CRM_Core_BAO_Setting::DIRECTORY_PREFERENCES_NAME,
+ 'customFileUploadDir' => CRM_Core_BAO_Setting::DIRECTORY_PREFERENCES_NAME,
+ 'customTemplateDir' => CRM_Core_BAO_Setting::DIRECTORY_PREFERENCES_NAME,
+ 'customPHPPathDir' => CRM_Core_BAO_Setting::DIRECTORY_PREFERENCES_NAME,
+ 'extensionsDir' => CRM_Core_BAO_Setting::DIRECTORY_PREFERENCES_NAME,
+ );
+
/**
* Build the form object.
*/
public function buildQuickForm() {
CRM_Utils_System::setTitle(ts('Settings - Upload Directories'));
+ parent::buildQuickForm();
$directories = array(
'uploadDir' => ts('Temporary Files'),
'extensionsDir' => ts('CiviCRM Extensions Directory'),
);
foreach ($directories as $name => $title) {
- $this->add('text', $name, $title);
+ //$this->add('text', $name, $title);
$this->addRule($name,
ts("'%1' directory does not exist",
array(1 => $title)
),
- 'fileExists'
+ 'settingPath'
);
}
- parent::buildQuickForm();
}
public function postProcess() {
class CRM_Admin_Form_Setting_Url extends CRM_Admin_Form_Setting {
protected $_settings = array(
'disable_core_css' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
+ 'userFrameworkResourceURL' => CRM_Core_BAO_Setting::URL_PREFERENCES_NAME,
+ 'imageUploadURL' => CRM_Core_BAO_Setting::URL_PREFERENCES_NAME,
+ 'customCSSURL' => CRM_Core_BAO_Setting::URL_PREFERENCES_NAME,
+ 'extensionsURL' => CRM_Core_BAO_Setting::URL_PREFERENCES_NAME,
);
/**
'version' => 3,
));
- $this->addElement('text', 'userFrameworkResourceURL', ts('CiviCRM Resource URL'));
- $this->addElement('text', 'imageUploadURL', ts('Image Upload URL'));
- $this->addElement('text', 'customCSSURL', ts('Custom css URL'));
- $this->addElement('text', 'extensionsURL', ts('Extension Resource URL'));
$this->addYesNo('enableSSL', ts('Force Secure URLs (SSL)'));
$this->addYesNo('verifySSL', ts('Verify SSL Certs'));
// FIXME: verifySSL should use $_settings instead of manually adding fields
unset($params[$var]);
}
- CRM_Core_BAO_Setting::fixAndStoreDirAndURL($params);
-
// also skip all Dir Params, we dont need to store those in the DB!
foreach ($params as $name => $val) {
if (substr($name, -3) == 'Dir') {
// 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 = Civi::settings()->get('enable_components');
if (!empty($enableComponents)) {
self::setItem($optionValue, $group, $name);
}
- /**
- * @param array $params
- * @param int $domainID
- */
- public static function fixAndStoreDirAndURL(&$params, $domainID = NULL) {
- if (self::isUpgradeFromPreFourOneAlpha1()) {
- return;
- }
-
- if (empty($domainID)) {
- $domainID = CRM_Core_Config::domainID();
- }
- $sql = "
- SELECT name, group_name
- FROM civicrm_setting
- WHERE domain_id = %1
- AND ( group_name = %2
- OR group_name = %3 )
-";
- $sqlParams = array(
- 1 => array($domainID, 'Integer'),
- 2 => array(self::DIRECTORY_PREFERENCES_NAME, 'String'),
- 3 => array(self::URL_PREFERENCES_NAME, 'String'),
- );
-
- $dirParams = array();
- $urlParams = array();
-
- $dao = CRM_Core_DAO::executeQuery($sql,
- $sqlParams,
- TRUE,
- NULL,
- FALSE,
- TRUE,
- // trap exceptions as error
- TRUE
- );
-
- if (is_a($dao, 'DB_Error')) {
- if (CRM_Core_Config::isUpgradeMode()) {
- // seems like this is a 4.0 -> 4.1 upgrade, so we suppress this error and continue
- return;
- }
- else {
- echo "Fatal DB error, exiting, seems like your schema does not have civicrm_setting table\n";
- exit();
- }
- }
-
- while ($dao->fetch()) {
- if (!isset($params[$dao->name])) {
- continue;
- }
- if ($dao->group_name == self::DIRECTORY_PREFERENCES_NAME) {
- $dirParams[$dao->name] = CRM_Utils_Array::value($dao->name, $params, '');
- }
- else {
- $urlParams[$dao->name] = CRM_Utils_Array::value($dao->name, $params, '');
- }
- unset($params[$dao->name]);
- }
-
- if (!empty($dirParams)) {
- self::storeDirectoryOrURLPreferences($dirParams,
- self::DIRECTORY_PREFERENCES_NAME
- );
- }
-
- if (!empty($urlParams)) {
- self::storeDirectoryOrURLPreferences($urlParams,
- self::URL_PREFERENCES_NAME
- );
- }
- }
-
- /**
- * @param array $params
- * @param $group
- */
- public static function storeDirectoryOrURLPreferences(&$params, $group) {
- foreach ($params as $name => $value) {
- // always try to store relative directory or url from CMS root
- $value = ($group == self::DIRECTORY_PREFERENCES_NAME) ? CRM_Utils_File::relativeDirectory($value) : CRM_Utils_System::relativeURL($value);
-
- self::setItem($value, $group, $name);
- }
- }
-
- /**
- * @param array $params
- * @param bool $setInConfig
- */
- public static function retrieveDirectoryAndURLPreferences(&$params, $setInConfig = FALSE) {
- if (CRM_Core_Config::isUpgradeMode()) {
- $isJoomla = (defined('CIVICRM_UF') && CIVICRM_UF == 'Joomla') ? TRUE : FALSE;
- // hack to set the resource base url so that js/ css etc is loaded correctly
- if ($isJoomla) {
- $params['userFrameworkResourceURL'] = CRM_Utils_File::addTrailingSlash(CIVICRM_UF_BASEURL, '/') . str_replace('administrator', '', CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', 'userFrameworkResourceURL', 'value', 'name'));
- }
- if (self::isUpgradeFromPreFourOneAlpha1()) {
- return;
- }
- }
-
- if ($setInConfig) {
- $config = CRM_Core_Config::singleton();
- }
-
- $sql = "
-SELECT name, group_name, value
-FROM civicrm_setting
-WHERE ( group_name = %1
-OR group_name = %2 )
-AND domain_id = %3
-";
- $sqlParams = array(
- 1 => array(self::DIRECTORY_PREFERENCES_NAME, 'String'),
- 2 => array(self::URL_PREFERENCES_NAME, 'String'),
- 3 => array(CRM_Core_Config::domainID(), 'Integer'),
- );
-
- $dao = CRM_Core_DAO::executeQuery($sql,
- $sqlParams,
- TRUE,
- NULL,
- FALSE,
- TRUE,
- // trap exceptions as error
- TRUE
- );
-
- if (is_a($dao, 'DB_Error')) {
- echo "Fatal DB error, exiting, seems like your schema does not have civicrm_setting table\n";
- exit();
- }
-
- while ($dao->fetch()) {
- $value = self::getOverride($dao->group_name, $dao->name, NULL);
- if ($value === NULL && $dao->value) {
- $value = unserialize($dao->value);
- if ($dao->group_name == self::DIRECTORY_PREFERENCES_NAME) {
- $value = CRM_Utils_File::absoluteDirectory($value);
- }
- else {
- // CRM-7622: we need to remove the language part
- $value = CRM_Utils_System::absoluteURL($value, TRUE);
- }
- }
- // CRM-10931, If DB doesn't have any value, carry on with any default value thats already available
- if (!isset($value) && !empty($params[$dao->name])) {
- $value = $params[$dao->name];
- }
- $params[$dao->name] = $value;
-
- if ($setInConfig) {
- $config->{$dao->name} = $value;
- }
- }
- }
-
/**
* Determine what, if any, overrides have been provided
* for a setting.
'positiveInteger',
'xssString',
'fileExists',
+ 'settingPath',
'autocomplete',
'validContact',
);
return (bool) filter_var($url, FILTER_VALIDATE_URL);
}
+ /**
+ * @param $url
+ *
+ * @return bool
+ */
+ public static function urlish($url) {
+ if (empty($url)) {
+ return TRUE;
+ }
+ if (!preg_match('/^([a-z]+):/', $url)) {
+ // allow relative URL's (CRM-15598)
+ $url = 'http://' . $_SERVER['HTTP_HOST'] . '/' . ltrim($url, '/');
+ }
+ return (bool) filter_var($url, FILTER_VALIDATE_URL);
+ }
+
/**
* @param $string
*
return file_exists($path);
}
+ /**
+ * Determine whether the value contains a valid reference to a directory.
+ *
+ * Paths stored in the setting system may be absolute -- or may be
+ * relative to the default data directory.
+ *
+ * @param string $path
+ * @return bool
+ */
+ public static function settingPath($path) {
+ return is_dir(\CRM_Utils_File::absoluteDirectory($path));
+ }
+
/**
* @param $value
* @param $options
'is_contact' => 0,
'description' => 'Absolute URL of the location where the civicrm module or component has been installed.',
'help_text' => NULL,
- 'validate_callback' => 'CRM_Utils_Rule::url',
+ 'validate_callback' => 'CRM_Utils_Rule::urlish',
),
'imageUploadURL' => array(
'group' => 'url',
'is_contact' => 0,
'description' => 'URL of the location for uploaded image files.',
'help_text' => NULL,
- 'validate_callback' => 'CRM_Utils_Rule::url',
+ 'validate_callback' => 'CRM_Utils_Rule::urlish',
),
'customCSSURL' => array(
'group' => 'url',
'is_contact' => 0,
'description' => 'You can modify the look and feel of CiviCRM by adding your own stylesheet. For small to medium sized modifications, use your css file to override some of the styles in civicrm.css. Or if you need to make drastic changes, you can choose to disable civicrm.css completely.',
'help_text' => NULL,
- 'validate_callback' => 'CRM_Utils_Rule::url',
+ 'validate_callback' => 'CRM_Utils_Rule::urlish',
),
'extensionsURL' => array(
'group' => 'url',
'is_contact' => 0,
'description' => 'Base URL for extension resources (images, stylesheets, etc). This should match extensionsDir.',
'help_text' => NULL,
- 'validate_callback' => 'CRM_Utils_Rule::url',
+ 'validate_callback' => 'CRM_Utils_Rule::urlish',
),
);
$this->assertEquals('/test/override', $values['imageUploadDir']);
}
- /**
- * Ensure that overrides in $civicrm_setting apply when
- * when using retrieveDirectoryAndURLPreferences().
- */
- public function testRetrieveDirectoryAndURLPreferences_Override() {
- global $civicrm_setting;
- $civicrm_setting[CRM_Core_BAO_Setting::DIRECTORY_PREFERENCES_NAME]['imageUploadDir'] = '/test/override';
-
- $params = array();
- CRM_Core_BAO_Setting::retrieveDirectoryAndURLPreferences($params);
- $this->assertEquals('/test/override', $params['imageUploadDir']);
- }
-
/**
* This test checks that CRM_Core_BAO_Setting::updateSettingsFromMetaData();
* 1) Removes 'maxAttachments' from config (because 'prefetch' is not set in the metadata it should
/**
* Ensure that overrides in $civicrm_setting apply when
- * when using retrieveDirectoryAndURLPreferences().
+ * when using getItem().
*/
public function testConvertConfigToSettingNoPrefetch() {
$settings = array('maxAttachments' => 6);
public function testCreateInvalidURLSettings() {
$params = array(
'domain_id' => $this->_domainID2,
- 'userFrameworkResourceURL' => 'dfhkdhfd',
+ 'userFrameworkResourceURL' => 'dfhkd*hfd',
);
$result = $this->callAPIFailure('setting', 'create', $params);
$params = array(