]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/TwitterBridge/TwitterBridgePlugin.php
Changed config flag for importing friends' timeline and added some 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  * @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 /**
33  * Plugin for sending and importing Twitter statuses
34  *
35  * This class allows users to link their Twitter accounts
36  *
37  * @category Plugin
38  * @package  StatusNet
39  * @author   Zach Copley <zach@status.net>
40  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
41  * @link     http://laconi.ca/
42  * @link     http://twitter.com/
43  */
44
45 class TwitterBridgePlugin extends Plugin
46 {
47     /**
48      * Initializer for the plugin.
49      */
50
51     function __construct()
52     {
53         parent::__construct();
54     }
55
56     /**
57      * Add Twitter-related paths to the router table
58      *
59      * Hook for RouterInitialized event.
60      *
61      * @param Net_URL_Mapper &$m path-to-action mapper
62      *
63      * @return boolean hook return
64      */
65
66     function onRouterInitialized(&$m)
67     {
68         $m->connect('twitter/authorization',
69                     array('action' => 'twitterauthorization'));
70         $m->connect('settings/twitter', array('action' => 'twittersettings'));
71
72         return true;
73     }
74
75     /**
76      * Add the Twitter Settings page to the Connect Settings menu
77      *
78      * @param Action &$action The calling page
79      *
80      * @return boolean hook return
81      */
82     function onEndConnectSettingsNav(&$action)
83     {
84         $action_name = $action->trimmed('action');
85
86         $action->menuItem(common_local_url('twittersettings'),
87                           _('Twitter'),
88                           _('Twitter integration options'),
89                           $action_name === 'twittersettings');
90
91         return true;
92     }
93
94     /**
95      * Automatically load the actions and libraries used by the Twitter bridge
96      *
97      * @param Class $cls the class
98      *
99      * @return boolean hook return
100      *
101      */
102     function onAutoload($cls)
103     {
104         switch ($cls) {
105         case 'TwittersettingsAction':
106         case 'TwitterauthorizationAction':
107             include_once INSTALLDIR.'/plugins/TwitterBridge/' .
108               strtolower(mb_substr($cls, 0, -6)) . '.php';
109             return false;
110         case 'TwitterOAuthClient':
111             include_once INSTALLDIR.'/plugins/TwitterBridge/twitteroauthclient.php';
112             return false;
113         default:
114             return true;
115         }
116     }
117
118     /**
119      * Add a Twitter queue item for each notice
120      *
121      * @param Notice $notice     the notice
122      * @param array  $transports the list of transports (queues)
123      *
124      * @return boolean hook return
125      */
126     function onStartEnqueueNotice($notice, $transports)
127     {
128         array_push($transports, 'twitter');
129         return true;
130     }
131
132     /**
133      * Add Twitter bridge daemons to the list of daemons to start
134      *
135      * @param array $daemons the list fo daemons to run
136      *
137      * @return boolean hook return
138      *
139      */
140     function onGetValidDaemons($daemons)
141     {
142         array_push($daemons, INSTALLDIR .
143                    '/plugins/TwitterBridge/daemons/twitterqueuehandler.php');
144         array_push($daemons, INSTALLDIR .
145                    '/plugins/TwitterBridge/daemons/synctwitterfriends.php');
146
147         if (common_config('twitterimport', 'enabled')) {
148             array_push($daemons, INSTALLDIR
149                 . '/plugins/TwitterBridge/daemons/twitterstatusfetcher.php');
150         }
151
152         return true;
153     }
154
155 }