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 require_once INSTALLDIR.'/lib/noticelist.php';
37 * Conversation tree in the browser
41 * @author Evan Prodromou <evan@controlyourself.ca>
42 * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
43 * @link http://laconi.ca/
46 class ConversationAction extends Action
54 * @param array $args Web and URL arguments
56 * @return boolean false if id not passed in
59 function prepare($args)
61 parent::prepare($args);
62 $this->id = $this->trimmed('id');
63 if (empty($this->id)) {
66 $this->id = $this->id+0;
67 $this->page = $this->trimmed('page');
68 if (empty($this->page)) {
77 * @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
96 return _("Conversation");
102 * Display a hierarchical unordered list in the content area.
103 * Uses ConversationTree to do most of the heavy lifting.
108 function showContent()
110 $notices = Notice::conversationStream($this->id, 0, null);
112 $ct = new ConversationTree($notices, $this);
121 * The widget class for displaying a hierarchical list of notices.
125 * @author Evan Prodromou <evan@controlyourself.ca>
126 * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
127 * @link http://laconi.ca/
130 class ConversationTree extends NoticeList
136 * Show the tree of notices
147 $this->out->elementStart('div', array('id' =>'notices_primary'));
148 $this->out->element('h2', null, _('Notices'));
149 $this->out->elementStart('ol', array('class' => 'notices xoxo'));
151 if (array_key_exists('root', $this->tree)) {
152 $rootid = $this->tree['root'][0];
153 $this->showNoticePlus($rootid);
156 $this->out->elementEnd('ol');
157 $this->out->elementEnd('div');
162 function _buildTree()
164 $this->tree = array();
165 $this->table = array();
167 while ($this->notice->fetch()) {
171 $id = $this->notice->id;
172 $notice = clone($this->notice);
174 $this->table[$id] = $notice;
176 if (is_null($notice->reply_to)) {
177 $this->tree['root'] = array($notice->id);
178 } else if (array_key_exists($notice->reply_to, $this->tree)) {
179 $this->tree[$notice->reply_to][] = $notice->id;
181 $this->tree[$notice->reply_to] = array($notice->id);
187 * Shows a notice plus its list of children.
189 * @param integer $id ID of the notice to show
194 function showNoticePlus($id)
196 $notice = $this->table[$id];
198 // We take responsibility for doing the li
200 $this->out->elementStart('li', array('class' => 'hentry notice',
201 'id' => 'notice-' . $id));
203 $item = $this->newListItem($notice);
206 if (array_key_exists($id, $this->tree)) {
207 $children = $this->tree[$id];
209 $this->out->elementStart('ol', array('class' => 'notices'));
213 foreach ($children as $child) {
214 $this->showNoticePlus($child);
217 $this->out->elementEnd('ol');
220 $this->out->elementEnd('li');
224 * Override parent class to return our preferred item.
226 * @param Notice $notice Notice to display
228 * @return NoticeListItem a list item to show
231 function newListItem($notice)
233 return new ConversationTreeItem($notice, $this->out);
238 * Conversation tree list item
240 * Special class of NoticeListItem for use inside conversation trees.
244 * @author Evan Prodromou <evan@controlyourself.ca>
245 * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
246 * @link http://laconi.ca/
249 class ConversationTreeItem extends NoticeListItem
252 * start a single notice.
254 * The default creates the <li>; we skip, since the ConversationTree
255 * takes care of that.
268 * The default closes the <li>; we skip, since the ConversationTree
269 * takes care of that.
280 * show link to notice conversation page
282 * Since we're only used on the conversation page, we skip this
287 function showContext()