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;
53 * For initializing members of the class.
55 * @param array $argarray misc. arguments
57 * @return boolean true
59 function prepare($argarray)
61 parent::prepare($argarray);
63 $convId = $this->trimmed('id');
66 // TRANS: Client exception thrown when no conversation ID is given.
67 throw new ClientException(_('No conversation ID.'));
70 $this->conversation = Conversation::getKV('id', $convId);
72 if (empty($this->conversation)) {
73 // TRANS: Client exception thrown when referring to a non-existing conversation ID (%d).
74 throw new ClientException(sprintf(_('No conversation with ID %d.'), $convId),
78 $stream = new ConversationNoticeStream($convId, $this->scoped);
80 $notice = $stream->getNotices(($this->page-1) * $this->count,
85 $this->notices = $notice->fetchAll();
93 * @param array $argarray is ignored since it's now passed in in prepare()
97 function handle($argarray=null)
99 $sitename = common_config('site', 'name');
100 // TRANS: Title for conversion timeline.
101 $title = _m('TITLE', 'Conversation');
102 $id = common_local_url('apiconversation', array('id' => $this->conversation->id, 'format' => $this->format));
103 $link = common_local_url('conversation', array('id' => $this->conversation->id));
107 switch($this->format) {
109 $this->showXmlTimeline($this->notices);
112 $this->showRssTimeline(
124 header('Content-Type: application/atom+xml; charset=utf-8');
126 $atom = new AtomNoticeFeed($this->auth_user);
129 $atom->setTitle($title);
130 $atom->setUpdated('now');
132 $atom->addLink($link);
133 $atom->setSelfLink($self);
135 $atom->addEntryFromNotices($this->notices);
136 $this->raw($atom->getString());
140 $this->showJsonTimeline($this->notices);
143 header('Content-Type: ' . ActivityStreamJSONDocument::CONTENT_TYPE);
144 $doc = new ActivityStreamJSONDocument($this->auth_user);
145 $doc->setTitle($title);
146 $doc->addLink($link, 'alternate', 'text/html');
147 $doc->addItemsFromNotices($this->notices);
148 $this->raw($doc->asString());
151 // TRANS: Client error displayed when coming across a non-supported API method.
152 $this->clientError(_('API method not found.'), $code = 404);
158 * Return true if read only.
162 * @param array $args other arguments
164 * @return boolean is read only action?
166 function isReadOnly(array $args=array())
168 if ($_SERVER['REQUEST_METHOD'] == 'GET' ||
169 $_SERVER['REQUEST_METHOD'] == 'HEAD') {
177 * Return last modified, if applicable.
181 * @return string last modified http header
183 function lastModified()
185 if (!empty($this->notices) && (count($this->notices) > 0)) {
186 return strtotime($this->notices[0]->created);
193 * Return etag, if applicable.
197 * @return string etag http header
201 if (!empty($this->notices) && (count($this->notices) > 0)) {
203 $last = count($this->notices) - 1;
205 return '"' . implode(
207 array($this->arg('action'),
208 common_user_cache_hash($this->auth_user),
211 strtotime($this->notices[0]->created),
212 strtotime($this->notices[$last]->created))
221 * Does this require authentication?
223 * @return boolean true if delete, else false
225 function requiresAuth()
227 if ($_SERVER['REQUEST_METHOD'] == 'GET' ||
228 $_SERVER['REQUEST_METHOD'] == 'HEAD') {