XOOPS 2.5.6  Final
 All Classes Namespaces Files Functions Variables Pages
xoopsstory.php
Go to the documentation of this file.
1 <?php
21 if (!defined('XOOPS_ROOT_PATH')) {
22  exit();
23 }
24 $GLOBALS['xoopsLogger']->addDeprecated("'/class/xoopstory.php' is deprecated since XOOPS 2.5.4, please create your own class instead.");
25 include_once XOOPS_ROOT_PATH."/class/xoopstopic.php";
26 include_once XOOPS_ROOT_PATH."/kernel/user.php";
27 
29 {
30  var $table;
31  var $storyid;
32  var $topicid;
33  var $uid;
34  var $title;
35  var $hometext;
36  var $bodytext="";
37  var $counter;
38  var $created;
40  var $expired;
41  var $hostname;
42  var $nohtml=0;
43  var $nosmiley=0;
44  var $ihome=0;
45  var $notifypub=0;
46  var $type;
47  var $approved;
50  var $db;
52  var $comments;
53 
54  function Story($storyid=-1)
55  {
57  $this->table = "";
58  $this->topicstable = "";
59  if ( is_array($storyid) ) {
60  $this->makeStory($storyid);
61  } elseif ( $storyid != -1 ) {
62  $this->getStory(intval($storyid));
63  }
64  }
65 
66  function setStoryId($value)
67  {
68  $this->storyid = intval($value);
69  }
70 
71  function setTopicId($value)
72  {
73  $this->topicid = intval($value);
74  }
75 
76  function setUid($value)
77  {
78  $this->uid = intval($value);
79  }
80 
81  function setTitle($value)
82  {
83  $this->title = $value;
84  }
85 
86  function setHometext($value)
87  {
88  $this->hometext = $value;
89  }
90 
91  function setBodytext($value)
92  {
93  $this->bodytext = $value;
94  }
95 
96  function setPublished($value)
97  {
98  $this->published = intval($value);
99  }
100 
101  function setExpired($value)
102  {
103  $this->expired = intval($value);
104  }
105 
106  function setHostname($value)
107  {
108  $this->hostname = $value;
109  }
110 
111  function setNohtml($value=0)
112  {
113  $this->nohtml = $value;
114  }
115 
116  function setNosmiley($value=0)
117  {
118  $this->nosmiley = $value;
119  }
120 
121  function setIhome($value)
122  {
123  $this->ihome = $value;
124  }
125 
126  function setNotifyPub($value)
127  {
128  $this->notifypub = $value;
129  }
130 
131  function setType($value)
132  {
133  $this->type = $value;
134  }
135 
136  function setApproved($value)
137  {
138  $this->approved = intval($value);
139  }
140 
141  function setTopicdisplay($value)
142  {
143  $this->topicdisplay = $value;
144  }
145 
146  function setTopicalign($value)
147  {
148  $this->topicalign = $value;
149  }
150 
151  function setComments($value)
152  {
153  $this->comments = intval($value);
154  }
155 
156  function store($approved=false)
157  {
158  //$newpost = 0;
160  $title =$myts->censorString($this->title);
161  $hometext =$myts->censorString($this->hometext);
162  $bodytext =$myts->censorString($this->bodytext);
163  $title = $myts->addSlashes($title);
164  $hometext = $myts->addSlashes($hometext);
165  $bodytext = $myts->addSlashes($bodytext);
166  if (!isset($this->nohtml) || $this->nohtml != 1) {
167  $this->nohtml = 0;
168  }
169  if (!isset($this->nosmiley) || $this->nosmiley != 1) {
170  $this->nosmiley = 0;
171  }
172  if (!isset($this->notifypub) || $this->notifypub != 1) {
173  $this->notifypub = 0;
174  }
175  if (!isset($this->topicdisplay) || $this->topicdisplay != 0) {
176  $this->topicdisplay = 1;
177  }
178  $expired = !empty($this->expired) ? $this->expired : 0;
179  if (!isset($this->storyid)) {
180  //$newpost = 1;
181  $newstoryid = $this->db->genId($this->table."_storyid_seq");
182  $created = time();
183  $published = ($this->approved) ? $this->published : 0;
184 
185  $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);
186  } else {
187  if ($this->approved) {
188  $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);
189  } else {
190  $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);
191  }
192  $newstoryid = $this->storyid;
193  }
194  if (!$result = $this->db->query($sql)) {
195  return false;
196  }
197  if (empty($newstoryid)) {
198  $newstoryid = $this->db->getInsertId();
199  $this->storyid = $newstoryid;
200  }
201  return $newstoryid;
202  }
203 
204  function getStory($storyid)
205  {
206  $storyid = intval($storyid);
207  $sql = "SELECT * FROM ".$this->table." WHERE storyid=" . $storyid . "";
208  $array = $this->db->fetchArray($this->db->query($sql));
209  $this->makeStory($array);
210  }
211 
212  function makeStory($array)
213  {
214  foreach ($array as $key => $value){
215  $this->$key = $value;
216  }
217  }
218 
219  function delete()
220  {
221  $sql = sprintf("DELETE FROM %s WHERE storyid = %u", $this->table, $this->storyid);
222  if (!$result = $this->db->query($sql)) {
223  return false;
224  }
225  return true;
226  }
227 
228  function updateCounter()
229  {
230  $sql = sprintf("UPDATE %s SET counter = counter+1 WHERE storyid = %u", $this->table, $this->storyid);
231  if (!$result = $this->db->queryF($sql)) {
232  return false;
233  }
234  return true;
235  }
236 
237  function updateComments($total)
238  {
239  $sql = sprintf("UPDATE %s SET comments = %u WHERE storyid = %u", $this->table, $total, $this->storyid);
240  if (!$result = $this->db->queryF($sql)) {
241  return false;
242  }
243  return true;
244  }
245 
246  function topicid()
247  {
248  return $this->topicid;
249  }
250 
251  function topic()
252  {
253  return new XoopsTopic($this->topicstable, $this->topicid);
254  }
255 
256  function uid()
257  {
258  return $this->uid;
259  }
260 
261  function uname()
262  {
263  return XoopsUser::getUnameFromId($this->uid);
264  }
265 
266  function title($format = "Show")
267  {
269  $smiley = 1;
270  if ($this->nosmiley()) {
271  $smiley = 0;
272  }
273  switch ( $format ) {
274  case "Show":
275  case "Edit":
276  $title = $myts->htmlSpecialChars($this->title);
277  break;
278  case "Preview":
279  case "InForm":
280  $title = $myts->htmlSpecialChars($myts->stripSlashesGPC($this->title));
281  break;
282  }
283  return $title;
284  }
285 
286  function hometext($format = "Show")
287  {
289  $html = 1;
290  $smiley = 1;
291  $xcodes = 1;
292  if ($this->nohtml()) {
293  $html = 0;
294  }
295  if ($this->nosmiley()) {
296  $smiley = 0;
297  }
298  switch ($format) {
299  case "Show":
300  $hometext = $myts->displayTarea($this->hometext, $html, $smiley, $xcodes);
301  break;
302  case "Edit":
303  $hometext = htmlspecialchars($this->hometext, ENT_QUOTES);
304  break;
305  case "Preview":
306  $hometext = $myts->previewTarea($this->hometext, $html, $smiley, $xcodes);
307  break;
308  case "InForm":
309  $hometext = htmlspecialchars($myts->stripSlashesGPC($this->hometext), ENT_QUOTES);
310  break;
311  }
312  return $hometext;
313  }
314 
315  function bodytext($format = "Show")
316  {
318  $html = 1;
319  $smiley = 1;
320  $xcodes = 1;
321  if ($this->nohtml()) {
322  $html = 0;
323  }
324  if ($this->nosmiley()) {
325  $smiley = 0;
326  }
327  switch ($format) {
328  case "Show":
329  $bodytext = $myts->displayTarea($this->bodytext, $html, $smiley, $xcodes);
330  break;
331  case "Edit":
332  $bodytext = htmlspecialchars($this->bodytext, ENT_QUOTES);
333  break;
334  case "Preview":
335  $bodytext = $myts->previewTarea($this->bodytext, $html, $smiley, $xcodes);
336  break;
337  case "InForm":
338  $bodytext = htmlspecialchars($myts->stripSlashesGPC($this->bodytext), ENT_QUOTES);
339  break;
340  }
341  return $bodytext;
342  }
343 
344  function counter()
345  {
346  return $this->counter;
347  }
348 
349  function created()
350  {
351  return $this->created;
352  }
353 
354  function published()
355  {
356  return $this->published;
357  }
358 
359  function expired()
360  {
361  return $this->expired;
362  }
363 
364  function hostname()
365  {
366  return $this->hostname;
367  }
368 
369  function storyid()
370  {
371  return $this->storyid;
372  }
373 
374  function nohtml()
375  {
376  return $this->nohtml;
377  }
378 
379  function nosmiley()
380  {
381  return $this->nosmiley;
382  }
383 
384  function notifypub()
385  {
386  return $this->notifypub;
387  }
388 
389  function type()
390  {
391  return $this->type;
392  }
393 
394  function ihome()
395  {
396  return $this->ihome;
397  }
398 
399  function topicdisplay()
400  {
401  return $this->topicdisplay;
402  }
403 
404  function topicalign($astext = true)
405  {
406  if ($astext) {
407  if ($this->topicalign == "R") {
408  $ret = "right";
409  } else {
410  $ret = "left";
411  }
412  return $ret;
413  }
414  return $this->topicalign;
415  }
416 
417  function comments()
418  {
419  return $this->comments;
420  }
421 }
422 ?>