]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Facebook/FacebookPlugin.php
Extract out Facebook app stuff into a plugin
[quix0rs-gnu-social.git] / plugins / Facebook / FacebookPlugin.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * Plugin to add a StatusNet Facebook application
6  *
7  * PHP version 5
8  *
9  * LICENCE: This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU Affero General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU Affero General Public License for more details.
18  *
19  * You should have received a copy of the GNU Affero General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  *
22  * @category  Plugin
23  * @package   StatusNet
24  * @author    Zach Copley <zach@status.net>
25  * @copyright 2009 StatusNet, Inc.
26  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27  * @link      http://status.net/
28  */
29
30 if (!defined('STATUSNET')) {
31     exit(1);
32 }
33
34 /**
35  * Facebook plugin to add a StatusNet Facebook application
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://status.net/
42  */
43
44 class FacebookPlugin extends Plugin
45 {
46
47     /**
48      * Add Facebook app actions to the router table
49      *
50      * Hook for RouterInitialized event.
51      *
52      * @param Net_URL_Mapper &$m path-to-action mapper
53      *
54      * @return boolean hook return
55      */
56
57     function onRouterInitialized(&$m)
58     {
59         $m->connect('facebook', array('action' => 'facebookhome'));
60         $m->connect('facebook/index.php', array('action' => 'facebookhome'));
61         $m->connect('facebook/settings.php', array('action' => 'facebooksettings'));
62         $m->connect('facebook/invite.php', array('action' => 'facebookinvite'));
63         $m->connect('facebook/remove', array('action' => 'facebookremove'));
64
65         return true;
66     }
67
68     /**
69      * Automatically load the actions and libraries used by the Facebook app
70      *
71      * @param Class $cls the class
72      *
73      * @return boolean hook return
74      *
75      */
76     function onAutoload($cls)
77     {
78         switch ($cls) {
79         case 'FacebookAction':
80         case 'FacebookhomeAction':
81         case 'FacebookinviteAction':
82         case 'FacebookremoveAction':
83         case 'FacebooksettingsAction':
84             include_once INSTALLDIR . '/plugins/Facebook/' .
85               strtolower(mb_substr($cls, 0, -6)) . '.php';
86             return false;
87         default:
88             return true;
89         }
90     }
91
92     /**
93      * Add a Facebook queue item for each notice
94      *
95      * @param Notice $notice      the notice
96      * @param array  &$transports the list of transports (queues)
97      *
98      * @return boolean hook return
99      */
100     function onStartEnqueueNotice($notice, &$transports)
101     {
102         array_push($transports, 'facebook');
103         return true;
104     }
105
106     /**
107      * broadcast the message when not using queuehandler
108      *
109      * @param Notice &$notice the notice
110      * @param array  $queue   destination queue
111      *
112      * @return boolean hook return
113      */
114     function onUnqueueHandleNotice(&$notice, $queue)
115     {
116         if (($queue == 'facebook') && ($this->_isLocal($notice))) {
117             facebookBroadcastNotice($notice);
118             return false;
119         }
120         return true;
121     }
122
123     /**
124      * Determine whether the notice was locally created
125      *
126      * @param Notice $notice
127      *
128      * @return boolean locality
129      */
130     function _isLocal($notice)
131     {
132         return ($notice->is_local == Notice::LOCAL_PUBLIC ||
133                 $notice->is_local == Notice::LOCAL_NONPUBLIC);
134     }
135
136     /**
137      * Add Facebook queuehandler to the list of daemons to start
138      *
139      * @param array $daemons the list fo daemons to run
140      *
141      * @return boolean hook return
142      *
143      */
144     function onGetValidDaemons($daemons)
145     {
146         array_push($daemons, INSTALLDIR .
147                    '/plugins/Facebook/facebookqueuehandler.php');
148         return true;
149     }
150
151 }