[ Index ]
 

Code source de XOOPS 2.0.17.1

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

/htdocs/include/ -> comment_delete.php (source)

   1  <?php
   2  // $Id: comment_delete.php 2 2005-11-02 18:23:29Z skalpa $

   3  //  ------------------------------------------------------------------------ //

   4  //                XOOPS - PHP Content Management System                      //

   5  //                    Copyright (c) 2000 XOOPS.org                           //

   6  //                       <http://www.xoops.org/>                             //

   7  //  ------------------------------------------------------------------------ //

   8  //  This program is free software; you can redistribute it and/or modify     //

   9  //  it under the terms of the GNU General Public License as published by     //

  10  //  the Free Software Foundation; either version 2 of the License, or        //

  11  //  (at your option) any later version.                                      //

  12  //                                                                           //

  13  //  You may not change or alter any portion of this comment or credits       //

  14  //  of supporting developers from this source code or any supporting         //

  15  //  source code which is considered copyrighted (c) material of the          //

  16  //  original comment or credit authors.                                      //

  17  //                                                                           //

  18  //  This program is distributed in the hope that it will be useful,          //

  19  //  but WITHOUT ANY WARRANTY; without even the implied warranty of           //

  20  //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //

  21  //  GNU General Public License for more details.                             //

  22  //                                                                           //

  23  //  You should have received a copy of the GNU General Public License        //

  24  //  along with this program; if not, write to the Free Software              //

  25  //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //

  26  //  ------------------------------------------------------------------------ //

  27  // Author: Kazumi Ono (AKA onokazu)                                          //

  28  // URL: http://www.xoops.org/ http://jp.xoops.org/  http://www.myweb.ne.jp/  //

  29  // Project: The XOOPS Project (http://www.xoops.org/)                        //

  30  // ------------------------------------------------------------------------- //

  31  
  32  if (!defined('XOOPS_ROOT_PATH') || !is_object($xoopsModule)) {
  33      exit();
  34  }
  35  include_once  XOOPS_ROOT_PATH.'/include/comment_constants.php';
  36  $op = 'delete';
  37  if (!empty($_POST)) {
  38      extract($_POST);
  39      $com_mode = isset($com_mode) ? htmlspecialchars(trim($com_mode), ENT_QUOTES) : 'flat';
  40      $com_order = isset($com_order) ? intval($com_order) : XOOPS_COMMENT_OLD1ST;
  41      $com_id = isset($com_id) ? intval($com_id) : 0;
  42  } else {
  43      $com_mode = isset($_GET['com_mode']) ? htmlspecialchars(trim($_GET['com_mode']), ENT_QUOTES) : 'flat';
  44      $com_order = isset($_GET['com_order']) ? intval($_GET['com_order']) : XOOPS_COMMENT_OLD1ST;
  45      $com_id = isset($_GET['com_id']) ? intval($_GET['com_id']) : 0;
  46  
  47  }
  48  
  49  if ('system' == $xoopsModule->getVar('dirname')) {
  50      $comment_handler =& xoops_gethandler('comment');
  51      $comment =& $comment_handler->get($com_id);
  52      $module_handler =& xoops_gethandler('module');
  53      $module =& $module_handler->get($comment->getVar('com_modid'));
  54      $comment_config = $module->getInfo('comments');
  55      $com_modid = $module->getVar('mid');
  56      $redirect_page = XOOPS_URL.'/modules/system/admin.php?fct=comments&amp;com_modid='.$com_modid.'&amp;com_itemid';
  57      $moddir = $module->getVar('dirname');
  58      unset($comment);
  59  } else {
  60      if (XOOPS_COMMENT_APPROVENONE == $xoopsModuleConfig['com_rule']) {
  61          exit();
  62      }
  63      $comment_config = $xoopsModule->getInfo('comments');
  64      $com_modid = $xoopsModule->getVar('mid');
  65      $redirect_page = $comment_config['pageName'].'?';
  66      $comment_confirm_extra = array();
  67      if (isset($comment_config['extraParams']) && is_array($comment_config['extraParams'])) {
  68          foreach ($comment_config['extraParams'] as $extra_param) {
  69              if (isset(${$extra_param})) {
  70                  $redirect_page .= $extra_param.'='.${$extra_param}.'&amp;';
  71                  
  72                  // for the confirmation page

  73                  $comment_confirm_extra [$extra_param] = ${$extra_param};
  74              } elseif (isset($_GET[$extra_param])) {
  75                  $redirect_page .= $extra_param.'='.$_GET[$extra_param].'&amp;';
  76                  
  77                  // for the confirmation page

  78                  $comment_confirm_extra [$extra_param] = $_GET[$extra_param];
  79              }
  80          }
  81      }
  82      $redirect_page .= $comment_config['itemName'];
  83      $moddir = $xoopsModule->getVar('dirname');
  84  }
  85  
  86  $accesserror = false;
  87  if (!is_object($xoopsUser)) {
  88      $accesserror = true;
  89  } else {
  90      if (!$xoopsUser->isAdmin($com_modid)) {
  91              $sysperm_handler =& xoops_gethandler('groupperm');
  92              if (!$sysperm_handler->checkRight('system_admin', XOOPS_SYSTEM_COMMENT, $xoopsUser->getGroups())) {
  93                  $accesserror = true;
  94              }
  95      }
  96  }
  97  
  98  if (false != $accesserror) {
  99      $ref = xoops_getenv('HTTP_REFERER');
 100      if ($ref != '') {
 101          redirect_header($ref, 2, _NOPERM);
 102      } else {
 103          redirect_header($redirect_page.'?'.$comment_config['itemName'].'='.intval($com_itemid), 2, _NOPERM);
 104      }
 105      exit();
 106  }
 107  
 108  include_once XOOPS_ROOT_PATH.'/language/'.$xoopsConfig['language'].'/comment.php';
 109  
 110  switch ($op) {
 111  case 'delete_one':
 112      $comment_handler = xoops_gethandler('comment');
 113      $comment =& $comment_handler->get($com_id);
 114      if (!$comment_handler->delete($comment)) {
 115          include  XOOPS_ROOT_PATH.'/header.php';
 116          xoops_error(_CM_COMDELETENG.' (ID: '.$comment->getVar('com_id').')');
 117          include  XOOPS_ROOT_PATH.'/footer.php';
 118          exit();
 119      }
 120  
 121      $com_itemid = $comment->getVar('com_itemid');
 122  
 123      // execute updateStat callback function if set

 124      if (isset($comment_config['callback']['update']) && trim($comment_config['callback']['update']) != '') {
 125          $skip = false;
 126          if (!function_exists($comment_config['callback']['update'])) {
 127              if (isset($comment_config['callbackFile'])) {
 128                  $callbackfile = trim($comment_config['callbackFile']);
 129                  if ($callbackfile != '' && file_exists(XOOPS_ROOT_PATH.'/modules/'.$moddir.'/'.$callbackfile)) {
 130                      include_once XOOPS_ROOT_PATH.'/modules/'.$moddir.'/'.$callbackfile;
 131                  }
 132                  if (!function_exists($comment_config['callback']['update'])) {
 133                      $skip = true;
 134                  }
 135              } else {
 136                  $skip = true;
 137              }
 138          }
 139          if (!$skip) {
 140              $criteria = new CriteriaCompo(new Criteria('com_modid', $com_modid));
 141              $criteria->add(new Criteria('com_itemid', $com_itemid));
 142              $criteria->add(new Criteria('com_status', XOOPS_COMMENT_ACTIVE));
 143              $comment_count = $comment_handler->getCount($criteria);
 144              $comment_config['callback']['update']($com_itemid, $comment_count);
 145          }
 146      }
 147  
 148      // update user posts if its not an anonymous post

 149      if ($comment->getVar('com_uid') != 0) {
 150          $member_handler =& xoops_gethandler('member');
 151          $com_poster =& $member_handler->getUser($comment->getVar('com_uid'));
 152          if (is_object($com_poster)) {
 153              $member_handler->updateUserByField($com_poster, 'posts', $com_poster->getVar('posts') - 1);
 154          }
 155      }
 156  
 157      // get all comments posted later within the same thread

 158      $thread_comments =& $comment_handler->getThread($comment->getVar('com_rootid'), $com_id);
 159      
 160      include_once XOOPS_ROOT_PATH.'/class/tree.php';
 161      $xot = new XoopsObjectTree($thread_comments, 'com_id', 'com_pid', 'com_rootid');
 162  
 163      $child_comments =& $xot->getFirstChild($com_id);
 164  
 165      // now set new parent ID for direct child comments

 166      $new_pid = $comment->getVar('com_pid');
 167      $errs = array();
 168      foreach (array_keys($child_comments) as $i) {
 169          $child_comments[$i]->setVar('com_pid', $new_pid);
 170          // if the deleted comment is a root comment, need to change root id to own id

 171          if (false != $comment->isRoot()) {
 172              $new_rootid = $child_comments[$i]->getVar('com_id');
 173              $child_comments[$i]->setVar('com_rootid', $child_comments[$i]->getVar('com_id'));
 174              if (!$comment_handler->insert($child_comments[$i])) {
 175                  $errs[] = 'Could not change comment parent ID from <b>'.$com_id.'</b> to <b>'.$new_pid.'</b>. (ID: '.$new_rootid.')';
 176              } else {
 177                  // need to change root id for all its child comments as well

 178                  $c_child_comments =& $xot->getAllChild($new_rootid);
 179                  $cc_count = count($c_child_comments);
 180                  foreach (array_keys($c_child_comments) as $j) {
 181                      $c_child_comments[$j]->setVar('com_rootid', $new_rootid);
 182                      if (!$comment_handler->insert($c_child_comments[$j])) {
 183                          $errs[] = 'Could not change comment root ID from <b>'.$com_id.'</b> to <b>'.$new_rootid.'</b>.';
 184                      }
 185                  }
 186              }
 187          } else {
 188              if (!$comment_handler->insert($child_comments[$i])) {
 189                  $errs[] = 'Could not change comment parent ID from <b>'.$com_id.'</b> to <b>'.$new_pid.'</b>.';
 190              }
 191          }
 192      }
 193      if (count($errs) > 0) {
 194          include  XOOPS_ROOT_PATH.'/header.php';
 195          xoops_error($errs);
 196          include  XOOPS_ROOT_PATH.'/footer.php';
 197          exit();
 198      }
 199      redirect_header($redirect_page.'='.$com_itemid.'&amp;com_order='.$com_order.'&amp;com_mode='.$com_mode, 1, _CM_COMDELETED);
 200      break;
 201  
 202  case 'delete_all':
 203      $comment_handler = xoops_gethandler('comment');
 204      $comment =& $comment_handler->get($com_id);
 205      $com_rootid = $comment->getVar('com_rootid');
 206  
 207      // get all comments posted later within the same thread

 208      $thread_comments =& $comment_handler->getThread($com_rootid, $com_id);
 209  
 210      // construct a comment tree

 211      include_once XOOPS_ROOT_PATH.'/class/tree.php';
 212      $xot = new XoopsObjectTree($thread_comments, 'com_id', 'com_pid', 'com_rootid');
 213      $child_comments =& $xot->getAllChild($com_id);
 214      // add itself here

 215      $child_comments[$com_id] =& $comment;
 216      $msgs = array();
 217      $deleted_num = array();
 218      $member_handler =& xoops_gethandler('member');
 219      foreach (array_keys($child_comments) as $i) {
 220          if (!$comment_handler->delete($child_comments[$i])) {
 221              $msgs[] = _CM_COMDELETENG.' (ID: '.$child_comments[$i]->getVar('com_id').')';
 222          } else {
 223              $msgs[] = _CM_COMDELETED.' (ID: '.$child_comments[$i]->getVar('com_id').')';
 224              // store poster ID and deleted post number into array for later use

 225              $poster_id = $child_comments[$i]->getVar('com_uid');
 226              if ($poster_id > 0) {
 227                  $deleted_num[$poster_id] = !isset($deleted_num[$poster_id]) ? 1 : ($deleted_num[$poster_id] + 1);
 228              }
 229          }
 230      }
 231      foreach ($deleted_num as $user_id => $post_num) {
 232          // update user posts

 233          $com_poster = $member_handler->getUser($user_id);
 234          if (is_object($com_poster)) {
 235              $member_handler->updateUserByField($com_poster, 'posts', $com_poster->getVar('posts') - $post_num);
 236          }
 237      }
 238  
 239      $com_itemid = $comment->getVar('com_itemid');
 240  
 241      // execute updateStat callback function if set

 242      if (isset($comment_config['callback']['update']) && trim($comment_config['callback']['update']) != '') {
 243          $skip = false;
 244          if (!function_exists($comment_config['callback']['update'])) {
 245              if (isset($comment_config['callbackFile'])) {
 246                  $callbackfile = trim($comment_config['callbackFile']);
 247                  if ($callbackfile != '' && file_exists(XOOPS_ROOT_PATH.'/modules/'.$moddir.'/'.$callbackfile)) {
 248                      include_once XOOPS_ROOT_PATH.'/modules/'.$moddir.'/'.$callbackfile;
 249                  }
 250                  if (!function_exists($comment_config['callback']['update'])) {
 251                      $skip = true;
 252                  }
 253              } else {
 254                  $skip = true;
 255              }
 256          }
 257          if (!$skip) {
 258              $criteria = new CriteriaCompo(new Criteria('com_modid', $com_modid));
 259              $criteria->add(new Criteria('com_itemid', $com_itemid));
 260              $criteria->add(new Criteria('com_status', XOOPS_COMMENT_ACTIVE));
 261              $comment_count = $comment_handler->getCount($criteria);
 262              $comment_config['callback']['update']($com_itemid, $comment_count);
 263          }
 264      }
 265  
 266      include  XOOPS_ROOT_PATH.'/header.php';
 267      xoops_result($msgs);
 268      echo '<br /><a href="'.$redirect_page.'='.$com_itemid.'&amp;com_order='.$com_order.'&amp;com_mode='.$com_mode.'">'._BACK.'</a>';
 269      include  XOOPS_ROOT_PATH.'/footer.php';
 270      break;
 271  
 272  case 'delete':
 273  default:
 274      include  XOOPS_ROOT_PATH.'/header.php';
 275      $comment_confirm = array('com_id' => $com_id, 'com_mode' => $com_mode, 'com_order' => $com_order, 'op' => array(_CM_DELETEONE => 'delete_one', _CM_DELETEALL => 'delete_all'));
 276      if (!empty($comment_confirm_extra) && is_array($comment_confirm_extra)) {
 277          $comment_confirm = $comment_confirm + $comment_confirm_extra;
 278      }
 279      xoops_confirm($comment_confirm, 'comment_delete.php', _CM_DELETESELECT);
 280      include  XOOPS_ROOT_PATH.'/footer.php';
 281      break;
 282  }
 283  ?>


Généré le : Sun Nov 25 11:44:32 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics