46 public function Story($storyid=-1)
48 $this->db =& Database::getInstance();
50 $this->topicstable =
'';
51 if (is_array($storyid)) {
52 $this->makeStory($storyid);
53 } elseif (-1 !== $storyid) {
54 $this->getStory((
int)$storyid);
58 public function setStoryId($value)
60 $this->storyid = (int)$value;
63 public function setTopicId($value)
65 $this->topicid = (int)$value;
68 public function setUid($value)
70 $this->uid = (int)$value;
73 public function setTitle($value)
75 $this->title = $value;
78 public function setHometext($value)
80 $this->hometext = $value;
83 public function setBodytext($value)
85 $this->bodytext = $value;
88 public function setPublished($value)
90 $this->published = (int)$value;
93 public function setExpired($value)
95 $this->expired = (int)$value;
98 public function setHostname($value)
100 $this->hostname = $value;
103 public function setNohtml($value=0)
105 $this->nohtml = $value;
108 public function setNosmiley($value=0)
110 $this->nosmiley = $value;
113 public function setIhome($value)
115 $this->ihome = $value;
118 public function setNotifyPub($value)
120 $this->notifypub = $value;
123 public function setType($value)
125 $this->type = $value;
128 public function setApproved($value)
130 $this->approved = (int)$value;
133 public function setTopicdisplay($value)
135 $this->topicdisplay = $value;
138 public function setTopicalign($value)
140 $this->topicalign = $value;
143 public function setComments($value)
145 $this->comments = (int)$value;
148 public function store($approved=
false)
152 $title =$myts->censorString($this->title);
153 $hometext =$myts->censorString($this->hometext);
154 $bodytext =$myts->censorString($this->bodytext);
155 $title = $myts->makeTboxData4Save($title);
156 $hometext = $myts->makeTareaData4Save($hometext);
157 $bodytext = $myts->makeTareaData4Save($bodytext);
158 if (!isset($this->nohtml) || 1 != $this->nohtml) {
161 if (!isset($this->nosmiley) || 1 != $this->nosmiley) {
164 if (!isset($this->notifypub) || 1 != $this->notifypub) {
165 $this->notifypub = 0;
167 if (!isset($this->topicdisplay) || 0 != $this->topicdisplay) {
168 $this->topicdisplay = 1;
170 $expired = !empty($this->expired) ? $this->expired : 0;
171 if (!isset($this->storyid)) {
173 $newstoryid = $this->db->genId($this->table .
'_storyid_seq');
175 $published = ($this->approved) ? $this->published : 0;
177 $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);
179 if ($this->approved) {
180 $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);
182 $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);
184 $newstoryid = $this->storyid;
186 if (!$result = $this->db->query($sql)) {
189 if (empty($newstoryid)) {
190 $newstoryid = $this->db->getInsertId();
191 $this->storyid = $newstoryid;
196 public function getStory($storyid)
198 $sql =
'SELECT * FROM ' . $this->table .
' WHERE storyid=' . $storyid .
'';
199 $array = $this->db->fetchArray($this->db->query($sql));
200 $this->makeStory($array);
203 public function makeStory($array)
205 foreach ($array as $key=>$value) {
206 $this->$key = $value;
210 public function delete()
212 $sql = sprintf(
'DELETE FROM %s WHERE storyid = %u', $this->table, $this->storyid);
213 if (!$result = $this->db->query($sql)) {
219 public function updateCounter()
221 $sql = sprintf(
'UPDATE %s SET counter = counter+1 WHERE storyid = %u', $this->table, $this->storyid);
222 if (!$result = $this->db->queryF($sql)) {
228 public function updateComments($total)
230 $sql = sprintf(
'UPDATE %s SET comments = %u WHERE storyid = %u', $this->table, $total, $this->storyid);
231 if (!$result = $this->db->queryF($sql)) {
237 public function topicid()
239 return $this->topicid;
242 public function topic()
244 return new XoopsTopic($this->topicstable, $this->topicid);
247 public function uid()
252 public function uname()
257 public function title($format=
'Show')
261 if ($this->nosmiley()) {
266 $title = $myts->makeTboxData4Show($this->title, $smiley);
269 $title = $myts->makeTboxData4Edit($this->title);
272 $title = $myts->makeTboxData4Preview($this->title, $smiley);
275 $title = $myts->makeTboxData4PreviewInForm($this->title);
281 public function hometext($format=
'Show')
287 if ($this->nohtml()) {
290 if ($this->nosmiley()) {
295 $hometext = $myts->makeTareaData4Show($this->hometext, $html, $smiley, $xcodes);
298 $hometext = $myts->makeTareaData4Edit($this->hometext);
301 $hometext = $myts->makeTareaData4Preview($this->hometext, $html, $smiley, $xcodes);
304 $hometext = $myts->makeTareaData4PreviewInForm($this->hometext);
310 public function bodytext($format=
'Show')
316 if ($this->nohtml()) {
319 if ($this->nosmiley()) {
324 $bodytext = $myts->makeTareaData4Show($this->bodytext, $html, $smiley, $xcodes);
327 $bodytext = $myts->makeTareaData4Edit($this->bodytext);
330 $bodytext = $myts->makeTareaData4Preview($this->bodytext, $html, $smiley, $xcodes);
333 $bodytext = $myts->makeTareaData4PreviewInForm($this->bodytext);
339 public function counter()
341 return $this->counter;
344 public function created()
346 return $this->created;
349 public function published()
351 return $this->published;
354 public function expired()
356 return $this->expired;
359 public function hostname()
361 return $this->hostname;
364 public function storyid()
366 return $this->storyid;
369 public function nohtml()
371 return $this->nohtml;
374 public function nosmiley()
376 return $this->nosmiley;
379 public function notifypub()
381 return $this->notifypub;
384 public function type()
389 public function ihome()
394 public function topicdisplay()
396 return $this->topicdisplay;
399 public function topicalign($astext=
true)
402 if (
'R' == $this->topicalign) {
409 return $this->topicalign;
412 public function comments()
414 return $this->comments;