3 * Laconica, the distributed open-source microblogging tool
5 * Plugin to enable Facebook Connect
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.
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.
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/>.
24 * @author Zach Copley <zach@controlyourself.ca>
25 * @copyright 2009 Control Yourself, Inc.
26 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27 * @link http://laconi.ca/
30 if (!defined('LACONICA')) {
34 define("FACEBOOK_CONNECT_SERVICE", 3);
36 require_once INSTALLDIR . '/lib/facebookutil.php';
37 require_once INSTALLDIR . '/plugins/FBConnect/FBConnectAuth.php';
38 require_once INSTALLDIR . '/plugins/FBConnect/FBConnectLogin.php';
39 require_once INSTALLDIR . '/plugins/FBConnect/FBConnectSettings.php';
40 require_once INSTALLDIR . '/plugins/FBConnect/FBCLoginGroupNav.php';
41 require_once INSTALLDIR . '/plugins/FBConnect/FBCSettingsNav.php';
45 * Plugin to enable Facebook Connect
49 * @author Zach Copley <zach@controlyourself.ca>
50 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
51 * @link http://laconi.ca/
54 class FBConnectPlugin extends Plugin
57 function __construct()
59 parent::__construct();
62 // Hook in new actions
63 function onRouterInitialized(&$m) {
64 $m->connect('main/facebookconnect', array('action' => 'FBConnectAuth'));
65 $m->connect('main/facebooklogin', array('action' => 'FBConnectLogin'));
66 $m->connect('settings/facebook', array('action' => 'FBConnectSettings'));
70 function onStartShowHTML($action)
72 $httpaccept = isset($_SERVER['HTTP_ACCEPT']) ?
73 $_SERVER['HTTP_ACCEPT'] : null;
75 // XXX: allow content negotiation for RDF, RSS, or XRDS
77 $cp = common_accept_to_prefs($httpaccept);
78 $sp = common_accept_to_prefs(PAGE_TYPE_PREFS);
80 $type = common_negotiate_type($cp, $sp);
83 throw new ClientException(_('This page is not available in a '.
84 'media type you accept'), 406);
88 header('Content-Type: '.$type);
90 $action->extraHeaders();
92 $action->startXML('html',
93 '-//W3C//DTD XHTML 1.0 Strict//EN',
94 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd');
96 $language = $action->getLanguage();
98 $action->elementStart('html', array('xmlns' => 'http://www.w3.org/1999/xhtml',
99 'xmlns:fb' => 'http://www.facebook.com/2008/fbml',
100 'xml:lang' => $language,
101 'lang' => $language));
107 function onEndShowLaconicaScripts($action)
110 $action->element('script',
111 array('type' => 'text/javascript',
112 'src' => 'http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php'),
115 $apikey = common_config('facebook', 'apikey');
116 $plugin_path = common_path('plugins/FBConnect');
118 $login_url = common_local_url('FBConnectAuth');
119 $logout_url = common_local_url('logout');
121 $html = sprintf('<script type="text/javascript">FB.init("%s", "%s/xd_receiver.htm");
123 function goto_login() {
124 window.location = "%s";
127 function goto_logout() {
128 window.location = "%s";
131 </script>', $apikey, $plugin_path, $login_url, $logout_url);
137 function onStartPrimaryNav($action)
139 $user = common_current_user();
143 $flink = Foreign_link::getByUserId($user->id, FACEBOOK_CONNECT_SERVICE);
147 $facebook = getFacebook();
149 if ($facebook->api_client->users_isAppUser($flink->foreign_id) ||
150 $facebook->api_client->added) {
152 // XXX: We need to replace this with a proper mini-icon and only after
153 // checing the FB Connect JavaScript lib method to see what the Connect
154 // status is. Checking Connect status looks to be impossible with the
157 $action->elementStart('li');
158 $action->elementStart('fb:profile-pic', array('uid' => $flink->foreign_id,
159 'facebook-logo' => 'true',
163 $action->elementEnd('fb:profile-pic');
164 $action->elementEnd('li');
169 $action->menuItem(common_local_url('all', array('nickname' => $user->nickname)),
170 _('Home'), _('Personal profile and friends timeline'), false, 'nav_home');
171 $action->menuItem(common_local_url('profilesettings'),
172 _('Account'), _('Change your email, avatar, password, profile'), false, 'nav_account');
173 if (common_config('xmpp', 'enabled')) {
174 $action->menuItem(common_local_url('imsettings'),
175 _('Connect'), _('Connect to IM, SMS, Twitter'), false, 'nav_connect');
177 $action->menuItem(common_local_url('smssettings'),
178 _('Connect'), _('Connect to SMS, Twitter'), false, 'nav_connect');
180 $action->menuItem(common_local_url('invite'),
182 sprintf(_('Invite friends and colleagues to join you on %s'),
183 common_config('site', 'name')),
184 false, 'nav_invitecontact');
186 // Need to override the Logout link to make it do FB stuff
188 $logout_url = common_local_url('logout');
189 $title = _('Logout from the site');
192 $html = sprintf('<li id="nav_logout"><a href="%s" title="%s" ' .
193 'onclick="FB.Connect.logout(function() { goto_logout() })">%s</a></li>',
194 $logout_url, $title, $text);
200 if (!common_config('site', 'closed')) {
201 $action->menuItem(common_local_url('register'),
202 _('Register'), _('Create an account'), false, 'nav_register');
204 $action->menuItem(common_local_url('openidlogin'),
205 _('OpenID'), _('Login with OpenID'), false, 'nav_openid');
206 $action->menuItem(common_local_url('login'),
207 _('Login'), _('Login to the site'), false, 'nav_login');
210 $action->menuItem(common_local_url('doc', array('title' => 'help')),
211 _('Help'), _('Help me!'), false, 'nav_help');
212 $action->menuItem(common_local_url('peoplesearch'),
213 _('Search'), _('Search for people or text'), false, 'nav_search');
218 function onStartShowLocalNavBlock($action)
220 $action_name = get_class($action);
222 $login_actions = array('LoginAction', 'RegisterAction',
223 'OpenidloginAction', 'FacebookStart');
225 if (in_array($action_name, $login_actions)) {
226 $nav = new FBCLoginGroupNav($action);
231 $connect_actions = array('SmssettingsAction',
232 'TwittersettingsAction', 'FBConnectSettingsAction');
234 if (in_array($action_name, $connect_actions)) {
235 $nav = new FBCSettingsNav($action);