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