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 define('CONVERSATION_LIMIT', 60);
39 require_once INSTALLDIR.'/lib/noticelist.php';
42 * Conversation tree in the browser
46 * @author Evan Prodromou <evan@controlyourself.ca>
47 * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
48 * @link http://laconi.ca/
51 class ConversationAction extends Action
59 * @param array $args Web and URL arguments
61 * @return boolean false if id not passed in
64 function prepare($args)
66 parent::prepare($args);
67 $this->id = $this->trimmed('id');
68 if (empty($this->id)) {
71 $this->id = $this->id+0;
72 $this->page = $this->trimmed('page');
73 if (empty($this->page)) {
82 * @param array $args Web and URL arguments
87 function handle($args)
89 parent::handle($args);
94 * Returns the page title
96 * @return string page title
101 return _("Conversation");
107 * Display a hierarchical unordered list in the content area.
108 * Uses ConversationTree to do most of the heavy lifting.
113 function showContent()
115 $notices = Notice::conversationStream($this->id, null, CONVERSATION_LIMIT);
117 $ct = new ConversationTree($notices, $this);
126 * The widget class for displaying a hierarchical list of notices.
130 * @author Evan Prodromou <evan@controlyourself.ca>
131 * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
132 * @link http://laconi.ca/
135 class ConversationTree extends NoticeList
141 * Show the tree of notices
148 $cnt = $this->_buildTree();
150 $this->out->elementStart('div', array('id' =>'notices_primary'));
151 $this->out->element('h2', null, _('Notices'));
152 $this->out->elementStart('ol', array('class' => 'notices xoxo'));
154 if (array_key_exists('root', $this->tree)) {
155 $rootid = $this->tree['root'][0];
156 $this->showNoticePlus($rootid);
159 $this->out->elementEnd('ol');
160 $this->out->elementEnd('div');
165 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
199 function showNoticePlus($id)
201 $notice = $this->table[$id];
203 // We take responsibility for doing the li
205 $this->out->elementStart('li', array('class' => 'hentry notice',
206 'id' => 'notice-' . $id));
208 $item = $this->newListItem($notice);
211 if (array_key_exists($id, $this->tree)) {
212 $children = $this->tree[$id];
214 $this->out->elementStart('ol', array('class' => 'notices'));
218 foreach ($children as $child) {
219 $this->showNoticePlus($child);
222 $this->out->elementEnd('ol');
225 $this->out->elementEnd('li');
229 * Override parent class to return our preferred item.
231 * @param Notice $notice Notice to display
233 * @return NoticeListItem a list item to show
236 function newListItem($notice)
238 return new ConversationTreeItem($notice, $this->out);
243 * Conversation tree list item
245 * Special class of NoticeListItem for use inside conversation trees.
249 * @author Evan Prodromou <evan@controlyourself.ca>
250 * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
251 * @link http://laconi.ca/
254 class ConversationTreeItem extends NoticeListItem
257 * start a single notice.
259 * The default creates the <li>; we skip, since the ConversationTree
260 * takes care of that.
273 * The default closes the <li>; we skip, since the ConversationTree
274 * takes care of that.
285 * show link to notice conversation page
287 * Since we're only used on the conversation page, we skip this
292 function showContext()