Dotclear

source: inc/admin/lib.pager.php @ 1926:9e3008aad0ff

Revision 1926:9e3008aad0ff, 14.6 KB checked in by Dsls, 12 years ago (diff)

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

Sites map