]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Share/actions/apitimelineretweetsofme.php
Merge remote-tracking branch 'upstream/master' into social-master
[quix0rs-gnu-social.git] / plugins / Share / actions / apitimelineretweetsofme.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * Show authenticating user's most recent notices that have been repeated
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 authenticating user's most recent notices that have been repeated
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 ApiTimelineRetweetsOfMeAction 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(array $args=array())
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(array $args=array())
87     {
88         parent::handle($args);
89
90         $offset = ($this->page-1) * $this->cnt;
91         $limit  = $this->cnt;
92
93         // TRANS: Title of list of repeated notices of the logged in user.
94         // TRANS: %s is the nickname of the logged in user.
95         $title      = sprintf(_("Repeats of %s"), $this->auth_user->nickname);
96         $sitename   = common_config('site', 'name');
97
98         $profile = $this->auth_user->getProfile();
99
100         $subtitle   = sprintf(
101             // TRANS: Subtitle of API time with retweets of me.
102             // TRANS: %1$s is the StatusNet sitename, %2$s is the user nickname, %3$s is the user profile name.
103             _('%1$s notices that %2$s / %3$s has repeated.'),
104             $sitename, $this->auth_user->nickname, $profile->getBestName()
105         );
106
107         $taguribase = TagURI::base();
108         $id         = "tag:$taguribase:RepeatsOfMe:" . $this->auth_user->id;
109
110         $link = common_local_url(
111             'all',
112              array('nickname' => $this->auth_user->nickname)
113         );
114
115         // This is a really bad query for some reason
116
117         if (!common_config('performance', 'high')) {
118             $strm = $this->auth_user->repeatsOfMe($offset, $limit, $this->since_id, $this->max_id);
119         } else {
120             $strm = new Notice();
121             $strm->whereAdd('0 = 1');
122             $strm->find();
123         }
124
125         switch ($this->format) {
126         case 'xml':
127             $this->showXmlTimeline($strm);
128             break;
129         case 'json':
130             $this->showJsonTimeline($strm);
131             break;
132         case 'atom':
133             header('Content-Type: application/atom+xml; charset=utf-8');
134             $atom = new AtomNoticeFeed($this->auth_user);
135             $atom->setId($id);
136             $atom->setTitle($title);
137             $atom->setSubtitle($subtitle);
138             $atom->setUpdated('now');
139             $atom->addLink($link);
140             $atom->setSelfLink($this->getSelfUri());
141             $atom->addEntryFromNotices($strm);
142             $this->raw($atom->getString());
143             break;
144         case 'as':
145             header('Content-Type: ' . ActivityStreamJSONDocument::CONTENT_TYPE);
146             $doc = new ActivityStreamJSONDocument($this->auth_user);
147             $doc->setTitle($title);
148             $doc->addLink($link, 'alternate', 'text/html');
149             $doc->addItemsFromNotices($strm);
150             $this->raw($doc->asString());
151             break;
152         default:
153             // TRANS: Client error displayed when coming across a non-supported API method.
154             $this->clientError(_('API method not found.'), 404);
155             break;
156         }
157     }
158
159     /**
160      * Return true if read only.
161      *
162      * MAY override
163      *
164      * @param array $args other arguments
165      *
166      * @return boolean is read only action?
167      */
168     function isReadOnly(array $args=array())
169     {
170         return true;
171     }
172 }