Dotclear

source: admin/comment.php @ 3874:ab8368569446

Revision 3874:ab8368569446, 8.6 KB checked in by franck <carnet.franck.paul@…>, 7 years ago (diff)

short notation for array (array() → [])

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

Sites map