Dotclear

source: admin/comment.php @ 2614:db6f6a1f4f25

Revision 2614:db6f6a1f4f25, 7.3 KB checked in by Nicolas <nikrou77@…>, 12 years ago (diff)

Move legacy editor to a plugin. First step for alternate editors.
Addresses #1896

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 -----------------------------------------
12
13require dirname(__FILE__).'/../inc/admin/prepend.php';
14
15dcPage::check('usage,contentadmin');
16
17$comment_id = null;
18$comment_dt = '';
19$comment_author = '';
20$comment_email = '';
21$comment_site = '';
22$comment_content = '';
23$comment_ip = '';
24$comment_status = '';
25$comment_trackback = 0;
26$comment_spam_status = '';
27
28
29# Status combo
30$status_combo = dcAdminCombos::getCommentStatusescombo();
31
32# Adding comment
33if (!empty($_POST['add']) && !empty($_POST['post_id']))
34{
35     try
36     {
37          $rs = $core->blog->getPosts(array('post_id' => $_POST['post_id'], 'post_type' => ''));
38
39          if ($rs->isEmpty()) {
40               throw new Exception(__('Entry does not exist.'));
41          }
42
43          $cur = $core->con->openCursor($core->prefix.'comment');
44
45          $cur->comment_author = $_POST['comment_author'];
46          $cur->comment_email = html::clean($_POST['comment_email']);
47          $cur->comment_site = html::clean($_POST['comment_site']);
48          $cur->comment_content = $core->HTMLfilter($_POST['comment_content']);
49          $cur->post_id = (integer) $_POST['post_id'];
50
51          # --BEHAVIOR-- adminBeforeCommentCreate
52          $core->callBehavior('adminBeforeCommentCreate',$cur);
53
54          $comment_id = $core->blog->addComment($cur);
55
56          # --BEHAVIOR-- adminAfterCommentCreate
57          $core->callBehavior('adminAfterCommentCreate',$cur,$comment_id);
58
59          dcPage::addSuccessNotice(__('Comment has been successfully created.'));
60          http::redirect($core->getPostAdminURL($rs->post_type,$rs->post_id,false).'&co=1');
61     } catch (Exception $e) {
62          $core->error->add($e->getMessage());
63     }
64}
65
66if (!empty($_REQUEST['id']))
67{
68     $params['comment_id'] = $_REQUEST['id'];
69
70     try {
71          $rs = $core->blog->getComments($params);
72          if (!$rs->isEmpty()) {
73               $comment_id = $rs->comment_id;
74               $post_id = $rs->post_id;
75               $post_type = $rs->post_type;
76               $post_title = $rs->post_title;
77               $comment_dt = $rs->comment_dt;
78               $comment_author = $rs->comment_author;
79               $comment_email = $rs->comment_email;
80               $comment_site = $rs->comment_site;
81               $comment_content = $rs->comment_content;
82               $comment_ip = $rs->comment_ip;
83               $comment_status = $rs->comment_status;
84               $comment_trackback = (boolean) $rs->comment_trackback;
85               $comment_spam_status = $rs->comment_spam_status;
86          }
87     } catch (Exception $e) {
88          $core->error->add($e->getMessage());
89     }
90}
91
92if (!$comment_id && !$core->error->flag()) {
93     $core->error->add(__('No comment'));
94}
95
96if (!$core->error->flag() && isset($rs))
97{
98     $can_edit = $can_delete = $can_publish = $core->auth->check('contentadmin',$core->blog->id);
99
100     if (!$core->auth->check('contentadmin',$core->blog->id) && $core->auth->userID() == $rs->user_id) {
101          $can_edit = true;
102          if ($core->auth->check('delete',$core->blog->id)) {
103               $can_delete = true;
104          }
105          if ($core->auth->check('publish',$core->blog->id)) {
106               $can_publish = true;
107          }
108     }
109
110     # update comment
111     if (!empty($_POST['update']) && $can_edit)
112     {
113          $cur = $core->con->openCursor($core->prefix.'comment');
114
115          $cur->comment_author = $_POST['comment_author'];
116          $cur->comment_email = html::clean($_POST['comment_email']);
117          $cur->comment_site = html::clean($_POST['comment_site']);
118          $cur->comment_content = $core->HTMLfilter($_POST['comment_content']);
119
120          if (isset($_POST['comment_status'])) {
121               $cur->comment_status = (integer) $_POST['comment_status'];
122          }
123
124          try
125          {
126               # --BEHAVIOR-- adminBeforeCommentUpdate
127               $core->callBehavior('adminBeforeCommentUpdate',$cur,$comment_id);
128
129               $core->blog->updComment($comment_id,$cur);
130
131               # --BEHAVIOR-- adminAfterCommentUpdate
132               $core->callBehavior('adminAfterCommentUpdate',$cur,$comment_id);
133
134               dcPage::addSuccessNotice(__('Comment has been successfully updated.'));
135               http::redirect('comment.php?id='.$comment_id);
136          }
137          catch (Exception $e)
138          {
139               $core->error->add($e->getMessage());
140          }
141     }
142
143     if (!empty($_POST['delete']) && $can_delete)
144     {
145          try {
146               # --BEHAVIOR-- adminBeforeCommentDelete
147               $core->callBehavior('adminBeforeCommentDelete',$comment_id);
148
149               $core->blog->delComment($comment_id);
150
151               dcPage::addSuccessNotice(__('Comment has been successfully deleted.'));
152               http::redirect($core->getPostAdminURL($rs->post_type,$rs->post_id).'&co=1',false);
153          } catch (Exception $e) {
154               $core->error->add($e->getMessage());
155          }
156     }
157
158     if (!$can_edit) {
159          $core->error->add(__("You can't edit this comment."));
160     }
161}
162
163/* DISPLAY
164-------------------------------------------------------- */
165if ($comment_id) {
166     $breadcrumb = dcPage::breadcrumb(
167          array(
168               html::escapeHTML($core->blog->name) => '',
169               html::escapeHTML($post_title) => $core->getPostAdminURL($post_type,$post_id).'&amp;co=1#c'.$comment_id,
170               __('Edit comment') => ''
171          ));
172} else {
173     $breadcrumb = dcPage::breadcrumb(
174          array(
175               html::escapeHTML($core->blog->name) => '',
176               html::escapeHTML($post_title) => $core->getPostAdminURL($post_type,$post_id),
177               __('Edit comment') => ''
178          ));
179}
180
181dcPage::open(__('Edit comment'),
182     dcPage::jsConfirmClose('comment-form').
183     dcPage::jsLoad('js/_comment.js').
184     $core->callBehavior('adminPostEditor').
185     # --BEHAVIOR-- adminCommentHeaders
186     $core->callBehavior('adminCommentHeaders'),
187     $breadcrumb
188);
189
190if ($comment_id)
191{
192     if (!empty($_GET['upd'])) {
193          dcPage::success(__('Comment has been successfully updated.'));
194     }
195
196     $comment_mailto = '';
197     if ($comment_email)
198     {
199          $comment_mailto = '<a href="mailto:'.html::escapeHTML($comment_email)
200          .'?subject='.rawurlencode(sprintf(__('Your comment on my blog %s'),$core->blog->name))
201          .'&amp;body='
202          .rawurlencode(sprintf(__("Hi!\n\nYou wrote a comment on:\n%s\n\n\n"),$rs->getPostURL()))
203          .'">'.__('Send an e-mail').'</a>';
204     }
205
206     echo
207     '<form action="comment.php" method="post" id="comment-form">'.
208     '<div class="fieldset">'.
209     '<h3>'.__('Information collected').'</h3>'.
210     '<p>'.__('IP address:').' '.
211     '<a href="comments.php?ip='.$comment_ip.'">'.$comment_ip.'</a></p>'.
212
213     '<p>'.__('Date:').' '.
214     dt::dt2str(__('%Y-%m-%d %H:%M'),$comment_dt).'</p>'.
215     '</div>'.
216
217     '<h3>'.__('Comment submitted').'</h3>'.
218     '<p><label for="comment_author" class="required"><abbr title="'.__('Required field').'">*</abbr>'.__('Author:').'</label>'.
219     form::field('comment_author',30,255,html::escapeHTML($comment_author)).
220     '</p>'.
221
222     '<p><label for="comment_email">'.__('Email:').'</label>'.
223     form::field('comment_email',30,255,html::escapeHTML($comment_email)).
224     '<span>'.$comment_mailto.'</span>'.
225     '</p>'.
226
227     '<p><label for="comment_site">'.__('Web site:').'</label>'.
228     form::field('comment_site',30,255,html::escapeHTML($comment_site)).
229     '</p>'.
230
231     '<p><label for="comment_status">'.__('Status:').'</label>'.
232     form::combo('comment_status',$status_combo,$comment_status,'','',!$can_publish).
233     '</p>'.
234
235     # --BEHAVIOR-- adminAfterCommentDesc
236     $core->callBehavior('adminAfterCommentDesc', $rs).
237
238     '<p class="area"><label for="comment_content">'.__('Comment:').'</label> '.
239     form::textarea('comment_content',50,10,html::escapeHTML($comment_content)).
240     '</p>'.
241
242     '<p>'.form::hidden('id',$comment_id).
243     $core->formNonce().
244     '<input type="submit" accesskey="s" name="update" value="'.__('Save').'" /> ';
245
246     if ($can_delete) {
247          echo '<input type="submit" class="delete" name="delete" value="'.__('Delete').'" />';
248     }
249     echo
250     '</p>'.
251     '</form>';
252}
253
254dcPage::helpBlock('core_comments');
255dcPage::close();
Note: See TracBrowser for help on using the repository browser.

Sites map