Dotclear

source: inc/admin/class.dc.list.php @ 979:ee243b25b452

Revision 979:ee243b25b452, 31.0 KB checked in by franck <carnet.franck.paul@…>, 13 years ago (diff)

Bugfix for blogs and users lists

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

Sites map