Dotclear

source: admin/comment.php @ 3703:53c8bef8608a

Revision 3703:53c8bef8608a, 8.8 KB checked in by franck <carnet.franck.paul@…>, 7 years ago (diff)

Use array form of optionnal parameters for form::combo(), code formatting (PSR-2)

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$comment_editor = $core->auth->getOption('editor');
29
30# Status combo
31$status_combo = dcAdminCombos::getCommentStatusescombo();
32
33# Adding comment (comming from post form, comments tab)
34if (!empty($_POST['add']) && !empty($_POST['post_id'])) {
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    } catch (Exception $e) {
61        $core->error->add($e->getMessage());
62    }
63    http::redirect($core->getPostAdminURL($rs->post_type, $rs->post_id, false) . '&co=1');
64}
65
66if (!empty($_REQUEST['id'])) {
67    $params['comment_id'] = $_REQUEST['id'];
68
69    try {
70        $rs = $core->blog->getComments($params);
71        if (!$rs->isEmpty()) {
72            $comment_id          = $rs->comment_id;
73            $post_id             = $rs->post_id;
74            $post_type           = $rs->post_type;
75            $post_title          = $rs->post_title;
76            $comment_dt          = $rs->comment_dt;
77            $comment_author      = $rs->comment_author;
78            $comment_email       = $rs->comment_email;
79            $comment_site        = $rs->comment_site;
80            $comment_content     = $rs->comment_content;
81            $comment_ip          = $rs->comment_ip;
82            $comment_status      = $rs->comment_status;
83            $comment_trackback   = (boolean) $rs->comment_trackback;
84            $comment_spam_status = $rs->comment_spam_status;
85        }
86    } catch (Exception $e) {
87        $core->error->add($e->getMessage());
88    }
89}
90
91if (!$comment_id && !$core->error->flag()) {
92    $core->error->add(__('No comments'));
93}
94
95if (!$core->error->flag() && isset($rs)) {
96    $can_edit = $can_delete = $can_publish = $core->auth->check('contentadmin', $core->blog->id);
97
98    if (!$core->auth->check('contentadmin', $core->blog->id) && $core->auth->userID() == $rs->user_id) {
99        $can_edit = true;
100        if ($core->auth->check('delete', $core->blog->id)) {
101            $can_delete = true;
102        }
103        if ($core->auth->check('publish', $core->blog->id)) {
104            $can_publish = true;
105        }
106    }
107
108    # update comment
109    if (!empty($_POST['update']) && $can_edit) {
110        $cur = $core->con->openCursor($core->prefix . 'comment');
111
112        $cur->comment_author  = $_POST['comment_author'];
113        $cur->comment_email   = html::clean($_POST['comment_email']);
114        $cur->comment_site    = html::clean($_POST['comment_site']);
115        $cur->comment_content = $core->HTMLfilter($_POST['comment_content']);
116
117        if (isset($_POST['comment_status'])) {
118            $cur->comment_status = (integer) $_POST['comment_status'];
119        }
120
121        try
122        {
123            # --BEHAVIOR-- adminBeforeCommentUpdate
124            $core->callBehavior('adminBeforeCommentUpdate', $cur, $comment_id);
125
126            $core->blog->updComment($comment_id, $cur);
127
128            # --BEHAVIOR-- adminAfterCommentUpdate
129            $core->callBehavior('adminAfterCommentUpdate', $cur, $comment_id);
130
131            dcPage::addSuccessNotice(__('Comment has been successfully updated.'));
132            $core->adminurl->redirect("admin.comment", array('id' => $comment_id));
133        } catch (Exception $e) {
134            $core->error->add($e->getMessage());
135        }
136    }
137
138    if (!empty($_POST['delete']) && $can_delete) {
139        try {
140            # --BEHAVIOR-- adminBeforeCommentDelete
141            $core->callBehavior('adminBeforeCommentDelete', $comment_id);
142
143            $core->blog->delComment($comment_id);
144
145            dcPage::addSuccessNotice(__('Comment has been successfully deleted.'));
146            http::redirect($core->getPostAdminURL($rs->post_type, $rs->post_id) . '&co=1', false);
147        } catch (Exception $e) {
148            $core->error->add($e->getMessage());
149        }
150    }
151
152    if (!$can_edit) {
153        $core->error->add(__("You can't edit this comment."));
154    }
155}
156
157/* DISPLAY
158-------------------------------------------------------- */
159if ($comment_id) {
160    $breadcrumb = dcPage::breadcrumb(
161        array(
162            html::escapeHTML($core->blog->name) => '',
163            html::escapeHTML($post_title)       => $core->getPostAdminURL($post_type, $post_id) . '&amp;co=1#c' . $comment_id,
164            __('Edit comment')                  => ''
165        ));
166} else {
167    $breadcrumb = dcPage::breadcrumb(
168        array(
169            html::escapeHTML($core->blog->name) => '',
170            html::escapeHTML($post_title)       => $core->getPostAdminURL($post_type, $post_id),
171            __('Edit comment')                  => ''
172        ));
173}
174
175dcPage::open(__('Edit comment'),
176    dcPage::jsConfirmClose('comment-form') .
177    dcPage::jsLoad('js/_comment.js') .
178    $core->callBehavior('adminPostEditor', $comment_editor['xhtml'], 'comment', array('#comment_content'), 'xhtml') .
179    # --BEHAVIOR-- adminCommentHeaders
180    $core->callBehavior('adminCommentHeaders'),
181    $breadcrumb
182);
183
184if ($comment_id) {
185    if (!empty($_GET['upd'])) {
186        dcPage::success(__('Comment has been successfully updated.'));
187    }
188
189    $comment_mailto = '';
190    if ($comment_email) {
191        $comment_mailto = '<a href="mailto:' . html::escapeHTML($comment_email)
192        . '?subject=' . rawurlencode(sprintf(__('Your comment on my blog %s'), $core->blog->name))
193        . '&amp;body='
194        . rawurlencode(sprintf(__("Hi!\n\nYou wrote a comment on:\n%s\n\n\n"), $rs->getPostURL()))
195        . '">' . __('Send an e-mail') . '</a>';
196    }
197
198    echo
199    '<form action="' . $core->adminurl->get("admin.comment") . '" method="post" id="comment-form">' .
200    '<div class="fieldset">' .
201    '<h3>' . __('Information collected') . '</h3>' .
202    '<p>' . __('IP address:') . ' ' .
203    '<a href="' . $core->adminurl->get("admin.comments", array('ip' => $comment_ip)) . '">' . $comment_ip . '</a></p>' .
204
205    '<p>' . __('Date:') . ' ' .
206    dt::dt2str(__('%Y-%m-%d %H:%M'), $comment_dt) . '</p>' .
207    '</div>' .
208
209    '<h3>' . __('Comment submitted') . '</h3>' .
210    '<p><label for="comment_author" class="required"><abbr title="' . __('Required field') . '">*</abbr>' . __('Author:') . '</label>' .
211    form::field('comment_author', 30, 255, html::escapeHTML($comment_author), '', '', false, 'required placeholder="' . __('Author') . '"') .
212    '</p>' .
213
214    '<p><label for="comment_email">' . __('Email:') . '</label>' .
215    form::field('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::field('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        array('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