Dotclear

source: inc/admin/class.dc.list.php @ 805:29349c682c86

Revision 805:29349c682c86, 31.0 KB checked in by Dsls <dsls@…>, 13 years ago (diff)

added default sortby and order for lists, removed unwanted warning

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

Sites map