3 * StatusNet - the distributed open-source microblogging tool
4 * Copyright (C) 2011, StatusNet, Inc.
6 * Show a stream of notices in a particular conversation
10 * This program is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU Affero General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Affero General Public License for more details.
20 * You should have received a copy of the GNU Affero General Public License
21 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 * @author Evan Prodromou <evan@status.net>
26 * @copyright 2011 StatusNet, Inc.
27 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
28 * @link http://status.net/
31 if (!defined('STATUSNET')) {
32 // This check helps protect against security problems;
33 // your code file can't be executed directly from the web.
38 * Show a stream of notices in a particular conversation
42 * @author Evan Prodromou <evan@status.net>
43 * @copyright 2011 StatusNet, Inc.
44 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
45 * @link http://status.net/
47 class ApiconversationAction extends ApiAuthAction
49 protected $conversation = null;
50 protected $notices = null;
52 protected function prepare(array $args=array())
54 parent::prepare($args);
56 $convId = $this->trimmed('id');
59 // TRANS: Client exception thrown when no conversation ID is given.
60 throw new ClientException(_('No conversation ID.'));
63 $this->conversation = Conversation::getKV('id', $convId);
65 if (empty($this->conversation)) {
66 // TRANS: Client exception thrown when referring to a non-existing conversation ID (%d).
67 throw new ClientException(sprintf(_('No conversation with ID %d.'), $convId),
71 $stream = new ConversationNoticeStream($convId, $this->scoped);
73 $notice = $stream->getNotices(($this->page-1) * $this->count,
78 $this->notices = $notice->fetchAll();
86 * @param array $argarray is ignored since it's now passed in in prepare()
90 function handle($argarray=null)
92 $sitename = common_config('site', 'name');
93 // TRANS: Title for conversion timeline.
94 $title = _m('TITLE', 'Conversation');
95 $id = common_local_url('apiconversation', array('id' => $this->conversation->id, 'format' => $this->format));
96 $link = common_local_url('conversation', array('id' => $this->conversation->id));
100 switch($this->format) {
102 $this->showXmlTimeline($this->notices);
105 $this->showRssTimeline(
117 header('Content-Type: application/atom+xml; charset=utf-8');
119 $atom = new AtomNoticeFeed($this->auth_user);
122 $atom->setTitle($title);
123 $atom->setUpdated('now');
125 $atom->addLink($link);
126 $atom->setSelfLink($self);
128 $atom->addEntryFromNotices($this->notices);
129 $this->raw($atom->getString());
133 $this->showJsonTimeline($this->notices);
136 header('Content-Type: ' . ActivityStreamJSONDocument::CONTENT_TYPE);
137 $doc = new ActivityStreamJSONDocument($this->auth_user);
138 $doc->setTitle($title);
139 $doc->addLink($link, 'alternate', 'text/html');
140 $doc->addItemsFromNotices($this->notices);
141 $this->raw($doc->asString());
144 // TRANS: Client error displayed when coming across a non-supported API method.
145 $this->clientError(_('API method not found.'), $code = 404);
151 * Return true if read only.
155 * @param array $args other arguments
157 * @return boolean is read only action?
159 function isReadOnly($args)
161 if ($_SERVER['REQUEST_METHOD'] == 'GET' ||
162 $_SERVER['REQUEST_METHOD'] == 'HEAD') {
170 * Return last modified, if applicable.
174 * @return string last modified http header
176 function lastModified()
178 if (!empty($this->notices) && (count($this->notices) > 0)) {
179 return strtotime($this->notices[0]->created);
186 * Return etag, if applicable.
190 * @return string etag http header
194 if (!empty($this->notices) && (count($this->notices) > 0)) {
196 $last = count($this->notices) - 1;
198 return '"' . implode(
200 array($this->arg('action'),
201 common_user_cache_hash($this->auth_user),
204 strtotime($this->notices[0]->created),
205 strtotime($this->notices[$last]->created))
214 * Does this require authentication?
216 * @return boolean true if delete, else false
218 function requiresAuth()
220 if ($_SERVER['REQUEST_METHOD'] == 'GET' ||
221 $_SERVER['REQUEST_METHOD'] == 'HEAD') {