Changeset 1527:5a3fad0f97e2
- Timestamp:
- 08/23/13 09:16:33 (10 years ago)
- Branch:
- default
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
admin/posts_actions.php
r1520 r1527 133 133 134 134 $fields = new FieldsList(); 135 136 /* Actions 137 -------------------------------------------------------- */ 138 if (!empty($_POST['action']) && !empty($_POST['entries'])) 135 $posts_ids = array(); 136 137 if (isset($_POST['redir']) && strpos($_POST['redir'],'://') === false) 138 { 139 $redir = $_POST['redir']; 140 } 141 else 142 { 143 $redir = 144 'posts.php?user_id='.$_POST['user_id']. 145 '&cat_id='.$_POST['cat_id']. 146 '&status='.$_POST['status']. 147 '&selected='.$_POST['selected']. 148 '&month='.$_POST['month']. 149 '&lang='.$_POST['lang']. 150 '&sortby='.$_POST['sortby']. 151 '&order='.$_POST['order']. 152 '&page='.$_POST['page']. 153 '&nb='.$_POST['nb']; 154 } 155 $redir_sel = $redir; 156 157 if (!empty($_POST['entries'])) 139 158 { 140 159 $entries = $_POST['entries']; 141 $action = $_POST['action'];142 143 if (isset($_POST['redir']) && strpos($_POST['redir'],'://') === false)144 {145 $redir = $_POST['redir'];146 }147 else148 {149 $redir =150 'posts.php?user_id='.$_POST['user_id'].151 '&cat_id='.$_POST['cat_id'].152 '&status='.$_POST['status'].153 '&selected='.$_POST['selected'].154 '&month='.$_POST['month'].155 '&lang='.$_POST['lang'].156 '&sortby='.$_POST['sortby'].157 '&order='.$_POST['order'].158 '&page='.$_POST['page'].159 '&nb='.$_POST['nb'];160 }161 160 162 161 foreach ($entries as $k => $v) { … … 175 174 176 175 $posts = $core->blog->getPosts($params); 177 178 $posts_ids = array();179 176 while ($posts->fetch()) { 180 177 $posts_ids[] = $posts->post_id; … … 183 180 // Redirection including selected entries 184 181 $redir_sel = $redir.'&'.$fields->getEntriesQS(); 185 186 # --BEHAVIOR-- adminPostsActions 187 $core->callBehavior('adminPostsActions',$core,$posts,$action,$redir); 188 189 if (preg_match('/^(publish|unpublish|schedule|pending)$/',$action)) 190 { 191 switch ($action) { 192 case 'unpublish' : $status = 0; break; 193 case 'schedule' : $status = -1; break; 194 case 'pending' : $status = -2; break; 195 default : $status = 1; break; 196 } 197 198 try 199 { 200 $core->blog->updPostsStatus($posts_ids,$status); 201 202 http::redirect($redir_sel.'&upd=1'); 203 } 204 catch (Exception $e) 205 { 206 $core->error->add($e->getMessage()); 207 } 208 } 209 elseif ($action == 'selected' || $action == 'unselected') 210 { 211 try 212 { 213 $core->blog->updPostsSelected($posts_ids,$action == 'selected'); 214 215 http::redirect($redir_sel."&upd=1"); 216 } 217 catch (Exception $e) 218 { 219 $core->error->add($e->getMessage()); 220 } 221 } 222 elseif ($action == 'delete') 223 { 224 try 225 { 226 // Backward compatibility 227 foreach($posts_ids as $post_id) 228 { 229 # --BEHAVIOR-- adminBeforePostDelete 230 $core->callBehavior('adminBeforePostDelete',(integer) $post_id); 231 } 232 233 # --BEHAVIOR-- adminBeforePostsDelete 234 $core->callBehavior('adminBeforePostsDelete',$posts_ids); 235 236 $core->blog->delPosts($posts_ids); 237 238 http::redirect($redir."&del=1"); 239 } 240 catch (Exception $e) 241 { 242 $core->error->add($e->getMessage()); 243 } 244 245 } 246 elseif ($action == 'category' && isset($_POST['new_cat_id'])) 247 { 248 $new_cat_id = $_POST['new_cat_id']; 249 250 try 251 { 252 if (!empty($_POST['new_cat_title']) && $core->auth->check('categories', $core->blog->id)) 253 { 254 $cur_cat = $core->con->openCursor($core->prefix.'category'); 255 $cur_cat->cat_title = $_POST['new_cat_title']; 256 $cur_cat->cat_url = ''; 257 258 $parent_cat = !empty($_POST['new_cat_parent']) ? $_POST['new_cat_parent'] : ''; 259 260 # --BEHAVIOR-- adminBeforeCategoryCreate 261 $core->callBehavior('adminBeforeCategoryCreate', $cur_cat); 262 263 $new_cat_id = $core->blog->addCategory($cur_cat, (integer) $parent_cat); 264 265 # --BEHAVIOR-- adminAfterCategoryCreate 266 $core->callBehavior('adminAfterCategoryCreate', $cur_cat, $new_cat_id); 267 } 268 269 $core->blog->updPostsCategory($posts_ids, $new_cat_id); 270 271 http::redirect($redir_sel."&upd=1"); 272 } 273 catch (Exception $e) 274 { 275 $core->error->add($e->getMessage()); 276 } 277 } 278 elseif ($action == 'author' && isset($_POST['new_auth_id']) 279 && $core->auth->check('admin',$core->blog->id)) 280 { 281 $new_user_id = $_POST['new_auth_id']; 282 283 try 284 { 285 if ($core->getUser($new_user_id)->isEmpty()) { 286 throw new Exception(__('This user does not exist')); 287 } 288 289 $cur = $core->con->openCursor($core->prefix.'post'); 290 $cur->user_id = $new_user_id; 291 $cur->update('WHERE post_id '.$core->con->in($posts_ids)); 292 293 http::redirect($redir_sel."&upd=1"); 294 } 295 catch (Exception $e) 296 { 297 $core->error->add($e->getMessage()); 298 } 299 } 300 elseif ($action == 'lang' && isset($_POST['new_lang'])) 301 { 302 $new_lang = $_POST['new_lang']; 303 try 304 { 305 $cur = $core->con->openCursor($core->prefix.'post'); 306 $cur->post_lang = $new_lang; 307 $cur->update('WHERE post_id '.$core->con->in($posts_ids)); 308 309 http::redirect($redir_sel."&upd=1"); 310 } 311 catch (Exception $e) 312 { 313 $core->error->add($e->getMessages()); 314 } 315 } 182 316 183 } else { 317 if (empty($_POST['entries'])) { 318 $core->error->add(__('At least one entry should be selected')); 319 } else { 320 $core->error->add(__('No action specified.')); 321 } 184 $posts = $core->con->select("SELECT blog_id FROM ".$core->prefix."blog WHERE false");; 185 } 186 187 /* Actions 188 -------------------------------------------------------- */ 189 if (!empty($_POST['action'])) 190 { 191 $action = $_POST['action']; 192 } 193 else 194 { 195 $core->error->add(__('No action specified.')); 322 196 dcPage::open( 323 197 __('Entries'),'',dcPage::breadcrumb( … … 334 208 exit; 335 209 } 210 211 # --BEHAVIOR-- adminPostsActions 212 $core->callBehavior('adminPostsActions',$core,$posts,$action,$redir); 213 214 if (preg_match('/^(publish|unpublish|schedule|pending)$/',$action)) 215 { 216 switch ($action) { 217 case 'unpublish' : $status = 0; break; 218 case 'schedule' : $status = -1; break; 219 case 'pending' : $status = -2; break; 220 default : $status = 1; break; 221 } 222 223 try 224 { 225 $core->blog->updPostsStatus($posts_ids,$status); 226 227 http::redirect($redir_sel.'&upd=1'); 228 } 229 catch (Exception $e) 230 { 231 $core->error->add($e->getMessage()); 232 } 233 } 234 elseif ($action == 'selected' || $action == 'unselected') 235 { 236 try 237 { 238 $core->blog->updPostsSelected($posts_ids,$action == 'selected'); 239 240 http::redirect($redir_sel."&upd=1"); 241 } 242 catch (Exception $e) 243 { 244 $core->error->add($e->getMessage()); 245 } 246 } 247 elseif ($action == 'delete') 248 { 249 try 250 { 251 // Backward compatibility 252 foreach($posts_ids as $post_id) 253 { 254 # --BEHAVIOR-- adminBeforePostDelete 255 $core->callBehavior('adminBeforePostDelete',(integer) $post_id); 256 } 257 258 # --BEHAVIOR-- adminBeforePostsDelete 259 $core->callBehavior('adminBeforePostsDelete',$posts_ids); 260 261 $core->blog->delPosts($posts_ids); 262 263 http::redirect($redir."&del=1"); 264 } 265 catch (Exception $e) 266 { 267 $core->error->add($e->getMessage()); 268 } 269 270 } 271 elseif ($action == 'category' && isset($_POST['new_cat_id'])) 272 { 273 $new_cat_id = $_POST['new_cat_id']; 274 275 try 276 { 277 if (!empty($_POST['new_cat_title']) && $core->auth->check('categories', $core->blog->id)) 278 { 279 $cur_cat = $core->con->openCursor($core->prefix.'category'); 280 $cur_cat->cat_title = $_POST['new_cat_title']; 281 $cur_cat->cat_url = ''; 282 283 $parent_cat = !empty($_POST['new_cat_parent']) ? $_POST['new_cat_parent'] : ''; 284 285 # --BEHAVIOR-- adminBeforeCategoryCreate 286 $core->callBehavior('adminBeforeCategoryCreate', $cur_cat); 287 288 $new_cat_id = $core->blog->addCategory($cur_cat, (integer) $parent_cat); 289 290 # --BEHAVIOR-- adminAfterCategoryCreate 291 $core->callBehavior('adminAfterCategoryCreate', $cur_cat, $new_cat_id); 292 } 293 294 $core->blog->updPostsCategory($posts_ids, $new_cat_id); 295 296 http::redirect($redir_sel."&upd=1"); 297 } 298 catch (Exception $e) 299 { 300 $core->error->add($e->getMessage()); 301 } 302 } 303 elseif ($action == 'author' && isset($_POST['new_auth_id']) 304 && $core->auth->check('admin',$core->blog->id)) 305 { 306 $new_user_id = $_POST['new_auth_id']; 307 308 try 309 { 310 if ($core->getUser($new_user_id)->isEmpty()) { 311 throw new Exception(__('This user does not exist')); 312 } 313 314 $cur = $core->con->openCursor($core->prefix.'post'); 315 $cur->user_id = $new_user_id; 316 $cur->update('WHERE post_id '.$core->con->in($posts_ids)); 317 318 http::redirect($redir_sel."&upd=1"); 319 } 320 catch (Exception $e) 321 { 322 $core->error->add($e->getMessage()); 323 } 324 } 325 elseif ($action == 'lang' && isset($_POST['new_lang'])) 326 { 327 $new_lang = $_POST['new_lang']; 328 try 329 { 330 $cur = $core->con->openCursor($core->prefix.'post'); 331 $cur->post_lang = $new_lang; 332 $cur->update('WHERE post_id '.$core->con->in($posts_ids)); 333 334 http::redirect($redir_sel."&upd=1"); 335 } 336 catch (Exception $e) 337 { 338 $core->error->add($e->getMessages()); 339 } 340 } 341 336 342 /* DISPLAY 337 343 -------------------------------------------------------- */
Note: See TracChangeset
for help on using the changeset viewer.