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';
44 * Plugin to enable Facebook Connect
48 * @author Zach Copley <zach@controlyourself.ca>
49 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
50 * @link http://laconi.ca/
53 class FBConnectPlugin extends Plugin
55 function __construct()
57 parent::__construct();
60 // Hook in new actions
61 function onRouterInitialized(&$m) {
62 $m->connect('main/facebookconnect', array('action' => 'FBConnectAuth'));
63 $m->connect('main/facebooklogin', array('action' => 'FBConnectLogin'));
64 $m->connect('settings/facebook', array('action' => 'FBConnectSettings'));
68 function onStartShowHTML($action)
70 $httpaccept = isset($_SERVER['HTTP_ACCEPT']) ?
71 $_SERVER['HTTP_ACCEPT'] : null;
73 // XXX: allow content negotiation for RDF, RSS, or XRDS
75 $cp = common_accept_to_prefs($httpaccept);
76 $sp = common_accept_to_prefs(PAGE_TYPE_PREFS);
78 $type = common_negotiate_type($cp, $sp);
81 throw new ClientException(_('This page is not available in a '.
82 'media type you accept'), 406);
85 header('Content-Type: '.$type);
87 $action->extraHeaders();
89 $action->startXML('html',
90 '-//W3C//DTD XHTML 1.0 Strict//EN',
91 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd');
93 $language = $action->getLanguage();
95 $action->elementStart('html',
96 array('xmlns' => 'http://www.w3.org/1999/xhtml',
97 'xmlns:fb' => 'http://www.facebook.com/2008/fbml',
98 'xml:lang' => $language,
99 'lang' => $language));
104 function onEndShowLaconicaScripts($action)
106 $action->element('script',
107 array('type' => 'text/javascript',
108 'src' => 'http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php'),
111 $apikey = common_config('facebook', 'apikey');
112 $plugin_path = common_path('plugins/FBConnect');
114 $login_url = common_local_url('FBConnectAuth');
115 $logout_url = common_local_url('logout');
117 $html = sprintf('<script type="text/javascript">FB.init("%s", "%s/xd_receiver.htm");
119 function goto_login() {
120 window.location = "%s";
123 function goto_logout() {
124 window.location = "%s";
127 </script>', $apikey, $plugin_path, $login_url, $logout_url);
133 function onEndShowLaconicaStyles($action)
135 $action->element('link', array('rel' => 'stylesheet',
136 'type' => 'text/css',
137 'href' => common_path('plugins/FBConnect/FBConnectPlugin.css')));
140 function onStartPrimaryNav($action)
142 $user = common_current_user();
146 $action->menuItem(common_local_url('all', array('nickname' => $user->nickname)),
147 _('Home'), _('Personal profile and friends timeline'), false, 'nav_home');
148 $action->menuItem(common_local_url('profilesettings'),
149 _('Account'), _('Change your email, avatar, password, profile'), false, 'nav_account');
150 if (common_config('xmpp', 'enabled')) {
151 $action->menuItem(common_local_url('imsettings'),
152 _('Connect'), _('Connect to IM, SMS, Twitter'), false, 'nav_connect');
154 $action->menuItem(common_local_url('smssettings'),
155 _('Connect'), _('Connect to SMS, Twitter'), false, 'nav_connect');
157 $action->menuItem(common_local_url('invite'),
159 sprintf(_('Invite friends and colleagues to join you on %s'),
160 common_config('site', 'name')),
161 false, 'nav_invitecontact');
163 $flink = Foreign_link::getByUserId($user->id, FACEBOOK_CONNECT_SERVICE);
170 $facebook = getFacebook();
171 $fbuid = getFacebook()->get_loggedin_user();
173 } catch (Exception $e) {
174 common_log(LOG_WARNING,
175 'Problem getting Facebook client: ' .
179 // Display Facebook Logged in indicator w/Facebook favicon
183 $action->elementStart('li', array('id' => 'nav_fb'));
184 $action->elementStart('fb:profile-pic', array('uid' => $flink->foreign_id,
188 $action->elementEnd('fb:profile-pic');
190 $iconurl = common_path('/plugins/FBConnect/fbfavicon.ico');
191 $action->element('img', array('src' => $iconurl));
193 $action->elementEnd('li');
198 // Need to override the Logout link to make it do FB stuff
202 $logout_url = common_local_url('logout');
203 $title = _('Logout from the site');
206 $html = sprintf('<li id="nav_logout"><a href="%s" title="%s" ' .
207 'onclick="FB.Connect.logout(function() { goto_logout() })">%s</a></li>',
208 $logout_url, $title, $text);
213 $action->menuItem(common_local_url('logout'),
214 _('Logout'), _('Logout from the site'), false, 'nav_logout');
218 if (!common_config('site', 'closed')) {
219 $action->menuItem(common_local_url('register'),
220 _('Register'), _('Create an account'), false, 'nav_register');
222 $action->menuItem(common_local_url('openidlogin'),
223 _('OpenID'), _('Login with OpenID'), false, 'nav_openid');
224 $action->menuItem(common_local_url('login'),
225 _('Login'), _('Login to the site'), false, 'nav_login');
228 $action->menuItem(common_local_url('doc', array('title' => 'help')),
229 _('Help'), _('Help me!'), false, 'nav_help');
230 $action->menuItem(common_local_url('peoplesearch'),
231 _('Search'), _('Search for people or text'), false, 'nav_search');
236 function onStartShowLocalNavBlock($action)
238 $action_name = get_class($action);
240 $login_actions = array('LoginAction', 'RegisterAction',
241 'OpenidloginAction', 'FBConnectLoginAction');
243 if (in_array($action_name, $login_actions)) {
244 $nav = new FBCLoginGroupNav($action);
249 $connect_actions = array('SmssettingsAction',
250 'TwittersettingsAction', 'FBConnectSettingsAction');
252 if (in_array($action_name, $connect_actions)) {
253 $nav = new FBCSettingsNav($action);
261 function onEndLogout($action)
265 $facebook = getFacebook();
266 $fbuid = $facebook->get_loggedin_user();
269 $facebook->logout(common_local_url('public'));
272 } catch (Exception $e) {
273 common_log(LOG_WARNING, 'Could\'t logout of Facebook: ' .