Dotclear

source: inc/admin/lib.pager.php @ 3239:9b3cb15542da

Revision 3239:9b3cb15542da, 22.6 KB checked in by franck <carnet.franck.paul@…>, 9 years ago (diff)

Add counters on posts and comments list admin pages, closes #2184

Line 
1<?php
2# -- BEGIN LICENSE BLOCK ---------------------------------------
3#
4# This file is part of Dotclear 2.
5#
6# Copyright (c) 2003-2013 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
14class dcPager extends pager
15{
16     protected $form_action;
17     protected $form_hidden;
18
19     protected function getLink($li_class,$href,$img_src,$img_src_nolink,$img_alt,$enable_link) {
20          if ($enable_link) {
21               $formatter = '<li class="%s btn"><a href="%s"><img src="%s" alt="%s"/></a><span class="hidden">%s</span></li>';
22               return sprintf ($formatter,
23                    $li_class,$href,$img_src,$img_alt,$img_alt);
24          } else {
25               $formatter = '<li class="%s no-link btn"><img src="%s" alt="%s"/></li>';
26               return sprintf ($formatter,
27                    $li_class,$img_src_nolink,$img_alt,$img_alt);
28          }
29     }
30     public function setURL() {
31          parent::setURL();
32          $url = parse_url($_SERVER['REQUEST_URI']);
33          if (isset($url['query'])) {
34               parse_str($url['query'],$args);
35          } else {
36               $args=array();
37          }
38          # Removing session information
39          if (session_id())
40          {
41               if (isset($args[session_name()]))
42                    unset($args[session_name()]);
43          }
44          if (isset($args[$this->var_page])) {
45               unset($args[$this->var_page]);
46          }
47          if (isset($args['ok'])) {
48               unset($args['ok']);
49          }
50          $this->form_hidden = '';
51          foreach ($args as $k=>$v) {
52               if (is_array($v)) {
53                    foreach ($v as $k2=>$v2) {
54                         $this->form_hidden .= form::hidden(array($k.'[]'),html::escapeHTML($v2));
55                    }
56               } else {
57                    $this->form_hidden .= form::hidden(array($k),html::escapeHTML($v));
58               }
59          }
60          $this->form_action = $url['path'];
61     }
62
63     /**
64     * Pager Links
65     *
66     * Returns pager links
67     *
68     * @return string
69     */
70     public function getLinks()
71     {
72          $this->setURL();
73          $htmlFirst = $this->getLink(
74               "first",
75               sprintf($this->page_url,1),
76               "images/pagination/first.png",
77               "images/pagination/no-first.png",
78               __('First page'),
79               ($this->env > 1)
80          );
81          $htmlPrev = $this->getLink(
82               "prev",
83               sprintf($this->page_url,$this->env-1),
84               "images/pagination/previous.png",
85               "images/pagination/no-previous.png",
86               __('Previous page'),
87               ($this->env > 1)
88          );
89          $htmlNext = $this->getLink(
90               "next",
91               sprintf($this->page_url,$this->env+1),
92               "images/pagination/next.png",
93               "images/pagination/no-next.png",
94               __('Next page'),
95               ($this->env < $this->nb_pages)
96          );
97          $htmlLast = $this->getLink(
98               "last",
99               sprintf($this->page_url,$this->nb_pages),
100               "images/pagination/last.png",
101               "images/pagination/no-last.png",
102               __('Last page'),
103               ($this->env < $this->nb_pages)
104          );
105          $htmlCurrent =
106               '<li class="active"><strong>'.
107               sprintf(__('Page %s / %s'),$this->env,$this->nb_pages).
108               '</strong></li>';
109
110          $htmlDirect =
111               ($this->nb_pages > 1 ?
112                    sprintf('<li class="direct-access">'.__('Direct access page %s'),
113                         form::field(array($this->var_page),3,10)).
114                    '<input type="submit" value="'.__('ok').'" class="reset" '.
115                    'name="ok" />'.$this->form_hidden.'</li>' : '');
116
117          $res =
118               '<form action="'.$this->form_action.'" method="get">'.
119               '<div class="pager"><ul>'.
120               $htmlFirst.
121               $htmlPrev.
122               $htmlCurrent.
123               $htmlNext.
124               $htmlLast.
125               $htmlDirect.
126               '</ul>'.
127               '</div>'.
128               '</form>'
129          ;
130
131          return $this->nb_elements > 0 ? $res : '';
132     }
133}
134
135class adminGenericList
136{
137     protected $core;
138     protected $rs;
139     protected $rs_count;
140
141     public function __construct($core,$rs,$rs_count)
142     {
143          $this->core =& $core;
144          $this->rs =& $rs;
145          $this->rs_count = $rs_count;
146          $this->html_prev = __('&#171; prev.');
147          $this->html_next = __('next &#187;');
148     }
149}
150
151class adminPostList extends adminGenericList
152{
153     public function display($page,$nb_per_page,$enclose_block='',$filter=false)
154     {
155          if ($this->rs->isEmpty())
156          {
157               if( $filter ) {
158                    echo '<p><strong>'.__('No entry matches the filter').'</strong></p>';
159               } else {
160                    echo '<p><strong>'.__('No entry').'</strong></p>';
161               }
162          }
163          else
164          {
165               $pager = new dcPager($page,$this->rs_count,$nb_per_page,10);
166               $entries = array();
167               if (isset($_REQUEST['entries'])) {
168                    foreach ($_REQUEST['entries'] as $v) {
169                         $entries[(integer)$v]=true;
170                    }
171               }
172               $html_block =
173               '<div class="table-outer">'.
174               '<table>';
175
176               if( $filter ) {
177                    $html_block .= '<caption>'.sprintf(__('List of %s entries matching the filter.'), $this->rs_count).'</caption>';
178               } else {
179                    $nb_published = $this->core->blog->getPosts(array('post_status' => 1),true)->f(0);
180                    $nb_pending = $this->core->blog->getPosts(array('post_status' => -2),true)->f(0);
181                    $nb_programmed = $this->core->blog->getPosts(array('post_status' => -1),true)->f(0);
182                    $nb_unpublished = $this->core->blog->getPosts(array('post_status' => 0),true)->f(0);
183                    $html_block .= '<caption>'.
184                         sprintf(__('List of entries (%s)'),$this->rs_count).
185                         ($nb_published ?
186                              sprintf(
187                              __(', <a href="%s">published</a> (1)',', <a href="%s">published</a> (%s)',$nb_published),
188                              $this->core->adminurl->get('admin.posts',array('status' => 1)),
189                              $nb_published) : '').
190                         ($nb_pending ?
191                              sprintf(
192                              __(', <a href="%s">pending</a> (1)',', <a href="%s">pending</a> (%s)',$nb_pending),
193                              $this->core->adminurl->get('admin.posts',array('status' => -2)),
194                              $nb_pending) : '').
195                         ($nb_programmed ?
196                              sprintf(__(', <a href="%s">programmed</a> (1)',', <a href="%s">programmed</a> (%s)',$nb_programmed),
197                              $this->core->adminurl->get('admin.posts',array('status' => -1)),
198                              $nb_programmed) : '').
199                         ($nb_unpublished ?
200                              sprintf(__(', <a href="%s">unpublished</a> (1)',', <a href="%s">unpublished</a> (%s)',$nb_unpublished),
201                              $this->core->adminurl->get('admin.posts',array('status' => 0)),
202                              $nb_unpublished) : '').
203                         '</caption>';
204               }
205
206               $cols = array(
207                    'title' =>               '<th colspan="2" class="first">'.__('Title').'</th>',
208                    'date' =>           '<th scope="col">'.__('Date').'</th>',
209                    'category' =>       '<th scope="col">'.__('Category').'</th>',
210                    'author' =>              '<th scope="col">'.__('Author').'</th>',
211                    'comments' =>       '<th scope="col"><img src="images/comments.png" alt="" title="'.__('Comments').
212                                             '" /><span class="hidden">'.__('Comments').'</span></th>',
213                    'trackbacks' =>          '<th scope="col"><img src="images/trackbacks.png" alt="" title="'.__('Trackbacks').
214                                             '" /><span class="hidden">'.__('Trackbacks').'</span></th>',
215                    'status' =>              '<th scope="col">'.__('Status').'</th>'
216               );
217               $cols = new ArrayObject($cols);
218               $this->core->callBehavior('adminPostListHeader',$this->core,$this->rs,$cols);
219
220               $html_block .= '<tr>'.implode(iterator_to_array($cols)).'</tr>%s</table></div>';
221               if ($enclose_block) {
222                    $html_block = sprintf($enclose_block,$html_block);
223               }
224
225               echo $pager->getLinks();
226
227               $blocks = explode('%s',$html_block);
228
229               echo $blocks[0];
230
231               while ($this->rs->fetch())
232               {
233                    echo $this->postLine(isset($entries[$this->rs->post_id]));
234               }
235
236               echo $blocks[1];
237
238               echo $pager->getLinks();
239          }
240     }
241
242     private function postLine($checked)
243     {
244          if ($this->core->auth->check('categories',$this->core->blog->id)) {
245               $cat_link = '<a href="'.$this->core->adminurl->get('admin.category',array('id' => '%s'),'&amp;',true).'">%s</a>';
246          } else {
247               $cat_link = '%2$s';
248          }
249
250          if ($this->rs->cat_title) {
251               $cat_title = sprintf($cat_link,$this->rs->cat_id,
252               html::escapeHTML($this->rs->cat_title));
253          } else {
254               $cat_title = __('(No cat)');
255          }
256
257          $img = '<img alt="%1$s" title="%1$s" src="images/%2$s" />';
258          $sts_class = '';
259          switch ($this->rs->post_status) {
260               case 1:
261                    $img_status = sprintf($img,__('Published'),'check-on.png');
262                    $sts_class = 'sts-online';
263                    break;
264               case 0:
265                    $img_status = sprintf($img,__('Unpublished'),'check-off.png');
266                    $sts_class = 'sts-offline';
267                    break;
268               case -1:
269                    $img_status = sprintf($img,__('Scheduled'),'scheduled.png');
270                    $sts_class = 'sts-scheduled';
271                    break;
272               case -2:
273                    $img_status = sprintf($img,__('Pending'),'check-wrn.png');
274                    $sts_class = 'sts-pending';
275                    break;
276          }
277
278          $protected = '';
279          if ($this->rs->post_password) {
280               $protected = sprintf($img,__('Protected'),'locker.png');
281          }
282
283          $selected = '';
284          if ($this->rs->post_selected) {
285               $selected = sprintf($img,__('Selected'),'selected.png');
286          }
287
288          $attach = '';
289          $nb_media = $this->rs->countMedia();
290          if ($nb_media > 0) {
291               $attach_str = $nb_media == 1 ? __('%d attachment') : __('%d attachments');
292               $attach = sprintf($img,sprintf($attach_str,$nb_media),'attach.png');
293          }
294
295          $res = '<tr class="line '.($this->rs->post_status != 1 ? 'offline ' : '').$sts_class.'"'.
296          ' id="p'.$this->rs->post_id.'">';
297
298          $cols = array(
299               'check' =>               '<td class="nowrap">'.
300                                        form::checkbox(array('entries[]'),$this->rs->post_id,$checked,'','',!$this->rs->isEditable()).
301                                        '</td>',
302               'title' =>               '<td class="maximal" scope="row"><a href="'.
303                                        $this->core->getPostAdminURL($this->rs->post_type,$this->rs->post_id).'">'.
304                                        html::escapeHTML($this->rs->post_title).'</a></td>',
305               'date' =>           '<td class="nowrap count">'.dt::dt2str(__('%Y-%m-%d %H:%M'),$this->rs->post_dt).'</td>',
306               'category' =>       '<td class="nowrap">'.$cat_title.'</td>',
307               'author' =>              '<td class="nowrap">'.html::escapeHTML($this->rs->user_id).'</td>',
308               'comments' =>       '<td class="nowrap count">'.$this->rs->nb_comment.'</td>',
309               'trackbacks' =>          '<td class="nowrap count">'.$this->rs->nb_trackback.'</td>',
310               'status' =>              '<td class="nowrap status">'.$img_status.' '.$selected.' '.$protected.' '.$attach.'</td>'
311          );
312          $cols = new ArrayObject($cols);
313          $this->core->callBehavior('adminPostListValue',$this->core,$this->rs,$cols);
314
315          $res .= implode(iterator_to_array($cols));
316          $res .= '</tr>';
317
318          return $res;
319     }
320}
321
322class adminPostMiniList extends adminGenericList
323{
324     public function display($page,$nb_per_page,$enclose_block='')
325     {
326          if ($this->rs->isEmpty())
327          {
328               echo '<p><strong>'.__('No entry').'</strong></p>';
329          }
330          else
331          {
332               $pager = new dcPager($page,$this->rs_count,$nb_per_page,10);
333
334               $html_block =
335               '<div class="table-outer clear">'.
336               '<table><caption class="hidden">'.__('Entries list').'</caption><tr>';
337
338               $cols = array(
339                    'title' =>          '<th scope="col">'.__('Title').'</th>',
340                    'date' =>      '<th scope="col">'.__('Date').'</th>',
341                    'author' =>         '<th scope="col">'.__('Author').'</th>',
342                    'status' =>         '<th scope="col">'.__('Status').'</th>'
343               );
344
345               $cols = new ArrayObject($cols);
346               $this->core->callBehavior('adminPostMiniListHeader',$this->core,$this->rs,$cols);
347
348               $html_block .= '<tr>'.implode(iterator_to_array($cols)).'</tr>%s</table></div>';
349               if ($enclose_block) {
350                    $html_block = sprintf($enclose_block,$html_block);
351               }
352
353               echo $pager->getLinks();
354
355               $blocks = explode('%s',$html_block);
356
357               echo $blocks[0];
358
359               while ($this->rs->fetch())
360               {
361                    echo $this->postLine();
362               }
363
364               echo $blocks[1];
365
366               echo $pager->getLinks();
367          }
368     }
369
370     private function postLine()
371     {
372          $img = '<img alt="%1$s" title="%1$s" src="images/%2$s" />';
373          $sts_class = '';
374          switch ($this->rs->post_status) {
375               case 1:
376                    $img_status = sprintf($img,__('Published'),'check-on.png');
377                    $sts_class = 'sts-online';
378                    break;
379               case 0:
380                    $img_status = sprintf($img,__('Unpublished'),'check-off.png');
381                    $sts_class = 'sts-offline';
382                    break;
383               case -1:
384                    $img_status = sprintf($img,__('Scheduled'),'scheduled.png');
385                    $sts_class = 'sts-scheduled';
386                    break;
387               case -2:
388                    $img_status = sprintf($img,__('Pending'),'check-wrn.png');
389                    $sts_class = 'sts-pending';
390                    break;
391          }
392
393          $protected = '';
394          if ($this->rs->post_password) {
395               $protected = sprintf($img,__('Protected'),'locker.png');
396          }
397
398          $selected = '';
399          if ($this->rs->post_selected) {
400               $selected = sprintf($img,__('Selected'),'selected.png');
401          }
402
403          $attach = '';
404          $nb_media = $this->rs->countMedia();
405          if ($nb_media > 0) {
406               $attach_str = $nb_media == 1 ? __('%d attachment') : __('%d attachments');
407               $attach = sprintf($img,sprintf($attach_str,$nb_media),'attach.png');
408          }
409
410          $res = '<tr class="line '.($this->rs->post_status != 1 ? 'offline ' : '').$sts_class.'"'.
411          ' id="p'.$this->rs->post_id.'">';
412
413          $cols = array(
414               'title' =>          '<td scope="row" class="maximal"><a href="'.
415                                   $this->core->getPostAdminURL($this->rs->post_type,$this->rs->post_id).'" '.
416                                   'title="'.html::escapeHTML($this->rs->getURL()).'">'.
417                                   html::escapeHTML($this->rs->post_title).'</a></td>',
418               'date' =>      '<td class="nowrap count">'.dt::dt2str(__('%Y-%m-%d %H:%M'),$this->rs->post_dt).'</td>',
419               'author' =>         '<td class="nowrap">'.html::escapeHTML($this->rs->user_id).'</td>',
420               'status' =>         '<td class="nowrap status">'.$img_status.' '.$selected.' '.$protected.' '.$attach.'</td>'
421          );
422
423          $cols = new ArrayObject($cols);
424          $this->core->callBehavior('adminPostMiniListValue',$this->core,$this->rs,$cols);
425
426          $res .= implode(iterator_to_array($cols));
427          $res .= '</tr>';
428
429          return $res;
430     }
431}
432
433class adminCommentList extends adminGenericList
434{
435     public function display($page,$nb_per_page,$enclose_block='',$filter=false,$spam=false)
436     {
437          if ($this->rs->isEmpty())
438          {
439               if( $filter ) {
440                    echo '<p><strong>'.__('No comments or trackbacks matches the filter').'</strong></p>';
441               } else {
442                    echo '<p><strong>'.__('No comments').'</strong></p>';
443               }
444          }
445          else
446          {
447               // Get antispam filters' name
448               $filters = array();
449               if ($spam) {
450                    if (class_exists('dcAntispam')) {
451                         dcAntispam::initFilters();
452                         $fs = dcAntispam::$filters->getFilters();
453                         foreach ($fs as $fid => $f)
454                         {
455                              $filters[$fid] = $f->name;
456                         }
457                    }
458               }
459
460               $pager = new dcPager($page,$this->rs_count,$nb_per_page,10);
461
462               $comments = array();
463               if (isset($_REQUEST['comments'])) {
464                    foreach ($_REQUEST['comments'] as $v) {
465                         $comments[(integer)$v]=true;
466                    }
467               }
468               $html_block =
469               '<div class="table-outer">'.
470               '<table>';
471
472               if( $filter ) {
473                    $html_block .= '<caption>'.
474                         sprintf(__(
475                              'Comment or trackback matching the filter.',
476                              'List of %s comments or trackbacks matching the filter.',
477                              $this->rs_count), $this->rs_count).
478                         '</caption>';
479               } else {
480                    $nb_published = $this->core->blog->getComments(array('comment_status' => 1),true)->f(0);
481                    $nb_spam = $this->core->blog->getComments(array('comment_status' => -2),true)->f(0);
482                    $nb_pending = $this->core->blog->getComments(array('comment_status' => -1),true)->f(0);
483                    $nb_unpublished = $this->core->blog->getComments(array('comment_status' => 0),true)->f(0);
484                    $html_block .= '<caption>'.
485                         sprintf(__('List of comments and trackbacks (%s)'),$this->rs_count).
486                         ($nb_published ?
487                              sprintf(
488                              __(', <a href="%s">published</a> (1)',', <a href="%s">published</a> (%s)',$nb_published),
489                              $this->core->adminurl->get('admin.comments',array('status' => 1)),
490                              $nb_published) : '').
491                         ($nb_spam ?
492                              sprintf(
493                              __(', <a href="%s">spam</a> (1)',', <a href="%s">spam</a> (%s)',$nb_spam),
494                              $this->core->adminurl->get('admin.comments',array('status' => -2)),
495                              $nb_spam) : '').
496                         ($nb_pending ?
497                              sprintf(__(', <a href="%s">pending</a> (1)',', <a href="%s">pending</a> (%s)',$nb_pending),
498                              $this->core->adminurl->get('admin.comments',array('status' => -1)),
499                              $nb_pending) : '').
500                         ($nb_unpublished ?
501                              sprintf(__(', <a href="%s">unpublished</a> (1)',', <a href="%s">unpublished</a> (%s)',$nb_unpublished),
502                              $this->core->adminurl->get('admin.comments',array('status' => 0)),
503                              $nb_unpublished) : '').
504                         '</caption>';
505               }
506
507               $cols = array(
508                    'type' => '<th colspan="2" scope="col" abbr="comm" class="first">'.__('Type').'</th>',
509                    'author' =>    '<th scope="col">'.__('Author').'</th>',
510                    'date' => '<th scope="col">'.__('Date').'</th>',
511                    'status' =>    '<th scope="col" class="txt-center">'.__('Status').'</th>'
512               );
513               if ($spam) {
514                    $cols['ip'] = '<th scope="col">'.__('IP').'</th>';
515                    $cols['spam_filter'] = '<th scope="col">'.__('Spam filter').'</th>';
516               }
517               $cols['entry'] = '<th scope="col" abbr="entry">'.__('Entry').'</th>';
518
519               $cols = new ArrayObject($cols);
520               $this->core->callBehavior('adminCommentListHeader',$this->core,$this->rs,$cols);
521
522               $html_block .= '<tr>'.implode(iterator_to_array($cols)).'</tr>%s</table></div>';
523
524               if ($enclose_block) {
525                    $html_block = sprintf($enclose_block,$html_block);
526               }
527
528               echo $pager->getLinks();
529
530               $blocks = explode('%s',$html_block);
531
532               echo $blocks[0];
533
534               while ($this->rs->fetch())
535               {
536                    echo $this->commentLine(isset($comments[$this->rs->comment_id]),$spam,$filters);
537               }
538
539               echo $blocks[1];
540
541               echo $pager->getLinks();
542          }
543     }
544
545     private function commentLine($checked=false,$spam=false,$filters=array())
546     {
547          global $core, $author, $status, $sortby, $order, $nb_per_page;
548
549          $author_url =
550          $this->core->adminurl->get('admin.comments',array(
551               'n' => $nb_per_page,
552               'status' => $status,
553               'sortby' => $sortby,
554               'order' => $order,
555               'author' => $this->rs->comment_author
556               ));
557
558          $post_url = $this->core->getPostAdminURL($this->rs->post_type,$this->rs->post_id);
559
560          $comment_url = $this->core->adminurl->get('admin.comment',array('id' => $this->rs->comment_id));
561
562          $comment_dt =
563          dt::dt2str($this->core->blog->settings->system->date_format.' - '.
564          $this->core->blog->settings->system->time_format,$this->rs->comment_dt);
565
566          $img = '<img alt="%1$s" title="%1$s" src="images/%2$s" />';
567          $sts_class = '';
568          switch ($this->rs->comment_status) {
569               case 1:
570                    $img_status = sprintf($img,__('Published'),'check-on.png');
571                    $sts_class = 'sts-online';
572                    break;
573               case 0:
574                    $img_status = sprintf($img,__('Unpublished'),'check-off.png');
575                    $sts_class = 'sts-offline';
576                    break;
577               case -1:
578                    $img_status = sprintf($img,__('Pending'),'check-wrn.png');
579                    $sts_class = 'sts-pending';
580                    break;
581               case -2:
582                    $img_status = sprintf($img,__('Junk'),'junk.png');
583                    $sts_class = 'sts-junk';
584                    break;
585          }
586
587          $post_title = html::escapeHTML($this->rs->post_title);
588          if (mb_strlen($post_title) > 70) {
589               $post_title = mb_strcut($post_title,0,67).'...';
590          }
591          $comment_title = sprintf(__('Edit the %1$s from %2$s'),
592               $this->rs->comment_trackback ? __('trackback') : __('comment'),
593               html::escapeHTML($this->rs->comment_author));
594
595          $res = '<tr class="line '.($this->rs->comment_status != 1 ? 'offline ' : '').$sts_class.'"'.
596          ' id="c'.$this->rs->comment_id.'">';
597
598          $cols = array(
599               'check' =>     '<td class="nowrap">'.
600                              form::checkbox(array('comments[]'),$this->rs->comment_id,$checked,'','',0).'</td>',
601               'type' => '<td class="nowrap" abbr="'.__('Type and author').'" scope="row">'.
602                              '<a href="'.$comment_url.'" title="'.$comment_title.'">'.
603                              '<img src="images/edit-mini.png" alt="'.__('Edit').'"/> '.
604                              ($this->rs->comment_trackback ? __('trackback') : __('comment')).' '.'</a></td>',
605               'author' =>    '<td class="nowrap maximal"><a href="'.$author_url.'">'.
606                              html::escapeHTML($this->rs->comment_author).'</a></td>',
607               'date'    =>   '<td class="nowrap count">'.dt::dt2str(__('%Y-%m-%d %H:%M'),$this->rs->comment_dt).'</td>',
608               'status' =>    '<td class="nowrap status txt-center">'.$img_status.'</td>'
609          );
610
611          if ($spam) {
612               $filter_name = '';
613               if ($this->rs->comment_spam_filter) {
614                    if (isset($filters[$this->rs->comment_spam_filter])) {
615                         $filter_name = $filters[$this->rs->comment_spam_filter];
616                    } else {
617                         $filter_name = $this->rs->comment_spam_filter;
618                    }
619               }
620               $cols['ip'] = '<td class="nowrap"><a href="'.
621                    $core->adminurl->get("admin.comments",array('ip' => $this->rs->comment_ip)).'">'.
622                    $this->rs->comment_ip.'</a></td>';
623               $cols['spam_filter'] = '<td class="nowrap">'.$filter_name.'</td>';
624          }
625          $cols['entry'] = '<td class="nowrap discrete"><a href="'.$post_url.'">'.$post_title.'</a>'.
626               ($this->rs->post_type != 'post' ? ' ('.html::escapeHTML($this->rs->post_type).')' : '').'</td>';
627
628          $cols = new ArrayObject($cols);
629          $this->core->callBehavior('adminCommentListValue',$this->core,$this->rs,$cols);
630
631          $res .= implode(iterator_to_array($cols));
632          $res .= '</tr>';
633
634          return $res;
635     }
636}
637
638class adminUserList extends adminGenericList
639{
640     public function display($page,$nb_per_page,$enclose_block='',$filter=false)
641     {
642          if ($this->rs->isEmpty())
643          {
644               if( $filter ) {
645                    echo '<p><strong>'.__('No user matches the filter').'</strong></p>';
646               } else {
647                    echo '<p><strong>'.__('No user').'</strong></p>';
648               }
649          }
650          else
651          {
652               $pager = new dcPager($page,$this->rs_count,$nb_per_page,10);
653
654               $html_block =
655               '<div class="table-outer clear">'.
656               '<table>';
657
658               if( $filter ) {
659                    $html_block .= '<caption>'.sprintf(__('List of %s users match the filter.'), $this->rs_count).'</caption>';
660               } else {
661                    $html_block .= '<caption class="hidden">'.__('Users list').'</caption>';
662               }
663
664               $cols = array(
665                    'username' =>       '<th colspan="2" scope="col" class="first">'.__('Username').'</th>',
666                    'first_name' =>          '<th scope="col">'.__('First Name').'</th>',
667                    'last_name' =>      '<th scope="col">'.__('Last Name').'</th>',
668                    'display_name' =>   '<th scope="col">'.__('Display name').'</th>',
669                    'entries' =>        '<th scope="col" class="nowrap">'.__('Entries (all types)').'</th>'
670               );
671
672               $cols = new ArrayObject($cols);
673               $this->core->callBehavior('adminUserListHeader',$this->core,$this->rs,$cols);
674
675               $html_block .= '<tr>'.implode(iterator_to_array($cols)).'</tr>%s</table></div>';
676               if ($enclose_block) {
677                    $html_block = sprintf($enclose_block,$html_block);
678               }
679
680               echo $pager->getLinks();
681
682               $blocks = explode('%s',$html_block);
683
684               echo $blocks[0];
685
686               while ($this->rs->fetch())
687               {
688                    echo $this->userLine();
689               }
690
691               echo $blocks[1];
692
693               echo $pager->getLinks();
694          }
695     }
696
697     private function userLine()
698     {
699          $img = '<img alt="%1$s" title="%1$s" src="images/%2$s" />';
700          $img_status = '';
701
702          $p = $this->core->getUserPermissions($this->rs->user_id);
703
704          if (isset($p[$this->core->blog->id]['p']['admin'])) {
705               $img_status = sprintf($img,__('admin'),'admin.png');
706          }
707          if ($this->rs->user_super) {
708               $img_status = sprintf($img,__('superadmin'),'superadmin.png');
709          }
710
711          $res = '<tr class="line">';
712
713          $cols = array(
714               'check' =>               '<td class="nowrap">'.form::hidden(array('nb_post[]'),(integer) $this->rs->nb_post).
715                                        form::checkbox(array('users[]'),$this->rs->user_id).'</td>',
716               'username' =>       '<td class="maximal" scope="row"><a href="'.
717                                        $this->core->adminurl->get('admin.user',array('id' => $this->rs->user_id)).'">'.
718                                        $this->rs->user_id.'</a>&nbsp;'.$img_status.'</td>',
719               'first_name' =>          '<td class="nowrap">'.html::escapeHTML($this->rs->user_firstname).'</td>',
720               'last_name' =>      '<td class="nowrap">'.html::escapeHTML($this->rs->user_name).'</td>',
721               'display_name' =>   '<td class="nowrap">'.html::escapeHTML($this->rs->user_displayname).'</td>',
722               'entries' =>        '<td class="nowrap count"><a href="'.
723                                        $this->core->adminurl->get('admin.posts',array('user_id' => $this->rs->user_id)).'">'.
724                                        $this->rs->nb_post.'</a></td>'
725          );
726
727          $cols = new ArrayObject($cols);
728          $this->core->callBehavior('adminUserListValue',$this->core,$this->rs,$cols);
729
730          $res .= implode(iterator_to_array($cols));
731          $res .= '</tr>';
732
733          return $res;
734     }
735}
Note: See TracBrowser for help on using the repository browser.

Sites map