1 | <?php |
---|
2 | # -- BEGIN LICENSE BLOCK ---------------------------------- |
---|
3 | # |
---|
4 | # This file is part of dctribune, a plugin for Dotclear 2. |
---|
5 | # |
---|
6 | # Copyright (c) 2009 Osku and contributors |
---|
7 | # Many thanks to Pep, Tomtom and JcDenis |
---|
8 | # Originally from Antoine Libert |
---|
9 | # |
---|
10 | # Licensed under the GPL version 2.0 license. |
---|
11 | # A copy of this license is available in LICENSE file or at |
---|
12 | # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
---|
13 | # |
---|
14 | # -- END LICENSE BLOCK ------------------------------------ |
---|
15 | |
---|
16 | if (!defined('DC_CONTEXT_ADMIN')) { return; } |
---|
17 | |
---|
18 | require DC_ROOT.'/inc/admin/lib.pager.php'; |
---|
19 | |
---|
20 | if (!empty($_REQUEST['edit']) && !empty($_REQUEST['id'])) { |
---|
21 | include dirname(__FILE__).'/edit.php'; |
---|
22 | return; |
---|
23 | } |
---|
24 | |
---|
25 | if (!empty($_REQUEST['config'])) { |
---|
26 | include dirname(__FILE__).'/config.php'; |
---|
27 | return; |
---|
28 | } |
---|
29 | |
---|
30 | if (is_null($core->blog->settings->tribune_flag)) { |
---|
31 | try { |
---|
32 | $core->blog->settings->setNameSpace('tribune'); |
---|
33 | |
---|
34 | // Tribune is not active by default |
---|
35 | $core->blog->settings->put('tribune_flag',false,'boolean','Enable chatbox plugin'); |
---|
36 | $core->blog->settings->put('tribune_syntax_wiki',false,'boolean','Syntax Wiki for chatbox'); |
---|
37 | $core->blog->settings->put('tribune_display_order',false,'boolean','Inverse order of chatbox'); |
---|
38 | $core->blog->settings->put('tribune_refresh_time',30000,'integer','Refresh rate of Tribune in millisecondes'); |
---|
39 | $core->blog->settings->put('tribune_message_length',140,'integer','Number of messages displayed in chatbox'); |
---|
40 | $core->blog->settings->put('tribune_limit',10,'integer','Number of messages displayed in chatbox'); |
---|
41 | |
---|
42 | $core->blog->settings->setNameSpace('system'); |
---|
43 | |
---|
44 | $core->blog->triggerBlog(); |
---|
45 | } |
---|
46 | catch (Exception $e) { |
---|
47 | $core->error->add($e->getMessage()); |
---|
48 | } |
---|
49 | } |
---|
50 | |
---|
51 | $default_tab = ''; |
---|
52 | $params=array(); |
---|
53 | |
---|
54 | $status = isset($_GET['status']) ? $_GET['status'] : ''; |
---|
55 | $nb = !empty($_GET['nb']) ? trim($_GET['nb']) : 0; |
---|
56 | |
---|
57 | if(empty($_GET['filter']) && !empty($_SESSION['messages_filter'])) { |
---|
58 | $s = unserialize(base64_decode($_SESSION['messages_filter'])); |
---|
59 | if ($s !== false) { |
---|
60 | $status = isset($s['status']) ? $s['status'] : ''; |
---|
61 | $nb = !empty($s['nb']) ? trim($s['nb']) : ''; |
---|
62 | } |
---|
63 | } elseif (!empty($_GET['filter'])) { |
---|
64 | $s = array( |
---|
65 | 'status' => $status, |
---|
66 | 'nb' => $nb); |
---|
67 | $_SESSION['messages_filter']=base64_encode(serialize($s)); |
---|
68 | } |
---|
69 | |
---|
70 | $combo_action = array(); |
---|
71 | $combo_action[__('Status')] = array( |
---|
72 | __('publish') => 'publish', |
---|
73 | __('unpublish') => 'unpublish', |
---|
74 | __('delete') => 'delete' |
---|
75 | ); |
---|
76 | |
---|
77 | $status_combo = array( |
---|
78 | '-' => '', |
---|
79 | __('published') => '1', |
---|
80 | __('unpublished') => '0' |
---|
81 | ); |
---|
82 | |
---|
83 | $sortby_combo = array( |
---|
84 | __('Date') => 'tribune_dt', |
---|
85 | __('Status') => 'tribune_state', |
---|
86 | ); |
---|
87 | |
---|
88 | $order_combo = array( |
---|
89 | __('Descending') => 'desc', |
---|
90 | __('Ascending') => 'asc' |
---|
91 | ); |
---|
92 | |
---|
93 | $show_filters = false; |
---|
94 | $add_message = false; |
---|
95 | |
---|
96 | $sortby = !empty($_GET['sortby']) ? $_GET['sortby'] : ''; |
---|
97 | $order = !empty($_GET['order']) ? $_GET['order'] : ''; |
---|
98 | $page = !empty($_GET['page']) ? $_GET['page'] : 1; |
---|
99 | $ip = !empty($_GET['ip']) ? $_GET['ip'] : ''; |
---|
100 | $nb_per_page = 10; |
---|
101 | if ((integer) $nb > 0) { |
---|
102 | if ($nb_per_page != $nb) { |
---|
103 | $show_filters = true; |
---|
104 | } |
---|
105 | $nb_per_page = (integer) $nb; |
---|
106 | } |
---|
107 | |
---|
108 | # - Status filter |
---|
109 | if ($status !== '' && in_array($status,$status_combo)) { |
---|
110 | $params['tribune_state'] = $status; |
---|
111 | $show_filters = true; |
---|
112 | } |
---|
113 | |
---|
114 | # - IP filter |
---|
115 | if ($ip) { |
---|
116 | $params['tribune_ip'] = $ip; |
---|
117 | $show_filters = true; |
---|
118 | } |
---|
119 | |
---|
120 | if (!in_array($sortby,$sortby_combo)) |
---|
121 | $sortby="tribune_dt"; |
---|
122 | if (!in_array($order,$order_combo)) |
---|
123 | $order="desc"; |
---|
124 | # - Sortby and order filter |
---|
125 | if ($sortby !== '' && in_array($sortby,$sortby_combo)) { |
---|
126 | if ($order !== '' && in_array($order,$order_combo)) { |
---|
127 | $params['order'] = $sortby.' '.$order; |
---|
128 | } |
---|
129 | |
---|
130 | //$show_filters = true; |
---|
131 | } |
---|
132 | |
---|
133 | if (!empty($_POST['actiontribune']) && !empty($_POST['checked'])) |
---|
134 | { |
---|
135 | switch ($_POST['actiontribune']) { |
---|
136 | case 'publish' : $status = 1; break; |
---|
137 | case 'unpublish' : $status = 0; break; |
---|
138 | case 'delete' : $status = -1; break; |
---|
139 | default : $status = 1; break; |
---|
140 | } |
---|
141 | |
---|
142 | if($status >= 0) |
---|
143 | { |
---|
144 | foreach ($_POST['checked'] as $k => $v) |
---|
145 | { |
---|
146 | try { |
---|
147 | $core->tribune->changeState($v, $status); |
---|
148 | } catch (Exception $e) { |
---|
149 | $core->error->add($e->getMessage()); |
---|
150 | break; |
---|
151 | } |
---|
152 | } |
---|
153 | |
---|
154 | if (!$core->error->flag()) { |
---|
155 | http::redirect($p_url.'&msg='.$status); |
---|
156 | } |
---|
157 | } |
---|
158 | else |
---|
159 | { |
---|
160 | foreach ($_POST['checked'] as $k => $v) |
---|
161 | { |
---|
162 | try { |
---|
163 | $core->tribune->delMsg($v); |
---|
164 | } catch (Exception $e) { |
---|
165 | $core->error->add($e->getMessage()); |
---|
166 | break; |
---|
167 | } |
---|
168 | } |
---|
169 | |
---|
170 | if (!$core->error->flag()) { |
---|
171 | http::redirect($p_url.'&removed=1'); |
---|
172 | } |
---|
173 | } |
---|
174 | } |
---|
175 | |
---|
176 | if (!empty($_POST['add_message'])) |
---|
177 | { |
---|
178 | $cur = $core->con->openCursor($core->prefix.'tribune'); |
---|
179 | $cur->tribune_nick = $_POST['tribune_nick']; |
---|
180 | $cur->tribune_msg = $_POST['tribune_msg']; |
---|
181 | |
---|
182 | try { |
---|
183 | $tid = $core->tribune->addMsg($cur); |
---|
184 | http::redirect($p_url.'&addmsg=1'); |
---|
185 | } catch (Exception $e) { |
---|
186 | $core->error->add($e->getMessage()); |
---|
187 | $add_message = true; |
---|
188 | } |
---|
189 | } |
---|
190 | |
---|
191 | if (!empty($_POST['saveconfig'])) |
---|
192 | { |
---|
193 | try |
---|
194 | { |
---|
195 | $tribune_flag = (empty($_POST['tribune_flag']))?false:true; |
---|
196 | |
---|
197 | $core->blog->settings->setNamespace('tribune'); |
---|
198 | $core->blog->settings->put('tribune_flag',$tribune_flag,'boolean','Active the tribune module'); |
---|
199 | $core->blog->triggerBlog(); |
---|
200 | |
---|
201 | $msg = __('Configuration successfully updated.'); |
---|
202 | } |
---|
203 | |
---|
204 | catch (Exception $e) |
---|
205 | { |
---|
206 | $core->error->add($e->getMessage()); |
---|
207 | } |
---|
208 | } |
---|
209 | |
---|
210 | $params['limit'] = array((($page-1)*$nb_per_page),$nb_per_page); |
---|
211 | |
---|
212 | try { |
---|
213 | $rs = $core->tribune->getMsgs($params); |
---|
214 | $count = $core->tribune->getMsgs($params,true); |
---|
215 | $pager = new pager($page,$count->f(0),$nb_per_page); |
---|
216 | $pager->var_page = 'page'; |
---|
217 | } catch (Exception $e) { |
---|
218 | $core->error->add($e->getMessage()); |
---|
219 | } |
---|
220 | ?> |
---|
221 | <html> |
---|
222 | <head> |
---|
223 | <title><?php echo __('Free chatbox'); ?></title> |
---|
224 | <?php echo dcPage::jsToolMan(); |
---|
225 | if (!$show_filters) { |
---|
226 | echo dcPage::jsLoad('js/filter-controls.js'); |
---|
227 | } |
---|
228 | if (!$add_message) { |
---|
229 | echo dcPage::jsLoad('index.php?pf=dctribune/js/_tribune.js'); |
---|
230 | } |
---|
231 | echo dcPage::jsLoad('index.php?pf=dctribune/js/_messages.js'); |
---|
232 | ?> |
---|
233 | |
---|
234 | </head> |
---|
235 | |
---|
236 | <body> |
---|
237 | <h2><?php echo html::escapeHTML($core->blog->name); ?> › <?php echo sprintf(__('Free chatbox (%s messages)'),$count->f(0));?> |
---|
238 | › <a class="button" href="<?php echo $p_url.'&config=1'; ?>"><?php echo html::escapeHTML( |
---|
239 | __('Configuration')); ?></a></h2> |
---|
240 | |
---|
241 | <?php |
---|
242 | if (isset($_GET['removed'])) { |
---|
243 | echo '<p class="message">'.__('Message(s) deleted.').'</p>'; |
---|
244 | } |
---|
245 | |
---|
246 | if (isset($_GET['addmsg'])) { |
---|
247 | echo '<p class="message">'.__('Message added.').'</p>'; |
---|
248 | } |
---|
249 | |
---|
250 | if (isset($_GET['msg'])) { |
---|
251 | if($_GET['msg'] == 0) |
---|
252 | echo '<p class="message">'.__('Message(s) selected offline.').'</p>'; |
---|
253 | else |
---|
254 | echo '<p class="message">'.__('Message(s) selected online.').'</p>'; |
---|
255 | } |
---|
256 | |
---|
257 | ?> |
---|
258 | |
---|
259 | <div id="tribune_add"> |
---|
260 | <?php |
---|
261 | if (!$add_message) { |
---|
262 | echo '<div class="two-cols"><p><strong><a id="tribune-control" href="#">'. |
---|
263 | __('Write a new message').'</a></strong></p></div>'; |
---|
264 | } |
---|
265 | ?> |
---|
266 | |
---|
267 | <?php |
---|
268 | echo |
---|
269 | '<form action="'.$p_url.'" method="post" id="add-message-form">'. |
---|
270 | '<fieldset><legend>'.__('Publish a message').'</legend>'. |
---|
271 | |
---|
272 | '<p><label class="classic required" title="'.__('Required field').'">'.__('Nick:').' '. |
---|
273 | form::field('tribune_nick',30,255,$core->auth->getInfo('user_displayname'),'',7).'</label></p>'. |
---|
274 | |
---|
275 | '<p class="area"><label class="classic required" title="'.__('Required field').'">'.__('Message:').' '. |
---|
276 | form::textarea('tribune_msg',50,3,'','',7).'</label></p>'. |
---|
277 | |
---|
278 | '<p>'.form::hidden(array('p'),'dctribune'). |
---|
279 | $core->formNonce(). |
---|
280 | '<input type="submit" name="add_message" value="'.__('publish').'" /></p>'. |
---|
281 | '</fieldset>'. |
---|
282 | '</form>'. |
---|
283 | '</div>'; |
---|
284 | ?> |
---|
285 | <div id="tribune_messages"> |
---|
286 | <?php |
---|
287 | if (!$show_filters) { |
---|
288 | echo '<p><a id="filter-control" class="form-control" href="#">'. |
---|
289 | __('Filters').'</a></p>'; |
---|
290 | } |
---|
291 | |
---|
292 | echo |
---|
293 | '<form action="plugin.php" method="get" id="filters-form">'. |
---|
294 | '<fieldset><legend>'.__('Filters').'</legend>'. |
---|
295 | |
---|
296 | '<div class="three-cols">'. |
---|
297 | |
---|
298 | '<div class="col">'. |
---|
299 | '<p><label>'.__('Status:'). |
---|
300 | form::combo('status',$status_combo,$status). |
---|
301 | '</label>'. |
---|
302 | '<label>'.__('IP address:'). |
---|
303 | form::field('ip',20,39,html::escapeHTML($ip)). |
---|
304 | '</label>'. |
---|
305 | '</p> '. |
---|
306 | '</div>'. |
---|
307 | |
---|
308 | '<div class="col">'. |
---|
309 | '<p><label>'.__('Order by:'). |
---|
310 | form::combo('sortby',$sortby_combo,$sortby). |
---|
311 | '</label></p> '. |
---|
312 | '<p><label class="classic">'. form::field('nb',3,3,$nb_per_page).' '. |
---|
313 | __('Messages per page').'</label></p>'. |
---|
314 | '</div>'. |
---|
315 | |
---|
316 | '<div class="col">'. |
---|
317 | '<p><label>'.__('Sort:'). |
---|
318 | form::combo('order',$order_combo,$order). |
---|
319 | '</label></p>'. |
---|
320 | '<p><input type="hidden" name="p" value="dctribune" />'. |
---|
321 | '<input type="submit" name="filter" value="'.__('filter').'" /></p>'. |
---|
322 | '</div>'. |
---|
323 | |
---|
324 | '</div>'. |
---|
325 | |
---|
326 | '<hr class="clear" />'. //Opera sucks |
---|
327 | |
---|
328 | '</fieldset>'. |
---|
329 | '</form>'. |
---|
330 | '</div>'; |
---|
331 | ?> |
---|
332 | |
---|
333 | <div id="tribune_list"> |
---|
334 | <form action="plugin.php" method="post" id="tribune-form"> |
---|
335 | <table class="maximal"> |
---|
336 | <thead> |
---|
337 | <tr> |
---|
338 | <th colspan="2"><?php echo __('Nick'); ?></th> |
---|
339 | <th><?php echo __('Message'); ?></th> |
---|
340 | <th><?php echo __('IP'); ?></th> |
---|
341 | <th><?php echo __('Date'); ?></th> |
---|
342 | <th><?php echo __('Status'); ?></th> |
---|
343 | <th> </th> |
---|
344 | </tr> |
---|
345 | </thead> |
---|
346 | <tbody id="tribune-list"> |
---|
347 | <?php |
---|
348 | while ($rs->fetch()) |
---|
349 | { |
---|
350 | if($rs->tribune_state == 0) { |
---|
351 | $line = 'offline'; |
---|
352 | $status = '<img alt="'.__('unpublished').'" title="'.__('unpublished').'" src="images/check-off.png" />'; |
---|
353 | } |
---|
354 | else |
---|
355 | { |
---|
356 | $line = ''; |
---|
357 | $status = '<img alt="'.__('published').'" title="'.__('published').'" src="images/check-on.png" />'; |
---|
358 | } |
---|
359 | $edit = '<a href="'.$p_url.'&edit=1&id='.$rs->tribune_id.'"><img src="images/edit-mini.png" alt="" title="'.__('modify this message').'" /></a>'; |
---|
360 | echo |
---|
361 | '<tr class="line '.$line.'" id="l_'.$rs->tribune_id.'">'. |
---|
362 | '<td class="minimal">'.form::checkbox(array('checked[]'),$rs->tribune_id).'</td>'. |
---|
363 | '<td>'.html::escapeHTML($rs->tribune_nick).'</td>'. |
---|
364 | '<td class="maximal">'.html::decodeEntities(html::clean($rs->tribune_msg)).'</td>'. |
---|
365 | '<td>'.html::escapeHTML($rs->tribune_ip).'</td>'. |
---|
366 | '<td class="nowrap">'.dt::dt2str(__('%Y-%m-%d %H:%M'),$rs->tribune_dt).'</td>'. |
---|
367 | '<td class="nowrap status">'.$status.'</td>'. |
---|
368 | '<td class="nowrap status">'.$edit.'</td>'. |
---|
369 | '</tr>' |
---|
370 | ; |
---|
371 | } |
---|
372 | ?> |
---|
373 | </tbody> |
---|
374 | </table> |
---|
375 | |
---|
376 | <div class="two-cols"> |
---|
377 | <?php echo '<p class="col checkboxes-helpers"></p>';?> |
---|
378 | <?php echo |
---|
379 | '<p class="col right">'.__('Selected messages action:').' '. |
---|
380 | form::hidden(array('p'),'dctribune'). |
---|
381 | form::combo('actiontribune',$combo_action). |
---|
382 | $core->formNonce(). |
---|
383 | '<input type="submit" value="'.__('ok').'" /></p>'; |
---|
384 | ?> |
---|
385 | </div> |
---|
386 | |
---|
387 | </form> |
---|
388 | <?php echo '<p>'.__('Page(s)').' : '.$pager->getLinks().'</p>';?> |
---|
389 | </div> |
---|
390 | |
---|
391 | </body> |
---|
392 | </html> |
---|