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