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