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) 2008, Controlez-Vous, 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)) {
73 function handle($args)
75 parent::handle($args);
81 return _("Conversation");
84 function showContent()
86 // FIXME this needs to be a tree, not a list
88 $qry = 'SELECT * FROM notice WHERE conversation = %s ';
90 $offset = ($this->page-1)*NOTICES_PER_PAGE;
91 $limit = NOTICES_PER_PAGE + 1;
93 $txt = sprintf($qry, $this->id);
95 $notices = Notice::getStream($txt,
96 'notice:conversation:'.$this->id,
99 $ct = new ConversationTree($notices, $this);
103 $this->pagination($this->page > 1, $cnt > NOTICES_PER_PAGE,
104 $this->page, 'conversation', array('id' => $this->id));
109 class ConversationTree extends NoticeList
118 $this->tree = array();
121 while ($this->notice->fetch()) {
123 $this->table[$this->notice->id] = clone($this->notice);
124 if (is_null($notice->reply_to)) {
125 // We assume no notice has -1 ID
126 $this->tree[-1] = array($notice->id);
127 } else if (array_key_exists($notice->reply_to, $this->tree)) {
128 $this->tree[$notice->reply_to][] = $notice->id;
130 $this->tree[$notice->reply_to] = array($notice->id);
134 $this->out->elementStart('div', array('id' =>'notices_primary'));
135 $this->out->element('h2', null, _('Notices'));
136 $this->out->elementStart('ul', array('class' => 'notices'));
138 if (array_key_exists(-1, $this->tree)) {
139 $this->showNoticePlus($this->tree[-1][0]);
142 $this->out->elementEnd('ul');
143 $this->out->elementEnd('div');
148 function showNoticePlus($id)
150 $notice = $this->table[$id];
154 // We take responsibility for doing the li
156 $this->out->elementStart('li', array('class' => 'hentry notice',
157 'id' => 'notice-' . $this->notice->id));
159 $item = $this->newListItem($notice);
162 if (array_key_exists($id, $this->tree)) {
163 $children = $this->tree[$id];
165 $this->out->elementStart('ul', array('class' => 'notices'));
167 foreach ($children as $child) {
168 $this->showNoticePlus($child);
171 $this->out->elementEnd('ul');
174 $this->out->elementEnd('li');
177 function newListItem($notice)
179 return new ConversationTreeItem($notice, $this->out);
183 class ConversationTreeItem extends NoticeListItem
187 // skip; ConversationTree draws the list
192 // skip; ConversationTree draws the list
195 function showContext()
197 // skip; this _is_ the context!