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