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