]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/apistatusesretweets.php
merge 0.9.x into 1.0.x
[quix0rs-gnu-social.git] / actions / apistatusesretweets.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * Show up to 100 repeats 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   StatusNet
24  * @author    Evan Prodromou <evan@status.net>
25  * @copyright 2009 StatusNet, Inc.
26  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27  * @link      http://status.net/
28  */
29
30 if (!defined('STATUSNET')) {
31     exit(1);
32 }
33
34 require_once INSTALLDIR . '/lib/apiauth.php';
35 require_once INSTALLDIR . '/lib/mediafile.php';
36
37 /**
38  * Show up to 100 repeats of a notice
39  *
40  * @category API
41  * @package  StatusNet
42  * @author   Evan Prodromou <evan@status.net>
43  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
44  * @link     http://status.net/
45  */
46 class ApiStatusesRetweetsAction extends ApiAuthAction
47 {
48     const MAXCOUNT = 100;
49
50     var $original = null;
51     var $cnt      = self::MAXCOUNT;
52
53     /**
54      * Take arguments for running
55      *
56      * @param array $args $_REQUEST args
57      *
58      * @return boolean success flag
59      */
60     function prepare($args)
61     {
62         parent::prepare($args);
63
64         $id = $this->trimmed('id');
65
66         $this->original = Notice::staticGet('id', $id);
67
68         if (empty($this->original)) {
69             // TRANS: Client error displayed trying to display redents of a non-exiting notice.
70             $this->clientError(_('No such notice.'),
71                                400, $this->format);
72             return false;
73         }
74
75         $cnt = $this->trimmed('count');
76
77         if (empty($cnt) || !is_integer($cnt)) {
78             $cnt = 100;
79         } else {
80             $this->cnt = min((int)$cnt, self::MAXCOUNT);
81         }
82
83         return true;
84     }
85
86     /**
87      * Handle the request
88      *
89      * Make a new notice for the update, save it, and show it
90      *
91      * @param array $args $_REQUEST data (unused)
92      *
93      * @return void
94      */
95     function handle($args)
96     {
97         parent::handle($args);
98
99         $strm = $this->original->repeatStream($this->cnt);
100
101         switch ($this->format) {
102         case 'xml':
103             $this->showXmlTimeline($strm);
104             break;
105         case 'json':
106             $this->showJsonTimeline($strm);
107             break;
108         default:
109             // TRANS: Client error displayed when coming across a non-supported API method.
110             $this->clientError(_('API method not found.'), $code = 404);
111             break;
112         }
113     }
114
115     /**
116      * Return true if read only.
117      *
118      * MAY override
119      *
120      * @param array $args other arguments
121      *
122      * @return boolean is read only action?
123      */
124
125     function isReadOnly($args)
126     {
127         return true;
128     }
129 }