[1905] | 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 ----------------------------------------- |
---|
[3707] | 12 | if (!defined('DC_RC_PATH')) {return;} |
---|
[1905] | 13 | |
---|
| 14 | class dcCommentsActionsPage extends dcActionsPage |
---|
| 15 | { |
---|
[3707] | 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 | } |
---|
[1905] | 26 | |
---|
[3707] | 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 | } |
---|
[2493] | 33 | |
---|
[3707] | 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 | ); |
---|
[2072] | 49 | |
---|
[3707] | 50 | } |
---|
| 51 | echo '<p><a class="back" href="' . $this->getRedirection(true) . '">' . __('Back to comments list') . '</a></p>'; |
---|
| 52 | } |
---|
[2493] | 53 | |
---|
[3707] | 54 | public function endPage() |
---|
| 55 | { |
---|
| 56 | dcPage::close(); |
---|
| 57 | } |
---|
[1905] | 58 | |
---|
[3707] | 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 | } |
---|
[2493] | 71 | |
---|
[3707] | 72 | /** |
---|
[2069] | 73 | * getcheckboxes -returns html code for selected entries |
---|
[3707] | 74 | * as a table containing entries checkboxes |
---|
[2069] | 75 | * |
---|
| 76 | * @access public |
---|
[3707] | 77 | * |
---|
[2069] | 78 | * @return string the html code for checkboxes |
---|
| 79 | */ |
---|
[3707] | 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 | } |
---|
[2069] | 99 | |
---|
[3707] | 100 | protected function fetchEntries($from) |
---|
| 101 | { |
---|
| 102 | $params = array(); |
---|
| 103 | if (!empty($from['comments'])) { |
---|
| 104 | $comments = $from['comments']; |
---|
[2493] | 105 | |
---|
[3707] | 106 | foreach ($comments as $k => $v) { |
---|
| 107 | $comments[$k] = (integer) $v; |
---|
| 108 | } |
---|
[2493] | 109 | |
---|
[3707] | 110 | $params['sql'] = 'AND C.comment_id IN(' . implode(',', $comments) . ') '; |
---|
| 111 | } else { |
---|
| 112 | $params['sql'] = 'AND 1=0 '; |
---|
| 113 | } |
---|
[2493] | 114 | |
---|
[3707] | 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 | } |
---|
[1905] | 127 | } |
---|
| 128 | |
---|
[2493] | 129 | class dcDefaultCommentActions |
---|
[1905] | 130 | { |
---|
[3707] | 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 | } |
---|
[2493] | 144 | |
---|
[3707] | 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 | } |
---|
[3047] | 152 | |
---|
[3707] | 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 | } |
---|
[3047] | 160 | |
---|
[3707] | 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 | } |
---|
[3047] | 166 | |
---|
[3707] | 167 | $ap->addAction( |
---|
| 168 | array(__('IP address') => $blacklist_actions), |
---|
| 169 | array('dcDefaultCommentActions', 'doBlacklistIP') |
---|
| 170 | ); |
---|
| 171 | } |
---|
| 172 | } |
---|
[1905] | 173 | |
---|
[3707] | 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 | } |
---|
[2493] | 191 | |
---|
[3707] | 192 | $core->blog->updCommentsStatus($co_ids, $status); |
---|
[2256] | 193 | |
---|
[3707] | 194 | dcPage::addSuccessNotice(__('Selected comments have been successfully updated.')); |
---|
| 195 | $ap->redirect(true); |
---|
| 196 | } |
---|
[1905] | 197 | |
---|
[3707] | 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 | } |
---|
[2493] | 209 | |
---|
[3707] | 210 | # --BEHAVIOR-- adminBeforeCommentsDelete |
---|
| 211 | $core->callBehavior('adminBeforeCommentsDelete', $co_ids); |
---|
[2493] | 212 | |
---|
[3707] | 213 | $core->blog->delComments($co_ids); |
---|
| 214 | dcPage::addSuccessNotice(__('Selected comments have been successfully deleted.')); |
---|
| 215 | $ap->redirect(false); |
---|
| 216 | } |
---|
[3047] | 217 | |
---|
[3707] | 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 | } |
---|
[3047] | 225 | |
---|
[3707] | 226 | $global = !empty($action) && $action == 'blacklist_global' && $core->auth->isSuperAdmin(); |
---|
[3047] | 227 | |
---|
[3707] | 228 | $ip_filter = new dcFilterIP($core); |
---|
| 229 | $rs = $ap->getRS(); |
---|
| 230 | while ($rs->fetch()) { |
---|
| 231 | $ip_filter->addIP('black', $rs->comment_ip, $global); |
---|
| 232 | } |
---|
[3047] | 233 | |
---|
[3707] | 234 | dcPage::addSuccessNotice(__('IP addresses for selected comments have been blacklisted.')); |
---|
| 235 | $ap->redirect(true); |
---|
| 236 | } |
---|
[1905] | 237 | } |
---|