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 $offset = ($this->page-1) * NOTICES_PER_PAGE;
111 $limit = NOTICES_PER_PAGE + 1;
113 $notices = Notice::conversationStream($this->id, $offset, $limit);
115 $ct = new ConversationTree($notices, $this);
119 $this->pagination($this->page > 1, $cnt > NOTICES_PER_PAGE,
120 $this->page, 'conversation', array('id' => $this->id));
127 * The widget class for displaying a hierarchical list of notices.
131 * @author Evan Prodromou <evan@controlyourself.ca>
132 * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
133 * @link http://laconi.ca/
136 class ConversationTree extends NoticeList
142 * Show the tree of notices
151 $this->tree = array();
152 $this->table = array();
154 while ($this->notice->fetch()) {
158 $id = $this->notice->id;
159 $notice = clone($this->notice);
161 $this->table[$id] = $notice;
163 if (is_null($notice->reply_to)) {
164 $this->tree['root'] = array($notice->id);
165 } else if (array_key_exists($notice->reply_to, $this->tree)) {
166 $this->tree[$notice->reply_to][] = $notice->id;
168 $this->tree[$notice->reply_to] = array($notice->id);
172 $this->out->elementStart('div', array('id' =>'notices_primary'));
173 $this->out->element('h2', null, _('Notices'));
174 $this->out->elementStart('ol', array('class' => 'notices xoxo'));
176 if (array_key_exists('root', $this->tree)) {
177 $rootid = $this->tree['root'][0];
178 $this->showNoticePlus($rootid);
181 $this->out->elementEnd('ol');
182 $this->out->elementEnd('div');
188 * Shows a notice plus its list of children.
190 * @param integer $id ID of the notice to show
195 function showNoticePlus($id)
197 $notice = $this->table[$id];
199 // We take responsibility for doing the li
201 $this->out->elementStart('li', array('class' => 'hentry notice',
202 'id' => 'notice-' . $id));
204 $item = $this->newListItem($notice);
207 if (array_key_exists($id, $this->tree)) {
208 $children = $this->tree[$id];
210 $this->out->elementStart('ol', array('class' => 'notices'));
214 foreach ($children as $child) {
215 $this->showNoticePlus($child);
218 $this->out->elementEnd('ol');
221 $this->out->elementEnd('li');
225 * Override parent class to return our preferred item.
227 * @param Notice $notice Notice to display
229 * @return NoticeListItem a list item to show
232 function newListItem($notice)
234 return new ConversationTreeItem($notice, $this->out);
239 * Conversation tree list item
241 * Special class of NoticeListItem for use inside conversation trees.
245 * @author Evan Prodromou <evan@controlyourself.ca>
246 * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
247 * @link http://laconi.ca/
250 class ConversationTreeItem extends NoticeListItem
253 * start a single notice.
255 * The default creates the <li>; we skip, since the ConversationTree
256 * takes care of that.
269 * The default closes the <li>; we skip, since the ConversationTree
270 * takes care of that.
281 * show link to notice conversation page
283 * Since we're only used on the conversation page, we skip this
288 function showContext()