Dotclear

source: inc/admin/actions/class.dcactioncomments.php @ 3159:a7553434ee4c

Revision 3159:a7553434ee4c, 6.2 KB checked in by franck <carnet.franck.paul@…>, 9 years ago (diff)

Use new setting type 'array' for some settings, addresses #1833

Line 
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 -----------------------------------------
12if (!defined('DC_RC_PATH')) { return; }
13
14class dcCommentsActionsPage extends dcActionsPage
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     /**
68     * getcheckboxes -returns html code for selected entries
69      *             as a table containing entries checkboxes
70     *
71     * @access public
72      *
73     * @return string the html code for checkboxes
74     */
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     }
116}
117
118class dcDefaultCommentActions
119{
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     }
221}
Note: See TracBrowser for help on using the repository browser.

Sites map