3
* Endpoint for Facebook integration.
5
* Copyright 2009-2014 Horde LLC (http://www.horde.org/)
7
* See the enclosed file COPYING for license information (LGPL-2). If you
8
* did not receive this file, see http://www.horde.org/licenses/lgpl.
10
* @author Michael J. Rubinsky <mrubinsk@horde.org>
12
* @license http://www.horde.org/licenses/lgpl LGPL-2
16
require_once __DIR__ . '/../../lib/Application.php';
17
Horde_Registry::appInit('horde');
19
// Get the facebook client.
21
$facebook = $injector->getInstance('Horde_Service_Facebook');
22
} catch (Horde_Exception $e) {
23
Horde::url('index.php', false, array('app' => 'horde'))->redirect();
26
// Url to return to after processing.
27
$return_url = $registry->getServiceLink('prefs', 'horde')
28
->add(array('group' => 'facebook'));
30
// See why we are here. A $code indicates the user has *just* authenticated the
31
// application and we now need to obtain the auth_token.
32
$vars = $injector->getInstance('Horde_Variables');
33
if (isset($vars->code)) {
34
$token = $injector->getInstance('Horde_Token');
35
if (!$token->isValid($vars->state, '', -1, false)) {
36
$notification->push(_("Unable to validate the request token. Please try your request again."));
37
$return_url->redirect();
40
$sessionKey = $facebook->auth->getSessionKey(
41
$vars->code, Horde::url('services/facebook', true));
43
// Store in user prefs
45
$uid = $facebook->auth->getLoggedInUser();
46
$prefs->setValue('facebook', serialize(array('uid' => (string)$uid, 'sid' => $sid)));
48
_("Succesfully connected your Facebook account or updated permissions."),
52
_("There was an error obtaining your Facebook session. Please try again later."),
55
} catch (Horde_Service_Facebook_Exception $e) {
57
_("Temporarily unable to connect with Facebook, Please try again."),
60
$return_url->redirect();
63
if (isset($vars->error)) {
64
if ($vars->error_reason == 'user_denied') {
65
$notification->push(_("You have denied the requested permissions."), 'horde.warning');
67
$notification->push(_("There was an error with the requested permissions"), 'horde.error');
69
$return_url->redirect();