Dotclear

source: inc/admin/lib.pager.php @ 1476:c45f3be639b6

Revision 1476:c45f3be639b6, 11.9 KB checked in by Dsls, 12 years ago (diff)
  • Selection is kept when going back to entries
  • Notifications when applying changes
  • Added "back to entries" link

see #1540

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"><tr>'.
52               '<th colspan="2">'.__('Title').'</th>'.
53               '<th>'.__('Date').'</th>'.
54               '<th>'.__('Category').'</th>'.
55               '<th>'.__('Author').'</th>'.
56               '<th>'.__('Comments').'</th>'.
57               '<th>'.__('Trackbacks').'</th>'.
58               '<th>'.__('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"><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"><tr>'.
167               '<th>'.__('Title').'</th>'.
168               '<th>'.__('Date').'</th>'.
169               '<th>'.__('Author').'</th>'.
170               '<th>'.__('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 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><tr>'.
262               '<th colspan="2">'.__('Title').'</th>'.
263               '<th>'.__('Date').'</th>'.
264               '<th>'.__('Author').'</th>'.
265               '<th>'.__('Type').'</th>'.
266               '<th>'.__('Status').'</th>'.
267               '<th>&nbsp;</th>'.
268               '</tr>%s</table>';
269               
270               if ($enclose_block) {
271                    $html_block = sprintf($enclose_block,$html_block);
272               }
273               
274               echo '<p class="pagination">'.__('Page(s)').' : '.$pager->getLinks().'</p>';
275               
276               $blocks = explode('%s',$html_block);
277               
278               echo $blocks[0];
279               
280               while ($this->rs->fetch())
281               {
282                    echo $this->commentLine();
283               }
284               
285               echo $blocks[1];
286               
287               echo '<p class="pagination">'.__('Page(s)').' : '.$pager->getLinks().'</p>';
288          }
289     }
290     
291     private function commentLine()
292     {
293          global $author, $status, $sortby, $order, $nb_per_page;
294         
295          $author_url =
296          'comments.php?n='.$nb_per_page.
297          '&amp;status='.$status.
298          '&amp;sortby='.$sortby.
299          '&amp;order='.$order.
300          '&amp;author='.rawurlencode($this->rs->comment_author);
301         
302          $post_url = $this->core->getPostAdminURL($this->rs->post_type,$this->rs->post_id);
303         
304          $comment_url = 'comment.php?id='.$this->rs->comment_id;
305         
306          $comment_dt =
307          dt::dt2str($this->core->blog->settings->system->date_format.' - '.
308          $this->core->blog->settings->system->time_format,$this->rs->comment_dt);
309         
310          $img = '<img alt="%1$s" title="%1$s" src="images/%2$s" />';
311          switch ($this->rs->comment_status) {
312               case 1:
313                    $img_status = sprintf($img,__('Published'),'check-on.png');
314                    break;
315               case 0:
316                    $img_status = sprintf($img,__('Unpublished'),'check-off.png');
317                    break;
318               case -1:
319                    $img_status = sprintf($img,__('Pending'),'check-wrn.png');
320                    break;
321               case -2:
322                    $img_status = sprintf($img,__('Junk'),'junk.png');
323                    break;
324          }
325         
326          $comment_author = html::escapeHTML($this->rs->comment_author);
327          if (mb_strlen($comment_author) > 20) {
328               $comment_author = mb_strcut($comment_author,0,17).'...';
329          }
330         
331          $res = '<tr class="line'.($this->rs->comment_status != 1 ? ' offline' : '').'"'.
332          ' id="c'.$this->rs->comment_id.'">';
333         
334          $res .=
335          '<td class="nowrap">'.
336          form::checkbox(array('comments[]'),$this->rs->comment_id,'','','',0).'</td>'.
337          '<td class="maximal"><a href="'.$post_url.'">'.
338          html::escapeHTML($this->rs->post_title).'</a>'.
339          ($this->rs->post_type != 'post' ? ' ('.html::escapeHTML($this->rs->post_type).')' : '').'</td>'.
340          '<td class="nowrap">'.dt::dt2str(__('%Y-%m-%d %H:%M'),$this->rs->comment_dt).'</td>'.
341          '<td class="nowrap"><a href="'.$author_url.'">'.html::escapeHTML($comment_author).'</a></td>'.
342          '<td class="nowrap">'.($this->rs->comment_trackback ? __('trackback') : __('comment')).'</td>'.
343          '<td class="nowrap status">'.$img_status.'</td>'.
344          '<td class="nowrap status"><a href="'.$comment_url.'">'.
345          '<img src="images/edit-mini.png" alt="" title="'.__('Edit this comment').'" /></a></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"><tr>'.
370               '<th colspan="2">'.__('Username').'</th>'.
371               '<th>'.__('First Name').'</th>'.
372               '<th>'.__('Last Name').'</th>'.
373               '<th>'.__('Display name').'</th>'.
374               '<th 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"><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