]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/statusnet.php
Merge branch 'master' into 1.0.x
[quix0rs-gnu-social.git] / lib / statusnet.php
index beeb26cccdccb182777682be0b875d8c8035f2e1..ff0502915ad2879be3ddafbdae255bb721fadbd8 100644 (file)
@@ -30,6 +30,8 @@ global $config, $_server, $_path;
 class StatusNet
 {
     protected static $have_config;
+    protected static $is_api;
+    protected static $plugins = array();
 
     /**
      * Configure and instantiate a plugin into the current configuration.
@@ -73,9 +75,22 @@ class StatusNet
                 $inst->$aname = $avalue;
             }
         }
+
+        // Record activated plugins for later display/config dump
+        self::$plugins[] = array($name, $attrs);
+
         return true;
     }
 
+    /**
+     * Get a list of activated plugins in this process.
+     * @return array of (string $name, array $args) pairs
+     */
+    public static function getActivePlugins()
+    {
+        return self::$plugins;
+    }
+
     /**
      * Initialize, or re-initialize, StatusNet global configuration
      * and plugins.
@@ -101,6 +116,60 @@ class StatusNet
         self::initPlugins();
     }
 
+    /**
+     * Get identifier of the currently active site configuration
+     * @return string
+     */
+    public static function currentSite()
+    {
+        return common_config('site', 'nickname');
+    }
+
+    /**
+     * Change site configuration to site specified by nickname,
+     * if set up via Status_network. If not, sites other than
+     * the current will fail horribly.
+     *
+     * May throw exception or trigger a fatal error if the given
+     * site is missing or configured incorrectly.
+     *
+     * @param string $nickname
+     */
+    public static function switchSite($nickname)
+    {
+        if ($nickname == StatusNet::currentSite()) {
+            return true;
+        }
+
+        $sn = Status_network::staticGet('nickname', $nickname);
+        if (empty($sn)) {
+            return false;
+            throw new Exception("No such site nickname '$nickname'");
+        }
+
+        $server = $sn->getServerName();
+        StatusNet::init($server);
+    }
+
+    /**
+     * Pull all local sites from status_network table.
+     *
+     * Behavior undefined if site is not configured via Status_network.
+     *
+     * @return array of nicknames
+     */
+    public static function findAllSites()
+    {
+        $sites = array();
+        $sn = new Status_network();
+        $sn->find();
+        while ($sn->fetch()) {
+            $sites[] = $sn->nickname;
+        }
+        return $sites;
+    }
+
+
     /**
      * Fire initialization events for all instantiated plugins.
      */
@@ -108,6 +177,11 @@ class StatusNet
     {
         // Load default plugins
         foreach (common_config('plugins', 'default') as $name => $params) {
+            $key = 'disable-' . $name;
+            if (common_config('plugins', $key)) {
+                continue;
+            }
+
             if (is_null($params)) {
                 addPlugin($name);
             } else if (is_array($params)) {
@@ -147,6 +221,16 @@ class StatusNet
         return self::$have_config;
     }
 
+    public function isApi()
+    {
+        return self::$is_api;
+    }
+    
+    public function setApi($mode)
+    {
+        self::$is_api = $mode;
+    }
+
     /**
      * Build default configuration array
      * @return array
@@ -167,6 +251,7 @@ class StatusNet
         global $_server, $_path, $config;
 
         Event::clearHandlers();
+        self::$plugins = array();
 
         // try to figure out where we are. $server and $path
         // can be set by including module, else we guess based
@@ -274,7 +359,6 @@ class StatusNet
         }
 
         // Backwards compatibility
-
         if (array_key_exists('memcached', $config)) {
             if ($config['memcached']['enabled']) {
                 addPlugin('Memcache', array('servers' => $config['memcached']['server']));
@@ -284,15 +368,30 @@ class StatusNet
                 $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']
+                ));
+            }
+        }
     }
 }
 
 class NoConfigException extends Exception
 {
-    public $config_files;
+    public $configFiles;
 
-    function __construct($msg, $config_files) {
+    function __construct($msg, $configFiles) {
         parent::__construct($msg);
-        $this->config_files = $config_files;
+        $this->configFiles = $configFiles;
     }
 }