Dotclear

source: inc/admin/actions/class.dcactioncomments.php @ 2166:6f409aa25386

Revision 2166:6f409aa25386, 4.9 KB checked in by Dsls, 12 years ago (diff)

revamped dcPage::breadcrumb, closes #1559

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(array(),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') => 'comments.php',
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>'.
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          if (!empty($from['comments'])) {
92               $comments = $from['comments'];
93               
94               foreach ($comments as $k => $v) {
95                    $comments[$k] = (integer) $v;
96               }
97               
98               $params['sql'] = 'AND C.comment_id IN('.implode(',',$comments).') ';
99               
100               if (!isset($from['full_content']) || empty($from['full_content'])) {
101                    $params['no_content'] = true;
102               }
103               
104               $co = $this->core->blog->getComments($params);
105               while ($co->fetch())     {
106                    $this->entries[$co->comment_id] = array(
107                         'title' => $co->post_title,
108                         'author' => $co->comment_author
109                    );
110               }
111               $this->rs = $co;
112          } else {
113               $this->rs = $this->core->con->select("SELECT blog_id FROM ".$this->core->prefix."blog WHERE false");;
114          }
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               $action = array('dcDefaultCommentActions','doChangeCommentStatus');
124               $ap->addAction(array(__('Publish') => 'publish'), $action);
125               $ap->addAction(array(__('Unpublish') => 'unpublish'), $action);
126               $ap->addAction(array(__('Mark as pending') => 'pending'), $action);
127               $ap->addAction(array(__('Mark as junk') => 'junk'), $action);
128          }
129     
130          if ($core->auth->check('delete,contentadmin',$core->blog->id))
131          {
132               $ap->addAction(array(__('Delete') => 'delete'),
133                    array('dcDefaultCommentActions','doDeleteComment'));
134          }
135     }
136
137     public static function doChangeCommentStatus($core, dcCommentsActionsPage $ap, $post) {
138          $action = $ap->getAction();
139          $co_ids = $ap->getIDs();
140          if (empty($co_ids)) {
141               throw new Exception(__('No comment selected'));
142          }
143          switch ($action) {
144               case 'unpublish' : $status = 0; break;
145               case 'pending' : $status = -1; break;
146               case 'junk' : $status = -2; break;
147               default : $status = 1; break;
148          }
149         
150          $core->blog->updCommentsStatus($co_ids,$status);
151          $ap->redirect(array('upd'=>1),true);
152     }
153
154     public static function doDeleteComment($core, dcCommentsActionsPage $ap, $post) {
155          $co_ids = $ap->getIDs();
156          if (empty($co_ids)) {
157               throw new Exception(__('No comment selected'));
158          }
159          // Backward compatibility
160          foreach($co_ids as $comment_id)
161          {
162               # --BEHAVIOR-- adminBeforeCommentDelete
163               $core->callBehavior('adminBeforeCommentDelete',$comment_id);                   
164          }
165         
166          # --BEHAVIOR-- adminBeforeCommentsDelete
167          $core->callBehavior('adminBeforeCommentsDelete',$co_ids);
168         
169          $core->blog->delComments($co_ids);
170          $ap->redirect(array('del'=>1), false);
171     }
172}
Note: See TracBrowser for help on using the repository browser.

Sites map