[ Index ]
 

Code source de XOOPS 2.0.17.1

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

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

   1  <?php
   2  // $Id: xoopstopic.php 783 2006-11-06 04:54:27Z 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  
  36  class XoopsTopic
  37  {
  38      var $table;
  39      var $topic_id;
  40      var $topic_pid;
  41      var $topic_title;
  42      var $topic_imgurl;
  43      var $prefix; // only used in topic tree

  44      var $use_permission=false;
  45      var $mid; // module id used for setting permission

  46  
  47  	function XoopsTopic($table, $topicid=0)
  48      {
  49          $this->db =& Database::getInstance();
  50          $this->table = $table;
  51          if ( is_array($topicid) ) {
  52              $this->makeTopic($topicid);
  53          } elseif ( $topicid != 0 ) {
  54              $this->getTopic(intval($topicid));
  55          } else {
  56              $this->topic_id = $topicid;
  57          }
  58      }
  59  
  60  	function setTopicTitle($value)
  61      {
  62          $this->topic_title = $value;
  63      }
  64  
  65  	function setTopicImgurl($value)
  66      {
  67          $this->topic_imgurl = $value;
  68      }
  69  
  70  	function setTopicPid($value)
  71      {
  72          $this->topic_pid = $value;
  73      }
  74  
  75  	function getTopic($topicid)
  76      {
  77          $sql = "SELECT * FROM ".$this->table." WHERE topic_id=".$topicid."";
  78          $array = $this->db->fetchArray($this->db->query($sql));
  79          $this->makeTopic($array);
  80      }
  81  
  82  	function makeTopic($array)
  83      {
  84          foreach($array as $key=>$value){
  85              $this->$key = $value;
  86          }
  87      }
  88  
  89  	function usePermission($mid)
  90      {
  91          $this->mid = $mid;
  92          $this->use_permission = true;
  93      }
  94  
  95  	function store()
  96      {
  97          $myts =& MyTextSanitizer::getInstance();
  98          $title = "";
  99          $imgurl = "";
 100          if ( isset($this->topic_title) && $this->topic_title != "" ) {
 101              $title = $myts->makeTboxData4Save($this->topic_title);
 102          }
 103          if ( isset($this->topic_imgurl) && $this->topic_imgurl != "" ) {
 104              $imgurl = $myts->makeTboxData4Save($this->topic_imgurl);
 105          }
 106          if ( !isset($this->topic_pid) || !is_numeric($this->topic_pid) ) {
 107              $this->topic_pid = 0;
 108          }
 109          if ( empty($this->topic_id) ) {
 110              $this->topic_id = $this->db->genId($this->table."_topic_id_seq");
 111              $sql = sprintf("INSERT INTO %s (topic_id, topic_pid, topic_imgurl, topic_title) VALUES (%u, %u, '%s', '%s')", $this->table, $this->topic_id, $this->topic_pid, $imgurl, $title);
 112          } else {
 113              $sql = sprintf("UPDATE %s SET topic_pid = %u, topic_imgurl = '%s', topic_title = '%s' WHERE topic_id = %u", $this->table, $this->topic_pid, $imgurl, $title, $this->topic_id);
 114          }
 115          if ( !$result = $this->db->query($sql) ) {
 116              ErrorHandler::show('0022');
 117          }
 118          if ( $this->use_permission == true ) {
 119              if ( empty($this->topic_id) ) {
 120                  $this->topic_id = $this->db->getInsertId();
 121              }
 122              $xt = new XoopsTree($this->table, "topic_id", "topic_pid");
 123              $parent_topics = $xt->getAllParentId($this->topic_id);
 124              if ( !empty($this->m_groups) && is_array($this->m_groups) ){
 125                  foreach ( $this->m_groups as $m_g ) {
 126                      $moderate_topics = XoopsPerms::getPermitted($this->mid, "ModInTopic", $m_g);
 127                      $add = true;
 128                      // only grant this permission when the group has this permission in all parent topics of the created topic

 129                      foreach($parent_topics as $p_topic){
 130                          if ( !in_array($p_topic, $moderate_topics) ) {
 131                              $add = false;
 132                              continue;
 133                          }
 134                      }
 135                      if ( $add == true ) {
 136                          $xp = new XoopsPerms();
 137                          $xp->setModuleId($this->mid);
 138                          $xp->setName("ModInTopic");
 139                          $xp->setItemId($this->topic_id);
 140                          $xp->store();
 141                          $xp->addGroup($m_g);
 142                      }
 143                  }
 144              }
 145              if ( !empty($this->s_groups) && is_array($this->s_groups) ){
 146                  foreach ( $s_groups as $s_g ) {
 147                      $submit_topics = XoopsPerms::getPermitted($this->mid, "SubmitInTopic", $s_g);
 148                      $add = true;
 149                      foreach($parent_topics as $p_topic){
 150                          if ( !in_array($p_topic, $submit_topics) ) {
 151                              $add = false;
 152                              continue;
 153                          }
 154                      }
 155                      if ( $add == true ) {
 156                          $xp = new XoopsPerms();
 157                          $xp->setModuleId($this->mid);
 158                          $xp->setName("SubmitInTopic");
 159                          $xp->setItemId($this->topic_id);
 160                          $xp->store();
 161                          $xp->addGroup($s_g);
 162                      }
 163                  }
 164              }
 165              if ( !empty($this->r_groups) && is_array($this->r_groups) ){
 166                  foreach ( $r_groups as $r_g ) {
 167                      $read_topics = XoopsPerms::getPermitted($this->mid, "ReadInTopic", $r_g);
 168                      $add = true;
 169                      foreach($parent_topics as $p_topic){
 170                          if ( !in_array($p_topic, $read_topics) ) {
 171                              $add = false;
 172                              continue;
 173                          }
 174                      }
 175                      if ( $add == true ) {
 176                          $xp = new XoopsPerms();
 177                          $xp->setModuleId($this->mid);
 178                          $xp->setName("ReadInTopic");
 179                          $xp->setItemId($this->topic_id);
 180                          $xp->store();
 181                          $xp->addGroup($r_g);
 182                      }
 183                  }
 184              }
 185          }
 186          return true;
 187      }
 188  
 189  	function delete()
 190      {
 191          $sql = sprintf("DELETE FROM %s WHERE topic_id = %u", $this->table, $this->topic_id);
 192          $this->db->query($sql);
 193      }
 194  
 195  	function topic_id()
 196      {
 197          return $this->topic_id;
 198      }
 199  
 200  	function topic_pid()
 201      {
 202          return $this->topic_pid;
 203      }
 204  
 205  	function topic_title($format="S")
 206      {
 207          $myts =& MyTextSanitizer::getInstance();
 208          switch($format){
 209              case "S":
 210                  $title = $myts->makeTboxData4Show($this->topic_title);
 211                  break;
 212              case "E":
 213                  $title = $myts->makeTboxData4Edit($this->topic_title);
 214                  break;
 215              case "P":
 216                  $title = $myts->makeTboxData4Preview($this->topic_title);
 217                  break;
 218              case "F":
 219                  $title = $myts->makeTboxData4PreviewInForm($this->topic_title);
 220                  break;
 221          }
 222          return $title;
 223      }
 224  
 225  	function topic_imgurl($format="S")
 226      {
 227          $myts =& MyTextSanitizer::getInstance();
 228          switch($format){
 229              case "S":
 230                  $imgurl= $myts->makeTboxData4Show($this->topic_imgurl);
 231                  break;
 232              case "E":
 233                  $imgurl = $myts->makeTboxData4Edit($this->topic_imgurl);
 234                  break;
 235              case "P":
 236                  $imgurl = $myts->makeTboxData4Preview($this->topic_imgurl);
 237                  break;
 238              case "F":
 239                  $imgurl = $myts->makeTboxData4PreviewInForm($this->topic_imgurl);
 240                  break;
 241          }
 242          return $imgurl;
 243      }
 244  
 245  	function prefix()
 246      {
 247          if ( isset($this->prefix) ) {
 248              return $this->prefix;
 249          }
 250      }
 251  
 252  	function getFirstChildTopics()
 253      {
 254          $ret = array();
 255          $xt = new XoopsTree($this->table, "topic_id", "topic_pid");
 256          $topic_arr = $xt->getFirstChild($this->topic_id, "topic_title");
 257          if ( is_array($topic_arr) && count($topic_arr) ) {
 258              foreach($topic_arr as $topic){
 259                  $ret[] = new XoopsTopic($this->table, $topic);
 260              }
 261          }
 262          return $ret;
 263      }
 264  
 265  	function getAllChildTopics()
 266      {
 267          $ret = array();
 268          $xt = new XoopsTree($this->table, "topic_id", "topic_pid");
 269          $topic_arr = $xt->getAllChild($this->topic_id, "topic_title");
 270          if ( is_array($topic_arr) && count($topic_arr) ) {
 271              foreach($topic_arr as $topic){
 272                  $ret[] = new XoopsTopic($this->table, $topic);
 273              }
 274          }
 275          return $ret;
 276      }
 277  
 278  	function getChildTopicsTreeArray()
 279      {
 280          $ret = array();
 281          $xt = new XoopsTree($this->table, "topic_id", "topic_pid");
 282          $topic_arr = $xt->getChildTreeArray($this->topic_id, "topic_title");
 283          if ( is_array($topic_arr) && count($topic_arr) ) {
 284              foreach($topic_arr as $topic){
 285                  $ret[] = new XoopsTopic($this->table, $topic);
 286              }
 287          }
 288          return $ret;
 289      }
 290  
 291  	function makeTopicSelBox($none=0, $seltopic=-1, $selname="", $onchange="")
 292      {
 293          $xt = new XoopsTree($this->table, "topic_id", "topic_pid");
 294          if ( $seltopic != -1 ) {
 295              $xt->makeMySelBox("topic_title", "topic_title", $seltopic, $none, $selname, $onchange);
 296          } elseif ( !empty($this->topic_id) ) {
 297              $xt->makeMySelBox("topic_title", "topic_title", $this->topic_id, $none, $selname, $onchange);
 298          } else {
 299              $xt->makeMySelBox("topic_title", "topic_title", 0, $none, $selname, $onchange);
 300          }
 301      }
 302  
 303      //generates nicely formatted linked path from the root id to a given id

 304  	function getNiceTopicPathFromId($funcURL)
 305      {
 306          $xt = new XoopsTree($this->table, "topic_id", "topic_pid");
 307          $ret = $xt->getNicePathFromId($this->topic_id, "topic_title", $funcURL);
 308          return $ret;
 309      }
 310  
 311  	function getAllChildTopicsId()
 312      {
 313          $xt = new XoopsTree($this->table, "topic_id", "topic_pid");
 314          $ret = $xt->getAllChildId($this->topic_id, "topic_title");
 315          return $ret;
 316      }
 317  
 318  	function getTopicsList()
 319      {
 320          $result = $this->db->query('SELECT topic_id, topic_pid, topic_title FROM '.$this->table);
 321          $ret = array();
 322          $myts =& MyTextSanitizer::getInstance();
 323          while ($myrow = $this->db->fetchArray($result)) {
 324              $ret[$myrow['topic_id']] = array('title' => $myts->htmlspecialchars($myrow['topic_title']), 'pid' => $myrow['topic_pid']);
 325          }
 326          return $ret;
 327      }
 328  
 329  	function topicExists($pid, $title) {
 330          $sql = "SELECT COUNT(*) from ".$this->table." WHERE topic_pid = ".intval($pid)." AND topic_title = '".trim($title)."'";
 331          $rs = $this->db->query($sql);
 332          list($count) = $this->db->fetchRow($rs);
 333          if ($count > 0) {
 334              return true;
 335          } else {
 336              return false;
 337          }
 338      }
 339  }
 340  ?>


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