]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/apistatusesretweets.php
Merge branch 'master' into 0.9.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
47 class ApiStatusesRetweetsAction extends ApiAuthAction
48 {
49     const MAXCOUNT = 100;
50
51     var $original = null;
52     var $cnt      = self::MAXCOUNT;
53
54     /**
55      * Take arguments for running
56      *
57      * @param array $args $_REQUEST args
58      *
59      * @return boolean success flag
60      *
61      */
62
63     function prepare($args)
64     {
65         parent::prepare($args);
66
67         $id = $this->trimmed('id');
68
69         $this->original = Notice::staticGet('id', $id);
70
71         if (empty($this->original)) {
72             $this->clientError(_('No such notice.'),
73                                400, $this->format);
74             return false;
75         }
76
77         $cnt = $this->trimmed('count');
78
79         if (empty($cnt) || !is_integer($cnt)) {
80             $cnt = 100;
81         } else {
82             $this->cnt = min((int)$cnt, self::MAXCOUNT);
83         }
84
85         return true;
86     }
87
88     /**
89      * Handle the request
90      *
91      * Make a new notice for the update, save it, and show it
92      *
93      * @param array $args $_REQUEST data (unused)
94      *
95      * @return void
96      */
97
98     function handle($args)
99     {
100         parent::handle($args);
101
102         $strm = $this->original->repeatStream($this->cnt);
103
104         switch ($this->format) {
105         case 'xml':
106             $this->showXmlTimeline($strm);
107             break;
108         case 'json':
109             $this->showJsonTimeline($strm);
110             break;
111         default:
112             $this->clientError(_('API method not found!'), $code = 404);
113             break;
114         }
115     }
116 }