Dotclear

source: inc/admin/class.dc.list.php @ 804:f10e7e0dffe0

Revision 804:f10e7e0dffe0, 30.5 KB checked in by Dsls <dsls@…>, 13 years ago (diff)

Tuned formfilters. Added sortby and order to filter form

Line 
1<?php
2# -- BEGIN LICENSE BLOCK ---------------------------------------
3#
4# This file is part of Dotclear 2.
5#
6# Copyright (c) 2003-2011 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 -----------------------------------------
12if (!defined('DC_RC_PATH')) { return; }
13
14/**
15@ingroup DC_CORE
16@nosubgrouping
17@brief Dotclear items pager class.
18
19Dotclear items pager handles pagination for every admin list.
20*/
21class adminItemsPager 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_pages).'" class="end">'.
59               $htmlEnd .= $this->html_end.'</a>';
60          }
61         
62          # Direct acces
63          $htmlDirectAccess = 
64               '<span>'.__('Direct access to page').'&nbsp;'.
65               form::field(array('page'),3,3,$this->env).'&nbsp;'.
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 items column class.
95
96Dotclear items column handles each column object use in adminItemsList class.
97*/
98class adminItemsColumn
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 == 'adminItemsList') {
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 adminItemsList 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 items list class.
258
259Dotclear items list handles administration lists
260*/
261abstract class adminItemsList implements dcFilterExtraInterface
262{
263     protected $core;
264     protected $rs;
265     protected $rs_count;
266     protected $columns;
267     protected $sortby;
268     protected $order;
269     protected $nb_per_page;
270     protected $page;
271     
272     /*
273     Sets columns of defined list
274     */
275     abstract function setColumns();
276     
277     /**
278     Inits List object
279     
280     @param    core      <b>dcCore</b>       dcCore object
281     */
282     public function __construct($core)
283     {
284         
285          $this->core = $core;
286          $this->context = get_class($this);
287          $this->columns = new ArrayObject();
288          $this->form_prefix = 'col_';
289         
290          $this->html_prev = __('prev');
291          $this->html_next = __('next');
292          $this->html_start = __('start');
293          $this->html_end = __('end');
294         
295          $this->nb_per_page = 10;
296         
297          $this->setColumns();
298         
299          # --BEHAVIOR-- adminItemsListConstruct
300          $core->callBehavior('adminItemsListConstruct',$this);
301         
302     }
303     
304     public function __clone() {
305          $arr = new ArrayObject();
306          foreach ($this->columns as $k=>$v) {
307               $arr[$k]= clone $v;
308          }
309          $this->columns = $arr;
310     }
311     /**
312     Apply limit, sortby and order filters to items parameters
313     
314     @param    params    <b>array</b>   Items parameters
315     
316     @return   <b>array</b>        Items parameters
317     */
318     public function applyFilters($params)
319     {
320          if (!is_null($this->sortby) && !is_null($this->order)) {
321               if (
322                    isset($this->columns[$this->sortby]) &&
323                    in_array($this->order,array('asc','desc'))
324               ) {
325                    $params['order'] = $this->columns[$this->sortby]->getInfo('alias').' '.$this->order;
326               }
327          }
328         
329          $params['limit'] = array((($this->page-1)*$this->nb_per_page),$this->nb_per_page);
330         
331          return $params;
332     }
333     
334     /**
335     Sets items and items counter
336     
337     @param    rs        <b>recordSet</b>    Items recordSet to display
338     @param    rs_count  <b>int</b>          Total items number
339     */
340     public function setItems($rs,$rs_count)
341     {
342          $this->rs = $rs;
343          $this->rs_count = $rs_count;
344     }
345     
346     /**
347     Returns HTML code form used to choose which column to display
348     
349     @return   <b>string</b>       HTML code form
350     */
351     public function getFormContent()
352     {
353          $block = 
354          '<h3>'.__('Displayed information').'</h3>'.
355          '<ul>%s</ul>';
356         
357          $list = array();
358          $sortby_combo = array();
359          foreach ($this->columns as $k => $v) {
360               $col_id = $this->form_prefix.$k;
361               $col_label = sprintf('<label for="%s">%s</label>',$col_id,$v->getInfo('title'));
362               $col_html = sprintf('<li class="line">%s</li>',$col_label.form::checkbox($col_id,1,$v->isVisible(),null,null,!$v->canHide()));
363               
364               if ($v->isListable()) {
365                    array_push($list,$col_html);
366               }
367               $sortby_combo[$v->getInfo('title')] = $k;
368          }
369          $order_combo = array(
370                    __('Descending') => 'desc',
371                    __('Ascending') => 'asc'
372          );
373         
374          $nb_per_page = !is_null($this->nb_per_page) ? $this->nb_per_page : 10;
375         
376          return
377          sprintf($block,implode('',$list)).
378          '<p><label for="nb_per_page">'.__('Items per page:').
379          '</label>&nbsp;'.form::field('nb_per_page',3,3,$nb_per_page).
380          '</p>'.
381          '<p><label for="sortby">'.__('Sort by:').
382          '</label>&nbsp;'.form::combo('sortby',$sortby_combo,$this->sortby).
383          '</p>'.
384          '<p><label for="order">'.__('Order:').
385          '</label>&nbsp;'.form::combo('order',$order_combo,$this->order).
386          '</p>';
387     }
388     
389     public function updateRequestParams($params) {
390          if (!is_null($this->sortby) && isset($this->columns[$this->sortby])) {
391               $params['sortby'] = $this->columns[$this->sortby]->getInfo('alias');
392          }
393          if (!is_null($this->order)) {
394               $params['order'] = $this->order;
395          }
396          if (!is_null($this->nb_per_page)) {
397               $params['nb_per_page'] = $this->nb_per_page;
398          }
399          if (!is_null($this->page)) {
400               $params['page'] = $this->page;
401          }
402          foreach ($this->columns as $k => $v) {
403               if($v->isVisible())
404                    $params[$this->form_prefix.$k] = 1;
405          }
406
407     }
408     
409     /**
410     Returns HTML hidden fields for list options
411     
412     @return   <b>string</b>       HTML hidden fields
413     */
414     public function getFormFieldsAsHidden()
415     {
416          $res = '';
417         
418          if (!is_null($this->sortby)) {
419               $res .= form::hidden(array('sortby'),$this->sortby);
420          }
421          if (!is_null($this->order)) {
422               $res .= form::hidden(array('order'),$this->order);
423          }
424          if (!is_null($this->nb_per_page)) {
425               $res .= form::hidden(array('nb_per_page'),$this->nb_per_page);
426          }
427          if (!is_null($this->page)) {
428               $res .= form::hidden(array('page'),$this->page);
429          }
430         
431          return $res;
432     }
433     
434     /**
435     Returns HTML code list to display
436     
437     @param    enclose_block  <b>string</b>       HTML wrapper of defined list
438     
439     @return   <b>string</b>       HTML code list
440     */
441     public function display($enclose_block = '')
442     {
443          if ($this->rs->isEmpty())
444          {
445               echo '<p><strong>'.__('No item').'</strong></p>';
446          }
447          else
448          {
449               $pager = new adminItemsPager($this->page,$this->rs_count,$this->nb_per_page,10);
450               $pager->html_prev = $this->html_prev;
451               $pager->html_next = $this->html_next;
452               $pager->html_start = $this->html_start;
453               $pager->html_end = $this->html_end;
454               $pager->var_page = 'page';
455               
456               $html_block =
457               '<table class="maximal clear">'.
458               $this->getCaption($this->page).
459               '<thead><tr>';
460               
461               foreach ($this->columns as $k => $v) {
462                    if ($v->isVisible()) {
463                         $title = $v->getInfo('title');
464                         if ($v->isSortable()) {
465                              $title = sprintf('<a href="%2$s">%1$s</a>',$title,$this->getSortLink($v));
466                         }
467                         $html_extra = '';
468                         foreach ($v->getInfo('html') as $i => $j) {
469                              $html_extra = $i.'="'.implode(' ',$j).'"';
470                         }
471                         $html_extra = !empty($html_extra) ? ' '.$html_extra : '';
472                         $html_block .= sprintf('<th scope="col"%2$s>%1$s</th>',$title,$html_extra);
473                    }
474               }
475               
476               $html_block .=
477               '</tr></thead>'.
478               '<tbody>%s</tbody>'.
479               '</table>';
480               
481               if ($enclose_block) {
482                    $html_block = sprintf($enclose_block,$html_block);
483               }
484               
485               echo '<div class="pagination">'.$pager->getLinks().'</div>';
486               
487               $blocks = explode('%s',$html_block);
488               
489               echo $blocks[0];
490               
491               while ($this->rs->fetch())
492               {
493                    echo $this->displayLine();
494               }
495               
496               echo $blocks[1];
497               
498               echo '<div class="pagination">'.$pager->getLinks().'</div>';
499          }
500     }
501     
502     /**
503     Adds column to defined list
504     
505     @param    id        <b>string</b>       Column id
506     @param    alias     <b>string</b>       Column alias for SQL
507     @param    title     <b>string</b>       Column title (for table headers)
508     @param    callback  <b>array</b>        Column callback (used for display)
509     @param    html      <b>string</b>       Extra html (used for table headers)
510     @param    sortable  <b>boolean</b>      Defines if the column can be sorted or not
511     @param    listable  <b>boolean</b>      Defines if the column can be listed or not
512     @param    can_hide  <b>boolean</b>      Defines if the column can be hidden or not
513     */
514     protected function addColumn($id,$alias,$title,$callback,$html = null,$sortable = true,$listable = true,$can_hide = true)
515     {
516          try {
517               if (is_null($html) || !is_array($html)) {
518                    $html = array();
519               }
520               if ($this->sortby === $alias && !is_null($this->order)) {
521                    if (array_key_exists('class',$html)) {
522                         array_push($html['class'],$this->order);
523                    }
524                    else {
525                         $html['class'] = array($this->order);
526                    }
527               }
528               $c = new adminItemsColumn($id,$alias,$title,$callback,$html,$sortable,$listable,$can_hide);
529               $this->columns[$id] = $c;
530          }
531          catch (Exception $e) {
532               if (DC_DEBUG) {
533                    $this->core->error->add(sprintf('[%s] %s',$id,$e->getMessage()));
534               }
535          }
536     }
537     
538     /**
539     Returns default caption text
540     
541     @return   <b>string</b>       Default caption
542     */
543     protected function getDefaultCaption()
544     {
545          return;
546     }
547     
548     /**
549     Returns default HTML code line
550     
551     @return   <b>string</b>       Default HTMl code line
552     */
553     protected function getDefaultLine()
554     {
555          return '<tr class="line">%s</tr>';
556     }
557     
558     /**
559     Loads list from user settings
560     */
561     public function load() {
562          $ws = $this->core->auth->user_prefs->addWorkspace('lists');
563          $user_pref = !is_null($ws->{$this->context.'_opts'}) ? unserialize($ws->{$this->context.'_opts'}) : array();
564          $this->sortby = array_key_exists('sortby',$user_pref) ? $user_pref['sortby'] : null;
565          $this->order = array_key_exists('order',$user_pref) ? $user_pref['order'] : null;
566          $this->nb_per_page = array_key_exists('nb_per_page',$user_pref) ? $user_pref['nb_per_page'] : 10;
567          $user_pref = !is_null($ws->{$this->context.'_col'}) ? unserialize($ws->{$this->context.'_col'}) : array();
568          foreach ($this->columns as $k => $v) {
569               $visibility =  array_key_exists($k,$user_pref) ? $user_pref[$k] : true;
570               $v->setVisibility($visibility);
571          }
572          if (!isset($this->columns[$this->sortby])) {
573               // No alias found
574               $this->sortby='';
575          }
576
577     }
578     
579     /**
580     Saves list to user settings
581     */
582     public function save() {
583          $ws = $this->core->auth->user_prefs->addWorkspace('lists');
584          $user_pref = !is_null($ws->{$this->context.'_opts'}) ? unserialize($ws->{$this->context.'_opts'}) : array();
585          $user_pref['order'] = $this->order;
586          $user_pref['nb_per_page'] = $this->nb_per_page;
587          $user_pref['sortby'] = $this->sortby;
588         
589          $this->core->auth->user_prefs->lists->put($this->context.'_opts',serialize($user_pref),'string');
590         
591          $user_pref = !is_null($ws->{$this->context.'_col'}) ? unserialize($ws->{$this->context.'_col'}) : array();
592         
593          foreach ($this->columns as $k => $v) {
594               $user_pref[$k] = $v->isVisible();
595          }
596          $this->core->auth->user_prefs->lists->put($this->context.'_col',serialize($user_pref),'string');
597     }
598     
599     /**
600     Set dedicated data from form submission
601     (either $_GET or $_POST depending on the context
602     
603     @param    data      <b>array</b>        Data to retrieve information from
604     */
605     public function initializeFromData ($data)
606     {
607          $load_from_settings = true;
608          foreach ($data as $k=>$v) {
609               if (strpos($k,$this->form_prefix) === 0) {
610                    $load_from_settings = false;
611               }
612          }
613          if ($load_from_settings) {
614               $this->load();
615          }
616          # Sortby
617          $this->sortby = array_key_exists('sortby',$data) ? $data['sortby'] : $this->sortby;
618          $this->order = array_key_exists('order',$data) ? $data['order'] : $this->order;
619          $this->nb_per_page = array_key_exists('nb_per_page',$data) ? (integer) $data['nb_per_page'] : $this->nb_per_page;
620          # Page
621          $this->page = array_key_exists('page',$data) ? (integer) $data['page'] : 1;
622          if ($load_from_settings)
623               return;
624          foreach ($this->columns as $k => $v) {
625               $key = $this->form_prefix.$k;
626               $visibility = !array_key_exists($key,$data) ? false : true;
627               $v->setVisibility($visibility);
628          }
629     }
630     
631     /**
632     Returns HTML code for each line of defined list
633     
634     @return   <b>string</b>       HTML code line
635     */
636     private function displayLine()
637     {
638          $res = '';
639         
640          foreach ($this->columns as $k => $v) {
641               if ($v->isVisible()) {
642                    $c = $v->getInfo('callback');
643                    $res .= $this->{$c[1]}();
644               }
645          }
646         
647          return sprintf($this->getDefaultLine(),$res);
648     }
649     
650     /**
651     Returns caption of defined list
652     
653     @param    page           <b>string|int</b>   Current page
654     
655     @return   <b>string</b>       HTML caption tag
656     */
657     private function getCaption($page)
658     {
659          $caption = $this->getDefaultCaption();
660         
661          if (!empty($caption)) {
662               $caption = sprintf(
663                    '<caption>%s - %s</caption>',
664                    $caption,sprintf(__('Page %s'),$page)
665               );
666          }
667         
668          return $caption;
669     }
670     
671     /**
672     Returns link to sort the defined column
673     
674     @param    c         <b>adminGenericColumn</b>     Current column
675     
676     @return   <b>string</b>       HTML link
677     */
678     private function getSortLink($c)
679     {
680          $order = 'desc';
681          if (!is_null($this->sortby) && $this->sortby === $c->getInfo('id')) {
682               if (!is_null($this->order) && $this->order === $order) {
683                    $order = 'asc';
684               }
685          }
686         
687          $args = $_GET;
688          $args['sortby'] = $c->getInfo('id');
689          $args['order'] = $order;
690         
691          array_walk($args,create_function('&$v,$k','$v=$k."=".$v;'));
692         
693          $url = $_SERVER['PHP_SELF'];
694          $url .= '?'.implode('&amp;',$args);
695         
696          return $url;
697     }
698}
699
700/**
701@ingroup DC_CORE
702@nosubgrouping
703@brief abstract posts list class.
704
705Handle posts list on admin side
706*/
707class adminPostList extends adminItemsList
708{
709     public function setColumns()
710     {
711          $this->addColumn('title','post_title',__('Title'),array('adminPostList','getTitle'),array('class' => array('maximal')),true,true,false);
712          $this->addColumn('date','post_dt',__('Date'),array('adminPostList','getDate'));
713          $this->addColumn('datetime','post_dt',__('Date and time'),array('adminPostList','getDateTime'));
714          $this->addColumn('category','cat_title',__('Category'),array('adminPostList','getCategory'));
715          $this->addColumn('author','user_id',__('Author'),array('adminPostList','getAuthor'));
716          $this->addColumn('comments','nb_comment',__('Comments'),array('adminPostList','getComments'));
717          $this->addColumn('trackbacks','nb_trackback',__('Trackbacks'),array('adminPostList','getTrackbacks'));
718          $this->addColumn('status','post_status',__('Status'),array('adminPostList','getStatus'));
719     }
720     
721     protected function getDefaultCaption()
722     {
723          return __('Entries list');
724     }
725     
726     protected function getDefaultLine()
727     {
728          return
729          '<tr class="line'.($this->rs->post_status != 1 ? ' offline' : '').'"'.
730          ' id="p'.$this->rs->post_id.'">%s</tr>';
731     }
732     
733     protected function getTitle()
734     {
735          return
736          '<th scope="row" class="maximal">'.
737          form::checkbox(array('entries[]'),$this->rs->post_id,'','','',!$this->rs->isEditable()).'&nbsp;'.
738          '<a href="'.$this->core->getPostAdminURL($this->rs->post_type,$this->rs->post_id).'">'.
739          html::escapeHTML($this->rs->post_title).'</a></th>';
740     }
741     
742     protected function getDate()
743     {
744          return '<td class="nowrap">'.dt::dt2str(__('%Y-%m-%d'),$this->rs->post_dt).'</td>';
745     }
746     
747     protected function getDateTime()
748     {
749          return '<td class="nowrap">'.dt::dt2str(__('%Y-%m-%d %H:%M'),$this->rs->post_dt).'</td>';
750     }
751     
752     protected function getCategory()
753     {
754          if ($this->core->auth->check('categories',$this->core->blog->id)) {
755               $cat_link = '<a href="category.php?id=%s">%s</a>';
756          } else {
757               $cat_link = '%2$s';
758          }
759         
760          if ($this->rs->cat_title) {
761               $cat_title = sprintf($cat_link,$this->rs->cat_id,
762               html::escapeHTML($this->rs->cat_title));
763          } else {
764               $cat_title = __('None');
765          }
766         
767          return '<td class="nowrap">'.$cat_title.'</td>';
768     }
769     
770     protected function getAuthor()
771     {
772          return '<td class="nowrap">'.$this->rs->user_id.'</td>';
773     }
774     
775     protected function getComments()
776     {
777          return '<td class="nowrap">'.$this->rs->nb_comment.'</td>';
778     }
779     
780     protected function getTrackbacks()
781     {
782          return '<td class="nowrap">'.$this->rs->nb_trackback.'</td>';
783     }
784     
785     protected function getStatus()
786     {
787          $img = '<img alt="%1$s" title="%1$s" src="images/%2$s" />';
788          switch ($this->rs->post_status) {
789               case 1:
790                    $img_status = sprintf($img,__('published'),'check-on.png');
791                    break;
792               case 0:
793                    $img_status = sprintf($img,__('unpublished'),'check-off.png');
794                    break;
795               case -1:
796                    $img_status = sprintf($img,__('scheduled'),'scheduled.png');
797                    break;
798               case -2:
799                    $img_status = sprintf($img,__('pending'),'check-wrn.png');
800                    break;
801          }
802         
803          $protected = '';
804          if ($this->rs->post_password) {
805               $protected = sprintf($img,__('protected'),'locker.png');
806          }
807         
808          $selected = '';
809          if ($this->rs->post_selected) {
810               $selected = sprintf($img,__('selected'),'selected.png');
811          }
812         
813          $attach = '';
814          $nb_media = $this->rs->countMedia();
815          if ($nb_media > 0) {
816               $attach_str = $nb_media == 1 ? __('%d attachment') : __('%d attachments');
817               $attach = sprintf($img,sprintf($attach_str,$nb_media),'attach.png');
818          }
819         
820          return '<td class="nowrap status">'.$img_status.' '.$selected.' '.$protected.' '.$attach.'</td>';
821     }
822}
823
824/**
825@ingroup DC_CORE
826@nosubgrouping
827@brief abstract mini posts list class.
828
829Handle mini posts list on admin side (used for link popup)
830*/
831class adminPostMiniList extends adminPostList
832{
833     public function setColumns()
834     {
835          $this->addColumn('title','post_title',__('Title'),array('adminPostMiniList','getTitle'),array('class' => array('maximal')),true,true,false);
836          $this->addColumn('date','post_dt',__('Date'),array('adminPostList','getDate'));
837          $this->addColumn('author','user_id',__('Author'),array('adminPostList','getAuthor'));
838          $this->addColumn('status','post_status',__('Status'),array('adminPostList','getStatus'));
839     }
840     
841     protected function getTitle() 
842     {
843          return
844          '<th scope="row" class="maximal">'.
845          form::checkbox(array('entries[]'),$this->rs->post_id,'','','',!$this->rs->isEditable()).'&nbsp;'.
846          '<a href="'.$this->core->getPostAdminURL($this->rs->post_type,$this->rs->post_id).'" '.
847          'title="'.html::escapeHTML($this->rs->getURL()).'">'.
848          html::escapeHTML($this->rs->post_title).'</a></td>';
849     }
850}
851
852/**
853@ingroup DC_CORE
854@nosubgrouping
855@brief abstract comments list class.
856
857Handle comments list on admin side
858*/
859class adminCommentList extends adminItemsList
860{
861     public function setColumns()
862     {
863          $this->addColumn('title','post_title',__('Title'),array('adminCommentList','getTitle'),array('class' => array('maximal')),true,true,false);
864          $this->addColumn('date','comment_dt',__('Date'),array('adminCommentList','getDate'));
865          $this->addColumn('author','comment_author',__('Author'),array('adminCommentList','getAuthor'));
866          $this->addColumn('type','comment_trackback',__('Type'),array('adminCommentList','getType'));
867          $this->addColumn('status','comment_status',__('Status'),array('adminCommentList','getStatus'));
868          $this->addColumn('edit',null,'',array('adminCommentList','getEdit'),null,false,false,false);
869     }
870     
871     protected function getDefaultCaption()
872     {
873          return __('Comments list');
874     }
875     
876     protected function getDefaultLine()
877     {
878          return
879          '<tr class="line'.($this->rs->comment_status != 1 ? ' offline' : '').'"'.
880          ' id="c'.$this->rs->comment_id.'">%s</tr>';
881     }
882     
883     protected function getTitle()
884     {
885          $post_url = $this->core->getPostAdminURL($this->rs->post_type,$this->rs->post_id);
886         
887          return
888          '<th scope="row" class="maximal">'.
889          form::checkbox(array('comments[]'),$this->rs->comment_id,'','','',0).'&nbsp;'.
890          '<a href="'.$post_url.'">'.
891          html::escapeHTML($this->rs->post_title).'</a>'.
892          ($this->rs->post_type != 'post' ? ' ('.html::escapeHTML($this->rs->post_type).')' : '').'</th>';
893     }
894     
895     protected function getDate()
896     {
897          return '<td class="nowrap">'.dt::dt2str(__('%Y-%m-%d %H:%M'),$this->rs->comment_dt).'</td>';
898     }
899     
900     protected function getAuthor()
901     {
902          global $author, $status, $sortby, $order, $nb_per_page;
903         
904          $author_url =
905          'comments.php?n='.$nb_per_page.
906          '&amp;status='.$status.
907          '&amp;sortby='.$sortby.
908          '&amp;order='.$order.
909          '&amp;author='.rawurlencode($this->rs->comment_author);
910         
911          $comment_author = html::escapeHTML($this->rs->comment_author);
912          if (mb_strlen($comment_author) > 20) {
913               $comment_author = mb_strcut($comment_author,0,17).'...';
914          }
915         
916          return '<td class="nowrap"><a href="'.$author_url.'">'.$comment_author.'</a></td>';
917     }
918     
919     protected function getType()
920     {
921          return '<td class="nowrap">'.($this->rs->comment_trackback ? __('trackback') : __('comment')).'</td>';
922     }
923     
924     protected function getStatus()
925     {
926          $img = '<img alt="%1$s" title="%1$s" src="images/%2$s" />';
927          switch ($this->rs->comment_status) {
928               case 1:
929                    $img_status = sprintf($img,__('published'),'check-on.png');
930                    break;
931               case 0:
932                    $img_status = sprintf($img,__('unpublished'),'check-off.png');
933                    break;
934               case -1:
935                    $img_status = sprintf($img,__('pending'),'check-wrn.png');
936                    break;
937               case -2:
938                    $img_status = sprintf($img,__('junk'),'junk.png');
939                    break;
940          }
941         
942          return '<td class="nowrap status">'.$img_status.'</td>';
943     }
944     
945     protected function getEdit()
946     {
947          $comment_url = 'comment.php?id='.$this->rs->comment_id;
948         
949          return
950          '<td class="nowrap status"><a href="'.$comment_url.'">'.
951          '<img src="images/edit-mini.png" alt="" title="'.__('Edit this comment').'" /></a></td>';
952     }
953}
954
955/**
956@ingroup DC_CORE
957@nosubgrouping
958@brief abstract users list class.
959
960Handle users list on admin side
961*/
962class adminUserList extends adminItemsList
963{
964     public function setColumns()
965     {
966          $this->addColumn('username','U.user_id',__('Username'),array('adminUserList','getUserName'),array('class' => array('maximal')),true,true,false);
967          $this->addColumn('firstname','user_firstname',__('First name'),array('adminUserList','getFirstName'),array('class' => array('nowrap')));
968          $this->addColumn('lastname','user_name',__('Last name'),array('adminUserList','getLastName'),array('class' => array('nowrap')));
969          $this->addColumn('displayname','user_displayname',__('Display name'),array('adminUserList','getDisplayName'),array('class' => array('nowrap')));
970          $this->addColumn('entries','nb_post',__('Entries'),array('adminUserList','getEntries'),array('class' => array('nowrap')));
971     }
972     
973     protected function getDefaultCaption()
974     {
975          return __('Users list');
976     }
977     
978     protected function getUserName()
979     {
980          $img = '<img alt="%1$s" title="%1$s" src="images/%2$s" />';
981          $img_status = '';
982         
983          $p = $this->core->getUserPermissions($this->rs->user_id);
984         
985          if (isset($p[$this->core->blog->id]['p']['admin'])) {
986               $img_status = sprintf($img,__('admin'),'admin.png');
987          }
988          if ($this->rs->user_super) {
989               $img_status = sprintf($img,__('superadmin'),'superadmin.png');
990          }
991         
992          return
993          '<th scope="row" class="maximal">'.form::hidden(array('nb_post[]'),(integer) $this->rs->nb_post).
994          form::checkbox(array('user_id[]'),$this->rs->user_id).'&nbsp;'.
995          '<a href="user.php?id='.$this->rs->user_id.'">'.
996          $this->rs->user_id.'</a>&nbsp;'.$img_status.'</th>';
997     }
998     
999     protected function getFirstName()
1000     {
1001          return '<td class="nowrap">'.$this->rs->user_firstname.'</td>';
1002     }
1003     
1004     protected function getLastName()
1005     {
1006          return '<td class="nowrap">'.$this->rs->user_name.'</td>';
1007     }
1008     
1009     protected function getDisplayName()
1010     {
1011          return '<td class="nowrap">'.$this->rs->user_displayname.'</td>';
1012     }
1013     
1014     protected function getEntries()
1015     {
1016          return
1017          '<td class="nowrap"><a href="posts.php?user_id='.$this->rs->user_id.'">'.
1018          $this->rs->nb_post.'</a></td>';
1019     }
1020}
1021
1022/**
1023@ingroup DC_CORE
1024@nosubgrouping
1025@brief abstract blogs list class.
1026
1027Handle blogs list on admin side
1028*/
1029class adminBlogList extends adminItemsList
1030{
1031     public function setColumns()
1032     {
1033          $this->addColumn('blogname','UPPER(blog_name)',__('Blog name'),array('adminBlogList','getBlogName'),array('class' => array('maximal')),true,true,false);
1034          $this->addColumn('lastupdate','blog_upddt',__('Last update'),array('adminBlogList','getLastUpdate'),array('class' => array('nowrap')));
1035          $this->addColumn('entries',null,__('Entries'),array('adminBlogList','getEntries'),array('class' => array('nowrap')),false);
1036          $this->addColumn('blogid','B.blog_id',__('Blog ID'),array('adminBlogList','getBlogId'),array('class' => array('nowrap')));
1037          $this->addColumn('action',null,'',array('adminBlogList','getAction'),array('class' => array('nowrap')),false);
1038          $this->addColumn('status','blog_status',__('status'),array('adminBlogList','getStatus'),array('class' => array('nowrap')));
1039     }
1040     
1041     protected function getDefaultCaption()
1042     {
1043          return __('Blogs list');
1044     }
1045     
1046     protected function getBlogName()
1047     {
1048          return
1049          '<th scope="row" class="maximal"><a href="index.php?switchblog='.$this->rs->blog_id.'" '.
1050          'title="'.sprintf(__('Switch to blog %s'),$this->rs->blog_id).'">'.
1051          html::escapeHTML($this->rs->blog_name).'</a></th>';
1052     }
1053     
1054     protected function getLastUpdate()
1055     {
1056          $offset = dt::getTimeOffset($this->core->auth->getInfo('user_tz'));
1057          $blog_upddt = dt::str(__('%Y-%m-%d %H:%M'),strtotime($this->rs->blog_upddt) + $offset);
1058     
1059          return '<td class="nowrap">'.$blog_upddt.'</td>';
1060     }
1061     
1062     protected function getEntries()
1063     {
1064          return '<td class="nowrap">'.$this->core->countBlogPosts($this->rs->blog_id).'</td>';
1065     }
1066     
1067     protected function getBlogId()
1068     {
1069          return '<td class="nowrap">'.html::escapeHTML($this->rs->blog_id).'</td>';
1070     }
1071     
1072     protected function getAction()
1073     {
1074          $edit_link = '';
1075          $blog_id = html::escapeHTML($this->rs->blog_id);
1076     
1077          if ($GLOBALS['core']->auth->isSuperAdmin()) {
1078               $edit_link = 
1079               '<a href="blog.php?id='.$blog_id.'" '.
1080               'title="'.sprintf(__('Edit blog %s'),$blog_id).'">'.
1081               __('edit').'</a>';
1082          }
1083         
1084          return '<td class="nowrap">'.$edit_link.'</td>';
1085     }
1086     
1087     protected function getStatus()
1088     {
1089          $img_status = $this->rs->blog_status == 1 ? 'check-on' : 'check-off';
1090          $txt_status = $GLOBALS['core']->getBlogStatus($this->rs->blog_status);
1091          $img_status = sprintf('<img src="images/%1$s.png" alt="%2$s" title="%2$s" />',$img_status,$txt_status);
1092         
1093          return '<td class="status">'.$img_status.'</td>';
1094     }
1095}
1096
1097/**
1098@ingroup DC_CORE
1099@nosubgrouping
1100@brief abstract blogs permissions list class.
1101
1102Handle blogs permissions list on admin side
1103*/
1104class adminBlogPermissionsList extends adminBlogList
1105{
1106     public function setColumns()
1107     {
1108          $this->addColumn('blogid','B.blog_id',__('Blog ID'),array('adminBlogPermissionsList','getBlogId'),array('class' => array('nowrap')),false,true,false);
1109          $this->addColumn('blogname','UPPER(blog_name)',__('Blog name'),array('adminBlogPermissionsList','getBlogName'),array('class' => array('maximal')),false);
1110          $this->addColumn('entries',null,__('Entries'),array('adminBlogList','getEntries'),array('class' => array('nowrap')),false);
1111          $this->addColumn('status','blog_status',__('status'),array('adminBlogList','getStatus'),array('class' => array('nowrap')),false);
1112     }
1113     
1114     protected function getBlogId()
1115     {
1116          return
1117          '<th scope="row" class="nowrap">'.
1118          form::checkbox(array('blog_id[]'),$this->rs->blog_id,'','','',false,'title="'.__('select').' '.$this->rs->blog_id.'"').
1119          $this->rs->blog_id.'</th>';
1120     }
1121     
1122     protected function getBlogName()
1123     {
1124          return '<td class="maximal">'.html::escapeHTML($this->rs->blog_name).'</td>';
1125     }
1126}
1127
1128?>
Note: See TracBrowser for help on using the repository browser.

Sites map