home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / CMS / xoops-2.0.18.1.exe / xoops-2.0.18.1 / htdocs / class / xoopsstory.php < prev    next >
Encoding:
PHP Script  |  2007-10-19  |  11.2 KB  |  435 lines

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