Dotclear

source: inc/admin/lib.pager.php @ 1622:8acfe7bdb542

Revision 1622:8acfe7bdb542, 12.5 KB checked in by Anne Kozlika <kozlika@…>, 11 years ago (diff)

HTML validation

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

Sites map