3 * Display a conversation in the browser
9 * @author Evan Prodromou <evan@controlyourself.ca>
10 * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
11 * @link http://laconi.ca/
13 * Laconica - a distributed open-source microblogging tool
14 * Copyright (C) 2009, Control Yourself, 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('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@controlyourself.ca>
45 * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
46 * @link http://laconi.ca/
49 class ConversationAction extends Action
57 * @param array $args Web and URL arguments
59 * @return boolean false if id not passed in
62 function prepare($args)
64 parent::prepare($args);
65 $this->id = $this->trimmed('id');
66 if (empty($this->id)) {
69 $this->id = $this->id+0;
70 $this->page = $this->trimmed('page');
71 if (empty($this->page)) {
80 * @param array $args Web and URL arguments
85 function handle($args)
87 parent::handle($args);
92 * Returns the page title
94 * @return string page title
99 return _("Conversation");
105 * Display a hierarchical unordered list in the content area.
106 * Uses ConversationTree to do most of the heavy lifting.
111 function showContent()
113 $notices = Notice::conversationStream($this->id, null, null);
115 $ct = new ConversationTree($notices, $this);
120 function isReadOnly()
129 * The widget class for displaying a hierarchical list of notices.
133 * @author Evan Prodromou <evan@controlyourself.ca>
134 * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
135 * @link http://laconi.ca/
138 class ConversationTree extends NoticeList
144 * Show the tree of notices
151 $cnt = $this->_buildTree();
153 $this->out->elementStart('div', array('id' =>'notices_primary'));
154 $this->out->element('h2', null, _('Notices'));
155 $this->out->elementStart('ol', array('class' => 'notices xoxo'));
157 if (array_key_exists('root', $this->tree)) {
158 $rootid = $this->tree['root'][0];
159 $this->showNoticePlus($rootid);
162 $this->out->elementEnd('ol');
163 $this->out->elementEnd('div');
168 function _buildTree()
172 $this->tree = array();
173 $this->table = array();
175 while ($this->notice->fetch()) {
179 $id = $this->notice->id;
180 $notice = clone($this->notice);
182 $this->table[$id] = $notice;
184 if (is_null($notice->reply_to)) {
185 $this->tree['root'] = array($notice->id);
186 } else if (array_key_exists($notice->reply_to, $this->tree)) {
187 $this->tree[$notice->reply_to][] = $notice->id;
189 $this->tree[$notice->reply_to] = array($notice->id);
197 * Shows a notice plus its list of children.
199 * @param integer $id ID of the notice to show
204 function showNoticePlus($id)
206 $notice = $this->table[$id];
208 // We take responsibility for doing the li
210 $this->out->elementStart('li', array('class' => 'hentry notice',
211 'id' => 'notice-' . $id));
213 $item = $this->newListItem($notice);
216 if (array_key_exists($id, $this->tree)) {
217 $children = $this->tree[$id];
219 $this->out->elementStart('ol', array('class' => 'notices'));
223 foreach ($children as $child) {
224 $this->showNoticePlus($child);
227 $this->out->elementEnd('ol');
230 $this->out->elementEnd('li');
234 * Override parent class to return our preferred item.
236 * @param Notice $notice Notice to display
238 * @return NoticeListItem a list item to show
241 function newListItem($notice)
243 return new ConversationTreeItem($notice, $this->out);
248 * Conversation tree list item
250 * Special class of NoticeListItem for use inside conversation trees.
254 * @author Evan Prodromou <evan@controlyourself.ca>
255 * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
256 * @link http://laconi.ca/
259 class ConversationTreeItem extends NoticeListItem
262 * start a single notice.
264 * The default creates the <li>; we skip, since the ConversationTree
265 * takes care of that.
278 * The default closes the <li>; we skip, since the ConversationTree
279 * takes care of that.
290 * show link to notice conversation page
292 * Since we're only used on the conversation page, we skip this
297 function showContext()