Dotclear

source: inc/admin/actions/class.dcactioncomments.php @ 2069:8c8ad1be0ea2

Revision 2069:8c8ad1be0ea2, 4.8 KB checked in by Dsls, 12 years ago (diff)

Implemented 3-column layout for comments actions.

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');
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          dcPage::open(
34               __('Comments'),
35               
36               dcPage::jsLoad('js/_comments_actions.js').
37               $head,
38               $breadcrumb
39          );   
40          echo '<p><a class="back" href="'.$this->getRedirection(array(),true).'">'.__('Back to comments list').'</a></p>';
41     }
42     
43     public function endPage() {
44          dcPage::close();
45     }
46
47     public function error(Exception $e) {
48          $this->core->error->add($e->getMessage());
49          $this->beginPage(dcPage::breadcrumb(
50               array(
51                    html::escapeHTML($this->core->blog->name) => '',
52                    __('Comments') => 'comments.php',
53                    '<span class="page-title">'.__('Comments actions').'</span>' => ''
54               ))
55          );
56          $this->endPage();
57     }
58     
59     /**
60     * getcheckboxes -returns html code for selected entries
61      *             as a table containing entries checkboxes
62     *
63     * @access public
64      *
65     * @return string the html code for checkboxes
66     */
67     public function getCheckboxes() {
68          $ret = 
69               '<table class="posts-list"><tr>'.
70               '<th colspan="2">'.__('Author').'</th><th>'.__('Title').'</th>'.
71               '</tr>';
72          foreach ($this->entries as $id=>$title) {
73               $ret .= 
74                    '<tr><td>'.
75                    form::checkbox(array($this->field_entries.'[]'),$id,true,'','').'</td>'.
76                    '<td>'.   $title['author'].'</td><td>'.$title['title'].'</td></tr>';
77          }
78          $ret .= '</table>';
79          return $ret;
80     }
81
82     protected function fetchEntries($from) {
83          if (!empty($from['comments'])) {
84               $comments = $from['comments'];
85               
86               foreach ($comments as $k => $v) {
87                    $comments[$k] = (integer) $v;
88               }
89               
90               $params['sql'] = 'AND C.comment_id IN('.implode(',',$comments).') ';
91               
92               if (!isset($from['full_content']) || empty($from['full_content'])) {
93                    $params['no_content'] = true;
94               }
95               
96               $co = $this->core->blog->getComments($params);
97               while ($co->fetch())     {
98                    $this->entries[$co->comment_id] = array(
99                         'title' => $co->post_title,
100                         'author' => $co->comment_author
101                    );
102               }
103               $this->rs = $co;
104          } else {
105               $this->rs = $this->core->con->select("SELECT blog_id FROM ".$this->core->prefix."blog WHERE false");;
106          }
107     }
108}
109
110class dcDefaultCommentActions 
111{
112     public static function adminCommentsActionsPage($core, dcCommentsActionsPage $ap) {
113          if ($core->auth->check('publish,contentadmin',$core->blog->id))
114          {
115               $action = array('dcDefaultCommentActions','doChangeCommentStatus');
116               $ap->addAction (array(__('Publish') => 'publish'), $action);
117               $ap->addAction (array(__('Publish') => 'publish'), $action);
118               $ap->addAction (array(__('Unpublish') => 'unpublish'), $action);
119               $ap->addAction (array(__('Mark as pending') => 'pending'), $action);
120               $ap->addAction(array(__('Mark as junk') => 'junk'), $action);
121          }
122     
123          if ($core->auth->check('delete,contentadmin',$core->blog->id))
124          {
125               $ap->addAction(array(__('Delete') => 'delete'),
126                    array('dcDefaultCommentActions','doDeleteComment'));
127          }
128     }
129
130     public static function doChangeCommentStatus($core, dcCommentsActionsPage $ap, $post) {
131          $action = $ap->getAction();
132          $co_ids = $ap->getIDs();
133          if (empty($co_ids)) {
134               throw new Exception(__('No comment selected'));
135          }
136          switch ($action) {
137               case 'unpublish' : $status = 0; break;
138               case 'pending' : $status = -1; break;
139               case 'junk' : $status = -2; break;
140               default : $status = 1; break;
141          }
142         
143          $core->blog->updCommentsStatus($co_ids,$status);
144          $ap->redirect(array('upd'=>1),true);
145     }
146
147     public static function doDeleteComment($core, dcCommentsActionsPage $ap, $post) {
148          $co_ids = $ap->getIDs();
149          if (empty($co_ids)) {
150               throw new Exception(__('No comment selected'));
151          }
152          // Backward compatibility
153          foreach($co_ids as $comment_id)
154          {
155               # --BEHAVIOR-- adminBeforeCommentDelete
156               $core->callBehavior('adminBeforeCommentDelete',$comment_id);                   
157          }
158         
159          # --BEHAVIOR-- adminBeforeCommentsDelete
160          $core->callBehavior('adminBeforeCommentsDelete',$co_ids);
161         
162          $core->blog->delComments($co_ids);
163          $ap->redirect(array('del'=>1), false);
164     }
165}
Note: See TracBrowser for help on using the repository browser.

Sites map