~ubuntu-branches/ubuntu/utopic/php-horde/utopic-proposed

« back to all changes in this revision

Viewing changes to horde-5.2.0/services/facebook/index.php

  • Committer: Package Import Robot
  • Author(s): Mathieu Parent
  • Date: 2014-08-05 11:53:04 UTC
  • mfrom: (1.1.12)
  • Revision ID: package-import@ubuntu.com-20140805115304-3jndo2sgnwsz2g7r
Tags: 5.2.1+debian0-1
* New upstream version 5.2.1
* Update patches

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?php
2
 
/**
3
 
 * Endpoint for Facebook integration.
4
 
 *
5
 
 * Copyright 2009-2014 Horde LLC (http://www.horde.org/)
6
 
 *
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.
9
 
 *
10
 
 * @author Michael J. Rubinsky <mrubinsk@horde.org>
11
 
 * @category Horde
12
 
 * @license  http://www.horde.org/licenses/lgpl LGPL-2
13
 
 * @package  Horde
14
 
 */
15
 
 
16
 
require_once __DIR__ . '/../../lib/Application.php';
17
 
Horde_Registry::appInit('horde');
18
 
 
19
 
// Get the facebook client.
20
 
try {
21
 
    $facebook = $injector->getInstance('Horde_Service_Facebook');
22
 
} catch (Horde_Exception $e) {
23
 
    Horde::url('index.php', false, array('app' => 'horde'))->redirect();
24
 
}
25
 
 
26
 
// Url to return to after processing.
27
 
$return_url = $registry->getServiceLink('prefs', 'horde')
28
 
      ->add(array('group' => 'facebook'));
29
 
 
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();
38
 
    }
39
 
    try {
40
 
        $sessionKey = $facebook->auth->getSessionKey(
41
 
            $vars->code, Horde::url('services/facebook', true));
42
 
        if ($sessionKey) {
43
 
            // Store in user prefs
44
 
            $sid = $sessionKey;
45
 
            $uid = $facebook->auth->getLoggedInUser();
46
 
            $prefs->setValue('facebook', serialize(array('uid' => (string)$uid, 'sid' => $sid)));
47
 
            $notification->push(
48
 
                _("Succesfully connected your Facebook account or updated permissions."),
49
 
                'horde.success');
50
 
        } else {
51
 
            $notification->push(
52
 
                _("There was an error obtaining your Facebook session. Please try again later."),
53
 
                'horde.error');
54
 
        }
55
 
    } catch (Horde_Service_Facebook_Exception $e) {
56
 
        $notification->push(
57
 
            _("Temporarily unable to connect with Facebook, Please try again."),
58
 
            'horde.error');
59
 
    }
60
 
    $return_url->redirect();
61
 
}
62
 
 
63
 
if (isset($vars->error)) {
64
 
    if ($vars->error_reason == 'user_denied') {
65
 
        $notification->push(_("You have denied the requested permissions."), 'horde.warning');
66
 
    } else {
67
 
        $notification->push(_("There was an error with the requested permissions"), 'horde.error');
68
 
    }
69
 
    $return_url->redirect();
70
 
}