1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace XoopsModules\News; |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* You may not change or alter any portion of this comment or credits |
7
|
|
|
* of supporting developers from this source code or any supporting source code |
8
|
|
|
* which is considered copyrighted (c) material of the original comment or credit authors. |
9
|
|
|
* |
10
|
|
|
* This program is distributed in the hope that it will be useful, |
11
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
12
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @copyright {@link https://xoops.org/ XOOPS Project} |
17
|
|
|
* @license {@link https://www.gnu.org/licenses/gpl-2.0.html GNU GPL 2 or later} |
18
|
|
|
* @package |
19
|
|
|
* @since |
20
|
|
|
* @author XOOPS Development Team |
21
|
|
|
*/ |
22
|
|
|
|
23
|
|
|
use XoopsModules\News; |
24
|
|
|
|
25
|
|
|
//require_once XOOPS_ROOT_PATH . '/modules/news/class/xoopsstory.php'; |
26
|
|
|
//require_once XOOPS_ROOT_PATH . '/modules/news/class/xoopstopic.php'; |
27
|
|
|
//require_once XOOPS_ROOT_PATH . '/modules/news/class/tree.php'; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Class NewsTopic |
31
|
|
|
*/ |
32
|
|
|
class NewsTopic extends XoopsTopic |
33
|
|
|
{ |
34
|
|
|
public $menu; |
35
|
|
|
public $topic_description; |
36
|
|
|
public $topic_frontpage; |
37
|
|
|
public $topic_rssurl; |
38
|
|
|
public $topic_color; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param int $topicid |
42
|
|
|
*/ |
43
|
|
|
public function __construct($topicid = 0) |
44
|
|
|
{ |
45
|
|
|
/** @var \XoopsMySQLDatabase $db */ |
46
|
|
|
$this->db = \XoopsDatabaseFactory::getDatabaseConnection(); |
|
|
|
|
47
|
|
|
$this->table = $this->db->prefix('news_topics'); |
48
|
|
|
if (\is_array($topicid)) { |
|
|
|
|
49
|
|
|
$this->makeTopic($topicid); |
50
|
|
|
} elseif (0 != $topicid) { |
51
|
|
|
$this->getTopic((int)$topicid); |
52
|
|
|
} else { |
53
|
|
|
$this->topic_id = $topicid; |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @param int $none |
59
|
|
|
* @param $seltopic |
60
|
|
|
* @param string $selname |
61
|
|
|
* @param string $onchange |
62
|
|
|
* @param bool $checkRight |
63
|
|
|
* @param string $perm_type |
64
|
|
|
* |
65
|
|
|
* @return null|string |
66
|
|
|
*/ |
67
|
|
|
public function makeMyTopicSelBox( |
68
|
|
|
$none = 0, |
69
|
|
|
$seltopic = -1, |
70
|
|
|
$selname = '', |
71
|
|
|
$onchange = '', |
72
|
|
|
$checkRight = false, |
73
|
|
|
$perm_type = 'news_view' |
74
|
|
|
) { |
75
|
|
|
$perms = ''; |
76
|
|
|
if ($checkRight) { |
77
|
|
|
global $xoopsUser; |
78
|
|
|
/** @var \XoopsModuleHandler $moduleHandler */ |
79
|
|
|
$moduleHandler = \xoops_getHandler('module'); |
80
|
|
|
$newsModule = $moduleHandler->getByDirname('news'); |
81
|
|
|
$groups = \is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS; |
82
|
|
|
$grouppermHandler = \xoops_getHandler('groupperm'); |
83
|
|
|
$topics = $grouppermHandler->getItemIds($perm_type, $groups, $newsModule->getVar('mid')); |
|
|
|
|
84
|
|
|
if (\count($topics) > 0) { |
85
|
|
|
$topics = \implode(',', $topics); |
86
|
|
|
$perms = ' AND topic_id IN (' . $topics . ') '; |
87
|
|
|
} else { |
88
|
|
|
return null; |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
if (-1 != $seltopic) { |
93
|
|
|
return $this->makeMySelBox('topic_title', 'topic_title', $seltopic, $none, $selname, $onchange, $perms); |
94
|
|
|
} elseif (!empty($this->topic_id)) { |
95
|
|
|
return $this->makeMySelBox('topic_title', 'topic_title', $this->topic_id, $none, $selname, $onchange, $perms); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
return $this->makeMySelBox('topic_title', 'topic_title', 0, $none, $selname, $onchange, $perms); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* makes a nicely ordered selection box |
103
|
|
|
* |
104
|
|
|
* @param $title |
105
|
|
|
* @param string $order |
106
|
|
|
* @param int $preset_id is used to specify a preselected item |
107
|
|
|
* @param int $none set $none to 1 to add a option with value 0 |
108
|
|
|
* |
109
|
|
|
* @param string $sel_name |
110
|
|
|
* @param string $onchange |
111
|
|
|
* @param $perms |
112
|
|
|
* |
113
|
|
|
* @return string |
114
|
|
|
*/ |
115
|
|
|
public function makeMySelBox( |
116
|
|
|
$title, |
117
|
|
|
$order, |
118
|
|
|
$preset_id, |
119
|
|
|
$none, |
120
|
|
|
$sel_name, |
121
|
|
|
$onchange, |
122
|
|
|
$perms |
123
|
|
|
) { |
124
|
|
|
$myts = \MyTextSanitizer::getInstance(); |
125
|
|
|
$outbuffer = ''; |
|
|
|
|
126
|
|
|
$outbuffer = "<select name='" . $sel_name . "'"; |
127
|
|
|
if ('' !== $onchange) { |
128
|
|
|
$outbuffer .= " onchange='" . $onchange . "'"; |
129
|
|
|
} |
130
|
|
|
$outbuffer .= ">\n"; |
131
|
|
|
$sql = 'SELECT topic_id, ' . $title . ' FROM ' . $this->table . ' WHERE (topic_pid=0)' . $perms; |
132
|
|
|
if ('' !== $order) { |
133
|
|
|
$sql .= " ORDER BY $order"; |
134
|
|
|
} |
135
|
|
|
$result = $this->db->query($sql); |
136
|
|
|
if ($none) { |
137
|
|
|
$outbuffer .= "<option value='0'>----</option>\n"; |
138
|
|
|
} |
139
|
|
|
while (list($catid, $name) = $this->db->fetchRow($result)) { |
140
|
|
|
$sel = ''; |
141
|
|
|
if ($catid == $preset_id) { |
142
|
|
|
$sel = ' selected'; |
143
|
|
|
} |
144
|
|
|
$name = $myts->displayTarea($name); |
145
|
|
|
$outbuffer .= "<option value='$catid'$sel>$name</option>\n"; |
146
|
|
|
$sel = ''; |
147
|
|
|
$arr = $this->getChildTreeArray($catid, $order, $perms); |
148
|
|
|
foreach ($arr as $option) { |
149
|
|
|
$option['prefix'] = \str_replace('.', '--', $option['prefix']); |
150
|
|
|
$catpath = $option['prefix'] . ' ' . $myts->displayTarea($option[$title]); |
151
|
|
|
|
152
|
|
|
if ($option['topic_id'] == $preset_id) { |
153
|
|
|
$sel = ' selected'; |
154
|
|
|
} |
155
|
|
|
$outbuffer .= "<option value='" . $option['topic_id'] . "'$sel>$catpath</option>\n"; |
156
|
|
|
$sel = ''; |
157
|
|
|
} |
158
|
|
|
} |
159
|
|
|
$outbuffer .= "</select>\n"; |
160
|
|
|
|
161
|
|
|
return $outbuffer; |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* @param int $sel_id |
166
|
|
|
* @param string $order |
167
|
|
|
* @param string $perms |
168
|
|
|
* @param array $parray |
169
|
|
|
* @param string $r_prefix |
170
|
|
|
* |
171
|
|
|
* @return array |
172
|
|
|
*/ |
173
|
|
|
public function getChildTreeArray($sel_id = 0, $order = '', $perms = '', $parray = [], $r_prefix = '') |
174
|
|
|
{ |
175
|
|
|
$sql = 'SELECT * FROM ' . $this->table . ' WHERE (topic_pid=' . $sel_id . ')' . $perms; |
176
|
|
|
if ('' !== $order) { |
177
|
|
|
$sql .= " ORDER BY $order"; |
178
|
|
|
} |
179
|
|
|
$result = $this->db->query($sql); |
180
|
|
|
$count = $this->db->getRowsNum($result); |
181
|
|
|
if (0 == $count) { |
182
|
|
|
return $parray; |
183
|
|
|
} |
184
|
|
|
while (false !== ($row = $this->db->fetchArray($result))) { |
185
|
|
|
$row['prefix'] = $r_prefix . '.'; |
186
|
|
|
$parray[] = $row; |
187
|
|
|
$parray = $this->getChildTreeArray($row['topic_id'], $order, $perms, $parray, $row['prefix']); |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
return $parray; |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
/** |
194
|
|
|
* @param $var |
195
|
|
|
* |
196
|
|
|
* @return mixed |
197
|
|
|
*/ |
198
|
|
|
public function getVar($var) |
199
|
|
|
{ |
200
|
|
|
if (\method_exists($this, $var)) { |
201
|
|
|
return $this->{$var}(); |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
return $this->$var; |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
/** |
208
|
|
|
* Get the total number of topics in the base |
209
|
|
|
* @param bool $checkRight |
210
|
|
|
* @return mixed|null |
211
|
|
|
*/ |
212
|
|
|
public function getAllTopicsCount($checkRight = true) |
213
|
|
|
{ |
214
|
|
|
$perms = ''; |
215
|
|
|
if ($checkRight) { |
216
|
|
|
global $xoopsUser; |
217
|
|
|
/** @var \XoopsModuleHandler $moduleHandler */ |
218
|
|
|
$moduleHandler = \xoops_getHandler('module'); |
219
|
|
|
$newsModule = $moduleHandler->getByDirname('news'); |
220
|
|
|
$groups = \is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS; |
221
|
|
|
$grouppermHandler = \xoops_getHandler('groupperm'); |
222
|
|
|
$topics = $grouppermHandler->getItemIds('news_submit', $groups, $newsModule->getVar('mid')); |
223
|
|
|
if (\count($topics) > 0) { |
224
|
|
|
$topics = \implode(',', $topics); |
225
|
|
|
$perms = ' WHERE topic_id IN (' . $topics . ') '; |
226
|
|
|
} else { |
227
|
|
|
return null; |
228
|
|
|
} |
229
|
|
|
} |
230
|
|
|
|
231
|
|
|
$sql = 'SELECT count(topic_id) AS cpt FROM ' . $this->table . $perms; |
232
|
|
|
$array = $this->db->fetchArray($this->db->query($sql)); |
233
|
|
|
|
234
|
|
|
return $array['cpt']; |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
/** |
238
|
|
|
* @param bool $checkRight |
239
|
|
|
* @param string $permission |
240
|
|
|
* |
241
|
|
|
* @return array |
242
|
|
|
*/ |
243
|
|
|
public function getAllTopics($checkRight = true, $permission = 'news_view') |
244
|
|
|
{ |
245
|
|
|
$topics_arr = []; |
246
|
|
|
/** @var \XoopsMySQLDatabase $db */ |
247
|
|
|
$db = \XoopsDatabaseFactory::getDatabaseConnection(); |
248
|
|
|
$table = $db->prefix('news_topics'); |
249
|
|
|
$sql = 'SELECT * FROM ' . $table; |
250
|
|
|
if ($checkRight) { |
251
|
|
|
$topics = \XoopsModules\News\Utility::getMyItemIds($permission); |
252
|
|
|
if (0 == \count($topics)) { |
253
|
|
|
return []; |
254
|
|
|
} |
255
|
|
|
$topics = \implode(',', $topics); |
256
|
|
|
$sql .= ' WHERE topic_id IN (' . $topics . ')'; |
257
|
|
|
} |
258
|
|
|
$sql .= ' ORDER BY topic_title'; |
259
|
|
|
$result = $db->query($sql); |
260
|
|
|
while (false !== ($array = $db->fetchArray($result))) { |
|
|
|
|
261
|
|
|
$topic = new self(); |
262
|
|
|
$topic->makeTopic($array); |
263
|
|
|
$topics_arr[$array['topic_id']] = $topic; |
264
|
|
|
unset($topic); |
265
|
|
|
} |
266
|
|
|
|
267
|
|
|
return $topics_arr; |
268
|
|
|
} |
269
|
|
|
|
270
|
|
|
/** |
271
|
|
|
* Returns the number of published news per topic |
272
|
|
|
*/ |
273
|
|
|
public function getNewsCountByTopic() |
274
|
|
|
{ |
275
|
|
|
$ret = []; |
276
|
|
|
$sql = 'SELECT count(storyid) AS cpt, topicid FROM ' . $this->db->prefix('news_stories') . ' WHERE (published > 0 AND published <= ' . \time() . ') AND (expired = 0 OR expired > ' . \time() . ') GROUP BY topicid'; |
277
|
|
|
$result = $this->db->query($sql); |
278
|
|
|
while (false !== ($row = $this->db->fetchArray($result))) { |
279
|
|
|
$ret[$row['topicid']] = $row['cpt']; |
280
|
|
|
} |
281
|
|
|
|
282
|
|
|
return $ret; |
283
|
|
|
} |
284
|
|
|
|
285
|
|
|
/** |
286
|
|
|
* Returns some stats about a topic |
287
|
|
|
* @param $topicid |
288
|
|
|
* @return array |
289
|
|
|
*/ |
290
|
|
|
public function getTopicMiniStats($topicid) |
291
|
|
|
{ |
292
|
|
|
$ret = []; |
293
|
|
|
$sql = 'SELECT count(storyid) AS cpt1, sum(counter) AS cpt2 FROM ' . $this->db->prefix('news_stories') . ' WHERE (topicid=' . $topicid . ') AND (published>0 AND published <= ' . \time() . ') AND (expired = 0 OR expired > ' . \time() . ')'; |
294
|
|
|
$result = $this->db->query($sql); |
295
|
|
|
$row = $this->db->fetchArray($result); |
296
|
|
|
$ret['count'] = $row['cpt1']; |
297
|
|
|
$ret['reads'] = $row['cpt2']; |
298
|
|
|
|
299
|
|
|
return $ret; |
300
|
|
|
} |
301
|
|
|
|
302
|
|
|
/** |
303
|
|
|
* @param $value |
304
|
|
|
*/ |
305
|
|
|
public function setMenu($value) |
306
|
|
|
{ |
307
|
|
|
$this->menu = $value; |
308
|
|
|
} |
309
|
|
|
|
310
|
|
|
/** |
311
|
|
|
* @param $value |
312
|
|
|
*/ |
313
|
|
|
public function setTopic_color($value) |
314
|
|
|
{ |
315
|
|
|
$this->topic_color = $value; |
316
|
|
|
} |
317
|
|
|
|
318
|
|
|
/** |
319
|
|
|
* @param $topicid |
320
|
|
|
*/ |
321
|
|
|
public function getTopic($topicid) |
322
|
|
|
{ |
323
|
|
|
$sql = 'SELECT * FROM ' . $this->table . ' WHERE topic_id=' . $topicid . ''; |
324
|
|
|
$array = $this->db->fetchArray($this->db->query($sql)); |
325
|
|
|
$this->makeTopic($array); |
326
|
|
|
} |
327
|
|
|
|
328
|
|
|
/** |
329
|
|
|
* @param $array |
330
|
|
|
*/ |
331
|
|
|
public function makeTopic($array) |
332
|
|
|
{ |
333
|
|
|
if (\is_array($array)) { |
334
|
|
|
foreach ($array as $key => $value) { |
335
|
|
|
$this->$key = $value; |
336
|
|
|
} |
337
|
|
|
} |
338
|
|
|
} |
339
|
|
|
|
340
|
|
|
/** |
341
|
|
|
* @return bool |
342
|
|
|
*/ |
343
|
|
|
public function store() |
344
|
|
|
{ |
345
|
|
|
$myts = \MyTextSanitizer::getInstance(); |
346
|
|
|
$title = ''; |
347
|
|
|
$imgurl = ''; |
348
|
|
|
$topic_description = $myts->censorString($this->topic_description); |
349
|
|
|
$topic_description = $myts->addSlashes($topic_description); |
350
|
|
|
$topic_rssurl = $myts->addSlashes($this->topic_rssurl); |
351
|
|
|
$topic_color = $myts->addSlashes($this->topic_color); |
352
|
|
|
|
353
|
|
|
$dirname = \basename(\dirname(__DIR__)); |
354
|
|
|
|
355
|
|
|
if (isset($this->topic_title) && '' !== $this->topic_title) { |
356
|
|
|
$title = $myts->addSlashes($this->topic_title); |
357
|
|
|
} |
358
|
|
|
if (isset($this->topic_imgurl) && '' !== $this->topic_imgurl) { |
359
|
|
|
$imgurl = $myts->addSlashes($this->topic_imgurl); |
360
|
|
|
} |
361
|
|
|
if (!isset($this->topic_pid) || !\is_numeric($this->topic_pid)) { |
362
|
|
|
$this->topic_pid = 0; |
363
|
|
|
} |
364
|
|
|
$topic_frontpage = (int)$this->topic_frontpage; |
365
|
|
|
$insert = false; |
366
|
|
|
if (empty($this->topic_id)) { |
367
|
|
|
$insert = true; |
368
|
|
|
$this->topic_id = $this->db->genId($this->table . '_topic_id_seq'); |
369
|
|
|
$sql = \sprintf( |
370
|
|
|
"INSERT INTO `%s` (topic_id, topic_pid, topic_imgurl, topic_title, menu, topic_description, topic_frontpage, topic_rssurl, topic_color) VALUES (%u, %u, '%s', '%s', %u, '%s', %d, '%s', '%s')", |
371
|
|
|
$this->table, |
372
|
|
|
(int)$this->topic_id, |
373
|
|
|
(int)$this->topic_pid, |
374
|
|
|
$imgurl, |
375
|
|
|
$title, |
376
|
|
|
(int)$this->menu, |
377
|
|
|
$topic_description, |
378
|
|
|
$topic_frontpage, |
379
|
|
|
$topic_rssurl, |
380
|
|
|
$topic_color |
381
|
|
|
); |
382
|
|
|
} else { |
383
|
|
|
$sql = \sprintf( |
384
|
|
|
"UPDATE `%s` SET topic_pid = %u, topic_imgurl = '%s', topic_title = '%s', menu=%d, topic_description='%s', topic_frontpage=%d, topic_rssurl='%s', topic_color='%s' WHERE topic_id = %u", |
385
|
|
|
$this->table, |
386
|
|
|
(int)$this->topic_pid, |
387
|
|
|
$imgurl, |
388
|
|
|
$title, |
389
|
|
|
(int)$this->menu, |
390
|
|
|
$topic_description, |
391
|
|
|
$topic_frontpage, |
392
|
|
|
$topic_rssurl, |
393
|
|
|
$topic_color, |
394
|
|
|
(int)$this->topic_id |
395
|
|
|
); |
396
|
|
|
} |
397
|
|
|
if (!$result = $this->db->query($sql)) { |
|
|
|
|
398
|
|
|
// TODO: Replace with something else |
399
|
|
|
// ErrorHandler::show('0022'); |
400
|
|
|
|
401
|
|
|
$helper = Helper::getHelper($dirname); |
402
|
|
|
$helper->redirect('admin/index.php', 5, $this->db->error()); |
403
|
|
|
} elseif ($insert) { |
404
|
|
|
$this->topic_id = $this->db->getInsertId(); |
405
|
|
|
} |
406
|
|
|
|
407
|
|
|
if (true === $this->use_permission) { |
408
|
|
|
$xt = new News\XoopsTree($this->table, 'topic_id', 'topic_pid'); |
409
|
|
|
$parent_topics = $xt->getAllParentId($this->topic_id); |
410
|
|
|
if (!empty($this->m_groups) && \is_array($this->m_groups)) { |
|
|
|
|
411
|
|
|
foreach ($this->m_groups as $m_g) { |
412
|
|
|
$moderate_topics = \XoopsPerms::getPermitted($this->mid, 'ModInTopic', $m_g); |
|
|
|
|
413
|
|
|
$add = true; |
414
|
|
|
// only grant this permission when the group has this permission in all parent topics of the created topic |
415
|
|
|
foreach ($parent_topics as $p_topic) { |
416
|
|
|
if (!\in_array($p_topic, $moderate_topics)) { |
417
|
|
|
$add = false; |
418
|
|
|
continue; |
419
|
|
|
} |
420
|
|
|
} |
421
|
|
|
if (true === $add) { |
422
|
|
|
$xp = new \XoopsPerms(); |
423
|
|
|
$xp->setModuleId($this->mid); |
424
|
|
|
$xp->setName('ModInTopic'); |
425
|
|
|
$xp->setItemId($this->topic_id); |
426
|
|
|
$xp->store(); |
427
|
|
|
$xp->addGroup($m_g); |
428
|
|
|
} |
429
|
|
|
} |
430
|
|
|
} |
431
|
|
|
if (!empty($this->s_groups) && \is_array($this->s_groups)) { |
|
|
|
|
432
|
|
|
foreach ($this->s_groups as $s_g) { |
433
|
|
|
$submit_topics = \XoopsPerms::getPermitted($this->mid, 'SubmitInTopic', $s_g); |
434
|
|
|
$add = true; |
435
|
|
|
foreach ($parent_topics as $p_topic) { |
436
|
|
|
if (!\in_array($p_topic, $submit_topics)) { |
437
|
|
|
$add = false; |
438
|
|
|
continue; |
439
|
|
|
} |
440
|
|
|
} |
441
|
|
|
if (true === $add) { |
442
|
|
|
$xp = new \XoopsPerms(); |
443
|
|
|
$xp->setModuleId($this->mid); |
444
|
|
|
$xp->setName('SubmitInTopic'); |
445
|
|
|
$xp->setItemId($this->topic_id); |
446
|
|
|
$xp->store(); |
447
|
|
|
$xp->addGroup($s_g); |
448
|
|
|
} |
449
|
|
|
} |
450
|
|
|
} |
451
|
|
|
if (!empty($this->r_groups) && \is_array($this->r_groups)) { |
|
|
|
|
452
|
|
|
foreach ($this->s_groups as $r_g) { |
453
|
|
|
$read_topics = \XoopsPerms::getPermitted($this->mid, 'ReadInTopic', $r_g); |
454
|
|
|
$add = true; |
455
|
|
|
foreach ($parent_topics as $p_topic) { |
456
|
|
|
if (!\in_array($p_topic, $read_topics)) { |
457
|
|
|
$add = false; |
458
|
|
|
continue; |
459
|
|
|
} |
460
|
|
|
} |
461
|
|
|
if (true === $add) { |
462
|
|
|
$xp = new \XoopsPerms(); |
463
|
|
|
$xp->setModuleId($this->mid); |
464
|
|
|
$xp->setName('ReadInTopic'); |
465
|
|
|
$xp->setItemId($this->topic_id); |
466
|
|
|
$xp->store(); |
467
|
|
|
$xp->addGroup($r_g); |
468
|
|
|
} |
469
|
|
|
} |
470
|
|
|
} |
471
|
|
|
} |
472
|
|
|
|
473
|
|
|
return true; |
474
|
|
|
} |
475
|
|
|
|
476
|
|
|
/** |
477
|
|
|
* @param $value |
478
|
|
|
*/ |
479
|
|
|
public function setTopicRssUrl($value) |
480
|
|
|
{ |
481
|
|
|
$this->topic_rssurl = $value; |
482
|
|
|
} |
483
|
|
|
|
484
|
|
|
/** |
485
|
|
|
* @param string $format |
486
|
|
|
* |
487
|
|
|
* @return mixed |
488
|
|
|
*/ |
489
|
|
|
public function topic_rssurl($format = 'S') |
490
|
|
|
{ |
491
|
|
|
$myts = \MyTextSanitizer::getInstance(); |
492
|
|
|
switch ($format) { |
493
|
|
|
case 'S': |
494
|
|
|
$topic_rssurl = $myts->displayTarea($this->topic_rssurl); |
495
|
|
|
break; |
496
|
|
|
case 'P': |
497
|
|
|
$topic_rssurl = $myts->previewTarea($this->topic_rssurl); |
498
|
|
|
break; |
499
|
|
|
case 'F': |
500
|
|
|
case 'E': |
501
|
|
|
$topic_rssurl = htmlspecialchars($this->topic_rssurl, ENT_QUOTES | ENT_HTML5); |
502
|
|
|
break; |
503
|
|
|
} |
504
|
|
|
|
505
|
|
|
return $topic_rssurl; |
|
|
|
|
506
|
|
|
} |
507
|
|
|
|
508
|
|
|
/** |
509
|
|
|
* @param string $format |
510
|
|
|
* |
511
|
|
|
* @return mixed |
512
|
|
|
*/ |
513
|
|
|
public function topic_color($format = 'S') |
514
|
|
|
{ |
515
|
|
|
$myts = \MyTextSanitizer::getInstance(); |
516
|
|
|
switch ($format) { |
517
|
|
|
case 'S': |
518
|
|
|
$topic_color = $myts->displayTarea($this->topic_color); |
519
|
|
|
break; |
520
|
|
|
case 'P': |
521
|
|
|
$topic_color = $myts->previewTarea($this->topic_color); |
522
|
|
|
break; |
523
|
|
|
case 'F': |
524
|
|
|
case 'E': |
525
|
|
|
$topic_color = htmlspecialchars($this->topic_color, ENT_QUOTES | ENT_HTML5); |
526
|
|
|
break; |
527
|
|
|
} |
528
|
|
|
|
529
|
|
|
return $topic_color; |
|
|
|
|
530
|
|
|
} |
531
|
|
|
|
532
|
|
|
/** |
533
|
|
|
* @return mixed |
534
|
|
|
*/ |
535
|
|
|
public function menu() |
536
|
|
|
{ |
537
|
|
|
return $this->menu; |
538
|
|
|
} |
539
|
|
|
|
540
|
|
|
/** |
541
|
|
|
* @param string $format |
542
|
|
|
* |
543
|
|
|
* @return mixed |
544
|
|
|
*/ |
545
|
|
|
public function topic_description($format = 'S') |
546
|
|
|
{ |
547
|
|
|
$myts = \MyTextSanitizer::getInstance(); |
548
|
|
|
switch ($format) { |
549
|
|
|
case 'S': |
550
|
|
|
$topic_description = $myts->displayTarea($this->topic_description, 1); |
551
|
|
|
break; |
552
|
|
|
case 'P': |
553
|
|
|
$topic_description = $myts->previewTarea($this->topic_description); |
554
|
|
|
break; |
555
|
|
|
case 'F': |
556
|
|
|
case 'E': |
557
|
|
|
$topic_description = htmlspecialchars($this->topic_description, ENT_QUOTES | ENT_HTML5); |
558
|
|
|
break; |
559
|
|
|
} |
560
|
|
|
|
561
|
|
|
return $topic_description; |
|
|
|
|
562
|
|
|
} |
563
|
|
|
|
564
|
|
|
/** |
565
|
|
|
* @param string $format |
566
|
|
|
* |
567
|
|
|
* @return mixed |
568
|
|
|
*/ |
569
|
|
|
public function topic_imgurl($format = 'S') |
570
|
|
|
{ |
571
|
|
|
if ('' === \trim($this->topic_imgurl)) { |
572
|
|
|
$this->topic_imgurl = 'blank.png'; |
573
|
|
|
} |
574
|
|
|
$myts = \MyTextSanitizer::getInstance(); |
|
|
|
|
575
|
|
|
switch ($format) { |
576
|
|
|
case 'S': |
577
|
|
|
$imgurl = htmlspecialchars($this->topic_imgurl, ENT_QUOTES | ENT_HTML5); |
578
|
|
|
break; |
579
|
|
|
case 'E': |
580
|
|
|
$imgurl = htmlspecialchars($this->topic_imgurl, ENT_QUOTES | ENT_HTML5); |
581
|
|
|
break; |
582
|
|
|
case 'P': |
583
|
|
|
$imgurl = htmlspecialchars($this->topic_imgurl, ENT_QUOTES | ENT_HTML5); |
584
|
|
|
break; |
585
|
|
|
case 'F': |
586
|
|
|
$imgurl = htmlspecialchars($this->topic_imgurl, ENT_QUOTES | ENT_HTML5); |
587
|
|
|
break; |
588
|
|
|
} |
589
|
|
|
|
590
|
|
|
return $imgurl; |
|
|
|
|
591
|
|
|
} |
592
|
|
|
|
593
|
|
|
/** |
594
|
|
|
* @param $topic |
595
|
|
|
* @param $topicstitles |
596
|
|
|
* |
597
|
|
|
* @return mixed |
598
|
|
|
*/ |
599
|
|
|
public function getTopicTitleFromId($topic, &$topicstitles) |
600
|
|
|
{ |
601
|
|
|
$myts = \MyTextSanitizer::getInstance(); |
602
|
|
|
$sql = 'SELECT topic_id, topic_title, topic_imgurl FROM ' . $this->table . ' WHERE '; |
603
|
|
|
if (!\is_array($topic)) { |
604
|
|
|
$sql .= ' topic_id=' . (int)$topic; |
605
|
|
|
} elseif (\count($topic) > 0) { |
606
|
|
|
$sql .= ' topic_id IN (' . \implode(',', $topic) . ')'; |
607
|
|
|
} else { |
608
|
|
|
return null; |
609
|
|
|
} |
610
|
|
|
$result = $this->db->query($sql); |
611
|
|
|
while (false !== ($row = $this->db->fetchArray($result))) { |
612
|
|
|
$topicstitles[$row['topic_id']] = [ |
613
|
|
|
'title' => $myts->displayTarea($row['topic_title']), |
614
|
|
|
'picture' => XOOPS_URL . '/uploads/news/image/' . $row['topic_imgurl'], |
615
|
|
|
]; |
616
|
|
|
} |
617
|
|
|
|
618
|
|
|
return $topicstitles; |
619
|
|
|
} |
620
|
|
|
|
621
|
|
|
/** |
622
|
|
|
* @param bool $frontpage |
623
|
|
|
* @param bool $perms |
624
|
|
|
* |
625
|
|
|
* @return array|string |
626
|
|
|
*/ |
627
|
|
|
public function getTopicsList($frontpage = false, $perms = false) |
628
|
|
|
{ |
629
|
|
|
$sql = 'SELECT topic_id, topic_pid, topic_title, topic_color FROM ' . $this->table . ' WHERE 1 '; |
630
|
|
|
if ($frontpage) { |
631
|
|
|
$sql .= ' AND topic_frontpage=1'; |
632
|
|
|
} |
633
|
|
|
if ($perms) { |
634
|
|
|
// $topicsids = []; |
635
|
|
|
$topicsids = \XoopsModules\News\Utility::getMyItemIds(); |
636
|
|
|
if (0 == \count($topicsids)) { |
637
|
|
|
return ''; |
638
|
|
|
} |
639
|
|
|
$topics = \implode(',', $topicsids); |
640
|
|
|
$sql .= ' AND topic_id IN (' . $topics . ')'; |
641
|
|
|
} |
642
|
|
|
$result = $this->db->query($sql); |
643
|
|
|
$ret = []; |
644
|
|
|
$myts = \MyTextSanitizer::getInstance(); |
645
|
|
|
while (false !== ($myrow = $this->db->fetchArray($result))) { |
646
|
|
|
$ret[$myrow['topic_id']] = [ |
647
|
|
|
'title' => $myts->displayTarea($myrow['topic_title']), |
648
|
|
|
'pid' => $myrow['topic_pid'], |
649
|
|
|
'color' => $myrow['topic_color'], |
650
|
|
|
]; |
651
|
|
|
} |
652
|
|
|
|
653
|
|
|
return $ret; |
654
|
|
|
} |
655
|
|
|
|
656
|
|
|
/** |
657
|
|
|
* @param $value |
658
|
|
|
*/ |
659
|
|
|
public function setTopicDescription($value) |
660
|
|
|
{ |
661
|
|
|
$this->topic_description = $value; |
662
|
|
|
} |
663
|
|
|
|
664
|
|
|
/** |
665
|
|
|
* @return mixed |
666
|
|
|
*/ |
667
|
|
|
public function topic_frontpage() |
668
|
|
|
{ |
669
|
|
|
return $this->topic_frontpage; |
670
|
|
|
} |
671
|
|
|
|
672
|
|
|
/** |
673
|
|
|
* @param $value |
674
|
|
|
*/ |
675
|
|
|
public function setTopicFrontpage($value) |
676
|
|
|
{ |
677
|
|
|
$this->topic_frontpage = (int)$value; |
678
|
|
|
} |
679
|
|
|
} |
680
|
|
|
|