]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/RSSCloud/RSSCloudPlugin.php
Merge branch 'master' into testing
[quix0rs-gnu-social.git] / plugins / RSSCloud / RSSCloudPlugin.php
index 10f81b8ddf9e06d6d525e3e1347ba772919076d6..c1951cdbf856b31931ae83d6cb82fcf9c61b1e20 100644 (file)
@@ -33,13 +33,35 @@ if (!defined('STATUSNET')) {
 
 define('RSSCLOUDPLUGIN_VERSION', '0.1');
 
+/**
+ * Plugin class for adding RSSCloud capabilities to StatusNet
+ *
+ * @category Plugin
+ * @package  StatusNet
+ * @author   Zach Copley <zach@status.net>
+ * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
+ * @link     http://status.net/
+ **/
+
 class RSSCloudPlugin extends Plugin
 {
+    /**
+     * Our friend, the constructor
+     *
+     * @return void
+     */
     function __construct()
     {
         parent::__construct();
     }
 
+    /**
+     * Setup the info for the subscription handler. Allow overriding
+     * to point at another cloud hub (not currently used).
+     *
+     * @return void
+     */
+
     function onInitializePlugin()
     {
         $this->domain   = common_config('rsscloud', 'domain');
@@ -50,7 +72,7 @@ class RSSCloudPlugin extends Plugin
 
         // set defaults
 
-        $local_server = parse_url(common_path('rsscloud/request_notify'));
+        $local_server = parse_url(common_path('main/rsscloud/request_notify'));
 
         if (empty($this->domain)) {
             $this->domain = $local_server['host'];
@@ -61,7 +83,7 @@ class RSSCloudPlugin extends Plugin
         }
 
         if (empty($this->path)) {
-            $this->path = '/rsscloud/request_notify';
+            $this->path = $local_server['path'];
         }
 
         if (empty($this->funct)) {
@@ -78,40 +100,68 @@ class RSSCloudPlugin extends Plugin
      *
      * Hook for RouterInitialized event.
      *
+     * @param Mapper $m URL parser and mapper
+     *
      * @return boolean hook return
      */
 
-    function onRouterInitialized(&$m)
+    function onRouterInitialized($m)
     {
-        $m->connect('rsscloud/request_notify', array('action' => 'RSSCloudRequestNotify'));
+        $m->connect('/main/rsscloud/request_notify',
+                    array('action' => 'RSSCloudRequestNotify'));
 
-        // XXX: This is just for end-to-end testing
-        $m->connect('rsscloud/notify', array('action' => 'LoggingAggregator'));
+        // XXX: This is just for end-to-end testing. Uncomment if you need to pretend
+        //      to be a cloud hub for some reason.
+        //$m->connect('/main/rsscloud/notify',
+        //            array('action' => 'LoggingAggregator'));
 
         return true;
     }
 
+    /**
+     * Automatically load the actions and libraries used by
+     * the RSSCloud plugin
+     *
+     * @param Class $cls the class
+     *
+     * @return boolean hook return
+     *
+     */
+
     function onAutoload($cls)
     {
         switch ($cls)
         {
-         case 'RSSCloudSubscription':
-            include_once(INSTALLDIR . '/plugins/RSSCloud/RSSCloudSubscription.php');
+        case 'RSSCloudSubscription':
+            include_once INSTALLDIR . '/plugins/RSSCloud/RSSCloudSubscription.php';
+            return false;
+        case 'RSSCloudNotifier':
+            include_once INSTALLDIR . '/plugins/RSSCloud/RSSCloudNotifier.php';
             return false;
-         case 'RSSCloudNotifier':
-            include_once(INSTALLDIR . '/plugins/RSSCloud/RSSCloudNotifier.php');
+        case 'RSSCloudQueueHandler':
+            include_once INSTALLDIR . '/plugins/RSSCloud/RSSCloudQueueHandler.php';
             return false;
-         case 'RSSCloudRequestNotifyAction':
-         case 'LoggingAggregatorAction':
-            include_once(INSTALLDIR . '/plugins/RSSCloud/' . mb_substr($cls, 0, -6) . '.php');
+        case 'RSSCloudRequestNotifyAction':
+        case 'LoggingAggregatorAction':
+            include_once INSTALLDIR . '/plugins/RSSCloud/' .
+              mb_substr($cls, 0, -6) . '.php';
             return false;
-         default:
+        default:
             return true;
         }
     }
 
-    function onStartApiRss($action){
+    /**
+     * Add a <cloud> element to the RSS feed (after the rss <channel>
+     * element is started).
+     *
+     * @param Action $action the ApiAction
+     *
+     * @return void
+     */
 
+    function onStartApiRss($action)
+    {
         if (get_class($action) == 'ApiTimelineUserAction') {
 
             $attrs = array('domain'            => $this->domain,
@@ -126,8 +176,8 @@ class RSSCloudPlugin extends Plugin
             foreach ($attrs as $name => $value) {
                 $action->xw->writeAttribute($name, $value);
             }
-            $action->xw->endElement();
 
+            $action->xw->endElement();
         }
     }
 
@@ -139,47 +189,24 @@ class RSSCloudPlugin extends Plugin
      *
      * @return boolean hook return
      */
+
     function onStartEnqueueNotice($notice, &$transports)
     {
-        array_push($transports, 'rsscloud');
+        if ($notice->isLocal()) {
+            array_push($transports, 'rsscloud');
+        }
         return true;
     }
 
     /**
-     * broadcast the message when not using queuehandler
-     *
-     * @param Notice &$notice the notice
-     * @param array  $queue   destination queue
+     * Create the rsscloud_subscription table if it's not
+     * already in the DB
      *
      * @return boolean hook return
      */
-    function onUnqueueHandleNotice(&$notice, $queue)
-    {
-        if (($queue == 'rsscloud') && ($this->_isLocal($notice))) {
-
-            // broadcast the notice here
-            common_debug('broadcasting rssCloud bound notice ' . $notice->id);
-
-            return false;
-        }
-        return true;
-    }
 
-    /**
-     * Determine whether the notice was locally created
-     *
-     * @param Notice $notice
-     *
-     * @return boolean locality
-     */
-    function _isLocal($notice)
+    function onCheckSchema()
     {
-        return ($notice->is_local == Notice::LOCAL_PUBLIC ||
-                $notice->is_local == Notice::LOCAL_NONPUBLIC);
-    }
-
-
-    function onCheckSchema() {
         $schema = Schema::get();
         $schema->ensureTable('rsscloud_subscription',
                              array(new ColumnDef('subscribed', 'integer',
@@ -187,14 +214,43 @@ class RSSCloudPlugin extends Plugin
                                    new ColumnDef('url', 'varchar',
                                                  '255', false, 'PRI'),
                                    new ColumnDef('failures', 'integer',
-                                                 null, false, 'MUL'),
+                                                 null, false, null, 0),
                                    new ColumnDef('created', 'datetime',
                                                  null, false),
-                                   new ColumnDef('modified', 'timestamp')
-                                  )
-                            );
+                                   new ColumnDef('modified', 'timestamp',
+                                                 null, false, null,
+                                                 'CURRENT_TIMESTAMP',
+                                                 'on update CURRENT_TIMESTAMP')
+                                   ));
          return true;
     }
 
+    /**
+     * Register RSSCloud notice queue handler
+     *
+     * @param QueueManager $manager
+     *
+     * @return boolean hook return
+     */
+    function onEndInitializeQueueManager($manager)
+    {
+        $manager->connect('rsscloud', 'RSSCloudQueueHandler');
+        return true;
+    }
+
+    function onPluginVersion(&$versions)
+    {
+        $versions[] = array('name' => 'RSSCloud',
+                            'version' => RSSCLOUDPLUGIN_VERSION,
+                            'author' => 'Zach Copley',
+                            'homepage' => 'http://status.net/wiki/Plugin:RSSCloud',
+                            'rawdescription' =>
+                            _m('The RSSCloud plugin enables your StatusNet instance to publish ' .
+                               'real-time updates for profile RSS feeds using the ' .
+                               '<a href="http://rsscloud.org/">RSSCloud protocol</a>".'));
+
+        return true;
+    }
+
 }