3 * StatusNet, the distributed open-source microblogging tool
5 * Add a notice to a user's list of favorite notices via the API
9 * LICENCE: This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU Affero General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Affero General Public License for more details.
19 * You should have received a copy of the GNU Affero General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 * @author Craig Andrews <candrews@integralblue.com>
25 * @author Evan Prodromou <evan@status.net>
26 * @author Zach Copley <zach@status.net>
27 * @author Mikael Nordfeldth <mmn@hethane.se>
28 * @copyright 2009 StatusNet, Inc.
29 * @copyright 2009 Free Software Foundation, Inc http://www.fsf.org
30 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
31 * @link http://gnu.io/
34 if (!defined('GNUSOCIAL')) { exit(1); }
37 * Favorites the status specified in the ID parameter as the authenticating user.
38 * Returns the favorite status when successful.
42 * @author Craig Andrews <candrews@integralblue.com>
43 * @author Evan Prodromou <evan@status.net>
44 * @author Zach Copley <zach@status.net>
45 * @author Mikael Nordfeldth <mmn@hethane.se>
46 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
47 * @link http://gnu.io/
49 class ApiFavoriteCreateAction extends ApiAuthAction
53 protected $needPost = true;
55 protected function prepare(array $args=array())
57 parent::prepare($args);
59 $this->notice = Notice::getKV($this->arg('id'));
60 if (!empty($this->notice->repeat_of)) {
61 common_log(LOG_DEBUG, 'Trying to Fave '.$this->notice->id.', repeat of '.$this->notice->repeat_of);
62 common_log(LOG_DEBUG, 'Will Fave '.$this->notice->repeat_of.' instead');
63 $real_notice_id = $this->notice->repeat_of;
64 $this->notice = Notice::getKV($real_notice_id);
70 protected function handle()
74 if (!in_array($this->format, array('xml', 'json'))) {
76 // TRANS: Client error displayed when coming across a non-supported API method.
77 _('API method not found.'),
83 if (empty($this->notice)) {
85 // TRANS: Client error displayed when requesting a status with a non-existing ID.
86 _('No status found with that ID.'),
93 $stored = Fave::addNew($this->scoped, $this->notice);
94 } catch (AlreadyFulfilledException $e) {
95 // Note: Twitter lets you fave things repeatedly via API.
96 $this->clientError($e->getMessage(), 403);
99 if ($this->format == 'xml') {
100 $this->showSingleXmlStatus($this->notice);
101 } elseif ($this->format == 'json') {
102 $this->show_single_json_status($this->notice);