CRM_Core_BAO_ConfigSetting::retrieve($this->_defaults);
- CRM_Core_Config_Defaults::setValues($this->_defaults, $formMode);
-
$list = array_flip(CRM_Core_OptionGroup::values('contact_autocomplete_options',
FALSE, FALSE, TRUE, NULL, 'name'
));
$this->_initVariables();
}
+ if (CRM_Utils_System::isSSL()) {
+ $this->userSystem->mapConfigToSSL();
+ }
+
if (isset($this->customPHPPathDir) && $this->customPHPPathDir) {
set_include_path($this->customPHPPathDir . PATH_SEPARATOR . get_include_path());
}
// 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)
- CRM_Core_Config_Defaults::setValues($variables);
-
- // retrieve directory and url preferences also
- CRM_Core_BAO_Setting::retrieveDirectoryAndURLPreferences($variables);
-
// serialise settings
$settings = $variables;
CRM_Core_BAO_ConfigSetting::add($settings);
}
- $urlArray = array('userFrameworkResourceURL', 'imageUploadURL');
- $dirArray = array('uploadDir', 'customFileUploadDir');
-
foreach ($variables as $key => $value) {
- if (in_array($key, $urlArray)) {
- $value = CRM_Utils_File::addTrailingSlash($value, '/');
- }
- elseif (in_array($key, $dirArray)) {
- if ($value) {
- $value = CRM_Utils_File::addTrailingSlash($value);
- }
- if (empty($value) || (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,
- )), ts('Check Settings'), 'alert');
- }
- }
-
$this->$key = $value;
}
- if ($this->userFrameworkResourceURL) {
- if (CRM_Utils_System::isSSL()) {
- $this->userFrameworkResourceURL = str_replace('http://', 'https://', $this->userFrameworkResourceURL);
- $this->resourceBase = $this->userFrameworkResourceURL;
-
- if (!empty($this->extensionsURL)) {
- $this->extensionsURL = str_replace('http://', 'https://', $this->extensionsURL);
- }
-
- $this->userSystem->mapConfigToSSL();
- }
+ $this->customFileUploadDir = CRM_Core_Config_Defaults::getCustomFileUploadDir();
+ $this->customPHPPathDir = CRM_Core_Config_Defaults::getCustomPhpPathDir();
+ $this->customTemplateDir = CRM_Core_Config_Defaults::getCustomTemplateDir();
+ $this->extensionsDir = CRM_Core_Config_Defaults::getExtensionsDir();
+ $this->imageUploadDir = CRM_Core_Config_Defaults::getImageUploadDir();
+ $this->resourceBase = CRM_Core_Config_Defaults::getResourceBase();
+ $this->uploadDir = CRM_Core_Config_Defaults::getImageUploadDir();
- $rrb = parse_url($this->userFrameworkResourceURL);
- $this->resourceBase = $this->userFrameworkResourceURL;
- if (isset($_SERVER['HTTP_HOST']) && isset($rrb['host'])) {
- $this->resourceBase = ($rrb['host'] == $_SERVER['HTTP_HOST']) ? $rrb['path'] : $this->userFrameworkResourceURL;
- }
- }
-
- if (!$this->customFileUploadDir) {
- $this->customFileUploadDir = $this->uploadDir;
- }
+ $this->userFrameworkResourceURL = CRM_Core_Config_Defaults::getUserFrameworkResourceUrl();
+ $this->customCSSURL = CRM_Core_Config_Defaults::getCustomCssUrl();
+ $this->extensionsURL = CRM_Core_Config_Defaults::getExtensionsUrl();
+ $this->imageUploadURL = CRM_Core_Config_Defaults::getImageUploadUrl();
$this->geocodeMethod = CRM_Utils_Geocode::getProviderClass();
}
$this->userFrameworkBaseURL = CRM_Utils_System::languageNegotiationURL($this->userFrameworkBaseURL);
if (CRM_Utils_System::isSSL()) {
- $this->userFrameworkBaseURL = str_replace('http://', 'https://',
- $this->userFrameworkBaseURL
- );
+ $this->userFrameworkBaseURL = str_replace('http://', 'https://', $this->userFrameworkBaseURL);
}
}
*
*/
public static function setValues(&$defaults, $formMode = FALSE) {
- $config = CRM_Core_Config::singleton();
-
- $baseURL = $config->userFrameworkBaseURL;
-
- // CRM-6216: Drupal’s $baseURL might have a trailing LANGUAGE_NEGOTIATION_PATH,
- // which needs to be stripped before we start basing ResourceURL on it
- if ($config->userSystem->is_drupal) {
- global $language;
- if (isset($language->prefix) and $language->prefix) {
- if (substr($baseURL, -(strlen($language->prefix) + 1)) == $language->prefix . '/') {
- $baseURL = substr($baseURL, 0, -(strlen($language->prefix) + 1));
- }
- }
- }
+ }
- $baseCMSURL = CRM_Utils_System::baseCMSURL();
- $path = CRM_Utils_File::baseFilePath();
- if (!isset($defaults['enableSSL'])) {
- $defaults['enableSSL'] = 0;
- }
- //set defaults if not set in db
- if (!isset($defaults['userFrameworkResourceURL'])) {
- if ($config->userFramework == 'Joomla') {
- $defaults['userFrameworkResourceURL'] = $baseURL . "components/com_civicrm/civicrm/";
- }
- elseif ($config->userFramework == 'WordPress') {
- $defaults['userFrameworkResourceURL'] = $baseURL . "wp-content/plugins/civicrm/civicrm/";
- }
- else {
- // Drupal setting
- // check and see if we are installed in sites/all (for D5 and above)
- // we dont use checkURL since drupal generates an error page and throws
- // the system for a loop on lobo's macosx box
- // or in modules
- global $civicrm_root;
- $cmsPath = $config->userSystem->cmsRootPath();
- $defaults['userFrameworkResourceURL'] = $baseURL . str_replace("$cmsPath/", '',
- str_replace('\\', '/', $civicrm_root)
- );
-
- if (strpos($civicrm_root,
- DIRECTORY_SEPARATOR . 'sites' . DIRECTORY_SEPARATOR . 'all' . DIRECTORY_SEPARATOR . 'modules'
- ) === FALSE
- ) {
- $startPos = strpos($civicrm_root,
- DIRECTORY_SEPARATOR . 'sites' . DIRECTORY_SEPARATOR
- );
- $endPos = strpos($civicrm_root,
- DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR
- );
- if ($startPos && $endPos) {
- // if component is in sites/SITENAME/modules
- $siteName = substr($civicrm_root,
- $startPos + 7,
- $endPos - $startPos - 7
- );
-
- $civicrmDirName = trim(basename($civicrm_root));
- $defaults['userFrameworkResourceURL'] = $baseURL . "sites/$siteName/modules/$civicrmDirName/";
- if (!isset($defaults['imageUploadURL'])) {
- $defaults['imageUploadURL'] = $baseURL . "sites/$siteName/files/civicrm/persist/contribute/";
- }
- }
- }
- }
- }
+ public static function getCustomCssUrl() {
+ return Civi::settings()->getUrl('customCSSURL', 'absolute');
+ }
- if (!isset($defaults['imageUploadURL'])) {
- if ($config->userFramework == 'Joomla') {
- // gross hack
- // we need to remove the administrator/ from the end
- $tempURL = str_replace("/administrator/", "/", $baseURL);
- $defaults['imageUploadURL'] = $tempURL . "media/civicrm/persist/contribute/";
- }
- elseif ($config->userFramework == 'WordPress') {
- //for standalone no need of sites/defaults directory
- $defaults['imageUploadURL'] = $baseURL . "wp-content/plugins/files/civicrm/persist/contribute/";
- }
- else {
- $defaults['imageUploadURL'] = $baseURL . "sites/default/files/civicrm/persist/contribute/";
- }
+ public static function getCustomFileUploadDir() {
+ $value = Civi::settings()->getPath('customFileUploadDir');
+ if (empty($value)) {
+ $defaultFileStorage = CRM_Core_Config::singleton()->userSystem->getDefaultFileStorage();
+ $value = $defaultFileStorage['url'] . "custom/";
}
+ $value = CRM_Utils_File::addTrailingSlash($value);
+ CRM_Utils_File::createDir($value);
+ CRM_Utils_File::restrictAccess($value);
+ return $value;
+ }
- if (!isset($defaults['imageUploadDir']) && is_dir($path)) {
- $imgDir = $path . "persist/contribute/";
- CRM_Utils_File::createDir($imgDir);
- $defaults['imageUploadDir'] = $imgDir;
- }
+ public static function getCustomPhpPathDir() {
+ return Civi::settings()->getPath('customPHPPathDir');
+ }
+
+ public static function getCustomTemplateDir() {
+ return Civi::settings()->getPath('customTemplateDir');
+ }
- if (!isset($defaults['uploadDir']) && is_dir($path)) {
- $uploadDir = $path . "upload/";
+ public static function getExtensionsUrl() {
+ return Civi::settings()->getUrl('extensionsURL', 'absolute');
+ }
+
+ public static function getExtensionsDir() {
+ return Civi::settings()->getPath('extensionsDir');
+ }
+
+ public static function getImageUploadDir() {
+ $value = Civi::settings()->getPath('imageUploadDir');
+ if (empty($value)) {
+ $defaultFileStorage = CRM_Core_Config::singleton()->userSystem->getDefaultFileStorage();
+ $value = $defaultFileStorage['path'] . "persist/contribute/";
+ }
+ $value = CRM_Utils_File::addTrailingSlash($value);
+ CRM_Utils_File::createDir($value);
+ return $value;
+ }
- CRM_Utils_File::createDir($uploadDir);
- CRM_Utils_File::restrictAccess($uploadDir);
- $defaults['uploadDir'] = $uploadDir;
+ public static function getImageUploadUrl() {
+ $imageUploadURL = Civi::settings()->getUrl('imageUploadURL', 'absolute');
+ if (empty($imageUploadURL)) {
+ $defaultFileStorage = CRM_Core_Config::singleton()->userSystem->getDefaultFileStorage();
+ $imageUploadURL = $defaultFileStorage['url'] . 'persist/contribute/';
}
+ return $imageUploadURL;
+ }
- if (!isset($defaults['customFileUploadDir']) && is_dir($path)) {
- $customDir = $path . "custom/";
+ public static function getUploadDir() {
+ $value = Civi::settings()->getPath('uploadDir');
+ if (empty($value)) {
+ $defaultFileStorage = CRM_Core_Config::singleton()->userSystem->getDefaultFileStorage();
+ $value = $defaultFileStorage['path'] . "upload/";
+ }
+ $value = CRM_Utils_File::addTrailingSlash($value);
+ CRM_Utils_File::createDir($value);
+ CRM_Utils_File::restrictAccess($value);
+ return $value;
+ }
- CRM_Utils_File::createDir($customDir);
- CRM_Utils_File::restrictAccess($customDir);
- $defaults['customFileUploadDir'] = $customDir;
+ public static function getUserFrameworkResourceUrl() {
+ $settings = Civi::settings();
+ $url = $settings->getUrl('userFrameworkResourceURL', 'absolute');
+ if (empty($url)) {
+ $config = CRM_Core_Config::singleton();
+ $civiSource = $config->userSystem->getCiviSourceStorage();
+ $url = $settings->filterUrl($civiSource['url'], 'absolute');
}
+ return $url;
+ }
- // FIXME: hack to bypass the step for generating defaults for components,
- // while running upgrade, to avoid any serious non-recoverable error
- // which might hinder the upgrade process.
- $args = array();
- if (isset($_GET[$config->userFrameworkURLVar])) {
- $args = explode('/', $_GET[$config->userFrameworkURLVar]);
+ public static function getResourceBase() {
+ $settings = Civi::settings();
+ $url = $settings->getUrl('userFrameworkResourceURL', 'relative');
+ if (empty($url)) {
+ $config = CRM_Core_Config::singleton();
+ $civiSource = $config->userSystem->getCiviSourceStorage();
+ $url = $settings->filterUrl($civiSource['url'], 'relative');
}
+ return $url;
}
}
return array($url, NULL, NULL);
}
+ /**
+ * Determine the default location for file storage.
+ *
+ * FIXME:
+ * 1. This was pulled out from a bigger function. It should be split
+ * into even smaller pieces and marked abstract.
+ * 2. This would be easier to compute by a calling a CMS API, but
+ * for whatever reason Civi gets it from config data.
+ *
+ * @return array
+ * - url: string. ex: "http://example.com/sites/foo.com/files/civicrm"
+ * - path: string. ex: "/var/www/sites/foo.com/files/civicrm"
+ */
+ public function getDefaultFileStorage() {
+ global $civicrm_root;
+ $config = CRM_Core_Config::singleton();
+ $baseURL = CRM_Utils_System::languageNegotiationURL($config->userFrameworkBaseURL, FALSE, TRUE);
+
+ $filesURL = NULL;
+ $filesPath = NULL;
+
+ if ($config->userFramework == 'Joomla') {
+ // gross hack
+ // we need to remove the administrator/ from the end
+ $tempURL = str_replace("/administrator/", "/", $baseURL);
+ $filesURL = $tempURL . "media/civicrm/";
+ }
+ elseif ($config->userFramework == 'WordPress') {
+ //for standalone no need of sites/defaults directory
+ $filesURL = $baseURL . "wp-content/plugins/files/civicrm/";
+ }
+ elseif ($this->is_drupal) {
+ $siteName = $config->userSystem->parseDrupalSiteName($civicrm_root);
+ if ($siteName) {
+ $filesURL = $baseURL . "sites/$siteName/files/civicrm/";
+ }
+ else {
+ $filesURL = $baseURL . "sites/default/files/civicrm/";
+ }
+ }
+ elseif ($config->userFramework == 'UnitTests') {
+ $filesURL = $baseURL . "sites/default/files/civicrm/";
+ }
+ else {
+ throw new CRM_Core_Exception("Failed to locate default file storage ($config->userFramework)");
+ }
+
+ return array(
+ 'url' => $filesURL,
+ 'path' => CRM_Utils_File::baseFilePath(),
+ );
+ }
+
+ /**
+ * Determine the location of the CiviCRM source tree.
+ *
+ * FIXME:
+ * 1. This was pulled out from a bigger function. It should be split
+ * into even smaller pieces and marked abstract.
+ * 2. This would be easier to compute by a calling a CMS API, but
+ * for whatever reason we take the hard way.
+ *
+ * @return array
+ * - url: string. ex: "http://example.com/sites/all/modules/civicrm"
+ * - path: string. ex: "/var/www/sites/all/modules/civicrm"
+ */
+ public function getCiviSourceStorage() {
+ global $civicrm_root;
+ $config = CRM_Core_Config::singleton();
+
+ // Don't use $config->userFrameworkBaseURL; it has garbage on it.
+ // More generally, w shouldn't be using $config here.
+ if (!defined('CIVICRM_UF_BASEURL')) {
+ throw new RuntimeException('Undefined constant: CIVICRM_UF_BASEURL');
+ }
+ $baseURL = CRM_Utils_File::addTrailingSlash(CIVICRM_UF_BASEURL, '/');
+ if (CRM_Utils_System::isSSL()) {
+ $baseURL = str_replace('http://', 'https://', $baseURL);
+ }
+
+ if ($config->userFramework == 'Joomla') {
+ $userFrameworkResourceURL = $baseURL . "components/com_civicrm/civicrm/";
+ }
+ elseif ($config->userFramework == 'WordPress') {
+ $userFrameworkResourceURL = $baseURL . "wp-content/plugins/civicrm/civicrm/";
+ }
+ elseif ($this->is_drupal) {
+ // Drupal setting
+ // check and see if we are installed in sites/all (for D5 and above)
+ // we dont use checkURL since drupal generates an error page and throws
+ // the system for a loop on lobo's macosx box
+ // or in modules
+ $cmsPath = $config->userSystem->cmsRootPath();
+ $userFrameworkResourceURL = $baseURL . str_replace("$cmsPath/", '',
+ str_replace('\\', '/', $civicrm_root)
+ );
+
+ $siteName = $config->userSystem->parseDrupalSiteName($civicrm_root);
+ if ($siteName) {
+ $civicrmDirName = trim(basename($civicrm_root));
+ $userFrameworkResourceURL = $baseURL . "sites/$siteName/modules/$civicrmDirName/";
+ }
+ }
+ else {
+ $userFrameworkResourceURL = NULL;
+ }
+
+ return array(
+ 'url' => $userFrameworkResourceURL,
+ 'path' => CRM_Utils_File::addTrailingSlash($civicrm_root),
+ );
+ }
+
/**
* Perform any post login activities required by the CMS.
*
return user_load($userID);
}
+ public function parseDrupalSiteName($civicrm_root) {
+ $siteName = NULL;
+ if (strpos($civicrm_root,
+ DIRECTORY_SEPARATOR . 'sites' . DIRECTORY_SEPARATOR . 'all' . DIRECTORY_SEPARATOR . 'modules'
+ ) === FALSE
+ ) {
+ $startPos = strpos($civicrm_root,
+ DIRECTORY_SEPARATOR . 'sites' . DIRECTORY_SEPARATOR
+ );
+ $endPos = strpos($civicrm_root,
+ DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR
+ );
+ if ($startPos && $endPos) {
+ // if component is in sites/SITENAME/modules
+ $siteName = substr($civicrm_root,
+ $startPos + 7,
+ $endPos - $startPos - 7
+ );
+ }
+ }
+ return $siteName;
+ }
+
}