CRM_Core_Config - Fix bugs in path/dir settings
authorTim Otten <totten@civicrm.org>
Wed, 9 Sep 2015 20:50:11 +0000 (13:50 -0700)
committerTim Otten <totten@civicrm.org>
Thu, 17 Sep 2015 22:49:29 +0000 (15:49 -0700)
CRM/Core/Config.php
CRM/Core/Config/Defaults.php
Civi/Core/SettingsBag.php

index 8fd55569f77376aaa3872e24b1a2fed2e4670938..688c7dabd28fde1979170d02d3ee2daddc7efba9 100644 (file)
@@ -296,7 +296,7 @@ class CRM_Core_Config extends CRM_Core_Config_Variables {
     $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();
+    $this->uploadDir = CRM_Core_Config_Defaults::getUploadDir();
 
     $this->userFrameworkResourceURL = CRM_Core_Config_Defaults::getUserFrameworkResourceUrl();
     $this->customCSSURL = CRM_Core_Config_Defaults::getCustomCssUrl();
index 9c468daf3f2d9c0dd937d5bc0cd0477f48dd28fa..3ea2982de58035fbeb526dd9b86dc4889169b61b 100644 (file)
@@ -61,10 +61,11 @@ class CRM_Core_Config_Defaults {
   }
 
   public static function getCustomFileUploadDir() {
-    $value = Civi::settings()->getPath('customFileUploadDir');
+    $settings = Civi::settings();
+    $value = $settings->getPath('customFileUploadDir');
     if (empty($value)) {
       $defaultFileStorage = CRM_Core_Config::singleton()->userSystem->getDefaultFileStorage();
-      $value = $defaultFileStorage['url'] . "custom/";
+      $value = $settings->filterPath($defaultFileStorage['path'] . "custom/");
     }
     $value = CRM_Utils_File::addTrailingSlash($value);
     CRM_Utils_File::createDir($value);
@@ -90,10 +91,11 @@ class CRM_Core_Config_Defaults {
   }
 
   public static function getImageUploadDir() {
-    $value = Civi::settings()->getPath('imageUploadDir');
+    $settings = Civi::settings();
+    $value = $settings->getPath('imageUploadDir');
     if (empty($value)) {
       $defaultFileStorage = CRM_Core_Config::singleton()->userSystem->getDefaultFileStorage();
-      $value = $defaultFileStorage['path'] . "persist/contribute/";
+      $value = $settings->filterPath($defaultFileStorage['path'] . "persist/contribute/");
     }
     $value = CRM_Utils_File::addTrailingSlash($value);
     CRM_Utils_File::createDir($value);
@@ -101,19 +103,21 @@ class CRM_Core_Config_Defaults {
   }
 
   public static function getImageUploadUrl() {
-    $imageUploadURL = Civi::settings()->getUrl('imageUploadURL', 'absolute');
+    $settings = Civi::settings();
+    $imageUploadURL = $settings->getUrl('imageUploadURL', 'absolute');
     if (empty($imageUploadURL)) {
       $defaultFileStorage = CRM_Core_Config::singleton()->userSystem->getDefaultFileStorage();
-      $imageUploadURL = $defaultFileStorage['url'] . 'persist/contribute/';
+      $imageUploadURL = $settings->filterUrl($defaultFileStorage['url'] . 'persist/contribute/', 'absolute');
     }
     return $imageUploadURL;
   }
 
   public static function getUploadDir() {
-    $value = Civi::settings()->getPath('uploadDir');
+    $settings = Civi::settings();
+    $value = $settings->getPath('uploadDir');
     if (empty($value)) {
       $defaultFileStorage = CRM_Core_Config::singleton()->userSystem->getDefaultFileStorage();
-      $value = $defaultFileStorage['path'] . "upload/";
+      $value = $settings->filterPath($defaultFileStorage['path'] . "upload/");
     }
     $value = CRM_Utils_File::addTrailingSlash($value);
     CRM_Utils_File::createDir($value);
index f7c668b83944b375540509aacc827272dffe948d..0496cfcf3f3322ed918ff1393c3deb5430fac3d0 100644 (file)
@@ -165,7 +165,7 @@ class SettingsBag {
    */
   public function getPath($key) {
     if (!isset($this->filteredValues[$key])) {
-      $this->filteredValues[$key] = \CRM_Utils_File::absoluteDirectory($this->get($key));
+      $this->filteredValues[$key] = $this->filterPath($this->get($key));
     }
     return $this->filteredValues[$key];
   }
@@ -350,11 +350,22 @@ class SettingsBag {
     if ($value) {
       if ($ssl || ($ssl === NULL && \CRM_Utils_System::isSSL())) {
         $value = str_replace('http://', 'https://', $value);
-        return $value;
       }
-      return $value;
     }
     return $value;
   }
 
+  /**
+   * @param string $value
+   * @return bool|string
+   */
+  public function filterPath($value) {
+    if ($value) {
+      return \CRM_Utils_File::absoluteDirectory($value);
+    }
+    else {
+      return FALSE;
+    }
+  }
+
 }