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