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';
34 define('TWITTERBRIDGEPLUGIN_VERSION', '0.9');
37 * Plugin for sending and importing Twitter statuses
39 * This class allows users to link their Twitter accounts
43 * @author Zach Copley <zach@status.net>
44 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
45 * @link http://laconi.ca/
46 * @link http://twitter.com/
49 class TwitterBridgePlugin extends Plugin
52 * Initializer for the plugin.
55 function __construct()
57 parent::__construct();
61 * Add Twitter-related paths to the router table
63 * Hook for RouterInitialized event.
65 * @param Net_URL_Mapper $m path-to-action mapper
67 * @return boolean hook return
70 function onRouterInitialized($m)
72 $m->connect('twitter/authorization',
73 array('action' => 'twitterauthorization'));
74 $m->connect('settings/twitter', array('action' => 'twittersettings'));
80 * Add the Twitter Settings page to the Connect Settings menu
82 * @param Action &$action The calling page
84 * @return boolean hook return
86 function onEndConnectSettingsNav(&$action)
88 $action_name = $action->trimmed('action');
90 $action->menuItem(common_local_url('twittersettings'),
92 _m('Twitter integration options'),
93 $action_name === 'twittersettings');
99 * Automatically load the actions and libraries used by the Twitter bridge
101 * @param Class $cls the class
103 * @return boolean hook return
106 function onAutoload($cls)
109 case 'TwittersettingsAction':
110 case 'TwitterauthorizationAction':
111 include_once INSTALLDIR . '/plugins/TwitterBridge/' .
112 strtolower(mb_substr($cls, 0, -6)) . '.php';
114 case 'TwitterOAuthClient':
115 include_once INSTALLDIR . '/plugins/TwitterBridge/twitteroauthclient.php';
123 * Add a Twitter queue item for each notice
125 * @param Notice $notice the notice
126 * @param array &$transports the list of transports (queues)
128 * @return boolean hook return
130 function onStartEnqueueNotice($notice, &$transports)
132 // Avoid a possible loop
134 if ($notice->source != 'twitter') {
135 array_push($transports, 'twitter');
142 * broadcast the message when not using queuehandler
144 * @param Notice &$notice the notice
145 * @param array $queue destination queue
147 * @return boolean hook return
149 function onUnqueueHandleNotice(&$notice, $queue)
151 if (($queue == 'twitter') && ($this->_isLocal($notice))) {
152 broadcast_twitter($notice);
159 * Determine whether the notice was locally created
161 * @param Notice $notice
163 * @return boolean locality
165 function _isLocal($notice)
167 return ($notice->is_local == Notice::LOCAL_PUBLIC ||
168 $notice->is_local == Notice::LOCAL_NONPUBLIC);
172 * Add Twitter bridge daemons to the list of daemons to start
174 * @param array $daemons the list fo daemons to run
176 * @return boolean hook return
179 function onGetValidDaemons($daemons)
181 array_push($daemons, INSTALLDIR .
182 '/plugins/TwitterBridge/daemons/twitterqueuehandler.php');
183 array_push($daemons, INSTALLDIR .
184 '/plugins/TwitterBridge/daemons/synctwitterfriends.php');
186 if (common_config('twitterimport', 'enabled')) {
187 array_push($daemons, INSTALLDIR
188 . '/plugins/TwitterBridge/daemons/twitterstatusfetcher.php');
194 function onPluginVersion(&$versions)
196 $versions[] = array('name' => 'TwitterBridge',
197 'version' => TWITTERBRIDGEPLUGIN_VERSION,
198 'author' => 'Zach Copley',
199 'homepage' => 'http://status.net/wiki/Plugin:TwitterBridge',
201 _m('The Twitter "bridge" plugin allows you to integrate ' .
202 'your StatusNet instance with ' .
203 '<a href="http://twitter.com/">Twitter</a>.'));