Dotclear

source: inc/admin/actions/class.dcactioncomments.php @ 2821:ce071e4ee01f

Revision 2821:ce071e4ee01f, 5.0 KB checked in by franck <carnet.franck.paul@…>, 11 years ago (diff)

Using dcAdminURL in core, some admin URLs remind unchanged and should be reviewed

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
144     public static function doChangeCommentStatus($core, dcCommentsActionsPage $ap, $post) {
145          $action = $ap->getAction();
146          $co_ids = $ap->getIDs();
147          if (empty($co_ids)) {
148               throw new Exception(__('No comment selected'));
149          }
150          switch ($action) {
151               case 'unpublish' : $status = 0; break;
152               case 'pending' : $status = -1; break;
153               case 'junk' : $status = -2; break;
154               default : $status = 1; break;
155          }
156
157          $core->blog->updCommentsStatus($co_ids,$status);
158
159          dcPage::addSuccessNotice(__('Selected comments have been successfully updated.'));
160          $ap->redirect(true);
161     }
162
163     public static function doDeleteComment($core, dcCommentsActionsPage $ap, $post) {
164          $co_ids = $ap->getIDs();
165          if (empty($co_ids)) {
166               throw new Exception(__('No comment selected'));
167          }
168          // Backward compatibility
169          foreach($co_ids as $comment_id)
170          {
171               # --BEHAVIOR-- adminBeforeCommentDelete
172               $core->callBehavior('adminBeforeCommentDelete',$comment_id);
173          }
174
175          # --BEHAVIOR-- adminBeforeCommentsDelete
176          $core->callBehavior('adminBeforeCommentsDelete',$co_ids);
177
178          $core->blog->delComments($co_ids);
179          dcPage::addSuccessNotice(__('Selected comments have been successfully deleted.'));
180          $ap->redirect(false);
181     }
182}
Note: See TracBrowser for help on using the repository browser.

Sites map