]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Favorite/actions/apistatusesfavs.php
XSS vulnerability when remote-subscribing
[quix0rs-gnu-social.git] / plugins / Favorite / actions / apistatusesfavs.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * Show up to 100 favs of a notice
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   GNUsocial
24  * @author    Hannes Mannerheim <h@nnesmannerhe.im>
25  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
26  * @link      http://www.gnu.org/software/social/
27  */
28
29 if (!defined('GNUSOCIAL')) { exit(1); }
30
31 /**
32  * Show up to 100 favs of a notice
33  *
34  */
35 class ApiStatusesFavsAction extends ApiAuthAction
36 {
37     const MAXCOUNT = 100;
38
39     var $original = null;   // Notice object for which to retrieve favs
40     var $cnt      = self::MAXCOUNT;
41
42     /**
43      * Take arguments for running
44      *
45      * @param array $args $_REQUEST args
46      *
47      * @return boolean success flag
48      */
49     protected function prepare(array $args=array())
50     {
51         parent::prepare($args);
52
53         if ($this->format !== 'json') {
54             $this->clientError('This method currently only serves JSON.', 415);
55         }
56
57         $id = $this->trimmed('id');
58
59         $this->original = Notice::getKV('id', $id);
60
61         if (!($this->original instanceof Notice)) {
62             // TRANS: Client error displayed trying to display redents of a non-exiting notice.
63             $this->clientError(_('No such notice.'), 400);
64         }
65
66         $cnt = $this->trimmed('count');
67
68         if (empty($cnt) || !is_integer($cnt)) {
69             $cnt = 100;
70         } else {
71             $this->cnt = min((int)$cnt, self::MAXCOUNT);
72         }
73
74         return true;
75     }
76
77     /**
78      * Handle the request
79      *
80      * Get favs and return them as json object
81      *
82      * @param array $args $_REQUEST data (unused)
83      *
84      * @return void
85      */
86     protected function handle()
87     {
88         parent::handle();
89         
90         $fave = new Fave();
91         $fave->selectAdd(); 
92         $fave->selectAdd('user_id');
93         $fave->notice_id = $this->original->id;
94         $fave->orderBy('modified');
95         if (!is_null($this->cnt)) {
96             $fave->limit(0, $this->cnt);
97         }
98
99                 $ids = $fave->fetchAll('user_id');
100                 
101                 // get nickname and profile image
102                 $ids_with_profile_data = array();
103                 $i=0;
104                 foreach($ids as $id) {
105                         $profile = Profile::getKV('id', $id);
106                         $ids_with_profile_data[$i]['user_id'] = $id;
107                         $ids_with_profile_data[$i]['nickname'] = $profile->nickname;
108                         $ids_with_profile_data[$i]['fullname'] = $profile->fullname;                    
109                         $ids_with_profile_data[$i]['profileurl'] = $profile->profileurl;                                                
110                         $profile = new Profile();
111                         $profile->id = $id;
112                         $avatarurl = $profile->avatarUrl(24);
113                         $ids_with_profile_data[$i]['avatarurl'] = $avatarurl;                                                           
114                         $i++;
115                 }
116                 
117                 $this->initDocument('json');
118                 $this->showJsonObjects($ids_with_profile_data);
119                 $this->endDocument('json');
120     }
121
122     /**
123      * Return true if read only.
124      *
125      * MAY override
126      *
127      * @param array $args other arguments
128      *
129      * @return boolean is read only action?
130      */
131
132     function isReadOnly($args)
133     {
134         return true;
135     }
136 }