[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 | |
---|
[1719] | 28 | |
---|
[0] | 29 | # Status combo |
---|
[1719] | 30 | $status_combo = dcAdminCombos::getCommentStatusescombo(); |
---|
[0] | 31 | |
---|
| 32 | # Adding comment |
---|
| 33 | if (!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 | http::redirect($core->getPostAdminURL($rs->post_type,$rs->post_id,false).'&co=1&creaco=1'); |
---|
| 60 | } catch (Exception $e) { |
---|
| 61 | $core->error->add($e->getMessage()); |
---|
| 62 | } |
---|
| 63 | } |
---|
| 64 | |
---|
| 65 | if (!empty($_REQUEST['id'])) |
---|
| 66 | { |
---|
| 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 | |
---|
| 91 | if (!$comment_id && !$core->error->flag()) { |
---|
| 92 | $core->error->add(__('No comment')); |
---|
| 93 | } |
---|
| 94 | |
---|
| 95 | if (!$core->error->flag() && isset($rs)) |
---|
| 96 | { |
---|
| 97 | $can_edit = $can_delete = $can_publish = $core->auth->check('contentadmin',$core->blog->id); |
---|
| 98 | |
---|
| 99 | if (!$core->auth->check('contentadmin',$core->blog->id) && $core->auth->userID() == $rs->user_id) { |
---|
| 100 | $can_edit = true; |
---|
| 101 | if ($core->auth->check('delete',$core->blog->id)) { |
---|
| 102 | $can_delete = true; |
---|
| 103 | } |
---|
| 104 | if ($core->auth->check('publish',$core->blog->id)) { |
---|
| 105 | $can_publish = true; |
---|
| 106 | } |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | # update comment |
---|
| 110 | if (!empty($_POST['update']) && $can_edit) |
---|
| 111 | { |
---|
| 112 | $cur = $core->con->openCursor($core->prefix.'comment'); |
---|
| 113 | |
---|
| 114 | $cur->comment_author = $_POST['comment_author']; |
---|
| 115 | $cur->comment_email = html::clean($_POST['comment_email']); |
---|
| 116 | $cur->comment_site = html::clean($_POST['comment_site']); |
---|
| 117 | $cur->comment_content = $core->HTMLfilter($_POST['comment_content']); |
---|
| 118 | |
---|
| 119 | if (isset($_POST['comment_status'])) { |
---|
| 120 | $cur->comment_status = (integer) $_POST['comment_status']; |
---|
| 121 | } |
---|
| 122 | |
---|
| 123 | try |
---|
| 124 | { |
---|
| 125 | # --BEHAVIOR-- adminBeforeCommentUpdate |
---|
| 126 | $core->callBehavior('adminBeforeCommentUpdate',$cur,$comment_id); |
---|
| 127 | |
---|
| 128 | $core->blog->updComment($comment_id,$cur); |
---|
| 129 | |
---|
| 130 | # --BEHAVIOR-- adminAfterCommentUpdate |
---|
| 131 | $core->callBehavior('adminAfterCommentUpdate',$cur,$comment_id); |
---|
| 132 | |
---|
| 133 | http::redirect('comment.php?id='.$comment_id.'&upd=1'); |
---|
| 134 | } |
---|
| 135 | catch (Exception $e) |
---|
| 136 | { |
---|
| 137 | $core->error->add($e->getMessage()); |
---|
| 138 | } |
---|
| 139 | } |
---|
| 140 | |
---|
| 141 | if (!empty($_POST['delete']) && $can_delete) |
---|
| 142 | { |
---|
| 143 | try { |
---|
| 144 | # --BEHAVIOR-- adminBeforeCommentDelete |
---|
| 145 | $core->callBehavior('adminBeforeCommentDelete',$comment_id); |
---|
| 146 | |
---|
| 147 | $core->blog->delComment($comment_id); |
---|
| 148 | http::redirect($core->getPostAdminURL($rs->post_type,$rs->post_id).'&co=1#c'.$comment_id,false); |
---|
| 149 | } catch (Exception $e) { |
---|
| 150 | $core->error->add($e->getMessage()); |
---|
| 151 | } |
---|
| 152 | } |
---|
| 153 | |
---|
| 154 | if (!$can_edit) { |
---|
| 155 | $core->error->add(__("You can't edit this comment.")); |
---|
| 156 | } |
---|
| 157 | } |
---|
| 158 | |
---|
| 159 | /* DISPLAY |
---|
| 160 | -------------------------------------------------------- */ |
---|
[1358] | 161 | if ($comment_id) { |
---|
| 162 | $breadcrumb = dcPage::breadcrumb( |
---|
| 163 | array( |
---|
| 164 | html::escapeHTML($core->blog->name) => '', |
---|
| 165 | html::escapeHTML($post_title) => $core->getPostAdminURL($post_type,$post_id).'&co=1#c'.$comment_id, |
---|
| 166 | '<span class="page-title">'.__('Edit comment').'</span>' => '' |
---|
| 167 | )); |
---|
| 168 | } else { |
---|
| 169 | $breadcrumb = dcPage::breadcrumb( |
---|
| 170 | array( |
---|
| 171 | html::escapeHTML($core->blog->name) => '', |
---|
| 172 | html::escapeHTML($post_title) => $core->getPostAdminURL($post_type,$post_id), |
---|
| 173 | '<span class="page-title">'.__('Edit comment').'</span>' => '' |
---|
| 174 | )); |
---|
| 175 | } |
---|
| 176 | |
---|
[0] | 177 | dcPage::open(__('Edit comment'), |
---|
| 178 | dcPage::jsConfirmClose('comment-form'). |
---|
| 179 | dcPage::jsToolBar(). |
---|
| 180 | dcPage::jsLoad('js/_comment.js'). |
---|
| 181 | # --BEHAVIOR-- adminCommentHeaders |
---|
[1358] | 182 | $core->callBehavior('adminCommentHeaders'), |
---|
| 183 | $breadcrumb |
---|
[0] | 184 | ); |
---|
| 185 | |
---|
| 186 | if ($comment_id) |
---|
| 187 | { |
---|
| 188 | if (!empty($_GET['upd'])) { |
---|
[1553] | 189 | dcPage::success(__('Comment has been successfully updated.')); |
---|
[0] | 190 | } |
---|
| 191 | |
---|
| 192 | $comment_mailto = ''; |
---|
| 193 | if ($comment_email) |
---|
| 194 | { |
---|
| 195 | $comment_mailto = '<a href="mailto:'.html::escapeHTML($comment_email) |
---|
| 196 | .'?subject='.rawurlencode(sprintf(__('Your comment on my blog %s'),$core->blog->name)) |
---|
| 197 | .'&body=' |
---|
| 198 | .rawurlencode(sprintf(__("Hi!\n\nYou wrote a comment on:\n%s\n\n\n"),$rs->getPostURL())) |
---|
| 199 | .'">'.__('Send an e-mail').'</a>'; |
---|
| 200 | } |
---|
[1332] | 201 | |
---|
[0] | 202 | echo |
---|
| 203 | '<form action="comment.php" method="post" id="comment-form">'. |
---|
[1399] | 204 | '<div class="fieldset">'. |
---|
| 205 | '<h3>'.__('Information collected').'</h3>'. |
---|
| 206 | '<p>'.__('IP address:').' '. |
---|
[0] | 207 | '<a href="comments.php?ip='.$comment_ip.'">'.$comment_ip.'</a></p>'. |
---|
| 208 | |
---|
[1399] | 209 | '<p>'.__('Date:').' '. |
---|
[0] | 210 | dt::dt2str(__('%Y-%m-%d %H:%M'),$comment_dt).'</p>'. |
---|
[1399] | 211 | '</div>'. |
---|
| 212 | |
---|
| 213 | '<h3>'.__('Comment submitted').'</h3>'. |
---|
| 214 | '<p><label for="comment_author" class="required"><abbr title="'.__('Required field').'">*</abbr>'.__('Author:').'</label>'. |
---|
| 215 | form::field('comment_author',30,255,html::escapeHTML($comment_author)). |
---|
| 216 | '</p>'. |
---|
[0] | 217 | |
---|
[1399] | 218 | '<p><label for="comment_email">'.__('Email:').'</label>'. |
---|
| 219 | form::field('comment_email',30,255,html::escapeHTML($comment_email)). |
---|
| 220 | '<span>'.$comment_mailto.'</span>'. |
---|
| 221 | '</p>'. |
---|
[0] | 222 | |
---|
[1399] | 223 | '<p><label for="comment_site">'.__('Web site:').'</label>'. |
---|
| 224 | form::field('comment_site',30,255,html::escapeHTML($comment_site)). |
---|
| 225 | '</p>'. |
---|
[0] | 226 | |
---|
[1399] | 227 | '<p><label for="comment_status">'.__('Status:').'</label>'. |
---|
[0] | 228 | form::combo('comment_status',$status_combo,$comment_status,'','',!$can_publish). |
---|
[1399] | 229 | '</p>'. |
---|
[0] | 230 | |
---|
| 231 | # --BEHAVIOR-- adminAfterCommentDesc |
---|
| 232 | $core->callBehavior('adminAfterCommentDesc', $rs). |
---|
| 233 | |
---|
| 234 | '<p class="area"><label for="comment_content">'.__('Comment:').'</label> '. |
---|
| 235 | form::textarea('comment_content',50,10,html::escapeHTML($comment_content)). |
---|
| 236 | '</p>'. |
---|
| 237 | |
---|
| 238 | '<p>'.form::hidden('id',$comment_id). |
---|
| 239 | $core->formNonce(). |
---|
[217] | 240 | '<input type="submit" accesskey="s" name="update" value="'.__('Save').'" /> '; |
---|
[0] | 241 | |
---|
| 242 | if ($can_delete) { |
---|
[205] | 243 | echo '<input type="submit" class="delete" name="delete" value="'.__('Delete').'" />'; |
---|
[0] | 244 | } |
---|
| 245 | echo |
---|
| 246 | '</p>'. |
---|
| 247 | '</form>'; |
---|
| 248 | } |
---|
| 249 | |
---|
| 250 | dcPage::helpBlock('core_comments'); |
---|
| 251 | dcPage::close(); |
---|
| 252 | ?> |
---|