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 * @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/
28 if (!defined('STATUSNET')) {
32 require_once INSTALLDIR . '/plugins/TwitterBridge/twitter.php';
35 * Plugin for sending and importing Twitter statuses
37 * This class allows users to link their Twitter accounts
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/
47 class TwitterBridgePlugin extends Plugin
50 * Initializer for the plugin.
53 function __construct()
55 parent::__construct();
59 * Add Twitter-related paths to the router table
61 * Hook for RouterInitialized event.
63 * @param Net_URL_Mapper $m path-to-action mapper
65 * @return boolean hook return
68 function onRouterInitialized($m)
70 $m->connect('twitter/authorization',
71 array('action' => 'twitterauthorization'));
72 $m->connect('settings/twitter', array('action' => 'twittersettings'));
78 * Add the Twitter Settings page to the Connect Settings menu
80 * @param Action &$action The calling page
82 * @return boolean hook return
84 function onEndConnectSettingsNav(&$action)
86 $action_name = $action->trimmed('action');
88 $action->menuItem(common_local_url('twittersettings'),
90 _m('Twitter integration options'),
91 $action_name === 'twittersettings');
97 * Automatically load the actions and libraries used by the Twitter bridge
99 * @param Class $cls the class
101 * @return boolean hook return
104 function onAutoload($cls)
107 case 'TwittersettingsAction':
108 case 'TwitterauthorizationAction':
109 include_once INSTALLDIR . '/plugins/TwitterBridge/' .
110 strtolower(mb_substr($cls, 0, -6)) . '.php';
112 case 'TwitterOAuthClient':
113 include_once INSTALLDIR . '/plugins/TwitterBridge/twitteroauthclient.php';
121 * Add a Twitter queue item for each notice
123 * @param Notice $notice the notice
124 * @param array &$transports the list of transports (queues)
126 * @return boolean hook return
128 function onStartEnqueueNotice($notice, &$transports)
130 // Avoid a possible loop
132 if ($notice->source != 'twitter') {
133 array_push($transports, 'twitter');
140 * broadcast the message when not using queuehandler
142 * @param Notice &$notice the notice
143 * @param array $queue destination queue
145 * @return boolean hook return
147 function onUnqueueHandleNotice(&$notice, $queue)
149 if (($queue == 'twitter') && ($this->_isLocal($notice))) {
150 broadcast_twitter($notice);
157 * Determine whether the notice was locally created
159 * @param Notice $notice
161 * @return boolean locality
163 function _isLocal($notice)
165 return ($notice->is_local == Notice::LOCAL_PUBLIC ||
166 $notice->is_local == Notice::LOCAL_NONPUBLIC);
170 * Add Twitter bridge daemons to the list of daemons to start
172 * @param array $daemons the list fo daemons to run
174 * @return boolean hook return
177 function onGetValidDaemons($daemons)
179 array_push($daemons, INSTALLDIR .
180 '/plugins/TwitterBridge/daemons/twitterqueuehandler.php');
181 array_push($daemons, INSTALLDIR .
182 '/plugins/TwitterBridge/daemons/synctwitterfriends.php');
184 if (common_config('twitterimport', 'enabled')) {
185 array_push($daemons, INSTALLDIR
186 . '/plugins/TwitterBridge/daemons/twitterstatusfetcher.php');