3 * StatusNet - the distributed open-source microblogging tool
4 * Copyright (C) 2011, StatusNet, Inc.
6 * Conversation tree widget for oooooold school playas
10 * This program is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU Affero General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Affero General Public License for more details.
20 * You should have received a copy of the GNU Affero General Public License
21 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 * @author Evan Prodromou <evan@status.net>
26 * @copyright 2011 StatusNet, Inc.
27 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
28 * @link http://status.net/
31 if (!defined('STATUSNET')) {
32 // This check helps protect against security problems;
33 // your code file can't be executed directly from the web.
40 * The widget class for displaying a hierarchical list of notices.
44 * @author Evan Prodromou <evan@status.net>
45 * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
46 * @link http://status.net/
48 class ConversationTree extends NoticeList
54 * Show the tree of notices
60 $cnt = $this->_buildTree();
62 $this->out->elementStart('div', array('id' =>'notices_primary'));
63 // TRANS: Header on conversation page. Hidden by default (h2).
64 $this->out->element('h2', null, _('Notices'));
65 $this->out->elementStart('ol', array('class' => 'notices xoxo old-school'));
67 if (array_key_exists('root', $this->tree)) {
68 $rootid = $this->tree['root'][0];
69 $this->showNoticePlus($rootid);
72 $this->out->elementEnd('ol');
73 $this->out->elementEnd('div');
82 $this->tree = array();
83 $this->table = array();
85 while ($this->notice->fetch()) {
89 $id = $this->notice->id;
90 $notice = clone($this->notice);
92 $this->table[$id] = $notice;
94 if (is_null($notice->reply_to)) {
95 $this->tree['root'] = array($notice->id);
96 } else if (array_key_exists($notice->reply_to, $this->tree)) {
97 $this->tree[$notice->reply_to][] = $notice->id;
99 $this->tree[$notice->reply_to] = array($notice->id);
107 * Shows a notice plus its list of children.
109 * @param integer $id ID of the notice to show
113 function showNoticePlus($id)
115 $notice = $this->table[$id];
117 $this->out->elementStart('li', array('class' => 'hentry notice',
118 'id' => 'notice-' . $id));
120 $item = $this->newListItem($notice);
123 if (array_key_exists($id, $this->tree)) {
124 $children = $this->tree[$id];
126 $this->out->elementStart('ol', array('class' => 'notices'));
130 foreach ($children as $child) {
131 $this->showNoticePlus($child);
134 $this->out->elementEnd('ol');
137 $this->out->elementEnd('li');
141 * Override parent class to return our preferred item.
143 * @param Notice $notice Notice to display
145 * @return NoticeListItem a list item to show
147 function newListItem($notice)
149 return new ConversationTreeItem($notice, $this->out);
154 * Conversation tree list item
156 * Special class of NoticeListItem for use inside conversation trees.
160 * @author Evan Prodromou <evan@status.net>
161 * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
162 * @link http://status.net/
164 class ConversationTreeItem extends NoticeListItem
167 * start a single notice.
169 * The default creates the <li>; we skip, since the ConversationTree
170 * takes care of that.
182 * The default closes the <li>; we skip, since the ConversationTree
183 * takes care of that.
193 * show link to notice conversation page
195 * Since we're only used on the conversation page, we skip this
199 function showContext()
205 * show people this notice is in reply to
207 * Tree context shows this, so we skip it.
211 function showAddressees()