Dotclear

source: plugins/pages/list.php @ 2048:a23152342139

Revision 2048:a23152342139, 8.6 KB checked in by Dsls, 12 years ago (diff)

exit is a bit rough and not really ob_start compliand, made it smoother for plugins; Tuned pages plugin so that it works ... now

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='',$head='') {
158          echo '<html><head><title>'.__('Pages').'</title>'.
159               dcPage::jsLoad('js/_posts_actions.js').
160               '<script type="text/javascript">'.
161               '//<![CDATA['.
162               dcPage::jsVar('dotclear.msg.confirm_delete_posts',__("Are you sure you want to delete selected pages?")).
163               '//]]>'.
164               $head.
165               '</script></head><body>';
166               '</head><body>'.$breadcrumb;
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          $this->from['post_type']='page';
185          return parent::process();
186     }
187     
188     public static function doReorderPages($core, dcPostsActionsPage $ap, $post) {
189          foreach($post['order'] as $post_id => $value) {
190               if (!$core->auth->check('publish,contentadmin',$core->blog->id))
191                    throw new Exception(__('You are not allowed to change this entry status'));
192               
193               $strReq = "WHERE blog_id = '".$core->con->escape($core->blog->id)."' ".
194                         "AND post_id ".$core->con->in($post_id);
195               
196               #If user can only publish, we need to check the post's owner
197               if (!$core->auth->check('contentadmin',$core->blog->id))
198                    $strReq .= "AND user_id = '".$core->con->escape($core->auth->userID())."' ";
199               
200               $cur = $core->con->openCursor($core->prefix.'post');
201               
202               $cur->post_position = (integer) $value-1;
203               $cur->post_upddt = date('Y-m-d H:i:s');
204               
205               $cur->update($strReq);
206               $core->blog->triggerBlog();
207               
208          }
209          $ap->redirect(array('reo'=>1),false);
210     }   
211}
212
213# Actions combo box
214
215$pages_actions_page = new dcPagesActionsPage($core,'plugin.php',array('p'=>'pages'));
216
217if (!$pages_actions_page->process()) {
218
219
220# --BEHAVIOR-- adminPagesActionsCombo
221$core->callBehavior('adminPagesActionsCombo',array(&$combo_action));
222
223/* Display
224-------------------------------------------------------- */
225?>
226<html>
227<head>
228  <title><?php echo __('Pages'); ?></title>
229  <?php
230     echo dcPage::jsLoad('js/jquery/jquery-ui.custom.js').
231          dcPage::jsLoad('index.php?pf=pages/list.js');
232  ?>
233  <script type="text/javascript">
234  //<![CDATA[
235  <?php echo dcPage::jsVar('dotclear.msg.confirm_delete_posts',__("Are you sure you want to delete selected pages?")); ?>
236  //]]>
237  </script>
238</head>
239
240<body>
241<?php
242echo dcPage::breadcrumb(
243     array(
244          html::escapeHTML($core->blog->name) => '',
245          '<span class="page-title">'.__('Pages').'</span>' => ''
246     ));
247
248if (!empty($_GET['upd'])) {
249     dcPage::success(__('Selected pages have been successfully updated.'));
250} elseif (!empty($_GET['del'])) {
251     dcPage::success(__('Selected pages have been successfully deleted.'));
252} elseif (!empty($_GET['reo'])) {
253     dcPage::success(__('Selected pages have been successfully reordered.'));
254}
255echo
256'<p class="top-add"><a class="button add" href="'.$p_url.'&amp;act=page">'.__('New page').'</a></p>';
257
258if (!$core->error->flag())
259{
260     # Show pages
261     $post_list->display($page,$nb_per_page,
262     '<form action="plugin.php" method="post" id="form-entries">'.
263     
264     '%s'.
265     
266     '<div class="two-cols">'.
267     '<p class="col checkboxes-helpers"></p>'.
268     
269     '<p class="col right"><label for="action" class="classic">'.__('Selected pages action:').'</label> '.
270     form::combo('action',$pages_actions_page->getCombo()).
271     '<input type="submit" value="'.__('ok').'" /></p>'.
272     form::hidden(array('post_type'),'page').
273     form::hidden(array('p'),'pages').
274     form::hidden(array('act'),'list').
275     '</div>'.
276     $core->formNonce().
277     '<p class="clear form-note hidden-if-js">'.
278     __('To rearrange pages order, change number at the begining of the line, then click on “Save pages order” button.').'</p>'.
279     '<p class="clear form-note hidden-if-no-js">'.
280     __('To rearrange pages order, move items by drag and drop, then click on “Save pages order” button.').'</p>'.
281     '<input type="submit" value="'.__('Save pages order').'" name="reorder" class="clear"/>'.
282     '</form>');
283}
284dcPage::helpBlock('pages');
285?>
286</body>
287</html>
288<?php
289}
290?>
Note: See TracBrowser for help on using the repository browser.

Sites map