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->page = $this->trimmed('page');
67 if (empty($this->page)) {
76 * @param array $args Web and URL arguments
81 function handle($args)
83 parent::handle($args);
88 * Returns the page title
90 * @return string page title
95 return _("Conversation");
101 * Display a hierarchical unordered list in the content area.
102 * Uses ConversationTree to do most of the heavy lifting.
107 function showContent()
109 // FIXME this needs to be a tree, not a list
111 $qry = 'SELECT * FROM notice WHERE conversation = %s ';
113 $offset = ($this->page-1) * NOTICES_PER_PAGE;
114 $limit = NOTICES_PER_PAGE + 1;
116 $txt = sprintf($qry, $this->id);
118 $notices = Notice::getStream($txt,
119 'notice:conversation:'.$this->id,
122 $ct = new ConversationTree($notices, $this);
126 $this->pagination($this->page > 1, $cnt > NOTICES_PER_PAGE,
127 $this->page, 'conversation', array('id' => $this->id));
135 * The widget class for displaying a hierarchical list of notices.
139 * @author Evan Prodromou <evan@controlyourself.ca>
140 * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
141 * @link http://laconi.ca/
144 class ConversationTree extends NoticeList
150 * Show the tree of notices
159 $this->tree = array();
160 $this->table = array();
162 while ($this->notice->fetch()) {
166 $id = $this->notice->id;
167 $notice = clone($this->notice);
169 $this->table[$id] = $notice;
171 if (is_null($notice->reply_to)) {
172 $this->tree['root'] = array($notice->id);
173 } else if (array_key_exists($notice->reply_to, $this->tree)) {
174 $this->tree[$notice->reply_to][] = $notice->id;
176 $this->tree[$notice->reply_to] = array($notice->id);
180 $this->out->elementStart('div', array('id' =>'notices_primary'));
181 $this->out->element('h2', null, _('Notices'));
182 $this->out->elementStart('ol', array('class' => 'notices xoxo'));
184 if (array_key_exists('root', $this->tree)) {
185 $rootid = $this->tree['root'][0];
186 $this->showNoticePlus($rootid);
189 $this->out->elementEnd('ol');
190 $this->out->elementEnd('div');
196 * Shows a notice plus its list of children.
198 * @param integer $id ID of the notice to show
203 function showNoticePlus($id)
205 $notice = $this->table[$id];
207 // We take responsibility for doing the li
209 $this->out->elementStart('li', array('class' => 'hentry notice',
210 'id' => 'notice-' . $this->notice->id));
212 $item = $this->newListItem($notice);
215 if (array_key_exists($id, $this->tree)) {
216 $children = $this->tree[$id];
218 $this->out->elementStart('ol', array('class' => 'notices'));
220 foreach ($children as $child) {
221 $this->showNoticePlus($child);
224 $this->out->elementEnd('ol');
227 $this->out->elementEnd('li');
231 * Override parent class to return our preferred item.
233 * @param Notice $notice Notice to display
235 * @return NoticeListItem a list item to show
238 function newListItem($notice)
240 return new ConversationTreeItem($notice, $this->out);
245 * Conversation tree list item
247 * Special class of NoticeListItem for use inside conversation trees.
251 * @author Evan Prodromou <evan@controlyourself.ca>
252 * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
253 * @link http://laconi.ca/
256 class ConversationTreeItem extends NoticeListItem
259 * start a single notice.
261 * The default creates the <li>; we skip, since the ConversationTree
262 * takes care of that.
275 * The default closes the <li>; we skip, since the ConversationTree
276 * takes care of that.
287 * show link to notice conversation page
289 * Since we're only used on the conversation page, we skip this
294 function showContext()