- Timestamp:
- 02/17/18 18:03:29 (7 years ago)
- Branch:
- default
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
inc/admin/actions/class.dcactioncomments.php
r3159 r3707 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 dcCommentsActionsPage 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('type','author','status', 19 'sortby','ip','order','page','nb','section'); 20 $this->field_entries = 'comments'; 21 $this->title_cb = __('Comments'); 22 $this->loadDefaults(); 23 $core->callBehavior('adminCommentsActionsPage',$core,$this); 24 } 25 26 protected function loadDefaults() { 27 // We could have added a behavior here, but we want default action 28 // to be setup first 29 dcDefaultCommentActions::adminCommentsActionsPage($this->core,$this); 30 } 31 32 public function beginPage($breadcrumb='',$head='') { 33 if ($this->in_plugin) { 34 echo '<html><head><title>'.__('Comments').'</title>'. 35 dcPage::jsLoad('js/_comments_actions.js'). 36 $head. 37 '</script></head><body>'. 38 $breadcrumb; 39 } else { 40 dcPage::open( 41 __('Comments'), 42 dcPage::jsLoad('js/_comments_actions.js'). 43 $head, 44 $breadcrumb 45 ); 46 47 } 48 echo '<p><a class="back" href="'.$this->getRedirection(true).'">'.__('Back to comments list').'</a></p>'; 49 } 50 51 public function endPage() { 52 dcPage::close(); 53 } 54 55 public function error(Exception $e) { 56 $this->core->error->add($e->getMessage()); 57 $this->beginPage(dcPage::breadcrumb( 58 array( 59 html::escapeHTML($this->core->blog->name) => '', 60 __('Comments') => $this->core->adminurl->get('admin.comments'), 61 __('Comments actions') => '' 62 )) 63 ); 64 $this->endPage(); 65 } 66 67 /** 16 public function __construct($core, $uri, $redirect_args = array()) 17 { 18 parent::__construct($core, $uri, $redirect_args); 19 $this->redirect_fields = array('type', 'author', 'status', 20 'sortby', 'ip', 'order', 'page', 'nb', 'section'); 21 $this->field_entries = 'comments'; 22 $this->title_cb = __('Comments'); 23 $this->loadDefaults(); 24 $core->callBehavior('adminCommentsActionsPage', $core, $this); 25 } 26 27 protected function loadDefaults() 28 { 29 // We could have added a behavior here, but we want default action 30 // to be setup first 31 dcDefaultCommentActions::adminCommentsActionsPage($this->core, $this); 32 } 33 34 public function beginPage($breadcrumb = '', $head = '') 35 { 36 if ($this->in_plugin) { 37 echo '<html><head><title>' . __('Comments') . '</title>' . 38 dcPage::jsLoad('js/_comments_actions.js') . 39 $head . 40 '</script></head><body>' . 41 $breadcrumb; 42 } else { 43 dcPage::open( 44 __('Comments'), 45 dcPage::jsLoad('js/_comments_actions.js') . 46 $head, 47 $breadcrumb 48 ); 49 50 } 51 echo '<p><a class="back" href="' . $this->getRedirection(true) . '">' . __('Back to comments list') . '</a></p>'; 52 } 53 54 public function endPage() 55 { 56 dcPage::close(); 57 } 58 59 public function error(Exception $e) 60 { 61 $this->core->error->add($e->getMessage()); 62 $this->beginPage(dcPage::breadcrumb( 63 array( 64 html::escapeHTML($this->core->blog->name) => '', 65 __('Comments') => $this->core->adminurl->get('admin.comments'), 66 __('Comments actions') => '' 67 )) 68 ); 69 $this->endPage(); 70 } 71 72 /** 68 73 * getcheckboxes -returns html code for selected entries 69 *as a table containing entries checkboxes74 * as a table containing entries checkboxes 70 75 * 71 76 * @access public 72 77 * 73 78 * @return string the html code for checkboxes 74 79 */ 75 public function getCheckboxes() { 76 $ret = 77 '<table class="posts-list"><tr>'. 78 '<th colspan="2">'.__('Author').'</th><th>'.__('Title').'</th>'. 79 '</tr>'; 80 foreach ($this->entries as $id=>$title) { 81 $ret .= 82 '<tr><td class="minimal">'. 83 form::checkbox(array($this->field_entries.'[]'),$id,true,'','').'</td>'. 84 '<td>'. $title['author'].'</td><td>'.$title['title'].'</td></tr>'; 85 } 86 $ret .= '</table>'; 87 return $ret; 88 } 89 90 protected function fetchEntries($from) { 91 $params=array(); 92 if (!empty($from['comments'])) { 93 $comments = $from['comments']; 94 95 foreach ($comments as $k => $v) { 96 $comments[$k] = (integer) $v; 97 } 98 99 $params['sql'] = 'AND C.comment_id IN('.implode(',',$comments).') '; 100 } else { 101 $params['sql'] = 'AND 1=0 '; 102 } 103 104 if (!isset($from['full_content']) || empty($from['full_content'])) { 105 $params['no_content'] = true; 106 } 107 $co = $this->core->blog->getComments($params); 108 while ($co->fetch()) { 109 $this->entries[$co->comment_id] = array( 110 'title' => $co->post_title, 111 'author' => $co->comment_author 112 ); 113 } 114 $this->rs = $co; 115 } 80 public function getCheckboxes() 81 { 82 $ret = 83 '<table class="posts-list"><tr>' . 84 '<th colspan="2">' . __('Author') . '</th><th>' . __('Title') . '</th>' . 85 '</tr>'; 86 foreach ($this->entries as $id => $title) { 87 $ret .= 88 '<tr><td class="minimal">' . 89 form::checkbox(array($this->field_entries . '[]'), $id, 90 array( 91 'checked' => true 92 )) . 93 '</td>' . 94 '<td>' . $title['author'] . '</td><td>' . $title['title'] . '</td></tr>'; 95 } 96 $ret .= '</table>'; 97 return $ret; 98 } 99 100 protected function fetchEntries($from) 101 { 102 $params = array(); 103 if (!empty($from['comments'])) { 104 $comments = $from['comments']; 105 106 foreach ($comments as $k => $v) { 107 $comments[$k] = (integer) $v; 108 } 109 110 $params['sql'] = 'AND C.comment_id IN(' . implode(',', $comments) . ') '; 111 } else { 112 $params['sql'] = 'AND 1=0 '; 113 } 114 115 if (!isset($from['full_content']) || empty($from['full_content'])) { 116 $params['no_content'] = true; 117 } 118 $co = $this->core->blog->getComments($params); 119 while ($co->fetch()) { 120 $this->entries[$co->comment_id] = array( 121 'title' => $co->post_title, 122 'author' => $co->comment_author 123 ); 124 } 125 $this->rs = $co; 126 } 116 127 } 117 128 118 129 class dcDefaultCommentActions 119 130 { 120 public static function adminCommentsActionsPage($core, dcCommentsActionsPage $ap) { 121 if ($core->auth->check('publish,contentadmin',$core->blog->id)) 122 { 123 $ap->addAction( 124 array(__('Status') => array( 125 __('Publish') => 'publish', 126 __('Unpublish') => 'unpublish', 127 __('Mark as pending') => 'pending', 128 __('Mark as junk') => 'junk' 129 )), 130 array('dcDefaultCommentActions','doChangeCommentStatus') 131 ); 132 } 133 134 if ($core->auth->check('delete,contentadmin',$core->blog->id)) 135 { 136 $ap->addAction( 137 array(__('Delete') => array( 138 __('Delete') => 'delete')), 139 array('dcDefaultCommentActions','doDeleteComment') 140 ); 141 } 142 143 $ip_filter_active = true; 144 if ($core->blog->settings->antispam->antispam_filters !== null) { 145 $filters_opt = $core->blog->settings->antispam->antispam_filters; 146 if (is_array($filters_opt)) { 147 $ip_filter_active = isset($filters_opt['dcFilterIP']) && is_array($filters_opt['dcFilterIP']) && $filters_opt['dcFilterIP'][0]==1; 148 } 149 } 150 151 if ($ip_filter_active) { 152 $blacklist_actions = array(__('Blacklist IP') => 'blacklist'); 153 if ($core->auth->isSuperAdmin()) { 154 $blacklist_actions[__('Blacklist IP (global)')] = 'blacklist_global'; 155 } 156 157 $ap->addAction( 158 array(__('IP address') => $blacklist_actions), 159 array('dcDefaultCommentActions','doBlacklistIP') 160 ); 161 } 162 } 163 164 public static function doChangeCommentStatus($core, dcCommentsActionsPage $ap, $post) { 165 $action = $ap->getAction(); 166 $co_ids = $ap->getIDs(); 167 if (empty($co_ids)) { 168 throw new Exception(__('No comment selected')); 169 } 170 switch ($action) { 171 case 'unpublish' : $status = 0; break; 172 case 'pending' : $status = -1; break; 173 case 'junk' : $status = -2; break; 174 default : $status = 1; break; 175 } 176 177 $core->blog->updCommentsStatus($co_ids,$status); 178 179 dcPage::addSuccessNotice(__('Selected comments have been successfully updated.')); 180 $ap->redirect(true); 181 } 182 183 public static function doDeleteComment($core, dcCommentsActionsPage $ap, $post) { 184 $co_ids = $ap->getIDs(); 185 if (empty($co_ids)) { 186 throw new Exception(__('No comment selected')); 187 } 188 // Backward compatibility 189 foreach($co_ids as $comment_id) 190 { 191 # --BEHAVIOR-- adminBeforeCommentDelete 192 $core->callBehavior('adminBeforeCommentDelete',$comment_id); 193 } 194 195 # --BEHAVIOR-- adminBeforeCommentsDelete 196 $core->callBehavior('adminBeforeCommentsDelete',$co_ids); 197 198 $core->blog->delComments($co_ids); 199 dcPage::addSuccessNotice(__('Selected comments have been successfully deleted.')); 200 $ap->redirect(false); 201 } 202 203 public static function doBlacklistIP($core, dcCommentsActionsPage $ap, $post) { 204 $action = $ap->getAction(); 205 $co_ids = $ap->getIDs(); 206 if (empty($co_ids)) { 207 throw new Exception(__('No comment selected')); 208 } 209 210 $global = !empty($action) && $action == 'blacklist_global' && $core->auth->isSuperAdmin(); 211 212 $ip_filter = new dcFilterIP($core); 213 $rs = $ap->getRS(); 214 while ($rs->fetch()) { 215 $ip_filter->addIP('black',$rs->comment_ip,$global); 216 } 217 218 dcPage::addSuccessNotice(__('IP addresses for selected comments have been blacklisted.')); 219 $ap->redirect(true); 220 } 131 public static function adminCommentsActionsPage($core, dcCommentsActionsPage $ap) 132 { 133 if ($core->auth->check('publish,contentadmin', $core->blog->id)) { 134 $ap->addAction( 135 array(__('Status') => array( 136 __('Publish') => 'publish', 137 __('Unpublish') => 'unpublish', 138 __('Mark as pending') => 'pending', 139 __('Mark as junk') => 'junk' 140 )), 141 array('dcDefaultCommentActions', 'doChangeCommentStatus') 142 ); 143 } 144 145 if ($core->auth->check('delete,contentadmin', $core->blog->id)) { 146 $ap->addAction( 147 array(__('Delete') => array( 148 __('Delete') => 'delete')), 149 array('dcDefaultCommentActions', 'doDeleteComment') 150 ); 151 } 152 153 $ip_filter_active = true; 154 if ($core->blog->settings->antispam->antispam_filters !== null) { 155 $filters_opt = $core->blog->settings->antispam->antispam_filters; 156 if (is_array($filters_opt)) { 157 $ip_filter_active = isset($filters_opt['dcFilterIP']) && is_array($filters_opt['dcFilterIP']) && $filters_opt['dcFilterIP'][0] == 1; 158 } 159 } 160 161 if ($ip_filter_active) { 162 $blacklist_actions = array(__('Blacklist IP') => 'blacklist'); 163 if ($core->auth->isSuperAdmin()) { 164 $blacklist_actions[__('Blacklist IP (global)')] = 'blacklist_global'; 165 } 166 167 $ap->addAction( 168 array(__('IP address') => $blacklist_actions), 169 array('dcDefaultCommentActions', 'doBlacklistIP') 170 ); 171 } 172 } 173 174 public static function doChangeCommentStatus($core, dcCommentsActionsPage $ap, $post) 175 { 176 $action = $ap->getAction(); 177 $co_ids = $ap->getIDs(); 178 if (empty($co_ids)) { 179 throw new Exception(__('No comment selected')); 180 } 181 switch ($action) { 182 case 'unpublish':$status = 0; 183 break; 184 case 'pending':$status = -1; 185 break; 186 case 'junk':$status = -2; 187 break; 188 default:$status = 1; 189 break; 190 } 191 192 $core->blog->updCommentsStatus($co_ids, $status); 193 194 dcPage::addSuccessNotice(__('Selected comments have been successfully updated.')); 195 $ap->redirect(true); 196 } 197 198 public static function doDeleteComment($core, dcCommentsActionsPage $ap, $post) 199 { 200 $co_ids = $ap->getIDs(); 201 if (empty($co_ids)) { 202 throw new Exception(__('No comment selected')); 203 } 204 // Backward compatibility 205 foreach ($co_ids as $comment_id) { 206 # --BEHAVIOR-- adminBeforeCommentDelete 207 $core->callBehavior('adminBeforeCommentDelete', $comment_id); 208 } 209 210 # --BEHAVIOR-- adminBeforeCommentsDelete 211 $core->callBehavior('adminBeforeCommentsDelete', $co_ids); 212 213 $core->blog->delComments($co_ids); 214 dcPage::addSuccessNotice(__('Selected comments have been successfully deleted.')); 215 $ap->redirect(false); 216 } 217 218 public static function doBlacklistIP($core, dcCommentsActionsPage $ap, $post) 219 { 220 $action = $ap->getAction(); 221 $co_ids = $ap->getIDs(); 222 if (empty($co_ids)) { 223 throw new Exception(__('No comment selected')); 224 } 225 226 $global = !empty($action) && $action == 'blacklist_global' && $core->auth->isSuperAdmin(); 227 228 $ip_filter = new dcFilterIP($core); 229 $rs = $ap->getRS(); 230 while ($rs->fetch()) { 231 $ip_filter->addIP('black', $rs->comment_ip, $global); 232 } 233 234 dcPage::addSuccessNotice(__('IP addresses for selected comments have been blacklisted.')); 235 $ap->redirect(true); 236 } 221 237 }
Note: See TracChangeset
for help on using the changeset viewer.