]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/conversationtree.php
Qvitter API changes (thanks hannes2peer)
[quix0rs-gnu-social.git] / lib / conversationtree.php
1 <?php
2 /**
3  * StatusNet - the distributed open-source microblogging tool
4  * Copyright (C) 2011, StatusNet, Inc.
5  *
6  * Conversation tree widget for oooooold school playas
7  * 
8  * PHP version 5
9  *
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.
14  *
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.
19  *
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/>.
22  *
23  * @category  Widget
24  * @package   StatusNet
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/
29  */
30
31 if (!defined('STATUSNET')) {
32     // This check helps protect against security problems;
33     // your code file can't be executed directly from the web.
34     exit(1);
35 }
36
37 /**
38  * Conversation tree
39  *
40  * The widget class for displaying a hierarchical list of notices.
41  *
42  * @category Widget
43  * @package  StatusNet
44  * @author   Evan Prodromou <evan@status.net>
45  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
46  * @link     http://status.net/
47  */
48 class ConversationTree extends NoticeList
49 {
50     var $tree  = null;
51     var $table = null;
52
53     /**
54      * Show the tree of notices
55      *
56      * @return void
57      */
58     function show()
59     {
60         $cnt = $this->_buildTree();
61
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'));
66
67         if (array_key_exists('root', $this->tree)) {
68             $rootid = $this->tree['root'][0];
69             $this->showNoticePlus($rootid);
70         }
71
72         $this->out->elementEnd('ol');
73         $this->out->elementEnd('div');
74
75         return $cnt;
76     }
77
78     function _buildTree()
79     {
80         $cnt = 0;
81
82         $this->tree  = array();
83         $this->table = array();
84
85         while ($this->notice->fetch()) {
86
87             $cnt++;
88
89             $id     = $this->notice->id;
90             $notice = clone($this->notice);
91
92             $this->table[$id] = $notice;
93
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;
98             } else {
99                 $this->tree[$notice->reply_to] = array($notice->id);
100             }
101         }
102
103         return $cnt;
104     }
105
106     /**
107      * Shows a notice plus its list of children.
108      *
109      * @param integer $id ID of the notice to show
110      *
111      * @return void
112      */
113     function showNoticePlus($id)
114     {
115         $notice = $this->table[$id];
116
117         $this->out->elementStart('li', array('class' => 'hentry notice',
118                                              'id' => 'notice-' . $id));
119
120         $item = $this->newListItem($notice);
121         $item->show();
122
123         if (array_key_exists($id, $this->tree)) {
124             $children = $this->tree[$id];
125
126             $this->out->elementStart('ol', array('class' => 'notices'));
127
128             sort($children);
129
130             foreach ($children as $child) {
131                 $this->showNoticePlus($child);
132             }
133
134             $this->out->elementEnd('ol');
135         }
136
137         $this->out->elementEnd('li');
138     }
139
140     /**
141      * Override parent class to return our preferred item.
142      *
143      * @param Notice $notice Notice to display
144      *
145      * @return NoticeListItem a list item to show
146      */
147     function newListItem($notice)
148     {
149         return new ConversationTreeItem($notice, $this->out);
150     }
151 }
152
153 /**
154  * Conversation tree list item
155  *
156  * Special class of NoticeListItem for use inside conversation trees.
157  *
158  * @category Widget
159  * @package  StatusNet
160  * @author   Evan Prodromou <evan@status.net>
161  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
162  * @link     http://status.net/
163  */
164 class ConversationTreeItem extends NoticeListItem
165 {
166     /**
167      * start a single notice.
168      *
169      * The default creates the <li>; we skip, since the ConversationTree
170      * takes care of that.
171      *
172      * @return void
173      */
174     function showStart()
175     {
176         return;
177     }
178
179     /**
180      * finish the notice
181      *
182      * The default closes the <li>; we skip, since the ConversationTree
183      * takes care of that.
184      *
185      * @return void
186      */
187     function showEnd()
188     {
189         return;
190     }
191
192     /**
193      * show link to notice conversation page
194      *
195      * Since we're only used on the conversation page, we skip this
196      *
197      * @return void
198      */
199     function showContext()
200     {
201         return;
202     }
203
204     /**
205      * show people this notice is in reply to
206      *
207      * Tree context shows this, so we skip it.
208      *
209      * @return void
210      */
211     function showAddressees()
212     {
213         return;
214     }
215 }