Dotclear

source: inc/admin/lib.pager.php @ 2008:e37733c175b5

Revision 2008:e37733c175b5, 15.1 KB checked in by Dsls, 12 years ago (diff)

fixed warnings on admin/comments.php

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

Sites map