[ Index ]
 

Code source de XOOPS 2.0.17.1

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

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

   1  <?php
   2  // $Id: xoopsstory.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.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/xoopstopic.php";
  35  include_once XOOPS_ROOT_PATH."/class/xoopsuser.php";
  36  
  37  class XoopsStory
  38  {
  39      var $table;
  40      var $storyid;
  41      var $topicid;
  42      var $uid;
  43      var $title;
  44      var $hometext;
  45      var $bodytext="";
  46      var $counter;
  47      var $created;
  48      var $published;
  49      var $expired;
  50      var $hostname;
  51      var $nohtml=0;
  52      var $nosmiley=0;
  53      var $ihome=0;
  54      var $notifypub=0;
  55      var $type;
  56      var $approved;
  57      var $topicdisplay;
  58      var $topicalign;
  59      var $db;
  60      var $topicstable;
  61      var $comments;
  62  
  63  	function Story($storyid=-1)
  64      {
  65          $this->db =& Database::getInstance();
  66          $this->table = "";
  67          $this->topicstable = "";
  68          if ( is_array($storyid) ) {
  69              $this->makeStory($storyid);
  70          } elseif ( $storyid != -1 ) {
  71              $this->getStory(intval($storyid));
  72          }
  73      }
  74  
  75  	function setStoryId($value)
  76      {
  77          $this->storyid = intval($value);
  78      }
  79  
  80  	function setTopicId($value)
  81      {
  82          $this->topicid = intval($value);
  83      }
  84  
  85  	function setUid($value)
  86      {
  87          $this->uid = intval($value);
  88      }
  89  
  90  	function setTitle($value)
  91      {
  92          $this->title = $value;
  93      }
  94  
  95  	function setHometext($value)
  96      {
  97          $this->hometext = $value;
  98      }
  99  
 100  	function setBodytext($value)
 101      {
 102          $this->bodytext = $value;
 103      }
 104  
 105  	function setPublished($value)
 106      {
 107          $this->published = intval($value);
 108      }
 109  
 110  	function setExpired($value)
 111      {
 112          $this->expired = intval($value);
 113      }
 114  
 115  	function setHostname($value)
 116      {
 117          $this->hostname = $value;
 118      }
 119  
 120  	function setNohtml($value=0)
 121      {
 122          $this->nohtml = $value;
 123      }
 124  
 125  	function setNosmiley($value=0)
 126      {
 127          $this->nosmiley = $value;
 128      }
 129  
 130  	function setIhome($value)
 131      {
 132          $this->ihome = $value;
 133      }
 134  
 135  	function setNotifyPub($value)
 136      {
 137          $this->notifypub = $value;
 138      }
 139  
 140  	function setType($value)
 141      {
 142          $this->type = $value;
 143      }
 144  
 145  	function setApproved($value)
 146      {
 147          $this->approved = intval($value);
 148      }
 149  
 150  	function setTopicdisplay($value)
 151      {
 152          $this->topicdisplay = $value;
 153      }
 154  
 155  	function setTopicalign($value)
 156      {
 157          $this->topicalign = $value;
 158      }
 159  
 160  	function setComments($value)
 161      {
 162          $this->comments = intval($value);
 163      }
 164  
 165  	function store($approved=false)
 166      {
 167          //$newpost = 0;

 168          $myts =& MyTextSanitizer::getInstance();
 169          $title =$myts->censorString($this->title);
 170          $hometext =$myts->censorString($this->hometext);
 171          $bodytext =$myts->censorString($this->bodytext);
 172          $title = $myts->makeTboxData4Save($title);
 173          $hometext = $myts->makeTareaData4Save($hometext);
 174          $bodytext = $myts->makeTareaData4Save($bodytext);
 175          if ( !isset($this->nohtml) || $this->nohtml != 1 ) {
 176              $this->nohtml = 0;
 177          }
 178          if ( !isset($this->nosmiley) || $this->nosmiley != 1 ) {
 179              $this->nosmiley = 0;
 180          }
 181          if ( !isset($this->notifypub) || $this->notifypub != 1 ) {
 182              $this->notifypub = 0;
 183          }
 184          if( !isset($this->topicdisplay) || $this->topicdisplay != 0 ) {
 185              $this->topicdisplay = 1;
 186          }
 187          $expired = !empty($this->expired) ? $this->expired : 0;
 188          if ( !isset($this->storyid) ) {
 189              //$newpost = 1;

 190              $newstoryid = $this->db->genId($this->table."_storyid_seq");
 191              $created = time();
 192              $published = ( $this->approved ) ? $this->published : 0;
 193  
 194              $sql = sprintf("INSERT INTO %s (storyid, uid, title, created, published, expired, hostname, nohtml, nosmiley, hometext, bodytext, counter, topicid, ihome, notifypub, story_type, topicdisplay, topicalign, comments) VALUES (%u, %u, '%s', %u, %u, %u, '%s', %u, %u, '%s', '%s', %u, %u, %u, %u, '%s', %u, '%s', %u)", $this->table, $newstoryid, $this->uid, $title, $created, $published, $expired, $this->hostname, $this->nohtml, $this->nosmiley, $hometext, $bodytext, 0, $this->topicid, $this->ihome, $this->notifypub, $this->type, $this->topicdisplay, $this->topicalign, $this->comments);
 195          } else {
 196              if ( $this->approved ) {
 197                  $sql = sprintf("UPDATE %s SET title = '%s', published = %u, expired = %u, nohtml = %u, nosmiley = %u, hometext = '%s', bodytext = '%s', topicid = %u, ihome = %u, topicdisplay = %u, topicalign = '%s', comments = %u WHERE storyid = %u", $this->table, $title, $this->published, $expired, $this->nohtml, $this->nosmiley, $hometext, $bodytext, $this->topicid, $this->ihome, $this->topicdisplay, $this->topicalign, $this->comments, $this->storyid);
 198              } else {
 199                  $sql = sprintf("UPDATE %s SET title = '%s', expired = %u, nohtml = %u, nosmiley = %u, hometext = '%s', bodytext = '%s', topicid = %u, ihome = %u, topicdisplay = %u, topicalign = '%s', comments = %u WHERE storyid = %u", $this->table, $title, $expired, $this->nohtml, $this->nosmiley, $hometext, $bodytext, $this->topicid, $this->ihome, $this->topicdisplay, $this->topicalign, $this->comments, $this->storyid);
 200              }
 201              $newstoryid = $this->storyid;
 202          }
 203          if (!$result = $this->db->query($sql)) {
 204              return false;
 205          }
 206          if ( empty($newstoryid) ) {
 207              $newstoryid = $this->db->getInsertId();
 208              $this->storyid = $newstoryid;
 209          }
 210          return $newstoryid;
 211      }
 212  
 213  	function getStory($storyid)
 214      {
 215          $sql = "SELECT * FROM ".$this->table." WHERE storyid=".$storyid."";
 216          $array = $this->db->fetchArray($this->db->query($sql));
 217          $this->makeStory($array);
 218      }
 219  
 220  	function makeStory($array)
 221      {
 222          foreach ( $array as $key=>$value ){
 223              $this->$key = $value;
 224          }
 225      }
 226  
 227  	function delete()
 228      {
 229          $sql = sprintf("DELETE FROM %s WHERE storyid = %u", $this->table, $this->storyid);
 230          if( !$result = $this->db->query($sql) ) {
 231              return false;
 232          }
 233          return true;
 234      }
 235  
 236  	function updateCounter()
 237      {
 238          $sql = sprintf("UPDATE %s SET counter = counter+1 WHERE storyid = %u", $this->table, $this->storyid);
 239          if ( !$result = $this->db->queryF($sql) ) {
 240              return false;
 241          }
 242          return true;
 243      }
 244  
 245  	function updateComments($total)
 246      {
 247          $sql = sprintf("UPDATE %s SET comments = %u WHERE storyid = %u", $this->table, $total, $this->storyid);
 248          if ( !$result = $this->db->queryF($sql) ) {
 249              return false;
 250          }
 251          return true;
 252      }
 253  
 254  	function topicid()
 255      {
 256          return $this->topicid;
 257      }
 258  
 259  	function topic()
 260      {
 261          return new XoopsTopic($this->topicstable, $this->topicid);
 262      }
 263  
 264  	function uid()
 265      {
 266          return $this->uid;
 267      }
 268  
 269  	function uname()
 270      {
 271          return XoopsUser::getUnameFromId($this->uid);
 272      }
 273  
 274  	function title($format="Show")
 275      {
 276          $myts =& MyTextSanitizer::getInstance();
 277          $smiley = 1;
 278          if ( $this->nosmiley() ) {
 279              $smiley = 0;
 280          }
 281          switch ( $format ) {
 282          case "Show":
 283              $title = $myts->makeTboxData4Show($this->title,$smiley);
 284              break;
 285          case "Edit":
 286              $title = $myts->makeTboxData4Edit($this->title);
 287              break;
 288          case "Preview":
 289              $title = $myts->makeTboxData4Preview($this->title,$smiley);
 290              break;
 291          case "InForm":
 292              $title = $myts->makeTboxData4PreviewInForm($this->title);
 293              break;
 294          }
 295          return $title;
 296      }
 297  
 298  	function hometext($format="Show")
 299      {
 300          $myts =& MyTextSanitizer::getInstance();
 301          $html = 1;
 302          $smiley = 1;
 303          $xcodes = 1;
 304          if ( $this->nohtml() ) {
 305              $html = 0;
 306          }
 307          if ( $this->nosmiley() ) {
 308              $smiley = 0;
 309          }
 310          switch ( $format ) {
 311          case "Show":
 312              $hometext = $myts->makeTareaData4Show($this->hometext,$html,$smiley,$xcodes);
 313              break;
 314          case "Edit":
 315              $hometext = $myts->makeTareaData4Edit($this->hometext);
 316              break;
 317          case "Preview":
 318              $hometext = $myts->makeTareaData4Preview($this->hometext,$html,$smiley,$xcodes);
 319              break;
 320          case "InForm":
 321              $hometext = $myts->makeTareaData4PreviewInForm($this->hometext);
 322              break;
 323          }
 324          return $hometext;
 325      }
 326  
 327  	function bodytext($format="Show")
 328      {
 329          $myts =& MyTextSanitizer::getInstance();
 330          $html = 1;
 331          $smiley = 1;
 332          $xcodes = 1;
 333          if ( $this->nohtml() ) {
 334              $html = 0;
 335          }
 336          if ( $this->nosmiley() ) {
 337              $smiley = 0;
 338          }
 339          switch ( $format ) {
 340          case "Show":
 341              $bodytext = $myts->makeTareaData4Show($this->bodytext,$html,$smiley,$xcodes);
 342              break;
 343          case "Edit":
 344              $bodytext = $myts->makeTareaData4Edit($this->bodytext);
 345              break;
 346          case "Preview":
 347              $bodytext = $myts->makeTareaData4Preview($this->bodytext,$html,$smiley, $xcodes);
 348              break;
 349          case "InForm":
 350              $bodytext = $myts->makeTareaData4PreviewInForm($this->bodytext);
 351              break;
 352          }
 353          return $bodytext;
 354      }
 355  
 356  	function counter()
 357      {
 358          return $this->counter;
 359      }
 360  
 361  	function created()
 362      {
 363          return $this->created;
 364      }
 365  
 366  	function published()
 367      {
 368          return $this->published;
 369      }
 370  
 371  	function expired()
 372      {
 373          return $this->expired;
 374      }
 375  
 376  	function hostname()
 377      {
 378          return $this->hostname;
 379      }
 380  
 381  	function storyid()
 382      {
 383          return $this->storyid;
 384      }
 385  
 386  	function nohtml()
 387      {
 388          return $this->nohtml;
 389      }
 390  
 391  	function nosmiley()
 392      {
 393          return $this->nosmiley;
 394      }
 395  
 396  	function notifypub()
 397      {
 398          return $this->notifypub;
 399      }
 400  
 401  	function type()
 402      {
 403          return $this->type;
 404      }
 405  
 406  	function ihome()
 407      {
 408          return $this->ihome;
 409      }
 410  
 411  	function topicdisplay()
 412      {
 413          return $this->topicdisplay;
 414      }
 415  
 416  	function topicalign($astext=true)
 417      {
 418          if ( $astext ) {
 419              if ( $this->topicalign == "R" ) {
 420                  $ret = "right";
 421              } else {
 422                  $ret = "left";
 423              }
 424              return $ret;
 425          }
 426          return $this->topicalign;
 427      }
 428  
 429  	function comments()
 430      {
 431          return $this->comments;
 432      }
 433  }
 434  ?>


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