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;
56 * Take arguments for running
58 * @return boolean success flag
60 protected function prepare(array $args=array())
62 parent::prepare($args);
64 $this->notice = Notice::getKV($this->arg('id'));
65 if (!empty($this->notice->repeat_of)) {
66 common_debug('Trying to Fave '.$this->notice->id.', repeat of '.$this->notice->repeat_of);
67 common_debug('Will Fave '.$this->notice->repeat_of.' instead');
68 $real_notice_id = $this->notice->repeat_of;
69 $this->notice = Notice::getKV($real_notice_id);
78 * Check the format and show the user info
82 protected function handle()
86 if (!in_array($this->format, array('xml', 'json'))) {
88 // TRANS: Client error displayed when coming across a non-supported API method.
89 _('API method not found.'),
95 if (empty($this->notice)) {
97 // TRANS: Client error displayed when requesting a status with a non-existing ID.
98 _('No status found with that ID.'),
104 // Note: Twitter lets you fave things repeatedly via API.
106 if (Fave::existsForProfile($this->notice, $this->scoped)) {
108 // TRANS: Client error displayed when trying to mark a notice favourite that already is a favourite.
109 _('This status is already a favorite.'),
115 // throws exception on failure
116 $stored = Fave::addNew($this->scoped, $this->notice);
118 if ($this->format == 'xml') {
119 $this->showSingleXmlStatus($this->notice);
120 } elseif ($this->format == 'json') {
121 $this->show_single_json_status($this->notice);