]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/gnusocial.php
Merge branch 'nightly' into 'nightly'
[quix0rs-gnu-social.git] / lib / gnusocial.php
index aecebe2556440788fa2fd1e7f0c1bd3a76d7e557..789cece2bea924d2c04e35a60e3e926df000e762 100644 (file)
@@ -141,6 +141,7 @@ class GNUsocial
         // Load settings from database; note we need autoload for this
         Config::loadSettings();
 
+        self::fillConfigVoids();
         self::verifyLoadedConfig();
 
         self::initPlugins();
@@ -420,6 +421,14 @@ class GNUsocial
         }
     }
 
+    static function fillConfigVoids()
+    {
+        // special cases on empty configuration options
+        if (!common_config('thumbnail', 'dir')) {
+            common_config_set('thumbnail', 'dir', File::path('thumb'));
+        }
+    }
+
     /**
      * Verify that the loaded config is good. Not complete, but will
      * throw exceptions on common configuration problems I hope.
@@ -429,10 +438,31 @@ class GNUsocial
      */
     static function verifyLoadedConfig()
     {
+        $mkdirs = [];
+
         if (common_config('htmlpurifier', 'Cache.DefinitionImpl') === 'Serializer'
                 && !is_dir(common_config('htmlpurifier', 'Cache.SerializerPath'))) {
-            if (!mkdir(common_config('htmlpurifier', 'Cache.SerializerPath'))) {
-                throw new ConfigException('Could not create HTMLPurifier cache dir: '._ve(common_config('htmlpurifier', 'Cache.SerializerPath')));
+            $mkdirs[common_config('htmlpurifier', 'Cache.SerializerPath')] = 'HTMLPurifier Serializer cache';
+        }
+
+        // go through our configurable storage directories
+        foreach (['attachments', 'thumbnail'] as $dirtype) {
+            $dir = common_config($dirtype, 'dir');
+            if (!empty($dir) && !is_dir($dir)) {
+                $mkdirs[$dir] = $dirtype;
+            }
+        }
+
+        // try to create those that are not directories
+        foreach ($mkdirs as $dir=>$description) {
+            if (is_file($dir)) {
+                throw new ConfigException('Expected directory for '._ve($description).' is a file!');
+            }
+            if (!mkdir($dir)) {
+                throw new ConfigException('Could not create directory for '._ve($description).': '._ve($dir));
+            }
+            if (!chmod($dir, 0775)) {
+                common_log(LOG_WARNING, 'Could not chmod 0775 on directory for '._ve($description).': '._ve($dir));
             }
         }