[ Index ]
 

Code source de Dotclear 2.0-beta6

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/admin/ -> comment.php (source)

   1  <?php
   2  # ***** BEGIN LICENSE BLOCK *****
   3  # This file is part of DotClear.
   4  # Copyright (c) 2005 Olivier Meunier and contributors. All rights
   5  # reserved.
   6  #
   7  # DotClear is free software; you can redistribute it and/or modify
   8  # it under the terms of the GNU General Public License as published by
   9  # the Free Software Foundation; either version 2 of the License, or
  10  # (at your option) any later version.
  11  # 
  12  # DotClear is distributed in the hope that it will be useful,
  13  # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15  # GNU General Public License for more details.
  16  # 
  17  # You should have received a copy of the GNU General Public License
  18  # along with DotClear; if not, write to the Free Software
  19  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  20  #
  21  # ***** END LICENSE BLOCK *****
  22  
  23  require dirname(__FILE__).'/../inc/admin/prepend.php';
  24  
  25  dcPage::check('usage,contentadmin');
  26  
  27  $comment_id = null;
  28  $comment_dt = '';
  29  $comment_author = '';
  30  $comment_email = '';
  31  $comment_site = '';
  32  $comment_content = '';
  33  $comment_ip = '';
  34  $comment_status = '';
  35  $comment_trackback = 0;
  36  $comment_spam_status = '';
  37  
  38  # Status combo
  39  foreach ($core->blog->getAllCommentStatus() as $k => $v) {
  40      $status_combo[$v] = (string) $k;
  41  }
  42  
  43  # Adding comment
  44  if (!empty($_POST['add']) && !empty($_POST['post_id']))
  45  {
  46      $cur = $core->con->openCursor($core->prefix.'comment');
  47      
  48      $cur->comment_author = $_POST['comment_author'];
  49      $cur->comment_email = html::clean($_POST['comment_email']);
  50      $cur->comment_site = html::clean($_POST['comment_site']);
  51      $cur->comment_content = $core->HTMLfilter($_POST['comment_content']);
  52      $cur->post_id = (integer) $_POST['post_id'];
  53      
  54      try {
  55          $core->blog->addComment($cur);
  56          http::redirect('post.php?id='.$_POST['post_id']);
  57      } catch (Exception $e) {
  58          $core->error->add($e->getMessage());
  59      }
  60  }
  61  
  62  if (!empty($_REQUEST['id']))
  63  {
  64      $params['comment_id'] = $_REQUEST['id'];
  65      
  66      try {
  67          $rs = $core->blog->getComments($params);
  68          if (!$rs->isEmpty()) {
  69              $comment_id = $rs->comment_id;
  70              $post_id = $rs->post_id;
  71              $comment_dt = $rs->comment_dt;
  72              $comment_author = $rs->comment_author;
  73              $comment_email = $rs->comment_email;
  74              $comment_site = $rs->comment_site;
  75              $comment_content = $rs->comment_content;
  76              $comment_ip = $rs->comment_ip;
  77              $comment_status = $rs->comment_status;
  78              $comment_trackback = (boolean) $rs->comment_trackback;
  79              $comment_spam_status = $rs->comment_spam_status;
  80          }
  81      } catch (Exception $e) {
  82          $core->error->add($e->getMessage());
  83      }
  84  }
  85  
  86  if (!$comment_id && !$core->error->flag()) {
  87      $core->error->add(__('No comment'));
  88  }
  89  
  90  if (!$core->error->flag() && isset($rs))
  91  {
  92      $can_edit = $can_delete = $can_publish = $core->auth->check('contentadmin',$core->blog->id);
  93      
  94      if (!$core->auth->check('contentadmin',$core->blog->id) && $core->auth->userID() == $rs->user_id) {
  95          $can_edit = true;
  96          if ($core->auth->check('delete',$core->blog->id)) {
  97              $can_delete = true;
  98          }
  99          if ($core->auth->check('publish',$core->blog->id)) {
 100              $can_publish = true;
 101          }
 102      }
 103      
 104      # update comment
 105      if (!empty($_POST['update']))
 106      {
 107          $cur = $core->con->openCursor($core->prefix.'comment');
 108          
 109          $cur->comment_author = $_POST['comment_author'];
 110          $cur->comment_email = html::clean($_POST['comment_email']);
 111          $cur->comment_site = html::clean($_POST['comment_site']);
 112          $cur->comment_content = $core->HTMLfilter($_POST['comment_content']);
 113          
 114          if (isset($_POST['comment_status'])) {
 115              $cur->comment_status = (integer) $_POST['comment_status'];
 116          }
 117          
 118          try {
 119              $core->blog->updComment($comment_id,$cur);
 120              http::redirect('comment.php?id='.$comment_id.'&upd=1');
 121          } catch (Exception $e) {
 122              $core->error->add($e->getMessage());
 123          }
 124      }
 125      
 126      if (!empty($_POST['delete'])) {
 127          $_POST['action'] = 'delete';
 128      }
 129      
 130      if (!empty($_POST['action']) && $can_edit)
 131      {
 132          switch ($_POST['action']) {
 133              case 'delete':
 134                  try {
 135                      $core->blog->delComment($rs->comment_id);
 136                      http::redirect('post.php?id='.$rs->post_id);
 137                  } catch (Exception $e) {
 138                      $core->error->add($e->getMessage());
 139                  }
 140                  break;
 141              case 'junk':
 142                  try {
 143                      $cur = $core->con->openCursor($core->prefix.'comment');
 144                      $cur->comment_status = -2;
 145                      $core->blog->updComment($rs->comment_id,$cur);
 146                      http::redirect('post.php?co=1&id='.$rs->post_id.'#c'.$rs->comment_id);
 147                  } catch (Exception $e) {
 148                      $core->error->add($e->getMessage());
 149                  }
 150                  break;
 151              case 'status':
 152                  try {
 153                      $cur = $core->con->openCursor($core->prefix.'comment');
 154                      $cur->comment_status = $rs->comment_status == 1 ? -1 : 1;
 155                      $core->blog->updComment($rs->comment_id,$cur);
 156                      http::redirect('post.php?co=1&id='.$rs->post_id.'#c'.$rs->comment_id);
 157                  } catch (Exception $e) {
 158                      $core->error->add($e->getMessage());
 159                  }
 160                  break;
 161          }
 162      }
 163      
 164      if (!$can_edit) {
 165          $core->error->add(__("You can't edit this comment."));
 166      }
 167  }
 168  
 169  /* DISPLAY
 170  -------------------------------------------------------- */
 171  dcPage::open(__('Edit comment'),
 172      dcPage::jsConfirmClose('comment-form').
 173      dcPage::jsToolBar().
 174      dcPage::jsLoad('js/_comment.js')
 175  );
 176  
 177  if ($comment_id)
 178  {
 179      echo '<h2>'.__('Edit comment').'</h2>';
 180      
 181      echo '<p><a href="post.php?co=1&amp;id='.$post_id.'#c'.$comment_id.'">'.
 182          __('Back to entry').'</a></p>';
 183      
 184      echo
 185      '<form action="comment.php" method="post" id="comment-form">'.
 186      '<p><label>'.__('IP address:').'</label> '.
 187      '<a href="comments.php?ip='.$comment_ip.'">'.$comment_ip.'</a></p>'.
 188      
 189      '<p><label>'.__('Date:').'</label> '.
 190      dt::dt2str(__('%Y-%m-%d %H:%M'),$comment_dt).'</p>'.
 191      
 192      '<p><label class="required" title="'.__('Required field').'">'.__('Author:').
 193      dcPage::help('comments','c_author').
 194      form::field('comment_author',30,255,html::escapeHTML($comment_author)).
 195      '</label></p>'.
 196      
 197      '<p><label>'.__('Email:').dcPage::help('comments','c_email').
 198      form::field('comment_email',30,255,html::escapeHTML($comment_email)).
 199      '</label></p>'.
 200      
 201      '<p><label>'.__('Web site:').dcPage::help('comments','c_site').
 202      form::field('comment_site',30,255,html::escapeHTML($comment_site)).
 203      '</label></p>'.
 204      
 205      '<p><label>'.__('Status:').dcPage::help('comments','c_status').
 206      form::combo('comment_status',$status_combo,$comment_status,'','',!$can_publish).
 207      '</label></p>'.
 208      
 209      # --BEHAVIOR-- adminAfterCommentDesc
 210      $core->callBehavior('adminAfterCommentDesc', $rs).
 211      
 212      '<p class="area"><label for="comment_content">'.__('Comment:').
 213      dcPage::help('comments','c_comment').'</label> '.
 214      form::textarea('comment_content',50,10,html::escapeHTML($comment_content)).
 215      '</p>'.
 216      
 217      '<p>'.form::hidden('id',$comment_id).
 218      '<input type="submit" accesskey="s" name="update" value="'.__('save').'" /> ';
 219      
 220      if ($can_delete) {
 221          echo '<input type="submit" name="delete" value="'.__('delete').'" />';
 222      }
 223      echo
 224      '</p>'.
 225      '</form>';
 226  }
 227  
 228  dcPage::close();
 229  ?>


Généré le : Fri Feb 23 22:16:06 2007 par Balluche grâce à PHPXref 0.7