Dotclear

source: inc/admin/lib.pager.php @ 1928:daad8ebfd228

Revision 1928:daad8ebfd228, 14.6 KB checked in by Dsls, 12 years ago (diff)

Restored useless older pager attributes, so that older plugins do not complain.

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

Sites map