Dotclear

source: inc/admin/lib.pager.php @ 1998:dae906985ebb

Revision 1998:dae906985ebb, 14.8 KB checked in by Dsls, 12 years ago (diff)

Updated pager to handle multiple parameters, see #1687

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.'[]'),$v2);
55                    }
56               } else {
57                    $this->form_hidden .= form::hidden(array($k),$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('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='')
154     {
155          if ($this->rs->isEmpty())
156          {
157               echo '<p><strong>'.__('No entry').'</strong></p>';
158          }
159          else
160          {
161               $pager = new dcPager($page,$this->rs_count,$nb_per_page,10);
162               $entries = array();
163               if (isset($_REQUEST['entries'])) {
164                    foreach ($_REQUEST['entries'] as $v) {
165                         $entries[(integer)$v]=true;
166                    }
167               }
168               $html_block =
169               '<table class="clear"><caption class="hidden">'.__('Entries list').'</caption><tr>'.
170               '<th colspan="2" class="first">'.__('Title').'</th>'.
171               '<th scope="col">'.__('Date').'</th>'.
172               '<th scope="col">'.__('Category').'</th>'.
173               '<th scope="col">'.__('Author').'</th>'.
174               '<th scope="col">'.__('Comments').'</th>'.
175               '<th scope="col">'.__('Trackbacks').'</th>'.
176               '<th scope="col">'.__('Status').'</th>'.
177               '</tr>%s</table>';
178               
179               if ($enclose_block) {
180                    $html_block = sprintf($enclose_block,$html_block);
181               }
182               
183               echo $pager->getLinks();
184               
185               $blocks = explode('%s',$html_block);
186               
187               echo $blocks[0];
188               
189               while ($this->rs->fetch())
190               {
191                    echo $this->postLine(isset($entries[$this->rs->post_id]));
192               }
193               
194               echo $blocks[1];
195               
196               echo $pager->getLinks();
197          }
198     }
199     
200     private function postLine($checked)
201     {
202          if ($this->core->auth->check('categories',$this->core->blog->id)) {
203               $cat_link = '<a href="category.php?id=%s">%s</a>';
204          } else {
205               $cat_link = '%2$s';
206          }
207         
208          if ($this->rs->cat_title) {
209               $cat_title = sprintf($cat_link,$this->rs->cat_id,
210               html::escapeHTML($this->rs->cat_title));
211          } else {
212               $cat_title = __('(No cat)');
213          }
214         
215          $img = '<img alt="%1$s" title="%1$s" src="images/%2$s" />';
216          switch ($this->rs->post_status) {
217               case 1:
218                    $img_status = sprintf($img,__('Published'),'check-on.png');
219                    break;
220               case 0:
221                    $img_status = sprintf($img,__('Unpublished'),'check-off.png');
222                    break;
223               case -1:
224                    $img_status = sprintf($img,__('Scheduled'),'scheduled.png');
225                    break;
226               case -2:
227                    $img_status = sprintf($img,__('Pending'),'check-wrn.png');
228                    break;
229          }
230         
231          $protected = '';
232          if ($this->rs->post_password) {
233               $protected = sprintf($img,__('Protected'),'locker.png');
234          }
235         
236          $selected = '';
237          if ($this->rs->post_selected) {
238               $selected = sprintf($img,__('Selected'),'selected.png');
239          }
240         
241          $attach = '';
242          $nb_media = $this->rs->countMedia();
243          if ($nb_media > 0) {
244               $attach_str = $nb_media == 1 ? __('%d attachment') : __('%d attachments');
245               $attach = sprintf($img,sprintf($attach_str,$nb_media),'attach.png');
246          }
247         
248          $res = '<tr class="line'.($this->rs->post_status != 1 ? ' offline' : '').'"'.
249          ' id="p'.$this->rs->post_id.'">';
250         
251          $res .=
252          '<td class="nowrap">'.
253          form::checkbox(array('entries[]'),$this->rs->post_id,$checked,'','',!$this->rs->isEditable()).'</td>'.
254          '<td class="maximal" scope="row"><a href="'.$this->core->getPostAdminURL($this->rs->post_type,$this->rs->post_id).'">'.
255          html::escapeHTML($this->rs->post_title).'</a></td>'.
256          '<td class="nowrap count">'.dt::dt2str(__('%Y-%m-%d %H:%M'),$this->rs->post_dt).'</td>'.
257          '<td class="nowrap">'.$cat_title.'</td>'.
258          '<td class="nowrap">'.html::escapeHTML($this->rs->user_id).'</td>'.
259          '<td class="nowrap count">'.$this->rs->nb_comment.'</td>'.
260          '<td class="nowrap count">'.$this->rs->nb_trackback.'</td>'.
261          '<td class="nowrap status">'.$img_status.' '.$selected.' '.$protected.' '.$attach.'</td>'.
262          '</tr>';
263         
264          return $res;
265     }
266}
267
268class adminPostMiniList extends adminGenericList
269{
270     public function display($page,$nb_per_page,$enclose_block='')
271     {
272          if ($this->rs->isEmpty())
273          {
274               echo '<p><strong>'.__('No entry').'</strong></p>';
275          }
276          else
277          {
278               $pager = new dcPager($page,$this->rs_count,$nb_per_page,10);
279               
280               $html_block =
281               '<table class="clear"><caption class="hidden">'.__('Entries list').'</caption><tr>'.
282               '<th scope="col">'.__('Title').'</th>'.
283               '<th scope="col">'.__('Date').'</th>'.
284               '<th scope="col">'.__('Author').'</th>'.
285               '<th scope="col">'.__('Status').'</th>'.
286               '</tr>%s</table>';
287               
288               if ($enclose_block) {
289                    $html_block = sprintf($enclose_block,$html_block);
290               }
291               
292               echo $pager->getLinks();
293               
294               $blocks = explode('%s',$html_block);
295               
296               echo $blocks[0];
297               
298               while ($this->rs->fetch())
299               {
300                    echo $this->postLine();
301               }
302               
303               echo $blocks[1];
304               
305               echo $pager->getLinks();
306          }
307     }
308     
309     private function postLine()
310     {
311          $img = '<img alt="%1$s" title="%1$s" src="images/%2$s" />';
312          switch ($this->rs->post_status) {
313               case 1:
314                    $img_status = sprintf($img,__('Published'),'check-on.png');
315                    break;
316               case 0:
317                    $img_status = sprintf($img,__('Unpublished'),'check-off.png');
318                    break;
319               case -1:
320                    $img_status = sprintf($img,__('Scheduled'),'scheduled.png');
321                    break;
322               case -2:
323                    $img_status = sprintf($img,__('Pending'),'check-wrn.png');
324                    break;
325          }
326         
327          $protected = '';
328          if ($this->rs->post_password) {
329               $protected = sprintf($img,__('Protected'),'locker.png');
330          }
331         
332          $selected = '';
333          if ($this->rs->post_selected) {
334               $selected = sprintf($img,__('Selected'),'selected.png');
335          }
336         
337          $attach = '';
338          $nb_media = $this->rs->countMedia();
339          if ($nb_media > 0) {
340               $attach_str = $nb_media == 1 ? __('%d attachment') : __('%d attachments');
341               $attach = sprintf($img,sprintf($attach_str,$nb_media),'attach.png');
342          }
343         
344          $res = '<tr class="line'.($this->rs->post_status != 1 ? ' offline' : '').'"'.
345          ' id="p'.$this->rs->post_id.'">';
346         
347          $res .=
348          '<td scope="row" class="maximal"><a href="'.$this->core->getPostAdminURL($this->rs->post_type,$this->rs->post_id).'" '.
349          'title="'.html::escapeHTML($this->rs->getURL()).'">'.
350          html::escapeHTML($this->rs->post_title).'</a></td>'.
351          '<td class="nowrap count">'.dt::dt2str(__('%Y-%m-%d %H:%M'),$this->rs->post_dt).'</td>'.
352          '<td class="nowrap">'.html::escapeHTML($this->rs->user_id).'</td>'.
353          '<td class="nowrap status">'.$img_status.' '.$selected.' '.$protected.' '.$attach.'</td>'.
354          '</tr>';
355         
356          return $res;
357     }
358}
359
360class adminCommentList extends adminGenericList
361{
362     public function display($page,$nb_per_page,$enclose_block='')
363     {
364          if ($this->rs->isEmpty())
365          {
366               echo '<p><strong>'.__('No comment').'</strong></p>';
367          }
368          else
369          {
370               $pager = new dcPager($page,$this->rs_count,$nb_per_page,10);
371               
372               $html_block =
373               '<table><caption class="hidden">'.__('Comments and trackbacks list').'</caption><tr>'.
374               '<th colspan="2" scope="col" abbr="comm" class="first">'.__('Type').'</th>'.
375               '<th scope="col">'.__('Author').'</th>'.
376               '<th scope="col">'.__('Date').'</th>'.
377               '<th scope="col" class="txt-center">'.__('Status').'</th>'.
378               '<th scope="col" abbr="entry">'.__('Entry title').'</th>'.
379               '</tr>%s</table>';
380
381               if ($enclose_block) {
382                    $html_block = sprintf($enclose_block,$html_block);
383               }
384               
385               echo $pager->getLinks();
386               
387               $blocks = explode('%s',$html_block);
388               
389               echo $blocks[0];
390               
391               while ($this->rs->fetch())
392               {
393                    echo $this->commentLine();
394               }
395               
396               echo $blocks[1];
397               
398               echo $pager->getLinks();
399          }
400     }
401     
402     private function commentLine()
403     {
404          global $author, $status, $sortby, $order, $nb_per_page;
405         
406          $author_url =
407          'comments.php?n='.$nb_per_page.
408          '&amp;status='.$status.
409          '&amp;sortby='.$sortby.
410          '&amp;order='.$order.
411          '&amp;author='.rawurlencode($this->rs->comment_author);
412         
413          $post_url = $this->core->getPostAdminURL($this->rs->post_type,$this->rs->post_id);
414         
415          $comment_url = 'comment.php?id='.$this->rs->comment_id;
416         
417          $comment_dt =
418          dt::dt2str($this->core->blog->settings->system->date_format.' - '.
419          $this->core->blog->settings->system->time_format,$this->rs->comment_dt);
420         
421          $img = '<img alt="%1$s" title="%1$s" src="images/%2$s" />';
422          switch ($this->rs->comment_status) {
423               case 1:
424                    $img_status = sprintf($img,__('Published'),'check-on.png');
425                    break;
426               case 0:
427                    $img_status = sprintf($img,__('Unpublished'),'check-off.png');
428                    break;
429               case -1:
430                    $img_status = sprintf($img,__('Pending'),'check-wrn.png');
431                    break;
432               case -2:
433                    $img_status = sprintf($img,__('Junk'),'junk.png');
434                    break;
435          }
436         
437          $post_title = html::escapeHTML($this->rs->post_title);
438          if (mb_strlen($post_title) > 60) {
439               $post_title = mb_strcut($post_title,0,57).'...';
440          }
441          $comment_title = sprintf(__('Edit the %1$s from %2$s'),
442               $this->rs->comment_trackback ? __('trackback') : __('comment'),
443               html::escapeHTML($this->rs->comment_author));
444         
445          $res = '<tr class="line'.($this->rs->comment_status != 1 ? ' offline' : '').'"'.
446          ' id="c'.$this->rs->comment_id.'">';
447         
448          $res .=
449          '<td class="nowrap">'.
450          form::checkbox(array('comments[]'),$this->rs->comment_id,'','','',0).'</td>'.
451          '<td class="nowrap" abbr="'.__('Type and author').'" scope="row">'.
452               '<a href="'.$comment_url.'" title="'.$comment_title.'">'.
453               '<img src="images/edit-mini.png" alt="'.__('Edit').'"/> '.
454               ($this->rs->comment_trackback ? __('trackback') : __('comment')).' '.'</a></td>'.
455          '<td class="nowrap maximal"><a href="'.$author_url.'">'.html::escapeHTML($this->rs->comment_author).'</a></td>'.
456          '<td class="nowrap count">'.dt::dt2str(__('%Y-%m-%d %H:%M'),$this->rs->comment_dt).'</td>'.
457          '<td class="nowrap status txt-center">'.$img_status.'</td>'.
458          '<td class="nowrap"><a href="'.$post_url.'">'.
459          html::escapeHTML($post_title).'</a>'.
460          ($this->rs->post_type != 'post' ? ' ('.html::escapeHTML($this->rs->post_type).')' : '').'</td>';
461         
462          $res .= '</tr>';
463         
464          return $res;
465     }
466}
467
468class adminUserList extends adminGenericList
469{
470     public function display($page,$nb_per_page,$enclose_block='')
471     {
472          if ($this->rs->isEmpty())
473          {
474               echo '<p><strong>'.__('No user').'</strong></p>';
475          }
476          else
477          {
478               $pager = new dcPager($page,$this->rs_count,$nb_per_page,10);
479               
480               $html_block =
481               '<table class="clear"><caption class="hidden">'.__('Users list').'</caption><tr>'.
482               '<th colspan="2" scope="col" class="first">'.__('Username').'</th>'.
483               '<th scope="col">'.__('First Name').'</th>'.
484               '<th scope="col">'.__('Last Name').'</th>'.
485               '<th scope="col">'.__('Display name').'</th>'.
486               '<th scope="col" class="nowrap">'.__('Entries (all types)').'</th>'.
487               '</tr>%s</table>';
488               
489               if ($enclose_block) {
490                    $html_block = sprintf($enclose_block,$html_block);
491               }
492               
493               echo $pager->getLinks();
494               
495               $blocks = explode('%s',$html_block);
496               
497               echo $blocks[0];
498               
499               while ($this->rs->fetch())
500               {
501                    echo $this->userLine();
502               }
503               
504               echo $blocks[1];
505               
506               echo $pager->getLinks();
507          }
508     }
509     
510     private function userLine()
511     {
512          $img = '<img alt="%1$s" title="%1$s" src="images/%2$s" />';
513          $img_status = '';
514         
515          $p = $this->core->getUserPermissions($this->rs->user_id);
516         
517          if (isset($p[$this->core->blog->id]['p']['admin'])) {
518               $img_status = sprintf($img,__('admin'),'admin.png');
519          }
520          if ($this->rs->user_super) {
521               $img_status = sprintf($img,__('superadmin'),'superadmin.png');
522          }
523          return
524          '<tr class="line">'.
525          '<td class="nowrap">'.form::hidden(array('nb_post[]'),(integer) $this->rs->nb_post).
526          form::checkbox(array('users[]'),$this->rs->user_id).'</td>'.
527          '<td class="maximal" scope="row"><a href="user.php?id='.$this->rs->user_id.'">'.
528          $this->rs->user_id.'</a>&nbsp;'.$img_status.'</td>'.
529          '<td class="nowrap">'.html::escapeHTML($this->rs->user_firstname).'</td>'.
530          '<td class="nowrap">'.html::escapeHTML($this->rs->user_name).'</td>'.
531          '<td class="nowrap">'.html::escapeHTML($this->rs->user_displayname).'</td>'.
532          '<td class="nowrap count"><a href="posts.php?user_id='.$this->rs->user_id.'">'.
533          $this->rs->nb_post.'</a></td>'.
534          '</tr>';
535     }
536}
537?>
Note: See TracBrowser for help on using the repository browser.

Sites map