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 EditMirrorAction extends AddMirrorAction
53 * Check pre-requisites and instantiate attributes
55 * @param Array $args array of arguments (URL, GET, POST)
57 * @return boolean success flag
60 function prepare($args)
62 parent::prepare($args);
63 $this->mirror = SubMirror::pkeyGet(array('subscriber' => $this->user->id,
64 'subscribed' => $this->profile->id));
67 $this->clientError(_m("Requested invalid profile to edit."));
70 $this->style = $this->validateStyle($this->trimmed('style'));
72 // DO NOT change to $this->boolean(), it will be wrong.
73 // We're checking for the presence of the setting, not its value.
74 $this->delete = (bool)$this->arg('delete');
79 protected function validateStyle($style)
81 $allowed = array('repeat', 'copy');
82 if (in_array($style, $allowed)) {
85 $this->clientError(_m("Bad form data."));
91 $mirror = SubMirror::getMirror($this->user, $this->profile);
93 $this->clientError(_m('Requested edit of missing mirror'));
98 } else if ($this->style != $mirror->style) {
99 $orig = clone($mirror);
100 $mirror->style = $this->style;
101 $mirror->modified = common_sql_now();
102 $mirror->update($orig);