3 * Handler for remote subscription finish callback
9 * @author Evan Prodromou <evan@controlyourself.ca>
10 * @author Robin Millette <millette@controlyourself.ca>
11 * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
12 * @link http://laconi.ca/
14 * Laconica - a distributed open-source microblogging tool
15 * Copyright (C) 2008, 2009, Control Yourself, Inc.
17 * This program is free software: you can redistribute it and/or modify
18 * it under the terms of the GNU Affero General Public License as published by
19 * the Free Software Foundation, either version 3 of the License, or
20 * (at your option) any later version.
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU Affero General Public License for more details.
27 * You should have received a copy of the GNU Affero General Public License
28 * along with this program. If not, see <http://www.gnu.org/licenses/>.
31 if (!defined('LACONICA')) {
35 require_once INSTALLDIR.'/extlib/libomb/service_consumer.php';
36 require_once INSTALLDIR.'/lib/omb.php';
39 * Handler for remote subscription finish callback
41 * When a remote user subscribes a local user, a redirect to this action is
42 * issued after the remote user authorized his service to subscribe.
46 * @author Evan Prodromou <evan@controlyourself.ca>
47 * @author Robin Millette <millette@controlyourself.ca>
48 * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
49 * @link http://laconi.ca/
51 class FinishremotesubscribeAction extends Action
57 * @param array $args query arguments
62 function handle($args)
64 parent::handle($args);
66 /* Restore session data. RemotesubscribeAction should have stored
68 $service = unserialize($_SESSION['oauth_authorization_request']);
71 $this->clientError(_('Not expecting this response!'));
75 common_debug('stored request: '. print_r($service, true), __FILE__);
77 /* Create user objects for both users. Do it early for request
79 $listenee = $service->getListeneeURI();
80 $user = User::staticGet('uri', $listenee);
83 $this->clientError(_('User being listened to doesn\'t exist.'));
87 $other = User::staticGet('uri', $service->getListenerURI());
90 $this->clientError(_('You can use the local subscription!'));
94 /* Perform the handling itself via libomb. */
96 $service->finishAuthorization($listenee);
97 } catch (OAuthException $e) {
98 if ($e->getMessage() == 'The authorized token does not equal the ' .
100 $this->clientError(_('Not authorized.'));
103 $this->clientError(_('Couldn\'t convert request token to ' .
107 } catch (OMB_RemoteServiceException $e) {
108 $this->clientError(_('Unknown version of OMB protocol.'));
110 } catch (Exception $e) {
111 common_debug('Got exception ' . print_r($e, true), __FILE__);
112 $this->clientError($e->getMessage());
116 /* The service URLs are not accessible from datastore, so setting them
117 after insertion of the profile. */
118 $remote = Remote_profile::staticGet('uri', $service->getListenerURI());
120 $orig_remote = clone($remote);
122 $remote->postnoticeurl =
123 $service->getServiceURI(OMB_ENDPOINT_POSTNOTICE);
124 $remote->updateprofileurl =
125 $service->getServiceURI(OMB_ENDPOINT_UPDATEPROFILE);
127 if (!$remote->update($orig_remote)) {
128 $this->serverError(_('Error updating remote profile'));
132 /* Clear the session data. */
133 unset($_SESSION['oauth_authorization_request']);
135 /* If we show subscriptions in reverse chronological order, the new one
136 should show up close to the top of the page. */
137 common_redirect(common_local_url('subscribers', array('nickname' =>