]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/RSSCloud/RSSCloudPlugin.php
Merge remote-tracking branch 'upstream/master' into social-master
[quix0rs-gnu-social.git] / plugins / RSSCloud / RSSCloudPlugin.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * Plugin to support RSSCloud
6  *
7  * PHP version 5
8  *
9  * LICENCE: This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU Affero General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU Affero General Public License for more details.
18    *
19  * You should have received a copy of the GNU Affero General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  *
22  * @category  Plugin
23  * @package   StatusNet
24  * @author    Zach Copley <zach@status.net>
25  * @copyright 2009 StatusNet, Inc.
26  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27  * @link      http://status.net/
28  */
29
30 if (!defined('STATUSNET')) {
31     exit(1);
32 }
33
34 define('RSSCLOUDPLUGIN_VERSION', '0.1');
35
36 /**
37  * Plugin class for adding RSSCloud capabilities to StatusNet
38  *
39  * @category Plugin
40  * @package  StatusNet
41  * @author   Zach Copley <zach@status.net>
42  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
43  * @link     http://status.net/
44  */
45 class RSSCloudPlugin extends Plugin
46 {
47     /**
48      * Our friend, the constructor
49      *
50      * @return void
51      */
52     function __construct()
53     {
54         parent::__construct();
55     }
56
57     /**
58      * Setup the info for the subscription handler. Allow overriding
59      * to point at another cloud hub (not currently used).
60      *
61      * @return void
62      */
63     function onInitializePlugin()
64     {
65         $this->domain   = common_config('rsscloud', 'domain');
66         $this->port     = common_config('rsscloud', 'port');
67         $this->path     = common_config('rsscloud', 'path');
68         $this->funct    = common_config('rsscloud', 'function');
69         $this->protocol = common_config('rsscloud', 'protocol');
70
71         // set defaults
72
73         $local_server = parse_url(common_path('main/rsscloud/request_notify'));
74
75         if (empty($this->domain)) {
76             $this->domain = $local_server['host'];
77         }
78
79         if (empty($this->port)) {
80             $this->port = '80';
81         }
82
83         if (empty($this->path)) {
84             $this->path = $local_server['path'];
85         }
86
87         if (empty($this->funct)) {
88             $this->funct = '';
89         }
90
91         if (empty($this->protocol)) {
92             $this->protocol = 'http-post';
93         }
94     }
95
96     /**
97      * Add RSSCloud-related paths to the router table
98      *
99      * Hook for RouterInitialized event.
100      *
101      * @param Mapper $m URL parser and mapper
102      *
103      * @return boolean hook return
104      */
105     function onRouterInitialized(URLMapper $m)
106     {
107         $m->connect('/main/rsscloud/request_notify',
108                     array('action' => 'RSSCloudRequestNotify'));
109
110         // XXX: This is just for end-to-end testing. Uncomment if you need to pretend
111         //      to be a cloud hub for some reason.
112         //$m->connect('/main/rsscloud/notify',
113         //            array('action' => 'LoggingAggregator'));
114
115         return true;
116     }
117
118     /**
119      * Add a <cloud> element to the RSS feed (after the rss <channel>
120      * element is started).
121      *
122      * @param Action $action the ApiAction
123      *
124      * @return void
125      */
126     function onStartApiRss($action)
127     {
128         if (get_class($action) == 'ApiTimelineUserAction') {
129
130             $attrs = array('domain'            => $this->domain,
131                            'port'              => $this->port,
132                            'path'              => $this->path,
133                            'registerProcedure' => $this->funct,
134                            'protocol'          => $this->protocol);
135
136             // Dipping into XMLWriter to avoid a full end element (</cloud>).
137
138             $action->xw->startElement('cloud');
139             foreach ($attrs as $name => $value) {
140                 $action->xw->writeAttribute($name, $value);
141             }
142
143             $action->xw->endElement();
144         }
145     }
146
147     /**
148      * Add an RSSCloud queue item for each notice
149      *
150      * @param Notice $notice      the notice
151      * @param array  &$transports the list of transports (queues)
152      *
153      * @return boolean hook return
154      */
155
156     function onStartEnqueueNotice(Notice $notice, array &$transports)
157     {
158         if ($notice->isLocal()) {
159             array_push($transports, 'rsscloud');
160         }
161         return true;
162     }
163
164     /**
165      * Create the rsscloud_subscription table if it's not
166      * already in the DB
167      *
168      * @return boolean hook return
169      */
170
171     function onCheckSchema()
172     {
173         $schema = Schema::get();
174         $schema->ensureTable('rsscloud_subscription',
175             array(
176                 'fields' => array(
177                     'subscribed' => array('type' => 'int', 'not null' => true),
178                     'url' => array('type' => 'varchar', 'length' => '191', 'not null' => true),
179                     'failures' => array('type' => 'int', 'not null' => true, 'default' => 0),
180                     'created' => array('type' => 'datetime', 'not null' => true),
181                     'modified' => array('type' => 'timestamp', 'not null' => true),
182                 ),
183                 'primary key' => array('subscribed', 'url'),
184             ));
185          return true;
186     }
187
188     /**
189      * Register RSSCloud notice queue handler
190      *
191      * @param QueueManager $manager
192      *
193      * @return boolean hook return
194      */
195     function onEndInitializeQueueManager(QueueManager $manager)
196     {
197         $manager->connect('rsscloud', 'RSSCloudQueueHandler');
198         return true;
199     }
200
201     function onPluginVersion(array &$versions)
202     {
203         $versions[] = array('name' => 'RSSCloud',
204                             'version' => RSSCLOUDPLUGIN_VERSION,
205                             'author' => 'Zach Copley',
206                             'homepage' => 'http://status.net/wiki/Plugin:RSSCloud',
207                             'rawdescription' =>
208                             // TRANS: Plugin description.
209                             _m('The RSSCloud plugin enables your StatusNet instance to publish ' .
210                                'real-time updates for profile RSS feeds using the ' .
211                                '<a href="http://rsscloud.org/">RSSCloud protocol</a>.'));
212
213         return true;
214     }
215 }