3 * StatusNet, the distributed open-source microblogging tool
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.
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.
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/>.
22 * @author Zach Copley <zach@status.net>
23 * @author Julien C <chaumond@gmail.com>
24 * @copyright 2009-2010 Control Yourself, Inc.
25 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
26 * @link http://status.net/
29 if (!defined('STATUSNET')) {
33 require_once INSTALLDIR . '/plugins/TwitterBridge/twitter.php';
36 * Plugin for sending and importing Twitter statuses
38 * This class allows users to link their Twitter accounts
42 * @author Zach Copley <zach@status.net>
43 * @author Julien C <chaumond@gmail.com>
44 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
45 * @link http://status.net/
46 * @link http://twitter.com/
49 class TwitterBridgePlugin extends Plugin
52 const VERSION = STATUSNET_VERSION;
55 * Initializer for the plugin.
60 // Allow the key and secret to be passed in
61 // Control panel will override
63 if (isset($this->consumer_key)) {
64 $key = common_config('twitter', 'consumer_key');
66 Config::save('twitter', 'consumer_key', $this->consumer_key);
70 if (isset($this->consumer_secret)) {
71 $secret = common_config('twitter', 'consumer_secret');
76 $this->consumer_secret
83 * Check to see if there is a consumer key and secret defined
84 * for Twitter integration.
86 * @return boolean result
89 static function hasKeys()
91 $ckey = common_config('twitter', 'consumer_key');
92 $csecret = common_config('twitter', 'consumer_secret');
94 if (empty($ckey) && empty($csecret)) {
95 $ckey = common_config('twitter', 'global_consumer_key');
96 $csecret = common_config('twitter', 'global_consumer_secret');
99 if (!empty($ckey) && !empty($csecret)) {
107 * Add Twitter-related paths to the router table
109 * Hook for RouterInitialized event.
111 * @param Net_URL_Mapper $m path-to-action mapper
113 * @return boolean hook return
116 function onRouterInitialized($m)
118 $m->connect('admin/twitter', array('action' => 'twitteradminpanel'));
120 if (self::hasKeys()) {
122 'twitter/authorization',
123 array('action' => 'twitterauthorization')
126 'settings/twitter', array(
127 'action' => 'twittersettings'
130 if (common_config('twitter', 'signin')) {
133 array('action' => 'twitterlogin')
142 * Add a login tab for 'Sign in with Twitter'
144 * @param Action &action the current action
148 function onEndLoginGroupNav(&$action)
150 $action_name = $action->trimmed('action');
152 if (self::hasKeys() && common_config('twitter', 'signin')) {
154 common_local_url('twitterlogin'),
156 _m('Login or register using Twitter'),
157 'twitterlogin' === $action_name
165 * Add the Twitter Settings page to the Connect Settings menu
167 * @param Action &$action The calling page
169 * @return boolean hook return
171 function onEndConnectSettingsNav(&$action)
173 if (self::hasKeys()) {
174 $action_name = $action->trimmed('action');
177 common_local_url('twittersettings'),
179 _m('Twitter integration options'),
180 $action_name === 'twittersettings'
187 * Automatically load the actions and libraries used by the Twitter bridge
189 * @param Class $cls the class
191 * @return boolean hook return
194 function onAutoload($cls)
197 case 'TwittersettingsAction':
198 case 'TwitterauthorizationAction':
199 case 'TwitterloginAction':
200 case 'TwitteradminpanelAction':
201 include_once INSTALLDIR . '/plugins/TwitterBridge/' .
202 strtolower(mb_substr($cls, 0, -6)) . '.php';
204 case 'TwitterOAuthClient':
205 case 'TwitterQueueHandler':
206 include_once INSTALLDIR . '/plugins/TwitterBridge/' .
207 strtolower($cls) . '.php';
215 * Add a Twitter queue item for each notice
217 * @param Notice $notice the notice
218 * @param array &$transports the list of transports (queues)
220 * @return boolean hook return
222 function onStartEnqueueNotice($notice, &$transports)
224 if (self::hasKeys() && $notice->isLocal()) {
225 // Avoid a possible loop
226 if ($notice->source != 'twitter') {
227 array_push($transports, 'twitter');
234 * Add Twitter bridge daemons to the list of daemons to start
236 * @param array $daemons the list fo daemons to run
238 * @return boolean hook return
240 function onGetValidDaemons($daemons)
242 if (self::hasKeys()) {
246 . '/plugins/TwitterBridge/daemons/synctwitterfriends.php'
248 if (common_config('twitterimport', 'enabled')) {
252 . '/plugins/TwitterBridge/daemons/twitterstatusfetcher.php'
261 * Register Twitter notice queue handler
263 * @param QueueManager $manager
265 * @return boolean hook return
267 function onEndInitializeQueueManager($manager)
269 if (self::hasKeys()) {
270 $manager->connect('twitter', 'TwitterQueueHandler');
276 * Add a Twitter tab to the admin panel
278 * @param Widget $nav Admin panel nav
280 * @return boolean hook value
283 function onEndAdminPanelNav($nav)
285 if (AdminPanelAction::canAdmin('twitter')) {
287 $action_name = $nav->action->trimmed('action');
290 common_local_url('twitteradminpanel'),
292 _m('Twitter bridge configuration'),
293 $action_name == 'twitteradminpanel',
294 'nav_twitter_admin_panel'
302 * Plugin version data
304 * @param array &$versions array of version blocks
306 * @return boolean hook value
309 function onPluginVersion(&$versions)
312 'name' => 'TwitterBridge',
313 'version' => self::VERSION,
314 'author' => 'Zach Copley, Julien C',
315 'homepage' => 'http://status.net/wiki/Plugin:TwitterBridge',
316 'rawdescription' => _m(
317 'The Twitter "bridge" plugin allows you to integrate ' .
318 'your StatusNet instance with ' .
319 '<a href="http://twitter.com/">Twitter</a>.'