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