]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/TwitterBridge/TwitterBridgePlugin.php
some formatting changes to make inblobs work
[quix0rs-gnu-social.git] / plugins / TwitterBridge / TwitterBridgePlugin.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * PHP version 5
6  *
7  * LICENCE: This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Affero General Public License for more details.
16  *
17  * You should have received a copy of the GNU Affero General Public License
18  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
19  *
20  * @category  Plugin
21  * @package   StatusNet
22  * @author    Zach Copley <zach@status.net>
23  * @copyright 2009 Control Yourself, Inc.
24  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
25  * @link      http://laconi.ca/
26  */
27
28 if (!defined('STATUSNET')) {
29     exit(1);
30 }
31
32 require_once INSTALLDIR . '/plugins/TwitterBridge/twitter.php';
33
34 /**
35  * Plugin for sending and importing Twitter statuses
36  *
37  * This class allows users to link their Twitter accounts
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://laconi.ca/
44  * @link     http://twitter.com/
45  */
46
47 class TwitterBridgePlugin extends Plugin
48 {
49     /**
50      * Initializer for the plugin.
51      */
52
53     function __construct()
54     {
55         parent::__construct();
56     }
57
58     /**
59      * Add Twitter-related paths to the router table
60      *
61      * Hook for RouterInitialized event.
62      *
63      * @param Net_URL_Mapper $m path-to-action mapper
64      *
65      * @return boolean hook return
66      */
67
68     function onRouterInitialized($m)
69     {
70         $m->connect('twitter/authorization',
71                     array('action' => 'twitterauthorization'));
72         $m->connect('settings/twitter', array('action' => 'twittersettings'));
73
74         return true;
75     }
76
77     /**
78      * Add the Twitter Settings page to the Connect Settings menu
79      *
80      * @param Action &$action The calling page
81      *
82      * @return boolean hook return
83      */
84     function onEndConnectSettingsNav(&$action)
85     {
86         $action_name = $action->trimmed('action');
87
88         $action->menuItem(common_local_url('twittersettings'),
89                           _m('Twitter'),
90                           _m('Twitter integration options'),
91                           $action_name === 'twittersettings');
92
93         return true;
94     }
95
96     /**
97      * Automatically load the actions and libraries used by the Twitter bridge
98      *
99      * @param Class $cls the class
100      *
101      * @return boolean hook return
102      *
103      */
104     function onAutoload($cls)
105     {
106         switch ($cls) {
107         case 'TwittersettingsAction':
108         case 'TwitterauthorizationAction':
109             include_once INSTALLDIR . '/plugins/TwitterBridge/' .
110               strtolower(mb_substr($cls, 0, -6)) . '.php';
111             return false;
112         case 'TwitterOAuthClient':
113             include_once INSTALLDIR . '/plugins/TwitterBridge/twitteroauthclient.php';
114             return false;
115         default:
116             return true;
117         }
118     }
119
120     /**
121      * Add a Twitter queue item for each notice
122      *
123      * @param Notice $notice      the notice
124      * @param array  &$transports the list of transports (queues)
125      *
126      * @return boolean hook return
127      */
128     function onStartEnqueueNotice($notice, &$transports)
129     {
130         // Avoid a possible loop
131
132         if ($notice->source != 'twitter') {
133             array_push($transports, 'twitter');
134         }
135
136         return true;
137     }
138
139     /**
140      * broadcast the message when not using queuehandler
141      *
142      * @param Notice &$notice the notice
143      * @param array  $queue   destination queue
144      *
145      * @return boolean hook return
146      */
147     function onUnqueueHandleNotice(&$notice, $queue)
148     {
149         if (($queue == 'twitter') && ($this->_isLocal($notice))) {
150             broadcast_twitter($notice);
151             return false;
152         }
153         return true;
154     }
155
156     /**
157      * Determine whether the notice was locally created
158      *
159      * @param Notice $notice
160      *
161      * @return boolean locality
162      */
163     function _isLocal($notice)
164     {
165         return ($notice->is_local == Notice::LOCAL_PUBLIC ||
166                 $notice->is_local == Notice::LOCAL_NONPUBLIC);
167     }
168
169     /**
170      * Add Twitter bridge daemons to the list of daemons to start
171      *
172      * @param array $daemons the list fo daemons to run
173      *
174      * @return boolean hook return
175      *
176      */
177     function onGetValidDaemons($daemons)
178     {
179         array_push($daemons, INSTALLDIR .
180                    '/plugins/TwitterBridge/daemons/twitterqueuehandler.php');
181         array_push($daemons, INSTALLDIR .
182                    '/plugins/TwitterBridge/daemons/synctwitterfriends.php');
183
184         if (common_config('twitterimport', 'enabled')) {
185             array_push($daemons, INSTALLDIR
186                 . '/plugins/TwitterBridge/daemons/twitterstatusfetcher.php');
187         }
188
189         return true;
190     }
191
192 }