]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/conversation.php
Added configurable options for attachments: supported mimetypes and quotas for uploads.
[quix0rs-gnu-social.git] / actions / conversation.php
1 <?php
2 /**
3  * Display a conversation in the browser
4  *
5  * PHP version 5
6  *
7  * @category Action
8  * @package  Laconica
9  * @author   Evan Prodromou <evan@controlyourself.ca>
10  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
11  * @link     http://laconi.ca/
12  *
13  * Laconica - a distributed open-source microblogging tool
14  * Copyright (C) 2009, Control Yourself, Inc.
15  *
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.
20  *
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.
25  *
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/>.
28  */
29
30 if (!defined('LACONICA')) {
31     exit(1);
32 }
33
34 require_once INSTALLDIR.'/lib/noticelist.php';
35
36 /**
37  * Conversation tree in the browser
38  *
39  * @category Action
40  * @package  Laconica
41  * @author   Evan Prodromou <evan@controlyourself.ca>
42  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
43  * @link     http://laconi.ca/
44  */
45
46 class ConversationAction extends Action
47 {
48     var $id   = null;
49     var $page = null;
50
51     /**
52      * Initialization.
53      *
54      * @param array $args Web and URL arguments
55      *
56      * @return boolean false if id not passed in
57      */
58
59     function prepare($args)
60     {
61         parent::prepare($args);
62         $this->id = $this->trimmed('id');
63         if (empty($this->id)) {
64             return false;
65         }
66         $this->page = $this->trimmed('page');
67         if (empty($this->page)) {
68             $this->page = 1;
69         }
70         return true;
71     }
72
73     /**
74      * Handle the action
75      *
76      * @param array $args Web and URL arguments
77      *
78      * @return void
79      */
80
81     function handle($args)
82     {
83         parent::handle($args);
84         $this->showPage();
85     }
86
87     /**
88      * Returns the page title
89      *
90      * @return string page title
91      */
92
93     function title()
94     {
95         return _("Conversation");
96     }
97
98     /**
99      * Show content.
100      *
101      * Display a hierarchical unordered list in the content area.
102      * Uses ConversationTree to do most of the heavy lifting.
103      *
104      * @return void
105      */
106
107     function showContent()
108     {
109         // FIXME this needs to be a tree, not a list
110
111         $qry = 'SELECT * FROM notice WHERE conversation = %s ';
112
113         $offset = ($this->page-1) * NOTICES_PER_PAGE;
114         $limit  = NOTICES_PER_PAGE + 1;
115
116         $txt = sprintf($qry, $this->id);
117
118         $notices = Notice::getStream($txt,
119                                      'notice:conversation:'.$this->id,
120                                      $offset, $limit);
121
122         $ct = new ConversationTree($notices, $this);
123
124         $cnt = $ct->show();
125
126         $this->pagination($this->page > 1, $cnt > NOTICES_PER_PAGE,
127                           $this->page, 'conversation', array('id' => $this->id));
128     }
129
130 }
131
132 /**
133  * Conversation tree
134  *
135  * The widget class for displaying a hierarchical list of notices.
136  *
137  * @category Widget
138  * @package  Laconica
139  * @author   Evan Prodromou <evan@controlyourself.ca>
140  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
141  * @link     http://laconi.ca/
142  */
143
144 class ConversationTree extends NoticeList
145 {
146     var $tree  = null;
147     var $table = null;
148
149     /**
150      * Show the tree of notices
151      *
152      * @return void
153      */
154
155     function show()
156     {
157         $cnt = 0;
158
159         $this->tree  = array();
160         $this->table = array();
161
162         while ($this->notice->fetch()) {
163
164             $cnt++;
165
166             $id     = $this->notice->id;
167             $notice = clone($this->notice);
168
169             $this->table[$id] = $notice;
170
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;
175             } else {
176                 $this->tree[$notice->reply_to] = array($notice->id);
177             }
178         }
179
180         $this->out->elementStart('div', array('id' =>'notices_primary'));
181         $this->out->element('h2', null, _('Notices'));
182         $this->out->elementStart('ul', array('class' => 'notices'));
183
184         if (array_key_exists('root', $this->tree)) {
185             $rootid = $this->tree['root'][0];
186             $this->showNoticePlus($rootid);
187         }
188
189         $this->out->elementEnd('ul');
190         $this->out->elementEnd('div');
191
192         return $cnt;
193     }
194
195     /**
196      * Shows a notice plus its list of children.
197      *
198      * @param integer $id ID of the notice to show
199      *
200      * @return void
201      */
202
203     function showNoticePlus($id)
204     {
205         $notice = $this->table[$id];
206
207         // We take responsibility for doing the li
208
209         $this->out->elementStart('li', array('class' => 'hentry notice',
210                                              'id' => 'notice-' . $this->notice->id));
211
212         $item = $this->newListItem($notice);
213         $item->show();
214
215         if (array_key_exists($id, $this->tree)) {
216             $children = $this->tree[$id];
217
218             $this->out->elementStart('ul', array('class' => 'notices'));
219
220             foreach ($children as $child) {
221                 $this->showNoticePlus($child);
222             }
223
224             $this->out->elementEnd('ul');
225         }
226
227         $this->out->elementEnd('li');
228     }
229
230     /**
231      * Override parent class to return our preferred item.
232      *
233      * @param Notice $notice Notice to display
234      *
235      * @return NoticeListItem a list item to show
236      */
237
238     function newListItem($notice)
239     {
240         return new ConversationTreeItem($notice, $this->out);
241     }
242 }
243
244 /**
245  * Conversation tree list item
246  *
247  * Special class of NoticeListItem for use inside conversation trees.
248  *
249  * @category Widget
250  * @package  Laconica
251  * @author   Evan Prodromou <evan@controlyourself.ca>
252  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
253  * @link     http://laconi.ca/
254  */
255
256 class ConversationTreeItem extends NoticeListItem
257 {
258     /**
259      * start a single notice.
260      *
261      * The default creates the <li>; we skip, since the ConversationTree
262      * takes care of that.
263      *
264      * @return void
265      */
266
267     function showStart()
268     {
269         return;
270     }
271
272     /**
273      * finish the notice
274      *
275      * The default closes the <li>; we skip, since the ConversationTree
276      * takes care of that.
277      *
278      * @return void
279      */
280
281     function showEnd()
282     {
283         return;
284     }
285
286     /**
287      * show link to notice conversation page
288      *
289      * Since we're only used on the conversation page, we skip this
290      *
291      * @return void
292      */
293
294     function showContext()
295     {
296         return;
297     }
298 }