| 1 | <?php |
|---|
| 2 | /** |
|---|
| 3 | * @package Dotclear |
|---|
| 4 | * @subpackage Backend |
|---|
| 5 | * |
|---|
| 6 | * @copyright Olivier Meunier & Association Dotclear |
|---|
| 7 | * @copyright GPL-2.0-only |
|---|
| 8 | */ |
|---|
| 9 | |
|---|
| 10 | if (!defined('DC_RC_PATH')) {return;} |
|---|
| 11 | |
|---|
| 12 | class dcCommentsActionsPage extends dcActionsPage |
|---|
| 13 | { |
|---|
| 14 | public function __construct($core, $uri, $redirect_args = array()) |
|---|
| 15 | { |
|---|
| 16 | parent::__construct($core, $uri, $redirect_args); |
|---|
| 17 | $this->redirect_fields = array('type', 'author', 'status', |
|---|
| 18 | 'sortby', 'ip', 'order', 'page', 'nb', 'section'); |
|---|
| 19 | $this->field_entries = 'comments'; |
|---|
| 20 | $this->title_cb = __('Comments'); |
|---|
| 21 | $this->loadDefaults(); |
|---|
| 22 | $core->callBehavior('adminCommentsActionsPage', $core, $this); |
|---|
| 23 | } |
|---|
| 24 | |
|---|
| 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 | } |
|---|
| 31 | |
|---|
| 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 | ); |
|---|
| 47 | |
|---|
| 48 | } |
|---|
| 49 | echo '<p><a class="back" href="' . $this->getRedirection(true) . '">' . __('Back to comments list') . '</a></p>'; |
|---|
| 50 | } |
|---|
| 51 | |
|---|
| 52 | public function endPage() |
|---|
| 53 | { |
|---|
| 54 | dcPage::close(); |
|---|
| 55 | } |
|---|
| 56 | |
|---|
| 57 | public function error(Exception $e) |
|---|
| 58 | { |
|---|
| 59 | $this->core->error->add($e->getMessage()); |
|---|
| 60 | $this->beginPage(dcPage::breadcrumb( |
|---|
| 61 | array( |
|---|
| 62 | html::escapeHTML($this->core->blog->name) => '', |
|---|
| 63 | __('Comments') => $this->core->adminurl->get('admin.comments'), |
|---|
| 64 | __('Comments actions') => '' |
|---|
| 65 | )) |
|---|
| 66 | ); |
|---|
| 67 | $this->endPage(); |
|---|
| 68 | } |
|---|
| 69 | |
|---|
| 70 | /** |
|---|
| 71 | * getcheckboxes -returns html code for selected entries |
|---|
| 72 | * as a table containing entries checkboxes |
|---|
| 73 | * |
|---|
| 74 | * @access public |
|---|
| 75 | * |
|---|
| 76 | * @return string the html code for checkboxes |
|---|
| 77 | */ |
|---|
| 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">' . |
|---|
| 87 | form::checkbox(array($this->field_entries . '[]'), $id, |
|---|
| 88 | array( |
|---|
| 89 | 'checked' => true |
|---|
| 90 | )) . |
|---|
| 91 | '</td>' . |
|---|
| 92 | '<td>' . $title['author'] . '</td><td>' . $title['title'] . '</td></tr>'; |
|---|
| 93 | } |
|---|
| 94 | $ret .= '</table>'; |
|---|
| 95 | return $ret; |
|---|
| 96 | } |
|---|
| 97 | |
|---|
| 98 | protected function fetchEntries($from) |
|---|
| 99 | { |
|---|
| 100 | $params = array(); |
|---|
| 101 | if (!empty($from['comments'])) { |
|---|
| 102 | $comments = $from['comments']; |
|---|
| 103 | |
|---|
| 104 | foreach ($comments as $k => $v) { |
|---|
| 105 | $comments[$k] = (integer) $v; |
|---|
| 106 | } |
|---|
| 107 | |
|---|
| 108 | $params['sql'] = 'AND C.comment_id IN(' . implode(',', $comments) . ') '; |
|---|
| 109 | } else { |
|---|
| 110 | $params['sql'] = 'AND 1=0 '; |
|---|
| 111 | } |
|---|
| 112 | |
|---|
| 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()) { |
|---|
| 118 | $this->entries[$co->comment_id] = array( |
|---|
| 119 | 'title' => $co->post_title, |
|---|
| 120 | 'author' => $co->comment_author |
|---|
| 121 | ); |
|---|
| 122 | } |
|---|
| 123 | $this->rs = $co; |
|---|
| 124 | } |
|---|
| 125 | } |
|---|
| 126 | |
|---|
| 127 | class dcDefaultCommentActions |
|---|
| 128 | { |
|---|
| 129 | public static function adminCommentsActionsPage($core, dcCommentsActionsPage $ap) |
|---|
| 130 | { |
|---|
| 131 | if ($core->auth->check('publish,contentadmin', $core->blog->id)) { |
|---|
| 132 | $ap->addAction( |
|---|
| 133 | array(__('Status') => array( |
|---|
| 134 | __('Publish') => 'publish', |
|---|
| 135 | __('Unpublish') => 'unpublish', |
|---|
| 136 | __('Mark as pending') => 'pending', |
|---|
| 137 | __('Mark as junk') => 'junk' |
|---|
| 138 | )), |
|---|
| 139 | array('dcDefaultCommentActions', 'doChangeCommentStatus') |
|---|
| 140 | ); |
|---|
| 141 | } |
|---|
| 142 | |
|---|
| 143 | if ($core->auth->check('delete,contentadmin', $core->blog->id)) { |
|---|
| 144 | $ap->addAction( |
|---|
| 145 | array(__('Delete') => array( |
|---|
| 146 | __('Delete') => 'delete')), |
|---|
| 147 | array('dcDefaultCommentActions', 'doDeleteComment') |
|---|
| 148 | ); |
|---|
| 149 | } |
|---|
| 150 | |
|---|
| 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 | } |
|---|
| 158 | |
|---|
| 159 | if ($ip_filter_active) { |
|---|
| 160 | $blacklist_actions = array(__('Blacklist IP') => 'blacklist'); |
|---|
| 161 | if ($core->auth->isSuperAdmin()) { |
|---|
| 162 | $blacklist_actions[__('Blacklist IP (global)')] = 'blacklist_global'; |
|---|
| 163 | } |
|---|
| 164 | |
|---|
| 165 | $ap->addAction( |
|---|
| 166 | array(__('IP address') => $blacklist_actions), |
|---|
| 167 | array('dcDefaultCommentActions', 'doBlacklistIP') |
|---|
| 168 | ); |
|---|
| 169 | } |
|---|
| 170 | } |
|---|
| 171 | |
|---|
| 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 | } |
|---|
| 189 | |
|---|
| 190 | $core->blog->updCommentsStatus($co_ids, $status); |
|---|
| 191 | |
|---|
| 192 | dcPage::addSuccessNotice(__('Selected comments have been successfully updated.')); |
|---|
| 193 | $ap->redirect(true); |
|---|
| 194 | } |
|---|
| 195 | |
|---|
| 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 | } |
|---|
| 207 | |
|---|
| 208 | # --BEHAVIOR-- adminBeforeCommentsDelete |
|---|
| 209 | $core->callBehavior('adminBeforeCommentsDelete', $co_ids); |
|---|
| 210 | |
|---|
| 211 | $core->blog->delComments($co_ids); |
|---|
| 212 | dcPage::addSuccessNotice(__('Selected comments have been successfully deleted.')); |
|---|
| 213 | $ap->redirect(false); |
|---|
| 214 | } |
|---|
| 215 | |
|---|
| 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 | } |
|---|
| 223 | |
|---|
| 224 | $global = !empty($action) && $action == 'blacklist_global' && $core->auth->isSuperAdmin(); |
|---|
| 225 | |
|---|
| 226 | $ip_filter = new dcFilterIP($core); |
|---|
| 227 | $rs = $ap->getRS(); |
|---|
| 228 | while ($rs->fetch()) { |
|---|
| 229 | $ip_filter->addIP('black', $rs->comment_ip, $global); |
|---|
| 230 | } |
|---|
| 231 | |
|---|
| 232 | dcPage::addSuccessNotice(__('IP addresses for selected comments have been blacklisted.')); |
|---|
| 233 | $ap->redirect(true); |
|---|
| 234 | } |
|---|
| 235 | } |
|---|