]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/TwitterBridge/TwitterBridgePlugin.php
Merge branch '0.9.x-mobile' into 0.9.x
[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 /**
35  * Plugin for sending and importing Twitter statuses
36  *
37  * This class allows users to link their Twitter accounts
38  *
39  * @category Plugin
40  * @package  StatusNet
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/
45  */
46
47 class TwitterBridgePlugin extends Plugin
48 {
49     /**
50      * Initializer for the plugin.
51      */
52
53     function __construct()
54     {
55         parent::__construct();
56     }
57
58     /**
59      * Add Twitter-related paths to the router table
60      *
61      * Hook for RouterInitialized event.
62      *
63      * @param Net_URL_Mapper $m path-to-action mapper
64      *
65      * @return boolean hook return
66      */
67
68     function onRouterInitialized($m)
69     {
70         $m->connect('twitter/authorization',
71                     array('action' => 'twitterauthorization'));
72         $m->connect('settings/twitter', array('action' => 'twittersettings'));
73
74         return true;
75     }
76
77     /**
78      * Add the Twitter Settings page to the Connect Settings menu
79      *
80      * @param Action &$action The calling page
81      *
82      * @return boolean hook return
83      */
84     function onEndConnectSettingsNav(&$action)
85     {
86         $action_name = $action->trimmed('action');
87
88         $action->menuItem(common_local_url('twittersettings'),
89                           _('Twitter'),
90                           _('Twitter integration options'),
91                           $action_name === 'twittersettings');
92
93         return true;
94     }
95
96     /**
97      * Automatically load the actions and libraries used by the Twitter bridge
98      *
99      * @param Class $cls the class
100      *
101      * @return boolean hook return
102      *
103      */
104     function onAutoload($cls)
105     {
106         switch ($cls) {
107         case 'TwittersettingsAction':
108         case 'TwitterauthorizationAction':
109             include_once INSTALLDIR . '/plugins/TwitterBridge/' .
110               strtolower(mb_substr($cls, 0, -6)) . '.php';
111             return false;
112         case 'TwitterOAuthClient':
113             include_once INSTALLDIR . '/plugins/TwitterBridge/twitteroauthclient.php';
114             return false;
115         default:
116             return true;
117         }
118     }
119
120     /**
121      * Add a Twitter queue item for each notice
122      *
123      * @param Notice $notice      the notice
124      * @param array  &$transports the list of transports (queues)
125      *
126      * @return boolean hook return
127      */
128     function onStartEnqueueNotice($notice, &$transports)
129     {
130         array_push($transports, 'twitter');
131         return true;
132     }
133
134     /**
135      * broadcast the message when not using queuehandler
136      *
137      * @param Notice &$notice the notice
138      * @param array  $queue   destination queue
139      *
140      * @return boolean hook return
141      */
142     function onUnqueueHandleNotice(&$notice, $queue)
143     {
144         if (($queue == 'twitter') && ($this->_isLocal($notice))) {
145             broadcast_twitter($notice);
146             return false;
147         }
148         return true;
149     }
150
151     /**
152      * Determine whether the notice was locally created
153      *
154      * @param Notice $notice
155      *
156      * @return boolean locality
157      */
158     function _isLocal($notice)
159     {
160         return ($notice->is_local == Notice::LOCAL_PUBLIC ||
161                 $notice->is_local == Notice::LOCAL_NONPUBLIC);
162     }
163
164     /**
165      * Add Twitter bridge daemons to the list of daemons to start
166      *
167      * @param array $daemons the list fo daemons to run
168      *
169      * @return boolean hook return
170      *
171      */
172     function onGetValidDaemons($daemons)
173     {
174         array_push($daemons, INSTALLDIR .
175                    '/plugins/TwitterBridge/daemons/twitterqueuehandler.php');
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 }