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/
50 class ApiconversationAction extends ApiAuthAction
52 protected $conversation = null;
53 protected $notices = null;
56 * For initializing members of the class.
58 * @param array $argarray misc. arguments
60 * @return boolean true
63 function prepare($argarray)
65 parent::prepare($argarray);
67 $convId = $this->trimmed('id');
70 throw new ClientException(_m('no conversation id'));
73 $this->conversation = Conversation::staticGet('id', $convId);
75 if (empty($this->conversation)) {
76 throw new ClientException(sprintf(_m('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()
102 function handle($argarray=null)
104 $sitename = common_config('site', 'name');
105 // TRANS: Timeline title for user and friends. %s is a user nickname.
106 $title = _("Conversation");
107 $id = common_local_url('apiconversation', array('id' => $this->conversation->id, 'format' => $this->format));
108 $link = common_local_url('conversation', array('id' => $this->conversation->id));
112 switch($this->format) {
114 $this->showXmlTimeline($this->notices);
117 $this->showRssTimeline(
129 header('Content-Type: application/atom+xml; charset=utf-8');
131 $atom = new AtomNoticeFeed($this->auth_user);
134 $atom->setTitle($title);
135 $atom->setUpdated('now');
137 $atom->addLink($link);
138 $atom->setSelfLink($self);
140 $atom->addEntryFromNotices($this->notices);
141 $this->raw($atom->getString());
145 $this->showJsonTimeline($this->notices);
148 header('Content-Type: ' . ActivityStreamJSONDocument::CONTENT_TYPE);
149 $doc = new ActivityStreamJSONDocument($this->auth_user);
150 $doc->setTitle($title);
151 $doc->addLink($link, 'alternate', 'text/html');
152 $doc->addItemsFromNotices($this->notices);
153 $this->raw($doc->asString());
156 // TRANS: Client error displayed when coming across a non-supported API method.
157 $this->clientError(_('API method not found.'), $code = 404);
163 * Return true if read only.
167 * @param array $args other arguments
169 * @return boolean is read only action?
172 function isReadOnly($args)
174 if ($_SERVER['REQUEST_METHOD'] == 'GET' ||
175 $_SERVER['REQUEST_METHOD'] == 'HEAD') {
183 * Return last modified, if applicable.
187 * @return string last modified http header
189 function lastModified()
191 if (!empty($this->notices) && (count($this->notices) > 0)) {
192 return strtotime($this->notices[0]->created);
199 * Return etag, if applicable.
203 * @return string etag http header
208 if (!empty($this->notices) && (count($this->notices) > 0)) {
210 $last = count($this->notices) - 1;
212 return '"' . implode(
214 array($this->arg('action'),
215 common_user_cache_hash($this->auth_user),
218 strtotime($this->notices[0]->created),
219 strtotime($this->notices[$last]->created))
228 * Does this require authentication?
230 * @return boolean true if delete, else false
233 function requiresAuth()
235 if ($_SERVER['REQUEST_METHOD'] == 'GET' ||
236 $_SERVER['REQUEST_METHOD'] == 'HEAD') {