3 * StatusNet - the distributed open-source microblogging tool
4 * Copyright (C) 2010, StatusNet, Inc.
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 * @author Brion Vibber <brion@status.net>
24 * @copyright 2010 StatusNet, Inc.
25 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPLv3
26 * @link http://status.net/
29 if (!defined('STATUSNET')) {
36 * - feed: a profile ID
37 * - token: session token to prevent CSRF attacks
38 * - ajax: boolean; whether to return Ajax or full-browser results
40 * Only works if the current user is logged in.
44 * @copyright 2010 StatusNet, Inc.
45 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPLv3
46 * @link http://status.net/
49 class AddMirrorAction extends Action
55 * Check pre-requisites and instantiate attributes
57 * @param Array $args array of arguments (URL, GET, POST)
59 * @return boolean success flag
62 function prepare($args)
64 parent::prepare($args);
65 $ok = $this->sharedBoilerplate();
67 // and now do something useful!
68 $this->profile = $this->validateProfile($this->trimmed('profile'));
75 function validateProfile($id)
78 $profile = Profile::staticGet('id', $id);
79 if ($profile && $profile->id != $this->user->id) {
82 // TRANS: Error message returned to user when setting up feed mirroring, but we were unable to resolve the given URL to a working feed.
83 $this->clientError(_m("Invalid profile for mirroring."));
87 * @fixme none of this belongs in end classes
88 * this stuff belongs in shared code!
90 function sharedBoilerplate()
92 // Only allow POST requests
94 if ($_SERVER['REQUEST_METHOD'] != 'POST') {
95 $this->clientError(_('This action only accepts POST requests.'));
101 $token = $this->trimmed('token');
103 if (!$token || $token != common_session_token()) {
104 $this->clientError(_('There was a problem with your session token.'.
105 ' Try again, please.'));
109 // Only for logged-in users
111 $this->user = common_current_user();
113 if (empty($this->user)) {
114 $this->clientError(_('Not logged in.'));
123 * Does the subscription and returns results.
125 * @param Array $args unused.
130 function handle($args)
132 // Throws exception on error
135 if ($this->boolean('ajax')) {
136 $this->startHTML('text/xml;charset=utf-8');
137 $this->elementStart('head');
138 $this->element('title', null, _('Subscribed'));
139 $this->elementEnd('head');
140 $this->elementStart('body');
141 $unsubscribe = new EditMirrorForm($this, $this->profile);
142 $unsubscribe->show();
143 $this->elementEnd('body');
144 $this->elementEnd('html');
146 $url = common_local_url('mirrorsettings');
147 common_redirect($url, 303);
151 function saveMirror()
153 SubMirror::saveMirror($this->user, $this->profile);