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.
37 require_once INSTALLDIR . '/lib/apiauth.php';
40 * Show a stream of notices in a particular conversation
44 * @author Evan Prodromou <evan@status.net>
45 * @copyright 2011 StatusNet, Inc.
46 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
47 * @link http://status.net/
49 class ApiconversationAction extends ApiAuthAction
51 protected $conversation = null;
52 protected $notices = null;
55 * For initializing members of the class.
57 * @param array $argarray misc. arguments
59 * @return boolean true
61 function prepare($argarray)
63 parent::prepare($argarray);
65 $convId = $this->trimmed('id');
68 // TRANS: Client exception thrown when no conversation ID is given.
69 throw new ClientException(_('No conversation ID.'));
72 $this->conversation = Conversation::staticGet('id', $convId);
74 if (empty($this->conversation)) {
75 // TRANS: Client exception thrown when referring to a non-existing conversation ID (%d).
76 throw new ClientException(sprintf(_('No conversation with ID %d.'), $convId),
80 $profile = Profile::current();
82 $stream = new ConversationNoticeStream($convId, $profile);
84 $notice = $stream->getNotices(($this->page-1) * $this->count,
89 $this->notices = $notice->fetchAll();
97 * @param array $argarray is ignored since it's now passed in in prepare()
101 function handle($argarray=null)
103 $sitename = common_config('site', 'name');
104 // TRANS: Title for conversion timeline.
105 $title = _m('TITLE', 'Conversation');
106 $id = common_local_url('apiconversation', array('id' => $this->conversation->id, 'format' => $this->format));
107 $link = common_local_url('conversation', array('id' => $this->conversation->id));
111 switch($this->format) {
113 $this->showXmlTimeline($this->notices);
116 $this->showRssTimeline(
128 header('Content-Type: application/atom+xml; charset=utf-8');
130 $atom = new AtomNoticeFeed($this->auth_user);
133 $atom->setTitle($title);
134 $atom->setUpdated('now');
136 $atom->addLink($link);
137 $atom->setSelfLink($self);
139 $atom->addEntryFromNotices($this->notices);
140 $this->raw($atom->getString());
144 $this->showJsonTimeline($this->notices);
147 header('Content-Type: ' . ActivityStreamJSONDocument::CONTENT_TYPE);
148 $doc = new ActivityStreamJSONDocument($this->auth_user);
149 $doc->setTitle($title);
150 $doc->addLink($link, 'alternate', 'text/html');
151 $doc->addItemsFromNotices($this->notices);
152 $this->raw($doc->asString());
155 // TRANS: Client error displayed when coming across a non-supported API method.
156 $this->clientError(_('API method not found.'), $code = 404);
162 * Return true if read only.
166 * @param array $args other arguments
168 * @return boolean is read only action?
170 function isReadOnly($args)
172 if ($_SERVER['REQUEST_METHOD'] == 'GET' ||
173 $_SERVER['REQUEST_METHOD'] == 'HEAD') {
181 * Return last modified, if applicable.
185 * @return string last modified http header
187 function lastModified()
189 if (!empty($this->notices) && (count($this->notices) > 0)) {
190 return strtotime($this->notices[0]->created);
197 * Return etag, if applicable.
201 * @return string etag http header
205 if (!empty($this->notices) && (count($this->notices) > 0)) {
207 $last = count($this->notices) - 1;
209 return '"' . implode(
211 array($this->arg('action'),
212 common_user_cache_hash($this->auth_user),
215 strtotime($this->notices[0]->created),
216 strtotime($this->notices[$last]->created))
225 * Does this require authentication?
227 * @return boolean true if delete, else false
229 function requiresAuth()
231 if ($_SERVER['REQUEST_METHOD'] == 'GET' ||
232 $_SERVER['REQUEST_METHOD'] == 'HEAD') {