3 * Display a conversation in the browser
9 * @author Evan Prodromou <evan@status.net>
10 * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
11 * @link http://status.net/
13 * StatusNet - the distributed open-source microblogging tool
14 * Copyright (C) 2009, StatusNet, Inc.
16 * This program is free software: you can redistribute it and/or modify
17 * it under the terms of the GNU Affero General Public License as published by
18 * the Free Software Foundation, either version 3 of the License, or
19 * (at your option) any later version.
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU Affero General Public License for more details.
26 * You should have received a copy of the GNU Affero General Public License
27 * along with this program. If not, see <http://www.gnu.org/licenses/>.
30 if (!defined('STATUSNET') && !defined('LACONICA')) {
34 // XXX: not sure how to do paging yet,
35 // so set a 60-notice limit
37 require_once INSTALLDIR.'/lib/noticelist.php';
40 * Conversation tree in the browser
44 * @author Evan Prodromou <evan@status.net>
45 * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
46 * @link http://status.net/
48 class ConversationAction extends Action
56 * @param array $args Web and URL arguments
58 * @return boolean false if id not passed in
60 function prepare($args)
62 parent::prepare($args);
63 $this->id = $this->trimmed('id');
64 if (empty($this->id)) {
67 $this->id = $this->id+0;
68 $this->page = $this->trimmed('page');
69 if (empty($this->page)) {
78 * @param array $args Web and URL arguments
82 function handle($args)
84 parent::handle($args);
89 * Returns the page title
91 * @return string page title
95 // TRANS: Title for page with a conversion (multiple notices in context).
96 return _('Conversation');
102 * Display a hierarchical unordered list in the content area.
103 * Uses ConversationTree to do most of the heavy lifting.
107 function showContent()
109 $notices = Notice::conversationStream($this->id, null, null);
111 $ct = new ConversationTree($notices, $this);
116 function isReadOnly()
125 * The widget class for displaying a hierarchical list of notices.
129 * @author Evan Prodromou <evan@status.net>
130 * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
131 * @link http://status.net/
133 class ConversationTree extends NoticeList
139 * Show the tree of notices
145 $cnt = $this->_buildTree();
147 $this->out->elementStart('div', array('id' =>'notices_primary'));
148 // TRANS: Header on conversation page. Hidden by default (h2).
149 $this->out->element('h2', null, _('Notices'));
150 $this->out->elementStart('ol', array('class' => 'notices xoxo'));
152 if (array_key_exists('root', $this->tree)) {
153 $rootid = $this->tree['root'][0];
154 $this->showNoticePlus($rootid);
157 $this->out->elementEnd('ol');
158 $this->out->elementEnd('div');
163 function _buildTree()
167 $this->tree = array();
168 $this->table = array();
170 while ($this->notice->fetch()) {
174 $id = $this->notice->id;
175 $notice = clone($this->notice);
177 $this->table[$id] = $notice;
179 if (is_null($notice->reply_to)) {
180 $this->tree['root'] = array($notice->id);
181 } else if (array_key_exists($notice->reply_to, $this->tree)) {
182 $this->tree[$notice->reply_to][] = $notice->id;
184 $this->tree[$notice->reply_to] = array($notice->id);
192 * Shows a notice plus its list of children.
194 * @param integer $id ID of the notice to show
198 function showNoticePlus($id)
200 $notice = $this->table[$id];
202 // We take responsibility for doing the li
204 $this->out->elementStart('li', array('class' => 'hentry notice',
205 'id' => 'notice-' . $id));
207 $item = $this->newListItem($notice);
210 if (array_key_exists($id, $this->tree)) {
211 $children = $this->tree[$id];
213 $this->out->elementStart('ol', array('class' => 'notices'));
217 foreach ($children as $child) {
218 $this->showNoticePlus($child);
221 $this->out->elementEnd('ol');
224 $this->out->elementEnd('li');
228 * Override parent class to return our preferred item.
230 * @param Notice $notice Notice to display
232 * @return NoticeListItem a list item to show
234 function newListItem($notice)
236 return new ConversationTreeItem($notice, $this->out);
241 * Conversation tree list item
243 * Special class of NoticeListItem for use inside conversation trees.
247 * @author Evan Prodromou <evan@status.net>
248 * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
249 * @link http://status.net/
251 class ConversationTreeItem extends NoticeListItem
254 * start a single notice.
256 * The default creates the <li>; we skip, since the ConversationTree
257 * takes care of that.
269 * The default closes the <li>; we skip, since the ConversationTree
270 * takes care of that.
280 * show link to notice conversation page
282 * Since we're only used on the conversation page, we skip this
286 function showContext()