| 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 |  | 
|---|
| 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 | if ($comment_id) { | 
|---|
| 163 |      $breadcrumb = dcPage::breadcrumb( | 
|---|
| 164 |           array( | 
|---|
| 165 |                html::escapeHTML($core->blog->name) => '', | 
|---|
| 166 |                html::escapeHTML($post_title) => $core->getPostAdminURL($post_type,$post_id).'&co=1#c'.$comment_id, | 
|---|
| 167 |                '<span class="page-title">'.__('Edit comment').'</span>' => '' | 
|---|
| 168 |           )); | 
|---|
| 169 | } else { | 
|---|
| 170 |      $breadcrumb = dcPage::breadcrumb( | 
|---|
| 171 |           array( | 
|---|
| 172 |                html::escapeHTML($core->blog->name) => '', | 
|---|
| 173 |                html::escapeHTML($post_title) => $core->getPostAdminURL($post_type,$post_id), | 
|---|
| 174 |                '<span class="page-title">'.__('Edit comment').'</span>' => '' | 
|---|
| 175 |           )); | 
|---|
| 176 | } | 
|---|
| 177 |  | 
|---|
| 178 | dcPage::open(__('Edit comment'), | 
|---|
| 179 |      dcPage::jsConfirmClose('comment-form'). | 
|---|
| 180 |      dcPage::jsToolBar(). | 
|---|
| 181 |      dcPage::jsLoad('js/_comment.js'). | 
|---|
| 182 |      # --BEHAVIOR-- adminCommentHeaders | 
|---|
| 183 |      $core->callBehavior('adminCommentHeaders'), | 
|---|
| 184 |      $breadcrumb | 
|---|
| 185 | ); | 
|---|
| 186 |  | 
|---|
| 187 | if ($comment_id) | 
|---|
| 188 | { | 
|---|
| 189 |      if (!empty($_GET['upd'])) { | 
|---|
| 190 |           dcPage::message(__('Comment has been successfully updated.')); | 
|---|
| 191 |      } | 
|---|
| 192 |       | 
|---|
| 193 |      $comment_mailto = ''; | 
|---|
| 194 |      if ($comment_email) | 
|---|
| 195 |      { | 
|---|
| 196 |           $comment_mailto = '<a href="mailto:'.html::escapeHTML($comment_email) | 
|---|
| 197 |           .'?subject='.rawurlencode(sprintf(__('Your comment on my blog %s'),$core->blog->name)) | 
|---|
| 198 |           .'&body=' | 
|---|
| 199 |           .rawurlencode(sprintf(__("Hi!\n\nYou wrote a comment on:\n%s\n\n\n"),$rs->getPostURL())) | 
|---|
| 200 |           .'">'.__('Send an e-mail').'</a>'; | 
|---|
| 201 |      } | 
|---|
| 202 |  | 
|---|
| 203 |      echo | 
|---|
| 204 |      '<form action="comment.php" method="post" id="comment-form">'. | 
|---|
| 205 |      '<div class="fieldset">'. | 
|---|
| 206 |      '<h3>'.__('Information collected').'</h3>'. | 
|---|
| 207 |      '<p>'.__('IP address:').' '. | 
|---|
| 208 |      '<a href="comments.php?ip='.$comment_ip.'">'.$comment_ip.'</a></p>'. | 
|---|
| 209 |       | 
|---|
| 210 |      '<p>'.__('Date:').' '. | 
|---|
| 211 |      dt::dt2str(__('%Y-%m-%d %H:%M'),$comment_dt).'</p>'. | 
|---|
| 212 |      '</div>'. | 
|---|
| 213 |  | 
|---|
| 214 |      '<h3>'.__('Comment submitted').'</h3>'.  | 
|---|
| 215 |      '<p><label for="comment_author" class="required"><abbr title="'.__('Required field').'">*</abbr>'.__('Author:').'</label>'. | 
|---|
| 216 |      form::field('comment_author',30,255,html::escapeHTML($comment_author)). | 
|---|
| 217 |      '</p>'. | 
|---|
| 218 |       | 
|---|
| 219 |      '<p><label for="comment_email">'.__('Email:').'</label>'. | 
|---|
| 220 |      form::field('comment_email',30,255,html::escapeHTML($comment_email)). | 
|---|
| 221 |      '<span>'.$comment_mailto.'</span>'. | 
|---|
| 222 |      '</p>'. | 
|---|
| 223 |       | 
|---|
| 224 |      '<p><label for="comment_site">'.__('Web site:').'</label>'. | 
|---|
| 225 |      form::field('comment_site',30,255,html::escapeHTML($comment_site)). | 
|---|
| 226 |      '</p>'. | 
|---|
| 227 |       | 
|---|
| 228 |      '<p><label for="comment_status">'.__('Status:').'</label>'. | 
|---|
| 229 |      form::combo('comment_status',$status_combo,$comment_status,'','',!$can_publish). | 
|---|
| 230 |      '</p>'. | 
|---|
| 231 |       | 
|---|
| 232 |      # --BEHAVIOR-- adminAfterCommentDesc | 
|---|
| 233 |      $core->callBehavior('adminAfterCommentDesc', $rs). | 
|---|
| 234 |       | 
|---|
| 235 |      '<p class="area"><label for="comment_content">'.__('Comment:').'</label> '. | 
|---|
| 236 |      form::textarea('comment_content',50,10,html::escapeHTML($comment_content)). | 
|---|
| 237 |      '</p>'. | 
|---|
| 238 |       | 
|---|
| 239 |      '<p>'.form::hidden('id',$comment_id). | 
|---|
| 240 |      $core->formNonce(). | 
|---|
| 241 |      '<input type="submit" accesskey="s" name="update" value="'.__('Save').'" /> '; | 
|---|
| 242 |       | 
|---|
| 243 |      if ($can_delete) { | 
|---|
| 244 |           echo '<input type="submit" class="delete" name="delete" value="'.__('Delete').'" />'; | 
|---|
| 245 |      } | 
|---|
| 246 |      echo | 
|---|
| 247 |      '</p>'. | 
|---|
| 248 |      '</form>'; | 
|---|
| 249 | } | 
|---|
| 250 |  | 
|---|
| 251 | dcPage::helpBlock('core_comments'); | 
|---|
| 252 | dcPage::close(); | 
|---|
| 253 | ?> | 
|---|