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