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

RevLine 
[0]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
[452]14/**
15@ingroup DC_CORE
16@nosubgrouping
[519]17@brief Dotclear items pager class.
[452]18
[519]19Dotclear items pager handles pagination for every admin list.
[452]20*/
[519]21class adminItemsPager extends pager
[449]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
[453]36          $htmlText = '<span>'.sprintf(__('Page %s over %s'),$this->env,$this->nb_pages).'</span>';
[449]37         
38          # Previous page
39          if($this->env != 1) {
40               $htmlPrev = '<a href="'.sprintf($this->page_url,$this->env-1).'" class="prev">'.
[453]41               $htmlPrev .= $this->html_prev.'</a>';
[449]42          }
43         
44          # Next page
45          if($this->env != $this->nb_pages) {
[453]46               $htmlNext = '<a href="'.sprintf($this->page_url,$this->env+1).'" class="next">';
[449]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">'.
[453]53               $htmlStart .= $this->html_start.'</a>';
[449]54          }
55         
56          # End
57          if($this->env != $this->nb_pages) {
[519]58               $htmlEnd = '<a href="'.sprintf($this->page_url,$this->nb_pages).'" class="end">'.
[453]59               $htmlEnd .= $this->html_end.'</a>';
[449]60          }
61         
62          # Direct acces
63          $htmlDirectAccess = 
64               '<span>'.__('Direct access to page').'&nbsp;'.
[453]65               form::field(array('page'),3,3,$this->env).'&nbsp;'.
[449]66               '<input type="submit" value="'.__('ok').'" />'.
[453]67               '</span>';
[449]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 =
[453]77               '<form method="get" action="'.$this->base_url.'"><p>'.
[449]78               $htmlStart.
79               $htmlPrev.
80               $htmlText.
81               $htmlNext.
82               $htmlEnd.
83               $htmlDirectAccess.
84               $htmlHidden.
[453]85               '</p></form>';
[449]86         
87          return $this->nb_elements > 0 ? $res : '';
88     }
89}
90
[452]91/**
92@ingroup DC_CORE
93@nosubgrouping
[519]94@brief Dotclear items column class.
[452]95
[519]96Dotclear items column handles each column object use in adminItemsList class.
[452]97*/
[519]98class adminItemsColumn
[238]99{
[452]100     protected $core;         /// <b>object</b> dcCore object
101     protected $id;           /// <b>string</b> ID of defined column
[508]102     protected $alias;        /// <b>string</b> ID of defined column
[452]103     protected $title;        /// <b>string</b> Title of defined column
104     protected $callback;     /// <b>array</b> Callback calls to display defined column
[508]105     protected $html;         /// <b>array</b> Extra HTML for defined column
[238]106     
[452]107     /**
108     Inits Generic column object
109     
110     @param    id        <b>string</b>       Column id
[508]111     @param    alias     <b>string</b>       Column alias for SQL
[452]112     @param    title     <b>string</b>       Column title (for table headers)
113     @param    callback  <b>array</b>        Column callback (used for display)
[508]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
[452]117     @param    can_hide  <b>boolean</b>      Defines if the column can be hidden or not
118     */
[508]119     public function __construct($id,$alias,$title,$callback,$html = null,$sortable = true,$listable = true,$can_hide = true)
[238]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          }
[242]128         
[508]129          if (is_null($html) || !is_array($html)) {
130               $html = array();
[238]131          }
[508]132         
133          if (!is_bool($sortable)) {
134               $sortable = true;
135          }
136         
137          if (!is_bool($listable)) {
138               $listable = true;
[242]139          }
140         
[418]141          if (!is_bool($can_hide)) {
142               $can_hide = true;
143          }
144         
[508]145          if (!is_string($alias) && $sortable) {
146               throw new Exception(__('Invalid column alias'));
147          }
148         
[238]149          try {
[242]150               if (!is_array($callback) || count($callback) < 2) {
151                    throw new Exception(__('Callback parameter should be an array'));
152               }
[238]153               $r = new ReflectionClass($callback[0]);
154               $f = $r->getMethod($callback[1]);
155               $p = $r->getParentClass();
[456]156               $find_parent = false;
157               
158               while (!$p) {
[519]159                    if ($p->name == 'adminItemsList') {
[456]160                         $find_parent = true;
161                    }
162                    else {
163                         $p->getParentClass();
164                    }
165               }
166               
167               if (!$p || !$f) {
[519]168                    throw new Exception(__('Callback class should be inherited of adminItemsList class'));
[238]169               }
170          }
171          catch (Exception $e) {
[242]172               throw new Exception(sprintf(__('Invalid column callback: %s'),$e->getMessage()));
[238]173          }
174         
175          $this->id = $id;
[508]176          $this->alias = $alias;
[238]177          $this->title = $title;
178          $this->callback = $callback;
179          $this->html = $html;
[508]180          $this->sortable = $sortable;
181          $this->listable = $listable;
[418]182          $this->can_hide = $can_hide;
[238]183          $this->visibility = true;
184     }
185     
[452]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)
[238]194     {
[452]195          return property_exists(get_class($this),$info) ? $this->{$info} : null;
[238]196     }
197     
[452]198     /**
199     Sets visibility of defined column
200     
201     @param    visibility     <b>boolean</b>      Column visibility
202     */
[238]203     public function setVisibility($visibility)
204     {
[508]205          if (is_bool($visibility) && $this->can_hide) {
[238]206               $this->visibility = $visibility;
207          }
[508]208          else {
209               $this->visibility = true;
210          }
[238]211     }
212     
[452]213     /**
214     Returns visibility status of defined column
215     
216     @return   <b>boolean</b>      true if column is visible, false otherwise
217     */
[238]218     public function isVisible()
219     {
220          return $this->visibility;
221     }
[418]222     
[452]223     /**
[508]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     /**
[452]244     Returns if the defined column can be hidden
245     
246     @return   <b>boolean</b> true if column can be hidden, false otherwise
247     */
[418]248     public function canHide()
249     {
250          return $this->can_hide;
251     }
[238]252}
253
[452]254/**
255@ingroup DC_CORE
256@nosubgrouping
[519]257@brief abstract items list class.
[452]258
[519]259Dotclear items list handles administration lists
[452]260*/
[519]261abstract class adminItemsList
[0]262{
263     protected $core;
264     protected $rs;
265     protected $rs_count;
[238]266     protected $columns;
[519]267     protected $sortby;
268     protected $order;
269     protected $nb_per_page;
270     protected $page;
[238]271     
[452]272     /*
273     Sets columns of defined list
274     */
[519]275     abstract function setColumns();
[452]276     
277     /**
278     Inits List object
279     
280     @param    core      <b>dcCore</b>       dcCore object
281     */
[519]282     public function __construct($core)
[0]283     {
[519]284         
285          $this->core = $core;
[238]286          $this->context = get_class($this);
287          $this->columns = array();
[242]288          $this->form_prefix = 'col_%s';
289          $this->form_trigger = 'add_filter';
[238]290         
[449]291          $this->html_prev = __('prev');
292          $this->html_next = __('next');
293          $this->html_start = __('start');
294          $this->html_end = __('end');
[238]295         
[519]296          $this->setOptions();
297         
[452]298          $this->setColumns();
[238]299         
[519]300          # --BEHAVIOR-- adminItemsListConstruct
301          $core->callBehavior('adminItemsListConstruct',$this);
[276]302         
[238]303          $this->setColumnsVisibility();
[0]304     }
[238]305     
[452]306     /**
[519]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     /**
[452]345     Returns HTML code form used to choose which column to display
[238]346     
[452]347     @return   <b>string</b>       HTML code form
348     */
[242]349     public function getColumnsForm()
350     {
351          $block = 
352          '<h3>'.__('Displayed information').'</h3>'.
353          '<ul>%s</ul>';
354         
355          $list = array();
356         
[452]357          foreach ($this->columns as $k => $v) {
[242]358               $col_id = sprintf($this->form_prefix,$k);
359               $col_label = sprintf('<label for="%s">%s</label>',$col_id,$v->getInfo('title'));
[418]360               $col_html = sprintf('<li class="line">%s</li>',$col_label.form::checkbox($col_id,1,$v->isVisible(),null,null,!$v->canHide()));
[242]361               
[508]362               if ($v->isListable()) {
363                    array_push($list,$col_html);
364               }
[242]365          }
366         
[519]367          $nb_per_page = !is_null($this->nb_per_page) ? $this->nb_per_page : 10;
[437]368         
[453]369          return
370          sprintf($block,implode('',$list)).
[519]371          '<p><label for="nb_per_page">'.__('Items per page:').
372          '</label>&nbsp;'.form::field('nb_per_page',3,3,$nb_per_page).
[453]373          '</p>';
[242]374     }
375     
[452]376     /**
[519]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     /**
[452]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     */
[519]408     public function display($enclose_block = '')
[0]409     {
410          if ($this->rs->isEmpty())
411          {
[463]412               echo '<p><strong>'.__('No item').'</strong></p>';
[0]413          }
414          else
415          {
[519]416               $pager = new adminItemsPager($this->page,$this->rs_count,$this->nb_per_page,10);
[0]417               $pager->html_prev = $this->html_prev;
418               $pager->html_next = $this->html_next;
[449]419               $pager->html_start = $this->html_start;
420               $pager->html_end = $this->html_end;
[0]421               $pager->var_page = 'page';
422               
[431]423               $html_block =
424               '<table class="maximal clear">'.
[519]425               $this->getCaption($this->page).
[431]426               '<thead><tr>';
[238]427               
[452]428               foreach ($this->columns as $k => $v) {
[238]429                    if ($v->isVisible()) {
[508]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);
[238]440                    }
441               }
442               
[431]443               $html_block .=
444               '</tr></thead>'.
445               '<tbody>%s</tbody>'.
446               '</table>';
[0]447               
448               if ($enclose_block) {
449                    $html_block = sprintf($enclose_block,$html_block);
450               }
451               
[449]452               echo '<div class="pagination">'.$pager->getLinks().'</div>';
[0]453               
454               $blocks = explode('%s',$html_block);
455               
456               echo $blocks[0];
457               
458               while ($this->rs->fetch())
459               {
[238]460                    echo $this->displayLine();
[0]461               }
462               
463               echo $blocks[1];
464               
[449]465               echo '<div class="pagination">'.$pager->getLinks().'</div>';
[0]466          }
467     }
468     
[452]469     /**
470     Adds column to defined list
471     
472     @param    id        <b>string</b>       Column id
[508]473     @param    alias     <b>string</b>       Column alias for SQL
[452]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)
[508]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
[452]479     @param    can_hide  <b>boolean</b>      Defines if the column can be hidden or not
480     */
[508]481     protected function addColumn($id,$alias,$title,$callback,$html = null,$sortable = true,$listable = true,$can_hide = true)
[452]482     {
483          try {
[508]484               if (is_null($html) || !is_array($html)) {
485                    $html = array();
486               }
[519]487               if ($this->sortby === $alias && !is_null($this->order)) {
[508]488                    if (array_key_exists('class',$html)) {
[519]489                         array_push($html['class'],$this->order);
[508]490                    }
491                    else {
[519]492                         $html['class'] = array($this->order);
[508]493                    }
494               }
[519]495               $c = new adminItemsColumn($id,$alias,$title,$callback,$html,$sortable,$listable,$can_hide);
[452]496               $this->columns[$id] = $c;
497          }
498          catch (Exception $e) {
499               if (DC_DEBUG) {
[519]500                    $this->core->error->add(sprintf('[%s] %s',$id,$e->getMessage()));
[452]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     /**
[519]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     /**
[452]557     Sets columns visibility of defined list
558     */
559     private function setColumnsVisibility()
560     {
[519]561          $opts = $_GET;
562         
563          # Visibility
[452]564          $ws = $this->core->auth->user_prefs->addWorkspace('lists');
565         
[519]566          $user_pref = !is_null($ws->{$this->context.'_col'}) ? unserialize($ws->{$this->context.'_col'}) : array();
[452]567         
568          foreach ($this->columns as $k => $v) {
569               $visibility =  array_key_exists($k,$user_pref) ? $user_pref[$k] : true;
[519]570               if (array_key_exists($this->form_trigger,$opts)) {
[452]571                    $key = sprintf($this->form_prefix,$k);
[519]572                    $visibility = !array_key_exists($key,$opts) ? false : true;
[452]573               }
574               $v->setVisibility($visibility);
575               $user_pref[$k] = $visibility;
576          }
577         
[519]578          if (array_key_exists($this->form_trigger,$opts)) {
579               $this->core->auth->user_prefs->lists->put($this->context.'_col',serialize($user_pref),'string');
[452]580          }
581     }
582     
583     /**
584     Returns HTML code for each line of defined list
585     
586     @return   <b>string</b>       HTML code line
587     */
[238]588     private function displayLine()
589     {
590          $res = '';
591         
[452]592          foreach ($this->columns as $k => $v) {
[238]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     
[452]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     */
[432]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     }
[508]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';
[519]633          if (!is_null($this->sortby) && $this->sortby === $c->getInfo('alias')) {
634               if (!is_null($this->order) && $this->order === $order) {
[508]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     }
[452]650}
651
652/**
653@ingroup DC_CORE
654@nosubgrouping
655@brief abstract posts list class.
656
657Handle posts list on admin side
658*/
[519]659class adminPostList extends adminItemsList
[452]660{
661     public function setColumns()
[432]662     {
[508]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'));
[432]671     }
672     
673     protected function getDefaultCaption()
674     {
675          return __('Entries list');
676     }
677     
[238]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
[431]688          '<th scope="row" class="maximal">'.
689          form::checkbox(array('entries[]'),$this->rs->post_id,'','','',!$this->rs->isEditable()).'&nbsp;'.
[238]690          '<a href="'.$this->core->getPostAdminURL($this->rs->post_type,$this->rs->post_id).'">'.
[431]691          html::escapeHTML($this->rs->post_title).'</a></th>';
[238]692     }
693     
694     protected function getDate()
695     {
[433]696          return '<td class="nowrap">'.dt::dt2str(__('%Y-%m-%d'),$this->rs->post_dt).'</td>';
697     }
698     
699     protected function getDateTime()
700     {
[238]701          return '<td class="nowrap">'.dt::dt2str(__('%Y-%m-%d %H:%M'),$this->rs->post_dt).'</td>';
702     }
703     
704     protected function getCategory()
[0]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         
[238]719          return '<td class="nowrap">'.$cat_title.'</td>';
[0]720     }
721     
[238]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()
[0]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         
[238]772          return '<td class="nowrap status">'.$img_status.' '.$selected.' '.$protected.' '.$attach.'</td>';
[0]773     }
774}
775
[452]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*/
[418]783class adminPostMiniList extends adminPostList
784{
[452]785     public function setColumns()
786     {
[508]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'));
[452]791     }
792     
[418]793     protected function getTitle() 
794     {
795          return
[431]796          '<th scope="row" class="maximal">'.
797          form::checkbox(array('entries[]'),$this->rs->post_id,'','','',!$this->rs->isEditable()).'&nbsp;'.
[418]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}
[238]803
[452]804/**
805@ingroup DC_CORE
806@nosubgrouping
807@brief abstract comments list class.
808
809Handle comments list on admin side
810*/
[519]811class adminCommentList extends adminItemsList
[0]812{
[452]813     public function setColumns()
814     {
[508]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);
[452]821     }
822     
[432]823     protected function getDefaultCaption()
824     {
825          return __('Comments list');
826     }
827     
[238]828     protected function getDefaultLine()
[0]829     {
[238]830          return
831          '<tr class="line'.($this->rs->comment_status != 1 ? ' offline' : '').'"'.
832          ' id="c'.$this->rs->comment_id.'">%s</tr>';
[0]833     }
834     
[238]835     protected function getTitle()
836     {
837          $post_url = $this->core->getPostAdminURL($this->rs->post_type,$this->rs->post_id);
838         
839          return
[431]840          '<th scope="row" class="maximal">'.
841          form::checkbox(array('comments[]'),$this->rs->comment_id,'','','',0).'&nbsp;'.
[242]842          '<a href="'.$post_url.'">'.
[238]843          html::escapeHTML($this->rs->post_title).'</a>'.
[431]844          ($this->rs->post_type != 'post' ? ' ('.html::escapeHTML($this->rs->post_type).')' : '').'</th>';
[238]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()
[0]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         
[238]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          }
[0]867         
[238]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     {
[0]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         
[238]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;
[0]900         
[238]901          return
[0]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
[452]907/**
908@ingroup DC_CORE
909@nosubgrouping
910@brief abstract users list class.
911
912Handle users list on admin side
913*/
[519]914class adminUserList extends adminItemsList
[0]915{
[452]916     public function setColumns()
917     {
[508]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')));
[452]923     }
924     
[432]925     protected function getDefaultCaption()
926     {
927          return __('Users list');
928     }
929     
[238]930     protected function getUserName()
[0]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          }
[238]943         
[0]944          return
[431]945          '<th scope="row" class="maximal">'.form::hidden(array('nb_post[]'),(integer) $this->rs->nb_post).
[242]946          form::checkbox(array('user_id[]'),$this->rs->user_id).'&nbsp;'.
[238]947          '<a href="user.php?id='.$this->rs->user_id.'">'.
[431]948          $this->rs->user_id.'</a>&nbsp;'.$img_status.'</th>';
[238]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
[0]969          '<td class="nowrap"><a href="posts.php?user_id='.$this->rs->user_id.'">'.
[238]970          $this->rs->nb_post.'</a></td>';
[0]971     }
972}
[238]973
[456]974/**
975@ingroup DC_CORE
976@nosubgrouping
977@brief abstract blogs list class.
978
979Handle blogs list on admin side
980*/
[519]981class adminBlogList extends adminItemsList
[456]982{
983     public function setColumns()
984     {
[508]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')));
[519]989          $this->addColumn('action',null,'',array('adminBlogList','getAction'),array('class' => array('nowrap')),false);
[508]990          $this->addColumn('status','blog_status',__('status'),array('adminBlogList','getStatus'),array('class' => array('nowrap')));
[456]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     {
[508]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);
[456]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
[0]1080?>
Note: See TracBrowser for help on using the repository browser.

Sites map