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 abstract class BaseMirrorAction 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 return $this->sharedBoilerplate();
68 protected function validateFeedUrl($url)
70 if (common_valid_http_url($url)) {
73 $this->clientError(_m("Invalid feed URL."));
77 protected function validateProfile($id)
80 $profile = Profile::staticGet('id', $id);
81 if ($profile && $profile->id != $this->user->id) {
84 // TRANS: Error message returned to user when setting up feed mirroring, but we were unable to resolve the given URL to a working feed.
85 $this->clientError(_m("Invalid profile for mirroring."));
93 protected function profileForFeed($url)
95 $oprofile = Ostatus_profile::ensureProfileURL($url);
96 if ($oprofile->isGroup()) {
97 $this->clientError(_m("Can't mirror a StatusNet group at this time."));
99 $this->oprofile = $oprofile; // @fixme ugly side effect :D
100 return $oprofile->localProfile();
104 * @fixme none of this belongs in end classes
105 * this stuff belongs in shared code!
107 function sharedBoilerplate()
109 // Only allow POST requests
111 if ($_SERVER['REQUEST_METHOD'] != 'POST') {
112 $this->clientError(_('This action only accepts POST requests.'));
118 $token = $this->trimmed('token');
120 if (!$token || $token != common_session_token()) {
121 $this->clientError(_('There was a problem with your session token.'.
122 ' Try again, please.'));
126 // Only for logged-in users
128 $this->user = common_current_user();
130 if (empty($this->user)) {
131 $this->clientError(_('Not logged in.'));
140 * Does the subscription and returns results.
142 * @param Array $args unused.
147 function handle($args)
149 // Throws exception on error
152 if ($this->boolean('ajax')) {
153 $this->startHTML('text/xml;charset=utf-8');
154 $this->elementStart('head');
155 $this->element('title', null, _('Subscribed'));
156 $this->elementEnd('head');
157 $this->elementStart('body');
158 $unsubscribe = new EditMirrorForm($this, $this->profile);
159 $unsubscribe->show();
160 $this->elementEnd('body');
161 $this->elementEnd('html');
163 $url = common_local_url('mirrorsettings');
164 common_redirect($url, 303);
168 abstract function saveMirror();