]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/apifriendstimeline.php
Started refactoring API into individual actions
[quix0rs-gnu-social.git] / actions / apifriendstimeline.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * Show the friends timeline
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  Personal
23  * @package   StatusNet
24  * @author    Zach Copley <zach@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/twitterapi.php';
35
36 class ApifriendstimelineAction extends TwitterapiAction
37 {
38
39     /**
40      * Take arguments for running
41      *
42      * @param array $args $_REQUEST args
43      *
44      * @return boolean success flag
45      *
46      */
47
48     function prepare($args)
49     {
50         parent::prepare($args);
51         return true;
52
53     }
54
55     function handle($args) {
56
57         parent::handle($args);
58         common_debug(var_export($args, true));
59
60         if ($this->requiresAuth()) {
61             if ($this->showBasicAuthHeader()) {
62                 $this->showTimeline();
63             }
64         } else {
65             $this->showTimeline();
66         }
67     }
68
69     function showTimeline()
70     {
71         common_debug('Auth user = ' . var_export($this->auth_user, true));
72
73         $user = $this->getTargetUser($this->arg('id'));
74
75         if (empty($user)) {
76             $this->clientError(_('No such user!'), 404, $this->arg('format'));
77             return;
78         }
79
80         $profile    = $user->getProfile();
81         $sitename   = common_config('site', 'name');
82         $title      = sprintf(_("%s and friends"), $user->nickname);
83         $taguribase = common_config('integration', 'taguri');
84         $id         = "tag:$taguribase:FriendsTimeline:" . $user->id;
85         $link       = common_local_url('all',
86             array('nickname' => $user->nickname));
87         $subtitle   = sprintf(_('Updates from %1$s and friends on %2$s!'),
88             $user->nickname, $sitename);
89
90         $page     = (int)$this->arg('page', 1);
91         $count    = (int)$this->arg('count', 20);
92         $max_id   = (int)$this->arg('max_id', 0);
93         $since_id = (int)$this->arg('since_id', 0);
94         $since    = $this->arg('since');
95
96         if (!empty($this->auth_user) && $this->auth_user->id == $user->id) {
97             $notice = $user->noticeInbox(($page-1)*$count,
98                 $count, $since_id, $max_id, $since);
99         } else {
100             $notice = $user->noticesWithFriends(($page-1)*$count,
101                 $count, $since_id, $max_id, $since);
102         }
103
104         switch($this->arg('format')) {
105         case 'xml':
106             $this->show_xml_timeline($notice);
107             break;
108         case 'rss':
109             $this->show_rss_timeline($notice, $title, $link, $subtitle);
110             break;
111         case 'atom':
112
113             $target_id = $this->arg('id');
114
115             if (isset($target_id)) {
116                 $selfuri = common_root_url() .
117                     'api/statuses/friends_timeline/' .
118                         $target_id . '.atom';
119             } else {
120                 $selfuri = common_root_url() .
121                     'api/statuses/friends_timeline.atom';
122             }
123             $this->show_atom_timeline($notice, $title, $id, $link,
124                 $subtitle, null, $selfuri);
125             break;
126         case 'json':
127             $this->show_json_timeline($notice);
128             break;
129         default:
130             $this->clientError(_('API method not found!'), $code = 404);
131         }
132
133     }
134
135     function requiresAuth()
136     {
137         return true;
138     }
139
140     /**
141      * Is this page read-only?
142      *
143      * @return boolean true
144      */
145
146     function isReadOnly($args)
147     {
148         return true;
149     }
150
151     /**
152      * When was this page last modified?
153      *
154      */
155
156     function lastModified()
157     {
158
159     }
160
161 }