]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Favorite/actions/apifavoritecreate.php
XSS vulnerability when remote-subscribing
[quix0rs-gnu-social.git] / plugins / Favorite / actions / apifavoritecreate.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * Add a notice to a user's list of favorite notices via the API
6  *
7  * PHP version 5
8  *
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.
13  *
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.
18  *
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/>.
21  *
22  * @category  API
23  * @package   StatusNet
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/
32  */
33
34 if (!defined('GNUSOCIAL')) { exit(1); }
35
36 /**
37  * Favorites the status specified in the ID parameter as the authenticating user.
38  * Returns the favorite status when successful.
39  *
40  * @category API
41  * @package  StatusNet
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/
48  */
49 class ApiFavoriteCreateAction extends ApiAuthAction
50 {
51     var $notice = null;
52
53     protected $needPost = true;
54
55     protected function prepare(array $args=array())
56     {
57         parent::prepare($args);
58
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);
65         }
66
67         return true;
68     }
69
70     protected function handle()
71     {
72         parent::handle();
73
74         if (!in_array($this->format, array('xml', 'json'))) {
75             $this->clientError(
76                 // TRANS: Client error displayed when coming across a non-supported API method.
77                 _('API method not found.'),
78                 404,
79                 $this->format
80             );
81         }
82
83         if (empty($this->notice)) {
84             $this->clientError(
85                 // TRANS: Client error displayed when requesting a status with a non-existing ID.
86                 _('No status found with that ID.'),
87                 404,
88                 $this->format
89             );
90         }
91
92         try {
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);
97         }
98
99         if ($this->format == 'xml') {
100             $this->showSingleXmlStatus($this->notice);
101         } elseif ($this->format == 'json') {
102             $this->show_single_json_status($this->notice);
103         }
104     }
105 }