]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/statusnet.php
Core plugin list would not merge into $config
[quix0rs-gnu-social.git] / lib / statusnet.php
index ff0502915ad2879be3ddafbdae255bb721fadbd8..56ac0cb1d31c7c223678e88da9bb0b5eab969441 100644 (file)
@@ -31,6 +31,7 @@ class StatusNet
 {
     protected static $have_config;
     protected static $is_api;
+    protected static $is_ajax;
     protected static $plugins = array();
 
     /**
@@ -107,9 +108,15 @@ class StatusNet
      */
     public static function init($server=null, $path=null, $conffile=null)
     {
-        StatusNet::initDefaults($server, $path);
-        StatusNet::loadConfigFile($conffile);
+        Router::clear();
 
+        self::initDefaults($server, $path);
+        self::loadConfigFile($conffile);
+
+        $sprofile = common_config('site', 'profile');
+        if (!empty($sprofile)) {
+            self::loadSiteProfile($sprofile);
+        }
         // Load settings from database; note we need autoload for this
         Config::loadSettings();
 
@@ -141,7 +148,7 @@ class StatusNet
             return true;
         }
 
-        $sn = Status_network::staticGet('nickname', $nickname);
+        $sn = Status_network::getKV('nickname', $nickname);
         if (empty($sn)) {
             return false;
             throw new Exception("No such site nickname '$nickname'");
@@ -169,12 +176,16 @@ class StatusNet
         return $sites;
     }
 
-
     /**
      * Fire initialization events for all instantiated plugins.
      */
     protected static function initPlugins()
     {
+        // Load core plugins
+        foreach (common_config('plugins', 'core') as $name => $params) {
+            call_user_func('addPlugin', $name, $params);
+        }
+
         // Load default plugins
         foreach (common_config('plugins', 'default') as $name => $params) {
             $key = 'disable-' . $name;
@@ -216,21 +227,31 @@ class StatusNet
      *
      * @return bool
      */
-    public function haveConfig()
+    public static function haveConfig()
     {
         return self::$have_config;
     }
 
-    public function isApi()
+    public static function isApi()
     {
         return self::$is_api;
     }
-    
-    public function setApi($mode)
+
+    public static function setApi($mode)
     {
         self::$is_api = $mode;
     }
 
+    public static function isAjax()
+    {
+        return self::$is_ajax;
+    }
+
+    public static function setAjax($mode)
+    {
+        self::$is_ajax = $mode;
+    }
+
     /**
      * Build default configuration array
      * @return array
@@ -246,9 +267,9 @@ class StatusNet
      * Establish default configuration based on given or default server and path
      * Sets global $_server, $_path, and $config
      */
-    protected static function initDefaults($server, $path)
+    public static function initDefaults($server, $path)
     {
-        global $_server, $_path, $config;
+        global $_server, $_path, $config, $_PEAR;
 
         Event::clearHandlers();
         self::$plugins = array();
@@ -280,21 +301,24 @@ class StatusNet
         // default configuration, overwritten in config.php
         // Keep DB_DataObject's db config synced to ours...
 
-        $config['db'] = &PEAR::getStaticProperty('DB_DataObject','options');
+        $config['db'] = &$_PEAR->getStaticProperty('DB_DataObject','options');
 
         $config['db'] = $default['db'];
 
-        // Backward compatibility
-
-        $config['site']['design'] =& $config['design'];
-
         if (function_exists('date_default_timezone_set')) {
             /* Work internally in UTC */
             date_default_timezone_set('UTC');
         }
     }
 
-    protected function _sn_to_path($sn)
+    public static function loadSiteProfile($name)
+    {
+        global $config;
+        $settings = SiteProfile::getSettings($name);
+        $config = array_merge($config, $settings);
+    }
+
+    protected static function _sn_to_path($sn)
     {
         $past_root = substr($sn, 1);
         $last_slash = strrpos($past_root, '/');
@@ -312,7 +336,7 @@ class StatusNet
      *
      * @throws NoConfigException
      */
-    protected function loadConfigFile($conffile=null)
+    protected static function loadConfigFile($conffile=null)
     {
         global $_server, $_path, $config;
 
@@ -341,8 +365,12 @@ class StatusNet
 
         foreach ($config_files as $_config_file) {
             if (@file_exists($_config_file)) {
-                include($_config_file);
-                self::$have_config = true;
+                // Ignore 0-byte config files
+                if (filesize($_config_file) > 0) {
+                    common_log(LOG_INFO, "Including config file: " . $_config_file);
+                    include($_config_file);
+                    self::$have_config = true;
+                }
             }
         }
 
@@ -351,13 +379,6 @@ class StatusNet
                                         $config_files);
         }
 
-        // Fixup for statusnet.ini
-        $_db_name = substr($config['db']['database'], strrpos($config['db']['database'], '/') + 1);
-
-        if ($_db_name != 'statusnet' && !array_key_exists('ini_'.$_db_name, $config['db'])) {
-            $config['db']['ini_'.$_db_name] = INSTALLDIR.'/classes/statusnet.ini';
-        }
-
         // Backwards compatibility
         if (array_key_exists('memcached', $config)) {
             if ($config['memcached']['enabled']) {
@@ -368,6 +389,7 @@ class StatusNet
                 $config['cache']['base'] = $config['memcached']['base'];
             }
         }
+
         if (array_key_exists('xmpp', $config)) {
             if ($config['xmpp']['enabled']) {
                 addPlugin('xmpp', array(
@@ -383,6 +405,28 @@ class StatusNet
                 ));
             }
         }
+
+        // Check for database server; must exist!
+
+        if (empty($config['db']['database'])) {
+            throw new ServerException("No database server for this site.");
+        }
+    }
+
+    /**
+     * Are we running from the web with HTTPS?
+     *
+     * @return boolean true if we're running with HTTPS; else false
+     */
+
+    static function isHTTPS()
+    {
+        // There are some exceptions to this; add them here!
+        if(empty($_SERVER['HTTPS'])) {
+            return false;
+        } else {
+            return $_SERVER['HTTPS'] !== 'off';
+        }
     }
 }