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