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_RC_PATH')) { return; } |
---|
13 | |
---|
14 | class dcPostsActionsPage extends dcActionsPage |
---|
15 | { |
---|
16 | public function __construct($core,$uri) { |
---|
17 | parent::__construct($core,$uri); |
---|
18 | $this->redirect_fields = array('user_id','cat_id','status', |
---|
19 | 'selected','month','lang','sortby','order','page','nb'); |
---|
20 | // We could have added a behavior here, but we want default action |
---|
21 | // to be setup first |
---|
22 | dcDefaultPostActions::adminPostsActionsPage($core,$this); |
---|
23 | $core->callBehavior('adminPostsActionsPage',$core,$this); |
---|
24 | |
---|
25 | } |
---|
26 | |
---|
27 | public function beginPage($breadcrumb='',$head='') { |
---|
28 | dcPage::open( |
---|
29 | __('Entries'), |
---|
30 | |
---|
31 | dcPage::jsLoad('js/_posts_actions.js'). |
---|
32 | $head, |
---|
33 | $breadcrumb |
---|
34 | ); |
---|
35 | echo '<p><a class="back" href="'.$this->getRedirection(array(),true).'">'.__('Back to entries list').'</a></p>'; |
---|
36 | } |
---|
37 | |
---|
38 | public function endPage() { |
---|
39 | dcPage::close(); |
---|
40 | } |
---|
41 | |
---|
42 | public function error(Exception $e) { |
---|
43 | $this->core->error->add($e->getMessage()); |
---|
44 | $this->beginPage(dcPage::breadcrumb( |
---|
45 | array( |
---|
46 | html::escapeHTML($this->core->blog->name) => '', |
---|
47 | __('Entries') => 'posts.php', |
---|
48 | '<span class="page-title">'.__('Entries actions').'</span>' => '' |
---|
49 | )) |
---|
50 | ); |
---|
51 | $this->endPage(); |
---|
52 | } |
---|
53 | |
---|
54 | protected function fetchEntries($from) { |
---|
55 | if (!empty($from['entries'])) |
---|
56 | { |
---|
57 | $entries = $from['entries']; |
---|
58 | |
---|
59 | foreach ($entries as $k => $v) { |
---|
60 | $entries[$k] = (integer) $v; |
---|
61 | } |
---|
62 | |
---|
63 | $params['sql'] = 'AND P.post_id IN('.implode(',',$entries).') '; |
---|
64 | |
---|
65 | if (!isset($from['full_content']) || empty($from['full_content'])) { |
---|
66 | $params['no_content'] = true; |
---|
67 | } |
---|
68 | |
---|
69 | if (isset($from['post_type'])) { |
---|
70 | $params['post_type'] = $from['post_type']; |
---|
71 | } |
---|
72 | |
---|
73 | $posts = $this->core->blog->getPosts($params); |
---|
74 | while ($posts->fetch()) { |
---|
75 | $this->entries[$posts->post_id] = $posts->post_title; |
---|
76 | } |
---|
77 | $this->rs = $posts; |
---|
78 | } else { |
---|
79 | $this->rs = $this->core->con->select("SELECT blog_id FROM ".$this->core->prefix."blog WHERE false");; |
---|
80 | } |
---|
81 | } |
---|
82 | } |
---|
83 | |
---|
84 | class dcDefaultPostActions |
---|
85 | { |
---|
86 | public static function adminPostsActionsPage($core, dcPostsActionsPage $ap) { |
---|
87 | if ($core->auth->check('publish,contentadmin',$core->blog->id)) { |
---|
88 | $ap->addAction( |
---|
89 | array(__('Status') => array( |
---|
90 | __('Publish') => 'publish', |
---|
91 | __('Unpublish') => 'unpublish', |
---|
92 | __('Schedule') => 'schedule', |
---|
93 | __('Mark as pending') => 'pending' |
---|
94 | )), |
---|
95 | array('dcDefaultPostActions','doChangePostStatus') |
---|
96 | ); |
---|
97 | } |
---|
98 | $ap->addAction( |
---|
99 | array(__('Mark')=> array( |
---|
100 | __('Mark as selected') => 'selected', |
---|
101 | __('Mark as unselected') => 'unselected' |
---|
102 | )), |
---|
103 | array('dcDefaultPostActions','doUpdateSelectedPost') |
---|
104 | ); |
---|
105 | $ap->addAction( |
---|
106 | array(__('Change') => array( |
---|
107 | __('Change category') => 'category', |
---|
108 | )), |
---|
109 | array('dcDefaultPostActions','doChangePostCategory') |
---|
110 | ); |
---|
111 | $ap->addAction( |
---|
112 | array(__('Change') => array( |
---|
113 | __('Change language') => 'lang', |
---|
114 | )), |
---|
115 | array('dcDefaultPostActions','doChangePostLang') |
---|
116 | ); |
---|
117 | if ($core->auth->check('admin',$core->blog->id)) |
---|
118 | { |
---|
119 | $ap->addAction( |
---|
120 | array(__('Change') => array( |
---|
121 | __('Change author') => 'author')), |
---|
122 | array('dcDefaultPostActions','doChangePostAuthor') |
---|
123 | ); |
---|
124 | } |
---|
125 | if ($core->auth->check('delete,contentadmin',$core->blog->id)) { |
---|
126 | $ap->addAction( |
---|
127 | array(__('Delete') => array( |
---|
128 | __('Delete') => 'delete')), |
---|
129 | array('dcDefaultPostActions','doDeletePost') |
---|
130 | ); |
---|
131 | } |
---|
132 | } |
---|
133 | |
---|
134 | public static function doChangePostStatus($core, dcPostsActionsPage $ap, $post) { |
---|
135 | switch ($ap->getAction()) { |
---|
136 | case 'unpublish' : $status = 0; break; |
---|
137 | case 'schedule' : $status = -1; break; |
---|
138 | case 'pending' : $status = -2; break; |
---|
139 | default : $status = 1; break; |
---|
140 | } |
---|
141 | $posts_ids = $ap->getIDs(); |
---|
142 | if (empty($posts_ids)) { |
---|
143 | throw new Exception(__('No entry selected')); |
---|
144 | } |
---|
145 | $core->blog->updPostsStatus($posts_ids,$status); |
---|
146 | |
---|
147 | $ap->redirect(array('upd' => 1),true); |
---|
148 | } |
---|
149 | |
---|
150 | public static function doUpdateSelectedPost($core, dcPostsActionsPage $ap, $post) { |
---|
151 | $posts_ids = $ap->getIDs(); |
---|
152 | if (empty($posts_ids)) { |
---|
153 | throw new Exception(__('No entry selected')); |
---|
154 | } |
---|
155 | $action = $ap->getAction(); |
---|
156 | $core->blog->updPostsSelected($posts_ids,$action == 'selected'); |
---|
157 | |
---|
158 | $ap->redirect(array('upd' => 1),true); |
---|
159 | } |
---|
160 | |
---|
161 | public static function doDeletePost($core, dcPostsActionsPage $ap, $post) { |
---|
162 | |
---|
163 | $posts_ids = $ap->getIDs(); |
---|
164 | if (empty($posts_ids)) { |
---|
165 | throw new Exception(__('No entry selected')); |
---|
166 | } |
---|
167 | // Backward compatibility |
---|
168 | foreach($posts_ids as $post_id) |
---|
169 | { |
---|
170 | # --BEHAVIOR-- adminBeforePostDelete |
---|
171 | $core->callBehavior('adminBeforePostDelete',(integer) $post_id); |
---|
172 | } |
---|
173 | |
---|
174 | # --BEHAVIOR-- adminBeforePostsDelete |
---|
175 | $core->callBehavior('adminBeforePostsDelete',$posts_ids); |
---|
176 | |
---|
177 | $core->blog->delPosts($posts_ids); |
---|
178 | |
---|
179 | $ap->redirect(array('del',1),false); |
---|
180 | } |
---|
181 | |
---|
182 | public static function doChangePostCategory($core, dcPostsActionsPage $ap, $post) { |
---|
183 | if (isset($post['new_cat_id'])) { |
---|
184 | $posts_ids = $ap->getIDs(); |
---|
185 | if (empty($posts_ids)) { |
---|
186 | throw new Exception(__('No entry selected')); |
---|
187 | } |
---|
188 | $new_cat_id = $post['new_cat_id']; |
---|
189 | if (!empty($post['new_cat_title']) && $core->auth->check('categories', $core->blog->id)) |
---|
190 | { |
---|
191 | $cur_cat = $core->con->openCursor($core->prefix.'category'); |
---|
192 | $cur_cat->cat_title = $post['new_cat_title']; |
---|
193 | $cur_cat->cat_url = ''; |
---|
194 | |
---|
195 | $parent_cat = !empty($post['new_cat_parent']) ? $post['new_cat_parent'] : ''; |
---|
196 | |
---|
197 | # --BEHAVIOR-- adminBeforeCategoryCreate |
---|
198 | $core->callBehavior('adminBeforeCategoryCreate', $cur_cat); |
---|
199 | |
---|
200 | $new_cat_id = $core->blog->addCategory($cur_cat, (integer) $parent_cat); |
---|
201 | |
---|
202 | # --BEHAVIOR-- adminAfterCategoryCreate |
---|
203 | $core->callBehavior('adminAfterCategoryCreate', $cur_cat, $new_cat_id); |
---|
204 | } |
---|
205 | |
---|
206 | $core->blog->updPostsCategory($posts_ids, $new_cat_id); |
---|
207 | |
---|
208 | $ap->redirect(array('upd'=>1),true); |
---|
209 | } else { |
---|
210 | $ap->beginPage( |
---|
211 | dcPage::breadcrumb( |
---|
212 | array( |
---|
213 | html::escapeHTML($core->blog->name) => '', |
---|
214 | __('Entries') => 'posts.php', |
---|
215 | '<span class="page-title">'.__('Change category for entries').'</span>' => '' |
---|
216 | ))); |
---|
217 | |
---|
218 | # categories list |
---|
219 | # Getting categories |
---|
220 | $categories_combo = dcAdminCombos::getCategoriesCombo( |
---|
221 | $core->blog->getCategories(array('post_type'=>'post')) |
---|
222 | ); |
---|
223 | echo |
---|
224 | '<form action="posts.php" method="post">'. |
---|
225 | $ap->getCheckboxes(). |
---|
226 | '<p><label for="new_cat_id" class="classic">'.__('Category:').'</label> '. |
---|
227 | form::combo('new_cat_id',$categories_combo,''); |
---|
228 | |
---|
229 | if ($core->auth->check('categories', $core->blog->id)) { |
---|
230 | echo |
---|
231 | '<div>'. |
---|
232 | '<p id="new_cat">'.__('Create a new category for the post(s)').'</p>'. |
---|
233 | '<p><label for="new_cat_title">'.__('Title:').'</label> '. |
---|
234 | form::field('new_cat_title',30,255,'','').'</p>'. |
---|
235 | '<p><label for="new_cat_parent">'.__('Parent:').'</label> '. |
---|
236 | form::combo('new_cat_parent',$categories_combo,'',''). |
---|
237 | '</p>'. |
---|
238 | '</div>'; |
---|
239 | } |
---|
240 | |
---|
241 | echo |
---|
242 | $core->formNonce(). |
---|
243 | form::hidden(array('action'),'category'). |
---|
244 | '<input type="submit" value="'.__('Save').'" /></p>'. |
---|
245 | '</form>'; |
---|
246 | $ap->endPage(); |
---|
247 | |
---|
248 | } |
---|
249 | |
---|
250 | } |
---|
251 | public static function doChangePostAuthor($core, dcPostsActionsPage $ap, $post) { |
---|
252 | if (isset($post['new_auth_id']) && $core->auth->check('admin',$core->blog->id)) { |
---|
253 | $new_user_id = $post['new_auth_id']; |
---|
254 | $posts_ids = $ap->getIDs(); |
---|
255 | if (empty($posts_ids)) { |
---|
256 | throw new Exception(__('No entry selected')); |
---|
257 | } |
---|
258 | if ($core->getUser($new_user_id)->isEmpty()) { |
---|
259 | throw new Exception(__('This user does not exist')); |
---|
260 | } |
---|
261 | |
---|
262 | $cur = $core->con->openCursor($core->prefix.'post'); |
---|
263 | $cur->user_id = $new_user_id; |
---|
264 | $cur->update('WHERE post_id '.$core->con->in($posts_ids)); |
---|
265 | |
---|
266 | $ap->redirect(array('upd' => 1),true); |
---|
267 | } else { |
---|
268 | $usersList = ''; |
---|
269 | if ($core->auth->check('admin',$core->blog->id)) { |
---|
270 | $params = array( |
---|
271 | 'limit' => 100, |
---|
272 | 'order' => 'nb_post DESC' |
---|
273 | ); |
---|
274 | $rs = $core->getUsers($params); |
---|
275 | while ($rs->fetch()) |
---|
276 | { |
---|
277 | $usersList .= ($usersList != '' ? ',' : '').'"'.$rs->user_id.'"'; |
---|
278 | } |
---|
279 | } |
---|
280 | $ap->beginPage( |
---|
281 | dcPage::breadcrumb( |
---|
282 | array( |
---|
283 | html::escapeHTML($core->blog->name) => '', |
---|
284 | __('Entries') => 'posts.php', |
---|
285 | '<span class="page-title">'.__('Change author for entries').'</span>' => '')), |
---|
286 | dcPage::jsLoad('js/jquery/jquery.autocomplete.js'). |
---|
287 | '<script type="text/javascript">'."\n". |
---|
288 | "//<![CDATA[\n". |
---|
289 | 'usersList = ['.$usersList.']'."\n". |
---|
290 | "\n//]]>\n". |
---|
291 | "</script>\n" |
---|
292 | ); |
---|
293 | |
---|
294 | echo |
---|
295 | '<form action="posts_actions.php" method="post">'. |
---|
296 | $ap->getCheckboxes(). |
---|
297 | '<p><label for="new_auth_id" class="classic">'.__('New author (author ID):').'</label> '. |
---|
298 | form::field('new_auth_id',20,255); |
---|
299 | |
---|
300 | echo |
---|
301 | $core->formNonce(). |
---|
302 | form::hidden(array('action'),'author'). |
---|
303 | '<input type="submit" value="'.__('Save').'" /></p>'. |
---|
304 | '</form>'; |
---|
305 | $ap->endPage(); |
---|
306 | } |
---|
307 | } |
---|
308 | public static function doChangePostLang($core, dcPostsActionsPage $ap, $post) { |
---|
309 | $posts_ids = $ap->getIDs(); |
---|
310 | if (empty($posts_ids)) { |
---|
311 | throw new Exception(__('No entry selected')); |
---|
312 | } |
---|
313 | if (isset($post['new_lang'])) { |
---|
314 | $new_lang = $post['new_lang']; |
---|
315 | $cur = $core->con->openCursor($core->prefix.'post'); |
---|
316 | $cur->post_lang = $new_lang; |
---|
317 | $cur->update('WHERE post_id '.$core->con->in($posts_ids)); |
---|
318 | |
---|
319 | $ap->redirect(array('upd' => 1),true); |
---|
320 | } else { |
---|
321 | $ap->beginPage( |
---|
322 | dcPage::breadcrumb( |
---|
323 | array( |
---|
324 | html::escapeHTML($core->blog->name) => '', |
---|
325 | __('Entries') => 'posts.php', |
---|
326 | '<span class="page-title">'.__('Change language for entries').'</span>' => '' |
---|
327 | ))); |
---|
328 | # lang list |
---|
329 | # Languages combo |
---|
330 | $rs = $core->blog->getLangs(array('order'=>'asc')); |
---|
331 | $all_langs = l10n::getISOcodes(0,1); |
---|
332 | $lang_combo = array('' => '', __('Most used') => array(), __('Available') => l10n::getISOcodes(1,1)); |
---|
333 | while ($rs->fetch()) { |
---|
334 | if (isset($all_langs[$rs->post_lang])) { |
---|
335 | $lang_combo[__('Most used')][$all_langs[$rs->post_lang]] = $rs->post_lang; |
---|
336 | unset($lang_combo[__('Available')][$all_langs[$rs->post_lang]]); |
---|
337 | } else { |
---|
338 | $lang_combo[__('Most used')][$rs->post_lang] = $rs->post_lang; |
---|
339 | } |
---|
340 | } |
---|
341 | unset($all_langs); |
---|
342 | unset($rs); |
---|
343 | |
---|
344 | echo |
---|
345 | '<form action="posts_actions.php" method="post">'. |
---|
346 | $ap->getCheckboxes(). |
---|
347 | |
---|
348 | '<p><label for="new_lang" class="classic">'.__('Entry lang:').'</label> '. |
---|
349 | form::combo('new_lang',$lang_combo,''); |
---|
350 | |
---|
351 | echo |
---|
352 | $core->formNonce(). |
---|
353 | form::hidden(array('action'),'lang'). |
---|
354 | '<input type="submit" value="'.__('Save').'" /></p>'. |
---|
355 | '</form>'; |
---|
356 | } |
---|
357 | } |
---|
358 | } |
---|