]> 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 5551f432040096d0c0fa1d4930ead29369d521c7..789cece2bea924d2c04e35a60e3e926df000e762 100644 (file)
@@ -27,6 +27,7 @@ global $config, $_server, $_path;
  */
 class GNUsocial
 {
+    protected static $config_files = array();
     protected static $have_config;
     protected static $is_api;
     protected static $is_ajax;
@@ -140,6 +141,9 @@ class GNUsocial
         // Load settings from database; note we need autoload for this
         Config::loadSettings();
 
+        self::fillConfigVoids();
+        self::verifyLoadedConfig();
+
         self::initPlugins();
     }
 
@@ -258,6 +262,15 @@ class GNUsocial
         return self::$have_config;
     }
 
+    /**
+     * Returns a list of configuration files that have
+     * been loaded for this instance of GNU social.
+     */
+    public static function configFiles()
+    {
+        return self::$config_files;
+    }
+
     public static function isApi()
     {
         return self::$is_api;
@@ -373,15 +386,11 @@ class GNUsocial
         if (isset($conffile)) {
             $config_files = array($conffile);
         } else {
-            $config_files = array('/etc/statusnet/statusnet.php',
-                                  '/etc/statusnet/laconica.php',
-                                  '/etc/laconica/laconica.php',
-                                  '/etc/statusnet/'.$_server.'.php',
-                                  '/etc/laconica/'.$_server.'.php');
+            $config_files = array('/etc/gnusocial/config.php',
+                                  '/etc/gnusocial/config.d/'.$_server.'.php');
 
             if (strlen($_path) > 0) {
-                $config_files[] = '/etc/statusnet/'.$_server.'_'.$_path.'.php';
-                $config_files[] = '/etc/laconica/'.$_server.'_'.$_path.'.php';
+                $config_files[] = '/etc/gnusocial/config.d/'.$_server.'_'.$_path.'.php';
             }
 
             $config_files[] = INSTALLDIR.'/config.php';
@@ -393,8 +402,8 @@ class GNUsocial
             if (@file_exists($_config_file)) {
                 // Ignore 0-byte config files
                 if (filesize($_config_file) > 0) {
-                    common_log(LOG_INFO, "Including config file: " . $_config_file);
                     include($_config_file);
+                    self::$config_files[] = $_config_file;
                     self::$have_config = true;
                 }
             }
@@ -412,6 +421,56 @@ 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.
+     *
+     * Might make changes to the filesystem, to created dirs, but will
+     * not make database changes.
+     */
+    static function verifyLoadedConfig()
+    {
+        $mkdirs = [];
+
+        if (common_config('htmlpurifier', 'Cache.DefinitionImpl') === 'Serializer'
+                && !is_dir(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));
+            }
+        }
+
+        if (!is_array(common_config('public', 'autosource'))) {
+            throw new ConfigException('Configuration option public/autosource is not an array.');
+        }
+    }
+
     /**
      * Are we running from the web with HTTPS?
      *
@@ -420,6 +479,10 @@ class GNUsocial
 
     static function isHTTPS()
     {
+        if (common_config('site', 'sslproxy')) {
+            return true;
+        }
+
         // There are some exceptions to this; add them here!
         if (empty($_SERVER['HTTPS'])) {
             return false;