/class/xml/rpc/class/xoopsstory.php

https://gitlab.com/VoyaTrax/vtCMS · PHP · 435 lines · 356 code · 48 blank · 31 comment · 36 complexity · 9803771492cd672ef7edd52d8c809f06 MD5 · raw file

  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. class XoopsStory
  37. {
  38. var $table;
  39. var $storyid;
  40. var $topicid;
  41. var $uid;
  42. var $title;
  43. var $hometext;
  44. var $bodytext="";
  45. var $counter;
  46. var $created;
  47. var $published;
  48. var $expired;
  49. var $hostname;
  50. var $nohtml=0;
  51. var $nosmiley=0;
  52. var $ihome=0;
  53. var $notifypub=0;
  54. var $type;
  55. var $approved;
  56. var $topicdisplay;
  57. var $topicalign;
  58. var $db;
  59. var $topicstable;
  60. var $comments;
  61. function Story($storyid=-1)
  62. {
  63. $this->db =& Database::getInstance();
  64. $this->table = "";
  65. $this->topicstable = "";
  66. if ( is_array($storyid) ) {
  67. $this->makeStory($storyid);
  68. } elseif ( $storyid != -1 ) {
  69. $this->getStory(intval($storyid));
  70. }
  71. }
  72. function setStoryId($value)
  73. {
  74. $this->storyid = intval($value);
  75. }
  76. function setTopicId($value)
  77. {
  78. $this->topicid = intval($value);
  79. }
  80. function setUid($value)
  81. {
  82. $this->uid = intval($value);
  83. }
  84. function setTitle($value)
  85. {
  86. $this->title = $value;
  87. }
  88. function setHometext($value)
  89. {
  90. $this->hometext = $value;
  91. }
  92. function setBodytext($value)
  93. {
  94. $this->bodytext = $value;
  95. }
  96. function setPublished($value)
  97. {
  98. $this->published = intval($value);
  99. }
  100. function setExpired($value)
  101. {
  102. $this->expired = intval($value);
  103. }
  104. function setHostname($value)
  105. {
  106. $this->hostname = $value;
  107. }
  108. function setNohtml($value=0)
  109. {
  110. $this->nohtml = $value;
  111. }
  112. function setNosmiley($value=0)
  113. {
  114. $this->nosmiley = $value;
  115. }
  116. function setIhome($value)
  117. {
  118. $this->ihome = $value;
  119. }
  120. function setNotifyPub($value)
  121. {
  122. $this->notifypub = $value;
  123. }
  124. function setType($value)
  125. {
  126. $this->type = $value;
  127. }
  128. function setApproved($value)
  129. {
  130. $this->approved = intval($value);
  131. }
  132. function setTopicdisplay($value)
  133. {
  134. $this->topicdisplay = $value;
  135. }
  136. function setTopicalign($value)
  137. {
  138. $this->topicalign = $value;
  139. }
  140. function setComments($value)
  141. {
  142. $this->comments = intval($value);
  143. }
  144. function store($approved=false)
  145. {
  146. //$newpost = 0;
  147. $myts =& MyTextSanitizer::getInstance();
  148. $title =$myts->censorString($this->title);
  149. $hometext =$myts->censorString($this->hometext);
  150. $bodytext =$myts->censorString($this->bodytext);
  151. $title = $myts->makeTboxData4Save($title);
  152. $hometext = $myts->makeTareaData4Save($hometext);
  153. $bodytext = $myts->makeTareaData4Save($bodytext);
  154. if ( !isset($this->nohtml) || $this->nohtml != 1 ) {
  155. $this->nohtml = 0;
  156. }
  157. if ( !isset($this->nosmiley) || $this->nosmiley != 1 ) {
  158. $this->nosmiley = 0;
  159. }
  160. if ( !isset($this->notifypub) || $this->notifypub != 1 ) {
  161. $this->notifypub = 0;
  162. }
  163. if( !isset($this->topicdisplay) || $this->topicdisplay != 0 ) {
  164. $this->topicdisplay = 1;
  165. }
  166. $expired = !empty($this->expired) ? $this->expired : 0;
  167. if ( !isset($this->storyid) ) {
  168. //$newpost = 1;
  169. $newstoryid = $this->db->genId($this->table."_storyid_seq");
  170. $created = time();
  171. $published = ( $this->approved ) ? $this->published : 0;
  172. $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);
  173. } else {
  174. if ( $this->approved ) {
  175. $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);
  176. } else {
  177. $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);
  178. }
  179. $newstoryid = $this->storyid;
  180. }
  181. if (!$result = $this->db->query($sql)) {
  182. return false;
  183. }
  184. if ( empty($newstoryid) ) {
  185. $newstoryid = $this->db->getInsertId();
  186. $this->storyid = $newstoryid;
  187. }
  188. return $newstoryid;
  189. }
  190. function getStory($storyid)
  191. {
  192. $storyid = intval($storyid);
  193. $sql = "SELECT * FROM ".$this->table." WHERE storyid=".$storyid."";
  194. $array = $this->db->fetchArray($this->db->query($sql));
  195. $this->makeStory($array);
  196. }
  197. function makeStory($array)
  198. {
  199. foreach ( $array as $key=>$value ){
  200. $this->$key = $value;
  201. }
  202. }
  203. function delete()
  204. {
  205. $sql = sprintf("DELETE FROM %s WHERE storyid = %u", $this->table, $this->storyid);
  206. if( !$result = $this->db->query($sql) ) {
  207. return false;
  208. }
  209. return true;
  210. }
  211. function updateCounter()
  212. {
  213. $sql = sprintf("UPDATE %s SET counter = counter+1 WHERE storyid = %u", $this->table, $this->storyid);
  214. if ( !$result = $this->db->queryF($sql) ) {
  215. return false;
  216. }
  217. return true;
  218. }
  219. function updateComments($total)
  220. {
  221. $sql = sprintf("UPDATE %s SET comments = %u WHERE storyid = %u", $this->table, $total, $this->storyid);
  222. if ( !$result = $this->db->queryF($sql) ) {
  223. return false;
  224. }
  225. return true;
  226. }
  227. function topicid()
  228. {
  229. return $this->topicid;
  230. }
  231. function topic()
  232. {
  233. return new XoopsTopic($this->topicstable, $this->topicid);
  234. }
  235. function uid()
  236. {
  237. return $this->uid;
  238. }
  239. function uname()
  240. {
  241. return XoopsUser::getUnameFromId($this->uid);
  242. }
  243. function title($format="Show")
  244. {
  245. $myts =& MyTextSanitizer::getInstance();
  246. $smiley = 1;
  247. if ( $this->nosmiley() ) {
  248. $smiley = 0;
  249. }
  250. switch ( $format ) {
  251. case "Show":
  252. $title = $myts->makeTboxData4Show($this->title,$smiley);
  253. break;
  254. case "Edit":
  255. $title = $myts->makeTboxData4Edit($this->title);
  256. break;
  257. case "Preview":
  258. $title = $myts->makeTboxData4Preview($this->title,$smiley);
  259. break;
  260. case "InForm":
  261. $title = $myts->makeTboxData4PreviewInForm($this->title);
  262. break;
  263. }
  264. return $title;
  265. }
  266. function hometext($format="Show")
  267. {
  268. $myts =& MyTextSanitizer::getInstance();
  269. $html = 1;
  270. $smiley = 1;
  271. $xcodes = 1;
  272. if ( $this->nohtml() ) {
  273. $html = 0;
  274. }
  275. if ( $this->nosmiley() ) {
  276. $smiley = 0;
  277. }
  278. switch ( $format ) {
  279. case "Show":
  280. $hometext = $myts->makeTareaData4Show($this->hometext,$html,$smiley,$xcodes);
  281. break;
  282. case "Edit":
  283. $hometext = $myts->makeTareaData4Edit($this->hometext);
  284. break;
  285. case "Preview":
  286. $hometext = $myts->makeTareaData4Preview($this->hometext,$html,$smiley,$xcodes);
  287. break;
  288. case "InForm":
  289. $hometext = $myts->makeTareaData4PreviewInForm($this->hometext);
  290. break;
  291. }
  292. return $hometext;
  293. }
  294. function bodytext($format="Show")
  295. {
  296. $myts =& MyTextSanitizer::getInstance();
  297. $html = 1;
  298. $smiley = 1;
  299. $xcodes = 1;
  300. if ( $this->nohtml() ) {
  301. $html = 0;
  302. }
  303. if ( $this->nosmiley() ) {
  304. $smiley = 0;
  305. }
  306. switch ( $format ) {
  307. case "Show":
  308. $bodytext = $myts->makeTareaData4Show($this->bodytext,$html,$smiley,$xcodes);
  309. break;
  310. case "Edit":
  311. $bodytext = $myts->makeTareaData4Edit($this->bodytext);
  312. break;
  313. case "Preview":
  314. $bodytext = $myts->makeTareaData4Preview($this->bodytext,$html,$smiley, $xcodes);
  315. break;
  316. case "InForm":
  317. $bodytext = $myts->makeTareaData4PreviewInForm($this->bodytext);
  318. break;
  319. }
  320. return $bodytext;
  321. }
  322. function counter()
  323. {
  324. return $this->counter;
  325. }
  326. function created()
  327. {
  328. return $this->created;
  329. }
  330. function published()
  331. {
  332. return $this->published;
  333. }
  334. function expired()
  335. {
  336. return $this->expired;
  337. }
  338. function hostname()
  339. {
  340. return $this->hostname;
  341. }
  342. function storyid()
  343. {
  344. return $this->storyid;
  345. }
  346. function nohtml()
  347. {
  348. return $this->nohtml;
  349. }
  350. function nosmiley()
  351. {
  352. return $this->nosmiley;
  353. }
  354. function notifypub()
  355. {
  356. return $this->notifypub;
  357. }
  358. function type()
  359. {
  360. return $this->type;
  361. }
  362. function ihome()
  363. {
  364. return $this->ihome;
  365. }
  366. function topicdisplay()
  367. {
  368. return $this->topicdisplay;
  369. }
  370. function topicalign($astext=true)
  371. {
  372. if ( $astext ) {
  373. if ( $this->topicalign == "R" ) {
  374. $ret = "right";
  375. } else {
  376. $ret = "left";
  377. }
  378. return $ret;
  379. }
  380. return $this->topicalign;
  381. }
  382. function comments()
  383. {
  384. return $this->comments;
  385. }
  386. }
  387. ?>