]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/RSSCloud/RSSCloudPlugin.php
a86c153f14ff3d4ed62472a1eae81560459b94d6
[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 class RSSCloudPlugin extends Plugin
37 {
38     function __construct()
39     {
40         parent::__construct();
41     }
42
43     function onInitializePlugin()
44     {
45         $this->domain   = common_config('rsscloud', 'domain');
46         $this->port     = common_config('rsscloud', 'port');
47         $this->path     = common_config('rsscloud', 'path');
48         $this->funct    = common_config('rsscloud', 'function');
49         $this->protocol = common_config('rsscloud', 'protocol');
50
51         // set defaults
52
53         $local_server = parse_url(common_path('rsscloud/request_notify'));
54
55         if (empty($this->domain)) {
56             $this->domain = $local_server['host'];
57         }
58
59         if (empty($this->port)) {
60             $this->port = '80';
61         }
62
63         if (empty($this->path)) {
64             $this->path = '/rsscloud/request_notify';
65         }
66
67         if (empty($this->funct)) {
68             $this->funct = '';
69         }
70
71         if (empty($this->protocol)) {
72             $this->protocol = 'http-post';
73         }
74     }
75
76     /**
77      * Add RSSCloud-related paths to the router table
78      *
79      * Hook for RouterInitialized event.
80      *
81      * @return boolean hook return
82      */
83
84     function onRouterInitialized(&$m)
85     {
86         $m->connect('rsscloud/request_notify', array('action' => 'RSSCloudRequestNotify'));
87
88         // XXX: This is just for end-to-end testing
89         $m->connect('rsscloud/notify', array('action' => 'LoggingAggregator'));
90
91         return true;
92     }
93
94     function onAutoload($cls)
95     {
96         switch ($cls)
97         {
98
99          case 'RSSCloudNotifier':
100             require_once(INSTALLDIR . '/plugins/RSSCloud/RSSCloudNotifier.php');
101             return false;
102          case 'RSSCloudRequestNotifyAction':
103          case 'LoggingAggregatorAction':
104             common_debug(mb_substr($cls, 0, -6) . '.php');
105             require_once(INSTALLDIR . '/plugins/RSSCloud/' . mb_substr($cls, 0, -6) . '.php');
106             return false;
107          default:
108             return true;
109         }
110     }
111
112     function onStartApiRss($action){
113
114         if (get_class($action) == 'ApiTimelineUserAction') {
115
116             $attrs = array('domain'            => $this->domain,
117                            'port'              => $this->port,
118                            'path'              => $this->path,
119                            'registerProcedure' => $this->funct,
120                            'protocol'          => $this->protocol);
121
122             // Dipping into XMLWriter to avoid a full end element (</cloud>).
123
124             $action->xw->startElement('cloud');
125             foreach ($attrs as $name => $value) {
126                 $action->xw->writeAttribute($name, $value);
127             }
128             $action->xw->endElement();
129
130         }
131     }
132
133     function onEndNoticeSave($notice){
134
135         common_debug("RSSCloudPlugin oneEndNoticeSave()");
136
137         $user = User::staticGet('id', $notice->profile_id);
138         $feed  = common_local_url('api', array('apiaction' => 'statuses',
139                                               'method'    => 'user_timeline',
140                                               'argument'  => $user->nickname . '.rss'));
141
142         // XXX: Dave's hub for testing
143         // $endpoint = 'http://rpc.rsscloud.org:5337/rsscloud/ping';
144
145         // $notifier = new RSSCloudNotifier();
146         // $notifier->postUpdate($endpoint, $feed);
147     }
148
149 }
150