Dotclear

source: inc/admin/class.dc.list.php @ 521:c37babfc02e2

Revision 521:c37babfc02e2, 29.0 KB checked in by Tomtom33 <tbouron@…>, 14 years ago (diff)

Retro compatibility with plugin - Step 1

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

Sites map