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 $profile = Profile::current();
80 $stream = new ConversationNoticeStream($convId, $profile);
82 $notice = $stream->getNotices(($this->page-1) * $this->count,
87 $this->notices = $notice->fetchAll();
95 * @param array $argarray is ignored since it's now passed in in prepare()
99 function handle($argarray=null)
101 $sitename = common_config('site', 'name');
102 // TRANS: Title for conversion timeline.
103 $title = _m('TITLE', 'Conversation');
104 $id = common_local_url('apiconversation', array('id' => $this->conversation->id, 'format' => $this->format));
105 $link = common_local_url('conversation', array('id' => $this->conversation->id));
109 switch($this->format) {
111 $this->showXmlTimeline($this->notices);
114 $this->showRssTimeline(
126 header('Content-Type: application/atom+xml; charset=utf-8');
128 $atom = new AtomNoticeFeed($this->auth_user);
131 $atom->setTitle($title);
132 $atom->setUpdated('now');
134 $atom->addLink($link);
135 $atom->setSelfLink($self);
137 $atom->addEntryFromNotices($this->notices);
138 $this->raw($atom->getString());
142 $this->showJsonTimeline($this->notices);
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($this->notices);
150 $this->raw($doc->asString());
153 // TRANS: Client error displayed when coming across a non-supported API method.
154 $this->clientError(_('API method not found.'), $code = 404);
160 * Return true if read only.
164 * @param array $args other arguments
166 * @return boolean is read only action?
168 function isReadOnly($args)
170 if ($_SERVER['REQUEST_METHOD'] == 'GET' ||
171 $_SERVER['REQUEST_METHOD'] == 'HEAD') {
179 * Return last modified, if applicable.
183 * @return string last modified http header
185 function lastModified()
187 if (!empty($this->notices) && (count($this->notices) > 0)) {
188 return strtotime($this->notices[0]->created);
195 * Return etag, if applicable.
199 * @return string etag http header
203 if (!empty($this->notices) && (count($this->notices) > 0)) {
205 $last = count($this->notices) - 1;
207 return '"' . implode(
209 array($this->arg('action'),
210 common_user_cache_hash($this->auth_user),
213 strtotime($this->notices[0]->created),
214 strtotime($this->notices[$last]->created))
223 * Does this require authentication?
225 * @return boolean true if delete, else false
227 function requiresAuth()
229 if ($_SERVER['REQUEST_METHOD'] == 'GET' ||
230 $_SERVER['REQUEST_METHOD'] == 'HEAD') {