Dotclear

source: plugins/pages/list.php @ 2002:a0de6679a058

Revision 2002:a0de6679a058, 8.3 KB checked in by Anne Kozlika <kozlika@…>, 12 years ago (diff)

Tableaux responsive. Poke jcDenis :-)

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

Sites map