Dotclear

source: inc/admin/lib.pager.php @ 1917:a6026fcf0bb2

Revision 1917:a6026fcf0bb2, 13.9 KB checked in by Anne Kozlika <kozlika@…>, 12 years ago (diff)

Pagination, mise en forme et compléments.

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
17     protected function getLink($li_class,$href,$img_src,$img_src_nolink,$img_alt,$enable_link) {
18          if ($enable_link) {
19               $formatter = '<li class="%s btn"><a href="%s"><img src="%s" alt="%s"/></a><span class="hidden">%s</span></li>';
20               return sprintf ($formatter,
21                    $li_class,$href,$img_src,$img_alt,$img_alt);
22          } else {
23               $formatter = '<li class="%s no-link btn"><img src="%s" alt="%s"/></li>';
24               return sprintf ($formatter,
25                    $li_class,$img_src_nolink,$img_alt,$img_alt);
26          }
27     }
28
29     /**
30     * Pager Links
31     *
32     * Returns pager links
33     *
34     * @return string
35     */
36     public function getLinks()
37     {
38          $this->setURL();
39          $htmlFirst = $this->getLink(
40               "first",
41               sprintf($this->page_url,1),
42               "images/pagination/first.png",
43               "images/pagination/no-first.png",
44               __('First page'),
45               ($this->env > 1)
46          );
47          $htmlPrev = $this->getLink(
48               "prev",
49               sprintf($this->page_url,$this->env-1),
50               "images/pagination/previous.png",
51               "images/pagination/no-previous.png",
52               __('Previous page'),
53               ($this->env > 1)
54          );
55          $htmlNext = $this->getLink(
56               "next",
57               sprintf($this->page_url,$this->env+1),
58               "images/pagination/next.png",
59               "images/pagination/no-next.png",
60               __('Next page'),
61               ($this->env < $this->nb_pages)
62          );
63          $htmlLast = $this->getLink(
64               "last",
65               sprintf($this->page_url,$this->nb_pages),
66               "images/pagination/last.png",
67               "images/pagination/no-last.png",
68               __('Last page'),
69               ($this->env < $this->nb_pages)
70          );
71          $htmlCurrent = 
72               '<li class="active"><strong>'.
73               sprintf(__('Page %s / %s'),$this->env,$this->nb_pages).
74               '</strong></li>';
75               
76          $htmlDirect = 
77               sprintf('<li class="direct-access">'.__('Direct access page %s'),
78                    form::field(array('page'),3,10)).
79               '<input type="submit" value="'.__('ok').'" class="reset" '.
80               'name="ok" /></li>';
81         
82          $res =   
83               '<form action="'.$this->page_url.'" method="get">'.
84               '<div class="pagination"><ul>'.
85               $htmlFirst.
86               $htmlPrev.
87               $htmlCurrent.
88               $htmlNext.
89               $htmlLast.
90               $htmlDirect.
91               '</ul>'.
92               '</div>'.
93               '</form>'
94          ;
95         
96          return $this->nb_elements > 0 ? $res : '';
97     }
98}
99
100class adminGenericList
101{
102     protected $core;
103     protected $rs;
104     protected $rs_count;
105     
106     public function __construct($core,$rs,$rs_count)
107     {
108          $this->core =& $core;
109          $this->rs =& $rs;
110          $this->rs_count = $rs_count;
111     }
112}
113
114class adminPostList extends adminGenericList
115{
116     public function display($page,$nb_per_page,$enclose_block='')
117     {
118          if ($this->rs->isEmpty())
119          {
120               echo '<p><strong>'.__('No entry').'</strong></p>';
121          }
122          else
123          {
124               $pager = new dcPager($page,$this->rs_count,$nb_per_page,10);
125               $entries = array();
126               if (isset($_REQUEST['entries'])) {
127                    foreach ($_REQUEST['entries'] as $v) {
128                         $entries[(integer)$v]=true;
129                    }
130               }
131               $html_block =
132               '<table class="clear"><caption class="hidden">'.__('Entries list').'</caption><tr>'.
133               '<th colspan="2" class="first">'.__('Title').'</th>'.
134               '<th scope="col">'.__('Date').'</th>'.
135               '<th scope="col">'.__('Category').'</th>'.
136               '<th scope="col">'.__('Author').'</th>'.
137               '<th scope="col">'.__('Comments').'</th>'.
138               '<th scope="col">'.__('Trackbacks').'</th>'.
139               '<th scope="col">'.__('Status').'</th>'.
140               '</tr>%s</table>';
141               
142               if ($enclose_block) {
143                    $html_block = sprintf($enclose_block,$html_block);
144               }
145               
146               echo $pager->getLinks();
147               
148               $blocks = explode('%s',$html_block);
149               
150               echo $blocks[0];
151               
152               while ($this->rs->fetch())
153               {
154                    echo $this->postLine(isset($entries[$this->rs->post_id]));
155               }
156               
157               echo $blocks[1];
158               
159               echo $pager->getLinks();
160          }
161     }
162     
163     private function postLine($checked)
164     {
165          if ($this->core->auth->check('categories',$this->core->blog->id)) {
166               $cat_link = '<a href="category.php?id=%s">%s</a>';
167          } else {
168               $cat_link = '%2$s';
169          }
170         
171          if ($this->rs->cat_title) {
172               $cat_title = sprintf($cat_link,$this->rs->cat_id,
173               html::escapeHTML($this->rs->cat_title));
174          } else {
175               $cat_title = __('(No cat)');
176          }
177         
178          $img = '<img alt="%1$s" title="%1$s" src="images/%2$s" />';
179          switch ($this->rs->post_status) {
180               case 1:
181                    $img_status = sprintf($img,__('Published'),'check-on.png');
182                    break;
183               case 0:
184                    $img_status = sprintf($img,__('Unpublished'),'check-off.png');
185                    break;
186               case -1:
187                    $img_status = sprintf($img,__('Scheduled'),'scheduled.png');
188                    break;
189               case -2:
190                    $img_status = sprintf($img,__('Pending'),'check-wrn.png');
191                    break;
192          }
193         
194          $protected = '';
195          if ($this->rs->post_password) {
196               $protected = sprintf($img,__('Protected'),'locker.png');
197          }
198         
199          $selected = '';
200          if ($this->rs->post_selected) {
201               $selected = sprintf($img,__('Selected'),'selected.png');
202          }
203         
204          $attach = '';
205          $nb_media = $this->rs->countMedia();
206          if ($nb_media > 0) {
207               $attach_str = $nb_media == 1 ? __('%d attachment') : __('%d attachments');
208               $attach = sprintf($img,sprintf($attach_str,$nb_media),'attach.png');
209          }
210         
211          $res = '<tr class="line'.($this->rs->post_status != 1 ? ' offline' : '').'"'.
212          ' id="p'.$this->rs->post_id.'">';
213         
214          $res .=
215          '<td class="nowrap">'.
216          form::checkbox(array('entries[]'),$this->rs->post_id,$checked,'','',!$this->rs->isEditable()).'</td>'.
217          '<td class="maximal" scope="row"><a href="'.$this->core->getPostAdminURL($this->rs->post_type,$this->rs->post_id).'">'.
218          html::escapeHTML($this->rs->post_title).'</a></td>'.
219          '<td class="nowrap count">'.dt::dt2str(__('%Y-%m-%d %H:%M'),$this->rs->post_dt).'</td>'.
220          '<td class="nowrap">'.$cat_title.'</td>'.
221          '<td class="nowrap">'.html::escapeHTML($this->rs->user_id).'</td>'.
222          '<td class="nowrap count">'.$this->rs->nb_comment.'</td>'.
223          '<td class="nowrap count">'.$this->rs->nb_trackback.'</td>'.
224          '<td class="nowrap status">'.$img_status.' '.$selected.' '.$protected.' '.$attach.'</td>'.
225          '</tr>';
226         
227          return $res;
228     }
229}
230
231class adminPostMiniList extends adminGenericList
232{
233     public function display($page,$nb_per_page,$enclose_block='')
234     {
235          if ($this->rs->isEmpty())
236          {
237               echo '<p><strong>'.__('No entry').'</strong></p>';
238          }
239          else
240          {
241               $pager = new dcPager($page,$this->rs_count,$nb_per_page,10);
242               
243               $html_block =
244               '<table class="clear"><caption class="hidden">'.__('Entries list').'</caption><tr>'.
245               '<th scope="col">'.__('Title').'</th>'.
246               '<th scope="col">'.__('Date').'</th>'.
247               '<th scope="col">'.__('Author').'</th>'.
248               '<th scope="col">'.__('Status').'</th>'.
249               '</tr>%s</table>';
250               
251               if ($enclose_block) {
252                    $html_block = sprintf($enclose_block,$html_block);
253               }
254               
255               echo $pager->getLinks();
256               
257               $blocks = explode('%s',$html_block);
258               
259               echo $blocks[0];
260               
261               while ($this->rs->fetch())
262               {
263                    echo $this->postLine();
264               }
265               
266               echo $blocks[1];
267               
268               echo $pager->getLinks();
269          }
270     }
271     
272     private function postLine()
273     {
274          $img = '<img alt="%1$s" title="%1$s" src="images/%2$s" />';
275          switch ($this->rs->post_status) {
276               case 1:
277                    $img_status = sprintf($img,__('Published'),'check-on.png');
278                    break;
279               case 0:
280                    $img_status = sprintf($img,__('Unpublished'),'check-off.png');
281                    break;
282               case -1:
283                    $img_status = sprintf($img,__('Scheduled'),'scheduled.png');
284                    break;
285               case -2:
286                    $img_status = sprintf($img,__('Pending'),'check-wrn.png');
287                    break;
288          }
289         
290          $protected = '';
291          if ($this->rs->post_password) {
292               $protected = sprintf($img,__('Protected'),'locker.png');
293          }
294         
295          $selected = '';
296          if ($this->rs->post_selected) {
297               $selected = sprintf($img,__('Selected'),'selected.png');
298          }
299         
300          $attach = '';
301          $nb_media = $this->rs->countMedia();
302          if ($nb_media > 0) {
303               $attach_str = $nb_media == 1 ? __('%d attachment') : __('%d attachments');
304               $attach = sprintf($img,sprintf($attach_str,$nb_media),'attach.png');
305          }
306         
307          $res = '<tr class="line'.($this->rs->post_status != 1 ? ' offline' : '').'"'.
308          ' id="p'.$this->rs->post_id.'">';
309         
310          $res .=
311          '<td scope="row" class="maximal"><a href="'.$this->core->getPostAdminURL($this->rs->post_type,$this->rs->post_id).'" '.
312          'title="'.html::escapeHTML($this->rs->getURL()).'">'.
313          html::escapeHTML($this->rs->post_title).'</a></td>'.
314          '<td class="nowrap count">'.dt::dt2str(__('%Y-%m-%d %H:%M'),$this->rs->post_dt).'</td>'.
315          '<td class="nowrap">'.html::escapeHTML($this->rs->user_id).'</td>'.
316          '<td class="nowrap status">'.$img_status.' '.$selected.' '.$protected.' '.$attach.'</td>'.
317          '</tr>';
318         
319          return $res;
320     }
321}
322
323class adminCommentList extends adminGenericList
324{
325     public function display($page,$nb_per_page,$enclose_block='')
326     {
327          if ($this->rs->isEmpty())
328          {
329               echo '<p><strong>'.__('No comment').'</strong></p>';
330          }
331          else
332          {
333               $pager = new dcPager($page,$this->rs_count,$nb_per_page,10);
334               
335               $html_block =
336               '<table><caption class="hidden">'.__('Comments and trackbacks list').'</caption><tr>'.
337               '<th colspan="2" scope="col" abbr="comm" class="first">'.__('Type').'</th>'.
338               '<th scope="col">'.__('Author').'</th>'.
339               '<th scope="col">'.__('Date').'</th>'.
340               '<th scope="col" class="txt-center">'.__('Status').'</th>'.
341               '<th scope="col" abbr="entry">'.__('Entry title').'</th>'.
342               '</tr>%s</table>';
343
344               if ($enclose_block) {
345                    $html_block = sprintf($enclose_block,$html_block);
346               }
347               
348               echo $pager->getLinks();
349               
350               $blocks = explode('%s',$html_block);
351               
352               echo $blocks[0];
353               
354               while ($this->rs->fetch())
355               {
356                    echo $this->commentLine();
357               }
358               
359               echo $blocks[1];
360               
361               echo $pager->getLinks();
362          }
363     }
364     
365     private function commentLine()
366     {
367          global $author, $status, $sortby, $order, $nb_per_page;
368         
369          $author_url =
370          'comments.php?n='.$nb_per_page.
371          '&amp;status='.$status.
372          '&amp;sortby='.$sortby.
373          '&amp;order='.$order.
374          '&amp;author='.rawurlencode($this->rs->comment_author);
375         
376          $post_url = $this->core->getPostAdminURL($this->rs->post_type,$this->rs->post_id);
377         
378          $comment_url = 'comment.php?id='.$this->rs->comment_id;
379         
380          $comment_dt =
381          dt::dt2str($this->core->blog->settings->system->date_format.' - '.
382          $this->core->blog->settings->system->time_format,$this->rs->comment_dt);
383         
384          $img = '<img alt="%1$s" title="%1$s" src="images/%2$s" />';
385          switch ($this->rs->comment_status) {
386               case 1:
387                    $img_status = sprintf($img,__('Published'),'check-on.png');
388                    break;
389               case 0:
390                    $img_status = sprintf($img,__('Unpublished'),'check-off.png');
391                    break;
392               case -1:
393                    $img_status = sprintf($img,__('Pending'),'check-wrn.png');
394                    break;
395               case -2:
396                    $img_status = sprintf($img,__('Junk'),'junk.png');
397                    break;
398          }
399         
400          $post_title = html::escapeHTML($this->rs->post_title);
401          if (mb_strlen($post_title) > 60) {
402               $post_title = mb_strcut($post_title,0,57).'...';
403          }
404          $comment_title = sprintf(__('Edit the %1$s from %2$s'),
405               $this->rs->comment_trackback ? __('trackback') : __('comment'),
406               html::escapeHTML($this->rs->comment_author));
407         
408          $res = '<tr class="line'.($this->rs->comment_status != 1 ? ' offline' : '').'"'.
409          ' id="c'.$this->rs->comment_id.'">';
410         
411          $res .=
412          '<td class="nowrap">'.
413          form::checkbox(array('comments[]'),$this->rs->comment_id,'','','',0).'</td>'.
414          '<td class="nowrap" abbr="'.__('Type and author').'" scope="raw">'.
415               '<a href="'.$comment_url.'" title="'.$comment_title.'">'.
416               '<img src="images/edit-mini.png" alt="'.__('Edit').'"/> '.
417               ($this->rs->comment_trackback ? __('trackback') : __('comment')).' '.'</a></td>'.
418          '<td class="nowrap maximal"><a href="'.$author_url.'">'.html::escapeHTML($this->rs->comment_author).'</a></td>'.
419          '<td class="nowrap count">'.dt::dt2str(__('%Y-%m-%d %H:%M'),$this->rs->comment_dt).'</td>'.
420          '<td class="nowrap status txt-center">'.$img_status.'</td>'.
421          '<td class="nowrap"><a href="'.$post_url.'">'.
422          html::escapeHTML($post_title).'</a>'.
423          ($this->rs->post_type != 'post' ? ' ('.html::escapeHTML($this->rs->post_type).')' : '').'</td>';
424         
425          $res .= '</tr>';
426         
427          return $res;
428     }
429}
430
431class adminUserList extends adminGenericList
432{
433     public function display($page,$nb_per_page,$enclose_block='')
434     {
435          if ($this->rs->isEmpty())
436          {
437               echo '<p><strong>'.__('No user').'</strong></p>';
438          }
439          else
440          {
441               $pager = new dcPager($page,$this->rs_count,$nb_per_page,10);
442               
443               $html_block =
444               '<table class="clear"><caption class="hidden">'.__('Users list').'</caption><tr>'.
445               '<th colspan="2" scope="col" class="first">'.__('Username').'</th>'.
446               '<th scope="col">'.__('First Name').'</th>'.
447               '<th scope="col">'.__('Last Name').'</th>'.
448               '<th scope="col">'.__('Display name').'</th>'.
449               '<th scope="col" class="nowrap">'.__('Entries (all types)').'</th>'.
450               '</tr>%s</table>';
451               
452               if ($enclose_block) {
453                    $html_block = sprintf($enclose_block,$html_block);
454               }
455               
456               echo $pager->getLinks();
457               
458               $blocks = explode('%s',$html_block);
459               
460               echo $blocks[0];
461               
462               while ($this->rs->fetch())
463               {
464                    echo $this->userLine();
465               }
466               
467               echo $blocks[1];
468               
469               echo $pager->getLinks();
470          }
471     }
472     
473     private function userLine()
474     {
475          $img = '<img alt="%1$s" title="%1$s" src="images/%2$s" />';
476          $img_status = '';
477         
478          $p = $this->core->getUserPermissions($this->rs->user_id);
479         
480          if (isset($p[$this->core->blog->id]['p']['admin'])) {
481               $img_status = sprintf($img,__('admin'),'admin.png');
482          }
483          if ($this->rs->user_super) {
484               $img_status = sprintf($img,__('superadmin'),'superadmin.png');
485          }
486          return
487          '<tr class="line">'.
488          '<td class="nowrap">'.form::hidden(array('nb_post[]'),(integer) $this->rs->nb_post).
489          form::checkbox(array('users[]'),$this->rs->user_id).'</td>'.
490          '<td class="maximal" scope="row"><a href="user.php?id='.$this->rs->user_id.'">'.
491          $this->rs->user_id.'</a>&nbsp;'.$img_status.'</td>'.
492          '<td class="nowrap">'.html::escapeHTML($this->rs->user_firstname).'</td>'.
493          '<td class="nowrap">'.html::escapeHTML($this->rs->user_name).'</td>'.
494          '<td class="nowrap">'.html::escapeHTML($this->rs->user_displayname).'</td>'.
495          '<td class="nowrap count"><a href="posts.php?user_id='.$this->rs->user_id.'">'.
496          $this->rs->nb_post.'</a></td>'.
497          '</tr>';
498     }
499}
500?>
Note: See TracBrowser for help on using the repository browser.

Sites map