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