[ Index ]
 

Code source de XOOPS 2.0.17.1

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

/htdocs/class/ -> xoopscomments.php (source)

   1  <?php
   2  // $Id: xoopscomments.php 506 2006-05-26 23:10:37Z 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.myweb.ne.jp/, http://www.xoops.org/, http://jp.xoops.org/ //

  29  // Project: The XOOPS Project                                                //

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

  31  if (!defined('XOOPS_ROOT_PATH')) {
  32      exit();
  33  }
  34  include_once XOOPS_ROOT_PATH."/class/xoopstree.php";
  35  require_once XOOPS_ROOT_PATH.'/class/xoopsobject.php';
  36  include_once XOOPS_ROOT_PATH.'/language/'.$GLOBALS['xoopsConfig']['language'].'/comment.php';
  37  
  38  class XoopsComments extends XoopsObject
  39  {
  40      var $ctable;
  41      var $db;
  42  
  43  	function XoopsComments($ctable, $id=null)
  44      {
  45          $this->ctable = $ctable;
  46          $this->db =& Database::getInstance();
  47          $this->XoopsObject();
  48          $this->initVar('comment_id', XOBJ_DTYPE_INT, null, false);
  49          $this->initVar('item_id', XOBJ_DTYPE_INT, null, false);
  50          $this->initVar('order', XOBJ_DTYPE_INT, null, false);
  51          $this->initVar('mode', XOBJ_DTYPE_OTHER, null, false);
  52          $this->initVar('subject', XOBJ_DTYPE_TXTBOX, null, false, 255);
  53          $this->initVar('comment', XOBJ_DTYPE_TXTAREA, null, false, null);
  54          $this->initVar('ip', XOBJ_DTYPE_OTHER, null, false);
  55          $this->initVar('pid', XOBJ_DTYPE_INT, 0, false);
  56          $this->initVar('date', XOBJ_DTYPE_INT, null, false);
  57          $this->initVar('nohtml', XOBJ_DTYPE_INT, 1, false);
  58          $this->initVar('nosmiley', XOBJ_DTYPE_INT, 0, false);
  59          $this->initVar('noxcode', XOBJ_DTYPE_INT, 0, false);
  60          $this->initVar('user_id', XOBJ_DTYPE_INT, null, false);
  61          $this->initVar('icon', XOBJ_DTYPE_OTHER, null, false);
  62          $this->initVar('prefix', XOBJ_DTYPE_OTHER, null, false);
  63          if ( !empty($id) ) {
  64              if ( is_array($id) ) {
  65                  $this->assignVars($id);
  66              } else {
  67                  $this->load(intval($id));
  68              }
  69          }
  70      }
  71  
  72  	function load($id)
  73      {
  74          $sql = "SELECT * FROM ".$this->ctable." WHERE comment_id=".$id."";
  75          $arr = $this->db->fetchArray($this->db->query($sql));
  76          $this->assignVars($arr);
  77      }
  78  
  79  	function store()
  80      {
  81          if ( !$this->cleanVars() ) {
  82              return false;
  83          }
  84          foreach ( $this->cleanVars as $k=>$v ) {
  85              $$k = $v;
  86          }
  87          $isnew = false;
  88          if ( empty($comment_id ) ) {
  89              $isnew = true;
  90              $comment_id = $this->db->genId($this->ctable."_comment_id_seq");
  91              $sql = sprintf("INSERT INTO %s (comment_id, pid, item_id, date, user_id, ip, subject, comment, nohtml, nosmiley, noxcode, icon) VALUES (%u, %u, %u, %u, %u, '%s', '%s', '%s', %u, %u, %u, '%s')", $this->ctable, $comment_id, $pid, $item_id, time(), $user_id, $ip, $subject, $comment, $nohtml, $nosmiley, $noxcode, $icon);
  92          } else {
  93              $sql = sprintf("UPDATE %s SET subject = '%s', comment = '%s', nohtml = %u, nosmiley = %u, noxcode = %u, icon = '%s'  WHERE comment_id = %u", $this->ctable, $subject, $comment, $nohtml, $nosmiley, $noxcode, $icon, $comment_id);
  94          }
  95          if ( !$result = $this->db->query($sql) ) {
  96              //echo $sql;

  97              return false;
  98          }
  99          if ( empty($comment_id) ) {
 100              $comment_id = $this->db->getInsertId();
 101          }
 102          if ( $isnew != false ) {
 103              $sql = sprintf("UPDATE %s SET posts = posts+1 WHERE uid = %u", $this->db->prefix("users"), $user_id);
 104              if (!$result = $this->db->query($sql)) {
 105                  echo "Could not update user posts.";
 106              }
 107          }
 108          return $comment_id;
 109      }
 110  
 111  	function delete()
 112      {
 113          $sql = sprintf("DELETE FROM %s WHERE comment_id = %u", $this->ctable, $this->getVar('comment_id'));
 114          if ( !$result = $this->db->query($sql) ) {
 115              return false;
 116          }
 117          $sql = sprintf("UPDATE %s SET posts = posts-1 WHERE uid = %u", $this->db->prefix("users"), $this->getVar("user_id"));
 118          if ( !$result = $this->db->query($sql) ) {
 119              echo "Could not update user posts.";
 120          }
 121          $mytree = new XoopsTree($this->ctable, "comment_id", "pid");
 122          $arr = $mytree->getAllChild($this->getVar("comment_id"), "comment_id");
 123          $size = count($arr);
 124          if ( $size > 0 ) {
 125              for ( $i = 0; $i < $size; $i++ ) {
 126                  $sql = sprintf("DELETE FROM %s WHERE comment_bid = %u", $this->ctable, $arr[$i]['comment_id']);
 127                  if ( !$result = $this->db->query($sql) ) {
 128                      echo "Could not delete comment.";
 129                  }
 130                  $sql = sprintf("UPDATE %s SET posts = posts-1 WHERE uid = %u", $this->db->prefix("users"), $arr[$i]['user_id']);
 131                  if ( !$result = $this->db->query($sql) ) {
 132                      echo "Could not update user posts.";
 133                  }
 134              }
 135          }
 136          return ($size + 1);
 137      }
 138  
 139  	function getCommentTree()
 140      {
 141          $mytree = new XoopsTree($this->ctable, "comment_id", "pid");
 142          $ret = array();
 143          $tarray = $mytree->getChildTreeArray($this->getVar("comment_id"), "comment_id");
 144          foreach ( $tarray as $ele ) {
 145              $ret[] = new XoopsComments($this->ctable,$ele);
 146          }
 147          return $ret;
 148      }
 149  
 150  	function getAllComments($criteria=array(), $asobject=true, $orderby="comment_id ASC", $limit=0, $start=0)
 151      {
 152          $ret = array();
 153          $where_query = "";
 154          if ( is_array($criteria) && count($criteria) > 0 ) {
 155              $where_query = " WHERE";
 156              foreach ( $criteria as $c ) {
 157                  $where_query .= " $c AND";
 158              }
 159              $where_query = substr($where_query, 0, -4);
 160          }
 161          if ( !$asobject ) {
 162              $sql = "SELECT comment_id FROM ".$this->ctable."$where_query ORDER BY $orderby";
 163              $result = $this->db->query($sql,$limit,$start);
 164              while ( $myrow = $this->db->fetchArray($result) ) {
 165                  $ret[] = $myrow['comment_id'];
 166              }
 167          } else {
 168              $sql = "SELECT * FROM ".$this->ctable."".$where_query." ORDER BY $orderby";
 169              $result = $this->db->query($sql,$limit,$start);
 170              while ( $myrow = $this->db->fetchArray($result) ) {
 171                  $ret[] = new XoopsComments($this->ctable,$myrow);
 172              }
 173          }
 174          //echo $sql;

 175          return $ret;
 176      }
 177  
 178      /* Methods below will be moved to maybe another class? */

 179  	function printNavBar($item_id, $mode="flat", $order=1)
 180      {
 181          global $xoopsConfig, $xoopsUser;
 182          echo "<form method='get' action='".$_SERVER['PHP_SELF']."'><table width='100%' border='0' cellspacing='1' cellpadding='2'><tr><td class='bg1' align='center'><select name='mode'><option value='nocomments'";
 183          if ( $mode == "nocomments" ) {
 184              echo " selected='selected'";
 185          }
 186          echo ">". _NOCOMMENTS ."</option><option value='flat'";
 187          if ($mode == 'flat') {
 188              echo " selected='selected'";
 189          }
 190          echo ">". _FLAT ."</option><option value='thread'";
 191          if ( $mode == "thread" || $mode == "" ) {
 192              echo " selected='selected'";
 193          }
 194          echo ">". _THREADED ."</option></select><select name='order'><option value='0'";
 195          if ( $order != 1 ) {
 196              echo " selected='selected'";
 197          }
 198          echo ">". _OLDESTFIRST ."</option><option value='1'";
 199          if ( $order == 1 ) {
 200              echo " selected='selected'";
 201          }
 202          echo ">". _NEWESTFIRST ."</option></select><input type='hidden' name='item_id' value='".intval($item_id)."' /><input type='submit' value='". _CM_REFRESH ."' />";
 203          if ( $xoopsConfig['anonpost'] == 1 || $xoopsUser ) {
 204              if ($mode != "flat" || $mode != "nocomments" || $mode != "thread" ) {
 205                  $mode = "flat";
 206              }
 207              echo "&nbsp;<input type='button' onclick='location=\"newcomment.php?item_id=".intval($item_id)."&amp;order=".intval($order)."&amp;mode=".$mode."\"' value='"._CM_POSTCOMMENT."' />";
 208          }
 209          echo "</td></tr></table></form>";
 210      }
 211  
 212  	function showThreadHead()
 213      {
 214          openThread();
 215      }
 216  
 217  	function showThreadPost($order, $mode, $adminview=0, $color_num=1)
 218      {
 219          global $xoopsConfig, $xoopsUser;
 220          $edit_image = "";
 221          $reply_image = "";
 222          $delete_image = "";
 223          $post_date = formatTimestamp($this->getVar("date"),"m");
 224          if ( $this->getVar("user_id") != 0 ) {
 225              $poster = new XoopsUser($this->getVar("user_id"));
 226              if ( !$poster->isActive() ) {
 227                  $poster = 0;
 228              }
 229          } else {
 230              $poster = 0;
 231          }
 232          if ( $this->getVar("icon") != null && $this->getVar("icon") != "" ) {
 233              $subject_image = "<a name='".$this->getVar("comment_id")."' id='".$this->getVar("comment_id")."'></a><img src='".XOOPS_URL."/images/subject/".$this->getVar("icon")."' alt='' />";
 234          } else {
 235              $subject_image =  "<a name='".$this->getVar("comment_id")."' id='".$this->getVar("comment_id")."'></a><img src='".XOOPS_URL."/images/icons/no_posticon.gif' alt='' />";
 236          }
 237          if ( $adminview ) {
 238              $ip_image = "<img src='".XOOPS_URL."/images/icons/ip.gif' alt='".$this->getVar("ip")."' />";
 239          } else {
 240              $ip_image = "<img src='".XOOPS_URL."/images/icons/ip.gif' alt='' />";
 241          }
 242          if ( $adminview || ($xoopsUser && $this->getVar("user_id") == $xoopsUser->getVar("uid")) ) {
 243              $edit_image = "<a href='editcomment.php?comment_id=".$this->getVar("comment_id")."&amp;mode=".$mode."&amp;order=".intval($order)."'><img src='".XOOPS_URL."/images/icons/edit.gif' alt='"._EDIT."' /></a>";
 244          }
 245          if ( $xoopsConfig['anonpost'] || $xoopsUser ) {
 246              $reply_image = "<a href='replycomment.php?comment_id=".$this->getVar("comment_id")."&amp;mode=".$mode."&amp;order=".intval($order)."'><img src='".XOOPS_URL."/images/icons/reply.gif' alt='"._REPLY."' /></a>";
 247          }
 248          if ( $adminview ) {
 249              $delete_image = "<a href='deletecomment.php?comment_id=".$this->getVar("comment_id")."&amp;mode=".$mode."&amp;order=".intval($order)."'><img src='".XOOPS_URL."/images/icons/delete.gif' alt='"._DELETE."' /></a>";
 250          }
 251  
 252          if ( $poster ) {
 253              $text = $this->getVar("comment");
 254              if ( $poster->getVar("attachsig") ) {
 255                  $text .= "<p><br />_________________<br />". $poster->user_sig()."</p>";
 256              }
 257              $reg_date = _CM_JOINED;
 258              $reg_date .= formatTimestamp($poster->getVar("user_regdate"),"s");
 259              $posts = _CM_POSTS;
 260              $posts .= $poster->getVar("posts");
 261              $user_from = _CM_FROM;
 262              $user_from .= $poster->getVar("user_from");
 263              $rank = $poster->rank();
 264              if ( $rank['image'] != "" ) {
 265                  $rank['image'] = "<img src='".XOOPS_UPLOAD_URL."/".$rank['image']."' alt='' />";
 266              }
 267              $avatar_image = "<img src='".XOOPS_UPLOAD_URL."/".$poster->getVar("user_avatar")."' alt='' />";
 268              if ( $poster->isOnline() ) {
 269                  $online_image = "<span style='color:#ee0000;font-weight:bold;'>"._ONLINE."</span>";
 270              } else {
 271                  $online_image = "";
 272              }
 273              $profile_image = "<a href='".XOOPS_URL."/userinfo.php?uid=".$poster->getVar("uid")."'><img src='".XOOPS_URL."/images/icons/profile.gif' alt='"._PROFILE."' /></a>";
 274              if ( $xoopsUser ) {
 275                  $pm_image =  "<a href='javascript:openWithSelfMain(\"".XOOPS_URL."/pmlite.php?send2=1&amp;to_userid=".$poster->getVar("uid")."\",\"pmlite\",450,370);'><img src='".XOOPS_URL."/images/icons/pm.gif' alt='".sprintf(_SENDPMTO,$poster->getVar("uname", "E"))."' /></a>";
 276              } else {
 277                  $pm_image = "";
 278              }
 279                 if ( $poster->getVar("user_viewemail") ) {
 280                  $email_image = "<a href='mailto:".$poster->getVar("email", "E")."'><img src='".XOOPS_URL."/images/icons/email.gif' alt='".sprintf(_SENDEMAILTO,$poster->getVar("uname", "E"))."' /></a>";
 281              } else {
 282                  $email_image = "";
 283              }
 284              $posterurl = $poster->getVar("url");
 285                 if ( $posterurl != "" ) {
 286                  $www_image = "<a href='$posterurl' target='_blank'><img src='".XOOPS_URL."/images/icons/www.gif' alt='"._VISITWEBSITE."' /></a>";
 287              } else {
 288                  $www_image = "";
 289              }
 290                 if ( $poster->getVar("user_icq") != "" ) {
 291                  $icq_image = "<a href='http://wwp.icq.com/scripts/search.dll?to=".$poster->getVar("user_icq", "E")."'><img src='".XOOPS_URL."/images/icons/icq_add.gif' alt='"._ADD."' /></a>";
 292              } else {
 293                  $icq_image = "";
 294              }
 295              if ( $poster->getVar("user_aim") != "" ) {
 296                  $aim_image = "<a href='aim:goim?screenname=".$poster->getVar("user_aim", "E")."&message=Hi+".$poster->getVar("user_aim")."+Are+you+there?'><img src='".XOOPS_URL."/images/icons/aim.gif' alt='aim' /></a>";
 297              } else {
 298                  $aim_image = "";
 299              }
 300                 if ( $poster->getVar("user_yim") != "" ) {
 301                  $yim_image = "<a href='http://edit.yahoo.com/config/send_webmesg?.target=".$poster->getVar("user_yim", "E")."&.src=pg'><img src='".XOOPS_URL."/images/icons/yim.gif' alt='yim' /></a>";
 302              } else {
 303                  $yim_image = "";
 304              }
 305              if ( $poster->getVar("user_msnm") != "" ) {
 306                  $msnm_image = "<a href='".XOOPS_URL."/userinfo.php?uid=".$poster->getVar("uid")."'><img src='".XOOPS_URL."/images/icons/msnm.gif' alt='msnm' /></a>";
 307              } else {
 308                  $msnm_image = "";
 309              }
 310              showThread($color_num, $subject_image, $this->getVar("subject"), $text, $post_date, $ip_image, $reply_image, $edit_image, $delete_image, $poster->getVar("uname"), $rank['title'], $rank['image'], $avatar_image, $reg_date, $posts, $user_from, $online_image, $profile_image, $pm_image, $email_image, $www_image, $icq_image, $aim_image, $yim_image, $msnm_image);
 311          } else {
 312              showThread($color_num, $subject_image, $this->getVar("subject"), $this->getVar("comment"), $post_date, $ip_image, $reply_image, $edit_image, $delete_image, $xoopsConfig['anonymous']);
 313          }
 314      }
 315  
 316  	function showThreadFoot()
 317      {
 318          closeThread();
 319      }
 320  
 321  	function showTreeHead($width="100%")
 322      {
 323          echo "<table border='0' class='outer' cellpadding='0' cellspacing='0' align='center' width='$width'><tr class='bg3' align='center'><td colspan='3'>". _CM_REPLIES ."</td></tr><tr class='bg3' align='left'><td width='60%' class='fg2'>". _CM_TITLE ."</td><td width='20%' class='fg2'>". _CM_POSTER ."</td><td class='fg2'>". _CM_POSTED ."</td></tr>";
 324      }
 325  
 326  	function showTreeItem($order, $mode, $color_num)
 327      {
 328          if ( $color_num == 1 ) {
 329              $bg = 'even';
 330          } else {
 331              $bg = 'odd';
 332          }
 333          $prefix = str_replace(".", "&nbsp;&nbsp;&nbsp;&nbsp;", $this->getVar("prefix"));
 334          $date = formatTimestamp($this->getVar("date"),"m");
 335          if ( $this->getVar("icon") != "" ) {
 336              $icon = "subject/".$this->getVar("icon", "E");
 337          } else {
 338              $icon = "icons/no_posticon.gif";
 339          }
 340          echo "<tr class='$bg' align='left'><td>".$prefix."<img src='".XOOPS_URL."/images/".$icon."'>&nbsp;<a href='".$_SERVER['PHP_SELF']."?item_id=".$this->getVar("item_id")."&amp;comment_id=".$this->getVar("comment_id")."&amp;mode=".$mode."&amp;order=".$order."#".$this->getVar("comment_id")."'>".$this->getVar("subject")."</a></td><td><a href='".XOOPS_URL."/userinfo.php?uid=".$this->getVar("user_id")."'>".XoopsUser::getUnameFromId($this->getVar("user_id"))."</a></td><td>".$date."</td></tr>";
 341      }
 342  
 343  	function showTreeFoot()
 344      {
 345          echo "</table><br />";
 346      }
 347  }
 348  ?>


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