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