Dotclear

source: plugins/pages/list.php @ 1926:9e3008aad0ff

Revision 1926:9e3008aad0ff, 5.7 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_CONTEXT_ADMIN')) { return; }
13dcPage::check('pages,contentadmin');
14
15/* Pager class
16-------------------------------------------------------- */
17class adminPageList extends adminGenericList
18{
19     public function display($page,$nb_per_page,$enclose_block='')
20     {
21          if ($this->rs->isEmpty())
22          {
23               echo '<p><strong>'.__('No page').'</strong></p>';
24          }
25          else
26          {
27               $pager = new dcPager($page,$this->rs_count,$nb_per_page,10);
28               
29               $html_block =
30               '<table class="clear"><tr>'.
31               '<th colspan="2">'.__('Title').'</th>'.
32               '<th>'.__('Date').'</th>'.
33               '<th>'.__('Author').'</th>'.
34               '<th>'.__('Comments').'</th>'.
35               '<th>'.__('Trackbacks').'</th>'.
36               '<th>'.__('Status').'</th>'.
37               '</tr>%s</table>';
38               
39               if ($enclose_block) {
40                    $html_block = sprintf($enclose_block,$html_block);
41               }
42               
43               echo $pager->getLinks();
44               
45               $blocks = explode('%s',$html_block);
46               
47               echo $blocks[0];
48               
49               while ($this->rs->fetch())
50               {
51                    echo $this->postLine();
52               }
53               
54               echo $blocks[1];
55               
56               echo $pager->getLinks();
57          }
58     }
59     
60     private function postLine()
61     {
62          $img = '<img alt="%1$s" title="%1$s" src="images/%2$s" />';
63          switch ($this->rs->post_status) {
64               case 1:
65                    $img_status = sprintf($img,__('Published'),'check-on.png');
66                    break;
67               case 0:
68                    $img_status = sprintf($img,__('Unpublished'),'check-off.png');
69                    break;
70               case -1:
71                    $img_status = sprintf($img,__('Scheduled'),'scheduled.png');
72                    break;
73               case -2:
74                    $img_status = sprintf($img,__('Pending'),'check-wrn.png');
75                    break;
76          }
77         
78          $protected = '';
79          if ($this->rs->post_password) {
80               $protected = sprintf($img,__('Protected'),'locker.png');
81          }
82         
83          $selected = '';
84          if ($this->rs->post_selected) {
85               $selected = sprintf($img,__('Hidden'),'hidden.png');
86          }
87         
88          $attach = '';
89          $nb_media = $this->rs->countMedia();
90          if ($nb_media > 0) {
91               $attach_str = $nb_media == 1 ? __('%d attachment') : __('%d attachments');
92               $attach = sprintf($img,sprintf($attach_str,$nb_media),'attach.png');
93          }
94         
95          $res = '<tr class="line'.($this->rs->post_status != 1 ? ' offline' : '').'"'.
96          ' id="p'.$this->rs->post_id.'">';
97         
98          $res .=
99          '<td class="nowrap">'.
100          form::checkbox(array('entries[]'),$this->rs->post_id,'','','',!$this->rs->isEditable(),'title="'.__('Select this page').'"').'</td>'.
101          '<td class="maximal"><a href="'.$this->core->getPostAdminURL($this->rs->post_type,$this->rs->post_id).'">'.
102          html::escapeHTML($this->rs->post_title).'</a></td>'.
103          '<td class="nowrap">'.dt::dt2str(__('%Y-%m-%d %H:%M'),$this->rs->post_dt).'</td>'.
104         
105          '<td class="nowrap">'.$this->rs->user_id.'</td>'.
106          '<td class="nowrap">'.$this->rs->nb_comment.'</td>'.
107          '<td class="nowrap">'.$this->rs->nb_trackback.'</td>'.
108          '<td class="nowrap status">'.$img_status.' '.$selected.' '.$protected.' '.$attach.'</td>'.
109          '</tr>';
110         
111          return $res;
112     }
113}
114
115/* Getting pages
116-------------------------------------------------------- */
117$params = array(
118     'post_type' => 'page'
119);
120
121$page = !empty($_GET['page']) ? max(1,(integer) $_GET['page']) : 1;
122$nb_per_page =  30;
123
124if (!empty($_GET['nb']) && (integer) $_GET['nb'] > 0) {
125     $nb_per_page = (integer) $_GET['nb'];
126}
127
128$params['limit'] = array((($page-1)*$nb_per_page),$nb_per_page);
129$params['no_content'] = true;
130$params['order'] = 'post_position ASC, post_title ASC';
131
132try {
133     $pages = $core->blog->getPosts($params);
134     $counter = $core->blog->getPosts($params,true);
135     $post_list = new adminPageList($core,$pages,$counter->f(0));
136} catch (Exception $e) {
137     $core->error->add($e->getMessage());
138}
139
140# Actions combo box
141$combo_action = array();
142if ($core->auth->check('publish,contentadmin',$core->blog->id))
143{
144     $combo_action[__('Publish')] = 'publish';
145     $combo_action[__('Unpublish')] = 'unpublish';
146     $combo_action[__('Schedule')] = 'schedule';
147     $combo_action[__('Mark as pending')] = 'pending';
148}
149if ($core->auth->check('admin',$core->blog->id)) {
150     $combo_action[__('Change author')] = 'author';
151}
152if ($core->auth->check('delete,contentadmin',$core->blog->id))
153{
154     $combo_action[__('Delete')] = 'delete';
155}
156
157# --BEHAVIOR-- adminPagesActionsCombo
158$core->callBehavior('adminPagesActionsCombo',array(&$combo_action));
159
160/* Display
161-------------------------------------------------------- */
162?>
163<html>
164<head>
165  <title><?php echo __('Pages'); ?></title>
166  <script type="text/javascript" src="js/_posts_list.js"></script>
167  <script type="text/javascript">
168  //<![CDATA[
169  <?php echo dcPage::jsVar('dotclear.msg.confirm_delete_posts',__("Are you sure you want to delete selected pages?")); ?>
170  //]]>
171  </script>
172</head>
173
174<body>
175<?php
176echo dcPage::breadcrumb(
177     array(
178          html::escapeHTML($core->blog->name) => '',
179          '<span class="page-title">'.__('Pages').'</span>' => ''
180     ));
181
182echo
183'<p class="top-add"><a class="button add" href="'.$p_url.'&amp;act=page">'.__('New page').'</a></p>';
184
185if (!$core->error->flag())
186{
187     # Show pages
188     $post_list->display($page,$nb_per_page,
189     '<form action="posts_actions.php" method="post" id="form-entries">'.
190     
191     '%s'.
192     
193     '<div class="two-cols">'.
194     '<p class="col checkboxes-helpers"></p>'.
195     
196     '<p class="col right"><label for="action" class="classic">'.__('Selected pages action:').'</label> '.
197     form::combo('action',$combo_action).
198     '<input type="submit" value="'.__('ok').'" /></p>'.
199     form::hidden(array('post_type'),'page').
200     form::hidden(array('redir'),html::escapeHTML($_SERVER['REQUEST_URI'])).
201     $core->formNonce().
202     '</div>'.
203     '</form>');
204}
205dcPage::helpBlock('pages');
206?>
207</body>
208</html>
Note: See TracBrowser for help on using the repository browser.

Sites map