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