]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/TwitterBridge/TwitterBridgePlugin.php
- Twitter username wasn't getting stored in Foreign_user when linking Twitter account...
[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 define('TWITTERBRIDGEPLUGIN_VERSION', '0.9');
35
36 /**
37  * Plugin for sending and importing Twitter statuses
38  *
39  * This class allows users to link their Twitter accounts
40  *
41  * @category Plugin
42  * @package  StatusNet
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/
47  */
48
49 class TwitterBridgePlugin extends Plugin
50 {
51     /**
52      * Initializer for the plugin.
53      */
54
55     function __construct()
56     {
57         parent::__construct();
58     }
59
60     /**
61      * Add Twitter-related paths to the router table
62      *
63      * Hook for RouterInitialized event.
64      *
65      * @param Net_URL_Mapper $m path-to-action mapper
66      *
67      * @return boolean hook return
68      */
69
70     function onRouterInitialized($m)
71     {
72         $m->connect('twitter/authorization',
73                     array('action' => 'twitterauthorization'));
74         $m->connect('settings/twitter', array('action' => 'twittersettings'));
75         
76         $m->connect('main/twitterlogin', array('action' => 'twitterlogin'));
77
78         return true;
79     }
80     
81     
82     
83     /*
84      * Add a login tab for Twitter Connect
85      *
86      * @param Action &action the current action
87      *
88      * @return void
89      */
90     function onEndLoginGroupNav(&$action)
91     {
92
93         $action_name = $action->trimmed('action');
94
95         $action->menuItem(common_local_url('twitterlogin'),
96                                            _('Twitter'),
97                                            _('Login or register using Twitter'),
98                                              'twitterlogin' === $action_name);
99
100         return true;
101     }
102     
103
104     /**
105      * Add the Twitter Settings page to the Connect Settings menu
106      *
107      * @param Action &$action The calling page
108      *
109      * @return boolean hook return
110      */
111     function onEndConnectSettingsNav(&$action)
112     {
113         $action_name = $action->trimmed('action');
114
115         $action->menuItem(common_local_url('twittersettings'),
116                           _m('Twitter'),
117                           _m('Twitter integration options'),
118                           $action_name === 'twittersettings');
119
120         return true;
121     }
122
123     /**
124      * Automatically load the actions and libraries used by the Twitter bridge
125      *
126      * @param Class $cls the class
127      *
128      * @return boolean hook return
129      *
130      */
131     function onAutoload($cls)
132     {
133         switch ($cls) {
134         case 'TwittersettingsAction':
135         case 'TwitterauthorizationAction':
136         case 'TwitterloginAction':
137             include_once INSTALLDIR . '/plugins/TwitterBridge/' .
138               strtolower(mb_substr($cls, 0, -6)) . '.php';
139             return false;
140         case 'TwitterOAuthClient':
141         case 'TwitterQueueHandler':
142             include_once INSTALLDIR . '/plugins/TwitterBridge/' .
143               strtolower($cls) . '.php';
144             return false;
145         default:
146             return true;
147         }
148     }
149
150     /**
151      * Add a Twitter queue item for each notice
152      *
153      * @param Notice $notice      the notice
154      * @param array  &$transports the list of transports (queues)
155      *
156      * @return boolean hook return
157      */
158     function onStartEnqueueNotice($notice, &$transports)
159     {
160         // Avoid a possible loop
161
162         if ($notice->source != 'twitter') {
163             array_push($transports, 'twitter');
164         }
165
166         return true;
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     function onGetValidDaemons($daemons)
177     {
178         array_push($daemons, INSTALLDIR .
179                    '/plugins/TwitterBridge/daemons/synctwitterfriends.php');
180
181         if (common_config('twitterimport', 'enabled')) {
182             array_push($daemons, INSTALLDIR
183                 . '/plugins/TwitterBridge/daemons/twitterstatusfetcher.php');
184         }
185
186         return true;
187     }
188
189     /**
190      * Register Twitter notice queue handler
191      *
192      * @param QueueManager $manager
193      *
194      * @return boolean hook return
195      */
196     function onEndInitializeQueueManager($manager)
197     {
198         $manager->connect('twitter', 'TwitterQueueHandler');
199         return true;
200     }
201
202     function onPluginVersion(&$versions)
203     {
204         $versions[] = array('name' => 'TwitterBridge',
205                             'version' => TWITTERBRIDGEPLUGIN_VERSION,
206                             'author' => 'Zach Copley',
207                             'homepage' => 'http://status.net/wiki/Plugin:TwitterBridge',
208                             'rawdescription' =>
209                             _m('The Twitter "bridge" plugin allows you to integrate ' .
210                                'your StatusNet instance with ' .
211                                '<a href="http://twitter.com/">Twitter</a>.'));
212         return true;
213     }
214
215 }