]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/apistatusesfavs.php
Qvitter API changes (thanks hannes2peer)
[quix0rs-gnu-social.git] / 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;
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     function prepare($args)
50     {
51         parent::prepare($args);
52
53         $id = $this->trimmed('id');
54
55         $this->original = Notice::staticGet('id', $id);
56
57         if (empty($this->original)) {
58             // TRANS: Client error displayed trying to display redents of a non-exiting notice.
59             $this->clientError(_('No such notice.'),
60                                400, $this->format);
61             return false;
62         }
63
64         $cnt = $this->trimmed('count');
65
66         if (empty($cnt) || !is_integer($cnt)) {
67             $cnt = 100;
68         } else {
69             $this->cnt = min((int)$cnt, self::MAXCOUNT);
70         }
71
72         return true;
73     }
74
75     /**
76      * Handle the request
77      *
78      * Get favs and return them as json object
79      *
80      * @param array $args $_REQUEST data (unused)
81      *
82      * @return void
83      */
84     function handle($args)
85     {
86         parent::handle($args);
87         
88         $fave = new Fave();
89         $fave->selectAdd(); 
90         $fave->selectAdd('user_id');
91         $fave->notice_id = $this->original->id;
92         $fave->orderBy('modified');
93         if (!is_null($this->cnt)) {
94             $fave->limit(0, $this->cnt);
95         }
96
97                 $ids = $fave->fetchAll('user_id');
98                 
99                 // get nickname and profile image
100                 $ids_with_profile_data = array();
101                 $i=0;
102                 foreach($ids as $id) {
103                         $profile = Profile::staticGet('id', $id);
104                         $ids_with_profile_data[$i]['user_id'] = $id;
105                         $ids_with_profile_data[$i]['nickname'] = $profile->nickname;
106                         $ids_with_profile_data[$i]['fullname'] = $profile->fullname;                    
107                         $ids_with_profile_data[$i]['profileurl'] = $profile->profileurl;                                                
108                         $profile = new Profile();
109                         $profile->id = $id;
110                         $avatarurl = $profile->avatarUrl(24);
111                         $ids_with_profile_data[$i]['avatarurl'] = $avatarurl;                                                           
112                         $i++;
113                 }
114                 
115                 $this->initDocument('json');
116                 $this->showJsonObjects($ids_with_profile_data);
117                 $this->endDocument('json');
118     }
119
120     /**
121      * Return true if read only.
122      *
123      * MAY override
124      *
125      * @param array $args other arguments
126      *
127      * @return boolean is read only action?
128      */
129
130     function isReadOnly($args)
131     {
132         return true;
133     }
134 }