Dotclear

source: plugins/pages/list.php @ 2000:c0c919d87d02

Revision 2000:c0c919d87d02, 8.3 KB checked in by Dsls, 12 years ago (diff)

Keep pages checked after update.

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               $entries = array();
29               if (isset($_REQUEST['entries'])) {
30                    foreach ($_REQUEST['entries'] as $v) {
31                         $entries[(integer)$v]=true;
32                    }
33               }             
34               $html_block =
35               '<table class="maximal dragable"><thead><tr>'.
36               '<th colspan="3">'.__('Title').'</th>'.
37               '<th>'.__('Date').'</th>'.
38               '<th>'.__('Author').'</th>'.
39               '<th>'.__('Comments').'</th>'.
40               '<th>'.__('Trackbacks').'</th>'.
41               '<th>'.__('Status').'</th>'.
42               '</tr></thead><tbody id="pageslist">%s</tbody></table>';
43               
44               if ($enclose_block) {
45                    $html_block = sprintf($enclose_block,$html_block);
46               }
47               
48               echo $pager->getLinks();
49               
50               $blocks = explode('%s',$html_block);
51               
52               echo $blocks[0];
53               
54               $count = 0;
55               while ($this->rs->fetch())
56               {
57                    echo $this->postLine($count,isset($entries[$this->rs->post_id]));
58                    $count ++;
59               }
60               
61               echo $blocks[1];
62               
63               echo $pager->getLinks();
64          }
65     }
66     
67     private function postLine($count,$checked)
68     {
69          $img = '<img alt="%1$s" title="%1$s" src="images/%2$s" />';
70          switch ($this->rs->post_status) {
71               case 1:
72                    $img_status = sprintf($img,__('Published'),'check-on.png');
73                    break;
74               case 0:
75                    $img_status = sprintf($img,__('Unpublished'),'check-off.png');
76                    break;
77               case -1:
78                    $img_status = sprintf($img,__('Scheduled'),'scheduled.png');
79                    break;
80               case -2:
81                    $img_status = sprintf($img,__('Pending'),'check-wrn.png');
82                    break;
83          }
84         
85          $protected = '';
86          if ($this->rs->post_password) {
87               $protected = sprintf($img,__('Protected'),'locker.png');
88          }
89         
90          $selected = '';
91          if ($this->rs->post_selected) {
92               $selected = sprintf($img,__('Hidden'),'hidden.png');
93          }
94         
95          $attach = '';
96          $nb_media = $this->rs->countMedia();
97          if ($nb_media > 0) {
98               $attach_str = $nb_media == 1 ? __('%d attachment') : __('%d attachments');
99               $attach = sprintf($img,sprintf($attach_str,$nb_media),'attach.png');
100          }
101         
102          $res = '<tr class="line'.($this->rs->post_status != 1 ? ' offline' : '').'"'.
103          ' id="p'.$this->rs->post_id.'">';
104         
105          $res .=
106          '<td class="nowrap handle minimal">'.form::field(array('order['.$this->rs->post_id.']'),2,3,$count+1,'position','',false,'title="'.sprintf(__('position of %s'),html::escapeHTML($this->rs->post_title)).'"').'</td>'.
107          '<td class="nowrap">'.
108          form::checkbox(array('entries[]'),$this->rs->post_id,$checked,'','',!$this->rs->isEditable(),'title="'.__('Select this page').'"').'</td>'.
109          '<td class="maximal"><a href="'.$this->core->getPostAdminURL($this->rs->post_type,$this->rs->post_id).'">'.
110          html::escapeHTML($this->rs->post_title).'</a></td>'.
111          '<td class="nowrap">'.dt::dt2str(__('%Y-%m-%d %H:%M'),$this->rs->post_dt).'</td>'.
112         
113          '<td class="nowrap">'.$this->rs->user_id.'</td>'.
114          '<td class="nowrap">'.$this->rs->nb_comment.'</td>'.
115          '<td class="nowrap">'.$this->rs->nb_trackback.'</td>'.
116          '<td class="nowrap status">'.$img_status.' '.$selected.' '.$protected.' '.$attach.'</td>'.
117          '</tr>';
118         
119          return $res;
120     }
121}
122
123/* Getting pages
124-------------------------------------------------------- */
125$params = array(
126     'post_type' => 'page'
127);
128
129$page = !empty($_GET['page']) ? max(1,(integer) $_GET['page']) : 1;
130$nb_per_page =  30;
131
132if (!empty($_GET['nb']) && (integer) $_GET['nb'] > 0) {
133     $nb_per_page = (integer) $_GET['nb'];
134}
135
136$params['limit'] = array((($page-1)*$nb_per_page),$nb_per_page);
137$params['no_content'] = true;
138$params['order'] = 'post_position ASC, post_title ASC';
139
140try {
141     $pages = $core->blog->getPosts($params);
142     $counter = $core->blog->getPosts($params,true);
143     $post_list = new adminPageList($core,$pages,$counter->f(0));
144} catch (Exception $e) {
145     $core->error->add($e->getMessage());
146}
147
148class dcPagesActionsPage extends dcPostsActionsPage {
149
150     public function __construct($core,$uri,$redirect_args=array()) {
151          parent::__construct($core,$uri,$redirect_args);
152          $this->redirect_fields = array();
153
154     }
155     
156     public function beginPage($breadcrumb='',$header='') {
157          echo '<html><head><title>'.__('Pages').'</title>'.
158               dcPage::jsLoad('index.php?pf=pages/list.js').
159               # --BEHAVIOR-- adminBeforePostDelete
160               $core->callBehavior('adminPagesActionsHeaders').
161               '<script type="text/javascript">'.
162               '//<![CDATA['.
163               dcPage::jsVar('dotclear.msg.confirm_delete_posts',__("Are you sure you want to delete selected pages?")).
164               '//]]>'.
165               '</script></head><body>';
166     }
167     
168     public function endPage() {
169          echo '</body></html>';
170     }
171     public function loadDefaults() {
172          parent::loadDefaults();
173          unset ($this->combos[__('Mark')]);
174          unset ($this->actions['selected']);
175          unset ($this->actions['unselected']);
176          $this->actions['reorder']=array('dcPagesActionsPage','doReorderPages');
177     }
178     public function process() {
179          // fake action for pages reordering
180          if (!empty($this->from['reorder'])) {
181               $this->from['action']='reorder';
182          }
183          parent::process();
184     }
185     
186     public static function doReorderPages($core, dcPostsActionsPage $ap, $post) {
187          foreach($post['order'] as $post_id => $value) {
188               if (!$core->auth->check('publish,contentadmin',$core->blog->id))
189                    throw new Exception(__('You are not allowed to change this entry status'));
190               
191               $strReq = "WHERE blog_id = '".$core->con->escape($core->blog->id)."' ".
192                         "AND post_id ".$core->con->in($post_id);
193               
194               #If user can only publish, we need to check the post's owner
195               if (!$core->auth->check('contentadmin',$core->blog->id))
196                    $strReq .= "AND user_id = '".$core->con->escape($core->auth->userID())."' ";
197               
198               $cur = $core->con->openCursor($core->prefix.'post');
199               
200               $cur->post_position = (integer) $value-1;
201               $cur->post_upddt = date('Y-m-d H:i:s');
202               
203               $cur->update($strReq);
204               $core->blog->triggerBlog();
205               
206          }
207          $ap->redirect(array('reo'=>1),false);
208     }   
209}
210
211# Actions combo box
212
213$pages_actions_page = new dcPagesActionsPage($core,'plugin.php',array('p'=>'pages'));
214
215$pages_actions_page->process();
216
217
218# --BEHAVIOR-- adminPagesActionsCombo
219$core->callBehavior('adminPagesActionsCombo',array(&$combo_action));
220
221/* Display
222-------------------------------------------------------- */
223?>
224<html>
225<head>
226  <title><?php echo __('Pages'); ?></title>
227  <?php
228     echo dcPage::jsLoad('js/jquery/jquery-ui.custom.js').
229          dcPage::jsLoad('index.php?pf=pages/list.js');
230  ?>
231  <script type="text/javascript">
232  //<![CDATA[
233  <?php echo dcPage::jsVar('dotclear.msg.confirm_delete_posts',__("Are you sure you want to delete selected pages?")); ?>
234  //]]>
235  </script>
236</head>
237
238<body>
239<?php
240echo dcPage::breadcrumb(
241     array(
242          html::escapeHTML($core->blog->name) => '',
243          '<span class="page-title">'.__('Pages').'</span>' => ''
244     ));
245
246if (!empty($_GET['upd'])) {
247     dcPage::success(__('Selected pages have been successfully updated.'));
248} elseif (!empty($_GET['del'])) {
249     dcPage::success(__('Selected pages have been successfully deleted.'));
250} elseif (!empty($_GET['reo'])) {
251     dcPage::success(__('Selected pages have been successfully reordered.'));
252}
253echo
254'<p class="top-add"><a class="button add" href="'.$p_url.'&amp;act=page">'.__('New page').'</a></p>';
255
256if (!$core->error->flag())
257{
258     # Show pages
259     $post_list->display($page,$nb_per_page,
260     '<form action="plugin.php" method="post" id="form-entries">'.
261     
262     '%s'.
263     
264     '<div class="two-cols">'.
265     '<p class="col checkboxes-helpers"></p>'.
266     
267     '<p class="col right"><label for="action" class="classic">'.__('Selected pages action:').'</label> '.
268     form::combo('action',$pages_actions_page->getCombo()).
269     '<input type="submit" value="'.__('ok').'" /></p>'.
270     form::hidden(array('post_type'),'page').
271     form::hidden(array('p'),'pages').
272     '</div>'.
273     $core->formNonce().
274     '<br class="clear"/>'.
275     '<input type="submit" value="'.__('Save categories order').'" name="reorder" class="clear"/>'.
276     '</form>');
277}
278dcPage::helpBlock('pages');
279?>
280</body>
281</html>
Note: See TracBrowser for help on using the repository browser.

Sites map