1 | <?php |
---|
2 | # -- BEGIN LICENSE BLOCK --------------------------------------- |
---|
3 | # |
---|
4 | # This file is part of Dotclear 2. |
---|
5 | # |
---|
6 | # Copyright (c) 2003-2010 Olivier Meunier & Association Dotclear |
---|
7 | # Licensed under the GPL version 2.0 license. |
---|
8 | # See LICENSE file or |
---|
9 | # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
---|
10 | # |
---|
11 | # -- END LICENSE BLOCK ----------------------------------------- |
---|
12 | if (!defined('DC_RC_PATH')) { return; } |
---|
13 | |
---|
14 | class adminGenericColumn |
---|
15 | { |
---|
16 | protected $core; |
---|
17 | protected $rs; |
---|
18 | protected $id; |
---|
19 | protected $title; |
---|
20 | protected $callback; |
---|
21 | protected $html; |
---|
22 | protected $order; |
---|
23 | protected $visibility; |
---|
24 | |
---|
25 | public function __construct($id,$title,$callback,$html = null,$order = null) |
---|
26 | { |
---|
27 | if (!is_string($id) || $id === '') { |
---|
28 | throw new Exception(__('Invalid column ID')); |
---|
29 | } |
---|
30 | |
---|
31 | if (!is_string($title)) { |
---|
32 | throw new Exception(__('Invalid column title')); |
---|
33 | } |
---|
34 | if (is_null($html) || !is_string($html)) { |
---|
35 | $html = ''; |
---|
36 | } |
---|
37 | if (!is_int($order)) { |
---|
38 | $order = null; |
---|
39 | } |
---|
40 | |
---|
41 | try { |
---|
42 | $r = new ReflectionClass($callback[0]); |
---|
43 | $f = $r->getMethod($callback[1]); |
---|
44 | $p = $r->getParentClass(); |
---|
45 | if (!$p || $p->name != 'adminGenericList') { |
---|
46 | throw new Exception(__('Invalid callback')); |
---|
47 | } |
---|
48 | } |
---|
49 | catch (Exception $e) { |
---|
50 | throw new Exception(__('Invalid callback')); |
---|
51 | } |
---|
52 | |
---|
53 | $this->id = $id; |
---|
54 | $this->title = $title; |
---|
55 | $this->callback = $callback; |
---|
56 | $this->html = $html; |
---|
57 | $this->order = $order; |
---|
58 | $this->visibility = true; |
---|
59 | } |
---|
60 | |
---|
61 | public function getInfo($k) |
---|
62 | { |
---|
63 | return property_exists(get_class($this),$k) ? $this->{$k} : null; |
---|
64 | } |
---|
65 | |
---|
66 | public function setVisibility($visibility) |
---|
67 | { |
---|
68 | if (is_bool($visibility)) { |
---|
69 | $this->visibility = $visibility; |
---|
70 | } |
---|
71 | } |
---|
72 | |
---|
73 | public function isVisible() |
---|
74 | { |
---|
75 | return $this->visibility; |
---|
76 | } |
---|
77 | } |
---|
78 | |
---|
79 | class adminGenericList |
---|
80 | { |
---|
81 | protected $core; |
---|
82 | protected $rs; |
---|
83 | protected $rs_count; |
---|
84 | protected $columns; |
---|
85 | |
---|
86 | |
---|
87 | public function __construct($core,$rs,$rs_count) |
---|
88 | { |
---|
89 | $this->core =& $core; |
---|
90 | $this->rs =& $rs; |
---|
91 | $this->rs_count = $rs_count; |
---|
92 | $this->context = get_class($this); |
---|
93 | $this->columns = array(); |
---|
94 | $this->column_pattern = 'c_%s'; |
---|
95 | |
---|
96 | $this->html_prev = __('«prev.'); |
---|
97 | $this->html_next = __('next»'); |
---|
98 | |
---|
99 | # Post columns |
---|
100 | $this->addColumn('adminPostList','title',__('Title'),array('adminPostList','getTitle')); |
---|
101 | $this->addColumn('adminPostList','date',__('Date'),array('adminPostList','getDate')); |
---|
102 | $this->addColumn('adminPostList','category',__('Category'),array('adminPostList','getCategory')); |
---|
103 | $this->addColumn('adminPostList','author',__('Author'),array('adminPostList','getAuthor')); |
---|
104 | $this->addColumn('adminPostList','comment',__('Comments'),array('adminPostList','getComments')); |
---|
105 | $this->addColumn('adminPostList','trackback',__('Trackbacks'),array('adminPostList','getTrackbacks')); |
---|
106 | $this->addColumn('adminPostList','status',__('Status'),array('adminPostList','getStatus')); |
---|
107 | |
---|
108 | # Post (mini list) columns |
---|
109 | $this->addColumn('adminPostMiniList','title',__('Title'),array('adminPostList','getTitle')); |
---|
110 | $this->addColumn('adminPostMiniList','date',__('Date'),array('adminPostList','getDate')); |
---|
111 | $this->addColumn('adminPostMiniList','author',__('Author'),array('adminPostList','getAuthor')); |
---|
112 | $this->addColumn('adminPostMiniList','status',__('Status'),array('adminPostList','getStatus')); |
---|
113 | |
---|
114 | # Comment columns |
---|
115 | $this->addColumn('adminCommentList','title',__('Title'),array('adminCommentList','getTitle')); |
---|
116 | $this->addColumn('adminCommentList','date',__('Date'),array('adminCommentList','getDate')); |
---|
117 | $this->addColumn('adminCommentList','author',__('Author'),array('adminCommentList','getAuthor')); |
---|
118 | $this->addColumn('adminCommentList','type',__('Type'),array('adminCommentList','getType')); |
---|
119 | $this->addColumn('adminCommentList','status',__('Status'),array('adminCommentList','getStatus')); |
---|
120 | $this->addColumn('adminCommentList','edit','',array('adminCommentList','getEdit')); |
---|
121 | |
---|
122 | # Comment columns |
---|
123 | $this->addColumn('adminUserList','username',__('Username'),array('adminUserList','getUserName')); |
---|
124 | $this->addColumn('adminUserList','firstname',__('First name'),array('adminUserList','getFirstName')); |
---|
125 | $this->addColumn('adminUserList','lastname',__('Last name'),array('adminUserList','getLastName')); |
---|
126 | $this->addColumn('adminUserList','displayname',__('Display name'),array('adminUserList','getDisplayName')); |
---|
127 | $this->addColumn('adminUserList','entries',__('Entries'),array('adminUserList','getEntries')); |
---|
128 | |
---|
129 | $this->setColumnsVisibility(); |
---|
130 | |
---|
131 | $core->callBehavior('adminGenericListConstruct',$this); |
---|
132 | } |
---|
133 | |
---|
134 | public function addColumn($context,$id,$title,$callback,$html = null,$order = null) |
---|
135 | { |
---|
136 | try { |
---|
137 | if (!array_key_exists($context,$this->columns)) { |
---|
138 | $this->columns[$context] = array(); |
---|
139 | } |
---|
140 | |
---|
141 | $c = new adminGenericColumn($id,$title,$callback,$html,$order); |
---|
142 | $this->columns[$context][$c->getInfo('id')] = $c; |
---|
143 | } |
---|
144 | catch (Exception $e) { |
---|
145 | if (DC_DEBUG) { |
---|
146 | $this->core->error->add($e->getMessage()); |
---|
147 | } |
---|
148 | } |
---|
149 | } |
---|
150 | |
---|
151 | public function setColumnsVisibility() |
---|
152 | { |
---|
153 | foreach ($this->columns[$this->context] as $k => $v) { |
---|
154 | $key = sprintf($this->column_pattern,$k); |
---|
155 | if (array_key_exists($key,$_REQUEST)) { |
---|
156 | $v->setVisibility((bool) $key); |
---|
157 | } |
---|
158 | } |
---|
159 | } |
---|
160 | |
---|
161 | public function display($page,$nb_per_page,$enclose_block='') |
---|
162 | { |
---|
163 | if ($this->rs->isEmpty()) |
---|
164 | { |
---|
165 | echo '<p><strong>'.__('No entry').'</strong></p>'; |
---|
166 | } |
---|
167 | else |
---|
168 | { |
---|
169 | $pager = new pager($page,$this->rs_count,$nb_per_page,10); |
---|
170 | $pager->html_prev = $this->html_prev; |
---|
171 | $pager->html_next = $this->html_next; |
---|
172 | $pager->var_page = 'page'; |
---|
173 | |
---|
174 | $html_block = '<table class="clear"><tr>'; |
---|
175 | |
---|
176 | foreach ($this->columns[$this->context] as $k => $v) { |
---|
177 | if ($v->isVisible()) { |
---|
178 | $html_block .= sprintf('<th%s>%s</th>',$v->getInfo('html'),$v->getInfo('title')); |
---|
179 | } |
---|
180 | } |
---|
181 | |
---|
182 | $html_block .= '</tr>%s</table>'; |
---|
183 | |
---|
184 | if ($enclose_block) { |
---|
185 | $html_block = sprintf($enclose_block,$html_block); |
---|
186 | } |
---|
187 | |
---|
188 | echo '<p>'.__('Page(s)').' : '.$pager->getLinks().'</p>'; |
---|
189 | |
---|
190 | $blocks = explode('%s',$html_block); |
---|
191 | |
---|
192 | echo $blocks[0]; |
---|
193 | |
---|
194 | while ($this->rs->fetch()) |
---|
195 | { |
---|
196 | echo $this->displayLine(); |
---|
197 | } |
---|
198 | |
---|
199 | echo $blocks[1]; |
---|
200 | |
---|
201 | echo '<p>'.__('Page(s)').' : '.$pager->getLinks().'</p>'; |
---|
202 | } |
---|
203 | } |
---|
204 | |
---|
205 | private function displayLine() |
---|
206 | { |
---|
207 | $res = ''; |
---|
208 | |
---|
209 | foreach ($this->columns[$this->context] as $k => $v) { |
---|
210 | if ($v->isVisible()) { |
---|
211 | $c = $v->getInfo('callback'); |
---|
212 | $func = $c[1]; |
---|
213 | $res .= $this->{$c[1]}(); |
---|
214 | } |
---|
215 | } |
---|
216 | |
---|
217 | return sprintf($this->getDefaultLine(),$res); |
---|
218 | } |
---|
219 | |
---|
220 | protected function getDefaultLine() |
---|
221 | { |
---|
222 | return '<tr class="line">%s</tr>'; |
---|
223 | } |
---|
224 | } |
---|
225 | |
---|
226 | class adminPostList extends adminGenericList |
---|
227 | { |
---|
228 | protected function getDefaultLine() |
---|
229 | { |
---|
230 | return |
---|
231 | '<tr class="line'.($this->rs->post_status != 1 ? ' offline' : '').'"'. |
---|
232 | ' id="p'.$this->rs->post_id.'">%s</tr>'; |
---|
233 | } |
---|
234 | |
---|
235 | protected function getTitle() |
---|
236 | { |
---|
237 | return |
---|
238 | '<td class="maximal">'. |
---|
239 | form::checkbox(array('entries[]'),$this->rs->post_id,'','','',!$this->rs->isEditable()).' '. |
---|
240 | '<a href="'.$this->core->getPostAdminURL($this->rs->post_type,$this->rs->post_id).'">'. |
---|
241 | html::escapeHTML($this->rs->post_title).'</a></td>'; |
---|
242 | } |
---|
243 | |
---|
244 | protected function getDate() |
---|
245 | { |
---|
246 | return '<td class="nowrap">'.dt::dt2str(__('%Y-%m-%d %H:%M'),$this->rs->post_dt).'</td>'; |
---|
247 | } |
---|
248 | |
---|
249 | protected function getCategory() |
---|
250 | { |
---|
251 | if ($this->core->auth->check('categories',$this->core->blog->id)) { |
---|
252 | $cat_link = '<a href="category.php?id=%s">%s</a>'; |
---|
253 | } else { |
---|
254 | $cat_link = '%2$s'; |
---|
255 | } |
---|
256 | |
---|
257 | if ($this->rs->cat_title) { |
---|
258 | $cat_title = sprintf($cat_link,$this->rs->cat_id, |
---|
259 | html::escapeHTML($this->rs->cat_title)); |
---|
260 | } else { |
---|
261 | $cat_title = __('None'); |
---|
262 | } |
---|
263 | |
---|
264 | return '<td class="nowrap">'.$cat_title.'</td>'; |
---|
265 | } |
---|
266 | |
---|
267 | protected function getAuthor() |
---|
268 | { |
---|
269 | return '<td class="nowrap">'.$this->rs->user_id.'</td>'; |
---|
270 | } |
---|
271 | |
---|
272 | protected function getComments() |
---|
273 | { |
---|
274 | return '<td class="nowrap">'.$this->rs->nb_comment.'</td>'; |
---|
275 | } |
---|
276 | |
---|
277 | protected function getTrackbacks() |
---|
278 | { |
---|
279 | return '<td class="nowrap">'.$this->rs->nb_trackback.'</td>'; |
---|
280 | } |
---|
281 | |
---|
282 | protected function getStatus() |
---|
283 | { |
---|
284 | $img = '<img alt="%1$s" title="%1$s" src="images/%2$s" />'; |
---|
285 | switch ($this->rs->post_status) { |
---|
286 | case 1: |
---|
287 | $img_status = sprintf($img,__('published'),'check-on.png'); |
---|
288 | break; |
---|
289 | case 0: |
---|
290 | $img_status = sprintf($img,__('unpublished'),'check-off.png'); |
---|
291 | break; |
---|
292 | case -1: |
---|
293 | $img_status = sprintf($img,__('scheduled'),'scheduled.png'); |
---|
294 | break; |
---|
295 | case -2: |
---|
296 | $img_status = sprintf($img,__('pending'),'check-wrn.png'); |
---|
297 | break; |
---|
298 | } |
---|
299 | |
---|
300 | $protected = ''; |
---|
301 | if ($this->rs->post_password) { |
---|
302 | $protected = sprintf($img,__('protected'),'locker.png'); |
---|
303 | } |
---|
304 | |
---|
305 | $selected = ''; |
---|
306 | if ($this->rs->post_selected) { |
---|
307 | $selected = sprintf($img,__('selected'),'selected.png'); |
---|
308 | } |
---|
309 | |
---|
310 | $attach = ''; |
---|
311 | $nb_media = $this->rs->countMedia(); |
---|
312 | if ($nb_media > 0) { |
---|
313 | $attach_str = $nb_media == 1 ? __('%d attachment') : __('%d attachments'); |
---|
314 | $attach = sprintf($img,sprintf($attach_str,$nb_media),'attach.png'); |
---|
315 | } |
---|
316 | |
---|
317 | return '<td class="nowrap status">'.$img_status.' '.$selected.' '.$protected.' '.$attach.'</td>'; |
---|
318 | } |
---|
319 | } |
---|
320 | |
---|
321 | class adminPostMiniList extends adminPostList{} |
---|
322 | |
---|
323 | class adminCommentList extends adminGenericList |
---|
324 | { |
---|
325 | protected function getDefaultLine() |
---|
326 | { |
---|
327 | return |
---|
328 | '<tr class="line'.($this->rs->comment_status != 1 ? ' offline' : '').'"'. |
---|
329 | ' id="c'.$this->rs->comment_id.'">%s</tr>'; |
---|
330 | } |
---|
331 | |
---|
332 | protected function getContent() |
---|
333 | { |
---|
334 | return |
---|
335 | '<tr class="line'.($this->rs->comment_status != 1 ? ' offline' : '').'"'. |
---|
336 | ' id="c'.$this->rs->comment_id.'">%s</tr>'; |
---|
337 | } |
---|
338 | |
---|
339 | protected function getTitle() |
---|
340 | { |
---|
341 | $post_url = $this->core->getPostAdminURL($this->rs->post_type,$this->rs->post_id); |
---|
342 | |
---|
343 | return |
---|
344 | '<td class="maximal"><a href="'.$post_url.'">'. |
---|
345 | html::escapeHTML($this->rs->post_title).'</a>'. |
---|
346 | ($this->rs->post_type != 'post' ? ' ('.html::escapeHTML($this->rs->post_type).')' : '').'</td>'; |
---|
347 | } |
---|
348 | |
---|
349 | protected function getDate() |
---|
350 | { |
---|
351 | return '<td class="nowrap">'.dt::dt2str(__('%Y-%m-%d %H:%M'),$this->rs->comment_dt).'</td>'; |
---|
352 | } |
---|
353 | |
---|
354 | protected function getAuthor() |
---|
355 | { |
---|
356 | global $author, $status, $sortby, $order, $nb_per_page; |
---|
357 | |
---|
358 | $author_url = |
---|
359 | 'comments.php?n='.$nb_per_page. |
---|
360 | '&status='.$status. |
---|
361 | '&sortby='.$sortby. |
---|
362 | '&order='.$order. |
---|
363 | '&author='.rawurlencode($this->rs->comment_author); |
---|
364 | |
---|
365 | $comment_author = html::escapeHTML($this->rs->comment_author); |
---|
366 | if (mb_strlen($comment_author) > 20) { |
---|
367 | $comment_author = mb_strcut($comment_author,0,17).'...'; |
---|
368 | } |
---|
369 | |
---|
370 | return '<td class="nowrap"><a href="'.$author_url.'">'.$comment_author.'</a></td>'; |
---|
371 | } |
---|
372 | |
---|
373 | protected function getType() |
---|
374 | { |
---|
375 | return '<td class="nowrap">'.($this->rs->comment_trackback ? __('trackback') : __('comment')).'</td>'; |
---|
376 | } |
---|
377 | |
---|
378 | protected function getStatus() |
---|
379 | { |
---|
380 | $img = '<img alt="%1$s" title="%1$s" src="images/%2$s" />'; |
---|
381 | switch ($this->rs->comment_status) { |
---|
382 | case 1: |
---|
383 | $img_status = sprintf($img,__('published'),'check-on.png'); |
---|
384 | break; |
---|
385 | case 0: |
---|
386 | $img_status = sprintf($img,__('unpublished'),'check-off.png'); |
---|
387 | break; |
---|
388 | case -1: |
---|
389 | $img_status = sprintf($img,__('pending'),'check-wrn.png'); |
---|
390 | break; |
---|
391 | case -2: |
---|
392 | $img_status = sprintf($img,__('junk'),'junk.png'); |
---|
393 | break; |
---|
394 | } |
---|
395 | |
---|
396 | return '<td class="nowrap status">'.$img_status.'</td>'; |
---|
397 | } |
---|
398 | |
---|
399 | protected function getEdit() |
---|
400 | { |
---|
401 | $comment_url = 'comment.php?id='.$this->rs->comment_id; |
---|
402 | |
---|
403 | return |
---|
404 | '<td class="nowrap status"><a href="'.$comment_url.'">'. |
---|
405 | '<img src="images/edit-mini.png" alt="" title="'.__('Edit this comment').'" /></a></td>'; |
---|
406 | } |
---|
407 | } |
---|
408 | |
---|
409 | class adminUserList extends adminGenericList |
---|
410 | { |
---|
411 | protected function getUserName() |
---|
412 | { |
---|
413 | $img = '<img alt="%1$s" title="%1$s" src="images/%2$s" />'; |
---|
414 | $img_status = ''; |
---|
415 | |
---|
416 | $p = $this->core->getUserPermissions($this->rs->user_id); |
---|
417 | |
---|
418 | if (isset($p[$this->core->blog->id]['p']['admin'])) { |
---|
419 | $img_status = sprintf($img,__('admin'),'admin.png'); |
---|
420 | } |
---|
421 | if ($this->rs->user_super) { |
---|
422 | $img_status = sprintf($img,__('superadmin'),'superadmin.png'); |
---|
423 | } |
---|
424 | |
---|
425 | return |
---|
426 | '<td class="maximal">'.form::hidden(array('nb_post[]'),(integer) $this->rs->nb_post). |
---|
427 | form::checkbox(array('user_id[]'),$this->rs->user_id). |
---|
428 | '<a href="user.php?id='.$this->rs->user_id.'">'. |
---|
429 | $this->rs->user_id.'</a> '.$img_status.'</td>'; |
---|
430 | } |
---|
431 | |
---|
432 | protected function getFirstName() |
---|
433 | { |
---|
434 | return '<td class="nowrap">'.$this->rs->user_firstname.'</td>'; |
---|
435 | } |
---|
436 | |
---|
437 | protected function getLastName() |
---|
438 | { |
---|
439 | return '<td class="nowrap">'.$this->rs->user_name.'</td>'; |
---|
440 | } |
---|
441 | |
---|
442 | protected function getDisplayName() |
---|
443 | { |
---|
444 | return '<td class="nowrap">'.$this->rs->user_displayname.'</td>'; |
---|
445 | } |
---|
446 | |
---|
447 | protected function getEntries() |
---|
448 | { |
---|
449 | return |
---|
450 | '<td class="nowrap"><a href="posts.php?user_id='.$this->rs->user_id.'">'. |
---|
451 | $this->rs->nb_post.'</a></td>'; |
---|
452 | } |
---|
453 | } |
---|
454 | |
---|
455 | ?> |
---|