[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 | { |
---|
| 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'); |
---|
[1806] | 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); |
---|
[1796] | 24 | |
---|
| 25 | } |
---|
| 26 | |
---|
| 27 | public function beginPage($breadcrumb='',$head='') { |
---|
| 28 | dcPage::open( |
---|
| 29 | __('Entries'), |
---|
[1806] | 30 | |
---|
[1796] | 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) { |
---|
[1806] | 43 | $this->core->error->add($e->getMessage()); |
---|
[1796] | 44 | $this->beginPage(dcPage::breadcrumb( |
---|
| 45 | array( |
---|
[1806] | 46 | html::escapeHTML($this->core->blog->name) => '', |
---|
[1796] | 47 | __('Entries') => 'posts.php', |
---|
| 48 | '<span class="page-title">'.__('Entries actions').'</span>' => '' |
---|
| 49 | )) |
---|
| 50 | ); |
---|
| 51 | $this->endPage(); |
---|
| 52 | } |
---|
| 53 | |
---|
[1806] | 54 | protected function fetchEntries($from) { |
---|
[1796] | 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 | { |
---|
[1806] | 86 | public static function adminPostsActionsPage($core, dcPostsActionsPage $ap) { |
---|
[1796] | 87 | if ($core->auth->check('publish,contentadmin',$core->blog->id)) { |
---|
[1806] | 88 | $ap->addAction( |
---|
[1796] | 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 | } |
---|
[1806] | 98 | $ap->addAction( |
---|
[1796] | 99 | array(__('Mark')=> array( |
---|
| 100 | __('Mark as selected') => 'selected', |
---|
| 101 | __('Mark as unselected') => 'unselected' |
---|
| 102 | )), |
---|
| 103 | array('dcDefaultPostActions','doUpdateSelectedPost') |
---|
| 104 | ); |
---|
[1806] | 105 | $ap->addAction( |
---|
[1796] | 106 | array(__('Change') => array( |
---|
| 107 | __('Change category') => 'category', |
---|
| 108 | )), |
---|
| 109 | array('dcDefaultPostActions','doChangePostCategory') |
---|
| 110 | ); |
---|
[1806] | 111 | $ap->addAction( |
---|
[1796] | 112 | array(__('Change') => array( |
---|
| 113 | __('Change language') => 'lang', |
---|
| 114 | )), |
---|
| 115 | array('dcDefaultPostActions','doChangePostLang') |
---|
| 116 | ); |
---|
| 117 | if ($core->auth->check('admin',$core->blog->id)) |
---|
| 118 | { |
---|
[1806] | 119 | $ap->addAction( |
---|
[1796] | 120 | array(__('Change') => array( |
---|
| 121 | __('Change author') => 'author')), |
---|
[1806] | 122 | array('dcDefaultPostActions','doChangePostAuthor') |
---|
[1796] | 123 | ); |
---|
| 124 | } |
---|
| 125 | if ($core->auth->check('delete,contentadmin',$core->blog->id)) { |
---|
[1806] | 126 | $ap->addAction( |
---|
[1796] | 127 | array(__('Delete') => array( |
---|
| 128 | __('Delete') => 'delete')), |
---|
| 129 | array('dcDefaultPostActions','doDeletePost') |
---|
| 130 | ); |
---|
| 131 | } |
---|
| 132 | } |
---|
| 133 | |
---|
[1806] | 134 | public static function doChangePostStatus($core, dcPostsActionsPage $ap, $post) { |
---|
| 135 | switch ($ap->getAction()) { |
---|
[1796] | 136 | case 'unpublish' : $status = 0; break; |
---|
| 137 | case 'schedule' : $status = -1; break; |
---|
| 138 | case 'pending' : $status = -2; break; |
---|
| 139 | default : $status = 1; break; |
---|
| 140 | } |
---|
[1806] | 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); |
---|
[1796] | 146 | |
---|
[1806] | 147 | $ap->redirect(array('upd' => 1),true); |
---|
[1796] | 148 | } |
---|
| 149 | |
---|
[1806] | 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')); |
---|
[1796] | 154 | } |
---|
[1806] | 155 | $action = $ap->getAction(); |
---|
| 156 | $core->blog->updPostsSelected($posts_ids,$action == 'selected'); |
---|
| 157 | |
---|
| 158 | $ap->redirect(array('upd' => 1),true); |
---|
[1796] | 159 | } |
---|
| 160 | |
---|
[1806] | 161 | public static function doDeletePost($core, dcPostsActionsPage $ap, $post) { |
---|
[1796] | 162 | |
---|
[1806] | 163 | $posts_ids = $ap->getIDs(); |
---|
[1796] | 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 | |
---|
[1806] | 179 | $ap->redirect(array('del',1),false); |
---|
[1796] | 180 | } |
---|
| 181 | |
---|
[1806] | 182 | public static function doChangePostCategory($core, dcPostsActionsPage $ap, $post) { |
---|
[1796] | 183 | if (isset($post['new_cat_id'])) { |
---|
[1806] | 184 | $posts_ids = $ap->getIDs(); |
---|
[1796] | 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 | |
---|
[1806] | 208 | $ap->redirect(array('upd'=>1),true); |
---|
[1796] | 209 | } else { |
---|
[1806] | 210 | $ap->beginPage( |
---|
[1796] | 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">'. |
---|
[1806] | 225 | $ap->getCheckboxes(). |
---|
[1796] | 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>'; |
---|
[1806] | 246 | $ap->endPage(); |
---|
[1796] | 247 | |
---|
| 248 | } |
---|
| 249 | |
---|
| 250 | } |
---|
[1806] | 251 | public static function doChangePostAuthor($core, dcPostsActionsPage $ap, $post) { |
---|
[1796] | 252 | if (isset($post['new_auth_id']) && $core->auth->check('admin',$core->blog->id)) { |
---|
| 253 | $new_user_id = $post['new_auth_id']; |
---|
[1806] | 254 | $posts_ids = $ap->getIDs(); |
---|
[1796] | 255 | if (empty($posts_ids)) { |
---|
| 256 | throw new Exception(__('No entry selected')); |
---|
| 257 | } |
---|
[1806] | 258 | if ($core->getUser($new_user_id)->isEmpty()) { |
---|
| 259 | throw new Exception(__('This user does not exist')); |
---|
| 260 | } |
---|
[1796] | 261 | |
---|
[1806] | 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); |
---|
[1796] | 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 | } |
---|
[1806] | 280 | $ap->beginPage( |
---|
[1796] | 281 | dcPage::breadcrumb( |
---|
| 282 | array( |
---|
| 283 | html::escapeHTML($core->blog->name) => '', |
---|
| 284 | __('Entries') => 'posts.php', |
---|
[1806] | 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" |
---|
[1796] | 292 | ); |
---|
| 293 | |
---|
| 294 | echo |
---|
| 295 | '<form action="posts_actions.php" method="post">'. |
---|
[1806] | 296 | $ap->getCheckboxes(). |
---|
[1796] | 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>'; |
---|
[1806] | 305 | $ap->endPage(); |
---|
[1796] | 306 | } |
---|
| 307 | } |
---|
[1806] | 308 | public static function doChangePostLang($core, dcPostsActionsPage $ap, $post) { |
---|
[1796] | 309 | if (isset($post['new_lang'])) { |
---|
| 310 | $new_lang = $post['new_lang']; |
---|
[1806] | 311 | $cur = $core->con->openCursor($core->prefix.'post'); |
---|
| 312 | $cur->post_lang = $new_lang; |
---|
| 313 | $cur->update('WHERE post_id '.$core->con->in($posts_ids)); |
---|
| 314 | |
---|
| 315 | $ap->redirect(array('upd' => 1),true); |
---|
[1796] | 316 | } else { |
---|
[1806] | 317 | $ap->beginPage( |
---|
[1796] | 318 | dcPage::breadcrumb( |
---|
| 319 | array( |
---|
| 320 | html::escapeHTML($core->blog->name) => '', |
---|
| 321 | __('Entries') => 'posts.php', |
---|
| 322 | '<span class="page-title">'.__('Change language for entries').'</span>' => '' |
---|
| 323 | ))); |
---|
| 324 | # lang list |
---|
| 325 | # Languages combo |
---|
| 326 | $rs = $core->blog->getLangs(array('order'=>'asc')); |
---|
| 327 | $all_langs = l10n::getISOcodes(0,1); |
---|
| 328 | $lang_combo = array('' => '', __('Most used') => array(), __('Available') => l10n::getISOcodes(1,1)); |
---|
| 329 | while ($rs->fetch()) { |
---|
| 330 | if (isset($all_langs[$rs->post_lang])) { |
---|
| 331 | $lang_combo[__('Most used')][$all_langs[$rs->post_lang]] = $rs->post_lang; |
---|
| 332 | unset($lang_combo[__('Available')][$all_langs[$rs->post_lang]]); |
---|
| 333 | } else { |
---|
| 334 | $lang_combo[__('Most used')][$rs->post_lang] = $rs->post_lang; |
---|
| 335 | } |
---|
| 336 | } |
---|
| 337 | unset($all_langs); |
---|
| 338 | unset($rs); |
---|
| 339 | |
---|
| 340 | echo |
---|
| 341 | '<form action="posts_actions.php" method="post">'. |
---|
[1806] | 342 | $ap->getCheckboxes(). |
---|
[1796] | 343 | |
---|
| 344 | '<p><label for="new_lang" class="classic">'.__('Entry lang:').'</label> '. |
---|
| 345 | form::combo('new_lang',$lang_combo,''); |
---|
| 346 | |
---|
| 347 | echo |
---|
| 348 | $core->formNonce(). |
---|
| 349 | form::hidden(array('action'),'lang'). |
---|
| 350 | '<input type="submit" value="'.__('Save').'" /></p>'. |
---|
| 351 | '</form>'; |
---|
| 352 | } |
---|
| 353 | } |
---|
| 354 | } |
---|