Dotclear

source: inc/admin/lib.pager.php @ 1909:e73d8d511f5c

Revision 1909:e73d8d511f5c, 13.8 KB checked in by Dsls, 12 years ago (diff)

New paging style 1st shot, see #1607

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

Sites map