auth->check('admin',$core->blog->id)) { return; } $core->addBehavior('adminPostsActionsCombo',array('behaviorsPostlistOptions','adminPostsActionsCombo')); $core->addBehavior('adminPostsActionsContent',array('behaviorsPostlistOptions','adminPostsActionsContent')); $core->addBehavior('adminPostsActions',array('behaviorsPostlistOptions','adminPostsActions')); class behaviorsPostlistOptions { public static function adminPostsActionsCombo($args) { if (!$GLOBALS['core']->auth->check('admin',$GLOBALS['core']->blog->id)) return; $args[0][__('Comments')][__('Mark as opened')] = 'commentsopen'; $args[0][__('Comments')][__('Mark as closed')] = 'commentsclose'; $args[0][__('Comments')][__('Delete all comments')] = 'commentsdelete'; $args[0][__('Trackbacks')][__('Mark as opened')] = 'trackbacksopen'; $args[0][__('Trackbacks')][__('Mark as closed')] = 'trackbacksclose'; $args[0][__('Trackbacks')][__('Delete all trackbacks')] = 'trackbacksdelete'; } public static function adminPostsActionsContent($core,$action,$hidden_fields) { $allow = array( 'commentsdelete' => __('Are you sure you want to delete all comments?'), 'trackbacksdelete' => __('Are you sure you want to delete all trackbacks?') ); if (!isset($allow[$action]) || !$core->auth->check('admin',$core->blog->id)){ return; } echo '

'.__('Confirm action').'

'. '
'. '

'.$allow[$action].'

'. '

'.$hidden_fields.$core->formNonce(). form::hidden(array('action'),'confirmed'.$action). '

'. '
'; } public static function adminPostsActions($core,$posts,$action,$redir) { $allow = array( 'commentsopen','commentsclose','confirmedcommentsdelete', 'trackbacksopen','trackbacksclose','confirmedtrackbacksdelete' ); if (!in_array($action,$allow) || !$core->auth->check('admin',$core->blog->id)){ return; } try { while ($posts->fetch()) { $id = $posts->post_id; switch ($action) { case 'commentsopen' : self::updPostOption($id,'post_open_comment',1); break; case 'commentsclose' : self::updPostOption($id,'post_open_comment',0); break; case 'trackbacksopen' : self::updPostOption($id,'post_open_tb',1); break; case 'trackbacksclose' : self::updPostOption($id,'post_open_tb',0); break; case 'confirmedcommentsdelete' : self::delPostComments($id,false); self::updPostOption($id,'nb_comment',0); break; case 'confirmedtrackbacksdelete' : self::delPostComments($id,true); self::updPostOption($id,'nb_trackback',0); break; } } if (!$core->error->flag()) { http::redirect($redir); } } catch (Exception $e) { $core->error->add($e->getMessage()); } } private static function updPostOption($id,$option,$value) { global $core; if (!$core->auth->check('admin',$core->blog->id)) { throw new Exception(__('You are not allowed to change this entry option')); } $id = abs((integer) $id); $cur = $core->con->openCursor($core->prefix.'post'); $cur->{$option} = $value; $cur->post_upddt = date('Y-m-d H:i:s'); $cur->update( 'WHERE post_id = '.$id.' '. "AND blog_id = '".$core->con->escape($core->blog->id)."' " ); $core->blog->triggerBlog(); } private static function delPostComments($id,$tb=false) { global $core; $params = array( 'no_content' => true, 'post_id' => abs((integer) $id), 'comment_trackback' => $tb ? 1: 0 ); $comments = $core->blog->getComments($params); while($comments->fetch()) { // slower but preserve core behaviors $core->blog->delComment($comments->comment_id); } } } ?>