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://laconi.ca/
29 if (!defined('STATUSNET')) {
33 require_once INSTALLDIR . '/plugins/TwitterBridge/twitter.php';
35 define('TWITTERBRIDGEPLUGIN_VERSION', '0.9');
38 * Plugin for sending and importing Twitter statuses
40 * This class allows users to link their Twitter accounts
44 * @author Zach Copley <zach@status.net>
45 * @author Julien C <chaumond@gmail.com>
46 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
47 * @link http://laconi.ca/
48 * @link http://twitter.com/
51 class TwitterBridgePlugin extends Plugin
54 * Initializer for the plugin.
57 function __construct()
59 parent::__construct();
63 * Add Twitter-related paths to the router table
65 * Hook for RouterInitialized event.
67 * @param Net_URL_Mapper $m path-to-action mapper
69 * @return boolean hook return
72 function onRouterInitialized($m)
74 $m->connect('twitter/authorization',
75 array('action' => 'twitterauthorization'));
76 $m->connect('settings/twitter', array('action' => 'twittersettings'));
77 $m->connect('main/twitterlogin', array('action' => 'twitterlogin'));
83 * Add a login tab for 'Sign in with Twitter'
85 * @param Action &action the current action
89 function onEndLoginGroupNav(&$action)
92 $action_name = $action->trimmed('action');
94 $action->menuItem(common_local_url('twitterlogin'),
96 _('Login or register using Twitter'),
97 'twitterlogin' === $action_name);
103 * Add the Twitter Settings page to the Connect Settings menu
105 * @param Action &$action The calling page
107 * @return boolean hook return
109 function onEndConnectSettingsNav(&$action)
111 $action_name = $action->trimmed('action');
113 $action->menuItem(common_local_url('twittersettings'),
115 _m('Twitter integration options'),
116 $action_name === 'twittersettings');
122 * Automatically load the actions and libraries used by the Twitter bridge
124 * @param Class $cls the class
126 * @return boolean hook return
129 function onAutoload($cls)
132 case 'TwittersettingsAction':
133 case 'TwitterauthorizationAction':
134 case 'TwitterloginAction':
135 include_once INSTALLDIR . '/plugins/TwitterBridge/' .
136 strtolower(mb_substr($cls, 0, -6)) . '.php';
138 case 'TwitterOAuthClient':
139 case 'TwitterQueueHandler':
140 include_once INSTALLDIR . '/plugins/TwitterBridge/' .
141 strtolower($cls) . '.php';
149 * Add a Twitter queue item for each notice
151 * @param Notice $notice the notice
152 * @param array &$transports the list of transports (queues)
154 * @return boolean hook return
156 function onStartEnqueueNotice($notice, &$transports)
158 // Avoid a possible loop
160 if ($notice->source != 'twitter') {
161 array_push($transports, 'twitter');
168 * Add Twitter bridge daemons to the list of daemons to start
170 * @param array $daemons the list fo daemons to run
172 * @return boolean hook return
174 function onGetValidDaemons($daemons)
176 array_push($daemons, INSTALLDIR .
177 '/plugins/TwitterBridge/daemons/synctwitterfriends.php');
179 if (common_config('twitterimport', 'enabled')) {
180 array_push($daemons, INSTALLDIR
181 . '/plugins/TwitterBridge/daemons/twitterstatusfetcher.php');
188 * Register Twitter notice queue handler
190 * @param QueueManager $manager
192 * @return boolean hook return
194 function onEndInitializeQueueManager($manager)
196 $manager->connect('twitter', 'TwitterQueueHandler');
200 function onPluginVersion(&$versions)
202 $versions[] = array('name' => 'TwitterBridge',
203 'version' => TWITTERBRIDGEPLUGIN_VERSION,
204 'author' => 'Zach Copley',
205 'homepage' => 'http://status.net/wiki/Plugin:TwitterBridge',
207 _m('The Twitter "bridge" plugin allows you to integrate ' .
208 'your StatusNet instance with ' .
209 '<a href="http://twitter.com/">Twitter</a>.'));