]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/apitimelineretweetedtome.php
Using GNUSOCIAL_VERSION instead of STATUSNET_VERSION
[quix0rs-gnu-social.git] / actions / apitimelineretweetedtome.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * Show most recent notices that are repeats in user's inbox
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 /**
35  * Show most recent notices that are repeats in user's inbox
36  *
37  * @category API
38  * @package  StatusNet
39  * @author   Evan Prodromou <evan@status.net>
40  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
41  * @link     http://status.net/
42  */
43 class ApiTimelineRetweetedToMeAction extends ApiAuthAction
44 {
45     const DEFAULTCOUNT = 20;
46     const MAXCOUNT     = 200;
47     const MAXNOTICES   = 3200;
48
49     var $repeats  = null;
50     var $cnt      = self::DEFAULTCOUNT;
51     var $page     = 1;
52     var $since_id = null;
53     var $max_id   = null;
54
55     /**
56      * Take arguments for running
57      *
58      * @param array $args $_REQUEST args
59      *
60      * @return boolean success flag
61      */
62     function prepare($args)
63     {
64         parent::prepare($args);
65
66         $cnt = $this->int('count', self::DEFAULTCOUNT, self::MAXCOUNT, 1);
67
68         $page = $this->int('page', 1, (self::MAXNOTICES/$this->cnt));
69
70         $since_id = $this->int('since_id');
71
72         $max_id = $this->int('max_id');
73
74         return true;
75     }
76
77     /**
78      * Handle the request
79      *
80      * show a timeline of the user's repeated notices
81      *
82      * @param array $args $_REQUEST data (unused)
83      *
84      * @return void
85      */
86     function handle($args)
87     {
88         parent::handle($args);
89
90         $offset = ($this->page-1) * $this->cnt;
91         $limit  = $this->cnt;
92
93         // TRANS: Title for Atom feed "repeated to me". %s is the user nickname.
94         $title      = sprintf(_("Repeated to %s"), $this->auth_user->nickname);
95         $subtitle   = sprintf(
96             // @todo FIXME: $profile is not defined.
97             // TRANS: Subtitle for API action that shows most recent notices that are repeats in user's inbox.
98             // TRANS: %1$s is the sitename, %2$s is a user nickname, %3$s is a user profile name.
99             _('%1$s notices that were to repeated to %2$s / %3$s.'),
100             $sitename, $this->user->nickname, $profile->getBestName()
101         );
102         $taguribase = TagURI::base();
103         $id         = "tag:$taguribase:RepeatedToMe:" . $this->auth_user->id;
104
105         $link = common_local_url(
106             'all',
107              array('nickname' => $this->auth_user->nickname)
108         );
109
110         $strm = $this->auth_user->repeatedToMe($offset, $limit, $this->since_id, $this->max_id);
111
112         switch ($this->format) {
113         case 'xml':
114             $this->showXmlTimeline($strm);
115             break;
116         case 'json':
117             $this->showJsonTimeline($strm);
118             break;
119         case 'atom':
120             header('Content-Type: application/atom+xml; charset=utf-8');
121
122             $atom = new AtomNoticeFeed($this->auth_user);
123
124             $atom->setId($id);
125             $atom->setTitle($title);
126             $atom->setSubtitle($subtitle);
127             $atom->setUpdated('now');
128             $atom->addLink($link);
129
130             $id = $this->arg('id');
131
132             $atom->setSelfLink($self);
133             $atom->addEntryFromNotices($strm);
134
135             $this->raw($atom->getString());
136
137             break;
138         case 'as':
139             header('Content-Type: ' . ActivityStreamJSONDocument::CONTENT_TYPE);
140             $doc = new ActivityStreamJSONDocument($this->auth_user);
141             $doc->setTitle($title);
142             $doc->addLink($link, 'alternate', 'text/html');
143             $doc->addItemsFromNotices($strm);
144             $this->raw($doc->asString());
145             break;
146         default:
147             // TRANS: Client error displayed when coming across a non-supported API method.
148             $this->clientError(_('API method not found.'), $code = 404);
149             break;
150         }
151     }
152
153     /**
154      * Return true if read only.
155      *
156      * MAY override
157      *
158      * @param array $args other arguments
159      *
160      * @return boolean is read only action?
161      */
162     function isReadOnly($args)
163     {
164         return true;
165     }
166 }