|
1
|
|
|
<?php |
|
|
|
|
|
|
2
|
|
|
/** |
|
3
|
|
|
* XOOPS news topic |
|
4
|
|
|
* |
|
5
|
|
|
* You may not change or alter any portion of this comment or credits |
|
6
|
|
|
* of supporting developers from this source code or any supporting source code |
|
7
|
|
|
* which is considered copyrighted (c) material of the original comment or credit authors. |
|
8
|
|
|
* This program is distributed in the hope that it will be useful, |
|
9
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
11
|
|
|
* |
|
12
|
|
|
* @copyright XOOPS Project (http://xoops.org) |
|
13
|
|
|
* @license GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html) |
|
14
|
|
|
* @package kernel |
|
15
|
|
|
* @since 2.0.0 |
|
16
|
|
|
* @author Kazumi Ono (AKA onokazu) http://www.myweb.ne.jp/, http://jp.xoops.org/ |
|
17
|
|
|
* @deprecated |
|
18
|
|
|
*/ |
|
19
|
|
|
|
|
20
|
|
|
// defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined'); |
|
|
|
|
|
|
21
|
|
|
//$GLOBALS['xoopsLogger']->addDeprecated("'/class/xoopstopic.php' is deprecated since XOOPS 2.5.4, please create your own class instead."); |
|
22
|
|
|
|
|
23
|
|
|
include_once XOOPS_ROOT_PATH . '/modules/news/class/xoopstree.php'; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Class MyXoopsTopic |
|
27
|
|
|
*/ |
|
28
|
|
|
class MyXoopsTopic |
|
|
|
|
|
|
29
|
|
|
{ |
|
30
|
|
|
public $table; |
|
31
|
|
|
public $topic_id; |
|
32
|
|
|
public $topic_pid; |
|
33
|
|
|
public $topic_title; |
|
34
|
|
|
public $topic_imgurl; |
|
35
|
|
|
public $prefix; // only used in topic tree |
|
36
|
|
|
public $use_permission = false; |
|
37
|
|
|
public $mid; // module id used for setting permission |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @param $table |
|
41
|
|
|
* @param int $topicid |
|
42
|
|
|
*/ |
|
43
|
|
View Code Duplication |
public function __construct($table, $topicid = 0) |
|
|
|
|
|
|
44
|
|
|
{ |
|
45
|
|
|
$this->db = XoopsDatabaseFactory::getDatabaseConnection(); |
|
|
|
|
|
|
46
|
|
|
$this->table = $table; |
|
47
|
|
|
if (is_array($topicid)) { |
|
48
|
|
|
$this->makeTopic($topicid); |
|
49
|
|
|
} elseif ($topicid != 0) { |
|
50
|
|
|
$this->getTopic((int)$topicid); |
|
51
|
|
|
} else { |
|
52
|
|
|
$this->topic_id = $topicid; |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @param $value |
|
58
|
|
|
*/ |
|
59
|
|
|
public function setTopicTitle($value) |
|
60
|
|
|
{ |
|
61
|
|
|
$this->topic_title = $value; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @param $value |
|
66
|
|
|
*/ |
|
67
|
|
|
public function setTopicImgurl($value) |
|
68
|
|
|
{ |
|
69
|
|
|
$this->topic_imgurl = $value; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @param $value |
|
74
|
|
|
*/ |
|
75
|
|
|
public function setTopicPid($value) |
|
76
|
|
|
{ |
|
77
|
|
|
$this->topic_pid = $value; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* @param $topicid |
|
82
|
|
|
*/ |
|
83
|
|
View Code Duplication |
public function getTopic($topicid) |
|
|
|
|
|
|
84
|
|
|
{ |
|
85
|
|
|
$topicid = (int)$topicid; |
|
86
|
|
|
$sql = 'SELECT * FROM ' . $this->table . ' WHERE topic_id=' . $topicid . ''; |
|
87
|
|
|
$array = $this->db->fetchArray($this->db->query($sql)); |
|
88
|
|
|
$this->makeTopic($array); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* @param $array |
|
93
|
|
|
*/ |
|
94
|
|
|
public function makeTopic($array) |
|
95
|
|
|
{ |
|
96
|
|
|
foreach ($array as $key => $value) { |
|
97
|
|
|
$this->$key = $value; |
|
98
|
|
|
} |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* @param $mid |
|
103
|
|
|
*/ |
|
104
|
|
|
public function usePermission($mid) |
|
105
|
|
|
{ |
|
106
|
|
|
$this->mid = $mid; |
|
107
|
|
|
$this->use_permission = true; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* @return bool |
|
112
|
|
|
*/ |
|
113
|
|
|
public function store() |
|
114
|
|
|
{ |
|
115
|
|
|
$myts = MyTextSanitizer::getInstance(); |
|
116
|
|
|
$title = ''; |
|
117
|
|
|
$imgurl = ''; |
|
118
|
|
|
if (isset($this->topic_title) && $this->topic_title != '') { |
|
119
|
|
|
$title = $myts->addSlashes($this->topic_title); |
|
120
|
|
|
} |
|
121
|
|
|
if (isset($this->topic_imgurl) && $this->topic_imgurl != '') { |
|
122
|
|
|
$imgurl = $myts->addSlashes($this->topic_imgurl); |
|
123
|
|
|
} |
|
124
|
|
|
if (!isset($this->topic_pid) || !is_numeric($this->topic_pid)) { |
|
125
|
|
|
$this->topic_pid = 0; |
|
126
|
|
|
} |
|
127
|
|
|
if (empty($this->topic_id)) { |
|
128
|
|
|
$this->topic_id = $this->db->genId($this->table . '_topic_id_seq'); |
|
129
|
|
|
$sql = sprintf("INSERT INTO %s (topic_id, topic_pid, topic_imgurl, topic_title) VALUES (%u, %u, '%s', '%s')", $this->table, $this->topic_id, $this->topic_pid, $imgurl, $title); |
|
130
|
|
|
} else { |
|
131
|
|
|
$sql = sprintf("UPDATE %s SET topic_pid = %u, topic_imgurl = '%s', topic_title = '%s' WHERE topic_id = %u", $this->table, $this->topic_pid, $imgurl, $title, $this->topic_id); |
|
132
|
|
|
} |
|
133
|
|
|
if (!$result = $this->db->query($sql)) { |
|
134
|
|
|
ErrorHandler::show('0022'); |
|
135
|
|
|
} |
|
136
|
|
|
if ($this->use_permission == true) { |
|
|
|
|
|
|
137
|
|
|
if (empty($this->topic_id)) { |
|
138
|
|
|
$this->topic_id = $this->db->getInsertId(); |
|
139
|
|
|
} |
|
140
|
|
|
$xt = new MyXoopsTree($this->table, 'topic_id', 'topic_pid'); |
|
141
|
|
|
$parent_topics = $xt->getAllParentId($this->topic_id); |
|
142
|
|
View Code Duplication |
if (!empty($this->m_groups) && is_array($this->m_groups)) { |
|
|
|
|
|
|
143
|
|
|
foreach ($this->m_groups as $m_g) { |
|
|
|
|
|
|
144
|
|
|
$moderate_topics = XoopsPerms::getPermitted($this->mid, 'ModInTopic', $m_g); |
|
145
|
|
|
$add = true; |
|
146
|
|
|
// only grant this permission when the group has this permission in all parent topics of the created topic |
|
147
|
|
|
foreach ($parent_topics as $p_topic) { |
|
148
|
|
|
if (!in_array($p_topic, $moderate_topics)) { |
|
149
|
|
|
$add = false; |
|
150
|
|
|
continue; |
|
151
|
|
|
} |
|
152
|
|
|
} |
|
153
|
|
|
if ($add == true) { |
|
|
|
|
|
|
154
|
|
|
$xp = new XoopsPerms(); |
|
155
|
|
|
$xp->setModuleId($this->mid); |
|
156
|
|
|
$xp->setName('ModInTopic'); |
|
157
|
|
|
$xp->setItemId($this->topic_id); |
|
158
|
|
|
$xp->store(); |
|
159
|
|
|
$xp->addGroup($m_g); |
|
160
|
|
|
} |
|
161
|
|
|
} |
|
162
|
|
|
} |
|
163
|
|
View Code Duplication |
if (!empty($this->s_groups) && is_array($this->s_groups)) { |
|
|
|
|
|
|
164
|
|
|
foreach ($s_groups as $s_g) { |
|
|
|
|
|
|
165
|
|
|
$submit_topics = XoopsPerms::getPermitted($this->mid, 'SubmitInTopic', $s_g); |
|
166
|
|
|
$add = true; |
|
167
|
|
|
foreach ($parent_topics as $p_topic) { |
|
168
|
|
|
if (!in_array($p_topic, $submit_topics)) { |
|
169
|
|
|
$add = false; |
|
170
|
|
|
continue; |
|
171
|
|
|
} |
|
172
|
|
|
} |
|
173
|
|
|
if ($add == true) { |
|
|
|
|
|
|
174
|
|
|
$xp = new XoopsPerms(); |
|
175
|
|
|
$xp->setModuleId($this->mid); |
|
176
|
|
|
$xp->setName('SubmitInTopic'); |
|
177
|
|
|
$xp->setItemId($this->topic_id); |
|
178
|
|
|
$xp->store(); |
|
179
|
|
|
$xp->addGroup($s_g); |
|
180
|
|
|
} |
|
181
|
|
|
} |
|
182
|
|
|
} |
|
183
|
|
View Code Duplication |
if (!empty($this->r_groups) && is_array($this->r_groups)) { |
|
|
|
|
|
|
184
|
|
|
foreach ($r_groups as $r_g) { |
|
|
|
|
|
|
185
|
|
|
$read_topics = XoopsPerms::getPermitted($this->mid, 'ReadInTopic', $r_g); |
|
186
|
|
|
$add = true; |
|
187
|
|
|
foreach ($parent_topics as $p_topic) { |
|
188
|
|
|
if (!in_array($p_topic, $read_topics)) { |
|
189
|
|
|
$add = false; |
|
190
|
|
|
continue; |
|
191
|
|
|
} |
|
192
|
|
|
} |
|
193
|
|
|
if ($add == true) { |
|
|
|
|
|
|
194
|
|
|
$xp = new XoopsPerms(); |
|
195
|
|
|
$xp->setModuleId($this->mid); |
|
196
|
|
|
$xp->setName('ReadInTopic'); |
|
197
|
|
|
$xp->setItemId($this->topic_id); |
|
198
|
|
|
$xp->store(); |
|
199
|
|
|
$xp->addGroup($r_g); |
|
200
|
|
|
} |
|
201
|
|
|
} |
|
202
|
|
|
} |
|
203
|
|
|
} |
|
204
|
|
|
|
|
205
|
|
|
return true; |
|
206
|
|
|
} |
|
207
|
|
|
|
|
208
|
|
|
public function delete() |
|
209
|
|
|
{ |
|
210
|
|
|
$sql = sprintf('DELETE FROM %s WHERE topic_id = %u', $this->table, $this->topic_id); |
|
211
|
|
|
$this->db->query($sql); |
|
212
|
|
|
} |
|
213
|
|
|
|
|
214
|
|
|
/** |
|
215
|
|
|
* @return int |
|
216
|
|
|
*/ |
|
217
|
|
|
public function topic_id() |
|
218
|
|
|
{ |
|
219
|
|
|
return $this->topic_id; |
|
220
|
|
|
} |
|
221
|
|
|
|
|
222
|
|
|
public function topic_pid() |
|
223
|
|
|
{ |
|
224
|
|
|
return $this->topic_pid; |
|
225
|
|
|
} |
|
226
|
|
|
|
|
227
|
|
|
/** |
|
228
|
|
|
* @param string $format |
|
229
|
|
|
* |
|
230
|
|
|
* @return mixed |
|
231
|
|
|
*/ |
|
232
|
|
View Code Duplication |
public function topic_title($format = 'S') |
|
|
|
|
|
|
233
|
|
|
{ |
|
234
|
|
|
$myts = MyTextSanitizer::getInstance(); |
|
235
|
|
|
switch ($format) { |
|
236
|
|
|
case 'S': |
|
237
|
|
|
case 'E': |
|
238
|
|
|
$title = $myts->htmlSpecialChars($this->topic_title); |
|
239
|
|
|
break; |
|
240
|
|
|
case 'P': |
|
241
|
|
|
case 'F': |
|
242
|
|
|
$title = $myts->htmlSpecialChars($myts->stripSlashesGPC($this->topic_title)); |
|
243
|
|
|
break; |
|
244
|
|
|
} |
|
245
|
|
|
|
|
246
|
|
|
return $title; |
|
|
|
|
|
|
247
|
|
|
} |
|
248
|
|
|
|
|
249
|
|
|
/** |
|
250
|
|
|
* @param string $format |
|
251
|
|
|
* |
|
252
|
|
|
* @return mixed |
|
253
|
|
|
*/ |
|
254
|
|
View Code Duplication |
public function topic_imgurl($format = 'S') |
|
|
|
|
|
|
255
|
|
|
{ |
|
256
|
|
|
$myts = MyTextSanitizer::getInstance(); |
|
257
|
|
|
switch ($format) { |
|
258
|
|
|
case 'S': |
|
259
|
|
|
case 'E': |
|
260
|
|
|
$imgurl = $myts->htmlSpecialChars($this->topic_imgurl); |
|
261
|
|
|
break; |
|
262
|
|
|
case 'P': |
|
263
|
|
|
case 'F': |
|
264
|
|
|
$imgurl = $myts->htmlSpecialChars($myts->stripSlashesGPC($this->topic_imgurl)); |
|
265
|
|
|
break; |
|
266
|
|
|
} |
|
267
|
|
|
|
|
268
|
|
|
return $imgurl; |
|
|
|
|
|
|
269
|
|
|
} |
|
270
|
|
|
|
|
271
|
|
|
/** |
|
272
|
|
|
* @return null |
|
273
|
|
|
*/ |
|
274
|
|
|
public function prefix() |
|
275
|
|
|
{ |
|
276
|
|
|
if (isset($this->prefix)) { |
|
277
|
|
|
return $this->prefix; |
|
278
|
|
|
} |
|
279
|
|
|
|
|
280
|
|
|
return null; |
|
281
|
|
|
} |
|
282
|
|
|
|
|
283
|
|
|
/** |
|
284
|
|
|
* @return array |
|
285
|
|
|
*/ |
|
286
|
|
View Code Duplication |
public function getFirstChildTopics() |
|
|
|
|
|
|
287
|
|
|
{ |
|
288
|
|
|
$ret = array(); |
|
289
|
|
|
$xt = new MyXoopsTree($this->table, 'topic_id', 'topic_pid'); |
|
290
|
|
|
$topic_arr = $xt->getFirstChild($this->topic_id, 'topic_title'); |
|
291
|
|
|
if (is_array($topic_arr) && count($topic_arr)) { |
|
292
|
|
|
foreach ($topic_arr as $topic) { |
|
293
|
|
|
$ret[] = new MyXoopsTopic($this->table, $topic); |
|
294
|
|
|
} |
|
295
|
|
|
} |
|
296
|
|
|
|
|
297
|
|
|
return $ret; |
|
298
|
|
|
} |
|
299
|
|
|
|
|
300
|
|
|
/** |
|
301
|
|
|
* @return array |
|
302
|
|
|
*/ |
|
303
|
|
View Code Duplication |
public function getAllChildTopics() |
|
|
|
|
|
|
304
|
|
|
{ |
|
305
|
|
|
$ret = array(); |
|
306
|
|
|
$xt = new MyXoopsTree($this->table, 'topic_id', 'topic_pid'); |
|
307
|
|
|
$topic_arr = $xt->getAllChild($this->topic_id, 'topic_title'); |
|
308
|
|
|
if (is_array($topic_arr) && count($topic_arr)) { |
|
309
|
|
|
foreach ($topic_arr as $topic) { |
|
310
|
|
|
$ret[] = new MyXoopsTopic($this->table, $topic); |
|
311
|
|
|
} |
|
312
|
|
|
} |
|
313
|
|
|
|
|
314
|
|
|
return $ret; |
|
315
|
|
|
} |
|
316
|
|
|
|
|
317
|
|
|
/** |
|
318
|
|
|
* @return array |
|
319
|
|
|
*/ |
|
320
|
|
View Code Duplication |
public function getChildTopicsTreeArray() |
|
|
|
|
|
|
321
|
|
|
{ |
|
322
|
|
|
$ret = array(); |
|
323
|
|
|
$xt = new MyXoopsTree($this->table, 'topic_id', 'topic_pid'); |
|
324
|
|
|
$topic_arr = $xt->getChildTreeArray($this->topic_id, 'topic_title'); |
|
325
|
|
|
if (is_array($topic_arr) && count($topic_arr)) { |
|
326
|
|
|
foreach ($topic_arr as $topic) { |
|
327
|
|
|
$ret[] = new MyXoopsTopic($this->table, $topic); |
|
328
|
|
|
} |
|
329
|
|
|
} |
|
330
|
|
|
|
|
331
|
|
|
return $ret; |
|
332
|
|
|
} |
|
333
|
|
|
|
|
334
|
|
|
/** |
|
335
|
|
|
* @param int $none |
|
336
|
|
|
* @param $seltopic |
|
337
|
|
|
* @param string $selname |
|
338
|
|
|
* @param string $onchange |
|
339
|
|
|
*/ |
|
340
|
|
|
public function makeTopicSelBox($none = 0, $seltopic = -1, $selname = '', $onchange = '') |
|
341
|
|
|
{ |
|
342
|
|
|
$xt = new MyXoopsObjectTree($this->table, 'topic_id', 'topic_pid'); |
|
343
|
|
|
if ($seltopic != -1) { |
|
344
|
|
|
$xt->makeMySelBox('topic_title', 'topic_title', $seltopic, $none, $selname, $onchange); |
|
|
|
|
|
|
345
|
|
|
} elseif (!empty($this->topic_id)) { |
|
346
|
|
|
$xt->makeMySelBox('topic_title', 'topic_title', $this->topic_id, $none, $selname, $onchange); |
|
|
|
|
|
|
347
|
|
|
} else { |
|
348
|
|
|
$xt->makeMySelBox('topic_title', 'topic_title', 0, $none, $selname, $onchange); |
|
|
|
|
|
|
349
|
|
|
} |
|
350
|
|
|
} |
|
351
|
|
|
|
|
352
|
|
|
//generates nicely formatted linked path from the root id to a given id |
|
353
|
|
|
/** |
|
354
|
|
|
* @param $funcURL |
|
355
|
|
|
* |
|
356
|
|
|
* @return mixed |
|
357
|
|
|
*/ |
|
358
|
|
View Code Duplication |
public function getNiceTopicPathFromId($funcURL) |
|
|
|
|
|
|
359
|
|
|
{ |
|
360
|
|
|
$xt = new MyXoopsObjectTree($this->table, 'topic_id', 'topic_pid'); |
|
361
|
|
|
$ret = $xt->getNicePathFromId($this->topic_id, 'topic_title', $funcURL); |
|
|
|
|
|
|
362
|
|
|
|
|
363
|
|
|
return $ret; |
|
364
|
|
|
} |
|
365
|
|
|
|
|
366
|
|
|
/** |
|
367
|
|
|
* @return mixed |
|
368
|
|
|
*/ |
|
369
|
|
View Code Duplication |
public function getAllChildTopicsId() |
|
|
|
|
|
|
370
|
|
|
{ |
|
371
|
|
|
$xt = new MyXoopsObjectTree($this->table, 'topic_id', 'topic_pid'); |
|
372
|
|
|
$ret = $xt->getAllChildId($this->topic_id, 'topic_title'); |
|
|
|
|
|
|
373
|
|
|
|
|
374
|
|
|
return $ret; |
|
375
|
|
|
} |
|
376
|
|
|
|
|
377
|
|
|
/** |
|
378
|
|
|
* @return array |
|
379
|
|
|
*/ |
|
380
|
|
|
public function getTopicsList() |
|
381
|
|
|
{ |
|
382
|
|
|
$result = $this->db->query('SELECT topic_id, topic_pid, topic_title FROM ' . $this->table); |
|
383
|
|
|
$ret = array(); |
|
384
|
|
|
$myts = MyTextSanitizer::getInstance(); |
|
385
|
|
View Code Duplication |
while ($myrow = $this->db->fetchArray($result)) { |
|
|
|
|
|
|
386
|
|
|
$ret[$myrow['topic_id']] = array('title' => $myts->htmlspecialchars($myrow['topic_title']), 'pid' => $myrow['topic_pid']); |
|
387
|
|
|
} |
|
388
|
|
|
|
|
389
|
|
|
return $ret; |
|
390
|
|
|
} |
|
391
|
|
|
|
|
392
|
|
|
/** |
|
393
|
|
|
* @param $pid |
|
394
|
|
|
* @param $title |
|
395
|
|
|
* |
|
396
|
|
|
* @return bool |
|
397
|
|
|
*/ |
|
398
|
|
|
public function topicExists($pid, $title) |
|
399
|
|
|
{ |
|
400
|
|
|
$sql = 'SELECT COUNT(*) from ' . $this->table . ' WHERE topic_pid = ' . (int)$pid . " AND topic_title = '" . trim($title) . "'"; |
|
401
|
|
|
$rs = $this->db->query($sql); |
|
402
|
|
|
list($count) = $this->db->fetchRow($rs); |
|
403
|
|
|
if ($count > 0) { |
|
404
|
|
|
return true; |
|
405
|
|
|
} else { |
|
406
|
|
|
return false; |
|
407
|
|
|
} |
|
408
|
|
|
} |
|
409
|
|
|
} |
|
410
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.