]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/statusnet.php
Introduced isCurrentProfileInScope() which shall check if current profile is
[quix0rs-gnu-social.git] / lib / statusnet.php
index 0a15d3b5251099b927b970743764908c44ea0cfa..844a15c339d10cc8ab363ef296c366ccba1c5963 100644 (file)
@@ -44,9 +44,17 @@ class StatusNet
      *
      * @throws ServerException if plugin can't be found
      */
-    public static function addPlugin($name, $attrs = null)
+    public static function addPlugin($name, array $attrs=array())
     {
         $name = ucfirst($name);
+
+        if (isset(self::$plugins[$name])) {
+            // We have already loaded this plugin. Don't try to
+            // do it again with (possibly) different values.
+            // Försten till kvarn får mala.
+            return true;
+        }
+
         $pluginclass = "{$name}Plugin";
 
         if (!class_exists($pluginclass)) {
@@ -70,15 +78,29 @@ class StatusNet
             }
         }
 
+        // Doesn't this $inst risk being garbage collected or something?
+        // TODO: put into a static array that makes sure $inst isn't lost.
         $inst = new $pluginclass();
-        if (!empty($attrs)) {
-            foreach ($attrs as $aname => $avalue) {
-                $inst->$aname = $avalue;
-            }
+        foreach ($attrs as $aname => $avalue) {
+            $inst->$aname = $avalue;
         }
 
         // Record activated plugins for later display/config dump
-        self::$plugins[] = array($name, $attrs);
+        self::$plugins[$name] = $attrs;
+
+        return true;
+    }
+
+    public static function delPlugin($name)
+    {
+        // Remove our plugin if it was previously loaded
+        $name = ucfirst($name);
+        if (isset(self::$plugins[$name])) {
+            unset(self::$plugins[$name]);
+        }
+
+        // make sure initPlugins will avoid this
+        common_config_set('plugins', 'disable-'.$name, true);
 
         return true;
     }
@@ -110,12 +132,12 @@ class StatusNet
     {
         Router::clear();
 
-        StatusNet::initDefaults($server, $path);
-        StatusNet::loadConfigFile($conffile);
+        self::initDefaults($server, $path);
+        self::loadConfigFile($conffile);
 
         $sprofile = common_config('site', 'profile');
         if (!empty($sprofile)) {
-            StatusNet::loadSiteProfile($sprofile);
+            self::loadSiteProfile($sprofile);
         }
         // Load settings from database; note we need autoload for this
         Config::loadSettings();
@@ -181,9 +203,13 @@ class StatusNet
      */
     protected static function initPlugins()
     {
+        // User config may have already added some of these plugins, with
+        // maybe configured parameters. The self::addPlugin function will
+        // ignore the new call if it has already been instantiated.
+
         // Load core plugins
         foreach (common_config('plugins', 'core') as $name => $params) {
-            call_user_func('addPlugin', $name, $params);
+            call_user_func('self::addPlugin', $name, $params);
         }
 
         // Load default plugins
@@ -193,18 +219,20 @@ class StatusNet
                 continue;
             }
 
+            // TODO: We should be able to avoid this is_null and assume $params
+            // is an array, since that's how it is typed in addPlugin
             if (is_null($params)) {
-                addPlugin($name);
+                self::addPlugin($name);
             } else if (is_array($params)) {
                 if (count($params) == 0) {
-                    addPlugin($name);
+                    self::addPlugin($name);
                 } else {
                     $keys = array_keys($params);
                     if (is_string($keys[0])) {
-                        addPlugin($name, $params);
+                        self::addPlugin($name, $params);
                     } else {
                         foreach ($params as $paramset) {
-                            addPlugin($name, $paramset);
+                            self::addPlugin($name, $paramset);
                         }
                     }
                 }
@@ -315,7 +343,7 @@ class StatusNet
     {
         global $config;
         $settings = SiteProfile::getSettings($name);
-        $config = array_merge($config, $settings);
+        $config = array_replace_recursive($config, $settings);
     }
 
     protected static function _sn_to_path($sn)
@@ -379,33 +407,6 @@ class StatusNet
                                         $config_files);
         }
 
-        // Backwards compatibility
-        if (array_key_exists('memcached', $config)) {
-            if ($config['memcached']['enabled']) {
-                addPlugin('Memcache', array('servers' => $config['memcached']['server']));
-            }
-
-            if (!empty($config['memcached']['base'])) {
-                $config['cache']['base'] = $config['memcached']['base'];
-            }
-        }
-
-        if (array_key_exists('xmpp', $config)) {
-            if ($config['xmpp']['enabled']) {
-                addPlugin('xmpp', array(
-                    'server' => $config['xmpp']['server'],
-                    'port' => $config['xmpp']['port'],
-                    'user' => $config['xmpp']['user'],
-                    'resource' => $config['xmpp']['resource'],
-                    'encryption' => $config['xmpp']['encryption'],
-                    'password' => $config['xmpp']['password'],
-                    'host' => $config['xmpp']['host'],
-                    'debug' => $config['xmpp']['debug'],
-                    'public' => $config['xmpp']['public']
-                ));
-            }
-        }
-
         // Check for database server; must exist!
 
         if (empty($config['db']['database'])) {
@@ -422,11 +423,20 @@ class StatusNet
     static function isHTTPS()
     {
         // There are some exceptions to this; add them here!
-        if(empty($_SERVER['HTTPS'])) {
+        if (empty($_SERVER['HTTPS'])) {
             return false;
-        } else {
-            return $_SERVER['HTTPS'] !== 'off';
         }
+
+        // If it is _not_ "off", it is on, so "true".
+        return strtolower($_SERVER['HTTPS']) !== 'off';
+    }
+
+    /**
+     * Can we use HTTPS? Then do! Only return false if it's not configured ("never").
+     */
+    static function useHTTPS()
+    {
+        return self::isHTTPS() || common_config('site', 'ssl') != 'never';
     }
 }