[0] | 1 | <?php |
---|
| 2 | # -- BEGIN LICENSE BLOCK --------------------------------------- |
---|
| 3 | # |
---|
| 4 | # This file is part of Dotclear 2. |
---|
| 5 | # |
---|
[270] | 6 | # Copyright (c) 2003-2011 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 | |
---|
| 28 | # Status combo |
---|
| 29 | foreach ($core->blog->getAllCommentStatus() as $k => $v) { |
---|
| 30 | $status_combo[$v] = (string) $k; |
---|
| 31 | } |
---|
| 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' => '')); |
---|
| 39 | |
---|
| 40 | if ($rs->isEmpty()) { |
---|
| 41 | throw new Exception(__('Entry does not exist.')); |
---|
| 42 | } |
---|
| 43 | |
---|
| 44 | $cur = $core->con->openCursor($core->prefix.'comment'); |
---|
| 45 | |
---|
| 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']; |
---|
| 51 | |
---|
| 52 | # --BEHAVIOR-- adminBeforeCommentCreate |
---|
| 53 | $core->callBehavior('adminBeforeCommentCreate',$cur); |
---|
| 54 | |
---|
| 55 | $comment_id = $core->blog->addComment($cur); |
---|
| 56 | |
---|
| 57 | # --BEHAVIOR-- adminAfterCommentCreate |
---|
| 58 | $core->callBehavior('adminAfterCommentCreate',$cur,$comment_id); |
---|
| 59 | |
---|
| 60 | http::redirect($core->getPostAdminURL($rs->post_type,$rs->post_id,false).'&co=1&creaco=1'); |
---|
| 61 | } catch (Exception $e) { |
---|
| 62 | $core->error->add($e->getMessage()); |
---|
| 63 | } |
---|
| 64 | } |
---|
| 65 | |
---|
| 66 | if (!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 | |
---|
| 92 | if (!$comment_id && !$core->error->flag()) { |
---|
| 93 | $core->error->add(__('No comment')); |
---|
| 94 | } |
---|
| 95 | |
---|
| 96 | if (!$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 | http::redirect('comment.php?id='.$comment_id.'&upd=1'); |
---|
| 135 | } |
---|
| 136 | catch (Exception $e) |
---|
| 137 | { |
---|
| 138 | $core->error->add($e->getMessage()); |
---|
| 139 | } |
---|
| 140 | } |
---|
| 141 | |
---|
| 142 | if (!empty($_POST['delete']) && $can_delete) |
---|
| 143 | { |
---|
| 144 | try { |
---|
| 145 | # --BEHAVIOR-- adminBeforeCommentDelete |
---|
| 146 | $core->callBehavior('adminBeforeCommentDelete',$comment_id); |
---|
| 147 | |
---|
| 148 | $core->blog->delComment($comment_id); |
---|
| 149 | http::redirect($core->getPostAdminURL($rs->post_type,$rs->post_id).'&co=1#c'.$comment_id,false); |
---|
| 150 | } catch (Exception $e) { |
---|
| 151 | $core->error->add($e->getMessage()); |
---|
| 152 | } |
---|
| 153 | } |
---|
| 154 | |
---|
| 155 | if (!$can_edit) { |
---|
| 156 | $core->error->add(__("You can't edit this comment.")); |
---|
| 157 | } |
---|
| 158 | } |
---|
| 159 | |
---|
| 160 | /* DISPLAY |
---|
| 161 | -------------------------------------------------------- */ |
---|
| 162 | dcPage::open(__('Edit comment'), |
---|
| 163 | dcPage::jsConfirmClose('comment-form'). |
---|
| 164 | dcPage::jsToolBar(). |
---|
| 165 | dcPage::jsLoad('js/_comment.js'). |
---|
| 166 | # --BEHAVIOR-- adminCommentHeaders |
---|
| 167 | $core->callBehavior('adminCommentHeaders') |
---|
| 168 | ); |
---|
| 169 | |
---|
| 170 | if ($comment_id) |
---|
| 171 | { |
---|
| 172 | if (!empty($_GET['upd'])) { |
---|
| 173 | echo '<p class="message">'.__('Comment has been successfully updated.').'</p>'; |
---|
| 174 | } |
---|
| 175 | |
---|
| 176 | $comment_mailto = ''; |
---|
| 177 | if ($comment_email) |
---|
| 178 | { |
---|
| 179 | $comment_mailto = '<a href="mailto:'.html::escapeHTML($comment_email) |
---|
| 180 | .'?subject='.rawurlencode(sprintf(__('Your comment on my blog %s'),$core->blog->name)) |
---|
| 181 | .'&body=' |
---|
| 182 | .rawurlencode(sprintf(__("Hi!\n\nYou wrote a comment on:\n%s\n\n\n"),$rs->getPostURL())) |
---|
| 183 | .'">'.__('Send an e-mail').'</a>'; |
---|
| 184 | } |
---|
| 185 | |
---|
| 186 | echo '<h2>'.html::escapeHTML($core->blog->name).' › '.__('Edit comment').'</h2>'; |
---|
| 187 | |
---|
| 188 | echo '<p><a class="back" href="'.$core->getPostAdminURL($post_type,$post_id).'&co=1#c'.$comment_id.'"> '. |
---|
| 189 | sprintf(__('Back to "%s"'),$post_title).'</a></p>'; |
---|
| 190 | |
---|
| 191 | echo |
---|
| 192 | '<form action="comment.php" method="post" id="comment-form">'. |
---|
[45] | 193 | '<p>'.__('IP address:').'<br /> '. |
---|
[0] | 194 | '<a href="comments.php?ip='.$comment_ip.'">'.$comment_ip.'</a></p>'. |
---|
| 195 | |
---|
[45] | 196 | '<p>'.__('Date:').'<br /> '. |
---|
[0] | 197 | dt::dt2str(__('%Y-%m-%d %H:%M'),$comment_dt).'</p>'. |
---|
| 198 | |
---|
[45] | 199 | '<p><label for="comment_author" class="required"><abbr title="'.__('Required field').'">*</abbr>'.__('Author:'). |
---|
[0] | 200 | form::field('comment_author',30,255,html::escapeHTML($comment_author)). |
---|
| 201 | '</label></p>'. |
---|
| 202 | |
---|
[45] | 203 | '<p><label for="comment_email">'.__('Email:'). |
---|
[0] | 204 | form::field('comment_email',30,255,html::escapeHTML($comment_email)). |
---|
| 205 | $comment_mailto. |
---|
| 206 | '</label></p>'. |
---|
| 207 | |
---|
[45] | 208 | '<p><label for="comment_site">'.__('Web site:'). |
---|
[0] | 209 | form::field('comment_site',30,255,html::escapeHTML($comment_site)). |
---|
| 210 | '</label></p>'. |
---|
| 211 | |
---|
[45] | 212 | '<p><label for="comment_status">'.__('Status:'). |
---|
[0] | 213 | form::combo('comment_status',$status_combo,$comment_status,'','',!$can_publish). |
---|
| 214 | '</label></p>'. |
---|
| 215 | |
---|
| 216 | # --BEHAVIOR-- adminAfterCommentDesc |
---|
| 217 | $core->callBehavior('adminAfterCommentDesc', $rs). |
---|
| 218 | |
---|
| 219 | '<p class="area"><label for="comment_content">'.__('Comment:').'</label> '. |
---|
| 220 | form::textarea('comment_content',50,10,html::escapeHTML($comment_content)). |
---|
| 221 | '</p>'. |
---|
| 222 | |
---|
| 223 | '<p>'.form::hidden('id',$comment_id). |
---|
| 224 | $core->formNonce(). |
---|
[217] | 225 | '<input type="submit" accesskey="s" name="update" value="'.__('Save').'" /> '; |
---|
[0] | 226 | |
---|
| 227 | if ($can_delete) { |
---|
[205] | 228 | echo '<input type="submit" class="delete" name="delete" value="'.__('Delete').'" />'; |
---|
[0] | 229 | } |
---|
| 230 | echo |
---|
| 231 | '</p>'. |
---|
| 232 | '</form>'; |
---|
| 233 | } |
---|
| 234 | |
---|
| 235 | dcPage::helpBlock('core_comments'); |
---|
| 236 | dcPage::close(); |
---|
| 237 | ?> |
---|