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 ----------------------------------------- |
---|
12 | if (!defined('DC_RC_PATH')) { return; } |
---|
13 | |
---|
14 | class 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 entries 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 | protected function fetchEntries($from) { |
---|
60 | if (!empty($from['comments'])) { |
---|
61 | $comments = $from['comments']; |
---|
62 | |
---|
63 | foreach ($comments as $k => $v) { |
---|
64 | $comments[$k] = (integer) $v; |
---|
65 | } |
---|
66 | |
---|
67 | $params['sql'] = 'AND C.comment_id IN('.implode(',',$comments).') '; |
---|
68 | |
---|
69 | if (!isset($from['full_content']) || empty($from['full_content'])) { |
---|
70 | $params['no_content'] = true; |
---|
71 | } |
---|
72 | |
---|
73 | $co = $this->core->blog->getComments($params); |
---|
74 | while ($co->fetch()) { |
---|
75 | $this->entries[$co->comment_id] = array( |
---|
76 | 'title' => $co->post_title, |
---|
77 | 'author' => $co->comment_author |
---|
78 | ); |
---|
79 | } |
---|
80 | $this->rs = $co; |
---|
81 | } |
---|
82 | } |
---|
83 | } |
---|
84 | |
---|
85 | class dcDefaultCommentActions |
---|
86 | { |
---|
87 | public static function adminCommentsActionsPage($core, dcCommentsActionsPage $ap) { |
---|
88 | if ($core->auth->check('publish,contentadmin',$core->blog->id)) |
---|
89 | { |
---|
90 | $action = array('dcDefaultCommentActions','doChangeCommentStatus'); |
---|
91 | $ap->addAction (array(__('Publish') => 'publish'), $action); |
---|
92 | $ap->addAction (array(__('Publish') => 'publish'), $action); |
---|
93 | $ap->addAction (array(__('Unpublish') => 'unpublish'), $action); |
---|
94 | $ap->addAction (array(__('Mark as pending') => 'pending'), $action); |
---|
95 | $ap->addAction(array(__('Mark as junk') => 'junk'), $action); |
---|
96 | } |
---|
97 | |
---|
98 | if ($core->auth->check('delete,contentadmin',$core->blog->id)) |
---|
99 | { |
---|
100 | $ap->addAction(array(__('Delete') => 'delete'), |
---|
101 | array('dcDefaultCommentActions','doDeleteComment')); |
---|
102 | } |
---|
103 | } |
---|
104 | |
---|
105 | public static function doChangeCommentStatus($core, dcCommentsActionsPage $ap, $post) { |
---|
106 | $action = $ap->getAction(); |
---|
107 | $co_ids = $ap->getIDs(); |
---|
108 | if (empty($co_ids)) { |
---|
109 | throw new Exception(__('No comment selected')); |
---|
110 | } |
---|
111 | switch ($action) { |
---|
112 | case 'unpublish' : $status = 0; break; |
---|
113 | case 'pending' : $status = -1; break; |
---|
114 | case 'junk' : $status = -2; break; |
---|
115 | default : $status = 1; break; |
---|
116 | } |
---|
117 | |
---|
118 | $core->blog->updCommentsStatus($co_ids,$status); |
---|
119 | $ap->redirect(array('upd'=>1),true); |
---|
120 | } |
---|
121 | |
---|
122 | public static function doDeleteComment($core, dcCommentsActionsPage $ap, $post) { |
---|
123 | $co_ids = $ap->getIDs(); |
---|
124 | if (empty($co_ids)) { |
---|
125 | throw new Exception(__('No comment selected')); |
---|
126 | } |
---|
127 | // Backward compatibility |
---|
128 | foreach($co_ids as $comment_id) |
---|
129 | { |
---|
130 | # --BEHAVIOR-- adminBeforeCommentDelete |
---|
131 | $core->callBehavior('adminBeforeCommentDelete',$comment_id); |
---|
132 | } |
---|
133 | |
---|
134 | # --BEHAVIOR-- adminBeforeCommentsDelete |
---|
135 | $core->callBehavior('adminBeforeCommentsDelete',$co_ids); |
---|
136 | |
---|
137 | $core->blog->delComments($co_ids); |
---|
138 | $ap->redirect(array('del'=>1), false); |
---|
139 | } |
---|
140 | } |
---|