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 | /** |
---|
15 | @ingroup DC_CORE |
---|
16 | @nosubgrouping |
---|
17 | @brief Dotclear Pager class. |
---|
18 | |
---|
19 | Dotclear Pager handles pagination for every admin list. |
---|
20 | */ |
---|
21 | class dcPager extends pager |
---|
22 | { |
---|
23 | public function getLinks() |
---|
24 | { |
---|
25 | $htmlText = ''; |
---|
26 | $htmlStart = ''; |
---|
27 | $htmlEnd = ''; |
---|
28 | $htmlPrev = ''; |
---|
29 | $htmlNext = ''; |
---|
30 | $htmlDirectAccess = ''; |
---|
31 | $htmlHidden = ''; |
---|
32 | |
---|
33 | $this->setURL(); |
---|
34 | |
---|
35 | # Page text |
---|
36 | $htmlText = '<span>'.sprintf(__('Page %s over %s'),$this->env,$this->nb_pages).'</span>'; |
---|
37 | |
---|
38 | # Previous page |
---|
39 | if($this->env != 1) { |
---|
40 | $htmlPrev = '<a href="'.sprintf($this->page_url,$this->env-1).'" class="prev">'. |
---|
41 | $htmlPrev .= $this->html_prev.'</a>'; |
---|
42 | } |
---|
43 | |
---|
44 | # Next page |
---|
45 | if($this->env != $this->nb_pages) { |
---|
46 | $htmlNext = '<a href="'.sprintf($this->page_url,$this->env+1).'" class="next">'; |
---|
47 | $htmlNext .= $this->html_next.'</a>'; |
---|
48 | } |
---|
49 | |
---|
50 | # Start |
---|
51 | if($this->env != 1) { |
---|
52 | $htmlStart = '<a href="'.sprintf($this->page_url,1).'" class="start">'. |
---|
53 | $htmlStart .= $this->html_start.'</a>'; |
---|
54 | } |
---|
55 | |
---|
56 | # End |
---|
57 | if($this->env != $this->nb_pages) { |
---|
58 | $htmlEnd = '<a href="'.sprintf($this->page_url,$this->nb_elements).'" class="end">'. |
---|
59 | $htmlEnd .= $this->html_end.'</a>'; |
---|
60 | } |
---|
61 | |
---|
62 | # Direct acces |
---|
63 | $htmlDirectAccess = |
---|
64 | '<span>'.__('Direct access to page').' '. |
---|
65 | form::field(array('page'),3,3,$this->env).' '. |
---|
66 | '<input type="submit" value="'.__('ok').'" />'. |
---|
67 | '</span>'; |
---|
68 | |
---|
69 | # Hidden fields |
---|
70 | foreach ($_GET as $k => $v) { |
---|
71 | if ($k != $this->var_page) { |
---|
72 | $htmlHidden .= form::hidden(array($k),$v); |
---|
73 | } |
---|
74 | } |
---|
75 | |
---|
76 | $res = |
---|
77 | '<form method="get" action="'.$this->base_url.'"><p>'. |
---|
78 | $htmlStart. |
---|
79 | $htmlPrev. |
---|
80 | $htmlText. |
---|
81 | $htmlNext. |
---|
82 | $htmlEnd. |
---|
83 | $htmlDirectAccess. |
---|
84 | $htmlHidden. |
---|
85 | '</p></form>'; |
---|
86 | |
---|
87 | return $this->nb_elements > 0 ? $res : ''; |
---|
88 | } |
---|
89 | } |
---|
90 | |
---|
91 | /** |
---|
92 | @ingroup DC_CORE |
---|
93 | @nosubgrouping |
---|
94 | @brief Dotclear Generic column class. |
---|
95 | |
---|
96 | Dotclear Generic column handles each column object use in adminGenericList class. |
---|
97 | */ |
---|
98 | class adminGenericColumn |
---|
99 | { |
---|
100 | protected $core; /// <b>object</b> dcCore object |
---|
101 | protected $id; /// <b>string</b> ID of defined column |
---|
102 | protected $title; /// <b>string</b> Title of defined column |
---|
103 | protected $callback; /// <b>array</b> Callback calls to display defined column |
---|
104 | protected $html; /// <b>string</b> Extra HTML for defined column |
---|
105 | protected $visibility; /// <b>boolean</b> Visibility of defined column |
---|
106 | |
---|
107 | /** |
---|
108 | Inits Generic column object |
---|
109 | |
---|
110 | @param id <b>string</b> Column id |
---|
111 | @param title <b>string</b> Column title (for table headers) |
---|
112 | @param callback <b>array</b> Column callback (used for display) |
---|
113 | @param html <b>string</b> Extra html (used for table headers) |
---|
114 | @param can_hide <b>boolean</b> Defines if the column can be hidden or not |
---|
115 | */ |
---|
116 | public function __construct($id,$title,$callback,$html = null,$can_hide = true) |
---|
117 | { |
---|
118 | if (!is_string($id) || $id === '') { |
---|
119 | throw new Exception(__('Invalid column ID')); |
---|
120 | } |
---|
121 | |
---|
122 | if (!is_string($title)) { |
---|
123 | throw new Exception(__('Invalid column title')); |
---|
124 | } |
---|
125 | |
---|
126 | if (is_null($html) || !is_string($html)) { |
---|
127 | $html = ''; |
---|
128 | } |
---|
129 | if (!empty($html)) { |
---|
130 | $html = ' '.$html; |
---|
131 | } |
---|
132 | |
---|
133 | if (!is_bool($can_hide)) { |
---|
134 | $can_hide = true; |
---|
135 | } |
---|
136 | |
---|
137 | try { |
---|
138 | if (!is_array($callback) || count($callback) < 2) { |
---|
139 | throw new Exception(__('Callback parameter should be an array')); |
---|
140 | } |
---|
141 | $r = new ReflectionClass($callback[0]); |
---|
142 | $f = $r->getMethod($callback[1]); |
---|
143 | $p = $r->getParentClass(); |
---|
144 | $find_parent = false; |
---|
145 | |
---|
146 | while (!$p) { |
---|
147 | if ($p->name == 'adminGenericList') { |
---|
148 | $find_parent = true; |
---|
149 | } |
---|
150 | else { |
---|
151 | $p->getParentClass(); |
---|
152 | } |
---|
153 | } |
---|
154 | |
---|
155 | if (!$p || !$f) { |
---|
156 | throw new Exception(__('Callback class should be inherited of adminGenericList class')); |
---|
157 | } |
---|
158 | } |
---|
159 | catch (Exception $e) { |
---|
160 | throw new Exception(sprintf(__('Invalid column callback: %s'),$e->getMessage())); |
---|
161 | } |
---|
162 | |
---|
163 | $this->id = $id; |
---|
164 | $this->title = $title; |
---|
165 | $this->callback = $callback; |
---|
166 | $this->html = $html; |
---|
167 | $this->can_hide = $can_hide; |
---|
168 | $this->visibility = true; |
---|
169 | } |
---|
170 | |
---|
171 | /** |
---|
172 | Gets information of defined column |
---|
173 | |
---|
174 | @param info <b>string</b> Column info to retrive |
---|
175 | |
---|
176 | @return <b>mixed</b> The information requested, null otherwise |
---|
177 | */ |
---|
178 | public function getInfo($info) |
---|
179 | { |
---|
180 | return property_exists(get_class($this),$info) ? $this->{$info} : null; |
---|
181 | } |
---|
182 | |
---|
183 | /** |
---|
184 | Sets visibility of defined column |
---|
185 | |
---|
186 | @param visibility <b>boolean</b> Column visibility |
---|
187 | */ |
---|
188 | public function setVisibility($visibility) |
---|
189 | { |
---|
190 | if (is_bool($visibility)) { |
---|
191 | $this->visibility = $visibility; |
---|
192 | } |
---|
193 | } |
---|
194 | |
---|
195 | /** |
---|
196 | Returns visibility status of defined column |
---|
197 | |
---|
198 | @return <b>boolean</b> true if column is visible, false otherwise |
---|
199 | */ |
---|
200 | public function isVisible() |
---|
201 | { |
---|
202 | return $this->visibility; |
---|
203 | } |
---|
204 | |
---|
205 | /** |
---|
206 | Returns if the defined column can be hidden |
---|
207 | |
---|
208 | @return <b>boolean</b> true if column can be hidden, false otherwise |
---|
209 | */ |
---|
210 | public function canHide() |
---|
211 | { |
---|
212 | return $this->can_hide; |
---|
213 | } |
---|
214 | } |
---|
215 | |
---|
216 | /** |
---|
217 | @ingroup DC_CORE |
---|
218 | @nosubgrouping |
---|
219 | @brief abstract Generic list class. |
---|
220 | |
---|
221 | Dotclear Generic list handles administration lists |
---|
222 | */ |
---|
223 | abstract class adminGenericList |
---|
224 | { |
---|
225 | protected $core; |
---|
226 | protected $rs; |
---|
227 | protected $rs_count; |
---|
228 | protected $columns; |
---|
229 | |
---|
230 | /* |
---|
231 | Sets columns of defined list |
---|
232 | */ |
---|
233 | public function setColumns() {} |
---|
234 | |
---|
235 | /** |
---|
236 | Inits List object |
---|
237 | |
---|
238 | @param core <b>dcCore</b> dcCore object |
---|
239 | @param rs <b>recordSet</b> Items recordSet to display |
---|
240 | @param rs_count <b>int</b> Total items number |
---|
241 | */ |
---|
242 | public function __construct($core,$rs,$rs_count) |
---|
243 | { |
---|
244 | $this->core =& $core; |
---|
245 | $this->rs =& $rs; |
---|
246 | $this->rs_count = $rs_count; |
---|
247 | $this->context = get_class($this); |
---|
248 | $this->columns = array(); |
---|
249 | $this->form_prefix = 'col_%s'; |
---|
250 | $this->form_trigger = 'add_filter'; |
---|
251 | |
---|
252 | $this->html_prev = __('prev'); |
---|
253 | $this->html_next = __('next'); |
---|
254 | $this->html_start = __('start'); |
---|
255 | $this->html_end = __('end'); |
---|
256 | |
---|
257 | $this->setColumns(); |
---|
258 | |
---|
259 | $core->callBehavior('adminListConstruct',$this); |
---|
260 | |
---|
261 | $this->setColumnsVisibility(); |
---|
262 | } |
---|
263 | |
---|
264 | /** |
---|
265 | Returns HTML code form used to choose which column to display |
---|
266 | |
---|
267 | @return <b>string</b> HTML code form |
---|
268 | */ |
---|
269 | public function getColumnsForm() |
---|
270 | { |
---|
271 | $block = |
---|
272 | '<h3>'.__('Displayed information').'</h3>'. |
---|
273 | '<ul>%s</ul>'; |
---|
274 | |
---|
275 | $list = array(); |
---|
276 | |
---|
277 | foreach ($this->columns as $k => $v) { |
---|
278 | $col_id = sprintf($this->form_prefix,$k); |
---|
279 | $col_label = sprintf('<label for="%s">%s</label>',$col_id,$v->getInfo('title')); |
---|
280 | $col_html = sprintf('<li class="line">%s</li>',$col_label.form::checkbox($col_id,1,$v->isVisible(),null,null,!$v->canHide())); |
---|
281 | |
---|
282 | array_push($list,$col_html); |
---|
283 | } |
---|
284 | |
---|
285 | $nb_per_page = isset($_GET['nb']) ? $_GET['nb'] : 10; |
---|
286 | |
---|
287 | return |
---|
288 | sprintf($block,implode('',$list)). |
---|
289 | '<p><label for="nb">'.__('Items per page:'). |
---|
290 | '</label> '.form::field('nb',3,3,$nb_per_page). |
---|
291 | '</p>'; |
---|
292 | } |
---|
293 | |
---|
294 | /** |
---|
295 | Returns HTML code list to display |
---|
296 | |
---|
297 | @param page <b>string|int</b> Current page |
---|
298 | @param nb_per_page <b>string|int</b> Number of items to display in each page |
---|
299 | @param enclose_block <b>string</b> HTML wrapper of defined list |
---|
300 | |
---|
301 | @return <b>string</b> HTML code list |
---|
302 | */ |
---|
303 | public function display($page,$nb_per_page,$enclose_block = '') |
---|
304 | { |
---|
305 | if ($this->rs->isEmpty()) |
---|
306 | { |
---|
307 | echo '<p><strong>'.__('No item').'</strong></p>'; |
---|
308 | } |
---|
309 | else |
---|
310 | { |
---|
311 | $pager = new dcPager($page,$this->rs_count,$nb_per_page,10); |
---|
312 | $pager->html_prev = $this->html_prev; |
---|
313 | $pager->html_next = $this->html_next; |
---|
314 | $pager->html_start = $this->html_start; |
---|
315 | $pager->html_end = $this->html_end; |
---|
316 | $pager->var_page = 'page'; |
---|
317 | |
---|
318 | $html_block = |
---|
319 | '<table class="maximal clear">'. |
---|
320 | $this->getCaption($page). |
---|
321 | '<thead><tr>'; |
---|
322 | |
---|
323 | foreach ($this->columns as $k => $v) { |
---|
324 | if ($v->isVisible()) { |
---|
325 | $html_extra = $v->getInfo('html') != '' ? ' '.$v->getInfo('html') : ''; |
---|
326 | $html_block .= sprintf('<th scope="col"%s>%s</th>',$html_extra,$v->getInfo('title')); |
---|
327 | } |
---|
328 | } |
---|
329 | |
---|
330 | $html_block .= |
---|
331 | '</tr></thead>'. |
---|
332 | '<tbody>%s</tbody>'. |
---|
333 | '</table>'; |
---|
334 | |
---|
335 | if ($enclose_block) { |
---|
336 | $html_block = sprintf($enclose_block,$html_block); |
---|
337 | } |
---|
338 | |
---|
339 | echo '<div class="pagination">'.$pager->getLinks().'</div>'; |
---|
340 | |
---|
341 | $blocks = explode('%s',$html_block); |
---|
342 | |
---|
343 | echo $blocks[0]; |
---|
344 | |
---|
345 | while ($this->rs->fetch()) |
---|
346 | { |
---|
347 | echo $this->displayLine(); |
---|
348 | } |
---|
349 | |
---|
350 | echo $blocks[1]; |
---|
351 | |
---|
352 | echo '<div class="pagination">'.$pager->getLinks().'</div>'; |
---|
353 | } |
---|
354 | } |
---|
355 | |
---|
356 | /** |
---|
357 | Adds column to defined list |
---|
358 | |
---|
359 | @param id <b>string</b> Column id |
---|
360 | @param title <b>string</b> Column title (for table headers) |
---|
361 | @param callback <b>array</b> Column callback (used for display) |
---|
362 | @param html <b>string</b> Extra html (used for table headers) |
---|
363 | @param can_hide <b>boolean</b> Defines if the column can be hidden or not |
---|
364 | */ |
---|
365 | protected function addColumn($id,$title,$callback,$html = null,$can_hide = true) |
---|
366 | { |
---|
367 | try { |
---|
368 | $c = new adminGenericColumn($id,$title,$callback,$html,$can_hide); |
---|
369 | $this->columns[$id] = $c; |
---|
370 | } |
---|
371 | catch (Exception $e) { |
---|
372 | if (DC_DEBUG) { |
---|
373 | $this->core->error->add($e->getMessage()); |
---|
374 | } |
---|
375 | } |
---|
376 | } |
---|
377 | |
---|
378 | /** |
---|
379 | Returns default caption text |
---|
380 | |
---|
381 | @return <b>string</b> Default caption |
---|
382 | */ |
---|
383 | protected function getDefaultCaption() |
---|
384 | { |
---|
385 | return; |
---|
386 | } |
---|
387 | |
---|
388 | /** |
---|
389 | Returns default HTMl code line |
---|
390 | |
---|
391 | @return <b>string</b> Default HTMl code line |
---|
392 | */ |
---|
393 | protected function getDefaultLine() |
---|
394 | { |
---|
395 | return '<tr class="line">%s</tr>'; |
---|
396 | } |
---|
397 | |
---|
398 | /** |
---|
399 | Sets columns visibility of defined list |
---|
400 | */ |
---|
401 | private function setColumnsVisibility() |
---|
402 | { |
---|
403 | $ws = $this->core->auth->user_prefs->addWorkspace('lists'); |
---|
404 | |
---|
405 | $user_pref = !is_null($ws->{$this->context}) ? unserialize($ws->{$this->context}) : array(); |
---|
406 | |
---|
407 | foreach ($this->columns as $k => $v) { |
---|
408 | $visibility = array_key_exists($k,$user_pref) ? $user_pref[$k] : true; |
---|
409 | if (array_key_exists($this->form_trigger,$_REQUEST)) { |
---|
410 | $key = sprintf($this->form_prefix,$k); |
---|
411 | $visibility = !array_key_exists($key,$_REQUEST) ? false : true; |
---|
412 | } |
---|
413 | if (!$v->canHide()) { |
---|
414 | $visibility = true; |
---|
415 | } |
---|
416 | $v->setVisibility($visibility); |
---|
417 | $user_pref[$k] = $visibility; |
---|
418 | } |
---|
419 | |
---|
420 | if (array_key_exists($this->form_trigger,$_REQUEST)) { |
---|
421 | $this->core->auth->user_prefs->lists->put($this->context,serialize($user_pref),'string'); |
---|
422 | } |
---|
423 | } |
---|
424 | |
---|
425 | /** |
---|
426 | Returns HTML code for each line of defined list |
---|
427 | |
---|
428 | @return <b>string</b> HTML code line |
---|
429 | */ |
---|
430 | private function displayLine() |
---|
431 | { |
---|
432 | $res = ''; |
---|
433 | |
---|
434 | foreach ($this->columns as $k => $v) { |
---|
435 | if ($v->isVisible()) { |
---|
436 | $c = $v->getInfo('callback'); |
---|
437 | $res .= $this->{$c[1]}(); |
---|
438 | } |
---|
439 | } |
---|
440 | |
---|
441 | return sprintf($this->getDefaultLine(),$res); |
---|
442 | } |
---|
443 | |
---|
444 | /** |
---|
445 | Returns caption of defined list |
---|
446 | |
---|
447 | @param page <b>string|int</b> Current page |
---|
448 | |
---|
449 | @return <b>string</b> HTML caption tag |
---|
450 | */ |
---|
451 | private function getCaption($page) |
---|
452 | { |
---|
453 | $caption = $this->getDefaultCaption(); |
---|
454 | |
---|
455 | if (!empty($caption)) { |
---|
456 | $caption = sprintf( |
---|
457 | '<caption>%s - %s</caption>', |
---|
458 | $caption,sprintf(__('Page %s'),$page) |
---|
459 | ); |
---|
460 | } |
---|
461 | |
---|
462 | return $caption; |
---|
463 | } |
---|
464 | } |
---|
465 | |
---|
466 | /** |
---|
467 | @ingroup DC_CORE |
---|
468 | @nosubgrouping |
---|
469 | @brief abstract posts list class. |
---|
470 | |
---|
471 | Handle posts list on admin side |
---|
472 | */ |
---|
473 | class adminPostList extends adminGenericList |
---|
474 | { |
---|
475 | public function setColumns() |
---|
476 | { |
---|
477 | $this->addColumn('title',__('Title'),array('adminPostList','getTitle'),' class="maximal"',false); |
---|
478 | $this->addColumn('date',__('Date'),array('adminPostList','getDate')); |
---|
479 | $this->addColumn('datetime',__('Date and time'),array('adminPostList','getDateTime')); |
---|
480 | $this->addColumn('category',__('Category'),array('adminPostList','getCategory')); |
---|
481 | $this->addColumn('author',__('Author'),array('adminPostList','getAuthor')); |
---|
482 | $this->addColumn('comment',__('Comments'),array('adminPostList','getComments')); |
---|
483 | $this->addColumn('trackback',__('Trackbacks'),array('adminPostList','getTrackbacks')); |
---|
484 | $this->addColumn('status',__('Status'),array('adminPostList','getStatus')); |
---|
485 | } |
---|
486 | |
---|
487 | protected function getDefaultCaption() |
---|
488 | { |
---|
489 | return __('Entries list'); |
---|
490 | } |
---|
491 | |
---|
492 | protected function getDefaultLine() |
---|
493 | { |
---|
494 | return |
---|
495 | '<tr class="line'.($this->rs->post_status != 1 ? ' offline' : '').'"'. |
---|
496 | ' id="p'.$this->rs->post_id.'">%s</tr>'; |
---|
497 | } |
---|
498 | |
---|
499 | protected function getTitle() |
---|
500 | { |
---|
501 | return |
---|
502 | '<th scope="row" class="maximal">'. |
---|
503 | form::checkbox(array('entries[]'),$this->rs->post_id,'','','',!$this->rs->isEditable()).' '. |
---|
504 | '<a href="'.$this->core->getPostAdminURL($this->rs->post_type,$this->rs->post_id).'">'. |
---|
505 | html::escapeHTML($this->rs->post_title).'</a></th>'; |
---|
506 | } |
---|
507 | |
---|
508 | protected function getDate() |
---|
509 | { |
---|
510 | return '<td class="nowrap">'.dt::dt2str(__('%Y-%m-%d'),$this->rs->post_dt).'</td>'; |
---|
511 | } |
---|
512 | |
---|
513 | protected function getDateTime() |
---|
514 | { |
---|
515 | return '<td class="nowrap">'.dt::dt2str(__('%Y-%m-%d %H:%M'),$this->rs->post_dt).'</td>'; |
---|
516 | } |
---|
517 | |
---|
518 | protected function getCategory() |
---|
519 | { |
---|
520 | if ($this->core->auth->check('categories',$this->core->blog->id)) { |
---|
521 | $cat_link = '<a href="category.php?id=%s">%s</a>'; |
---|
522 | } else { |
---|
523 | $cat_link = '%2$s'; |
---|
524 | } |
---|
525 | |
---|
526 | if ($this->rs->cat_title) { |
---|
527 | $cat_title = sprintf($cat_link,$this->rs->cat_id, |
---|
528 | html::escapeHTML($this->rs->cat_title)); |
---|
529 | } else { |
---|
530 | $cat_title = __('None'); |
---|
531 | } |
---|
532 | |
---|
533 | return '<td class="nowrap">'.$cat_title.'</td>'; |
---|
534 | } |
---|
535 | |
---|
536 | protected function getAuthor() |
---|
537 | { |
---|
538 | return '<td class="nowrap">'.$this->rs->user_id.'</td>'; |
---|
539 | } |
---|
540 | |
---|
541 | protected function getComments() |
---|
542 | { |
---|
543 | return '<td class="nowrap">'.$this->rs->nb_comment.'</td>'; |
---|
544 | } |
---|
545 | |
---|
546 | protected function getTrackbacks() |
---|
547 | { |
---|
548 | return '<td class="nowrap">'.$this->rs->nb_trackback.'</td>'; |
---|
549 | } |
---|
550 | |
---|
551 | protected function getStatus() |
---|
552 | { |
---|
553 | $img = '<img alt="%1$s" title="%1$s" src="images/%2$s" />'; |
---|
554 | switch ($this->rs->post_status) { |
---|
555 | case 1: |
---|
556 | $img_status = sprintf($img,__('published'),'check-on.png'); |
---|
557 | break; |
---|
558 | case 0: |
---|
559 | $img_status = sprintf($img,__('unpublished'),'check-off.png'); |
---|
560 | break; |
---|
561 | case -1: |
---|
562 | $img_status = sprintf($img,__('scheduled'),'scheduled.png'); |
---|
563 | break; |
---|
564 | case -2: |
---|
565 | $img_status = sprintf($img,__('pending'),'check-wrn.png'); |
---|
566 | break; |
---|
567 | } |
---|
568 | |
---|
569 | $protected = ''; |
---|
570 | if ($this->rs->post_password) { |
---|
571 | $protected = sprintf($img,__('protected'),'locker.png'); |
---|
572 | } |
---|
573 | |
---|
574 | $selected = ''; |
---|
575 | if ($this->rs->post_selected) { |
---|
576 | $selected = sprintf($img,__('selected'),'selected.png'); |
---|
577 | } |
---|
578 | |
---|
579 | $attach = ''; |
---|
580 | $nb_media = $this->rs->countMedia(); |
---|
581 | if ($nb_media > 0) { |
---|
582 | $attach_str = $nb_media == 1 ? __('%d attachment') : __('%d attachments'); |
---|
583 | $attach = sprintf($img,sprintf($attach_str,$nb_media),'attach.png'); |
---|
584 | } |
---|
585 | |
---|
586 | return '<td class="nowrap status">'.$img_status.' '.$selected.' '.$protected.' '.$attach.'</td>'; |
---|
587 | } |
---|
588 | } |
---|
589 | |
---|
590 | /** |
---|
591 | @ingroup DC_CORE |
---|
592 | @nosubgrouping |
---|
593 | @brief abstract mini posts list class. |
---|
594 | |
---|
595 | Handle mini posts list on admin side (used for link popup) |
---|
596 | */ |
---|
597 | class adminPostMiniList extends adminPostList |
---|
598 | { |
---|
599 | public function setColumns() |
---|
600 | { |
---|
601 | $this->addColumn('title',__('Title'),array('adminPostMiniList','getTitle'),' class="maximal"',false); |
---|
602 | $this->addColumn('date',__('Date'),array('adminPostList','getDate')); |
---|
603 | $this->addColumn('author',__('Author'),array('adminPostList','getAuthor')); |
---|
604 | $this->addColumn('status',__('Status'),array('adminPostList','getStatus')); |
---|
605 | } |
---|
606 | |
---|
607 | protected function getTitle() |
---|
608 | { |
---|
609 | return |
---|
610 | '<th scope="row" class="maximal">'. |
---|
611 | form::checkbox(array('entries[]'),$this->rs->post_id,'','','',!$this->rs->isEditable()).' '. |
---|
612 | '<a href="'.$this->core->getPostAdminURL($this->rs->post_type,$this->rs->post_id).'" '. |
---|
613 | 'title="'.html::escapeHTML($this->rs->getURL()).'">'. |
---|
614 | html::escapeHTML($this->rs->post_title).'</a></td>'; |
---|
615 | } |
---|
616 | } |
---|
617 | |
---|
618 | /** |
---|
619 | @ingroup DC_CORE |
---|
620 | @nosubgrouping |
---|
621 | @brief abstract comments list class. |
---|
622 | |
---|
623 | Handle comments list on admin side |
---|
624 | */ |
---|
625 | class adminCommentList extends adminGenericList |
---|
626 | { |
---|
627 | public function setColumns() |
---|
628 | { |
---|
629 | $this->addColumn('title',__('Title'),array('adminCommentList','getTitle'),' class="maximal"',false); |
---|
630 | $this->addColumn('date',__('Date'),array('adminCommentList','getDate')); |
---|
631 | $this->addColumn('author',__('Author'),array('adminCommentList','getAuthor')); |
---|
632 | $this->addColumn('type',__('Type'),array('adminCommentList','getType')); |
---|
633 | $this->addColumn('status',__('Status'),array('adminCommentList','getStatus')); |
---|
634 | $this->addColumn('edit','',array('adminCommentList','getEdit')); |
---|
635 | } |
---|
636 | |
---|
637 | protected function getDefaultCaption() |
---|
638 | { |
---|
639 | return __('Comments list'); |
---|
640 | } |
---|
641 | |
---|
642 | protected function getDefaultLine() |
---|
643 | { |
---|
644 | return |
---|
645 | '<tr class="line'.($this->rs->comment_status != 1 ? ' offline' : '').'"'. |
---|
646 | ' id="c'.$this->rs->comment_id.'">%s</tr>'; |
---|
647 | } |
---|
648 | |
---|
649 | protected function getTitle() |
---|
650 | { |
---|
651 | $post_url = $this->core->getPostAdminURL($this->rs->post_type,$this->rs->post_id); |
---|
652 | |
---|
653 | return |
---|
654 | '<th scope="row" class="maximal">'. |
---|
655 | form::checkbox(array('comments[]'),$this->rs->comment_id,'','','',0).' '. |
---|
656 | '<a href="'.$post_url.'">'. |
---|
657 | html::escapeHTML($this->rs->post_title).'</a>'. |
---|
658 | ($this->rs->post_type != 'post' ? ' ('.html::escapeHTML($this->rs->post_type).')' : '').'</th>'; |
---|
659 | } |
---|
660 | |
---|
661 | protected function getDate() |
---|
662 | { |
---|
663 | return '<td class="nowrap">'.dt::dt2str(__('%Y-%m-%d %H:%M'),$this->rs->comment_dt).'</td>'; |
---|
664 | } |
---|
665 | |
---|
666 | protected function getAuthor() |
---|
667 | { |
---|
668 | global $author, $status, $sortby, $order, $nb_per_page; |
---|
669 | |
---|
670 | $author_url = |
---|
671 | 'comments.php?n='.$nb_per_page. |
---|
672 | '&status='.$status. |
---|
673 | '&sortby='.$sortby. |
---|
674 | '&order='.$order. |
---|
675 | '&author='.rawurlencode($this->rs->comment_author); |
---|
676 | |
---|
677 | $comment_author = html::escapeHTML($this->rs->comment_author); |
---|
678 | if (mb_strlen($comment_author) > 20) { |
---|
679 | $comment_author = mb_strcut($comment_author,0,17).'...'; |
---|
680 | } |
---|
681 | |
---|
682 | return '<td class="nowrap"><a href="'.$author_url.'">'.$comment_author.'</a></td>'; |
---|
683 | } |
---|
684 | |
---|
685 | protected function getType() |
---|
686 | { |
---|
687 | return '<td class="nowrap">'.($this->rs->comment_trackback ? __('trackback') : __('comment')).'</td>'; |
---|
688 | } |
---|
689 | |
---|
690 | protected function getStatus() |
---|
691 | { |
---|
692 | $img = '<img alt="%1$s" title="%1$s" src="images/%2$s" />'; |
---|
693 | switch ($this->rs->comment_status) { |
---|
694 | case 1: |
---|
695 | $img_status = sprintf($img,__('published'),'check-on.png'); |
---|
696 | break; |
---|
697 | case 0: |
---|
698 | $img_status = sprintf($img,__('unpublished'),'check-off.png'); |
---|
699 | break; |
---|
700 | case -1: |
---|
701 | $img_status = sprintf($img,__('pending'),'check-wrn.png'); |
---|
702 | break; |
---|
703 | case -2: |
---|
704 | $img_status = sprintf($img,__('junk'),'junk.png'); |
---|
705 | break; |
---|
706 | } |
---|
707 | |
---|
708 | return '<td class="nowrap status">'.$img_status.'</td>'; |
---|
709 | } |
---|
710 | |
---|
711 | protected function getEdit() |
---|
712 | { |
---|
713 | $comment_url = 'comment.php?id='.$this->rs->comment_id; |
---|
714 | |
---|
715 | return |
---|
716 | '<td class="nowrap status"><a href="'.$comment_url.'">'. |
---|
717 | '<img src="images/edit-mini.png" alt="" title="'.__('Edit this comment').'" /></a></td>'; |
---|
718 | } |
---|
719 | } |
---|
720 | |
---|
721 | /** |
---|
722 | @ingroup DC_CORE |
---|
723 | @nosubgrouping |
---|
724 | @brief abstract users list class. |
---|
725 | |
---|
726 | Handle users list on admin side |
---|
727 | */ |
---|
728 | class adminUserList extends adminGenericList |
---|
729 | { |
---|
730 | public function setColumns() |
---|
731 | { |
---|
732 | $this->addColumn('username',__('Username'),array('adminUserList','getUserName'),'class="maximal"',false); |
---|
733 | $this->addColumn('firstname',__('First name'),array('adminUserList','getFirstName'),'class="nowrap"'); |
---|
734 | $this->addColumn('lastname',__('Last name'),array('adminUserList','getLastName'),'class="nowrap"'); |
---|
735 | $this->addColumn('displayname',__('Display name'),array('adminUserList','getDisplayName'),'class="nowrap"'); |
---|
736 | $this->addColumn('entries',__('Entries'),array('adminUserList','getEntries'),'class="nowrap"'); |
---|
737 | } |
---|
738 | |
---|
739 | protected function getDefaultCaption() |
---|
740 | { |
---|
741 | return __('Users list'); |
---|
742 | } |
---|
743 | |
---|
744 | protected function getUserName() |
---|
745 | { |
---|
746 | $img = '<img alt="%1$s" title="%1$s" src="images/%2$s" />'; |
---|
747 | $img_status = ''; |
---|
748 | |
---|
749 | $p = $this->core->getUserPermissions($this->rs->user_id); |
---|
750 | |
---|
751 | if (isset($p[$this->core->blog->id]['p']['admin'])) { |
---|
752 | $img_status = sprintf($img,__('admin'),'admin.png'); |
---|
753 | } |
---|
754 | if ($this->rs->user_super) { |
---|
755 | $img_status = sprintf($img,__('superadmin'),'superadmin.png'); |
---|
756 | } |
---|
757 | |
---|
758 | return |
---|
759 | '<th scope="row" class="maximal">'.form::hidden(array('nb_post[]'),(integer) $this->rs->nb_post). |
---|
760 | form::checkbox(array('user_id[]'),$this->rs->user_id).' '. |
---|
761 | '<a href="user.php?id='.$this->rs->user_id.'">'. |
---|
762 | $this->rs->user_id.'</a> '.$img_status.'</th>'; |
---|
763 | } |
---|
764 | |
---|
765 | protected function getFirstName() |
---|
766 | { |
---|
767 | return '<td class="nowrap">'.$this->rs->user_firstname.'</td>'; |
---|
768 | } |
---|
769 | |
---|
770 | protected function getLastName() |
---|
771 | { |
---|
772 | return '<td class="nowrap">'.$this->rs->user_name.'</td>'; |
---|
773 | } |
---|
774 | |
---|
775 | protected function getDisplayName() |
---|
776 | { |
---|
777 | return '<td class="nowrap">'.$this->rs->user_displayname.'</td>'; |
---|
778 | } |
---|
779 | |
---|
780 | protected function getEntries() |
---|
781 | { |
---|
782 | return |
---|
783 | '<td class="nowrap"><a href="posts.php?user_id='.$this->rs->user_id.'">'. |
---|
784 | $this->rs->nb_post.'</a></td>'; |
---|
785 | } |
---|
786 | } |
---|
787 | |
---|
788 | /** |
---|
789 | @ingroup DC_CORE |
---|
790 | @nosubgrouping |
---|
791 | @brief abstract blogs list class. |
---|
792 | |
---|
793 | Handle blogs list on admin side |
---|
794 | */ |
---|
795 | class adminBlogList extends adminGenericList |
---|
796 | { |
---|
797 | public function setColumns() |
---|
798 | { |
---|
799 | $this->addColumn('blogname',__('Blog name'),array('adminBlogList','getBlogName'),'class="maximal"',false); |
---|
800 | $this->addColumn('lastupdate',__('Last update'),array('adminBlogList','getLastUpdate'),'class="nowrap"'); |
---|
801 | $this->addColumn('entries',__('Entries'),array('adminBlogList','getEntries'),'class="nowrap"'); |
---|
802 | $this->addColumn('blogid',__('Blog ID'),array('adminBlogList','getBlogId'),'class="nowrap"'); |
---|
803 | $this->addColumn('action','',array('adminBlogList','getAction'),'class="nowrap"'); |
---|
804 | $this->addColumn('status',__('status'),array('adminBlogList','getStatus'),'class="nowrap"'); |
---|
805 | } |
---|
806 | |
---|
807 | protected function getDefaultCaption() |
---|
808 | { |
---|
809 | return __('Blogs list'); |
---|
810 | } |
---|
811 | |
---|
812 | protected function getBlogName() |
---|
813 | { |
---|
814 | return |
---|
815 | '<th scope="row" class="maximal"><a href="index.php?switchblog='.$this->rs->blog_id.'" '. |
---|
816 | 'title="'.sprintf(__('Switch to blog %s'),$this->rs->blog_id).'">'. |
---|
817 | html::escapeHTML($this->rs->blog_name).'</a></th>'; |
---|
818 | } |
---|
819 | |
---|
820 | protected function getLastUpdate() |
---|
821 | { |
---|
822 | $offset = dt::getTimeOffset($this->core->auth->getInfo('user_tz')); |
---|
823 | $blog_upddt = dt::str(__('%Y-%m-%d %H:%M'),strtotime($this->rs->blog_upddt) + $offset); |
---|
824 | |
---|
825 | return '<td class="nowrap">'.$blog_upddt.'</td>'; |
---|
826 | } |
---|
827 | |
---|
828 | protected function getEntries() |
---|
829 | { |
---|
830 | return '<td class="nowrap">'.$this->core->countBlogPosts($this->rs->blog_id).'</td>'; |
---|
831 | } |
---|
832 | |
---|
833 | protected function getBlogId() |
---|
834 | { |
---|
835 | return '<td class="nowrap">'.html::escapeHTML($this->rs->blog_id).'</td>'; |
---|
836 | } |
---|
837 | |
---|
838 | protected function getAction() |
---|
839 | { |
---|
840 | $edit_link = ''; |
---|
841 | $blog_id = html::escapeHTML($this->rs->blog_id); |
---|
842 | |
---|
843 | if ($GLOBALS['core']->auth->isSuperAdmin()) { |
---|
844 | $edit_link = |
---|
845 | '<a href="blog.php?id='.$blog_id.'" '. |
---|
846 | 'title="'.sprintf(__('Edit blog %s'),$blog_id).'">'. |
---|
847 | __('edit').'</a>'; |
---|
848 | } |
---|
849 | |
---|
850 | return '<td class="nowrap">'.$edit_link.'</td>'; |
---|
851 | } |
---|
852 | |
---|
853 | protected function getStatus() |
---|
854 | { |
---|
855 | $img_status = $this->rs->blog_status == 1 ? 'check-on' : 'check-off'; |
---|
856 | $txt_status = $GLOBALS['core']->getBlogStatus($this->rs->blog_status); |
---|
857 | $img_status = sprintf('<img src="images/%1$s.png" alt="%2$s" title="%2$s" />',$img_status,$txt_status); |
---|
858 | |
---|
859 | return '<td class="status">'.$img_status.'</td>'; |
---|
860 | } |
---|
861 | } |
---|
862 | |
---|
863 | /** |
---|
864 | @ingroup DC_CORE |
---|
865 | @nosubgrouping |
---|
866 | @brief abstract blogs permissions list class. |
---|
867 | |
---|
868 | Handle blogs permissions list on admin side |
---|
869 | */ |
---|
870 | class adminBlogPermissionsList extends adminBlogList |
---|
871 | { |
---|
872 | public function setColumns() |
---|
873 | { |
---|
874 | $this->addColumn('blogid',__('Blog ID'),array('adminBlogPermissionsList','getBlogId'),'class="nowrap"',false); |
---|
875 | $this->addColumn('blogname',__('Blog name'),array('adminBlogPermissionsList','getBlogName'),'class="maximal"'); |
---|
876 | $this->addColumn('entries',__('Entries'),array('adminBlogList','getEntries'),'class="nowrap"'); |
---|
877 | $this->addColumn('status',__('status'),array('adminBlogList','getStatus'),'class="nowrap"'); |
---|
878 | } |
---|
879 | |
---|
880 | protected function getBlogId() |
---|
881 | { |
---|
882 | return |
---|
883 | '<th scope="row" class="nowrap">'. |
---|
884 | form::checkbox(array('blog_id[]'),$this->rs->blog_id,'','','',false,'title="'.__('select').' '.$this->rs->blog_id.'"'). |
---|
885 | $this->rs->blog_id.'</th>'; |
---|
886 | } |
---|
887 | |
---|
888 | protected function getBlogName() |
---|
889 | { |
---|
890 | return '<td class="maximal">'.html::escapeHTML($this->rs->blog_name).'</td>'; |
---|
891 | } |
---|
892 | } |
---|
893 | |
---|
894 | ?> |
---|