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