@@ -26,613 +26,613 @@ discard block |
||
26 | 26 | */ |
27 | 27 | class ForumHandler extends \XoopsPersistableObjectHandler |
28 | 28 | { |
29 | - /** |
|
30 | - * @param null|\XoopsDatabase $db |
|
31 | - */ |
|
32 | - public function __construct(\XoopsDatabase $db = null) |
|
33 | - { |
|
34 | - parent::__construct($db, 'newbb_forums', Forum::class, 'forum_id', 'forum_name'); |
|
35 | - } |
|
36 | - |
|
37 | - /** |
|
38 | - * @param \XoopsObject $object |
|
39 | - * @param bool $force |
|
40 | - * @return bool |
|
41 | - * @internal param \XoopsObject $forum |
|
42 | - */ |
|
43 | - |
|
44 | - public function insert(\XoopsObject $object, $force = true) //insert($forum) |
|
45 | - { |
|
46 | - $forum = $object; |
|
47 | - if (!parent::insert($forum, true)) { |
|
48 | - return false; |
|
49 | - } |
|
50 | - |
|
51 | - if ($forum->isNew()) { |
|
52 | - $this->applyPermissionTemplate($forum); |
|
53 | - } |
|
54 | - |
|
55 | - return $forum->getVar('forum_id'); |
|
56 | - } |
|
57 | - |
|
58 | - /** |
|
59 | - * @param \XoopsObject $forum |
|
60 | - * @param bool $force |
|
61 | - * @return bool |
|
62 | - */ |
|
63 | - public function delete(\XoopsObject $forum, $force = false) //delete(&$forum) |
|
64 | - { |
|
65 | - global $xoopsModule; |
|
66 | - // RMV-NOTIFY |
|
67 | - xoops_notification_deletebyitem($xoopsModule->getVar('mid'), 'forum', $forum->getVar('forum_id')); |
|
68 | - // Get list of all topics in forum, to delete them too |
|
69 | - /** @var Newbb\TopicHandler $topicHandler */ |
|
70 | - $topicHandler = Newbb\Helper::getInstance()->getHandler('Topic'); |
|
71 | - $topicHandler->deleteAll(new \Criteria('forum_id', $forum->getVar('forum_id')), true, true); |
|
72 | - $this->updateAll('parent_forum', $forum->getVar('parent_forum'), new \Criteria('parent_forum', $forum->getVar('forum_id'))); |
|
73 | - $this->deletePermission($forum); |
|
74 | - |
|
75 | - return parent::delete($forum); |
|
76 | - } |
|
77 | - |
|
78 | - /** |
|
79 | - * @param string $perm |
|
80 | - * @return mixed |
|
81 | - */ |
|
82 | - public function getIdsByPermission($perm = 'access') |
|
83 | - { |
|
84 | - /** var Newbb\PermissionHandler $permHandler */ |
|
85 | - $permHandler = Newbb\Helper::getInstance()->getHandler('Permission'); |
|
86 | - return $permHandler->getForums($perm); |
|
87 | - } |
|
88 | - |
|
89 | - /** |
|
90 | - * @param int|array $cat |
|
91 | - * @param string $permission |
|
92 | - * @param null $tags |
|
93 | - * @param bool $asObject |
|
94 | - * @return array |
|
95 | - */ |
|
96 | - public function &getByPermission($cat = 0, $permission = 'access', $tags = null, $asObject = true) |
|
97 | - { |
|
98 | - $_cachedForums = []; |
|
99 | - if (!$valid_ids = $this->getIdsByPermission($permission)) { |
|
100 | - return $_cachedForums; |
|
101 | - } |
|
102 | - |
|
103 | - $criteria = new \CriteriaCompo(new \Criteria('forum_id', '(' . implode(', ', $valid_ids) . ')', 'IN')); |
|
104 | - if (is_numeric($cat) && $cat > 0) { |
|
105 | - $criteria->add(new \Criteria('cat_id', (int)$cat)); |
|
106 | - } elseif (is_array($cat) && count($cat) > 0) { |
|
107 | - $criteria->add(new \Criteria('cat_id', '(' . implode(', ', $cat) . ')', 'IN')); |
|
108 | - } |
|
109 | - $criteria->setSort('forum_order'); |
|
110 | - $criteria->setOrder('ASC'); |
|
111 | - $_cachedForums = $this->getAll($criteria, $tags, $asObject); |
|
112 | - |
|
113 | - return $_cachedForums; |
|
114 | - } |
|
115 | - |
|
116 | - /** |
|
117 | - * @param int $categoryid |
|
118 | - * @param string $permission |
|
119 | - * @param bool $asObject |
|
120 | - * @param null $tags |
|
121 | - * @return array |
|
122 | - */ |
|
123 | - public function &getForumsByCategory($categoryid = 0, $permission = '', $asObject = true, $tags = null) |
|
124 | - { |
|
125 | - $forums = $this->getByPermission($categoryid, $permission, $tags); |
|
126 | - if ($asObject) { |
|
127 | - return $forums; |
|
128 | - } |
|
129 | - |
|
130 | - $forums_array = []; |
|
131 | - $array_cat = []; |
|
132 | - $array_forum = []; |
|
133 | - if (!is_array($forums)) { |
|
134 | - return []; |
|
135 | - } |
|
136 | - foreach (array_keys($forums) as $forumid) { |
|
137 | - $forum = $forums[$forumid]; |
|
138 | - $forums_array[$forum->getVar('parent_forum')][$forumid] = [ |
|
139 | - 'cid' => $forum->getVar('cat_id'), |
|
140 | - 'title' => $forum->getVar('forum_name') |
|
141 | - ]; |
|
142 | - } |
|
143 | - if (!isset($forums_array[0])) { |
|
144 | - $ret = []; |
|
145 | - |
|
146 | - return $ret; |
|
147 | - } |
|
148 | - foreach ($forums_array[0] as $key => $forum) { |
|
149 | - if (isset($forums_array[$key])) { |
|
150 | - $forum['sub'] = $forums_array[$key]; |
|
151 | - } |
|
152 | - $array_forum[$forum['cid']][$key] = $forum; |
|
153 | - } |
|
154 | - ksort($array_forum); |
|
155 | - unset($forums, $forums_array); |
|
156 | - |
|
157 | - return $array_forum; |
|
158 | - } |
|
159 | - |
|
160 | - /** |
|
161 | - * @param $forum |
|
162 | - * @param null $criteria |
|
163 | - * @return array |
|
164 | - */ |
|
165 | - public function getAllTopics(&$forum, $criteria = null) |
|
166 | - { |
|
167 | - global $myts, $viewAllForums; |
|
168 | - $startdate = ''; |
|
169 | - |
|
170 | - require_once $GLOBALS['xoops']->path('modules/newbb/include/functions.render.php'); |
|
171 | - require_once $GLOBALS['xoops']->path('modules/newbb/include/functions.session.php'); |
|
172 | - require_once $GLOBALS['xoops']->path('modules/newbb/include/functions.time.php'); |
|
173 | - require_once $GLOBALS['xoops']->path('modules/newbb/include/functions.read.php'); |
|
174 | - require_once $GLOBALS['xoops']->path('modules/newbb/include/functions.topic.php'); |
|
175 | - |
|
176 | - $criteria_vars = ['startdate', 'start', 'sort', 'order', 'type', 'status', 'excerpt']; |
|
177 | - foreach ($criteria_vars as $var) { |
|
178 | - ${$var} = $criteria[$var]; |
|
179 | - } |
|
180 | - |
|
181 | - $topic_lastread = newbbGetCookie('LT', true); |
|
182 | - $criteria_forum = ''; |
|
183 | - if (is_object($forum)) { |
|
184 | - $criteria_forum = ' AND t.forum_id = ' . $forum->getVar('forum_id'); |
|
185 | - $hot_threshold = $forum->getVar('hot_threshold'); |
|
186 | - } else { |
|
187 | - $hot_threshold = 10; |
|
188 | - if (is_array($forum) && count($forum) > 0) { |
|
189 | - $criteria_forum = ' AND t.forum_id IN (' . implode(',', array_keys($forum)) . ')'; |
|
190 | - } elseif (!empty($forum)) { |
|
191 | - $criteria_forum = ' AND t.forum_id =' . (int)$forum; |
|
192 | - } |
|
193 | - } |
|
194 | - |
|
195 | - $criteria_post = $startdate ? ' p.post_time > ' . $startdate : ' 1 = 1 '; |
|
196 | - $criteria_topic = empty($type) ? '' : " AND t.type_id={$type}"; |
|
197 | - $criteria_extra = ''; |
|
198 | - $criteria_approve = ' AND t.approved = 1'; |
|
199 | - $post_on = ' p.post_id = t.topic_last_post_id'; |
|
200 | - $leftjoin = ' LEFT JOIN ' . $this->db->prefix('newbb_posts') . ' p ON p.post_id = t.topic_last_post_id'; |
|
201 | - $sort_array = []; |
|
202 | - switch ($status) { |
|
203 | - case 'digest': |
|
204 | - $criteria_extra = ' AND t.topic_digest = 1'; |
|
205 | - break; |
|
206 | - |
|
207 | - case 'unreplied': |
|
208 | - $criteria_extra = ' AND t.topic_replies < 1'; |
|
209 | - break; |
|
210 | - |
|
211 | - case 'unread': |
|
212 | - if (empty($GLOBALS['xoopsModuleConfig']['read_mode'])) { |
|
213 | - } elseif (2 == $GLOBALS['xoopsModuleConfig']['read_mode']) { |
|
214 | - // START irmtfan use read_uid to find the unread posts when the user is logged in |
|
215 | - $read_uid = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getVar('uid') : 0; |
|
216 | - if (!empty($read_uid)) { |
|
217 | - $leftjoin .= ' LEFT JOIN ' . $this->db->prefix('newbb_reads_topic') . ' r ON r.read_item = t.topic_id AND r.uid = ' . $read_uid . ' '; |
|
218 | - $criteria_post .= ' AND (r.read_id IS NULL OR r.post_id < t.topic_last_post_id)'; |
|
219 | - } else { |
|
220 | - } |
|
221 | - // END irmtfan use read_uid to find the unread posts when the user is logged in |
|
222 | - } elseif (1 == $GLOBALS['xoopsModuleConfig']['read_mode']) { |
|
223 | - // START irmtfan fix read_mode = 1 bugs - for all users (member and anon) |
|
224 | - if ($time_criterion = max($GLOBALS['last_visit'], $startdate)) { |
|
225 | - $criteria_post = ' p.post_time > ' . $time_criterion; // for all users |
|
226 | - $topics = []; |
|
227 | - $topic_lastread = newbbGetCookie('LT', true); |
|
228 | - if (count($topic_lastread) > 0) { |
|
229 | - foreach ($topic_lastread as $id => $time) { |
|
230 | - if ($time > $time_criterion) { |
|
231 | - $topics[] = $id; |
|
232 | - } |
|
233 | - } |
|
234 | - } |
|
235 | - if (count($topics) > 0) { |
|
236 | - $criteria_extra = ' AND t.topic_id NOT IN (' . implode(',', $topics) . ')'; |
|
237 | - } |
|
238 | - } |
|
239 | - // END irmtfan fix read_mode = 1 bugs - for all users (member and anon) |
|
240 | - } |
|
241 | - break; |
|
242 | - case 'pending': |
|
243 | - $post_on = ' p.topic_id = t.topic_id'; |
|
244 | - $criteria_post .= ' AND p.pid = 0'; |
|
245 | - $criteria_approve = ' AND t.approved = 0'; |
|
246 | - break; |
|
247 | - |
|
248 | - case 'deleted': |
|
249 | - $criteria_approve = ' AND t.approved = -1'; |
|
250 | - break; |
|
251 | - |
|
252 | - case 'all': // For viewall.php; do not display sticky topics at first |
|
253 | - case 'active': // same as "all" |
|
254 | - break; |
|
255 | - |
|
256 | - default: |
|
257 | - if ($startdate > 0) { |
|
258 | - $criteria_post = ' (p.post_time > ' . $startdate . ' OR t.topic_sticky=1)'; |
|
259 | - } |
|
260 | - $sort_array[] = 't.topic_sticky DESC'; |
|
261 | - break; |
|
262 | - } |
|
263 | - |
|
264 | - $select = 't.*, ' . ' p.post_time as last_post_time, p.poster_name as last_poster_name, p.icon, p.post_id, p.uid'; |
|
265 | - $from = $this->db->prefix('newbb_topics') . ' t ' . $leftjoin; |
|
266 | - $where = $criteria_post . $criteria_topic . $criteria_forum . $criteria_extra . $criteria_approve; |
|
267 | - |
|
268 | - if ($excerpt) { |
|
269 | - $select .= ', p.post_karma, p.require_reply, pt.post_text'; |
|
270 | - $from .= ' LEFT JOIN ' . $this->db->prefix('newbb_posts_text') . ' pt ON pt.post_id = t.topic_last_post_id'; |
|
271 | - } |
|
272 | - if ('u.uname' === $sort) { |
|
273 | - $sort = 't.topic_poster'; |
|
274 | - } |
|
275 | - |
|
276 | - $sort_array[] = trim($sort . ' ' . $order); |
|
277 | - $sortby = implode(', ', array_filter($sort_array)); |
|
278 | - if (empty($sortby)) { |
|
279 | - $sortby = 't.topic_last_post_id DESC'; |
|
280 | - } |
|
281 | - |
|
282 | - $sql = 'SELECT ' . $select . ' FROM ' . $from . ' WHERE ' . $where . ' ORDER BY ' . $sortby; |
|
283 | - |
|
284 | - if (!$result = $this->db->query($sql, $GLOBALS['xoopsModuleConfig']['topics_per_page'], $start)) { |
|
285 | - redirect_header('index.php', 2, _MD_NEWBB_ERROROCCURED); |
|
286 | - } |
|
287 | - |
|
288 | - $sticky = 0; |
|
289 | - $topics = []; |
|
290 | - $posters = []; |
|
291 | - $reads = []; |
|
292 | - $types = []; |
|
293 | - |
|
294 | - /** @var Newbb\TypeHandler $typeHandler */ |
|
295 | - $typeHandler = Newbb\Helper::getInstance()->getHandler('Type'); |
|
296 | - $typen = $typeHandler->getByForum($forum->getVar('forum_id')); |
|
297 | - while (false !== ($myrow = $this->db->fetchArray($result))) { |
|
298 | - if ($myrow['topic_sticky']) { |
|
299 | - ++$sticky; |
|
300 | - } |
|
301 | - |
|
302 | - // ------------------------------------------------------ |
|
303 | - // topic_icon: priority: sticky -> digest -> regular |
|
304 | - |
|
305 | - if ($myrow['topic_haspoll']) { |
|
306 | - if ($myrow['topic_sticky']) { |
|
307 | - $topic_icon = newbbDisplayImage('topic_sticky', _MD_NEWBB_TOPICSTICKY) . '<br>' . newbbDisplayImage('poll', _MD_NEWBB_TOPICHASPOLL); |
|
308 | - } else { |
|
309 | - $topic_icon = newbbDisplayImage('poll', _MD_NEWBB_TOPICHASPOLL); |
|
310 | - } |
|
311 | - } elseif ($myrow['topic_sticky']) { |
|
312 | - $topic_icon = newbbDisplayImage('topic_sticky', _MD_NEWBB_TOPICSTICKY); |
|
313 | - } elseif (!empty($myrow['icon'])) { |
|
314 | - $topic_icon = '<img src="' . XOOPS_URL . '/images/subject/' . htmlspecialchars($myrow['icon'], ENT_QUOTES | ENT_HTML5) . '" alt="" />'; |
|
315 | - } else { |
|
316 | - $topic_icon = '<img src="' . XOOPS_URL . '/images/icons/no_posticon.gif" alt="" />'; |
|
317 | - } |
|
318 | - |
|
319 | - // ------------------------------------------------------ |
|
320 | - // rating_img |
|
321 | - $rating = number_format($myrow['rating'] / 2, 0); |
|
322 | - // irmtfan - add alt key for rating |
|
323 | - if ($rating < 1) { |
|
324 | - $rating_img = newbbDisplayImage('blank'); |
|
325 | - } else { |
|
326 | - $rating_img = newbbDisplayImage('rate' . $rating, constant('_MD_NEWBB_RATE' . $rating)); |
|
327 | - } |
|
328 | - // ------------------------------------------------------ |
|
329 | - // topic_page_jump |
|
330 | - $topic_page_jump = ''; |
|
331 | - $topic_page_jump_icon = ''; |
|
332 | - $totalpages = ceil(($myrow['topic_replies'] + 1) / $GLOBALS['xoopsModuleConfig']['posts_per_page']); |
|
333 | - if ($totalpages > 1) { |
|
334 | - $topic_page_jump .= ' '; |
|
335 | - $append = false; |
|
336 | - for ($i = 1; $i <= $totalpages; ++$i) { |
|
337 | - if ($i > 3 && $i < $totalpages) { |
|
338 | - if (!$append) { |
|
339 | - $topic_page_jump .= '...'; |
|
340 | - $append = true; |
|
341 | - } |
|
342 | - } else { |
|
343 | - $topic_page_jump .= '[<a href="' . XOOPS_URL . '/modules/newbb/viewtopic.php?topic_id=' . $myrow['topic_id'] . '&start=' . (($i - 1) * $GLOBALS['xoopsModuleConfig']['posts_per_page']) . '">' . $i . '</a>]'; |
|
344 | - // irmtfan remove here and move |
|
345 | - //$topic_page_jump_icon = "<a href='" . XOOPS_URL . "/modules/newbb/viewtopic.php?post_id=" . $myrow['post_id'] . "&start=" . (($i - 1) * $GLOBALS['xoopsModuleConfig']['posts_per_page']) . "'>" . newbbDisplayImage('lastposticon',_MD_NEWBB_GOTOLASTPOST) . '</a>'; |
|
346 | - } |
|
347 | - } |
|
348 | - } |
|
349 | - // irmtfan - move here for both topics with and without pages |
|
350 | - $topic_page_jump_icon = "<a href='" . XOOPS_URL . '/modules/newbb/viewtopic.php?post_id=' . $myrow['post_id'] . "'>" . newbbDisplayImage('lastposticon', _MD_NEWBB_GOTOLASTPOST) . '</a>'; |
|
351 | - |
|
352 | - // ------------------------------------------------------ |
|
353 | - // => topic array |
|
354 | - $forum_link = ''; |
|
355 | - if (!empty($viewAllForums[$myrow['forum_id']])) { |
|
356 | - $forum_link = '<a href="' . XOOPS_URL . '/modules/newbb/viewforum.php?forum=' . $myrow['forum_id'] . '">' . $viewAllForums[$myrow['forum_id']]['forum_name'] . '</a>'; |
|
357 | - } |
|
358 | - |
|
359 | - $topic_title = $myts->htmlSpecialChars($myrow['topic_title']); |
|
360 | - // irmtfan remove here and move to for loop |
|
361 | - //if ($myrow['type_id'] > 0) { |
|
362 | - //$topic_title = '<span style="color:'.$typen[$myrow["type_id"]]["type_color"].'">['.$typen[$myrow["type_id"]]["type_name"].']</span> '.$topic_title.''; |
|
363 | - //} |
|
364 | - if ($myrow['topic_digest']) { |
|
365 | - $topic_title = "<span class='digest'>" . $topic_title . '</span>'; |
|
366 | - } |
|
367 | - |
|
368 | - if (0 == $excerpt) { |
|
369 | - $topic_excerpt = ''; |
|
370 | - } elseif (($myrow['post_karma'] > 0 || $myrow['require_reply'] > 0) && !newbbIsAdmin($forum)) { |
|
371 | - $topic_excerpt = ''; |
|
372 | - } else { |
|
373 | - $topic_excerpt = xoops_substr(newbbHtml2text($myts->displayTarea($myrow['post_text'])), 0, $excerpt); |
|
374 | - $topic_excerpt = str_replace('[', '[', $myts->htmlSpecialChars($topic_excerpt)); |
|
375 | - } |
|
376 | - // START irmtfan move here |
|
377 | - $topics[$myrow['topic_id']] = [ |
|
378 | - 'topic_id' => $myrow['topic_id'], |
|
379 | - 'topic_icon' => $topic_icon, |
|
380 | - 'type_id' => $myrow['type_id'], |
|
381 | - //'type_text' => $topic_prefix,/*irmtfan remove here and move to for loop*/ |
|
382 | - 'topic_title' => $topic_title, |
|
383 | - //'topic_link' => XOOPS_URL . '/modules/newbb/viewtopic.php?topic_id=' . $myrow['topic_id'], |
|
384 | - 'topic_link' => 'viewtopic.php?topic_id=' . $myrow['topic_id'], |
|
385 | - 'rating_img' => $rating_img, |
|
386 | - 'topic_page_jump' => $topic_page_jump, |
|
387 | - 'topic_page_jump_icon' => $topic_page_jump_icon, |
|
388 | - 'topic_replies' => $myrow['topic_replies'], |
|
389 | - |
|
390 | - 'topic_digest' => $myrow['topic_digest'], |
|
391 | - //mb |
|
392 | - |
|
393 | - 'topic_poster_uid' => $myrow['topic_poster'], |
|
394 | - 'topic_poster_name' => $myts->htmlSpecialChars($myrow['poster_name'] ?: $GLOBALS['xoopsConfig']['anonymous']), |
|
395 | - 'topic_views' => $myrow['topic_views'], |
|
396 | - 'topic_time' => newbbFormatTimestamp($myrow['topic_time']), |
|
397 | - 'topic_last_posttime' => newbbFormatTimestamp($myrow['last_post_time']), |
|
398 | - 'topic_last_poster_uid' => $myrow['uid'], |
|
399 | - 'topic_last_poster_name' => $myts->htmlSpecialChars($myrow['last_poster_name'] ?: $GLOBALS['xoopsConfig']['anonymous']), |
|
400 | - 'topic_forum_link' => $forum_link, |
|
401 | - 'topic_excerpt' => $topic_excerpt, |
|
402 | - 'stick' => empty($myrow['topic_sticky']), |
|
403 | - 'stats' => [ |
|
404 | - $myrow['topic_status'], |
|
405 | - $myrow['topic_digest'], |
|
406 | - $myrow['topic_replies'] |
|
407 | - ], |
|
408 | - /* irmtfan uncomment use ib the for loop*/ |
|
409 | - //"topic_poster" => $topic_poster,/*irmtfan remove here and move to for loop*/ |
|
410 | - //"topic_last_poster" => $topic_last_poster,/*irmtfan remove here and move to for loop*/ |
|
411 | - //"topic_folder" => newbbDisplayImage($topic_folder,$topic_folder_text),/*irmtfan remove here and move to for loop*/ |
|
412 | - ]; |
|
413 | - // END irmtfan move here |
|
414 | - /* users */ |
|
415 | - $posters[$myrow['topic_poster']] = 1; |
|
416 | - $posters[$myrow['uid']] = 1; |
|
417 | - // reads |
|
418 | - if (!empty($GLOBALS['xoopsModuleConfig']['read_mode'])) { |
|
419 | - $reads[$myrow['topic_id']] = (1 == $GLOBALS['xoopsModuleConfig']['read_mode']) ? $myrow['last_post_time'] : $myrow['topic_last_post_id']; |
|
420 | - } |
|
421 | - }// irmtfan while end |
|
422 | - // START irmtfan move to a for loop |
|
423 | - $posters_name = newbbGetUnameFromIds(array_keys($posters), $GLOBALS['xoopsModuleConfig']['show_realname'], true); |
|
424 | - //$topic_poster = newbbGetUnameFromId($myrow['topic_poster'], $GLOBALS['xoopsModuleConfig']['show_realname'], true); |
|
425 | - //$topic_last_poster = newbbGetUnameFromId($myrow['uid'], $GLOBALS['xoopsModuleConfig']['show_realname'], true); |
|
426 | - $topic_isRead = newbbIsRead('topic', $reads); |
|
427 | - foreach (array_keys($topics) as $id) { |
|
428 | - $topics[$id]['topic_read'] = empty($topic_isRead[$id]) ? 0 : 1; // add topic-read/topic-new smarty variable |
|
429 | - if (!empty($topics[$id]['type_id']) && isset($typen[$topics[$id]['type_id']])) { |
|
430 | - $topics[$id]['topic_title'] = getTopicTitle($topics[$id]['topic_title'], $typen[$topics[$id]['type_id']]['type_name'], $typen[$topics[$id]['type_id']]['type_color']); |
|
431 | - } |
|
432 | - //$topic_prefix = (!empty($typen[$myrow['type_id']])) ? getTopicTitle("", $typen[$myrow['type_id']]["type_name"], $typen[$myrow['type_id']]["type_color"]) : ""; |
|
433 | - $topics[$id]['topic_poster'] = !empty($posters_name[$topics[$id]['topic_poster_uid']]) ? $posters_name[$topics[$id]['topic_poster_uid']] : $topics[$id]['topic_poster_name']; |
|
434 | - $topics[$id]['topic_last_poster'] = !empty($posters_name[$topics[$id]['topic_last_poster_uid']]) ? $posters_name[$topics[$id]['topic_last_poster_uid']] : $topics[$id]['topic_last_poster_name']; |
|
435 | - |
|
436 | - // ------------------------------------------------------ |
|
437 | - // topic_folder: priority: newhot -> hot/new -> regular |
|
438 | - list($topic_status, $topic_digest, $topic_replies) = $topics[$id]['stats']; |
|
439 | - if (1 == $topic_status) { |
|
440 | - $topic_folder = 'topic_locked'; |
|
441 | - $topic_folder_text = _MD_NEWBB_TOPICLOCKED; |
|
442 | - } else { |
|
443 | - if ($topic_digest) { |
|
444 | - $topic_folder = 'topic_digest'; |
|
445 | - $topic_folder_text = _MD_NEWBB_TOPICDIGEST; |
|
446 | - } elseif ($topic_replies >= $hot_threshold) { |
|
447 | - $topic_folder = empty($topic_isRead[$id]) ? 'topic_hot_new' : 'topic_hot'; |
|
448 | - $topic_folder_text = empty($topic_isRead[$id]) ? _MD_NEWBB_MORETHAN : _MD_NEWBB_MORETHAN2; |
|
449 | - } else { |
|
450 | - $topic_folder = empty($topic_isRead[$id]) ? 'topic_new' : 'topic'; |
|
451 | - $topic_folder_text = empty($topic_isRead[$id]) ? _MD_NEWBB_NEWPOSTS : _MD_NEWBB_NONEWPOSTS; |
|
452 | - } |
|
453 | - } |
|
454 | - $topics[$id]['topic_folder'] = newbbDisplayImage($topic_folder, $topic_folder_text); |
|
455 | - unset($topics[$id]['topic_poster_name'], $topics[$id]['topic_last_poster_name'], $topics[$id]['stats']); |
|
456 | - } // irmtfan end for loop |
|
457 | - // END irmtfan move to a for loop |
|
458 | - if (count($topics) > 0) { |
|
459 | - $sql = ' SELECT DISTINCT topic_id FROM ' . $this->db->prefix('newbb_posts') . " WHERE attachment != ''" . ' AND topic_id IN (' . implode(',', array_keys($topics)) . ')'; |
|
460 | - if ($result = $this->db->query($sql)) { |
|
461 | - while (false !== (list($topic_id) = $this->db->fetchRow($result))) { |
|
462 | - $topics[$topic_id]['attachment'] = ' ' . newbbDisplayImage('attachment', _MD_NEWBB_TOPICSHASATT); |
|
463 | - } |
|
464 | - } |
|
465 | - } |
|
466 | - |
|
467 | - return [$topics, $sticky]; |
|
468 | - } |
|
469 | - |
|
470 | - /** |
|
471 | - * @param $forum |
|
472 | - * @param $startdate |
|
473 | - * @param $type |
|
474 | - * @return null|int |
|
475 | - */ |
|
476 | - public function getTopicCount(&$forum, $startdate, $type) |
|
477 | - { |
|
478 | - require_once $GLOBALS['xoops']->path('modules/newbb/include/functions.session.php'); |
|
479 | - |
|
480 | - $criteria_extra = ''; |
|
481 | - $criteria_approve = ' AND t.approved = 1'; // any others? |
|
482 | - $leftjoin = ' LEFT JOIN ' . $this->db->prefix('newbb_posts') . ' p ON p.post_id = t.topic_last_post_id'; |
|
483 | - $criteria_post = ' p.post_time > ' . $startdate; |
|
484 | - switch ($type) { |
|
485 | - case 'digest': |
|
486 | - $criteria_extra = ' AND topic_digest = 1'; |
|
487 | - break; |
|
488 | - case 'unreplied': |
|
489 | - $criteria_extra = ' AND topic_replies < 1'; |
|
490 | - break; |
|
491 | - case 'unread': |
|
492 | - if (empty($GLOBALS['xoopsModuleConfig']['read_mode'])) { |
|
493 | - } elseif (2 == $GLOBALS['xoopsModuleConfig']['read_mode']) { |
|
494 | - // START irmtfan use read_uid to find the unread posts when the user is logged in |
|
495 | - |
|
496 | - $read_uid = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getVar('uid') : 0; |
|
497 | - if (!empty($read_uid)) { |
|
498 | - $leftjoin .= ' LEFT JOIN ' . $this->db->prefix('newbb_reads_topic') . ' r ON r.read_item = t.topic_id AND r.uid = ' . $read_uid . ' '; |
|
499 | - $criteria_post .= ' AND (r.read_id IS NULL OR r.post_id < t.topic_last_post_id)'; |
|
500 | - } else { |
|
501 | - } |
|
502 | - // END irmtfan use read_uid to find the unread posts when the user is logged in |
|
503 | - } elseif (1 == $GLOBALS['xoopsModuleConfig']['read_mode']) { |
|
504 | - // START irmtfan fix read_mode = 1 bugs - for all users (member and anon) |
|
505 | - if ($time_criterion = max($GLOBALS['last_visit'], $startdate)) { |
|
506 | - $criteria_post = ' p.post_time > ' . $time_criterion; // for all users |
|
507 | - $topics = []; |
|
508 | - $topic_lastread = newbbGetCookie('LT', true); |
|
509 | - if (count($topic_lastread) > 0) { |
|
510 | - foreach ($topic_lastread as $id => $time) { |
|
511 | - if ($time > $time_criterion) { |
|
512 | - $topics[] = $id; |
|
513 | - } |
|
514 | - } |
|
515 | - } |
|
516 | - if (count($topics) > 0) { |
|
517 | - $criteria_extra = ' AND t.topic_id NOT IN (' . implode(',', $topics) . ')'; |
|
518 | - } |
|
519 | - } |
|
520 | - // END irmtfan fix read_mode = 1 bugs - for all users (member and anon) |
|
521 | - } |
|
522 | - break; |
|
523 | - case 'pending': |
|
524 | - $criteria_approve = ' AND t.approved = 0'; |
|
525 | - break; |
|
526 | - case 'deleted': |
|
527 | - $criteria_approve = ' AND t.approved = -1'; |
|
528 | - break; |
|
529 | - case 'all': |
|
530 | - break; |
|
531 | - default: |
|
532 | - $criteria_post = ' (p.post_time > ' . $startdate . ' OR t.topic_sticky=1)'; |
|
533 | - break; |
|
534 | - } |
|
535 | - $criteria_forum = ''; |
|
536 | - if (is_object($forum)) { |
|
537 | - $criteria_forum = ' AND t.forum_id = ' . $forum->getVar('forum_id'); |
|
538 | - } else { |
|
539 | - if (is_array($forum) && count($forum) > 0) { |
|
540 | - $criteria_forum = ' AND t.forum_id IN (' . implode(',', array_keys($forum)) . ')'; |
|
541 | - } elseif (!empty($forum)) { |
|
542 | - $criteria_forum = ' AND t.forum_id =' . (int)$forum; |
|
543 | - } |
|
544 | - } |
|
545 | - |
|
546 | - $sql = 'SELECT COUNT(*) AS count FROM ' . $this->db->prefix('newbb_topics') . ' t ' . $leftjoin; |
|
547 | - $sql .= ' WHERE ' . $criteria_post . $criteria_forum . $criteria_extra . $criteria_approve; |
|
548 | - if (!$result = $this->db->query($sql)) { |
|
549 | - //xoops_error($this->db->error().'<br>'.$sql); |
|
550 | - return null; |
|
551 | - } |
|
552 | - $myrow = $this->db->fetchArray($result); |
|
553 | - $count = $myrow['count']; |
|
554 | - |
|
555 | - return $count; |
|
556 | - } |
|
557 | - |
|
558 | - // get permission |
|
559 | - |
|
560 | - /** |
|
561 | - * @param $forum |
|
562 | - * @param string $type |
|
563 | - * @param bool $checkCategory |
|
564 | - * @return bool |
|
565 | - */ |
|
566 | - public function getPermission($forum, $type = 'access', $checkCategory = true) |
|
567 | - { |
|
568 | - global $xoopsModule; |
|
569 | - static $_cachedPerms; |
|
570 | - |
|
571 | - if ('all' === $type) { |
|
572 | - return true; |
|
573 | - } |
|
574 | - |
|
575 | - require_once dirname(__DIR__) . '/include/functions.user.php'; |
|
576 | - if (newbbIsAdmin($forum)) { |
|
577 | - return true; |
|
578 | - } |
|
579 | - //if ($GLOBALS["xoopsUserIsAdmin"] && $xoopsModule->getVar("dirname") === "newbb") { |
|
580 | - //return true; |
|
581 | - //} |
|
582 | - |
|
583 | - if (!is_object($forum)) { |
|
584 | - $forum = $this->get($forum); |
|
585 | - } |
|
586 | - |
|
587 | - if (!empty($checkCategory)) { |
|
588 | - /** @var Newbb\CategoryHandler $categoryHandler */ |
|
589 | - $categoryHandler = Newbb\Helper::getInstance()->getHandler('Category'); |
|
590 | - $categoryPerm = $categoryHandler->getPermission($forum->getVar('cat_id')); |
|
591 | - if (!$categoryPerm) { |
|
592 | - return false; |
|
593 | - } |
|
594 | - } |
|
595 | - |
|
596 | - $type = strtolower($type); |
|
597 | - // START irmtfan commented and removed |
|
598 | - //if ('moderate' === $type) { |
|
599 | - //require_once $GLOBALS['xoops']->path('modules/newbb/include/functions.user.php'); |
|
600 | - //$permission = newbbIsModerator($forum); |
|
601 | - //} else { |
|
602 | - $forum_id = $forum->getVar('forum_id'); |
|
603 | - /** var Newbb\PermissionHandler $permHandler */ |
|
604 | - $permHandler = Newbb\Helper::getInstance()->getHandler('Permission'); |
|
605 | - $permission = $permHandler->getPermission('forum', $type, $forum_id); |
|
606 | - //} |
|
607 | - // END irmtfan commented and removed |
|
608 | - return $permission; |
|
609 | - } |
|
610 | - |
|
611 | - /** |
|
612 | - * @param $forum |
|
613 | - * @return mixed |
|
614 | - */ |
|
615 | - public function deletePermission(&$forum) |
|
616 | - { |
|
617 | - /** var Newbb\PermissionHandler $permHandler */ |
|
618 | - $permHandler = Newbb\Helper::getInstance()->getHandler('Permission'); |
|
619 | - |
|
620 | - return $permHandler->deleteByForum($forum->getVar('forum_id')); |
|
621 | - } |
|
622 | - |
|
623 | - /** |
|
624 | - * @param $forum |
|
625 | - * @return mixed |
|
626 | - */ |
|
627 | - public function applyPermissionTemplate(&$forum) |
|
628 | - { |
|
629 | - /** var Newbb\PermissionHandler $permHandler */ |
|
630 | - $permHandler = Newbb\Helper::getInstance()->getHandler('Permission'); |
|
631 | - |
|
632 | - return $permHandler->applyTemplate($forum->getVar('forum_id')); |
|
633 | - } |
|
634 | - |
|
635 | - /* |
|
29 | + /** |
|
30 | + * @param null|\XoopsDatabase $db |
|
31 | + */ |
|
32 | + public function __construct(\XoopsDatabase $db = null) |
|
33 | + { |
|
34 | + parent::__construct($db, 'newbb_forums', Forum::class, 'forum_id', 'forum_name'); |
|
35 | + } |
|
36 | + |
|
37 | + /** |
|
38 | + * @param \XoopsObject $object |
|
39 | + * @param bool $force |
|
40 | + * @return bool |
|
41 | + * @internal param \XoopsObject $forum |
|
42 | + */ |
|
43 | + |
|
44 | + public function insert(\XoopsObject $object, $force = true) //insert($forum) |
|
45 | + { |
|
46 | + $forum = $object; |
|
47 | + if (!parent::insert($forum, true)) { |
|
48 | + return false; |
|
49 | + } |
|
50 | + |
|
51 | + if ($forum->isNew()) { |
|
52 | + $this->applyPermissionTemplate($forum); |
|
53 | + } |
|
54 | + |
|
55 | + return $forum->getVar('forum_id'); |
|
56 | + } |
|
57 | + |
|
58 | + /** |
|
59 | + * @param \XoopsObject $forum |
|
60 | + * @param bool $force |
|
61 | + * @return bool |
|
62 | + */ |
|
63 | + public function delete(\XoopsObject $forum, $force = false) //delete(&$forum) |
|
64 | + { |
|
65 | + global $xoopsModule; |
|
66 | + // RMV-NOTIFY |
|
67 | + xoops_notification_deletebyitem($xoopsModule->getVar('mid'), 'forum', $forum->getVar('forum_id')); |
|
68 | + // Get list of all topics in forum, to delete them too |
|
69 | + /** @var Newbb\TopicHandler $topicHandler */ |
|
70 | + $topicHandler = Newbb\Helper::getInstance()->getHandler('Topic'); |
|
71 | + $topicHandler->deleteAll(new \Criteria('forum_id', $forum->getVar('forum_id')), true, true); |
|
72 | + $this->updateAll('parent_forum', $forum->getVar('parent_forum'), new \Criteria('parent_forum', $forum->getVar('forum_id'))); |
|
73 | + $this->deletePermission($forum); |
|
74 | + |
|
75 | + return parent::delete($forum); |
|
76 | + } |
|
77 | + |
|
78 | + /** |
|
79 | + * @param string $perm |
|
80 | + * @return mixed |
|
81 | + */ |
|
82 | + public function getIdsByPermission($perm = 'access') |
|
83 | + { |
|
84 | + /** var Newbb\PermissionHandler $permHandler */ |
|
85 | + $permHandler = Newbb\Helper::getInstance()->getHandler('Permission'); |
|
86 | + return $permHandler->getForums($perm); |
|
87 | + } |
|
88 | + |
|
89 | + /** |
|
90 | + * @param int|array $cat |
|
91 | + * @param string $permission |
|
92 | + * @param null $tags |
|
93 | + * @param bool $asObject |
|
94 | + * @return array |
|
95 | + */ |
|
96 | + public function &getByPermission($cat = 0, $permission = 'access', $tags = null, $asObject = true) |
|
97 | + { |
|
98 | + $_cachedForums = []; |
|
99 | + if (!$valid_ids = $this->getIdsByPermission($permission)) { |
|
100 | + return $_cachedForums; |
|
101 | + } |
|
102 | + |
|
103 | + $criteria = new \CriteriaCompo(new \Criteria('forum_id', '(' . implode(', ', $valid_ids) . ')', 'IN')); |
|
104 | + if (is_numeric($cat) && $cat > 0) { |
|
105 | + $criteria->add(new \Criteria('cat_id', (int)$cat)); |
|
106 | + } elseif (is_array($cat) && count($cat) > 0) { |
|
107 | + $criteria->add(new \Criteria('cat_id', '(' . implode(', ', $cat) . ')', 'IN')); |
|
108 | + } |
|
109 | + $criteria->setSort('forum_order'); |
|
110 | + $criteria->setOrder('ASC'); |
|
111 | + $_cachedForums = $this->getAll($criteria, $tags, $asObject); |
|
112 | + |
|
113 | + return $_cachedForums; |
|
114 | + } |
|
115 | + |
|
116 | + /** |
|
117 | + * @param int $categoryid |
|
118 | + * @param string $permission |
|
119 | + * @param bool $asObject |
|
120 | + * @param null $tags |
|
121 | + * @return array |
|
122 | + */ |
|
123 | + public function &getForumsByCategory($categoryid = 0, $permission = '', $asObject = true, $tags = null) |
|
124 | + { |
|
125 | + $forums = $this->getByPermission($categoryid, $permission, $tags); |
|
126 | + if ($asObject) { |
|
127 | + return $forums; |
|
128 | + } |
|
129 | + |
|
130 | + $forums_array = []; |
|
131 | + $array_cat = []; |
|
132 | + $array_forum = []; |
|
133 | + if (!is_array($forums)) { |
|
134 | + return []; |
|
135 | + } |
|
136 | + foreach (array_keys($forums) as $forumid) { |
|
137 | + $forum = $forums[$forumid]; |
|
138 | + $forums_array[$forum->getVar('parent_forum')][$forumid] = [ |
|
139 | + 'cid' => $forum->getVar('cat_id'), |
|
140 | + 'title' => $forum->getVar('forum_name') |
|
141 | + ]; |
|
142 | + } |
|
143 | + if (!isset($forums_array[0])) { |
|
144 | + $ret = []; |
|
145 | + |
|
146 | + return $ret; |
|
147 | + } |
|
148 | + foreach ($forums_array[0] as $key => $forum) { |
|
149 | + if (isset($forums_array[$key])) { |
|
150 | + $forum['sub'] = $forums_array[$key]; |
|
151 | + } |
|
152 | + $array_forum[$forum['cid']][$key] = $forum; |
|
153 | + } |
|
154 | + ksort($array_forum); |
|
155 | + unset($forums, $forums_array); |
|
156 | + |
|
157 | + return $array_forum; |
|
158 | + } |
|
159 | + |
|
160 | + /** |
|
161 | + * @param $forum |
|
162 | + * @param null $criteria |
|
163 | + * @return array |
|
164 | + */ |
|
165 | + public function getAllTopics(&$forum, $criteria = null) |
|
166 | + { |
|
167 | + global $myts, $viewAllForums; |
|
168 | + $startdate = ''; |
|
169 | + |
|
170 | + require_once $GLOBALS['xoops']->path('modules/newbb/include/functions.render.php'); |
|
171 | + require_once $GLOBALS['xoops']->path('modules/newbb/include/functions.session.php'); |
|
172 | + require_once $GLOBALS['xoops']->path('modules/newbb/include/functions.time.php'); |
|
173 | + require_once $GLOBALS['xoops']->path('modules/newbb/include/functions.read.php'); |
|
174 | + require_once $GLOBALS['xoops']->path('modules/newbb/include/functions.topic.php'); |
|
175 | + |
|
176 | + $criteria_vars = ['startdate', 'start', 'sort', 'order', 'type', 'status', 'excerpt']; |
|
177 | + foreach ($criteria_vars as $var) { |
|
178 | + ${$var} = $criteria[$var]; |
|
179 | + } |
|
180 | + |
|
181 | + $topic_lastread = newbbGetCookie('LT', true); |
|
182 | + $criteria_forum = ''; |
|
183 | + if (is_object($forum)) { |
|
184 | + $criteria_forum = ' AND t.forum_id = ' . $forum->getVar('forum_id'); |
|
185 | + $hot_threshold = $forum->getVar('hot_threshold'); |
|
186 | + } else { |
|
187 | + $hot_threshold = 10; |
|
188 | + if (is_array($forum) && count($forum) > 0) { |
|
189 | + $criteria_forum = ' AND t.forum_id IN (' . implode(',', array_keys($forum)) . ')'; |
|
190 | + } elseif (!empty($forum)) { |
|
191 | + $criteria_forum = ' AND t.forum_id =' . (int)$forum; |
|
192 | + } |
|
193 | + } |
|
194 | + |
|
195 | + $criteria_post = $startdate ? ' p.post_time > ' . $startdate : ' 1 = 1 '; |
|
196 | + $criteria_topic = empty($type) ? '' : " AND t.type_id={$type}"; |
|
197 | + $criteria_extra = ''; |
|
198 | + $criteria_approve = ' AND t.approved = 1'; |
|
199 | + $post_on = ' p.post_id = t.topic_last_post_id'; |
|
200 | + $leftjoin = ' LEFT JOIN ' . $this->db->prefix('newbb_posts') . ' p ON p.post_id = t.topic_last_post_id'; |
|
201 | + $sort_array = []; |
|
202 | + switch ($status) { |
|
203 | + case 'digest': |
|
204 | + $criteria_extra = ' AND t.topic_digest = 1'; |
|
205 | + break; |
|
206 | + |
|
207 | + case 'unreplied': |
|
208 | + $criteria_extra = ' AND t.topic_replies < 1'; |
|
209 | + break; |
|
210 | + |
|
211 | + case 'unread': |
|
212 | + if (empty($GLOBALS['xoopsModuleConfig']['read_mode'])) { |
|
213 | + } elseif (2 == $GLOBALS['xoopsModuleConfig']['read_mode']) { |
|
214 | + // START irmtfan use read_uid to find the unread posts when the user is logged in |
|
215 | + $read_uid = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getVar('uid') : 0; |
|
216 | + if (!empty($read_uid)) { |
|
217 | + $leftjoin .= ' LEFT JOIN ' . $this->db->prefix('newbb_reads_topic') . ' r ON r.read_item = t.topic_id AND r.uid = ' . $read_uid . ' '; |
|
218 | + $criteria_post .= ' AND (r.read_id IS NULL OR r.post_id < t.topic_last_post_id)'; |
|
219 | + } else { |
|
220 | + } |
|
221 | + // END irmtfan use read_uid to find the unread posts when the user is logged in |
|
222 | + } elseif (1 == $GLOBALS['xoopsModuleConfig']['read_mode']) { |
|
223 | + // START irmtfan fix read_mode = 1 bugs - for all users (member and anon) |
|
224 | + if ($time_criterion = max($GLOBALS['last_visit'], $startdate)) { |
|
225 | + $criteria_post = ' p.post_time > ' . $time_criterion; // for all users |
|
226 | + $topics = []; |
|
227 | + $topic_lastread = newbbGetCookie('LT', true); |
|
228 | + if (count($topic_lastread) > 0) { |
|
229 | + foreach ($topic_lastread as $id => $time) { |
|
230 | + if ($time > $time_criterion) { |
|
231 | + $topics[] = $id; |
|
232 | + } |
|
233 | + } |
|
234 | + } |
|
235 | + if (count($topics) > 0) { |
|
236 | + $criteria_extra = ' AND t.topic_id NOT IN (' . implode(',', $topics) . ')'; |
|
237 | + } |
|
238 | + } |
|
239 | + // END irmtfan fix read_mode = 1 bugs - for all users (member and anon) |
|
240 | + } |
|
241 | + break; |
|
242 | + case 'pending': |
|
243 | + $post_on = ' p.topic_id = t.topic_id'; |
|
244 | + $criteria_post .= ' AND p.pid = 0'; |
|
245 | + $criteria_approve = ' AND t.approved = 0'; |
|
246 | + break; |
|
247 | + |
|
248 | + case 'deleted': |
|
249 | + $criteria_approve = ' AND t.approved = -1'; |
|
250 | + break; |
|
251 | + |
|
252 | + case 'all': // For viewall.php; do not display sticky topics at first |
|
253 | + case 'active': // same as "all" |
|
254 | + break; |
|
255 | + |
|
256 | + default: |
|
257 | + if ($startdate > 0) { |
|
258 | + $criteria_post = ' (p.post_time > ' . $startdate . ' OR t.topic_sticky=1)'; |
|
259 | + } |
|
260 | + $sort_array[] = 't.topic_sticky DESC'; |
|
261 | + break; |
|
262 | + } |
|
263 | + |
|
264 | + $select = 't.*, ' . ' p.post_time as last_post_time, p.poster_name as last_poster_name, p.icon, p.post_id, p.uid'; |
|
265 | + $from = $this->db->prefix('newbb_topics') . ' t ' . $leftjoin; |
|
266 | + $where = $criteria_post . $criteria_topic . $criteria_forum . $criteria_extra . $criteria_approve; |
|
267 | + |
|
268 | + if ($excerpt) { |
|
269 | + $select .= ', p.post_karma, p.require_reply, pt.post_text'; |
|
270 | + $from .= ' LEFT JOIN ' . $this->db->prefix('newbb_posts_text') . ' pt ON pt.post_id = t.topic_last_post_id'; |
|
271 | + } |
|
272 | + if ('u.uname' === $sort) { |
|
273 | + $sort = 't.topic_poster'; |
|
274 | + } |
|
275 | + |
|
276 | + $sort_array[] = trim($sort . ' ' . $order); |
|
277 | + $sortby = implode(', ', array_filter($sort_array)); |
|
278 | + if (empty($sortby)) { |
|
279 | + $sortby = 't.topic_last_post_id DESC'; |
|
280 | + } |
|
281 | + |
|
282 | + $sql = 'SELECT ' . $select . ' FROM ' . $from . ' WHERE ' . $where . ' ORDER BY ' . $sortby; |
|
283 | + |
|
284 | + if (!$result = $this->db->query($sql, $GLOBALS['xoopsModuleConfig']['topics_per_page'], $start)) { |
|
285 | + redirect_header('index.php', 2, _MD_NEWBB_ERROROCCURED); |
|
286 | + } |
|
287 | + |
|
288 | + $sticky = 0; |
|
289 | + $topics = []; |
|
290 | + $posters = []; |
|
291 | + $reads = []; |
|
292 | + $types = []; |
|
293 | + |
|
294 | + /** @var Newbb\TypeHandler $typeHandler */ |
|
295 | + $typeHandler = Newbb\Helper::getInstance()->getHandler('Type'); |
|
296 | + $typen = $typeHandler->getByForum($forum->getVar('forum_id')); |
|
297 | + while (false !== ($myrow = $this->db->fetchArray($result))) { |
|
298 | + if ($myrow['topic_sticky']) { |
|
299 | + ++$sticky; |
|
300 | + } |
|
301 | + |
|
302 | + // ------------------------------------------------------ |
|
303 | + // topic_icon: priority: sticky -> digest -> regular |
|
304 | + |
|
305 | + if ($myrow['topic_haspoll']) { |
|
306 | + if ($myrow['topic_sticky']) { |
|
307 | + $topic_icon = newbbDisplayImage('topic_sticky', _MD_NEWBB_TOPICSTICKY) . '<br>' . newbbDisplayImage('poll', _MD_NEWBB_TOPICHASPOLL); |
|
308 | + } else { |
|
309 | + $topic_icon = newbbDisplayImage('poll', _MD_NEWBB_TOPICHASPOLL); |
|
310 | + } |
|
311 | + } elseif ($myrow['topic_sticky']) { |
|
312 | + $topic_icon = newbbDisplayImage('topic_sticky', _MD_NEWBB_TOPICSTICKY); |
|
313 | + } elseif (!empty($myrow['icon'])) { |
|
314 | + $topic_icon = '<img src="' . XOOPS_URL . '/images/subject/' . htmlspecialchars($myrow['icon'], ENT_QUOTES | ENT_HTML5) . '" alt="" />'; |
|
315 | + } else { |
|
316 | + $topic_icon = '<img src="' . XOOPS_URL . '/images/icons/no_posticon.gif" alt="" />'; |
|
317 | + } |
|
318 | + |
|
319 | + // ------------------------------------------------------ |
|
320 | + // rating_img |
|
321 | + $rating = number_format($myrow['rating'] / 2, 0); |
|
322 | + // irmtfan - add alt key for rating |
|
323 | + if ($rating < 1) { |
|
324 | + $rating_img = newbbDisplayImage('blank'); |
|
325 | + } else { |
|
326 | + $rating_img = newbbDisplayImage('rate' . $rating, constant('_MD_NEWBB_RATE' . $rating)); |
|
327 | + } |
|
328 | + // ------------------------------------------------------ |
|
329 | + // topic_page_jump |
|
330 | + $topic_page_jump = ''; |
|
331 | + $topic_page_jump_icon = ''; |
|
332 | + $totalpages = ceil(($myrow['topic_replies'] + 1) / $GLOBALS['xoopsModuleConfig']['posts_per_page']); |
|
333 | + if ($totalpages > 1) { |
|
334 | + $topic_page_jump .= ' '; |
|
335 | + $append = false; |
|
336 | + for ($i = 1; $i <= $totalpages; ++$i) { |
|
337 | + if ($i > 3 && $i < $totalpages) { |
|
338 | + if (!$append) { |
|
339 | + $topic_page_jump .= '...'; |
|
340 | + $append = true; |
|
341 | + } |
|
342 | + } else { |
|
343 | + $topic_page_jump .= '[<a href="' . XOOPS_URL . '/modules/newbb/viewtopic.php?topic_id=' . $myrow['topic_id'] . '&start=' . (($i - 1) * $GLOBALS['xoopsModuleConfig']['posts_per_page']) . '">' . $i . '</a>]'; |
|
344 | + // irmtfan remove here and move |
|
345 | + //$topic_page_jump_icon = "<a href='" . XOOPS_URL . "/modules/newbb/viewtopic.php?post_id=" . $myrow['post_id'] . "&start=" . (($i - 1) * $GLOBALS['xoopsModuleConfig']['posts_per_page']) . "'>" . newbbDisplayImage('lastposticon',_MD_NEWBB_GOTOLASTPOST) . '</a>'; |
|
346 | + } |
|
347 | + } |
|
348 | + } |
|
349 | + // irmtfan - move here for both topics with and without pages |
|
350 | + $topic_page_jump_icon = "<a href='" . XOOPS_URL . '/modules/newbb/viewtopic.php?post_id=' . $myrow['post_id'] . "'>" . newbbDisplayImage('lastposticon', _MD_NEWBB_GOTOLASTPOST) . '</a>'; |
|
351 | + |
|
352 | + // ------------------------------------------------------ |
|
353 | + // => topic array |
|
354 | + $forum_link = ''; |
|
355 | + if (!empty($viewAllForums[$myrow['forum_id']])) { |
|
356 | + $forum_link = '<a href="' . XOOPS_URL . '/modules/newbb/viewforum.php?forum=' . $myrow['forum_id'] . '">' . $viewAllForums[$myrow['forum_id']]['forum_name'] . '</a>'; |
|
357 | + } |
|
358 | + |
|
359 | + $topic_title = $myts->htmlSpecialChars($myrow['topic_title']); |
|
360 | + // irmtfan remove here and move to for loop |
|
361 | + //if ($myrow['type_id'] > 0) { |
|
362 | + //$topic_title = '<span style="color:'.$typen[$myrow["type_id"]]["type_color"].'">['.$typen[$myrow["type_id"]]["type_name"].']</span> '.$topic_title.''; |
|
363 | + //} |
|
364 | + if ($myrow['topic_digest']) { |
|
365 | + $topic_title = "<span class='digest'>" . $topic_title . '</span>'; |
|
366 | + } |
|
367 | + |
|
368 | + if (0 == $excerpt) { |
|
369 | + $topic_excerpt = ''; |
|
370 | + } elseif (($myrow['post_karma'] > 0 || $myrow['require_reply'] > 0) && !newbbIsAdmin($forum)) { |
|
371 | + $topic_excerpt = ''; |
|
372 | + } else { |
|
373 | + $topic_excerpt = xoops_substr(newbbHtml2text($myts->displayTarea($myrow['post_text'])), 0, $excerpt); |
|
374 | + $topic_excerpt = str_replace('[', '[', $myts->htmlSpecialChars($topic_excerpt)); |
|
375 | + } |
|
376 | + // START irmtfan move here |
|
377 | + $topics[$myrow['topic_id']] = [ |
|
378 | + 'topic_id' => $myrow['topic_id'], |
|
379 | + 'topic_icon' => $topic_icon, |
|
380 | + 'type_id' => $myrow['type_id'], |
|
381 | + //'type_text' => $topic_prefix,/*irmtfan remove here and move to for loop*/ |
|
382 | + 'topic_title' => $topic_title, |
|
383 | + //'topic_link' => XOOPS_URL . '/modules/newbb/viewtopic.php?topic_id=' . $myrow['topic_id'], |
|
384 | + 'topic_link' => 'viewtopic.php?topic_id=' . $myrow['topic_id'], |
|
385 | + 'rating_img' => $rating_img, |
|
386 | + 'topic_page_jump' => $topic_page_jump, |
|
387 | + 'topic_page_jump_icon' => $topic_page_jump_icon, |
|
388 | + 'topic_replies' => $myrow['topic_replies'], |
|
389 | + |
|
390 | + 'topic_digest' => $myrow['topic_digest'], |
|
391 | + //mb |
|
392 | + |
|
393 | + 'topic_poster_uid' => $myrow['topic_poster'], |
|
394 | + 'topic_poster_name' => $myts->htmlSpecialChars($myrow['poster_name'] ?: $GLOBALS['xoopsConfig']['anonymous']), |
|
395 | + 'topic_views' => $myrow['topic_views'], |
|
396 | + 'topic_time' => newbbFormatTimestamp($myrow['topic_time']), |
|
397 | + 'topic_last_posttime' => newbbFormatTimestamp($myrow['last_post_time']), |
|
398 | + 'topic_last_poster_uid' => $myrow['uid'], |
|
399 | + 'topic_last_poster_name' => $myts->htmlSpecialChars($myrow['last_poster_name'] ?: $GLOBALS['xoopsConfig']['anonymous']), |
|
400 | + 'topic_forum_link' => $forum_link, |
|
401 | + 'topic_excerpt' => $topic_excerpt, |
|
402 | + 'stick' => empty($myrow['topic_sticky']), |
|
403 | + 'stats' => [ |
|
404 | + $myrow['topic_status'], |
|
405 | + $myrow['topic_digest'], |
|
406 | + $myrow['topic_replies'] |
|
407 | + ], |
|
408 | + /* irmtfan uncomment use ib the for loop*/ |
|
409 | + //"topic_poster" => $topic_poster,/*irmtfan remove here and move to for loop*/ |
|
410 | + //"topic_last_poster" => $topic_last_poster,/*irmtfan remove here and move to for loop*/ |
|
411 | + //"topic_folder" => newbbDisplayImage($topic_folder,$topic_folder_text),/*irmtfan remove here and move to for loop*/ |
|
412 | + ]; |
|
413 | + // END irmtfan move here |
|
414 | + /* users */ |
|
415 | + $posters[$myrow['topic_poster']] = 1; |
|
416 | + $posters[$myrow['uid']] = 1; |
|
417 | + // reads |
|
418 | + if (!empty($GLOBALS['xoopsModuleConfig']['read_mode'])) { |
|
419 | + $reads[$myrow['topic_id']] = (1 == $GLOBALS['xoopsModuleConfig']['read_mode']) ? $myrow['last_post_time'] : $myrow['topic_last_post_id']; |
|
420 | + } |
|
421 | + }// irmtfan while end |
|
422 | + // START irmtfan move to a for loop |
|
423 | + $posters_name = newbbGetUnameFromIds(array_keys($posters), $GLOBALS['xoopsModuleConfig']['show_realname'], true); |
|
424 | + //$topic_poster = newbbGetUnameFromId($myrow['topic_poster'], $GLOBALS['xoopsModuleConfig']['show_realname'], true); |
|
425 | + //$topic_last_poster = newbbGetUnameFromId($myrow['uid'], $GLOBALS['xoopsModuleConfig']['show_realname'], true); |
|
426 | + $topic_isRead = newbbIsRead('topic', $reads); |
|
427 | + foreach (array_keys($topics) as $id) { |
|
428 | + $topics[$id]['topic_read'] = empty($topic_isRead[$id]) ? 0 : 1; // add topic-read/topic-new smarty variable |
|
429 | + if (!empty($topics[$id]['type_id']) && isset($typen[$topics[$id]['type_id']])) { |
|
430 | + $topics[$id]['topic_title'] = getTopicTitle($topics[$id]['topic_title'], $typen[$topics[$id]['type_id']]['type_name'], $typen[$topics[$id]['type_id']]['type_color']); |
|
431 | + } |
|
432 | + //$topic_prefix = (!empty($typen[$myrow['type_id']])) ? getTopicTitle("", $typen[$myrow['type_id']]["type_name"], $typen[$myrow['type_id']]["type_color"]) : ""; |
|
433 | + $topics[$id]['topic_poster'] = !empty($posters_name[$topics[$id]['topic_poster_uid']]) ? $posters_name[$topics[$id]['topic_poster_uid']] : $topics[$id]['topic_poster_name']; |
|
434 | + $topics[$id]['topic_last_poster'] = !empty($posters_name[$topics[$id]['topic_last_poster_uid']]) ? $posters_name[$topics[$id]['topic_last_poster_uid']] : $topics[$id]['topic_last_poster_name']; |
|
435 | + |
|
436 | + // ------------------------------------------------------ |
|
437 | + // topic_folder: priority: newhot -> hot/new -> regular |
|
438 | + list($topic_status, $topic_digest, $topic_replies) = $topics[$id]['stats']; |
|
439 | + if (1 == $topic_status) { |
|
440 | + $topic_folder = 'topic_locked'; |
|
441 | + $topic_folder_text = _MD_NEWBB_TOPICLOCKED; |
|
442 | + } else { |
|
443 | + if ($topic_digest) { |
|
444 | + $topic_folder = 'topic_digest'; |
|
445 | + $topic_folder_text = _MD_NEWBB_TOPICDIGEST; |
|
446 | + } elseif ($topic_replies >= $hot_threshold) { |
|
447 | + $topic_folder = empty($topic_isRead[$id]) ? 'topic_hot_new' : 'topic_hot'; |
|
448 | + $topic_folder_text = empty($topic_isRead[$id]) ? _MD_NEWBB_MORETHAN : _MD_NEWBB_MORETHAN2; |
|
449 | + } else { |
|
450 | + $topic_folder = empty($topic_isRead[$id]) ? 'topic_new' : 'topic'; |
|
451 | + $topic_folder_text = empty($topic_isRead[$id]) ? _MD_NEWBB_NEWPOSTS : _MD_NEWBB_NONEWPOSTS; |
|
452 | + } |
|
453 | + } |
|
454 | + $topics[$id]['topic_folder'] = newbbDisplayImage($topic_folder, $topic_folder_text); |
|
455 | + unset($topics[$id]['topic_poster_name'], $topics[$id]['topic_last_poster_name'], $topics[$id]['stats']); |
|
456 | + } // irmtfan end for loop |
|
457 | + // END irmtfan move to a for loop |
|
458 | + if (count($topics) > 0) { |
|
459 | + $sql = ' SELECT DISTINCT topic_id FROM ' . $this->db->prefix('newbb_posts') . " WHERE attachment != ''" . ' AND topic_id IN (' . implode(',', array_keys($topics)) . ')'; |
|
460 | + if ($result = $this->db->query($sql)) { |
|
461 | + while (false !== (list($topic_id) = $this->db->fetchRow($result))) { |
|
462 | + $topics[$topic_id]['attachment'] = ' ' . newbbDisplayImage('attachment', _MD_NEWBB_TOPICSHASATT); |
|
463 | + } |
|
464 | + } |
|
465 | + } |
|
466 | + |
|
467 | + return [$topics, $sticky]; |
|
468 | + } |
|
469 | + |
|
470 | + /** |
|
471 | + * @param $forum |
|
472 | + * @param $startdate |
|
473 | + * @param $type |
|
474 | + * @return null|int |
|
475 | + */ |
|
476 | + public function getTopicCount(&$forum, $startdate, $type) |
|
477 | + { |
|
478 | + require_once $GLOBALS['xoops']->path('modules/newbb/include/functions.session.php'); |
|
479 | + |
|
480 | + $criteria_extra = ''; |
|
481 | + $criteria_approve = ' AND t.approved = 1'; // any others? |
|
482 | + $leftjoin = ' LEFT JOIN ' . $this->db->prefix('newbb_posts') . ' p ON p.post_id = t.topic_last_post_id'; |
|
483 | + $criteria_post = ' p.post_time > ' . $startdate; |
|
484 | + switch ($type) { |
|
485 | + case 'digest': |
|
486 | + $criteria_extra = ' AND topic_digest = 1'; |
|
487 | + break; |
|
488 | + case 'unreplied': |
|
489 | + $criteria_extra = ' AND topic_replies < 1'; |
|
490 | + break; |
|
491 | + case 'unread': |
|
492 | + if (empty($GLOBALS['xoopsModuleConfig']['read_mode'])) { |
|
493 | + } elseif (2 == $GLOBALS['xoopsModuleConfig']['read_mode']) { |
|
494 | + // START irmtfan use read_uid to find the unread posts when the user is logged in |
|
495 | + |
|
496 | + $read_uid = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getVar('uid') : 0; |
|
497 | + if (!empty($read_uid)) { |
|
498 | + $leftjoin .= ' LEFT JOIN ' . $this->db->prefix('newbb_reads_topic') . ' r ON r.read_item = t.topic_id AND r.uid = ' . $read_uid . ' '; |
|
499 | + $criteria_post .= ' AND (r.read_id IS NULL OR r.post_id < t.topic_last_post_id)'; |
|
500 | + } else { |
|
501 | + } |
|
502 | + // END irmtfan use read_uid to find the unread posts when the user is logged in |
|
503 | + } elseif (1 == $GLOBALS['xoopsModuleConfig']['read_mode']) { |
|
504 | + // START irmtfan fix read_mode = 1 bugs - for all users (member and anon) |
|
505 | + if ($time_criterion = max($GLOBALS['last_visit'], $startdate)) { |
|
506 | + $criteria_post = ' p.post_time > ' . $time_criterion; // for all users |
|
507 | + $topics = []; |
|
508 | + $topic_lastread = newbbGetCookie('LT', true); |
|
509 | + if (count($topic_lastread) > 0) { |
|
510 | + foreach ($topic_lastread as $id => $time) { |
|
511 | + if ($time > $time_criterion) { |
|
512 | + $topics[] = $id; |
|
513 | + } |
|
514 | + } |
|
515 | + } |
|
516 | + if (count($topics) > 0) { |
|
517 | + $criteria_extra = ' AND t.topic_id NOT IN (' . implode(',', $topics) . ')'; |
|
518 | + } |
|
519 | + } |
|
520 | + // END irmtfan fix read_mode = 1 bugs - for all users (member and anon) |
|
521 | + } |
|
522 | + break; |
|
523 | + case 'pending': |
|
524 | + $criteria_approve = ' AND t.approved = 0'; |
|
525 | + break; |
|
526 | + case 'deleted': |
|
527 | + $criteria_approve = ' AND t.approved = -1'; |
|
528 | + break; |
|
529 | + case 'all': |
|
530 | + break; |
|
531 | + default: |
|
532 | + $criteria_post = ' (p.post_time > ' . $startdate . ' OR t.topic_sticky=1)'; |
|
533 | + break; |
|
534 | + } |
|
535 | + $criteria_forum = ''; |
|
536 | + if (is_object($forum)) { |
|
537 | + $criteria_forum = ' AND t.forum_id = ' . $forum->getVar('forum_id'); |
|
538 | + } else { |
|
539 | + if (is_array($forum) && count($forum) > 0) { |
|
540 | + $criteria_forum = ' AND t.forum_id IN (' . implode(',', array_keys($forum)) . ')'; |
|
541 | + } elseif (!empty($forum)) { |
|
542 | + $criteria_forum = ' AND t.forum_id =' . (int)$forum; |
|
543 | + } |
|
544 | + } |
|
545 | + |
|
546 | + $sql = 'SELECT COUNT(*) AS count FROM ' . $this->db->prefix('newbb_topics') . ' t ' . $leftjoin; |
|
547 | + $sql .= ' WHERE ' . $criteria_post . $criteria_forum . $criteria_extra . $criteria_approve; |
|
548 | + if (!$result = $this->db->query($sql)) { |
|
549 | + //xoops_error($this->db->error().'<br>'.$sql); |
|
550 | + return null; |
|
551 | + } |
|
552 | + $myrow = $this->db->fetchArray($result); |
|
553 | + $count = $myrow['count']; |
|
554 | + |
|
555 | + return $count; |
|
556 | + } |
|
557 | + |
|
558 | + // get permission |
|
559 | + |
|
560 | + /** |
|
561 | + * @param $forum |
|
562 | + * @param string $type |
|
563 | + * @param bool $checkCategory |
|
564 | + * @return bool |
|
565 | + */ |
|
566 | + public function getPermission($forum, $type = 'access', $checkCategory = true) |
|
567 | + { |
|
568 | + global $xoopsModule; |
|
569 | + static $_cachedPerms; |
|
570 | + |
|
571 | + if ('all' === $type) { |
|
572 | + return true; |
|
573 | + } |
|
574 | + |
|
575 | + require_once dirname(__DIR__) . '/include/functions.user.php'; |
|
576 | + if (newbbIsAdmin($forum)) { |
|
577 | + return true; |
|
578 | + } |
|
579 | + //if ($GLOBALS["xoopsUserIsAdmin"] && $xoopsModule->getVar("dirname") === "newbb") { |
|
580 | + //return true; |
|
581 | + //} |
|
582 | + |
|
583 | + if (!is_object($forum)) { |
|
584 | + $forum = $this->get($forum); |
|
585 | + } |
|
586 | + |
|
587 | + if (!empty($checkCategory)) { |
|
588 | + /** @var Newbb\CategoryHandler $categoryHandler */ |
|
589 | + $categoryHandler = Newbb\Helper::getInstance()->getHandler('Category'); |
|
590 | + $categoryPerm = $categoryHandler->getPermission($forum->getVar('cat_id')); |
|
591 | + if (!$categoryPerm) { |
|
592 | + return false; |
|
593 | + } |
|
594 | + } |
|
595 | + |
|
596 | + $type = strtolower($type); |
|
597 | + // START irmtfan commented and removed |
|
598 | + //if ('moderate' === $type) { |
|
599 | + //require_once $GLOBALS['xoops']->path('modules/newbb/include/functions.user.php'); |
|
600 | + //$permission = newbbIsModerator($forum); |
|
601 | + //} else { |
|
602 | + $forum_id = $forum->getVar('forum_id'); |
|
603 | + /** var Newbb\PermissionHandler $permHandler */ |
|
604 | + $permHandler = Newbb\Helper::getInstance()->getHandler('Permission'); |
|
605 | + $permission = $permHandler->getPermission('forum', $type, $forum_id); |
|
606 | + //} |
|
607 | + // END irmtfan commented and removed |
|
608 | + return $permission; |
|
609 | + } |
|
610 | + |
|
611 | + /** |
|
612 | + * @param $forum |
|
613 | + * @return mixed |
|
614 | + */ |
|
615 | + public function deletePermission(&$forum) |
|
616 | + { |
|
617 | + /** var Newbb\PermissionHandler $permHandler */ |
|
618 | + $permHandler = Newbb\Helper::getInstance()->getHandler('Permission'); |
|
619 | + |
|
620 | + return $permHandler->deleteByForum($forum->getVar('forum_id')); |
|
621 | + } |
|
622 | + |
|
623 | + /** |
|
624 | + * @param $forum |
|
625 | + * @return mixed |
|
626 | + */ |
|
627 | + public function applyPermissionTemplate(&$forum) |
|
628 | + { |
|
629 | + /** var Newbb\PermissionHandler $permHandler */ |
|
630 | + $permHandler = Newbb\Helper::getInstance()->getHandler('Permission'); |
|
631 | + |
|
632 | + return $permHandler->applyTemplate($forum->getVar('forum_id')); |
|
633 | + } |
|
634 | + |
|
635 | + /* |
|
636 | 636 | function isForum($forum) |
637 | 637 | { |
638 | 638 | $count = false; |
@@ -647,422 +647,422 @@ discard block |
||
647 | 647 | } |
648 | 648 | */ |
649 | 649 | |
650 | - /** |
|
651 | - * clean orphan forums from database |
|
652 | - * @param string $table_link |
|
653 | - * @param string $field_link |
|
654 | - * @param string $field_object |
|
655 | - * @param array $forum_ids forum IDs |
|
656 | - * @return bool true on success |
|
657 | - */ |
|
658 | - // START irmtfan rewrite forum cleanOrphan function. add parent_forum and cat_id orphan check |
|
659 | - // public function cleanOrphan(array $forum_ids = array()) |
|
660 | - public function cleanOrphan($table_link = '', $field_link = '', $field_object = '', $forum_ids = []) |
|
661 | - { |
|
662 | - // check parent_forum orphan forums |
|
663 | - if (empty($forum_ids)) { |
|
664 | - $forum_ids = $this->getIds(); |
|
665 | - } |
|
666 | - if (empty($forum_ids)) { |
|
667 | - return false; |
|
668 | - } |
|
669 | - /* |
|
650 | + /** |
|
651 | + * clean orphan forums from database |
|
652 | + * @param string $table_link |
|
653 | + * @param string $field_link |
|
654 | + * @param string $field_object |
|
655 | + * @param array $forum_ids forum IDs |
|
656 | + * @return bool true on success |
|
657 | + */ |
|
658 | + // START irmtfan rewrite forum cleanOrphan function. add parent_forum and cat_id orphan check |
|
659 | + // public function cleanOrphan(array $forum_ids = array()) |
|
660 | + public function cleanOrphan($table_link = '', $field_link = '', $field_object = '', $forum_ids = []) |
|
661 | + { |
|
662 | + // check parent_forum orphan forums |
|
663 | + if (empty($forum_ids)) { |
|
664 | + $forum_ids = $this->getIds(); |
|
665 | + } |
|
666 | + if (empty($forum_ids)) { |
|
667 | + return false; |
|
668 | + } |
|
669 | + /* |
|
670 | 670 | $sql = " UPDATE ".$GLOBALS['xoopsDB']->prefix("newbb_forums"). |
671 | 671 | " SET parent_forum = 0". |
672 | 672 | " WHERE (parent_forum NOT IN ( ".$forum_ids."))". |
673 | 673 | " OR parent_forum = forum_id"; |
674 | 674 | */ |
675 | - $criteria = new \CriteriaCompo(); |
|
676 | - $criteria->add(new \Criteria('parent_forum', '(' . implode(', ', $forum_ids) . ')', 'NOT IN'), 'AND'); |
|
677 | - $criteria->add(new \Criteria('parent_forum', '`forum_id`', '='), 'OR'); |
|
678 | - $b1 = $this->updateAll('parent_forum', 0, $criteria, true); |
|
679 | - // check cat_id orphan forums |
|
680 | - $categoryHandler = Newbb\Helper::getInstance()->getHandler('Category'); |
|
681 | - $cat_ids = $categoryHandler->getIds(); |
|
682 | - if (empty($cat_ids)) { |
|
683 | - return false; |
|
684 | - } |
|
685 | - $criteria = new \CriteriaCompo(); |
|
686 | - $criteria->add(new \Criteria('cat_id', '(' . implode(', ', $cat_ids) . ')', 'NOT IN'), 'AND'); |
|
687 | - $b2 = $this->updateAll('cat_id', $cat_ids[0], $criteria, true); |
|
688 | - |
|
689 | - return ($b1 && $b2); |
|
690 | - } |
|
691 | - // END irmtfan rewrite forum cleanOrphan function. add parent_forum and cat_id orphan check |
|
692 | - |
|
693 | - /** |
|
694 | - * forum data synchronization |
|
695 | - * |
|
696 | - * @param mixed $object null for all forums; integer for forum_id; object for forum object |
|
697 | - * @return bool |
|
698 | - * @internal param int $mode 1 for stats only; 2 for forum index data only; 0 for both |
|
699 | - * |
|
700 | - */ |
|
701 | - public function synchronization($object = null) |
|
702 | - { |
|
703 | - if (empty($object)) { |
|
704 | - $forums = $this->getIds(); |
|
705 | - $this->cleanOrphan('', '', '', $forums); // irmtfan - move cleanOrphan to synchronization function |
|
706 | - foreach ($forums as $id) { |
|
707 | - $this->synchronization($id); |
|
708 | - } |
|
709 | - |
|
710 | - return true; |
|
711 | - } |
|
712 | - |
|
713 | - if (!is_object($object)) { |
|
714 | - $object = $this->get((int)$object); |
|
715 | - } |
|
716 | - |
|
717 | - if (!$object->getVar('forum_id')) { |
|
718 | - return false; |
|
719 | - } |
|
720 | - $sql = 'SELECT MAX(post_id) AS last_post, COUNT(*) AS total FROM ' . $this->db->prefix('newbb_posts') . ' AS p LEFT JOIN ' . $this->db->prefix('newbb_topics') . ' AS t ON p.topic_id=t.topic_id WHERE p.approved=1 AND t.approved=1 AND p.forum_id = ' . $object->getVar('forum_id'); |
|
721 | - |
|
722 | - if ($result = $this->db->query($sql)) { |
|
723 | - $last_post = 0; |
|
724 | - $posts = 0; |
|
725 | - if ($row = $this->db->fetchArray($result)) { |
|
726 | - $last_post = (int)$row['last_post']; |
|
727 | - $posts = (int)$row['total']; |
|
728 | - } |
|
729 | - if ($object->getVar('forum_last_post_id') !== $last_post) { |
|
730 | - $object->setVar('forum_last_post_id', $last_post); |
|
731 | - } |
|
732 | - if ($object->getVar('forum_posts') !== $posts) { |
|
733 | - $object->setVar('forum_posts', $posts); |
|
734 | - } |
|
735 | - } |
|
736 | - |
|
737 | - $sql = 'SELECT COUNT(*) AS total FROM ' . $this->db->prefix('newbb_topics') . ' WHERE approved=1 AND forum_id = ' . $object->getVar('forum_id'); |
|
738 | - if ($result = $this->db->query($sql)) { |
|
739 | - if ($row = $this->db->fetchArray($result)) { |
|
740 | - if ($object->getVar('forum_topics') !== $row['total']) { |
|
741 | - $object->setVar('forum_topics', $row['total']); |
|
742 | - } |
|
743 | - } |
|
744 | - } |
|
745 | - $object->setDirty(); |
|
746 | - |
|
747 | - return $this->insert($object, true); |
|
748 | - } |
|
749 | - |
|
750 | - /** |
|
751 | - * @param null $passedSubForums |
|
752 | - * @return array |
|
753 | - */ |
|
754 | - public function getSubforumStats($passedSubForums = null) |
|
755 | - { |
|
756 | - $stats = []; |
|
757 | - |
|
758 | - require_once $GLOBALS['xoops']->path('modules/newbb/include/functions.forum.php'); |
|
759 | - |
|
760 | - $subForumTree = newbbGetSubForum(); |
|
761 | - if (empty($passedSubForums)) { |
|
762 | - $sub_forums = $subForumTree; |
|
763 | - } else { |
|
764 | - foreach ($passedSubForums as $id) { |
|
765 | - $sub_forums[$id] = isset($subForumTree[$id]) ? $subForumTree[$id] : null; |
|
766 | - } |
|
767 | - } |
|
768 | - |
|
769 | - $forums_id = []; |
|
770 | - foreach (array_keys($sub_forums) as $id) { |
|
771 | - if (empty($sub_forums[$id])) { |
|
772 | - continue; |
|
773 | - } |
|
774 | - $forums_id = array_merge($forums_id, $sub_forums[$id]); |
|
775 | - } |
|
776 | - if (!$forums_id) { |
|
777 | - return $stats; |
|
778 | - } |
|
779 | - $sql = ' SELECT forum_posts AS posts, forum_topics AS topics, forum_id AS id' . ' FROM ' . $this->table . ' WHERE forum_id IN (' . implode(', ', $forums_id) . ')'; |
|
780 | - if (!$result = $this->db->query($sql)) { |
|
781 | - return $stats; |
|
782 | - } |
|
783 | - |
|
784 | - $forum_stats = []; |
|
785 | - while (false !== ($row = $this->db->fetchArray($result))) { |
|
786 | - $forum_stats[$row['id']] = ['topics' => $row['topics'], 'posts' => $row['posts']]; |
|
787 | - } |
|
788 | - |
|
789 | - foreach (array_keys($sub_forums) as $id) { |
|
790 | - if (empty($sub_forums[$id])) { |
|
791 | - continue; |
|
792 | - } |
|
793 | - $stats[$id] = ['topics' => 0, 'posts' => 0]; |
|
794 | - foreach ($sub_forums[$id] as $fid) { |
|
795 | - $stats[$id]['topics'] += $forum_stats[$fid]['topics']; |
|
796 | - $stats[$id]['posts'] += $forum_stats[$fid]['posts']; |
|
797 | - } |
|
798 | - } |
|
799 | - |
|
800 | - return $stats; |
|
801 | - } |
|
802 | - |
|
803 | - /** |
|
804 | - * @param $forums |
|
805 | - * @param int $length_title_index |
|
806 | - * @param int $count_subforum |
|
807 | - * @return array |
|
808 | - */ |
|
809 | - public function &display($forums, $length_title_index = 30, $count_subforum = 1) |
|
810 | - { |
|
811 | - global $myts; |
|
812 | - |
|
813 | - $posts = []; |
|
814 | - $postsObject = []; |
|
815 | - foreach (array_keys($forums) as $id) { |
|
816 | - $posts[] = $forums[$id]['forum_last_post_id']; |
|
817 | - } |
|
818 | - if (!empty($posts)) { |
|
819 | - $postHandler = Newbb\Helper::getInstance()->getHandler('Post'); |
|
820 | - $tags_post = ['uid', 'topic_id', 'post_time', 'poster_name', 'icon']; |
|
821 | - if (!empty($length_title_index)) { |
|
822 | - $tags_post[] = 'subject'; |
|
823 | - } |
|
824 | - $posts = $postHandler->getAll(new \Criteria('post_id', '(' . implode(', ', $posts) . ')', 'IN'), $tags_post, false); |
|
825 | - } |
|
826 | - |
|
827 | - // Get topic/post stats per forum |
|
828 | - $stats_forum = []; |
|
829 | - |
|
830 | - if (!empty($count_subforum)) { |
|
831 | - $stats_forum = $this->getSubforumStats(array_keys($forums)); // irmtfan uncomment to count sub forum posts/topics |
|
832 | - } |
|
833 | - |
|
834 | - $users = []; |
|
835 | - $reads = []; |
|
836 | - $topics = []; |
|
837 | - |
|
838 | - foreach (array_keys($forums) as $id) { |
|
839 | - $forum =& $forums[$id]; |
|
840 | - |
|
841 | - if (!$forum['forum_last_post_id']) { |
|
842 | - continue; |
|
843 | - } |
|
844 | - if (!$post = @$posts[$forum['forum_last_post_id']]) { |
|
845 | - $forum['forum_last_post_id'] = 0; |
|
846 | - continue; |
|
847 | - } |
|
848 | - |
|
849 | - $users[] = $post['uid']; |
|
850 | - if ($moderators[$id] = $forum['forum_moderator']) { |
|
851 | - $users = array_merge($users, $moderators[$id]); |
|
852 | - } |
|
853 | - |
|
854 | - // reads |
|
855 | - if (!empty($GLOBALS['xoopsModuleConfig']['read_mode'])) { |
|
856 | - $reads[$id] = (1 == $GLOBALS['xoopsModuleConfig']['read_mode']) ? $post['post_time'] : $post['post_id']; |
|
857 | - } |
|
858 | - } |
|
859 | - |
|
860 | - require_once $GLOBALS['xoops']->path('modules/newbb/include/functions.user.php'); |
|
861 | - require_once $GLOBALS['xoops']->path('modules/newbb/include/functions.time.php'); |
|
862 | - require_once $GLOBALS['xoops']->path('modules/newbb/include/functions.render.php'); |
|
863 | - require_once $GLOBALS['xoops']->path('modules/newbb/include/functions.read.php'); |
|
864 | - $forum_isread = newbbIsRead('forum', $reads); |
|
865 | - $users_linked = newbbGetUnameFromIds(array_unique($users), !empty($GLOBALS['xoopsModuleConfig']['show_realname']), true); |
|
866 | - |
|
867 | - $forums_array = []; |
|
868 | - $name_anonymous = $myts->htmlSpecialChars($GLOBALS['xoopsConfig']['anonymous']); |
|
869 | - |
|
870 | - foreach (array_keys($forums) as $id) { |
|
871 | - $forum =& $forums[$id]; |
|
872 | - |
|
873 | - $_forum_data = []; |
|
874 | - $_forum_data['forum_order'] = $forum['forum_order']; |
|
875 | - $_forum_data['forum_id'] = $id; |
|
876 | - $_forum_data['forum_cid'] = $forum['cat_id']; |
|
877 | - $_forum_data['forum_name'] = $forum['forum_name']; |
|
878 | - $forumDescLength = $GLOBALS['xoopsModuleConfig']['forum_desc_length']; |
|
879 | - $_forum_data['forum_desc'] = mb_strimwidth($forum['forum_desc'], 0, $forumDescLength, '...'); |
|
880 | - $_forum_data['forum_topics'] = $forum['forum_topics'] + @$stats_forum[$id]['topics']; |
|
881 | - $_forum_data['forum_posts'] = $forum['forum_posts'] + @$stats_forum[$id]['posts']; |
|
882 | - //$_forum_data["forum_type"]= $forum['forum_type']; |
|
883 | - |
|
884 | - $forum_moderators = []; |
|
885 | - if (!empty($moderators[$id])) { |
|
886 | - foreach (@$moderators[$id] as $moderator) { |
|
887 | - $forum_moderators[] = @$users_linked[$moderator]; |
|
888 | - } |
|
889 | - } |
|
890 | - $_forum_data['forum_moderators'] = implode(', ', $forum_moderators); |
|
891 | - |
|
892 | - // irmtfan change if/endif to if{} method |
|
893 | - if ($post_id = $forum['forum_last_post_id']) { |
|
894 | - $post =& $posts[$post_id]; |
|
895 | - $_forum_data['forum_lastpost_id'] = $post_id; |
|
896 | - $_forum_data['forum_lastpost_time'] = newbbFormatTimestamp($post['post_time']); |
|
897 | - if (!empty($users_linked[$post['uid']])) { |
|
898 | - $_forum_data['forum_lastpost_user'] = $users_linked[$post['uid']]; |
|
899 | - } elseif ($poster_name = $post['poster_name']) { |
|
900 | - $_forum_data['forum_lastpost_user'] = $poster_name; |
|
901 | - } else { |
|
902 | - $_forum_data['forum_lastpost_user'] = $name_anonymous; |
|
903 | - } |
|
904 | - if (!empty($length_title_index)) { |
|
905 | - $subject = $post['subject']; |
|
906 | - if ($length_title_index < 255) { |
|
907 | - $subject = xoops_substr($subject, 0, $length_title_index); |
|
908 | - } |
|
909 | - $_forum_data['forum_lastpost_subject'] = $subject; |
|
910 | - } |
|
911 | - // irmtfan - remove icon_path and use newbbDisplayImage |
|
912 | - $_forum_data['forum_lastpost_icon'] = newbbDisplayImage('lastposticon', _MD_NEWBB_GOTOLASTPOST); |
|
913 | - // START irmtfan change the method to add read smarty |
|
914 | - if (empty($forum_isread[$id])) { |
|
915 | - $_forum_data['forum_folder'] = newbbDisplayImage('forum_new', _MD_NEWBB_NEWPOSTS); |
|
916 | - $_forum_data['forum_read'] = 0; // irmtfan add forum-read/forum-new smarty variable |
|
917 | - } else { |
|
918 | - $_forum_data['forum_folder'] = newbbDisplayImage('forum', _MD_NEWBB_NONEWPOSTS); |
|
919 | - $_forum_data['forum_read'] = 1; // irmtfan add forum-read/forum-new smarty variable |
|
920 | - } |
|
921 | - // END irmtfan change the method to add read smarty |
|
922 | - } |
|
923 | - $forums_array[$forum['parent_forum']][] = $_forum_data; |
|
924 | - } |
|
925 | - |
|
926 | - return $forums_array; |
|
927 | - } |
|
928 | - |
|
929 | - /** |
|
930 | - * get a hierarchical tree of forums |
|
931 | - * |
|
932 | - * {@link newbbTree} |
|
933 | - * |
|
934 | - * @param int $cat_id category ID |
|
935 | - * @param int $pid Top forum ID |
|
936 | - * @param string $permission permission type |
|
937 | - * @param string $prefix prefix for display |
|
938 | - * @param string|array|null $tags variables to fetch |
|
939 | - * @return array associative array of category IDs and sanitized titles |
|
940 | - */ |
|
941 | - public function &getTree($cat_id = 0, $pid = 0, $permission = 'access', $prefix = '--', $tags = null) |
|
942 | - { |
|
943 | - $pid = (int)$pid; |
|
944 | - $perm_string = $permission; |
|
945 | - if (!is_array($tags) || 0 === count($tags)) { |
|
946 | - $tags = ['forum_id', 'parent_forum', 'forum_name', 'forum_order', 'cat_id']; |
|
947 | - } |
|
948 | - $forumsObject = $this->getByPermission($cat_id, $perm_string, $tags); |
|
949 | - |
|
950 | - require_once __DIR__ . '/Tree.php'; |
|
951 | - $forums_structured = []; |
|
952 | - foreach (array_keys($forumsObject) as $key) { |
|
953 | - $forums_structured[$forumsObject[$key]->getVar('cat_id')][$key] = $forumsObject[$key]; |
|
954 | - } |
|
955 | - |
|
956 | - foreach (array_keys($forums_structured) as $cid) { |
|
957 | - $tree = new ObjectTree($forums_structured[$cid]); |
|
958 | - $forum_array[$cid] = $tree->makeTree($prefix, $pid, $tags); |
|
959 | - unset($tree); |
|
960 | - } |
|
961 | - |
|
962 | - return $forum_array; |
|
963 | - } |
|
964 | - |
|
965 | - /** |
|
966 | - * get a hierarchical array tree of forums |
|
967 | - * |
|
968 | - * {@link newbbTree} |
|
969 | - * |
|
970 | - * @param int $cat_id category ID |
|
971 | - * @param int $pid Top forum ID |
|
972 | - * @param string $permission permission type |
|
973 | - * @param string|array|null $tags variables to fetch |
|
974 | - * @param integer $depth level of subcategories |
|
975 | - * @return array associative array of category IDs and sanitized titles |
|
976 | - */ |
|
977 | - public function &getArrayTree($cat_id = 0, $pid = 0, $permission = 'access', $tags = null, $depth = 0) |
|
978 | - { |
|
979 | - $pid = (int)$pid; |
|
980 | - $perm_string = $permission; |
|
981 | - if (!is_array($tags) || 0 === count($tags)) { |
|
982 | - $tags = ['forum_id', 'parent_forum', 'forum_name', 'forum_order', 'cat_id']; |
|
983 | - } |
|
984 | - $forumsObject = $this->getByPermission($cat_id, $perm_string, $tags); |
|
985 | - |
|
986 | - require_once __DIR__ . '/Tree.php'; |
|
987 | - $forums_structured = []; |
|
988 | - foreach (array_keys($forumsObject) as $key) { |
|
989 | - $forumObject =& $forumsObject[$key]; |
|
990 | - $forums_structured[$forumObject->getVar('cat_id')][$key] = $forumsObject[$key]; |
|
991 | - } |
|
992 | - foreach (array_keys($forums_structured) as $cid) { |
|
993 | - $tree = new ObjectTree($forums_structured[$cid]); |
|
994 | - $forum_array[$cid] = $tree->makeArrayTree($pid, $tags, $depth); |
|
995 | - unset($tree); |
|
996 | - } |
|
997 | - |
|
998 | - return $forum_array; |
|
999 | - } |
|
1000 | - |
|
1001 | - /** |
|
1002 | - * @param $object |
|
1003 | - * @return array|null |
|
1004 | - */ |
|
1005 | - public function &getParents($object) |
|
1006 | - { |
|
1007 | - $ret = null; |
|
1008 | - if (!$object->getVar('forum_id')) { |
|
1009 | - return $ret; |
|
1010 | - } |
|
1011 | - |
|
1012 | - require_once $GLOBALS['xoops']->path('modules/newbb/include/functions.forum.php'); |
|
1013 | - if (!$parents = newbbGetParentForum($object->getVar('forum_id'))) { |
|
1014 | - return $ret; |
|
1015 | - } |
|
1016 | - $parents_list = $this->getList(new \Criteria('forum_id', '(' . implode(', ', $parents) . ')', 'IN')); |
|
1017 | - foreach ($parents as $key => $id) { |
|
1018 | - $ret[] = ['forum_id' => $id, 'forum_name' => $parents_list[$id]]; |
|
1019 | - } |
|
1020 | - unset($parents, $parents_list); |
|
1021 | - |
|
1022 | - return $ret; |
|
1023 | - } |
|
1024 | - |
|
1025 | - // START irmtfan - get forum Ids by values. parse positive values to forum IDs and negative values to category IDs. value=0 => all valid forums |
|
1026 | - |
|
1027 | - /** |
|
1028 | - * function for get forum Ids by positive and negative values |
|
1029 | - * |
|
1030 | - * @param int|text|array $values : positive values = forums | negative values = cats | $values=0 = all valid forums, $permission , true/false $parse_cats |
|
1031 | - * @param string $permission |
|
1032 | - * @param bool $parse_cats |
|
1033 | - * @return array|mixed $validForums |
|
1034 | - */ |
|
1035 | - public function getIdsByValues($values = 0, $permission = 'access', $parse_cats = true) |
|
1036 | - { |
|
1037 | - // Get all valid forums with this permission |
|
1038 | - $validForums = $this->getIdsByPermission($permission); |
|
1039 | - // if no value or value=0 return all valid forums |
|
1040 | - if (empty($values)) { |
|
1041 | - return $validForums; |
|
1042 | - } |
|
1043 | - $values = is_numeric($values) ? [$values] : $values; |
|
1044 | - //parse negative values to category IDs |
|
1045 | - $forums = []; |
|
1046 | - $cats = []; |
|
1047 | - foreach ($values as $val) { |
|
1048 | - if (0 == $val) { |
|
1049 | - // value=0 => all valid forums |
|
1050 | - return $validForums; |
|
1051 | - } elseif ($val > 0) { |
|
1052 | - $forums[] = $val; |
|
1053 | - } else { |
|
1054 | - $cats[] = abs($val); |
|
1055 | - } |
|
1056 | - } |
|
1057 | - // if dont want to parse categories OR no cats return all forums |
|
1058 | - if (empty($parse_cats) || empty($cats)) { |
|
1059 | - return array_intersect($validForums, $forums); |
|
1060 | - } |
|
1061 | - // Get all forums by category IDs |
|
1062 | - $forumObjs = $this->getForumsByCategory($cats, $permission, true); |
|
1063 | - $forums = array_merge($forums, array_keys($forumObjs)); |
|
1064 | - |
|
1065 | - return array_intersect($validForums, $forums); |
|
1066 | - } |
|
1067 | - // END irmtfan - get forum Ids by values. parse positive values to forum IDs and negative values to category IDs. value=0 => all valid forums |
|
675 | + $criteria = new \CriteriaCompo(); |
|
676 | + $criteria->add(new \Criteria('parent_forum', '(' . implode(', ', $forum_ids) . ')', 'NOT IN'), 'AND'); |
|
677 | + $criteria->add(new \Criteria('parent_forum', '`forum_id`', '='), 'OR'); |
|
678 | + $b1 = $this->updateAll('parent_forum', 0, $criteria, true); |
|
679 | + // check cat_id orphan forums |
|
680 | + $categoryHandler = Newbb\Helper::getInstance()->getHandler('Category'); |
|
681 | + $cat_ids = $categoryHandler->getIds(); |
|
682 | + if (empty($cat_ids)) { |
|
683 | + return false; |
|
684 | + } |
|
685 | + $criteria = new \CriteriaCompo(); |
|
686 | + $criteria->add(new \Criteria('cat_id', '(' . implode(', ', $cat_ids) . ')', 'NOT IN'), 'AND'); |
|
687 | + $b2 = $this->updateAll('cat_id', $cat_ids[0], $criteria, true); |
|
688 | + |
|
689 | + return ($b1 && $b2); |
|
690 | + } |
|
691 | + // END irmtfan rewrite forum cleanOrphan function. add parent_forum and cat_id orphan check |
|
692 | + |
|
693 | + /** |
|
694 | + * forum data synchronization |
|
695 | + * |
|
696 | + * @param mixed $object null for all forums; integer for forum_id; object for forum object |
|
697 | + * @return bool |
|
698 | + * @internal param int $mode 1 for stats only; 2 for forum index data only; 0 for both |
|
699 | + * |
|
700 | + */ |
|
701 | + public function synchronization($object = null) |
|
702 | + { |
|
703 | + if (empty($object)) { |
|
704 | + $forums = $this->getIds(); |
|
705 | + $this->cleanOrphan('', '', '', $forums); // irmtfan - move cleanOrphan to synchronization function |
|
706 | + foreach ($forums as $id) { |
|
707 | + $this->synchronization($id); |
|
708 | + } |
|
709 | + |
|
710 | + return true; |
|
711 | + } |
|
712 | + |
|
713 | + if (!is_object($object)) { |
|
714 | + $object = $this->get((int)$object); |
|
715 | + } |
|
716 | + |
|
717 | + if (!$object->getVar('forum_id')) { |
|
718 | + return false; |
|
719 | + } |
|
720 | + $sql = 'SELECT MAX(post_id) AS last_post, COUNT(*) AS total FROM ' . $this->db->prefix('newbb_posts') . ' AS p LEFT JOIN ' . $this->db->prefix('newbb_topics') . ' AS t ON p.topic_id=t.topic_id WHERE p.approved=1 AND t.approved=1 AND p.forum_id = ' . $object->getVar('forum_id'); |
|
721 | + |
|
722 | + if ($result = $this->db->query($sql)) { |
|
723 | + $last_post = 0; |
|
724 | + $posts = 0; |
|
725 | + if ($row = $this->db->fetchArray($result)) { |
|
726 | + $last_post = (int)$row['last_post']; |
|
727 | + $posts = (int)$row['total']; |
|
728 | + } |
|
729 | + if ($object->getVar('forum_last_post_id') !== $last_post) { |
|
730 | + $object->setVar('forum_last_post_id', $last_post); |
|
731 | + } |
|
732 | + if ($object->getVar('forum_posts') !== $posts) { |
|
733 | + $object->setVar('forum_posts', $posts); |
|
734 | + } |
|
735 | + } |
|
736 | + |
|
737 | + $sql = 'SELECT COUNT(*) AS total FROM ' . $this->db->prefix('newbb_topics') . ' WHERE approved=1 AND forum_id = ' . $object->getVar('forum_id'); |
|
738 | + if ($result = $this->db->query($sql)) { |
|
739 | + if ($row = $this->db->fetchArray($result)) { |
|
740 | + if ($object->getVar('forum_topics') !== $row['total']) { |
|
741 | + $object->setVar('forum_topics', $row['total']); |
|
742 | + } |
|
743 | + } |
|
744 | + } |
|
745 | + $object->setDirty(); |
|
746 | + |
|
747 | + return $this->insert($object, true); |
|
748 | + } |
|
749 | + |
|
750 | + /** |
|
751 | + * @param null $passedSubForums |
|
752 | + * @return array |
|
753 | + */ |
|
754 | + public function getSubforumStats($passedSubForums = null) |
|
755 | + { |
|
756 | + $stats = []; |
|
757 | + |
|
758 | + require_once $GLOBALS['xoops']->path('modules/newbb/include/functions.forum.php'); |
|
759 | + |
|
760 | + $subForumTree = newbbGetSubForum(); |
|
761 | + if (empty($passedSubForums)) { |
|
762 | + $sub_forums = $subForumTree; |
|
763 | + } else { |
|
764 | + foreach ($passedSubForums as $id) { |
|
765 | + $sub_forums[$id] = isset($subForumTree[$id]) ? $subForumTree[$id] : null; |
|
766 | + } |
|
767 | + } |
|
768 | + |
|
769 | + $forums_id = []; |
|
770 | + foreach (array_keys($sub_forums) as $id) { |
|
771 | + if (empty($sub_forums[$id])) { |
|
772 | + continue; |
|
773 | + } |
|
774 | + $forums_id = array_merge($forums_id, $sub_forums[$id]); |
|
775 | + } |
|
776 | + if (!$forums_id) { |
|
777 | + return $stats; |
|
778 | + } |
|
779 | + $sql = ' SELECT forum_posts AS posts, forum_topics AS topics, forum_id AS id' . ' FROM ' . $this->table . ' WHERE forum_id IN (' . implode(', ', $forums_id) . ')'; |
|
780 | + if (!$result = $this->db->query($sql)) { |
|
781 | + return $stats; |
|
782 | + } |
|
783 | + |
|
784 | + $forum_stats = []; |
|
785 | + while (false !== ($row = $this->db->fetchArray($result))) { |
|
786 | + $forum_stats[$row['id']] = ['topics' => $row['topics'], 'posts' => $row['posts']]; |
|
787 | + } |
|
788 | + |
|
789 | + foreach (array_keys($sub_forums) as $id) { |
|
790 | + if (empty($sub_forums[$id])) { |
|
791 | + continue; |
|
792 | + } |
|
793 | + $stats[$id] = ['topics' => 0, 'posts' => 0]; |
|
794 | + foreach ($sub_forums[$id] as $fid) { |
|
795 | + $stats[$id]['topics'] += $forum_stats[$fid]['topics']; |
|
796 | + $stats[$id]['posts'] += $forum_stats[$fid]['posts']; |
|
797 | + } |
|
798 | + } |
|
799 | + |
|
800 | + return $stats; |
|
801 | + } |
|
802 | + |
|
803 | + /** |
|
804 | + * @param $forums |
|
805 | + * @param int $length_title_index |
|
806 | + * @param int $count_subforum |
|
807 | + * @return array |
|
808 | + */ |
|
809 | + public function &display($forums, $length_title_index = 30, $count_subforum = 1) |
|
810 | + { |
|
811 | + global $myts; |
|
812 | + |
|
813 | + $posts = []; |
|
814 | + $postsObject = []; |
|
815 | + foreach (array_keys($forums) as $id) { |
|
816 | + $posts[] = $forums[$id]['forum_last_post_id']; |
|
817 | + } |
|
818 | + if (!empty($posts)) { |
|
819 | + $postHandler = Newbb\Helper::getInstance()->getHandler('Post'); |
|
820 | + $tags_post = ['uid', 'topic_id', 'post_time', 'poster_name', 'icon']; |
|
821 | + if (!empty($length_title_index)) { |
|
822 | + $tags_post[] = 'subject'; |
|
823 | + } |
|
824 | + $posts = $postHandler->getAll(new \Criteria('post_id', '(' . implode(', ', $posts) . ')', 'IN'), $tags_post, false); |
|
825 | + } |
|
826 | + |
|
827 | + // Get topic/post stats per forum |
|
828 | + $stats_forum = []; |
|
829 | + |
|
830 | + if (!empty($count_subforum)) { |
|
831 | + $stats_forum = $this->getSubforumStats(array_keys($forums)); // irmtfan uncomment to count sub forum posts/topics |
|
832 | + } |
|
833 | + |
|
834 | + $users = []; |
|
835 | + $reads = []; |
|
836 | + $topics = []; |
|
837 | + |
|
838 | + foreach (array_keys($forums) as $id) { |
|
839 | + $forum =& $forums[$id]; |
|
840 | + |
|
841 | + if (!$forum['forum_last_post_id']) { |
|
842 | + continue; |
|
843 | + } |
|
844 | + if (!$post = @$posts[$forum['forum_last_post_id']]) { |
|
845 | + $forum['forum_last_post_id'] = 0; |
|
846 | + continue; |
|
847 | + } |
|
848 | + |
|
849 | + $users[] = $post['uid']; |
|
850 | + if ($moderators[$id] = $forum['forum_moderator']) { |
|
851 | + $users = array_merge($users, $moderators[$id]); |
|
852 | + } |
|
853 | + |
|
854 | + // reads |
|
855 | + if (!empty($GLOBALS['xoopsModuleConfig']['read_mode'])) { |
|
856 | + $reads[$id] = (1 == $GLOBALS['xoopsModuleConfig']['read_mode']) ? $post['post_time'] : $post['post_id']; |
|
857 | + } |
|
858 | + } |
|
859 | + |
|
860 | + require_once $GLOBALS['xoops']->path('modules/newbb/include/functions.user.php'); |
|
861 | + require_once $GLOBALS['xoops']->path('modules/newbb/include/functions.time.php'); |
|
862 | + require_once $GLOBALS['xoops']->path('modules/newbb/include/functions.render.php'); |
|
863 | + require_once $GLOBALS['xoops']->path('modules/newbb/include/functions.read.php'); |
|
864 | + $forum_isread = newbbIsRead('forum', $reads); |
|
865 | + $users_linked = newbbGetUnameFromIds(array_unique($users), !empty($GLOBALS['xoopsModuleConfig']['show_realname']), true); |
|
866 | + |
|
867 | + $forums_array = []; |
|
868 | + $name_anonymous = $myts->htmlSpecialChars($GLOBALS['xoopsConfig']['anonymous']); |
|
869 | + |
|
870 | + foreach (array_keys($forums) as $id) { |
|
871 | + $forum =& $forums[$id]; |
|
872 | + |
|
873 | + $_forum_data = []; |
|
874 | + $_forum_data['forum_order'] = $forum['forum_order']; |
|
875 | + $_forum_data['forum_id'] = $id; |
|
876 | + $_forum_data['forum_cid'] = $forum['cat_id']; |
|
877 | + $_forum_data['forum_name'] = $forum['forum_name']; |
|
878 | + $forumDescLength = $GLOBALS['xoopsModuleConfig']['forum_desc_length']; |
|
879 | + $_forum_data['forum_desc'] = mb_strimwidth($forum['forum_desc'], 0, $forumDescLength, '...'); |
|
880 | + $_forum_data['forum_topics'] = $forum['forum_topics'] + @$stats_forum[$id]['topics']; |
|
881 | + $_forum_data['forum_posts'] = $forum['forum_posts'] + @$stats_forum[$id]['posts']; |
|
882 | + //$_forum_data["forum_type"]= $forum['forum_type']; |
|
883 | + |
|
884 | + $forum_moderators = []; |
|
885 | + if (!empty($moderators[$id])) { |
|
886 | + foreach (@$moderators[$id] as $moderator) { |
|
887 | + $forum_moderators[] = @$users_linked[$moderator]; |
|
888 | + } |
|
889 | + } |
|
890 | + $_forum_data['forum_moderators'] = implode(', ', $forum_moderators); |
|
891 | + |
|
892 | + // irmtfan change if/endif to if{} method |
|
893 | + if ($post_id = $forum['forum_last_post_id']) { |
|
894 | + $post =& $posts[$post_id]; |
|
895 | + $_forum_data['forum_lastpost_id'] = $post_id; |
|
896 | + $_forum_data['forum_lastpost_time'] = newbbFormatTimestamp($post['post_time']); |
|
897 | + if (!empty($users_linked[$post['uid']])) { |
|
898 | + $_forum_data['forum_lastpost_user'] = $users_linked[$post['uid']]; |
|
899 | + } elseif ($poster_name = $post['poster_name']) { |
|
900 | + $_forum_data['forum_lastpost_user'] = $poster_name; |
|
901 | + } else { |
|
902 | + $_forum_data['forum_lastpost_user'] = $name_anonymous; |
|
903 | + } |
|
904 | + if (!empty($length_title_index)) { |
|
905 | + $subject = $post['subject']; |
|
906 | + if ($length_title_index < 255) { |
|
907 | + $subject = xoops_substr($subject, 0, $length_title_index); |
|
908 | + } |
|
909 | + $_forum_data['forum_lastpost_subject'] = $subject; |
|
910 | + } |
|
911 | + // irmtfan - remove icon_path and use newbbDisplayImage |
|
912 | + $_forum_data['forum_lastpost_icon'] = newbbDisplayImage('lastposticon', _MD_NEWBB_GOTOLASTPOST); |
|
913 | + // START irmtfan change the method to add read smarty |
|
914 | + if (empty($forum_isread[$id])) { |
|
915 | + $_forum_data['forum_folder'] = newbbDisplayImage('forum_new', _MD_NEWBB_NEWPOSTS); |
|
916 | + $_forum_data['forum_read'] = 0; // irmtfan add forum-read/forum-new smarty variable |
|
917 | + } else { |
|
918 | + $_forum_data['forum_folder'] = newbbDisplayImage('forum', _MD_NEWBB_NONEWPOSTS); |
|
919 | + $_forum_data['forum_read'] = 1; // irmtfan add forum-read/forum-new smarty variable |
|
920 | + } |
|
921 | + // END irmtfan change the method to add read smarty |
|
922 | + } |
|
923 | + $forums_array[$forum['parent_forum']][] = $_forum_data; |
|
924 | + } |
|
925 | + |
|
926 | + return $forums_array; |
|
927 | + } |
|
928 | + |
|
929 | + /** |
|
930 | + * get a hierarchical tree of forums |
|
931 | + * |
|
932 | + * {@link newbbTree} |
|
933 | + * |
|
934 | + * @param int $cat_id category ID |
|
935 | + * @param int $pid Top forum ID |
|
936 | + * @param string $permission permission type |
|
937 | + * @param string $prefix prefix for display |
|
938 | + * @param string|array|null $tags variables to fetch |
|
939 | + * @return array associative array of category IDs and sanitized titles |
|
940 | + */ |
|
941 | + public function &getTree($cat_id = 0, $pid = 0, $permission = 'access', $prefix = '--', $tags = null) |
|
942 | + { |
|
943 | + $pid = (int)$pid; |
|
944 | + $perm_string = $permission; |
|
945 | + if (!is_array($tags) || 0 === count($tags)) { |
|
946 | + $tags = ['forum_id', 'parent_forum', 'forum_name', 'forum_order', 'cat_id']; |
|
947 | + } |
|
948 | + $forumsObject = $this->getByPermission($cat_id, $perm_string, $tags); |
|
949 | + |
|
950 | + require_once __DIR__ . '/Tree.php'; |
|
951 | + $forums_structured = []; |
|
952 | + foreach (array_keys($forumsObject) as $key) { |
|
953 | + $forums_structured[$forumsObject[$key]->getVar('cat_id')][$key] = $forumsObject[$key]; |
|
954 | + } |
|
955 | + |
|
956 | + foreach (array_keys($forums_structured) as $cid) { |
|
957 | + $tree = new ObjectTree($forums_structured[$cid]); |
|
958 | + $forum_array[$cid] = $tree->makeTree($prefix, $pid, $tags); |
|
959 | + unset($tree); |
|
960 | + } |
|
961 | + |
|
962 | + return $forum_array; |
|
963 | + } |
|
964 | + |
|
965 | + /** |
|
966 | + * get a hierarchical array tree of forums |
|
967 | + * |
|
968 | + * {@link newbbTree} |
|
969 | + * |
|
970 | + * @param int $cat_id category ID |
|
971 | + * @param int $pid Top forum ID |
|
972 | + * @param string $permission permission type |
|
973 | + * @param string|array|null $tags variables to fetch |
|
974 | + * @param integer $depth level of subcategories |
|
975 | + * @return array associative array of category IDs and sanitized titles |
|
976 | + */ |
|
977 | + public function &getArrayTree($cat_id = 0, $pid = 0, $permission = 'access', $tags = null, $depth = 0) |
|
978 | + { |
|
979 | + $pid = (int)$pid; |
|
980 | + $perm_string = $permission; |
|
981 | + if (!is_array($tags) || 0 === count($tags)) { |
|
982 | + $tags = ['forum_id', 'parent_forum', 'forum_name', 'forum_order', 'cat_id']; |
|
983 | + } |
|
984 | + $forumsObject = $this->getByPermission($cat_id, $perm_string, $tags); |
|
985 | + |
|
986 | + require_once __DIR__ . '/Tree.php'; |
|
987 | + $forums_structured = []; |
|
988 | + foreach (array_keys($forumsObject) as $key) { |
|
989 | + $forumObject =& $forumsObject[$key]; |
|
990 | + $forums_structured[$forumObject->getVar('cat_id')][$key] = $forumsObject[$key]; |
|
991 | + } |
|
992 | + foreach (array_keys($forums_structured) as $cid) { |
|
993 | + $tree = new ObjectTree($forums_structured[$cid]); |
|
994 | + $forum_array[$cid] = $tree->makeArrayTree($pid, $tags, $depth); |
|
995 | + unset($tree); |
|
996 | + } |
|
997 | + |
|
998 | + return $forum_array; |
|
999 | + } |
|
1000 | + |
|
1001 | + /** |
|
1002 | + * @param $object |
|
1003 | + * @return array|null |
|
1004 | + */ |
|
1005 | + public function &getParents($object) |
|
1006 | + { |
|
1007 | + $ret = null; |
|
1008 | + if (!$object->getVar('forum_id')) { |
|
1009 | + return $ret; |
|
1010 | + } |
|
1011 | + |
|
1012 | + require_once $GLOBALS['xoops']->path('modules/newbb/include/functions.forum.php'); |
|
1013 | + if (!$parents = newbbGetParentForum($object->getVar('forum_id'))) { |
|
1014 | + return $ret; |
|
1015 | + } |
|
1016 | + $parents_list = $this->getList(new \Criteria('forum_id', '(' . implode(', ', $parents) . ')', 'IN')); |
|
1017 | + foreach ($parents as $key => $id) { |
|
1018 | + $ret[] = ['forum_id' => $id, 'forum_name' => $parents_list[$id]]; |
|
1019 | + } |
|
1020 | + unset($parents, $parents_list); |
|
1021 | + |
|
1022 | + return $ret; |
|
1023 | + } |
|
1024 | + |
|
1025 | + // START irmtfan - get forum Ids by values. parse positive values to forum IDs and negative values to category IDs. value=0 => all valid forums |
|
1026 | + |
|
1027 | + /** |
|
1028 | + * function for get forum Ids by positive and negative values |
|
1029 | + * |
|
1030 | + * @param int|text|array $values : positive values = forums | negative values = cats | $values=0 = all valid forums, $permission , true/false $parse_cats |
|
1031 | + * @param string $permission |
|
1032 | + * @param bool $parse_cats |
|
1033 | + * @return array|mixed $validForums |
|
1034 | + */ |
|
1035 | + public function getIdsByValues($values = 0, $permission = 'access', $parse_cats = true) |
|
1036 | + { |
|
1037 | + // Get all valid forums with this permission |
|
1038 | + $validForums = $this->getIdsByPermission($permission); |
|
1039 | + // if no value or value=0 return all valid forums |
|
1040 | + if (empty($values)) { |
|
1041 | + return $validForums; |
|
1042 | + } |
|
1043 | + $values = is_numeric($values) ? [$values] : $values; |
|
1044 | + //parse negative values to category IDs |
|
1045 | + $forums = []; |
|
1046 | + $cats = []; |
|
1047 | + foreach ($values as $val) { |
|
1048 | + if (0 == $val) { |
|
1049 | + // value=0 => all valid forums |
|
1050 | + return $validForums; |
|
1051 | + } elseif ($val > 0) { |
|
1052 | + $forums[] = $val; |
|
1053 | + } else { |
|
1054 | + $cats[] = abs($val); |
|
1055 | + } |
|
1056 | + } |
|
1057 | + // if dont want to parse categories OR no cats return all forums |
|
1058 | + if (empty($parse_cats) || empty($cats)) { |
|
1059 | + return array_intersect($validForums, $forums); |
|
1060 | + } |
|
1061 | + // Get all forums by category IDs |
|
1062 | + $forumObjs = $this->getForumsByCategory($cats, $permission, true); |
|
1063 | + $forums = array_merge($forums, array_keys($forumObjs)); |
|
1064 | + |
|
1065 | + return array_intersect($validForums, $forums); |
|
1066 | + } |
|
1067 | + // END irmtfan - get forum Ids by values. parse positive values to forum IDs and negative values to category IDs. value=0 => all valid forums |
|
1068 | 1068 | } |
@@ -48,105 +48,105 @@ |
||
48 | 48 | */ |
49 | 49 | class ReadForumHandler extends Newbb\ReadHandler |
50 | 50 | { |
51 | - /** |
|
52 | - * @param \XoopsDatabase|null $db |
|
53 | - */ |
|
54 | - public function __construct(\XoopsDatabase $db = null) |
|
55 | - { |
|
56 | - parent::__construct($db, 'forum'); |
|
57 | - } |
|
58 | - |
|
59 | - /** |
|
60 | - * clean orphan items from database |
|
61 | - * |
|
62 | - * @param string $table_link |
|
63 | - * @param string $field_link |
|
64 | - * @param string $field_object |
|
65 | - * @return bool true on success |
|
66 | - */ |
|
67 | - public function cleanOrphan($table_link = '', $field_link = '', $field_object = '') //cleanOrphan() |
|
68 | - { |
|
69 | - parent::cleanOrphan($this->db->prefix('newbb_posts'), 'post_id'); |
|
70 | - |
|
71 | - return parent::cleanOrphan($this->db->prefix('newbb_forums'), 'forum_id', 'read_item'); |
|
72 | - } |
|
73 | - |
|
74 | - /** |
|
75 | - * @param int $status |
|
76 | - * @param null $uid |
|
77 | - * @return bool |
|
78 | - */ |
|
79 | - public function setReadItems($status = 0, $uid = null) |
|
80 | - { |
|
81 | - if (empty($this->mode)) { |
|
82 | - return true; |
|
83 | - } |
|
84 | - |
|
85 | - if (1 == $this->mode) { |
|
86 | - return $this->setReadItemsCookie($status); |
|
87 | - } else { |
|
88 | - return $this->setReadItemsDb($status, $uid); |
|
89 | - } |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * @param $status |
|
94 | - * @param $items |
|
95 | - * @return bool |
|
96 | - */ |
|
97 | - public function setReadItemsCookie($status, $items) |
|
98 | - { |
|
99 | - $cookie_name = 'LF'; |
|
100 | - $items = []; |
|
101 | - if (!empty($status)) { |
|
102 | - /** @var Newbb\ForumHandler $itemHandler */ |
|
103 | - $itemHandler = Newbb\Helper::getInstance()->getHandler('Forum'); |
|
104 | - $items_id = $itemHandler->getIds(); |
|
105 | - foreach ($items_id as $key) { |
|
106 | - $items[$key] = time(); |
|
107 | - } |
|
108 | - } |
|
109 | - newbbSetCookie($cookie_name, $items); |
|
110 | - |
|
111 | - return true; |
|
112 | - } |
|
113 | - |
|
114 | - /** |
|
115 | - * @param $status |
|
116 | - * @param $uid |
|
117 | - * @return bool |
|
118 | - */ |
|
119 | - public function setReadItemsDb($status, $uid) |
|
120 | - { |
|
121 | - if (empty($uid)) { |
|
122 | - if (is_object($GLOBALS['xoopsUser'])) { |
|
123 | - $uid = $GLOBALS['xoopsUser']->getVar('uid'); |
|
124 | - } else { |
|
125 | - return false; |
|
126 | - } |
|
127 | - } |
|
128 | - if (empty($status)) { |
|
129 | - $this->deleteAll(new \Criteria('uid', $uid)); |
|
130 | - |
|
131 | - return true; |
|
132 | - } |
|
133 | - |
|
134 | - /** @var Newbb\ForumHandler $itemHandler */ |
|
135 | - $itemHandler = Newbb\Helper::getInstance()->getHandler('Forum'); |
|
136 | - $itemsObject = $itemHandler->getAll(null, ['forum_last_post_id']); |
|
137 | - foreach (array_keys($itemsObject) as $key) { |
|
138 | - $this->setReadDb($key, $itemsObject[$key]->getVar('forum_last_post_id'), $uid); |
|
139 | - } |
|
140 | - unset($itemsObject); |
|
141 | - |
|
142 | - return true; |
|
143 | - } |
|
144 | - |
|
145 | - /** |
|
146 | - * |
|
147 | - */ |
|
148 | - public function synchronization() |
|
149 | - { |
|
150 | - // return; |
|
151 | - } |
|
51 | + /** |
|
52 | + * @param \XoopsDatabase|null $db |
|
53 | + */ |
|
54 | + public function __construct(\XoopsDatabase $db = null) |
|
55 | + { |
|
56 | + parent::__construct($db, 'forum'); |
|
57 | + } |
|
58 | + |
|
59 | + /** |
|
60 | + * clean orphan items from database |
|
61 | + * |
|
62 | + * @param string $table_link |
|
63 | + * @param string $field_link |
|
64 | + * @param string $field_object |
|
65 | + * @return bool true on success |
|
66 | + */ |
|
67 | + public function cleanOrphan($table_link = '', $field_link = '', $field_object = '') //cleanOrphan() |
|
68 | + { |
|
69 | + parent::cleanOrphan($this->db->prefix('newbb_posts'), 'post_id'); |
|
70 | + |
|
71 | + return parent::cleanOrphan($this->db->prefix('newbb_forums'), 'forum_id', 'read_item'); |
|
72 | + } |
|
73 | + |
|
74 | + /** |
|
75 | + * @param int $status |
|
76 | + * @param null $uid |
|
77 | + * @return bool |
|
78 | + */ |
|
79 | + public function setReadItems($status = 0, $uid = null) |
|
80 | + { |
|
81 | + if (empty($this->mode)) { |
|
82 | + return true; |
|
83 | + } |
|
84 | + |
|
85 | + if (1 == $this->mode) { |
|
86 | + return $this->setReadItemsCookie($status); |
|
87 | + } else { |
|
88 | + return $this->setReadItemsDb($status, $uid); |
|
89 | + } |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * @param $status |
|
94 | + * @param $items |
|
95 | + * @return bool |
|
96 | + */ |
|
97 | + public function setReadItemsCookie($status, $items) |
|
98 | + { |
|
99 | + $cookie_name = 'LF'; |
|
100 | + $items = []; |
|
101 | + if (!empty($status)) { |
|
102 | + /** @var Newbb\ForumHandler $itemHandler */ |
|
103 | + $itemHandler = Newbb\Helper::getInstance()->getHandler('Forum'); |
|
104 | + $items_id = $itemHandler->getIds(); |
|
105 | + foreach ($items_id as $key) { |
|
106 | + $items[$key] = time(); |
|
107 | + } |
|
108 | + } |
|
109 | + newbbSetCookie($cookie_name, $items); |
|
110 | + |
|
111 | + return true; |
|
112 | + } |
|
113 | + |
|
114 | + /** |
|
115 | + * @param $status |
|
116 | + * @param $uid |
|
117 | + * @return bool |
|
118 | + */ |
|
119 | + public function setReadItemsDb($status, $uid) |
|
120 | + { |
|
121 | + if (empty($uid)) { |
|
122 | + if (is_object($GLOBALS['xoopsUser'])) { |
|
123 | + $uid = $GLOBALS['xoopsUser']->getVar('uid'); |
|
124 | + } else { |
|
125 | + return false; |
|
126 | + } |
|
127 | + } |
|
128 | + if (empty($status)) { |
|
129 | + $this->deleteAll(new \Criteria('uid', $uid)); |
|
130 | + |
|
131 | + return true; |
|
132 | + } |
|
133 | + |
|
134 | + /** @var Newbb\ForumHandler $itemHandler */ |
|
135 | + $itemHandler = Newbb\Helper::getInstance()->getHandler('Forum'); |
|
136 | + $itemsObject = $itemHandler->getAll(null, ['forum_last_post_id']); |
|
137 | + foreach (array_keys($itemsObject) as $key) { |
|
138 | + $this->setReadDb($key, $itemsObject[$key]->getVar('forum_last_post_id'), $uid); |
|
139 | + } |
|
140 | + unset($itemsObject); |
|
141 | + |
|
142 | + return true; |
|
143 | + } |
|
144 | + |
|
145 | + /** |
|
146 | + * |
|
147 | + */ |
|
148 | + public function synchronization() |
|
149 | + { |
|
150 | + // return; |
|
151 | + } |
|
152 | 152 | } |
@@ -19,24 +19,24 @@ |
||
19 | 19 | */ |
20 | 20 | class TextHandler extends \XoopsPersistableObjectHandler |
21 | 21 | { |
22 | - /** |
|
23 | - * @param \XoopsDatabase $db |
|
24 | - */ |
|
25 | - public function __construct(\XoopsDatabase $db = null) |
|
26 | - { |
|
27 | - parent::__construct($db, 'newbb_posts_text', Text::class, 'post_id', ''); |
|
28 | - } |
|
22 | + /** |
|
23 | + * @param \XoopsDatabase $db |
|
24 | + */ |
|
25 | + public function __construct(\XoopsDatabase $db = null) |
|
26 | + { |
|
27 | + parent::__construct($db, 'newbb_posts_text', Text::class, 'post_id', ''); |
|
28 | + } |
|
29 | 29 | |
30 | - /** |
|
31 | - * clean orphan items from database |
|
32 | - * |
|
33 | - * @param string $table_link |
|
34 | - * @param string $field_link |
|
35 | - * @param string $field_object |
|
36 | - * @return bool true on success |
|
37 | - */ |
|
38 | - public function cleanOrphan($table_link = '', $field_link = '', $field_object = '') //cleanOrphan() |
|
39 | - { |
|
40 | - return parent::cleanOrphan($this->db->prefix('newbb_posts'), 'post_id'); |
|
41 | - } |
|
30 | + /** |
|
31 | + * clean orphan items from database |
|
32 | + * |
|
33 | + * @param string $table_link |
|
34 | + * @param string $field_link |
|
35 | + * @param string $field_object |
|
36 | + * @return bool true on success |
|
37 | + */ |
|
38 | + public function cleanOrphan($table_link = '', $field_link = '', $field_object = '') //cleanOrphan() |
|
39 | + { |
|
40 | + return parent::cleanOrphan($this->db->prefix('newbb_posts'), 'post_id'); |
|
41 | + } |
|
42 | 42 | } |
@@ -25,1133 +25,1133 @@ |
||
25 | 25 | */ |
26 | 26 | class TopicRenderer |
27 | 27 | { |
28 | - public $vars = []; |
|
29 | - |
|
30 | - /** |
|
31 | - * reference to moduleConfig |
|
32 | - */ |
|
33 | - public $config; |
|
34 | - |
|
35 | - /** |
|
36 | - * Current user has no access to current page |
|
37 | - */ |
|
38 | - private $noperm = false; |
|
39 | - |
|
40 | - /** |
|
41 | - * For multiple forums |
|
42 | - */ |
|
43 | - public $is_multiple = false; |
|
44 | - |
|
45 | - /** |
|
46 | - * force to parse vars (run against static vars) irmtfan |
|
47 | - */ |
|
48 | - public $force = false; |
|
49 | - |
|
50 | - /** |
|
51 | - * Vistitor's level: 0 - anonymous; 1 - user; 2 - moderator or admin |
|
52 | - */ |
|
53 | - public $userlevel = 0; |
|
54 | - |
|
55 | - public $query = []; |
|
56 | - |
|
57 | - /** |
|
58 | - * reference to an object handler |
|
59 | - */ |
|
60 | - private $handler; |
|
61 | - |
|
62 | - /** |
|
63 | - * Requested page |
|
64 | - */ |
|
65 | - private $page = 'list.topic.php'; |
|
66 | - |
|
67 | - /** |
|
68 | - * query variables |
|
69 | - */ |
|
70 | - private $args = ['forum', 'uid', 'lastposter', 'type', 'status', 'mode', 'sort', 'order', 'start', 'since']; |
|
71 | - |
|
72 | - /** |
|
73 | - * Constructor |
|
74 | - */ |
|
75 | - // public function TopicRenderer() |
|
76 | - public function __construct() |
|
77 | - { |
|
78 | - $this->handler = Newbb\Helper::getInstance()->getHandler('Topic'); |
|
79 | - } |
|
80 | - |
|
81 | - /** |
|
82 | - * Access the only instance of this class |
|
83 | - * @return TopicRenderer |
|
84 | - */ |
|
85 | - public static function getInstance() |
|
86 | - { |
|
87 | - static $instance; |
|
88 | - if (null === $instance) { |
|
89 | - $instance = new static(); |
|
90 | - } |
|
91 | - |
|
92 | - return $instance; |
|
93 | - } |
|
94 | - |
|
95 | - public function init() |
|
96 | - { |
|
97 | - $this->noperm = false; |
|
98 | - $this->query = []; |
|
99 | - } |
|
100 | - |
|
101 | - /** |
|
102 | - * @param $var |
|
103 | - * @param $val |
|
104 | - * @return array|int|string |
|
105 | - */ |
|
106 | - public function setVar($var, $val) |
|
107 | - { |
|
108 | - switch ($var) { |
|
109 | - case 'forum': |
|
110 | - if (is_numeric($val)) { |
|
111 | - $val = (int)$val; |
|
112 | - // START irmtfan - if the forum is array |
|
113 | - } elseif (is_array($val)) { |
|
114 | - $val = implode('|', $val); |
|
115 | - //} elseif (!empty($val)) { |
|
116 | - // $val = implode("|", array_map("intval", explode(", ", $val))); |
|
117 | - } |
|
118 | - // END irmtfan - if the forum is array |
|
119 | - break; |
|
120 | - |
|
121 | - case 'type': |
|
122 | - case 'mode': |
|
123 | - case 'order': |
|
124 | - case 'start': |
|
125 | - case 'since': |
|
126 | - $val = (int)$val; |
|
127 | - break; |
|
128 | - |
|
129 | - case 'uid': // irmtfan add multi topic poster |
|
130 | - case 'lastposter': // irmtfan add multi lastposter |
|
131 | - break; |
|
132 | - |
|
133 | - case 'status': |
|
134 | - // START irmtfan to accept multiple status |
|
135 | - $val = is_array($val) ? $val : [$val]; |
|
136 | - $val = implode(',', $val); |
|
137 | - //$val = (in_array($val, array_keys($this->getStatus( $this->userlevel ))) ) ? $val : "all"; //irmtfan no need to check if status is empty or not |
|
138 | - //if ($val === "all" && !$this->is_multiple) $val = ""; irmtfan commented because it is done in sort |
|
139 | - // END irmtfan to accept multiple status |
|
140 | - break; |
|
141 | - |
|
142 | - default: |
|
143 | - break; |
|
144 | - } |
|
145 | - |
|
146 | - return $val; |
|
147 | - } |
|
148 | - |
|
149 | - /** |
|
150 | - * @param array $vars |
|
151 | - */ |
|
152 | - public function setVars(array $vars = []) |
|
153 | - { |
|
154 | - $this->init(); |
|
155 | - |
|
156 | - foreach ($vars as $var => $val) { |
|
157 | - if (!in_array($var, $this->args)) { |
|
158 | - continue; |
|
159 | - } |
|
160 | - $this->vars[$var] = $this->setVar($var, $val); |
|
161 | - } |
|
162 | - $this->parseVars(); |
|
163 | - } |
|
164 | - |
|
165 | - /** |
|
166 | - * @param null $status |
|
167 | - */ |
|
168 | - public function myParseStatus($status = null) |
|
169 | - { |
|
170 | - switch ($status) { |
|
171 | - case 'digest': |
|
172 | - $this->query['where'][] = 't.topic_digest = 1'; |
|
173 | - break; |
|
174 | - |
|
175 | - case 'undigest': |
|
176 | - $this->query['where'][] = 't.topic_digest = 0'; |
|
177 | - break; |
|
178 | - |
|
179 | - case 'sticky': |
|
180 | - $this->query['where'][] = 't.topic_sticky = 1'; |
|
181 | - break; |
|
182 | - |
|
183 | - case 'unsticky': |
|
184 | - $this->query['where'][] = 't.topic_sticky = 0'; |
|
185 | - break; |
|
186 | - |
|
187 | - case 'lock': |
|
188 | - $this->query['where'][] = 't.topic_status = 1'; |
|
189 | - break; |
|
190 | - |
|
191 | - case 'unlock': |
|
192 | - $this->query['where'][] = 't.topic_status = 0'; |
|
193 | - break; |
|
194 | - |
|
195 | - case 'poll': |
|
196 | - $this->query['where'][] = 't.topic_haspoll = 1'; |
|
197 | - break; |
|
198 | - |
|
199 | - case 'unpoll': |
|
200 | - $this->query['where'][] = 't.topic_haspoll = 0'; |
|
201 | - break; |
|
202 | - |
|
203 | - case 'voted': |
|
204 | - $this->query['where'][] = 't.votes > 0'; |
|
205 | - break; |
|
206 | - |
|
207 | - case 'unvoted': |
|
208 | - $this->query['where'][] = 't.votes < 1'; |
|
209 | - break; |
|
210 | - |
|
211 | - case 'replied': |
|
212 | - $this->query['where'][] = 't.topic_replies > 0'; |
|
213 | - break; |
|
214 | - |
|
215 | - case 'unreplied': |
|
216 | - $this->query['where'][] = 't.topic_replies < 1'; |
|
217 | - break; |
|
218 | - |
|
219 | - case 'viewed': |
|
220 | - $this->query['where'][] = 't.topic_views > 0'; |
|
221 | - break; |
|
222 | - |
|
223 | - case 'unviewed': |
|
224 | - $this->query['where'][] = 't.topic_views < 1'; |
|
225 | - break; |
|
226 | - |
|
227 | - case 'read': |
|
228 | - // Skip |
|
229 | - if (empty($this->config['read_mode'])) { |
|
230 | - // Use database |
|
231 | - } elseif (2 == $this->config['read_mode']) { |
|
232 | - // START irmtfan use read_uid to find the unread posts when the user is logged in |
|
233 | - $read_uid = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getVar('uid') : 0; |
|
234 | - if (!empty($read_uid)) { |
|
235 | - $this->query['join'][] = 'LEFT JOIN ' . $this->handler->db->prefix('newbb_reads_topic') . ' AS r ON r.read_item = t.topic_id AND r.uid = ' . $read_uid . ' '; |
|
236 | - $this->query['where'][] = 'r.post_id = t.topic_last_post_id'; |
|
237 | - } else { |
|
238 | - } |
|
239 | - // END irmtfan change criteria to get from uid p.uid = last post submit user id |
|
240 | - // User cookie |
|
241 | - } elseif (1 == $this->config['read_mode']) { |
|
242 | - // START irmtfan fix read_mode = 1 bugs - for all users (member and anon) |
|
243 | - $startdate = !empty($this->vars['since']) ? (time() - newbbGetSinceTime($this->vars['since'])) : 0; |
|
244 | - if ($lastvisit = max($GLOBALS['last_visit'], $startdate)) { |
|
245 | - $readmode1query = ''; |
|
246 | - if ($lastvisit > $startdate) { |
|
247 | - $readmode1query = 'p.post_time < ' . $lastvisit; |
|
248 | - } |
|
249 | - $topics = []; |
|
250 | - $topic_lastread = newbbGetCookie('LT', true); |
|
251 | - if (count($topic_lastread) > 0) { |
|
252 | - foreach ($topic_lastread as $id => $time) { |
|
253 | - if ($time > $lastvisit) { |
|
254 | - $topics[] = $id; |
|
255 | - } |
|
256 | - } |
|
257 | - } |
|
258 | - if (count($topics) > 0) { |
|
259 | - $topicquery = ' t.topic_id IN (' . implode(',', $topics) . ')'; |
|
260 | - // because it should be OR |
|
261 | - $readmode1query = !empty($readmode1query) ? '(' . $readmode1query . ' OR ' . $topicquery . ')' : $topicquery; |
|
262 | - } |
|
263 | - $this->query['where'][] = $readmode1query; |
|
264 | - } |
|
265 | - // END irmtfan fix read_mode = 1 bugs - for all users (member and anon) |
|
266 | - } |
|
267 | - break; |
|
268 | - |
|
269 | - case 'unread': |
|
270 | - // Skip |
|
271 | - if (empty($this->config['read_mode'])) { |
|
272 | - // Use database |
|
273 | - } elseif (2 == $this->config['read_mode']) { |
|
274 | - // START irmtfan use read_uid to find the unread posts when the user is logged in |
|
275 | - $read_uid = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getVar('uid') : 0; |
|
276 | - if (!empty($read_uid)) { |
|
277 | - $this->query['join'][] = 'LEFT JOIN ' . $this->handler->db->prefix('newbb_reads_topic') . ' AS r ON r.read_item = t.topic_id AND r.uid = ' . $read_uid . ' '; |
|
278 | - $this->query['where'][] = '(r.read_id IS NULL OR r.post_id < t.topic_last_post_id)'; |
|
279 | - } else { |
|
280 | - } |
|
281 | - // END irmtfan change criteria to get from uid p.uid = last post submit user id |
|
282 | - // User cookie |
|
283 | - } elseif (1 == $this->config['read_mode']) { |
|
284 | - // START irmtfan fix read_mode = 1 bugs - for all users (member and anon) |
|
285 | - $startdate = !empty($this->vars['since']) ? (time() - newbbGetSinceTime($this->vars['since'])) : 0; |
|
286 | - if ($lastvisit = max($GLOBALS['last_visit'], $startdate)) { |
|
287 | - if ($lastvisit > $startdate) { |
|
288 | - $this->query['where'][] = 'p.post_time > ' . $lastvisit; |
|
289 | - } |
|
290 | - $topics = []; |
|
291 | - $topic_lastread = newbbGetCookie('LT', true); |
|
292 | - if (count($topic_lastread) > 0) { |
|
293 | - foreach ($topic_lastread as $id => $time) { |
|
294 | - if ($time > $lastvisit) { |
|
295 | - $topics[] = $id; |
|
296 | - } |
|
297 | - } |
|
298 | - } |
|
299 | - if (count($topics) > 0) { |
|
300 | - $this->query['where'][] = ' t.topic_id NOT IN (' . implode(',', $topics) . ')'; |
|
301 | - } |
|
302 | - } |
|
303 | - // END irmtfan fix read_mode = 1 bugs - for all users (member and anon) |
|
304 | - } |
|
305 | - break; |
|
306 | - |
|
307 | - case 'pending': |
|
308 | - if ($this->userlevel < 2) { |
|
309 | - $this->noperm = true; |
|
310 | - } else { |
|
311 | - $this->query['where'][] = 't.approved = 0'; |
|
312 | - } |
|
313 | - break; |
|
314 | - |
|
315 | - case 'deleted': |
|
316 | - if ($this->userlevel < 2) { |
|
317 | - $this->noperm = true; |
|
318 | - } else { |
|
319 | - $this->query['where'][] = 't.approved = -1'; |
|
320 | - } |
|
321 | - break; |
|
322 | - |
|
323 | - case 'all': // For viewall.php; do not display sticky topics at first |
|
324 | - case 'active': // same as 'all' |
|
325 | - $this->query['where'][] = 't.approved = 1'; |
|
326 | - break; |
|
327 | - |
|
328 | - default: // irmtfan do nothing |
|
329 | - break; |
|
330 | - } |
|
331 | - } |
|
332 | - |
|
333 | - /** |
|
334 | - * @param $var |
|
335 | - * @param $val |
|
336 | - */ |
|
337 | - public function parseVar($var, $val) |
|
338 | - { |
|
339 | - switch ($var) { |
|
340 | - case 'forum': |
|
341 | - /** @var Newbb\ForumHandler $forumHandler */ |
|
342 | - $forumHandler = Newbb\Helper::getInstance()->getHandler('Forum'); |
|
343 | - // START irmtfan - get forum Ids by values. parse positive values to forum IDs and negative values to category IDs. value=0 => all valid forums |
|
344 | - // Get accessible forums |
|
345 | - $accessForums = $forumHandler->getIdsByValues(array_map('intval', @explode('|', $val))); |
|
346 | - // Filter specified forums if any |
|
347 | - //if (!empty($val) && $_forums = @explode('|', $val)) { |
|
348 | - //$accessForums = array_intersect($accessForums, array_map('intval', $_forums)); |
|
349 | - //} |
|
350 | - $this->vars['forum'] = $this->setVar('forum', $accessForums); |
|
351 | - // END irmtfan - get forum Ids by values. parse positive values to forum IDs and negative values to category IDs. value=0 => all valid forums |
|
352 | - |
|
353 | - if (empty($accessForums)) { |
|
354 | - $this->noperm = true; |
|
355 | - // irmtfan - it just return return the forum_id only when the forum_id is the first allowed forum - no need for this code implode is enough removed. |
|
356 | - //} elseif (count($accessForums) === 1) { |
|
357 | - //$this->query["where"][] = "t.forum_id = " . $accessForums[0]; |
|
358 | - } else { |
|
359 | - $this->query['where'][] = 't.forum_id IN ( ' . implode(', ', $accessForums) . ' )'; |
|
360 | - } |
|
361 | - break; |
|
362 | - |
|
363 | - case 'uid': // irmtfan add multi topic poster |
|
364 | - if (-1 !== $val) { |
|
365 | - $val = implode(',', array_map('intval', explode(',', $val))); |
|
366 | - $this->query['where'][] = 't.topic_poster IN ( ' . $val . ' )'; |
|
367 | - } |
|
368 | - break; |
|
369 | - case 'lastposter': // irmtfan add multi lastposter |
|
370 | - if (-1 !== $val) { |
|
371 | - $val = implode(',', array_map('intval', explode(',', $val))); |
|
372 | - $this->query['where'][] = 'p.uid IN ( ' . $val . ' )'; |
|
373 | - } |
|
374 | - break; |
|
375 | - |
|
376 | - case 'since': |
|
377 | - if (!empty($val)) { |
|
378 | - // START irmtfan if unread && read_mode = 1 and last_visit > startdate do not add where query | to accept multiple status |
|
379 | - $startdate = time() - newbbGetSinceTime($val); |
|
380 | - if (in_array('unread', explode(',', $this->vars['status'], true)) && 1 == $this->config['read_mode'] |
|
381 | - && $GLOBALS['last_visit'] > $startdate) { |
|
382 | - break; |
|
383 | - } |
|
384 | - // irmtfan digest_time | to accept multiple status |
|
385 | - if (in_array('digest', explode(',', $this->vars['status'], true))) { |
|
386 | - $this->query['where'][] = 't.digest_time > ' . $startdate; |
|
387 | - } |
|
388 | - // irmtfan - should be >= instead of = |
|
389 | - $this->query['where'][] = 'p.post_time >= ' . $startdate; |
|
390 | - // END irmtfan if unread && read_mode = 1 and last_visit > startdate do not add where query |
|
391 | - } |
|
392 | - break; |
|
393 | - |
|
394 | - case 'type': |
|
395 | - if (!empty($val)) { |
|
396 | - $this->query['where'][] = 't.type_id = ' . $val; |
|
397 | - } |
|
398 | - break; |
|
399 | - |
|
400 | - case 'status': |
|
401 | - // START irmtfan to accept multiple status |
|
402 | - $val = explode(',', $val); |
|
403 | - // irmtfan - add 'all' to always parse t.approved = 1 |
|
404 | - if (0 === count(array_intersect($val, ['all', 'active', 'pending', 'deleted']))) { |
|
405 | - $val[] = 'all'; |
|
406 | - } |
|
407 | - foreach ($val as $key => $status) { |
|
408 | - $this->myParseStatus($status); |
|
409 | - } |
|
410 | - // END irmtfan to accept multiple status |
|
411 | - break; |
|
412 | - |
|
413 | - case 'sort': |
|
414 | - if ($sort = $this->getSort($val, 'sort')) { |
|
415 | - $this->query['sort'][] = $sort . (empty($this->vars['order']) ? ' DESC' : ' ASC'); |
|
416 | - } else { // irmtfan if sort is not in the list |
|
417 | - $this->query['sort'][] = 't.topic_last_post_id' . (empty($this->vars['order']) ? ' DESC' : ' ASC'); |
|
418 | - } |
|
419 | - break; |
|
420 | - |
|
421 | - default: |
|
422 | - break; |
|
423 | - } |
|
424 | - } |
|
425 | - |
|
426 | - /** |
|
427 | - * @return bool |
|
428 | - */ |
|
429 | - public function parseVars() |
|
430 | - { |
|
431 | - static $parsed; |
|
432 | - // irmtfan - force to parse vars (run against static vars) |
|
433 | - if (null !== $parsed && !$this->force) { |
|
434 | - return true; |
|
435 | - } |
|
436 | - |
|
437 | - if (!isset($this->vars['forum'])) { |
|
438 | - $this->vars['forum'] = null; |
|
439 | - } |
|
440 | - //irmtfan parse status for rendering topic correctly - if empty($_GET(status)) it will show all topics include deleted and pendings. 'all' instead of all |
|
441 | - if (!isset($this->vars['status'])) { |
|
442 | - $this->vars['status'] = 'all'; |
|
443 | - } |
|
444 | - // irmtfan if sort is not set or is empty get a default sort- if empty($_GET(sort)) | if sort=null eg: /list.topic.php?sort= |
|
445 | - if (empty($this->vars['sort'])) { |
|
446 | - $this->vars['sort'] = 'lastpost'; |
|
447 | - } // use lastpost instead of sticky |
|
448 | - |
|
449 | - foreach ($this->vars as $var => $val) { |
|
450 | - $this->parseVar($var, $val); |
|
451 | - if (empty($val)) { |
|
452 | - unset($this->vars[$var]); |
|
453 | - } |
|
454 | - } |
|
455 | - $parsed = true; |
|
456 | - |
|
457 | - return true; |
|
458 | - } |
|
459 | - |
|
460 | - /** |
|
461 | - * @param null $header |
|
462 | - * @param null $var |
|
463 | - * @return array|null |
|
464 | - */ |
|
465 | - public function getSort($header = null, $var = null) |
|
466 | - { |
|
467 | - $headers = [ |
|
468 | - 'topic' => [ |
|
469 | - 'title' => _MD_NEWBB_TOPICS, |
|
470 | - 'sort' => 't.topic_title' |
|
471 | - ], |
|
472 | - 'forum' => [ |
|
473 | - 'title' => _MD_NEWBB_FORUM, |
|
474 | - 'sort' => 't.forum_id' |
|
475 | - ], |
|
476 | - 'poster' => [ |
|
477 | - 'title' => _MD_NEWBB_TOPICPOSTER, /*irmtfan _MD_NEWBB_POSTER to _MD_NEWBB_TOPICPOSTER*/ |
|
478 | - 'sort' => 't.topic_poster' |
|
479 | - ], |
|
480 | - 'replies' => [ |
|
481 | - 'title' => _MD_NEWBB_REPLIES, |
|
482 | - 'sort' => 't.topic_replies' |
|
483 | - ], |
|
484 | - 'views' => [ |
|
485 | - 'title' => _MD_NEWBB_VIEWS, |
|
486 | - 'sort' => 't.topic_views' |
|
487 | - ], |
|
488 | - 'lastpost' => [ // irmtfan show topic_page_jump_icon smarty |
|
489 | - 'title' => _MD_NEWBB_LASTPOST, |
|
490 | - /*irmtfan _MD_NEWBB_DATE to _MD_NEWBB_LASTPOSTTIME again change to _MD_LASTPOST*/ |
|
491 | - 'sort' => 't.topic_last_post_id' |
|
492 | - ], |
|
493 | - // START irmtfan add more sorts |
|
494 | - 'lastposttime' => [ // irmtfan same as lastpost |
|
495 | - 'title' => _MD_NEWBB_LASTPOSTTIME, |
|
496 | - 'sort' => 't.topic_last_post_id' |
|
497 | - ], |
|
498 | - 'lastposter' => [ // irmtfan |
|
499 | - 'title' => _MD_NEWBB_POSTER, |
|
500 | - 'sort' => 'p.uid',// poster uid |
|
501 | - ], |
|
502 | - 'lastpostmsgicon' => [ // irmtfan |
|
503 | - 'title' => _MD_NEWBB_MESSAGEICON, |
|
504 | - 'sort' => 'p.icon',// post message icon |
|
505 | - ], |
|
506 | - 'ratings' => [ |
|
507 | - 'title' => _MD_NEWBB_RATINGS, |
|
508 | - 'sort' => 't.rating', // irmtfan t.topic_rating to t.rating |
|
509 | - ], |
|
510 | - 'votes' => [ |
|
511 | - 'title' => _MD_NEWBB_VOTES, |
|
512 | - 'sort' => 't.votes' |
|
513 | - ], |
|
514 | - 'publish' => [ |
|
515 | - 'title' => _MD_NEWBB_TOPICTIME, |
|
516 | - 'sort' => 't.topic_id' |
|
517 | - ], |
|
518 | - 'digest' => [ |
|
519 | - 'title' => _MD_NEWBB_DIGEST, |
|
520 | - 'sort' => 't.digest_time' |
|
521 | - ], |
|
522 | - 'sticky' => [ |
|
523 | - 'title' => _MD_NEWBB_STICKY, |
|
524 | - 'sort' => 't.topic_sticky' |
|
525 | - ], |
|
526 | - 'lock' => [ |
|
527 | - 'title' => _MD_NEWBB_LOCK, |
|
528 | - 'sort' => 't.topic_status' |
|
529 | - ], |
|
530 | - 'poll' => [ |
|
531 | - 'title' => _MD_NEWBB_POLL_POLL, |
|
532 | - 'sort' => 't.poll_id' |
|
533 | - ] |
|
534 | - ]; |
|
535 | - $types = $this->getTypes(); |
|
536 | - if (!empty($types)) { |
|
537 | - $headers['type'] = [ |
|
538 | - 'title' => _MD_NEWBB_TYPE, |
|
539 | - 'sort' => 't.type_id' |
|
540 | - ]; |
|
541 | - } |
|
542 | - if (2 == $this->userlevel) { |
|
543 | - $headers['approve'] = [ |
|
544 | - 'title' => _MD_NEWBB_APPROVE, |
|
545 | - 'sort' => 't.approved' |
|
546 | - ]; |
|
547 | - } |
|
548 | - // END irmtfan add more sorts |
|
549 | - if (empty($header) && empty($var)) { |
|
550 | - return $headers; |
|
551 | - } |
|
552 | - if (!empty($var) && !empty($header)) { |
|
553 | - return @$headers[$header][$var]; |
|
554 | - } |
|
555 | - if (empty($var)) { |
|
556 | - return @$headers[$header]; |
|
557 | - } |
|
558 | - $ret = null; |
|
559 | - foreach (array_keys($headers) as $key) { |
|
560 | - $ret[$key] = @$headers[$key][$var]; |
|
561 | - } |
|
562 | - |
|
563 | - return $ret; |
|
564 | - } |
|
565 | - |
|
566 | - // START irmtfan add Display topic headers function |
|
567 | - |
|
568 | - /** |
|
569 | - * @param null $header |
|
570 | - * @return array |
|
571 | - */ |
|
572 | - public function getHeader($header = null) |
|
573 | - { |
|
574 | - $headersSort = $this->getSort('', 'title'); |
|
575 | - // additional headers - important: those cannot be in sort anyway |
|
576 | - $headers = array_merge($headersSort, [ |
|
577 | - 'attachment' => _MD_NEWBB_TOPICSHASATT, // show attachment smarty |
|
578 | - 'read' => _MD_NEWBB_MARK_UNREAD . '|' . _MD_NEWBB_MARK_READ, // read/unread show topic_folder smarty |
|
579 | - 'pagenav' => _MD_NEWBB_PAGENAV_DISPLAY, // show topic_page_jump smarty - sort by topic_replies? |
|
580 | - ]); |
|
581 | - |
|
582 | - return $this->getFromKeys($headers, $header); |
|
583 | - } |
|
584 | - |
|
585 | - // END irmtfan add Display topic headers function |
|
586 | - |
|
587 | - /** |
|
588 | - * @param null $type |
|
589 | - * @param null $status |
|
590 | - * @return array |
|
591 | - */ |
|
592 | - public function getStatus($type = null, $status = null) |
|
593 | - { |
|
594 | - $links = [ |
|
595 | - //"" => "", /* irmtfan remove empty array */ |
|
596 | - 'all' => _ALL, |
|
597 | - 'digest' => _MD_NEWBB_DIGEST, |
|
598 | - 'undigest' => _MD_NEWBB_UNDIGEST, // irmtfan add |
|
599 | - 'sticky' => _MD_NEWBB_STICKY, // irmtfan add |
|
600 | - 'unsticky' => _MD_NEWBB_UNSTICKY, // irmtfan add |
|
601 | - 'lock' => _MD_NEWBB_LOCK, // irmtfan add |
|
602 | - 'unlock' => _MD_NEWBB_UNLOCK, // irmtfan add |
|
603 | - 'poll' => _MD_NEWBB_TOPICHASPOLL, // irmtfan add |
|
604 | - 'unpoll' => _MD_NEWBB_TOPICHASNOTPOLL, // irmtfan add |
|
605 | - 'voted' => _MD_NEWBB_VOTED, // irmtfan add |
|
606 | - 'unvoted' => _MD_NEWBB_UNVOTED, // irmtfan add |
|
607 | - 'viewed' => _MD_NEWBB_VIEWED, // irmtfan add |
|
608 | - 'unviewed' => _MD_NEWBB_UNVIEWED, // irmtfan add |
|
609 | - 'replied' => _MD_NEWBB_REPLIED, // irmtfan add |
|
610 | - 'unreplied' => _MD_NEWBB_UNREPLIED, |
|
611 | - 'read' => _MD_NEWBB_READ, // irmtfan add |
|
612 | - 'unread' => _MD_NEWBB_UNREAD |
|
613 | - ]; |
|
614 | - $links_admin = [ |
|
615 | - 'active' => _MD_NEWBB_TYPE_ADMIN, |
|
616 | - 'pending' => _MD_NEWBB_TYPE_PENDING, |
|
617 | - 'deleted' => _MD_NEWBB_TYPE_DELETED |
|
618 | - ]; |
|
619 | - |
|
620 | - // all status, for admin |
|
621 | - if ($type > 1) { |
|
622 | - $links = array_merge($links, $links_admin);// irmtfan to accept multiple status |
|
623 | - } |
|
624 | - |
|
625 | - return $this->getFromKeys($links, $status); // irmtfan to accept multiple status |
|
626 | - } |
|
627 | - |
|
628 | - /** |
|
629 | - * @param \Smarty $xoopsTpl |
|
630 | - * @throws \RuntimeException |
|
631 | - */ |
|
632 | - public function buildSelection(\Smarty $xoopsTpl) |
|
633 | - { |
|
634 | - $selection = ['action' => $this->page]; |
|
635 | - $selection['vars'] = $this->vars; |
|
636 | - require_once dirname(__DIR__) . '/include/functions.forum.php'; |
|
637 | - $forum_selected = empty($this->vars['forum']) ? null : explode('|', @$this->vars['forum']); |
|
638 | - $selection['forum'] = '<select name="forum[]" multiple="multiple">'; |
|
639 | - $selection['forum'] .= '<option value="0">' . _MD_NEWBB_ALL . '</option>'; |
|
640 | - $selection['forum'] .= newbbForumSelectBox($forum_selected); |
|
641 | - $selection['forum'] .= '</select>'; |
|
642 | - |
|
643 | - $sort_selected = $this->vars['sort']; |
|
644 | - $sorts = $this->getSort('', 'title'); |
|
645 | - $selection['sort'] = "<select name='sort'>"; |
|
646 | - if (!is_array($sorts)) { |
|
647 | - throw new \RuntimeException('$sorts must be an array.'); |
|
648 | - } |
|
649 | - foreach ($sorts as $sort => $title) { |
|
650 | - $selection['sort'] .= "<option value='" . $sort . "' " . (($sort == $sort_selected) ? " selected='selected'" : '') . '>' . $title . '</option>'; |
|
651 | - } |
|
652 | - $selection['sort'] .= '</select>'; |
|
653 | - |
|
654 | - $selection['order'] = "<select name='order'>"; |
|
655 | - $selection['order'] .= "<option value='0' " . (empty($this->vars['order']) ? " selected='selected'" : '') . '>' . _DESCENDING . '</option>'; |
|
656 | - $selection['order'] .= "<option value='1' " . (!empty($this->vars['order']) ? " selected='selected'" : '') . '>' . _ASCENDING . '</option>'; |
|
657 | - $selection['order'] .= '</select>'; |
|
658 | - |
|
659 | - $since = isset($this->vars['since']) ? $this->vars['since'] : $this->config['since_default']; |
|
660 | - $selection['since'] = newbbSinceSelectBox($since); |
|
661 | - |
|
662 | - $xoopsTpl->assign_by_ref('selection', $selection); |
|
663 | - } |
|
664 | - |
|
665 | - /** |
|
666 | - * @param \Smarty $xoopsTpl |
|
667 | - */ |
|
668 | - public function buildSearch(\Smarty $xoopsTpl) |
|
669 | - { |
|
670 | - $search = []; |
|
671 | - $search['forum'] = @$this->vars['forum']; |
|
672 | - $search['since'] = @$this->vars['since']; |
|
673 | - $search['searchin'] = 'both'; |
|
674 | - |
|
675 | - $xoopsTpl->assign_by_ref('search', $search); |
|
676 | - } |
|
677 | - |
|
678 | - /** |
|
679 | - * @param \Smarty $xoopsTpl |
|
680 | - * @throws \RuntimeException |
|
681 | - */ |
|
682 | - public function buildHeaders(\Smarty $xoopsTpl) |
|
683 | - { |
|
684 | - $args = []; |
|
685 | - foreach ($this->vars as $var => $val) { |
|
686 | - if ('sort' === $var || 'order' === $var) { |
|
687 | - continue; |
|
688 | - } |
|
689 | - $args[] = "{$var}={$val}"; |
|
690 | - } |
|
691 | - |
|
692 | - $headers = $this->getSort('', 'title'); |
|
693 | - if (!is_array($headers)) { |
|
694 | - throw new \RuntimeException('$headers must be an array.'); |
|
695 | - } |
|
696 | - foreach ($headers as $header => $title) { |
|
697 | - $_args = ["sort={$header}"]; |
|
698 | - if (@$this->vars['sort'] == $header) { |
|
699 | - $_args[] = 'order=' . ((@$this->vars['order'] + 1) % 2); |
|
700 | - } |
|
701 | - $headers_data[$header]['title'] = $title; |
|
702 | - $headers_data[$header]['link'] = $this->page . '?' . implode('&', array_merge($args, $_args)); |
|
703 | - } |
|
704 | - $xoopsTpl->assign_by_ref('headers', $headers_data); |
|
705 | - } |
|
706 | - |
|
707 | - /** |
|
708 | - * @param \Smarty $xoopsTpl |
|
709 | - */ |
|
710 | - public function buildFilters(\Smarty $xoopsTpl) |
|
711 | - { |
|
712 | - $args = []; |
|
713 | - foreach ($this->vars as $var => $val) { |
|
714 | - if ('status' === $var) { |
|
715 | - continue; |
|
716 | - } |
|
717 | - $args[] = "{$var}={$val}"; |
|
718 | - } |
|
719 | - |
|
720 | - $links = $this->getStatus($this->userlevel); |
|
721 | - |
|
722 | - $status = []; |
|
723 | - foreach ($links as $link => $title) { |
|
724 | - $_args = ["status={$link}"]; |
|
725 | - $status[$link]['title'] = $title; |
|
726 | - $status[$link]['link'] = $this->page . '?' . implode('&', array_merge($args, $_args)); |
|
727 | - } |
|
728 | - $xoopsTpl->assign_by_ref('filters', $status); |
|
729 | - } |
|
730 | - |
|
731 | - /** |
|
732 | - * @param null $type_id |
|
733 | - * @return mixed |
|
734 | - */ |
|
735 | - public function getTypes($type_id = null) |
|
736 | - { |
|
737 | - static $types; |
|
738 | - if (!isset($types)) { |
|
739 | - /** @var Newbb\TypeHandler $typeHandler */ |
|
740 | - $typeHandler = Newbb\Helper::getInstance()->getHandler('Type'); |
|
741 | - |
|
742 | - $types = $typeHandler->getByForum(explode('|', @$this->vars['forum'])); |
|
743 | - } |
|
744 | - |
|
745 | - if (empty($type_id)) { |
|
746 | - return $types; |
|
747 | - } |
|
748 | - |
|
749 | - return @$types[$type_id]; |
|
750 | - } |
|
751 | - |
|
752 | - /** |
|
753 | - * @param \Smarty $xoopsTpl |
|
754 | - * @return bool |
|
755 | - */ |
|
756 | - public function buildTypes(\Smarty $xoopsTpl) |
|
757 | - { |
|
758 | - $status = ''; |
|
759 | - if (!$types = $this->getTypes()) { |
|
760 | - return true; |
|
761 | - } |
|
762 | - |
|
763 | - $args = []; |
|
764 | - foreach ($this->vars as $var => $val) { |
|
765 | - if ('type' === $var) { |
|
766 | - continue; |
|
767 | - } |
|
768 | - $args[] = "{$var}={$val}"; |
|
769 | - } |
|
770 | - |
|
771 | - foreach ($types as $id => $type) { |
|
772 | - $_args = ["type={$id}"]; |
|
773 | - $status[$id]['title'] = $type['type_name']; |
|
774 | - $status[$id]['link'] = $this->page . '?' . implode('&', array_merge($args, $_args)); |
|
775 | - } |
|
776 | - $xoopsTpl->assign_by_ref('types', $status); |
|
777 | - } |
|
778 | - |
|
779 | - /** |
|
780 | - * @param \Smarty $xoopsTpl |
|
781 | - * @return bool |
|
782 | - */ |
|
783 | - public function buildCurrent(\Smarty $xoopsTpl) |
|
784 | - { |
|
785 | - if (empty($this->vars['status']) && !$this->is_multiple) { |
|
786 | - return true; |
|
787 | - } |
|
788 | - |
|
789 | - $args = []; |
|
790 | - foreach ($this->vars as $var => $val) { |
|
791 | - $args[] = "{$var}={$val}"; |
|
792 | - } |
|
793 | - |
|
794 | - $status = []; |
|
795 | - $status['title'] = implode(',', $this->getStatus($this->userlevel, $this->vars['status'])); // irmtfan to accept multiple status |
|
796 | - //$status['link'] = $this->page.(empty($this->vars['status']) ? '' : '?status='.$this->vars['status']); |
|
797 | - $status['link'] = $this->page . (empty($args) ? '' : '?' . implode('&', $args)); |
|
798 | - |
|
799 | - $xoopsTpl->assign_by_ref('current', $status); |
|
800 | - } |
|
801 | - |
|
802 | - /** |
|
803 | - * @param \Smarty $xoopsTpl |
|
804 | - */ |
|
805 | - public function buildPagenav(\Smarty $xoopsTpl) |
|
806 | - { |
|
807 | - $count_topic = $this->getCount(); |
|
808 | - if ($count_topic > $this->config['topics_per_page']) { |
|
809 | - $args = []; |
|
810 | - foreach ($this->vars as $var => $val) { |
|
811 | - if ('start' === $var) { |
|
812 | - continue; |
|
813 | - } |
|
814 | - $args[] = "{$var}={$val}"; |
|
815 | - } |
|
816 | - require_once $GLOBALS['xoops']->path('class/pagenav.php'); |
|
817 | - $nav = new \XoopsPageNav($count_topic, $this->config['topics_per_page'], @$this->vars['start'], 'start', implode('&', $args)); |
|
818 | - if (isset($GLOBALS['xoopsModuleConfig']['do_rewrite'])) { |
|
819 | - $nav->url = formatURL(Request::getString('SERVER_NAME', '', 'SERVER')) . ' /' . $nav->url; |
|
820 | - } |
|
821 | - if ('select' === $this->config['pagenav_display']) { |
|
822 | - $navi = $nav->renderSelect(); |
|
823 | - } elseif ('image' === $this->config['pagenav_display']) { |
|
824 | - $navi = $nav->renderImageNav(4); |
|
825 | - } else { |
|
826 | - $navi = $nav->renderNav(4); |
|
827 | - } |
|
828 | - $xoopsTpl->assign('pagenav', $navi); |
|
829 | - } else { |
|
830 | - $xoopsTpl->assign('pagenav', ''); |
|
831 | - } |
|
832 | - } |
|
833 | - |
|
834 | - /** |
|
835 | - * @return int |
|
836 | - */ |
|
837 | - public function getCount() |
|
838 | - { |
|
839 | - if ($this->noperm) { |
|
840 | - return 0; |
|
841 | - } |
|
842 | - |
|
843 | - $selects = []; |
|
844 | - $froms = []; |
|
845 | - $joins = []; |
|
846 | - $wheres = []; |
|
847 | - |
|
848 | - // topic fields |
|
849 | - $selects[] = 'COUNT(*)'; |
|
850 | - |
|
851 | - $froms[] = $this->handler->db->prefix('newbb_topics') . ' AS t '; |
|
852 | - $joins[] = 'LEFT JOIN ' . $this->handler->db->prefix('newbb_posts') . ' AS p ON p.post_id = t.topic_last_post_id'; |
|
853 | - $wheres[] = '1 = 1'; |
|
854 | - |
|
855 | - $sql = ' SELECT ' . implode(', ', $selects) . ' FROM ' . implode(', ', $froms) . ' ' . implode(' ', $joins) . (!empty($this->query['join']) ? ' ' . implode(' ', $this->query['join']) : '') . // irmtfan bug fix: Undefined index: join when post_excerpt = 0 |
|
856 | - ' WHERE ' . implode(' AND ', $wheres) . ' AND ' . @implode(' AND ', @$this->query['where']); |
|
857 | - |
|
858 | - if (!$result = $this->handler->db->query($sql)) { |
|
859 | - return 0; |
|
860 | - } |
|
861 | - list($count) = $this->handler->db->fetchRow($result); |
|
862 | - |
|
863 | - return $count; |
|
864 | - } |
|
865 | - |
|
866 | - /** |
|
867 | - * @param \Smarty $xoopsTpl |
|
868 | - * @return array|void |
|
869 | - */ |
|
870 | - public function renderTopics(\Smarty $xoopsTpl = null) |
|
871 | - { |
|
872 | - $myts = \MyTextSanitizer::getInstance(); // irmtfan Instanciate |
|
873 | - |
|
874 | - $ret = []; |
|
875 | - //$this->parseVars(); |
|
876 | - |
|
877 | - if ($this->noperm) { |
|
878 | - if (is_object($xoopsTpl)) { |
|
879 | - $xoopsTpl->assign_by_ref('topics', $ret); |
|
880 | - |
|
881 | - return; |
|
882 | - } |
|
883 | - |
|
884 | - return $ret; |
|
885 | - } |
|
886 | - |
|
887 | - $selects = []; |
|
888 | - $froms = []; |
|
889 | - $joins = []; |
|
890 | - $wheres = []; |
|
891 | - |
|
892 | - // topic fields |
|
893 | - $selects[] = 't.*'; |
|
894 | - // post fields |
|
895 | - $selects[] = 'p.post_time as last_post_time, p.poster_name as last_poster_name, p.icon, p.post_id, p.uid'; |
|
896 | - |
|
897 | - $froms[] = $this->handler->db->prefix('newbb_topics') . ' AS t '; |
|
898 | - $joins[] = 'LEFT JOIN ' . $this->handler->db->prefix('newbb_posts') . ' AS p ON p.post_id = t.topic_last_post_id'; |
|
899 | - $wheres[] = '1 = 1'; |
|
900 | - |
|
901 | - if (!empty($this->config['post_excerpt'])) { |
|
902 | - $selects[] = 'p.post_karma, p.require_reply, pt.post_text'; |
|
903 | - $this->query['join'][] = 'LEFT JOIN ' . $this->handler->db->prefix('newbb_posts_text') . ' AS pt ON pt.post_id = t.topic_last_post_id'; |
|
904 | - } |
|
905 | - //if (empty($this->query["sort"])) $this->query["sort"][] = 't.topic_last_post_id DESC'; // irmtfan commented no need |
|
906 | - |
|
907 | - $sql = ' SELECT ' . implode(', ', $selects) . ' FROM ' . implode(', ', $froms) . ' ' . implode(' ', $joins) . (!empty($this->query['join']) ? ' ' . implode(' ', $this->query['join']) : '') . // irmtfan bug fix: Undefined index join when post_excerpt = 0 |
|
908 | - ' WHERE ' . implode(' AND ', $wheres) . ' AND ' . @implode(' AND ', @$this->query['where']) . ' ORDER BY ' . implode(', ', $this->query['sort']); |
|
909 | - |
|
910 | - if (!$result = $this->handler->db->query($sql, $this->config['topics_per_page'], @$this->vars['start'])) { |
|
911 | - if (is_object($xoopsTpl)) { |
|
912 | - $xoopsTpl->assign_by_ref('topics', $ret); |
|
913 | - |
|
914 | - return; |
|
915 | - } |
|
916 | - |
|
917 | - return $ret; |
|
918 | - } |
|
919 | - |
|
920 | - require_once dirname(__DIR__) . '/include/functions.render.php'; |
|
921 | - require_once dirname(__DIR__) . '/include/functions.session.php'; |
|
922 | - require_once dirname(__DIR__) . '/include/functions.time.php'; |
|
923 | - require_once dirname(__DIR__) . '/include/functions.read.php'; |
|
924 | - require_once dirname(__DIR__) . '/include/functions.topic.php'; |
|
925 | - |
|
926 | - $sticky = 0; |
|
927 | - $topics = []; |
|
928 | - $posters = []; |
|
929 | - $reads = []; |
|
930 | - $types = []; |
|
931 | - $forums = []; |
|
932 | - $anonymous = $myts->htmlSpecialChars($GLOBALS['xoopsConfig']['anonymous']); |
|
933 | - |
|
934 | - while (false !== ($myrow = $this->handler->db->fetchArray($result))) { |
|
935 | - if ($myrow['topic_sticky']) { |
|
936 | - ++$sticky; |
|
937 | - } |
|
938 | - |
|
939 | - // ------------------------------------------------------ |
|
940 | - // START irmtfan remove topic_icon hardcode smarty |
|
941 | - // topic_icon: just regular topic_icon |
|
942 | - if (!empty($myrow['icon'])) { |
|
943 | - $topic_icon = '<img align="middle" src="' . XOOPS_URL . '/images/subject/' . htmlspecialchars($myrow['icon'], ENT_QUOTES | ENT_HTML5) . '" alt="" />'; |
|
944 | - } else { |
|
945 | - $topic_icon = '<img align="middle" src="' . XOOPS_URL . '/images/icons/no_posticon.gif" alt="" />'; |
|
946 | - } |
|
947 | - // END irmtfan remove topic_icon hardcode smarty |
|
948 | - |
|
949 | - // ------------------------------------------------------ |
|
950 | - // rating_img |
|
951 | - $rating = number_format($myrow['rating'] / 2, 0); |
|
952 | - // irmtfan - add alt key for rating |
|
953 | - if ($rating < 1) { |
|
954 | - $rating_img = newbbDisplayImage('blank'); |
|
955 | - } else { |
|
956 | - $rating_img = newbbDisplayImage('rate' . $rating, constant('_MD_NEWBB_RATE' . $rating)); |
|
957 | - } |
|
958 | - |
|
959 | - // ------------------------------------------------------ |
|
960 | - // topic_page_jump |
|
961 | - $topic_page_jump = ''; |
|
962 | - $topic_page_jump_icon = ''; |
|
963 | - $totalpages = ceil(($myrow['topic_replies'] + 1) / $this->config['posts_per_page']); |
|
964 | - if ($totalpages > 1) { |
|
965 | - $topic_page_jump .= ' '; |
|
966 | - $append = false; |
|
967 | - for ($i = 1; $i <= $totalpages; ++$i) { |
|
968 | - if ($i > 3 && $i < $totalpages) { |
|
969 | - if (!$append) { |
|
970 | - $topic_page_jump .= '...'; |
|
971 | - $append = true; |
|
972 | - } |
|
973 | - } else { |
|
974 | - $topic_page_jump .= '[<a href="' . XOOPS_URL . '/modules/newbb/viewtopic.php?topic_id=' . $myrow['topic_id'] . '&start=' . (($i - 1) * $this->config['posts_per_page']) . '">' . $i . '</a>]'; |
|
975 | - // irmtfan remove here and move |
|
976 | - //$topic_page_jump_icon = "<a href='" . XOOPS_URL . "/modules/newbb/viewtopic.php?topic_id=" . $myrow['topic_id'] . "&start=" . (($i - 1) * $this->config['posts_per_page']) . "" . "'>" . newbbDisplayImage('document',_MD_NEWBB_GOTOLASTPOST) . '</a>'; |
|
977 | - } |
|
978 | - } |
|
979 | - } |
|
980 | - // irmtfan - move here for both topics with and without pages - change topic_id to post_id |
|
981 | - $topic_page_jump_icon = "<a href='" . XOOPS_URL . '/modules/newbb/viewtopic.php?post_id=' . $myrow['topic_last_post_id'] . '' . "'>" . newbbDisplayImage('lastposticon', _MD_NEWBB_GOTOLASTPOST) . '</a>'; |
|
982 | - |
|
983 | - // ------------------------------------------------------ |
|
984 | - // => topic array |
|
985 | - |
|
986 | - $topic_title = $myts->htmlSpecialChars($myrow['topic_title']); |
|
987 | - // irmtfan use topic_title_excerpt for block topic title length |
|
988 | - $topic_title_excerpt = $topic_title; |
|
989 | - if (!empty($this->config['topic_title_excerpt'])) { |
|
990 | - $topic_title_excerpt = xoops_substr($topic_title, 0, $this->config['topic_title_excerpt']); |
|
991 | - } |
|
992 | - // irmtfan hardcode class commented |
|
993 | - //if ($myrow['topic_digest']) { |
|
994 | - // $topic_title = "<span class='digest'>" . $topic_title . "</span>"; |
|
995 | - //} |
|
996 | - |
|
997 | - if (empty($this->config['post_excerpt'])) { |
|
998 | - $topic_excerpt = ''; |
|
999 | - } elseif (($myrow['post_karma'] > 0 || $myrow['require_reply'] > 0) && !newbbIsAdmin($myrow['forum_id'])) { |
|
1000 | - $topic_excerpt = ''; |
|
1001 | - } else { |
|
1002 | - $topic_excerpt = xoops_substr(newbbHtml2text($myts->displayTarea($myrow['post_text'])), 0, $this->config['post_excerpt']); |
|
1003 | - $topic_excerpt = str_replace('[', '[', $myts->htmlSpecialChars($topic_excerpt)); |
|
1004 | - } |
|
1005 | - |
|
1006 | - $topics[$myrow['topic_id']] = [ |
|
1007 | - 'topic_id' => $myrow['topic_id'], |
|
1008 | - 'topic_icon' => $topic_icon, |
|
1009 | - 'type_id' => $myrow['type_id'], |
|
1010 | - 'topic_title_excerpt' => $topic_title_excerpt, |
|
1011 | - //irmtfan use topic_title_excerpt |
|
1012 | - //'topic_link' => XOOPS_URL . '/modules/newbb/viewtopic.php?topic_id=' . $myrow['topic_id'], // . '&forum=' . $myrow['forum_id'], // irmtfan comment |
|
1013 | - 'topic_link' => 'viewtopic.php?topic_id=' . $myrow['topic_id'], |
|
1014 | - // irmtfan remove hardcode link |
|
1015 | - 'rating_img' => $rating_img, |
|
1016 | - 'votes' => $myrow['votes'], |
|
1017 | - //irmtfan added |
|
1018 | - 'topic_page_jump' => $topic_page_jump, |
|
1019 | - 'topic_page_jump_icon' => $topic_page_jump_icon, |
|
1020 | - 'topic_replies' => $myrow['topic_replies'], |
|
1021 | - 'topic_poster_uid' => $myrow['topic_poster'], |
|
1022 | - 'topic_poster_name' => !empty($myrow['poster_name']) ? $myts->htmlSpecialChars($myrow['poster_name']) : $anonymous, |
|
1023 | - 'topic_views' => $myrow['topic_views'], |
|
1024 | - 'topic_time' => newbbFormatTimestamp($myrow['topic_time']), |
|
1025 | - 'topic_last_post_id' => $myrow['topic_last_post_id'], |
|
1026 | - //irmtfan added |
|
1027 | - 'topic_last_posttime' => newbbFormatTimestamp($myrow['last_post_time']), |
|
1028 | - 'topic_last_poster_uid' => $myrow['uid'], |
|
1029 | - 'topic_last_poster_name' => !empty($myrow['last_poster_name']) ? $myts->htmlSpecialChars($myrow['last_poster_name']) : $anonymous, |
|
1030 | - 'topic_forum' => $myrow['forum_id'], |
|
1031 | - 'topic_excerpt' => $topic_excerpt, |
|
1032 | - 'sticky' => $myrow['topic_sticky'] ? newbbDisplayImage('topic_sticky', _MD_NEWBB_TOPICSTICKY) : '', |
|
1033 | - // irmtfan bug fixed |
|
1034 | - 'lock' => $myrow['topic_status'] ? newbbDisplayImage('topic_locked', _MD_NEWBB_TOPICLOCK) : '', |
|
1035 | - //irmtfan added |
|
1036 | - 'digest' => $myrow['topic_digest'] ? newbbDisplayImage('topic_digest', _MD_NEWBB_TOPICDIGEST) : '', |
|
1037 | - //irmtfan added |
|
1038 | - 'poll' => $myrow['topic_haspoll'] ? newbbDisplayImage('poll', _MD_NEWBB_TOPICHASPOLL) : '', |
|
1039 | - //irmtfan added |
|
1040 | - 'approve' => $myrow['approved'], |
|
1041 | - //irmtfan added |
|
1042 | - ]; |
|
1043 | - |
|
1044 | - /* users */ |
|
1045 | - $posters[$myrow['topic_poster']] = 1; |
|
1046 | - $posters[$myrow['uid']] = 1; |
|
1047 | - // reads |
|
1048 | - if (!empty($this->config['read_mode'])) { |
|
1049 | - $reads[$myrow['topic_id']] = (1 == $this->config['read_mode']) ? $myrow['last_post_time'] : $myrow['topic_last_post_id']; |
|
1050 | - } |
|
1051 | - // types |
|
1052 | - if (!empty($myrow['type_id'])) { |
|
1053 | - //$types[$myrow['type_id']] = 1; |
|
1054 | - } |
|
1055 | - // forums |
|
1056 | - $forums[$myrow['forum_id']] = 1; |
|
1057 | - } |
|
1058 | - $posters_name = newbbGetUnameFromIds(array_keys($posters), $this->config['show_realname'], true); |
|
1059 | - $topic_isRead = newbbIsRead('topic', $reads); |
|
1060 | - /* |
|
28 | + public $vars = []; |
|
29 | + |
|
30 | + /** |
|
31 | + * reference to moduleConfig |
|
32 | + */ |
|
33 | + public $config; |
|
34 | + |
|
35 | + /** |
|
36 | + * Current user has no access to current page |
|
37 | + */ |
|
38 | + private $noperm = false; |
|
39 | + |
|
40 | + /** |
|
41 | + * For multiple forums |
|
42 | + */ |
|
43 | + public $is_multiple = false; |
|
44 | + |
|
45 | + /** |
|
46 | + * force to parse vars (run against static vars) irmtfan |
|
47 | + */ |
|
48 | + public $force = false; |
|
49 | + |
|
50 | + /** |
|
51 | + * Vistitor's level: 0 - anonymous; 1 - user; 2 - moderator or admin |
|
52 | + */ |
|
53 | + public $userlevel = 0; |
|
54 | + |
|
55 | + public $query = []; |
|
56 | + |
|
57 | + /** |
|
58 | + * reference to an object handler |
|
59 | + */ |
|
60 | + private $handler; |
|
61 | + |
|
62 | + /** |
|
63 | + * Requested page |
|
64 | + */ |
|
65 | + private $page = 'list.topic.php'; |
|
66 | + |
|
67 | + /** |
|
68 | + * query variables |
|
69 | + */ |
|
70 | + private $args = ['forum', 'uid', 'lastposter', 'type', 'status', 'mode', 'sort', 'order', 'start', 'since']; |
|
71 | + |
|
72 | + /** |
|
73 | + * Constructor |
|
74 | + */ |
|
75 | + // public function TopicRenderer() |
|
76 | + public function __construct() |
|
77 | + { |
|
78 | + $this->handler = Newbb\Helper::getInstance()->getHandler('Topic'); |
|
79 | + } |
|
80 | + |
|
81 | + /** |
|
82 | + * Access the only instance of this class |
|
83 | + * @return TopicRenderer |
|
84 | + */ |
|
85 | + public static function getInstance() |
|
86 | + { |
|
87 | + static $instance; |
|
88 | + if (null === $instance) { |
|
89 | + $instance = new static(); |
|
90 | + } |
|
91 | + |
|
92 | + return $instance; |
|
93 | + } |
|
94 | + |
|
95 | + public function init() |
|
96 | + { |
|
97 | + $this->noperm = false; |
|
98 | + $this->query = []; |
|
99 | + } |
|
100 | + |
|
101 | + /** |
|
102 | + * @param $var |
|
103 | + * @param $val |
|
104 | + * @return array|int|string |
|
105 | + */ |
|
106 | + public function setVar($var, $val) |
|
107 | + { |
|
108 | + switch ($var) { |
|
109 | + case 'forum': |
|
110 | + if (is_numeric($val)) { |
|
111 | + $val = (int)$val; |
|
112 | + // START irmtfan - if the forum is array |
|
113 | + } elseif (is_array($val)) { |
|
114 | + $val = implode('|', $val); |
|
115 | + //} elseif (!empty($val)) { |
|
116 | + // $val = implode("|", array_map("intval", explode(", ", $val))); |
|
117 | + } |
|
118 | + // END irmtfan - if the forum is array |
|
119 | + break; |
|
120 | + |
|
121 | + case 'type': |
|
122 | + case 'mode': |
|
123 | + case 'order': |
|
124 | + case 'start': |
|
125 | + case 'since': |
|
126 | + $val = (int)$val; |
|
127 | + break; |
|
128 | + |
|
129 | + case 'uid': // irmtfan add multi topic poster |
|
130 | + case 'lastposter': // irmtfan add multi lastposter |
|
131 | + break; |
|
132 | + |
|
133 | + case 'status': |
|
134 | + // START irmtfan to accept multiple status |
|
135 | + $val = is_array($val) ? $val : [$val]; |
|
136 | + $val = implode(',', $val); |
|
137 | + //$val = (in_array($val, array_keys($this->getStatus( $this->userlevel ))) ) ? $val : "all"; //irmtfan no need to check if status is empty or not |
|
138 | + //if ($val === "all" && !$this->is_multiple) $val = ""; irmtfan commented because it is done in sort |
|
139 | + // END irmtfan to accept multiple status |
|
140 | + break; |
|
141 | + |
|
142 | + default: |
|
143 | + break; |
|
144 | + } |
|
145 | + |
|
146 | + return $val; |
|
147 | + } |
|
148 | + |
|
149 | + /** |
|
150 | + * @param array $vars |
|
151 | + */ |
|
152 | + public function setVars(array $vars = []) |
|
153 | + { |
|
154 | + $this->init(); |
|
155 | + |
|
156 | + foreach ($vars as $var => $val) { |
|
157 | + if (!in_array($var, $this->args)) { |
|
158 | + continue; |
|
159 | + } |
|
160 | + $this->vars[$var] = $this->setVar($var, $val); |
|
161 | + } |
|
162 | + $this->parseVars(); |
|
163 | + } |
|
164 | + |
|
165 | + /** |
|
166 | + * @param null $status |
|
167 | + */ |
|
168 | + public function myParseStatus($status = null) |
|
169 | + { |
|
170 | + switch ($status) { |
|
171 | + case 'digest': |
|
172 | + $this->query['where'][] = 't.topic_digest = 1'; |
|
173 | + break; |
|
174 | + |
|
175 | + case 'undigest': |
|
176 | + $this->query['where'][] = 't.topic_digest = 0'; |
|
177 | + break; |
|
178 | + |
|
179 | + case 'sticky': |
|
180 | + $this->query['where'][] = 't.topic_sticky = 1'; |
|
181 | + break; |
|
182 | + |
|
183 | + case 'unsticky': |
|
184 | + $this->query['where'][] = 't.topic_sticky = 0'; |
|
185 | + break; |
|
186 | + |
|
187 | + case 'lock': |
|
188 | + $this->query['where'][] = 't.topic_status = 1'; |
|
189 | + break; |
|
190 | + |
|
191 | + case 'unlock': |
|
192 | + $this->query['where'][] = 't.topic_status = 0'; |
|
193 | + break; |
|
194 | + |
|
195 | + case 'poll': |
|
196 | + $this->query['where'][] = 't.topic_haspoll = 1'; |
|
197 | + break; |
|
198 | + |
|
199 | + case 'unpoll': |
|
200 | + $this->query['where'][] = 't.topic_haspoll = 0'; |
|
201 | + break; |
|
202 | + |
|
203 | + case 'voted': |
|
204 | + $this->query['where'][] = 't.votes > 0'; |
|
205 | + break; |
|
206 | + |
|
207 | + case 'unvoted': |
|
208 | + $this->query['where'][] = 't.votes < 1'; |
|
209 | + break; |
|
210 | + |
|
211 | + case 'replied': |
|
212 | + $this->query['where'][] = 't.topic_replies > 0'; |
|
213 | + break; |
|
214 | + |
|
215 | + case 'unreplied': |
|
216 | + $this->query['where'][] = 't.topic_replies < 1'; |
|
217 | + break; |
|
218 | + |
|
219 | + case 'viewed': |
|
220 | + $this->query['where'][] = 't.topic_views > 0'; |
|
221 | + break; |
|
222 | + |
|
223 | + case 'unviewed': |
|
224 | + $this->query['where'][] = 't.topic_views < 1'; |
|
225 | + break; |
|
226 | + |
|
227 | + case 'read': |
|
228 | + // Skip |
|
229 | + if (empty($this->config['read_mode'])) { |
|
230 | + // Use database |
|
231 | + } elseif (2 == $this->config['read_mode']) { |
|
232 | + // START irmtfan use read_uid to find the unread posts when the user is logged in |
|
233 | + $read_uid = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getVar('uid') : 0; |
|
234 | + if (!empty($read_uid)) { |
|
235 | + $this->query['join'][] = 'LEFT JOIN ' . $this->handler->db->prefix('newbb_reads_topic') . ' AS r ON r.read_item = t.topic_id AND r.uid = ' . $read_uid . ' '; |
|
236 | + $this->query['where'][] = 'r.post_id = t.topic_last_post_id'; |
|
237 | + } else { |
|
238 | + } |
|
239 | + // END irmtfan change criteria to get from uid p.uid = last post submit user id |
|
240 | + // User cookie |
|
241 | + } elseif (1 == $this->config['read_mode']) { |
|
242 | + // START irmtfan fix read_mode = 1 bugs - for all users (member and anon) |
|
243 | + $startdate = !empty($this->vars['since']) ? (time() - newbbGetSinceTime($this->vars['since'])) : 0; |
|
244 | + if ($lastvisit = max($GLOBALS['last_visit'], $startdate)) { |
|
245 | + $readmode1query = ''; |
|
246 | + if ($lastvisit > $startdate) { |
|
247 | + $readmode1query = 'p.post_time < ' . $lastvisit; |
|
248 | + } |
|
249 | + $topics = []; |
|
250 | + $topic_lastread = newbbGetCookie('LT', true); |
|
251 | + if (count($topic_lastread) > 0) { |
|
252 | + foreach ($topic_lastread as $id => $time) { |
|
253 | + if ($time > $lastvisit) { |
|
254 | + $topics[] = $id; |
|
255 | + } |
|
256 | + } |
|
257 | + } |
|
258 | + if (count($topics) > 0) { |
|
259 | + $topicquery = ' t.topic_id IN (' . implode(',', $topics) . ')'; |
|
260 | + // because it should be OR |
|
261 | + $readmode1query = !empty($readmode1query) ? '(' . $readmode1query . ' OR ' . $topicquery . ')' : $topicquery; |
|
262 | + } |
|
263 | + $this->query['where'][] = $readmode1query; |
|
264 | + } |
|
265 | + // END irmtfan fix read_mode = 1 bugs - for all users (member and anon) |
|
266 | + } |
|
267 | + break; |
|
268 | + |
|
269 | + case 'unread': |
|
270 | + // Skip |
|
271 | + if (empty($this->config['read_mode'])) { |
|
272 | + // Use database |
|
273 | + } elseif (2 == $this->config['read_mode']) { |
|
274 | + // START irmtfan use read_uid to find the unread posts when the user is logged in |
|
275 | + $read_uid = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getVar('uid') : 0; |
|
276 | + if (!empty($read_uid)) { |
|
277 | + $this->query['join'][] = 'LEFT JOIN ' . $this->handler->db->prefix('newbb_reads_topic') . ' AS r ON r.read_item = t.topic_id AND r.uid = ' . $read_uid . ' '; |
|
278 | + $this->query['where'][] = '(r.read_id IS NULL OR r.post_id < t.topic_last_post_id)'; |
|
279 | + } else { |
|
280 | + } |
|
281 | + // END irmtfan change criteria to get from uid p.uid = last post submit user id |
|
282 | + // User cookie |
|
283 | + } elseif (1 == $this->config['read_mode']) { |
|
284 | + // START irmtfan fix read_mode = 1 bugs - for all users (member and anon) |
|
285 | + $startdate = !empty($this->vars['since']) ? (time() - newbbGetSinceTime($this->vars['since'])) : 0; |
|
286 | + if ($lastvisit = max($GLOBALS['last_visit'], $startdate)) { |
|
287 | + if ($lastvisit > $startdate) { |
|
288 | + $this->query['where'][] = 'p.post_time > ' . $lastvisit; |
|
289 | + } |
|
290 | + $topics = []; |
|
291 | + $topic_lastread = newbbGetCookie('LT', true); |
|
292 | + if (count($topic_lastread) > 0) { |
|
293 | + foreach ($topic_lastread as $id => $time) { |
|
294 | + if ($time > $lastvisit) { |
|
295 | + $topics[] = $id; |
|
296 | + } |
|
297 | + } |
|
298 | + } |
|
299 | + if (count($topics) > 0) { |
|
300 | + $this->query['where'][] = ' t.topic_id NOT IN (' . implode(',', $topics) . ')'; |
|
301 | + } |
|
302 | + } |
|
303 | + // END irmtfan fix read_mode = 1 bugs - for all users (member and anon) |
|
304 | + } |
|
305 | + break; |
|
306 | + |
|
307 | + case 'pending': |
|
308 | + if ($this->userlevel < 2) { |
|
309 | + $this->noperm = true; |
|
310 | + } else { |
|
311 | + $this->query['where'][] = 't.approved = 0'; |
|
312 | + } |
|
313 | + break; |
|
314 | + |
|
315 | + case 'deleted': |
|
316 | + if ($this->userlevel < 2) { |
|
317 | + $this->noperm = true; |
|
318 | + } else { |
|
319 | + $this->query['where'][] = 't.approved = -1'; |
|
320 | + } |
|
321 | + break; |
|
322 | + |
|
323 | + case 'all': // For viewall.php; do not display sticky topics at first |
|
324 | + case 'active': // same as 'all' |
|
325 | + $this->query['where'][] = 't.approved = 1'; |
|
326 | + break; |
|
327 | + |
|
328 | + default: // irmtfan do nothing |
|
329 | + break; |
|
330 | + } |
|
331 | + } |
|
332 | + |
|
333 | + /** |
|
334 | + * @param $var |
|
335 | + * @param $val |
|
336 | + */ |
|
337 | + public function parseVar($var, $val) |
|
338 | + { |
|
339 | + switch ($var) { |
|
340 | + case 'forum': |
|
341 | + /** @var Newbb\ForumHandler $forumHandler */ |
|
342 | + $forumHandler = Newbb\Helper::getInstance()->getHandler('Forum'); |
|
343 | + // START irmtfan - get forum Ids by values. parse positive values to forum IDs and negative values to category IDs. value=0 => all valid forums |
|
344 | + // Get accessible forums |
|
345 | + $accessForums = $forumHandler->getIdsByValues(array_map('intval', @explode('|', $val))); |
|
346 | + // Filter specified forums if any |
|
347 | + //if (!empty($val) && $_forums = @explode('|', $val)) { |
|
348 | + //$accessForums = array_intersect($accessForums, array_map('intval', $_forums)); |
|
349 | + //} |
|
350 | + $this->vars['forum'] = $this->setVar('forum', $accessForums); |
|
351 | + // END irmtfan - get forum Ids by values. parse positive values to forum IDs and negative values to category IDs. value=0 => all valid forums |
|
352 | + |
|
353 | + if (empty($accessForums)) { |
|
354 | + $this->noperm = true; |
|
355 | + // irmtfan - it just return return the forum_id only when the forum_id is the first allowed forum - no need for this code implode is enough removed. |
|
356 | + //} elseif (count($accessForums) === 1) { |
|
357 | + //$this->query["where"][] = "t.forum_id = " . $accessForums[0]; |
|
358 | + } else { |
|
359 | + $this->query['where'][] = 't.forum_id IN ( ' . implode(', ', $accessForums) . ' )'; |
|
360 | + } |
|
361 | + break; |
|
362 | + |
|
363 | + case 'uid': // irmtfan add multi topic poster |
|
364 | + if (-1 !== $val) { |
|
365 | + $val = implode(',', array_map('intval', explode(',', $val))); |
|
366 | + $this->query['where'][] = 't.topic_poster IN ( ' . $val . ' )'; |
|
367 | + } |
|
368 | + break; |
|
369 | + case 'lastposter': // irmtfan add multi lastposter |
|
370 | + if (-1 !== $val) { |
|
371 | + $val = implode(',', array_map('intval', explode(',', $val))); |
|
372 | + $this->query['where'][] = 'p.uid IN ( ' . $val . ' )'; |
|
373 | + } |
|
374 | + break; |
|
375 | + |
|
376 | + case 'since': |
|
377 | + if (!empty($val)) { |
|
378 | + // START irmtfan if unread && read_mode = 1 and last_visit > startdate do not add where query | to accept multiple status |
|
379 | + $startdate = time() - newbbGetSinceTime($val); |
|
380 | + if (in_array('unread', explode(',', $this->vars['status'], true)) && 1 == $this->config['read_mode'] |
|
381 | + && $GLOBALS['last_visit'] > $startdate) { |
|
382 | + break; |
|
383 | + } |
|
384 | + // irmtfan digest_time | to accept multiple status |
|
385 | + if (in_array('digest', explode(',', $this->vars['status'], true))) { |
|
386 | + $this->query['where'][] = 't.digest_time > ' . $startdate; |
|
387 | + } |
|
388 | + // irmtfan - should be >= instead of = |
|
389 | + $this->query['where'][] = 'p.post_time >= ' . $startdate; |
|
390 | + // END irmtfan if unread && read_mode = 1 and last_visit > startdate do not add where query |
|
391 | + } |
|
392 | + break; |
|
393 | + |
|
394 | + case 'type': |
|
395 | + if (!empty($val)) { |
|
396 | + $this->query['where'][] = 't.type_id = ' . $val; |
|
397 | + } |
|
398 | + break; |
|
399 | + |
|
400 | + case 'status': |
|
401 | + // START irmtfan to accept multiple status |
|
402 | + $val = explode(',', $val); |
|
403 | + // irmtfan - add 'all' to always parse t.approved = 1 |
|
404 | + if (0 === count(array_intersect($val, ['all', 'active', 'pending', 'deleted']))) { |
|
405 | + $val[] = 'all'; |
|
406 | + } |
|
407 | + foreach ($val as $key => $status) { |
|
408 | + $this->myParseStatus($status); |
|
409 | + } |
|
410 | + // END irmtfan to accept multiple status |
|
411 | + break; |
|
412 | + |
|
413 | + case 'sort': |
|
414 | + if ($sort = $this->getSort($val, 'sort')) { |
|
415 | + $this->query['sort'][] = $sort . (empty($this->vars['order']) ? ' DESC' : ' ASC'); |
|
416 | + } else { // irmtfan if sort is not in the list |
|
417 | + $this->query['sort'][] = 't.topic_last_post_id' . (empty($this->vars['order']) ? ' DESC' : ' ASC'); |
|
418 | + } |
|
419 | + break; |
|
420 | + |
|
421 | + default: |
|
422 | + break; |
|
423 | + } |
|
424 | + } |
|
425 | + |
|
426 | + /** |
|
427 | + * @return bool |
|
428 | + */ |
|
429 | + public function parseVars() |
|
430 | + { |
|
431 | + static $parsed; |
|
432 | + // irmtfan - force to parse vars (run against static vars) |
|
433 | + if (null !== $parsed && !$this->force) { |
|
434 | + return true; |
|
435 | + } |
|
436 | + |
|
437 | + if (!isset($this->vars['forum'])) { |
|
438 | + $this->vars['forum'] = null; |
|
439 | + } |
|
440 | + //irmtfan parse status for rendering topic correctly - if empty($_GET(status)) it will show all topics include deleted and pendings. 'all' instead of all |
|
441 | + if (!isset($this->vars['status'])) { |
|
442 | + $this->vars['status'] = 'all'; |
|
443 | + } |
|
444 | + // irmtfan if sort is not set or is empty get a default sort- if empty($_GET(sort)) | if sort=null eg: /list.topic.php?sort= |
|
445 | + if (empty($this->vars['sort'])) { |
|
446 | + $this->vars['sort'] = 'lastpost'; |
|
447 | + } // use lastpost instead of sticky |
|
448 | + |
|
449 | + foreach ($this->vars as $var => $val) { |
|
450 | + $this->parseVar($var, $val); |
|
451 | + if (empty($val)) { |
|
452 | + unset($this->vars[$var]); |
|
453 | + } |
|
454 | + } |
|
455 | + $parsed = true; |
|
456 | + |
|
457 | + return true; |
|
458 | + } |
|
459 | + |
|
460 | + /** |
|
461 | + * @param null $header |
|
462 | + * @param null $var |
|
463 | + * @return array|null |
|
464 | + */ |
|
465 | + public function getSort($header = null, $var = null) |
|
466 | + { |
|
467 | + $headers = [ |
|
468 | + 'topic' => [ |
|
469 | + 'title' => _MD_NEWBB_TOPICS, |
|
470 | + 'sort' => 't.topic_title' |
|
471 | + ], |
|
472 | + 'forum' => [ |
|
473 | + 'title' => _MD_NEWBB_FORUM, |
|
474 | + 'sort' => 't.forum_id' |
|
475 | + ], |
|
476 | + 'poster' => [ |
|
477 | + 'title' => _MD_NEWBB_TOPICPOSTER, /*irmtfan _MD_NEWBB_POSTER to _MD_NEWBB_TOPICPOSTER*/ |
|
478 | + 'sort' => 't.topic_poster' |
|
479 | + ], |
|
480 | + 'replies' => [ |
|
481 | + 'title' => _MD_NEWBB_REPLIES, |
|
482 | + 'sort' => 't.topic_replies' |
|
483 | + ], |
|
484 | + 'views' => [ |
|
485 | + 'title' => _MD_NEWBB_VIEWS, |
|
486 | + 'sort' => 't.topic_views' |
|
487 | + ], |
|
488 | + 'lastpost' => [ // irmtfan show topic_page_jump_icon smarty |
|
489 | + 'title' => _MD_NEWBB_LASTPOST, |
|
490 | + /*irmtfan _MD_NEWBB_DATE to _MD_NEWBB_LASTPOSTTIME again change to _MD_LASTPOST*/ |
|
491 | + 'sort' => 't.topic_last_post_id' |
|
492 | + ], |
|
493 | + // START irmtfan add more sorts |
|
494 | + 'lastposttime' => [ // irmtfan same as lastpost |
|
495 | + 'title' => _MD_NEWBB_LASTPOSTTIME, |
|
496 | + 'sort' => 't.topic_last_post_id' |
|
497 | + ], |
|
498 | + 'lastposter' => [ // irmtfan |
|
499 | + 'title' => _MD_NEWBB_POSTER, |
|
500 | + 'sort' => 'p.uid',// poster uid |
|
501 | + ], |
|
502 | + 'lastpostmsgicon' => [ // irmtfan |
|
503 | + 'title' => _MD_NEWBB_MESSAGEICON, |
|
504 | + 'sort' => 'p.icon',// post message icon |
|
505 | + ], |
|
506 | + 'ratings' => [ |
|
507 | + 'title' => _MD_NEWBB_RATINGS, |
|
508 | + 'sort' => 't.rating', // irmtfan t.topic_rating to t.rating |
|
509 | + ], |
|
510 | + 'votes' => [ |
|
511 | + 'title' => _MD_NEWBB_VOTES, |
|
512 | + 'sort' => 't.votes' |
|
513 | + ], |
|
514 | + 'publish' => [ |
|
515 | + 'title' => _MD_NEWBB_TOPICTIME, |
|
516 | + 'sort' => 't.topic_id' |
|
517 | + ], |
|
518 | + 'digest' => [ |
|
519 | + 'title' => _MD_NEWBB_DIGEST, |
|
520 | + 'sort' => 't.digest_time' |
|
521 | + ], |
|
522 | + 'sticky' => [ |
|
523 | + 'title' => _MD_NEWBB_STICKY, |
|
524 | + 'sort' => 't.topic_sticky' |
|
525 | + ], |
|
526 | + 'lock' => [ |
|
527 | + 'title' => _MD_NEWBB_LOCK, |
|
528 | + 'sort' => 't.topic_status' |
|
529 | + ], |
|
530 | + 'poll' => [ |
|
531 | + 'title' => _MD_NEWBB_POLL_POLL, |
|
532 | + 'sort' => 't.poll_id' |
|
533 | + ] |
|
534 | + ]; |
|
535 | + $types = $this->getTypes(); |
|
536 | + if (!empty($types)) { |
|
537 | + $headers['type'] = [ |
|
538 | + 'title' => _MD_NEWBB_TYPE, |
|
539 | + 'sort' => 't.type_id' |
|
540 | + ]; |
|
541 | + } |
|
542 | + if (2 == $this->userlevel) { |
|
543 | + $headers['approve'] = [ |
|
544 | + 'title' => _MD_NEWBB_APPROVE, |
|
545 | + 'sort' => 't.approved' |
|
546 | + ]; |
|
547 | + } |
|
548 | + // END irmtfan add more sorts |
|
549 | + if (empty($header) && empty($var)) { |
|
550 | + return $headers; |
|
551 | + } |
|
552 | + if (!empty($var) && !empty($header)) { |
|
553 | + return @$headers[$header][$var]; |
|
554 | + } |
|
555 | + if (empty($var)) { |
|
556 | + return @$headers[$header]; |
|
557 | + } |
|
558 | + $ret = null; |
|
559 | + foreach (array_keys($headers) as $key) { |
|
560 | + $ret[$key] = @$headers[$key][$var]; |
|
561 | + } |
|
562 | + |
|
563 | + return $ret; |
|
564 | + } |
|
565 | + |
|
566 | + // START irmtfan add Display topic headers function |
|
567 | + |
|
568 | + /** |
|
569 | + * @param null $header |
|
570 | + * @return array |
|
571 | + */ |
|
572 | + public function getHeader($header = null) |
|
573 | + { |
|
574 | + $headersSort = $this->getSort('', 'title'); |
|
575 | + // additional headers - important: those cannot be in sort anyway |
|
576 | + $headers = array_merge($headersSort, [ |
|
577 | + 'attachment' => _MD_NEWBB_TOPICSHASATT, // show attachment smarty |
|
578 | + 'read' => _MD_NEWBB_MARK_UNREAD . '|' . _MD_NEWBB_MARK_READ, // read/unread show topic_folder smarty |
|
579 | + 'pagenav' => _MD_NEWBB_PAGENAV_DISPLAY, // show topic_page_jump smarty - sort by topic_replies? |
|
580 | + ]); |
|
581 | + |
|
582 | + return $this->getFromKeys($headers, $header); |
|
583 | + } |
|
584 | + |
|
585 | + // END irmtfan add Display topic headers function |
|
586 | + |
|
587 | + /** |
|
588 | + * @param null $type |
|
589 | + * @param null $status |
|
590 | + * @return array |
|
591 | + */ |
|
592 | + public function getStatus($type = null, $status = null) |
|
593 | + { |
|
594 | + $links = [ |
|
595 | + //"" => "", /* irmtfan remove empty array */ |
|
596 | + 'all' => _ALL, |
|
597 | + 'digest' => _MD_NEWBB_DIGEST, |
|
598 | + 'undigest' => _MD_NEWBB_UNDIGEST, // irmtfan add |
|
599 | + 'sticky' => _MD_NEWBB_STICKY, // irmtfan add |
|
600 | + 'unsticky' => _MD_NEWBB_UNSTICKY, // irmtfan add |
|
601 | + 'lock' => _MD_NEWBB_LOCK, // irmtfan add |
|
602 | + 'unlock' => _MD_NEWBB_UNLOCK, // irmtfan add |
|
603 | + 'poll' => _MD_NEWBB_TOPICHASPOLL, // irmtfan add |
|
604 | + 'unpoll' => _MD_NEWBB_TOPICHASNOTPOLL, // irmtfan add |
|
605 | + 'voted' => _MD_NEWBB_VOTED, // irmtfan add |
|
606 | + 'unvoted' => _MD_NEWBB_UNVOTED, // irmtfan add |
|
607 | + 'viewed' => _MD_NEWBB_VIEWED, // irmtfan add |
|
608 | + 'unviewed' => _MD_NEWBB_UNVIEWED, // irmtfan add |
|
609 | + 'replied' => _MD_NEWBB_REPLIED, // irmtfan add |
|
610 | + 'unreplied' => _MD_NEWBB_UNREPLIED, |
|
611 | + 'read' => _MD_NEWBB_READ, // irmtfan add |
|
612 | + 'unread' => _MD_NEWBB_UNREAD |
|
613 | + ]; |
|
614 | + $links_admin = [ |
|
615 | + 'active' => _MD_NEWBB_TYPE_ADMIN, |
|
616 | + 'pending' => _MD_NEWBB_TYPE_PENDING, |
|
617 | + 'deleted' => _MD_NEWBB_TYPE_DELETED |
|
618 | + ]; |
|
619 | + |
|
620 | + // all status, for admin |
|
621 | + if ($type > 1) { |
|
622 | + $links = array_merge($links, $links_admin);// irmtfan to accept multiple status |
|
623 | + } |
|
624 | + |
|
625 | + return $this->getFromKeys($links, $status); // irmtfan to accept multiple status |
|
626 | + } |
|
627 | + |
|
628 | + /** |
|
629 | + * @param \Smarty $xoopsTpl |
|
630 | + * @throws \RuntimeException |
|
631 | + */ |
|
632 | + public function buildSelection(\Smarty $xoopsTpl) |
|
633 | + { |
|
634 | + $selection = ['action' => $this->page]; |
|
635 | + $selection['vars'] = $this->vars; |
|
636 | + require_once dirname(__DIR__) . '/include/functions.forum.php'; |
|
637 | + $forum_selected = empty($this->vars['forum']) ? null : explode('|', @$this->vars['forum']); |
|
638 | + $selection['forum'] = '<select name="forum[]" multiple="multiple">'; |
|
639 | + $selection['forum'] .= '<option value="0">' . _MD_NEWBB_ALL . '</option>'; |
|
640 | + $selection['forum'] .= newbbForumSelectBox($forum_selected); |
|
641 | + $selection['forum'] .= '</select>'; |
|
642 | + |
|
643 | + $sort_selected = $this->vars['sort']; |
|
644 | + $sorts = $this->getSort('', 'title'); |
|
645 | + $selection['sort'] = "<select name='sort'>"; |
|
646 | + if (!is_array($sorts)) { |
|
647 | + throw new \RuntimeException('$sorts must be an array.'); |
|
648 | + } |
|
649 | + foreach ($sorts as $sort => $title) { |
|
650 | + $selection['sort'] .= "<option value='" . $sort . "' " . (($sort == $sort_selected) ? " selected='selected'" : '') . '>' . $title . '</option>'; |
|
651 | + } |
|
652 | + $selection['sort'] .= '</select>'; |
|
653 | + |
|
654 | + $selection['order'] = "<select name='order'>"; |
|
655 | + $selection['order'] .= "<option value='0' " . (empty($this->vars['order']) ? " selected='selected'" : '') . '>' . _DESCENDING . '</option>'; |
|
656 | + $selection['order'] .= "<option value='1' " . (!empty($this->vars['order']) ? " selected='selected'" : '') . '>' . _ASCENDING . '</option>'; |
|
657 | + $selection['order'] .= '</select>'; |
|
658 | + |
|
659 | + $since = isset($this->vars['since']) ? $this->vars['since'] : $this->config['since_default']; |
|
660 | + $selection['since'] = newbbSinceSelectBox($since); |
|
661 | + |
|
662 | + $xoopsTpl->assign_by_ref('selection', $selection); |
|
663 | + } |
|
664 | + |
|
665 | + /** |
|
666 | + * @param \Smarty $xoopsTpl |
|
667 | + */ |
|
668 | + public function buildSearch(\Smarty $xoopsTpl) |
|
669 | + { |
|
670 | + $search = []; |
|
671 | + $search['forum'] = @$this->vars['forum']; |
|
672 | + $search['since'] = @$this->vars['since']; |
|
673 | + $search['searchin'] = 'both'; |
|
674 | + |
|
675 | + $xoopsTpl->assign_by_ref('search', $search); |
|
676 | + } |
|
677 | + |
|
678 | + /** |
|
679 | + * @param \Smarty $xoopsTpl |
|
680 | + * @throws \RuntimeException |
|
681 | + */ |
|
682 | + public function buildHeaders(\Smarty $xoopsTpl) |
|
683 | + { |
|
684 | + $args = []; |
|
685 | + foreach ($this->vars as $var => $val) { |
|
686 | + if ('sort' === $var || 'order' === $var) { |
|
687 | + continue; |
|
688 | + } |
|
689 | + $args[] = "{$var}={$val}"; |
|
690 | + } |
|
691 | + |
|
692 | + $headers = $this->getSort('', 'title'); |
|
693 | + if (!is_array($headers)) { |
|
694 | + throw new \RuntimeException('$headers must be an array.'); |
|
695 | + } |
|
696 | + foreach ($headers as $header => $title) { |
|
697 | + $_args = ["sort={$header}"]; |
|
698 | + if (@$this->vars['sort'] == $header) { |
|
699 | + $_args[] = 'order=' . ((@$this->vars['order'] + 1) % 2); |
|
700 | + } |
|
701 | + $headers_data[$header]['title'] = $title; |
|
702 | + $headers_data[$header]['link'] = $this->page . '?' . implode('&', array_merge($args, $_args)); |
|
703 | + } |
|
704 | + $xoopsTpl->assign_by_ref('headers', $headers_data); |
|
705 | + } |
|
706 | + |
|
707 | + /** |
|
708 | + * @param \Smarty $xoopsTpl |
|
709 | + */ |
|
710 | + public function buildFilters(\Smarty $xoopsTpl) |
|
711 | + { |
|
712 | + $args = []; |
|
713 | + foreach ($this->vars as $var => $val) { |
|
714 | + if ('status' === $var) { |
|
715 | + continue; |
|
716 | + } |
|
717 | + $args[] = "{$var}={$val}"; |
|
718 | + } |
|
719 | + |
|
720 | + $links = $this->getStatus($this->userlevel); |
|
721 | + |
|
722 | + $status = []; |
|
723 | + foreach ($links as $link => $title) { |
|
724 | + $_args = ["status={$link}"]; |
|
725 | + $status[$link]['title'] = $title; |
|
726 | + $status[$link]['link'] = $this->page . '?' . implode('&', array_merge($args, $_args)); |
|
727 | + } |
|
728 | + $xoopsTpl->assign_by_ref('filters', $status); |
|
729 | + } |
|
730 | + |
|
731 | + /** |
|
732 | + * @param null $type_id |
|
733 | + * @return mixed |
|
734 | + */ |
|
735 | + public function getTypes($type_id = null) |
|
736 | + { |
|
737 | + static $types; |
|
738 | + if (!isset($types)) { |
|
739 | + /** @var Newbb\TypeHandler $typeHandler */ |
|
740 | + $typeHandler = Newbb\Helper::getInstance()->getHandler('Type'); |
|
741 | + |
|
742 | + $types = $typeHandler->getByForum(explode('|', @$this->vars['forum'])); |
|
743 | + } |
|
744 | + |
|
745 | + if (empty($type_id)) { |
|
746 | + return $types; |
|
747 | + } |
|
748 | + |
|
749 | + return @$types[$type_id]; |
|
750 | + } |
|
751 | + |
|
752 | + /** |
|
753 | + * @param \Smarty $xoopsTpl |
|
754 | + * @return bool |
|
755 | + */ |
|
756 | + public function buildTypes(\Smarty $xoopsTpl) |
|
757 | + { |
|
758 | + $status = ''; |
|
759 | + if (!$types = $this->getTypes()) { |
|
760 | + return true; |
|
761 | + } |
|
762 | + |
|
763 | + $args = []; |
|
764 | + foreach ($this->vars as $var => $val) { |
|
765 | + if ('type' === $var) { |
|
766 | + continue; |
|
767 | + } |
|
768 | + $args[] = "{$var}={$val}"; |
|
769 | + } |
|
770 | + |
|
771 | + foreach ($types as $id => $type) { |
|
772 | + $_args = ["type={$id}"]; |
|
773 | + $status[$id]['title'] = $type['type_name']; |
|
774 | + $status[$id]['link'] = $this->page . '?' . implode('&', array_merge($args, $_args)); |
|
775 | + } |
|
776 | + $xoopsTpl->assign_by_ref('types', $status); |
|
777 | + } |
|
778 | + |
|
779 | + /** |
|
780 | + * @param \Smarty $xoopsTpl |
|
781 | + * @return bool |
|
782 | + */ |
|
783 | + public function buildCurrent(\Smarty $xoopsTpl) |
|
784 | + { |
|
785 | + if (empty($this->vars['status']) && !$this->is_multiple) { |
|
786 | + return true; |
|
787 | + } |
|
788 | + |
|
789 | + $args = []; |
|
790 | + foreach ($this->vars as $var => $val) { |
|
791 | + $args[] = "{$var}={$val}"; |
|
792 | + } |
|
793 | + |
|
794 | + $status = []; |
|
795 | + $status['title'] = implode(',', $this->getStatus($this->userlevel, $this->vars['status'])); // irmtfan to accept multiple status |
|
796 | + //$status['link'] = $this->page.(empty($this->vars['status']) ? '' : '?status='.$this->vars['status']); |
|
797 | + $status['link'] = $this->page . (empty($args) ? '' : '?' . implode('&', $args)); |
|
798 | + |
|
799 | + $xoopsTpl->assign_by_ref('current', $status); |
|
800 | + } |
|
801 | + |
|
802 | + /** |
|
803 | + * @param \Smarty $xoopsTpl |
|
804 | + */ |
|
805 | + public function buildPagenav(\Smarty $xoopsTpl) |
|
806 | + { |
|
807 | + $count_topic = $this->getCount(); |
|
808 | + if ($count_topic > $this->config['topics_per_page']) { |
|
809 | + $args = []; |
|
810 | + foreach ($this->vars as $var => $val) { |
|
811 | + if ('start' === $var) { |
|
812 | + continue; |
|
813 | + } |
|
814 | + $args[] = "{$var}={$val}"; |
|
815 | + } |
|
816 | + require_once $GLOBALS['xoops']->path('class/pagenav.php'); |
|
817 | + $nav = new \XoopsPageNav($count_topic, $this->config['topics_per_page'], @$this->vars['start'], 'start', implode('&', $args)); |
|
818 | + if (isset($GLOBALS['xoopsModuleConfig']['do_rewrite'])) { |
|
819 | + $nav->url = formatURL(Request::getString('SERVER_NAME', '', 'SERVER')) . ' /' . $nav->url; |
|
820 | + } |
|
821 | + if ('select' === $this->config['pagenav_display']) { |
|
822 | + $navi = $nav->renderSelect(); |
|
823 | + } elseif ('image' === $this->config['pagenav_display']) { |
|
824 | + $navi = $nav->renderImageNav(4); |
|
825 | + } else { |
|
826 | + $navi = $nav->renderNav(4); |
|
827 | + } |
|
828 | + $xoopsTpl->assign('pagenav', $navi); |
|
829 | + } else { |
|
830 | + $xoopsTpl->assign('pagenav', ''); |
|
831 | + } |
|
832 | + } |
|
833 | + |
|
834 | + /** |
|
835 | + * @return int |
|
836 | + */ |
|
837 | + public function getCount() |
|
838 | + { |
|
839 | + if ($this->noperm) { |
|
840 | + return 0; |
|
841 | + } |
|
842 | + |
|
843 | + $selects = []; |
|
844 | + $froms = []; |
|
845 | + $joins = []; |
|
846 | + $wheres = []; |
|
847 | + |
|
848 | + // topic fields |
|
849 | + $selects[] = 'COUNT(*)'; |
|
850 | + |
|
851 | + $froms[] = $this->handler->db->prefix('newbb_topics') . ' AS t '; |
|
852 | + $joins[] = 'LEFT JOIN ' . $this->handler->db->prefix('newbb_posts') . ' AS p ON p.post_id = t.topic_last_post_id'; |
|
853 | + $wheres[] = '1 = 1'; |
|
854 | + |
|
855 | + $sql = ' SELECT ' . implode(', ', $selects) . ' FROM ' . implode(', ', $froms) . ' ' . implode(' ', $joins) . (!empty($this->query['join']) ? ' ' . implode(' ', $this->query['join']) : '') . // irmtfan bug fix: Undefined index: join when post_excerpt = 0 |
|
856 | + ' WHERE ' . implode(' AND ', $wheres) . ' AND ' . @implode(' AND ', @$this->query['where']); |
|
857 | + |
|
858 | + if (!$result = $this->handler->db->query($sql)) { |
|
859 | + return 0; |
|
860 | + } |
|
861 | + list($count) = $this->handler->db->fetchRow($result); |
|
862 | + |
|
863 | + return $count; |
|
864 | + } |
|
865 | + |
|
866 | + /** |
|
867 | + * @param \Smarty $xoopsTpl |
|
868 | + * @return array|void |
|
869 | + */ |
|
870 | + public function renderTopics(\Smarty $xoopsTpl = null) |
|
871 | + { |
|
872 | + $myts = \MyTextSanitizer::getInstance(); // irmtfan Instanciate |
|
873 | + |
|
874 | + $ret = []; |
|
875 | + //$this->parseVars(); |
|
876 | + |
|
877 | + if ($this->noperm) { |
|
878 | + if (is_object($xoopsTpl)) { |
|
879 | + $xoopsTpl->assign_by_ref('topics', $ret); |
|
880 | + |
|
881 | + return; |
|
882 | + } |
|
883 | + |
|
884 | + return $ret; |
|
885 | + } |
|
886 | + |
|
887 | + $selects = []; |
|
888 | + $froms = []; |
|
889 | + $joins = []; |
|
890 | + $wheres = []; |
|
891 | + |
|
892 | + // topic fields |
|
893 | + $selects[] = 't.*'; |
|
894 | + // post fields |
|
895 | + $selects[] = 'p.post_time as last_post_time, p.poster_name as last_poster_name, p.icon, p.post_id, p.uid'; |
|
896 | + |
|
897 | + $froms[] = $this->handler->db->prefix('newbb_topics') . ' AS t '; |
|
898 | + $joins[] = 'LEFT JOIN ' . $this->handler->db->prefix('newbb_posts') . ' AS p ON p.post_id = t.topic_last_post_id'; |
|
899 | + $wheres[] = '1 = 1'; |
|
900 | + |
|
901 | + if (!empty($this->config['post_excerpt'])) { |
|
902 | + $selects[] = 'p.post_karma, p.require_reply, pt.post_text'; |
|
903 | + $this->query['join'][] = 'LEFT JOIN ' . $this->handler->db->prefix('newbb_posts_text') . ' AS pt ON pt.post_id = t.topic_last_post_id'; |
|
904 | + } |
|
905 | + //if (empty($this->query["sort"])) $this->query["sort"][] = 't.topic_last_post_id DESC'; // irmtfan commented no need |
|
906 | + |
|
907 | + $sql = ' SELECT ' . implode(', ', $selects) . ' FROM ' . implode(', ', $froms) . ' ' . implode(' ', $joins) . (!empty($this->query['join']) ? ' ' . implode(' ', $this->query['join']) : '') . // irmtfan bug fix: Undefined index join when post_excerpt = 0 |
|
908 | + ' WHERE ' . implode(' AND ', $wheres) . ' AND ' . @implode(' AND ', @$this->query['where']) . ' ORDER BY ' . implode(', ', $this->query['sort']); |
|
909 | + |
|
910 | + if (!$result = $this->handler->db->query($sql, $this->config['topics_per_page'], @$this->vars['start'])) { |
|
911 | + if (is_object($xoopsTpl)) { |
|
912 | + $xoopsTpl->assign_by_ref('topics', $ret); |
|
913 | + |
|
914 | + return; |
|
915 | + } |
|
916 | + |
|
917 | + return $ret; |
|
918 | + } |
|
919 | + |
|
920 | + require_once dirname(__DIR__) . '/include/functions.render.php'; |
|
921 | + require_once dirname(__DIR__) . '/include/functions.session.php'; |
|
922 | + require_once dirname(__DIR__) . '/include/functions.time.php'; |
|
923 | + require_once dirname(__DIR__) . '/include/functions.read.php'; |
|
924 | + require_once dirname(__DIR__) . '/include/functions.topic.php'; |
|
925 | + |
|
926 | + $sticky = 0; |
|
927 | + $topics = []; |
|
928 | + $posters = []; |
|
929 | + $reads = []; |
|
930 | + $types = []; |
|
931 | + $forums = []; |
|
932 | + $anonymous = $myts->htmlSpecialChars($GLOBALS['xoopsConfig']['anonymous']); |
|
933 | + |
|
934 | + while (false !== ($myrow = $this->handler->db->fetchArray($result))) { |
|
935 | + if ($myrow['topic_sticky']) { |
|
936 | + ++$sticky; |
|
937 | + } |
|
938 | + |
|
939 | + // ------------------------------------------------------ |
|
940 | + // START irmtfan remove topic_icon hardcode smarty |
|
941 | + // topic_icon: just regular topic_icon |
|
942 | + if (!empty($myrow['icon'])) { |
|
943 | + $topic_icon = '<img align="middle" src="' . XOOPS_URL . '/images/subject/' . htmlspecialchars($myrow['icon'], ENT_QUOTES | ENT_HTML5) . '" alt="" />'; |
|
944 | + } else { |
|
945 | + $topic_icon = '<img align="middle" src="' . XOOPS_URL . '/images/icons/no_posticon.gif" alt="" />'; |
|
946 | + } |
|
947 | + // END irmtfan remove topic_icon hardcode smarty |
|
948 | + |
|
949 | + // ------------------------------------------------------ |
|
950 | + // rating_img |
|
951 | + $rating = number_format($myrow['rating'] / 2, 0); |
|
952 | + // irmtfan - add alt key for rating |
|
953 | + if ($rating < 1) { |
|
954 | + $rating_img = newbbDisplayImage('blank'); |
|
955 | + } else { |
|
956 | + $rating_img = newbbDisplayImage('rate' . $rating, constant('_MD_NEWBB_RATE' . $rating)); |
|
957 | + } |
|
958 | + |
|
959 | + // ------------------------------------------------------ |
|
960 | + // topic_page_jump |
|
961 | + $topic_page_jump = ''; |
|
962 | + $topic_page_jump_icon = ''; |
|
963 | + $totalpages = ceil(($myrow['topic_replies'] + 1) / $this->config['posts_per_page']); |
|
964 | + if ($totalpages > 1) { |
|
965 | + $topic_page_jump .= ' '; |
|
966 | + $append = false; |
|
967 | + for ($i = 1; $i <= $totalpages; ++$i) { |
|
968 | + if ($i > 3 && $i < $totalpages) { |
|
969 | + if (!$append) { |
|
970 | + $topic_page_jump .= '...'; |
|
971 | + $append = true; |
|
972 | + } |
|
973 | + } else { |
|
974 | + $topic_page_jump .= '[<a href="' . XOOPS_URL . '/modules/newbb/viewtopic.php?topic_id=' . $myrow['topic_id'] . '&start=' . (($i - 1) * $this->config['posts_per_page']) . '">' . $i . '</a>]'; |
|
975 | + // irmtfan remove here and move |
|
976 | + //$topic_page_jump_icon = "<a href='" . XOOPS_URL . "/modules/newbb/viewtopic.php?topic_id=" . $myrow['topic_id'] . "&start=" . (($i - 1) * $this->config['posts_per_page']) . "" . "'>" . newbbDisplayImage('document',_MD_NEWBB_GOTOLASTPOST) . '</a>'; |
|
977 | + } |
|
978 | + } |
|
979 | + } |
|
980 | + // irmtfan - move here for both topics with and without pages - change topic_id to post_id |
|
981 | + $topic_page_jump_icon = "<a href='" . XOOPS_URL . '/modules/newbb/viewtopic.php?post_id=' . $myrow['topic_last_post_id'] . '' . "'>" . newbbDisplayImage('lastposticon', _MD_NEWBB_GOTOLASTPOST) . '</a>'; |
|
982 | + |
|
983 | + // ------------------------------------------------------ |
|
984 | + // => topic array |
|
985 | + |
|
986 | + $topic_title = $myts->htmlSpecialChars($myrow['topic_title']); |
|
987 | + // irmtfan use topic_title_excerpt for block topic title length |
|
988 | + $topic_title_excerpt = $topic_title; |
|
989 | + if (!empty($this->config['topic_title_excerpt'])) { |
|
990 | + $topic_title_excerpt = xoops_substr($topic_title, 0, $this->config['topic_title_excerpt']); |
|
991 | + } |
|
992 | + // irmtfan hardcode class commented |
|
993 | + //if ($myrow['topic_digest']) { |
|
994 | + // $topic_title = "<span class='digest'>" . $topic_title . "</span>"; |
|
995 | + //} |
|
996 | + |
|
997 | + if (empty($this->config['post_excerpt'])) { |
|
998 | + $topic_excerpt = ''; |
|
999 | + } elseif (($myrow['post_karma'] > 0 || $myrow['require_reply'] > 0) && !newbbIsAdmin($myrow['forum_id'])) { |
|
1000 | + $topic_excerpt = ''; |
|
1001 | + } else { |
|
1002 | + $topic_excerpt = xoops_substr(newbbHtml2text($myts->displayTarea($myrow['post_text'])), 0, $this->config['post_excerpt']); |
|
1003 | + $topic_excerpt = str_replace('[', '[', $myts->htmlSpecialChars($topic_excerpt)); |
|
1004 | + } |
|
1005 | + |
|
1006 | + $topics[$myrow['topic_id']] = [ |
|
1007 | + 'topic_id' => $myrow['topic_id'], |
|
1008 | + 'topic_icon' => $topic_icon, |
|
1009 | + 'type_id' => $myrow['type_id'], |
|
1010 | + 'topic_title_excerpt' => $topic_title_excerpt, |
|
1011 | + //irmtfan use topic_title_excerpt |
|
1012 | + //'topic_link' => XOOPS_URL . '/modules/newbb/viewtopic.php?topic_id=' . $myrow['topic_id'], // . '&forum=' . $myrow['forum_id'], // irmtfan comment |
|
1013 | + 'topic_link' => 'viewtopic.php?topic_id=' . $myrow['topic_id'], |
|
1014 | + // irmtfan remove hardcode link |
|
1015 | + 'rating_img' => $rating_img, |
|
1016 | + 'votes' => $myrow['votes'], |
|
1017 | + //irmtfan added |
|
1018 | + 'topic_page_jump' => $topic_page_jump, |
|
1019 | + 'topic_page_jump_icon' => $topic_page_jump_icon, |
|
1020 | + 'topic_replies' => $myrow['topic_replies'], |
|
1021 | + 'topic_poster_uid' => $myrow['topic_poster'], |
|
1022 | + 'topic_poster_name' => !empty($myrow['poster_name']) ? $myts->htmlSpecialChars($myrow['poster_name']) : $anonymous, |
|
1023 | + 'topic_views' => $myrow['topic_views'], |
|
1024 | + 'topic_time' => newbbFormatTimestamp($myrow['topic_time']), |
|
1025 | + 'topic_last_post_id' => $myrow['topic_last_post_id'], |
|
1026 | + //irmtfan added |
|
1027 | + 'topic_last_posttime' => newbbFormatTimestamp($myrow['last_post_time']), |
|
1028 | + 'topic_last_poster_uid' => $myrow['uid'], |
|
1029 | + 'topic_last_poster_name' => !empty($myrow['last_poster_name']) ? $myts->htmlSpecialChars($myrow['last_poster_name']) : $anonymous, |
|
1030 | + 'topic_forum' => $myrow['forum_id'], |
|
1031 | + 'topic_excerpt' => $topic_excerpt, |
|
1032 | + 'sticky' => $myrow['topic_sticky'] ? newbbDisplayImage('topic_sticky', _MD_NEWBB_TOPICSTICKY) : '', |
|
1033 | + // irmtfan bug fixed |
|
1034 | + 'lock' => $myrow['topic_status'] ? newbbDisplayImage('topic_locked', _MD_NEWBB_TOPICLOCK) : '', |
|
1035 | + //irmtfan added |
|
1036 | + 'digest' => $myrow['topic_digest'] ? newbbDisplayImage('topic_digest', _MD_NEWBB_TOPICDIGEST) : '', |
|
1037 | + //irmtfan added |
|
1038 | + 'poll' => $myrow['topic_haspoll'] ? newbbDisplayImage('poll', _MD_NEWBB_TOPICHASPOLL) : '', |
|
1039 | + //irmtfan added |
|
1040 | + 'approve' => $myrow['approved'], |
|
1041 | + //irmtfan added |
|
1042 | + ]; |
|
1043 | + |
|
1044 | + /* users */ |
|
1045 | + $posters[$myrow['topic_poster']] = 1; |
|
1046 | + $posters[$myrow['uid']] = 1; |
|
1047 | + // reads |
|
1048 | + if (!empty($this->config['read_mode'])) { |
|
1049 | + $reads[$myrow['topic_id']] = (1 == $this->config['read_mode']) ? $myrow['last_post_time'] : $myrow['topic_last_post_id']; |
|
1050 | + } |
|
1051 | + // types |
|
1052 | + if (!empty($myrow['type_id'])) { |
|
1053 | + //$types[$myrow['type_id']] = 1; |
|
1054 | + } |
|
1055 | + // forums |
|
1056 | + $forums[$myrow['forum_id']] = 1; |
|
1057 | + } |
|
1058 | + $posters_name = newbbGetUnameFromIds(array_keys($posters), $this->config['show_realname'], true); |
|
1059 | + $topic_isRead = newbbIsRead('topic', $reads); |
|
1060 | + /* |
|
1061 | 1061 | $type_list = array(); |
1062 | 1062 | if (count($types) > 0) { |
1063 | 1063 | $typeHandler = Newbb\Helper::getInstance()->getHandler('Type'); |
1064 | 1064 | $type_list = $typeHandler->getAll(new \Criteria("type_id", "(".implode(", ", array_keys($types)).")", "IN"), null, false); |
1065 | 1065 | } |
1066 | 1066 | */ |
1067 | - $type_list = $this->getTypes(); |
|
1068 | - /** @var Newbb\ForumHandler $forumHandler */ |
|
1069 | - $forumHandler = Newbb\Helper::getInstance()->getHandler('Forum'); |
|
1070 | - |
|
1071 | - if (count($forums) > 0) { |
|
1072 | - $forum_list = $forumHandler->getAll(new \Criteria('forum_id', '(' . implode(', ', array_keys($forums)) . ')', 'IN'), ['forum_name', 'hot_threshold'], false); |
|
1073 | - } else { |
|
1074 | - $forum_list = $forumHandler->getAll(); |
|
1075 | - } |
|
1076 | - |
|
1077 | - foreach (array_keys($topics) as $id) { |
|
1078 | - $topics[$id]['topic_read'] = empty($topic_isRead[$id]) ? 0 : 1; // add topic-read/topic-new smarty variable |
|
1079 | - $topics[$id]['topic_forum_link'] = '<a href="' . XOOPS_URL . '/modules/newbb/viewforum.php?forum=' . $topics[$id]['topic_forum'] . '">' . $forum_list[$topics[$id]['topic_forum']]['forum_name'] . '</a>'; |
|
1080 | - |
|
1081 | - //irmtfan use topic_title_excerpt -- add else |
|
1082 | - if (!empty($topics[$id]['type_id']) && isset($type_list[$topics[$id]['type_id']])) { |
|
1083 | - $topics[$id]['topic_title'] = getTopicTitle($topics[$id]['topic_title_excerpt'], $type_list[$topics[$id]['type_id']]['type_name'], $type_list[$topics[$id]['type_id']]['type_color']); |
|
1084 | - } else { |
|
1085 | - $topics[$id]['topic_title'] = $topics[$id]['topic_title_excerpt']; |
|
1086 | - } |
|
1087 | - $topics[$id]['topic_poster'] = !empty($posters_name[$topics[$id]['topic_poster_uid']]) ? $posters_name[$topics[$id]['topic_poster_uid']] : $topics[$id]['topic_poster_name']; |
|
1088 | - $topics[$id]['topic_last_poster'] = !empty($posters_name[$topics[$id]['topic_last_poster_uid']]) ? $posters_name[$topics[$id]['topic_last_poster_uid']] : $topics[$id]['topic_last_poster_name']; |
|
1089 | - // ------------------------------------------------------ |
|
1090 | - // START irmtfan remove hardcodes from topic_folder smarty |
|
1091 | - // topic_folder: priority: newhot -> hot/new -> regular |
|
1092 | - //list($topic_status, $topic_digest, $topic_replies) = $topics[$id]["stats"]; irmtfan |
|
1093 | - // START irmtfan - add topic_folder_text for alt |
|
1094 | - //if ($topics[$id]["lock"] === 1) { |
|
1095 | - // $topic_folder = 'topic_locked'; |
|
1096 | - // $topic_folder_text = _MD_NEWBB_TOPICLOCKED; |
|
1097 | - //} else { |
|
1098 | - //if ($topic_digest) { |
|
1099 | - // $topic_folder = 'topic_digest'; |
|
1100 | - // $topic_folder_text = _MD_NEWBB_TOPICDIGEST; |
|
1101 | - if ($topics[$id]['topic_replies'] >= $forum_list[$topics[$id]['topic_forum']]['hot_threshold']) { |
|
1102 | - $topic_folder = empty($topic_isRead[$id]) ? 'topic_hot_new' : 'topic_hot'; |
|
1103 | - $topic_folder_text = empty($topic_isRead[$id]) ? _MD_NEWBB_MORETHAN : _MD_NEWBB_MORETHAN2; |
|
1104 | - } else { |
|
1105 | - $topic_folder = empty($topic_isRead[$id]) ? 'topic_new' : 'topic'; |
|
1106 | - $topic_folder_text = empty($topic_isRead[$id]) ? _MD_NEWBB_NEWPOSTS : _MD_NEWBB_NONEWPOSTS; |
|
1107 | - } |
|
1108 | - //} |
|
1109 | - // END irmtfan remove hardcodes from topic_folder smarty |
|
1110 | - $topics[$id]['topic_folder'] = newbbDisplayImage($topic_folder, $topic_folder_text); |
|
1111 | - // END irmtfan - add topic_folder_text for alt |
|
1112 | - |
|
1113 | - unset($topics[$id]['topic_poster_name'], $topics[$id]['topic_last_poster_name']);// irmtfan remove $topics[$id]["stats"] because it is not exist now |
|
1114 | - } |
|
1115 | - |
|
1116 | - if (count($topics) > 0) { |
|
1117 | - $sql = ' SELECT DISTINCT topic_id FROM ' . $this->handler->db->prefix('newbb_posts') . " WHERE attachment != ''" . ' AND topic_id IN (' . implode(',', array_keys($topics)) . ')'; |
|
1118 | - if ($result = $this->handler->db->query($sql)) { |
|
1119 | - while (false !== (list($topic_id) = $this->handler->db->fetchRow($result))) { |
|
1120 | - $topics[$topic_id]['attachment'] = ' ' . newbbDisplayImage('attachment', _MD_NEWBB_TOPICSHASATT); |
|
1121 | - } |
|
1122 | - } |
|
1123 | - } |
|
1124 | - |
|
1125 | - if (is_object($xoopsTpl)) { |
|
1126 | - $xoopsTpl->assign_by_ref('sticky', $sticky); |
|
1127 | - $xoopsTpl->assign_by_ref('topics', $topics); |
|
1128 | - |
|
1129 | - return; |
|
1130 | - } |
|
1131 | - |
|
1132 | - return [$topics, $sticky]; |
|
1133 | - } |
|
1134 | - |
|
1135 | - // START irmtfan to create an array from selected keys of an array |
|
1136 | - |
|
1137 | - /** |
|
1138 | - * @param $array |
|
1139 | - * @param null $keys |
|
1140 | - * @return array |
|
1141 | - */ |
|
1142 | - public function getFromKeys($array, $keys = null) |
|
1143 | - { |
|
1144 | - if (empty($keys)) { |
|
1145 | - return $array; |
|
1146 | - } // all keys |
|
1147 | - $keyarr = is_string($keys) ? explode(',', $keys) : $keys; |
|
1148 | - $keyarr = array_intersect(array_keys($array), $keyarr); // keys should be in array |
|
1149 | - $ret = []; |
|
1150 | - foreach ($keyarr as $key) { |
|
1151 | - $ret[$key] = $array[$key]; |
|
1152 | - } |
|
1153 | - |
|
1154 | - return $ret; |
|
1155 | - } |
|
1156 | - // END irmtfan to create an array from selected keys of an array |
|
1067 | + $type_list = $this->getTypes(); |
|
1068 | + /** @var Newbb\ForumHandler $forumHandler */ |
|
1069 | + $forumHandler = Newbb\Helper::getInstance()->getHandler('Forum'); |
|
1070 | + |
|
1071 | + if (count($forums) > 0) { |
|
1072 | + $forum_list = $forumHandler->getAll(new \Criteria('forum_id', '(' . implode(', ', array_keys($forums)) . ')', 'IN'), ['forum_name', 'hot_threshold'], false); |
|
1073 | + } else { |
|
1074 | + $forum_list = $forumHandler->getAll(); |
|
1075 | + } |
|
1076 | + |
|
1077 | + foreach (array_keys($topics) as $id) { |
|
1078 | + $topics[$id]['topic_read'] = empty($topic_isRead[$id]) ? 0 : 1; // add topic-read/topic-new smarty variable |
|
1079 | + $topics[$id]['topic_forum_link'] = '<a href="' . XOOPS_URL . '/modules/newbb/viewforum.php?forum=' . $topics[$id]['topic_forum'] . '">' . $forum_list[$topics[$id]['topic_forum']]['forum_name'] . '</a>'; |
|
1080 | + |
|
1081 | + //irmtfan use topic_title_excerpt -- add else |
|
1082 | + if (!empty($topics[$id]['type_id']) && isset($type_list[$topics[$id]['type_id']])) { |
|
1083 | + $topics[$id]['topic_title'] = getTopicTitle($topics[$id]['topic_title_excerpt'], $type_list[$topics[$id]['type_id']]['type_name'], $type_list[$topics[$id]['type_id']]['type_color']); |
|
1084 | + } else { |
|
1085 | + $topics[$id]['topic_title'] = $topics[$id]['topic_title_excerpt']; |
|
1086 | + } |
|
1087 | + $topics[$id]['topic_poster'] = !empty($posters_name[$topics[$id]['topic_poster_uid']]) ? $posters_name[$topics[$id]['topic_poster_uid']] : $topics[$id]['topic_poster_name']; |
|
1088 | + $topics[$id]['topic_last_poster'] = !empty($posters_name[$topics[$id]['topic_last_poster_uid']]) ? $posters_name[$topics[$id]['topic_last_poster_uid']] : $topics[$id]['topic_last_poster_name']; |
|
1089 | + // ------------------------------------------------------ |
|
1090 | + // START irmtfan remove hardcodes from topic_folder smarty |
|
1091 | + // topic_folder: priority: newhot -> hot/new -> regular |
|
1092 | + //list($topic_status, $topic_digest, $topic_replies) = $topics[$id]["stats"]; irmtfan |
|
1093 | + // START irmtfan - add topic_folder_text for alt |
|
1094 | + //if ($topics[$id]["lock"] === 1) { |
|
1095 | + // $topic_folder = 'topic_locked'; |
|
1096 | + // $topic_folder_text = _MD_NEWBB_TOPICLOCKED; |
|
1097 | + //} else { |
|
1098 | + //if ($topic_digest) { |
|
1099 | + // $topic_folder = 'topic_digest'; |
|
1100 | + // $topic_folder_text = _MD_NEWBB_TOPICDIGEST; |
|
1101 | + if ($topics[$id]['topic_replies'] >= $forum_list[$topics[$id]['topic_forum']]['hot_threshold']) { |
|
1102 | + $topic_folder = empty($topic_isRead[$id]) ? 'topic_hot_new' : 'topic_hot'; |
|
1103 | + $topic_folder_text = empty($topic_isRead[$id]) ? _MD_NEWBB_MORETHAN : _MD_NEWBB_MORETHAN2; |
|
1104 | + } else { |
|
1105 | + $topic_folder = empty($topic_isRead[$id]) ? 'topic_new' : 'topic'; |
|
1106 | + $topic_folder_text = empty($topic_isRead[$id]) ? _MD_NEWBB_NEWPOSTS : _MD_NEWBB_NONEWPOSTS; |
|
1107 | + } |
|
1108 | + //} |
|
1109 | + // END irmtfan remove hardcodes from topic_folder smarty |
|
1110 | + $topics[$id]['topic_folder'] = newbbDisplayImage($topic_folder, $topic_folder_text); |
|
1111 | + // END irmtfan - add topic_folder_text for alt |
|
1112 | + |
|
1113 | + unset($topics[$id]['topic_poster_name'], $topics[$id]['topic_last_poster_name']);// irmtfan remove $topics[$id]["stats"] because it is not exist now |
|
1114 | + } |
|
1115 | + |
|
1116 | + if (count($topics) > 0) { |
|
1117 | + $sql = ' SELECT DISTINCT topic_id FROM ' . $this->handler->db->prefix('newbb_posts') . " WHERE attachment != ''" . ' AND topic_id IN (' . implode(',', array_keys($topics)) . ')'; |
|
1118 | + if ($result = $this->handler->db->query($sql)) { |
|
1119 | + while (false !== (list($topic_id) = $this->handler->db->fetchRow($result))) { |
|
1120 | + $topics[$topic_id]['attachment'] = ' ' . newbbDisplayImage('attachment', _MD_NEWBB_TOPICSHASATT); |
|
1121 | + } |
|
1122 | + } |
|
1123 | + } |
|
1124 | + |
|
1125 | + if (is_object($xoopsTpl)) { |
|
1126 | + $xoopsTpl->assign_by_ref('sticky', $sticky); |
|
1127 | + $xoopsTpl->assign_by_ref('topics', $topics); |
|
1128 | + |
|
1129 | + return; |
|
1130 | + } |
|
1131 | + |
|
1132 | + return [$topics, $sticky]; |
|
1133 | + } |
|
1134 | + |
|
1135 | + // START irmtfan to create an array from selected keys of an array |
|
1136 | + |
|
1137 | + /** |
|
1138 | + * @param $array |
|
1139 | + * @param null $keys |
|
1140 | + * @return array |
|
1141 | + */ |
|
1142 | + public function getFromKeys($array, $keys = null) |
|
1143 | + { |
|
1144 | + if (empty($keys)) { |
|
1145 | + return $array; |
|
1146 | + } // all keys |
|
1147 | + $keyarr = is_string($keys) ? explode(',', $keys) : $keys; |
|
1148 | + $keyarr = array_intersect(array_keys($array), $keyarr); // keys should be in array |
|
1149 | + $ret = []; |
|
1150 | + foreach ($keyarr as $key) { |
|
1151 | + $ret[$key] = $array[$key]; |
|
1152 | + } |
|
1153 | + |
|
1154 | + return $ret; |
|
1155 | + } |
|
1156 | + // END irmtfan to create an array from selected keys of an array |
|
1157 | 1157 | } |
@@ -21,175 +21,175 @@ |
||
21 | 21 | */ |
22 | 22 | class TypeHandler extends \XoopsPersistableObjectHandler |
23 | 23 | { |
24 | - /** |
|
25 | - * @param null|\XoopsDatabase $db |
|
26 | - */ |
|
27 | - public function __construct(\XoopsDatabase $db = null) |
|
28 | - { |
|
29 | - parent::__construct($db, 'newbb_type', Type::class, 'type_id', 'type_name'); |
|
30 | - } |
|
31 | - |
|
32 | - /** |
|
33 | - * Get types linked to a forum |
|
34 | - * |
|
35 | - * @param mixed $forums single forum ID or an array of forum IDs |
|
36 | - * @return array associative array of types (name, color, order) |
|
37 | - */ |
|
38 | - public function getByForum($forums = null) |
|
39 | - { |
|
40 | - $ret = []; |
|
41 | - |
|
42 | - $forums = (is_array($forums) ? array_filter(array_map('intval', array_map('trim', $forums))) : (empty($forums) ? 0 : [(int)$forums])); |
|
43 | - |
|
44 | - $sql = ' SELECT o.type_id, o.type_name, o.type_color, l.type_order' |
|
45 | - . ' FROM ' |
|
46 | - . $this->db->prefix('newbb_type_forum') |
|
47 | - . ' AS l ' |
|
48 | - . " LEFT JOIN {$this->table} AS o ON o.{$this->keyName} = l.{$this->keyName} " |
|
49 | - . ' WHERE ' |
|
50 | - . ' l.forum_id ' |
|
51 | - . (empty($forums) ? 'IS NOT NULL' : 'IN (' . implode(', ', $forums) . ')') |
|
52 | - . ' ORDER BY l.type_order ASC'; |
|
53 | - if (false === ($result = $this->db->query($sql))) { |
|
54 | - //xoops_error($this->db->error()); |
|
55 | - return $ret; |
|
56 | - } |
|
57 | - |
|
58 | - while (false !== ($myrow = $this->db->fetchArray($result))) { |
|
59 | - $ret[$myrow[$this->keyName]] = [ |
|
60 | - 'type_id' => $myrow[$this->keyName], |
|
61 | - 'type_order' => $myrow['type_order'], |
|
62 | - 'type_name' => htmlspecialchars($myrow['type_name'], ENT_QUOTES | ENT_HTML5), |
|
63 | - 'type_color' => htmlspecialchars($myrow['type_color'], ENT_QUOTES | ENT_HTML5) |
|
64 | - ]; |
|
65 | - } |
|
66 | - |
|
67 | - return $ret; |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * Update types linked to a forum |
|
72 | - * |
|
73 | - * @param integer $forum_id |
|
74 | - * @param array $types |
|
75 | - * @return boolean |
|
76 | - */ |
|
77 | - public function updateByForum($forum_id, $types) |
|
78 | - { |
|
79 | - $forum_id = (int)$forum_id; |
|
80 | - if (empty($forum_id)) { |
|
81 | - return false; |
|
82 | - } |
|
83 | - |
|
84 | - $types_existing = $this->getByForum($forum_id); |
|
85 | - $types_valid = []; |
|
86 | - $types_add = []; |
|
87 | - $types_update = []; |
|
88 | - foreach (array_keys($types_existing) as $key) { |
|
89 | - if (empty($types[$key])) { |
|
90 | - continue; |
|
91 | - } |
|
92 | - $types_valid[] = $key; |
|
93 | - if ($types[$key] !== $types_existing[$key]['type_order']) { |
|
94 | - $types_update[] = $key; |
|
95 | - } |
|
96 | - } |
|
97 | - foreach (array_keys($types) as $key) { |
|
98 | - if (!empty($types[$key]) && !isset($types_existing[$key])) { |
|
99 | - $types_add[] = $key; |
|
100 | - } |
|
101 | - } |
|
102 | - $types_valid = array_filter($types_valid); |
|
103 | - $types_add = array_filter($types_add); |
|
104 | - $types_update = array_filter($types_update); |
|
105 | - |
|
106 | - if (!empty($types_valid)) { |
|
107 | - $sql = 'DELETE FROM ' . $this->db->prefix('newbb_type_forum') . ' WHERE ' . ' forum_id = ' . $forum_id . ' AND ' . // irmtfan bug fix: delete other forums types when update the type for a specific forum |
|
108 | - " {$this->keyName} NOT IN (" . implode(', ', $types_valid) . ')'; |
|
109 | - if (false === ($result = $this->db->queryF($sql))) { |
|
110 | - } |
|
111 | - } |
|
112 | - |
|
113 | - if (!empty($types_update)) { |
|
114 | - $type_query = []; |
|
115 | - foreach ($types_update as $key) { |
|
116 | - $order = $types[$key]; |
|
117 | - if ($types_existing[$key]['type_order'] == $order) { |
|
118 | - continue; |
|
119 | - } |
|
120 | - $sql = 'UPDATE ' . $this->db->prefix('newbb_type_forum') . " SET type_order = {$order}" . " WHERE {$this->keyName} = {$key} AND forum_id = {$forum_id}"; |
|
121 | - if (false === ($result = $this->db->queryF($sql))) { |
|
122 | - } |
|
123 | - } |
|
124 | - } |
|
125 | - |
|
126 | - if (!empty($types_add)) { |
|
127 | - $type_query = []; |
|
128 | - foreach ($types_add as $key) { |
|
129 | - $order = $types[$key]; |
|
130 | - //if (!in_array($key, $types_add)) continue; |
|
131 | - $type_query[] = "({$key}, {$forum_id}, {$order})"; |
|
132 | - } |
|
133 | - $sql = 'INSERT INTO ' . $this->db->prefix('newbb_type_forum') . ' (type_id, forum_id, type_order) ' . ' VALUES ' . implode(', ', $type_query); |
|
134 | - if (false === ($result = $this->db->queryF($sql))) { |
|
135 | - //xoops_error($this->db->error()); |
|
136 | - } |
|
137 | - } |
|
138 | - |
|
139 | - return true; |
|
140 | - } |
|
141 | - |
|
142 | - /** |
|
143 | - * delete an object as well as links relying on it |
|
144 | - * |
|
145 | - * @param Type|\XoopsObject $object {@link Type} |
|
146 | - * @param bool $force flag to force the query execution despite security settings |
|
147 | - * @return bool |
|
148 | - */ |
|
149 | - public function delete(\XoopsObject $object, $force = true) |
|
150 | - { |
|
151 | - if (!is_object($object) || !$object->getVar($this->keyName)) { |
|
152 | - return false; |
|
153 | - } |
|
154 | - $queryFunc = empty($force) ? 'query' : 'queryF'; |
|
155 | - |
|
156 | - /* |
|
24 | + /** |
|
25 | + * @param null|\XoopsDatabase $db |
|
26 | + */ |
|
27 | + public function __construct(\XoopsDatabase $db = null) |
|
28 | + { |
|
29 | + parent::__construct($db, 'newbb_type', Type::class, 'type_id', 'type_name'); |
|
30 | + } |
|
31 | + |
|
32 | + /** |
|
33 | + * Get types linked to a forum |
|
34 | + * |
|
35 | + * @param mixed $forums single forum ID or an array of forum IDs |
|
36 | + * @return array associative array of types (name, color, order) |
|
37 | + */ |
|
38 | + public function getByForum($forums = null) |
|
39 | + { |
|
40 | + $ret = []; |
|
41 | + |
|
42 | + $forums = (is_array($forums) ? array_filter(array_map('intval', array_map('trim', $forums))) : (empty($forums) ? 0 : [(int)$forums])); |
|
43 | + |
|
44 | + $sql = ' SELECT o.type_id, o.type_name, o.type_color, l.type_order' |
|
45 | + . ' FROM ' |
|
46 | + . $this->db->prefix('newbb_type_forum') |
|
47 | + . ' AS l ' |
|
48 | + . " LEFT JOIN {$this->table} AS o ON o.{$this->keyName} = l.{$this->keyName} " |
|
49 | + . ' WHERE ' |
|
50 | + . ' l.forum_id ' |
|
51 | + . (empty($forums) ? 'IS NOT NULL' : 'IN (' . implode(', ', $forums) . ')') |
|
52 | + . ' ORDER BY l.type_order ASC'; |
|
53 | + if (false === ($result = $this->db->query($sql))) { |
|
54 | + //xoops_error($this->db->error()); |
|
55 | + return $ret; |
|
56 | + } |
|
57 | + |
|
58 | + while (false !== ($myrow = $this->db->fetchArray($result))) { |
|
59 | + $ret[$myrow[$this->keyName]] = [ |
|
60 | + 'type_id' => $myrow[$this->keyName], |
|
61 | + 'type_order' => $myrow['type_order'], |
|
62 | + 'type_name' => htmlspecialchars($myrow['type_name'], ENT_QUOTES | ENT_HTML5), |
|
63 | + 'type_color' => htmlspecialchars($myrow['type_color'], ENT_QUOTES | ENT_HTML5) |
|
64 | + ]; |
|
65 | + } |
|
66 | + |
|
67 | + return $ret; |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * Update types linked to a forum |
|
72 | + * |
|
73 | + * @param integer $forum_id |
|
74 | + * @param array $types |
|
75 | + * @return boolean |
|
76 | + */ |
|
77 | + public function updateByForum($forum_id, $types) |
|
78 | + { |
|
79 | + $forum_id = (int)$forum_id; |
|
80 | + if (empty($forum_id)) { |
|
81 | + return false; |
|
82 | + } |
|
83 | + |
|
84 | + $types_existing = $this->getByForum($forum_id); |
|
85 | + $types_valid = []; |
|
86 | + $types_add = []; |
|
87 | + $types_update = []; |
|
88 | + foreach (array_keys($types_existing) as $key) { |
|
89 | + if (empty($types[$key])) { |
|
90 | + continue; |
|
91 | + } |
|
92 | + $types_valid[] = $key; |
|
93 | + if ($types[$key] !== $types_existing[$key]['type_order']) { |
|
94 | + $types_update[] = $key; |
|
95 | + } |
|
96 | + } |
|
97 | + foreach (array_keys($types) as $key) { |
|
98 | + if (!empty($types[$key]) && !isset($types_existing[$key])) { |
|
99 | + $types_add[] = $key; |
|
100 | + } |
|
101 | + } |
|
102 | + $types_valid = array_filter($types_valid); |
|
103 | + $types_add = array_filter($types_add); |
|
104 | + $types_update = array_filter($types_update); |
|
105 | + |
|
106 | + if (!empty($types_valid)) { |
|
107 | + $sql = 'DELETE FROM ' . $this->db->prefix('newbb_type_forum') . ' WHERE ' . ' forum_id = ' . $forum_id . ' AND ' . // irmtfan bug fix: delete other forums types when update the type for a specific forum |
|
108 | + " {$this->keyName} NOT IN (" . implode(', ', $types_valid) . ')'; |
|
109 | + if (false === ($result = $this->db->queryF($sql))) { |
|
110 | + } |
|
111 | + } |
|
112 | + |
|
113 | + if (!empty($types_update)) { |
|
114 | + $type_query = []; |
|
115 | + foreach ($types_update as $key) { |
|
116 | + $order = $types[$key]; |
|
117 | + if ($types_existing[$key]['type_order'] == $order) { |
|
118 | + continue; |
|
119 | + } |
|
120 | + $sql = 'UPDATE ' . $this->db->prefix('newbb_type_forum') . " SET type_order = {$order}" . " WHERE {$this->keyName} = {$key} AND forum_id = {$forum_id}"; |
|
121 | + if (false === ($result = $this->db->queryF($sql))) { |
|
122 | + } |
|
123 | + } |
|
124 | + } |
|
125 | + |
|
126 | + if (!empty($types_add)) { |
|
127 | + $type_query = []; |
|
128 | + foreach ($types_add as $key) { |
|
129 | + $order = $types[$key]; |
|
130 | + //if (!in_array($key, $types_add)) continue; |
|
131 | + $type_query[] = "({$key}, {$forum_id}, {$order})"; |
|
132 | + } |
|
133 | + $sql = 'INSERT INTO ' . $this->db->prefix('newbb_type_forum') . ' (type_id, forum_id, type_order) ' . ' VALUES ' . implode(', ', $type_query); |
|
134 | + if (false === ($result = $this->db->queryF($sql))) { |
|
135 | + //xoops_error($this->db->error()); |
|
136 | + } |
|
137 | + } |
|
138 | + |
|
139 | + return true; |
|
140 | + } |
|
141 | + |
|
142 | + /** |
|
143 | + * delete an object as well as links relying on it |
|
144 | + * |
|
145 | + * @param Type|\XoopsObject $object {@link Type} |
|
146 | + * @param bool $force flag to force the query execution despite security settings |
|
147 | + * @return bool |
|
148 | + */ |
|
149 | + public function delete(\XoopsObject $object, $force = true) |
|
150 | + { |
|
151 | + if (!is_object($object) || !$object->getVar($this->keyName)) { |
|
152 | + return false; |
|
153 | + } |
|
154 | + $queryFunc = empty($force) ? 'query' : 'queryF'; |
|
155 | + |
|
156 | + /* |
|
157 | 157 | * Remove forum-type links |
158 | 158 | */ |
159 | - $sql = 'DELETE' . ' FROM ' . $this->db->prefix('newbb_type_forum') . ' WHERE ' . $this->keyName . ' = ' . $object->getVar($this->keyName); |
|
160 | - if (false === ($result = $this->db->{$queryFunc}($sql))) { |
|
161 | - // xoops_error($this->db->error()); |
|
162 | - } |
|
159 | + $sql = 'DELETE' . ' FROM ' . $this->db->prefix('newbb_type_forum') . ' WHERE ' . $this->keyName . ' = ' . $object->getVar($this->keyName); |
|
160 | + if (false === ($result = $this->db->{$queryFunc}($sql))) { |
|
161 | + // xoops_error($this->db->error()); |
|
162 | + } |
|
163 | 163 | |
164 | - /* |
|
164 | + /* |
|
165 | 165 | * Reset topic type linked to this type |
166 | 166 | */ |
167 | - $sql = 'UPATE' . ' ' . $this->db->prefix('newbb_topics') . ' SET ' . $this->keyName . '=0' . ' WHERE ' . $this->keyName . ' = ' . $object->getVar($this->keyName); |
|
168 | - if (false === ($result = $this->db->{$queryFunc}($sql))) { |
|
169 | - //xoops_error($this->db->error()); |
|
170 | - } |
|
171 | - |
|
172 | - return parent::delete($object, $force); |
|
173 | - } |
|
174 | - |
|
175 | - /** |
|
176 | - * clean orphan links from database |
|
177 | - * |
|
178 | - * @param string $table_link |
|
179 | - * @param string $field_link |
|
180 | - * @param string $field_object |
|
181 | - * @return bool true on success |
|
182 | - */ |
|
183 | - public function cleanOrphan($table_link = '', $field_link = '', $field_object = '') //cleanOrphan() |
|
184 | - { |
|
185 | - /* clear forum-type links */ |
|
186 | - $sql = 'DELETE FROM ' . $this->db->prefix('newbb_type_forum') . " WHERE ({$this->keyName} NOT IN ( SELECT DISTINCT {$this->keyName} FROM {$this->table}) )"; |
|
187 | - $this->db->queryF($sql); |
|
188 | - |
|
189 | - /* reconcile topic-type link */ |
|
190 | - $sql = 'UPATE ' . $this->db->prefix('newbb_topics') . " SET {$this->keyName} = 0" . " WHERE ({$this->keyName} NOT IN ( SELECT DISTINCT {$this->keyName} FROM {$this->table}) )"; |
|
191 | - $this->db->queryF($sql); |
|
192 | - |
|
193 | - return true; |
|
194 | - } |
|
167 | + $sql = 'UPATE' . ' ' . $this->db->prefix('newbb_topics') . ' SET ' . $this->keyName . '=0' . ' WHERE ' . $this->keyName . ' = ' . $object->getVar($this->keyName); |
|
168 | + if (false === ($result = $this->db->{$queryFunc}($sql))) { |
|
169 | + //xoops_error($this->db->error()); |
|
170 | + } |
|
171 | + |
|
172 | + return parent::delete($object, $force); |
|
173 | + } |
|
174 | + |
|
175 | + /** |
|
176 | + * clean orphan links from database |
|
177 | + * |
|
178 | + * @param string $table_link |
|
179 | + * @param string $field_link |
|
180 | + * @param string $field_object |
|
181 | + * @return bool true on success |
|
182 | + */ |
|
183 | + public function cleanOrphan($table_link = '', $field_link = '', $field_object = '') //cleanOrphan() |
|
184 | + { |
|
185 | + /* clear forum-type links */ |
|
186 | + $sql = 'DELETE FROM ' . $this->db->prefix('newbb_type_forum') . " WHERE ({$this->keyName} NOT IN ( SELECT DISTINCT {$this->keyName} FROM {$this->table}) )"; |
|
187 | + $this->db->queryF($sql); |
|
188 | + |
|
189 | + /* reconcile topic-type link */ |
|
190 | + $sql = 'UPATE ' . $this->db->prefix('newbb_topics') . " SET {$this->keyName} = 0" . " WHERE ({$this->keyName} NOT IN ( SELECT DISTINCT {$this->keyName} FROM {$this->table}) )"; |
|
191 | + $this->db->queryF($sql); |
|
192 | + |
|
193 | + return true; |
|
194 | + } |
|
195 | 195 | } |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | //define("NEWBB_HANDLER_PERMISSION_FORUM", 1); |
19 | 19 | |
20 | 20 | if (defined('FORUM_PERM_ITEMS') && class_exists('ForumPermissionHandler')) { |
21 | - exit('access denied'); |
|
21 | + exit('access denied'); |
|
22 | 22 | } |
23 | 23 | // irmtfan add pdf and print permissions. |
24 | 24 | define('FORUM_PERM_ITEMS', 'access,view,post,reply,edit,delete,addpoll,vote,attach,noapprove,type,html,signature,pdf,print'); |
@@ -28,246 +28,246 @@ discard block |
||
28 | 28 | */ |
29 | 29 | class PermissionForumHandler extends PermissionHandler |
30 | 30 | { |
31 | - protected $templateFilename; |
|
31 | + protected $templateFilename; |
|
32 | 32 | |
33 | - /** |
|
34 | - * @param \XoopsDatabase $db |
|
35 | - */ |
|
36 | - public function __construct(\XoopsDatabase $db = null) |
|
37 | - { |
|
38 | - // $this->PermissionHandler($db); |
|
39 | - parent::__construct($db); |
|
40 | - $this->templateFilename = XOOPS_VAR_PATH . '/configs/newbb_permission_template.php'; |
|
41 | - } |
|
33 | + /** |
|
34 | + * @param \XoopsDatabase $db |
|
35 | + */ |
|
36 | + public function __construct(\XoopsDatabase $db = null) |
|
37 | + { |
|
38 | + // $this->PermissionHandler($db); |
|
39 | + parent::__construct($db); |
|
40 | + $this->templateFilename = XOOPS_VAR_PATH . '/configs/newbb_permission_template.php'; |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * @param bool $fullname |
|
45 | - * @return array |
|
46 | - */ |
|
47 | - public function getValidPerms($fullname = false) |
|
48 | - { |
|
49 | - static $validPerms = []; |
|
50 | - if (isset($validPerms[(int)$fullname])) { |
|
51 | - return $validPerms[(int)$fullname]; |
|
52 | - } |
|
53 | - $items = array_filter(array_map('trim', explode(',', FORUM_PERM_ITEMS))); |
|
54 | - if (!empty($fullname)) { |
|
55 | - foreach (array_keys($items) as $key) { |
|
56 | - $items[$key] = 'forum_' . $items[$key]; |
|
57 | - } |
|
58 | - } |
|
59 | - $validPerms[(int)$fullname] = $items; |
|
43 | + /** |
|
44 | + * @param bool $fullname |
|
45 | + * @return array |
|
46 | + */ |
|
47 | + public function getValidPerms($fullname = false) |
|
48 | + { |
|
49 | + static $validPerms = []; |
|
50 | + if (isset($validPerms[(int)$fullname])) { |
|
51 | + return $validPerms[(int)$fullname]; |
|
52 | + } |
|
53 | + $items = array_filter(array_map('trim', explode(',', FORUM_PERM_ITEMS))); |
|
54 | + if (!empty($fullname)) { |
|
55 | + foreach (array_keys($items) as $key) { |
|
56 | + $items[$key] = 'forum_' . $items[$key]; |
|
57 | + } |
|
58 | + } |
|
59 | + $validPerms[(int)$fullname] = $items; |
|
60 | 60 | |
61 | - return $items; |
|
62 | - } |
|
61 | + return $items; |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * @param $mid |
|
66 | - * @param int $id |
|
67 | - * @return array |
|
68 | - */ |
|
69 | - public function getValidItems($mid, $id = 0) |
|
70 | - { |
|
71 | - static $suspension = []; |
|
72 | - $full_items = []; |
|
73 | - if (empty($mid)) { |
|
74 | - return $full_items; |
|
75 | - } |
|
64 | + /** |
|
65 | + * @param $mid |
|
66 | + * @param int $id |
|
67 | + * @return array |
|
68 | + */ |
|
69 | + public function getValidItems($mid, $id = 0) |
|
70 | + { |
|
71 | + static $suspension = []; |
|
72 | + $full_items = []; |
|
73 | + if (empty($mid)) { |
|
74 | + return $full_items; |
|
75 | + } |
|
76 | 76 | |
77 | - require_once dirname(__DIR__) . '/include/functions.user.php'; |
|
78 | - $uid = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getVar('uid') : 0; |
|
79 | - $ip = \Xmf\IPAddress::fromRequest()->asReadable(); |
|
80 | - if (!empty($GLOBALS['xoopsModuleConfig']['enable_usermoderate']) && !isset($suspension[$uid][$id]) |
|
81 | - && !newbbIsAdmin($id)) { |
|
82 | - /** @var Newbb\ModerateHandler $moderateHandler */ |
|
83 | - $moderateHandler = Newbb\Helper::getInstance()->getHandler('Moderate'); |
|
84 | - if (!$moderateHandler->verifyUser($uid, '', $id)) { |
|
85 | - $suspension[$uid][$ip][$id] = 1; |
|
86 | - } else { |
|
87 | - $suspension[$uid][$ip][$id] = 0; |
|
88 | - } |
|
89 | - } |
|
77 | + require_once dirname(__DIR__) . '/include/functions.user.php'; |
|
78 | + $uid = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getVar('uid') : 0; |
|
79 | + $ip = \Xmf\IPAddress::fromRequest()->asReadable(); |
|
80 | + if (!empty($GLOBALS['xoopsModuleConfig']['enable_usermoderate']) && !isset($suspension[$uid][$id]) |
|
81 | + && !newbbIsAdmin($id)) { |
|
82 | + /** @var Newbb\ModerateHandler $moderateHandler */ |
|
83 | + $moderateHandler = Newbb\Helper::getInstance()->getHandler('Moderate'); |
|
84 | + if (!$moderateHandler->verifyUser($uid, '', $id)) { |
|
85 | + $suspension[$uid][$ip][$id] = 1; |
|
86 | + } else { |
|
87 | + $suspension[$uid][$ip][$id] = 0; |
|
88 | + } |
|
89 | + } |
|
90 | 90 | |
91 | - $items = $this->getValidPerms(); |
|
92 | - foreach ($items as $item) { |
|
93 | - /* skip access for suspended users */ |
|
94 | - //if ( !empty($suspension[$uid][$ip][$id]) && in_array($item, array("post", "reply", "edit", "delete", "addpoll", "vote", "attach", "noapprove", "type")) ) continue; |
|
95 | - if (!empty($suspension[$uid][$ip][$id])) { |
|
96 | - continue; |
|
97 | - } |
|
98 | - $full_items[] = "'forum_{$item}'"; |
|
99 | - } |
|
91 | + $items = $this->getValidPerms(); |
|
92 | + foreach ($items as $item) { |
|
93 | + /* skip access for suspended users */ |
|
94 | + //if ( !empty($suspension[$uid][$ip][$id]) && in_array($item, array("post", "reply", "edit", "delete", "addpoll", "vote", "attach", "noapprove", "type")) ) continue; |
|
95 | + if (!empty($suspension[$uid][$ip][$id])) { |
|
96 | + continue; |
|
97 | + } |
|
98 | + $full_items[] = "'forum_{$item}'"; |
|
99 | + } |
|
100 | 100 | |
101 | - return $full_items; |
|
102 | - } |
|
101 | + return $full_items; |
|
102 | + } |
|
103 | 103 | |
104 | - /* |
|
104 | + /* |
|
105 | 105 | * Returns permissions for a certain type |
106 | 106 | * |
107 | 107 | * @param int $id id of the item (forum, topic or possibly post) to get permissions for |
108 | 108 | * |
109 | 109 | * @return array |
110 | 110 | */ |
111 | - /** |
|
112 | - * @param int|array $id |
|
113 | - * @return bool|array |
|
114 | - */ |
|
115 | - public function getPermissions($id = 0) |
|
116 | - { |
|
117 | - $permissions = []; |
|
118 | - if (is_object($GLOBALS['xoopsModule']) && 'newbb' === $GLOBALS['xoopsModule']->getVar('dirname')) { |
|
119 | - $modid = $GLOBALS['xoopsModule']->getVar('mid'); |
|
120 | - } else { |
|
121 | - /** @var \XoopsModuleHandler $moduleHandler */ |
|
122 | - $moduleHandler = xoops_getHandler('module'); |
|
123 | - $xoopsNewBB = $moduleHandler->getByDirname('newbb'); |
|
124 | - $modid = $xoopsNewBB->getVar('mid'); |
|
125 | - unset($xoopsNewBB); |
|
126 | - } |
|
111 | + /** |
|
112 | + * @param int|array $id |
|
113 | + * @return bool|array |
|
114 | + */ |
|
115 | + public function getPermissions($id = 0) |
|
116 | + { |
|
117 | + $permissions = []; |
|
118 | + if (is_object($GLOBALS['xoopsModule']) && 'newbb' === $GLOBALS['xoopsModule']->getVar('dirname')) { |
|
119 | + $modid = $GLOBALS['xoopsModule']->getVar('mid'); |
|
120 | + } else { |
|
121 | + /** @var \XoopsModuleHandler $moduleHandler */ |
|
122 | + $moduleHandler = xoops_getHandler('module'); |
|
123 | + $xoopsNewBB = $moduleHandler->getByDirname('newbb'); |
|
124 | + $modid = $xoopsNewBB->getVar('mid'); |
|
125 | + unset($xoopsNewBB); |
|
126 | + } |
|
127 | 127 | |
128 | - // Get user's groups |
|
129 | - $groups = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getGroups() : [XOOPS_GROUP_ANONYMOUS]; |
|
130 | - // Create string of groupid's separated by commas, inserted in a set of brackets |
|
131 | - if (count($groups) < 1) { |
|
132 | - return false; |
|
133 | - } |
|
134 | - // Create criteria for getting only the permissions regarding this module and this user's groups |
|
135 | - $criteria = new \CriteriaCompo(new \Criteria('gperm_modid', $modid)); |
|
136 | - $criteria->add(new \Criteria('gperm_groupid', '(' . implode(',', $groups) . ')', 'IN')); |
|
137 | - if ($id) { |
|
138 | - if (is_array($id)) { |
|
139 | - $criteria->add(new \Criteria('gperm_itemid', '(' . implode(',', $id) . ')', 'IN')); |
|
140 | - } else { |
|
141 | - $criteria->add(new \Criteria('gperm_itemid', (int)$id)); |
|
142 | - } |
|
143 | - } |
|
144 | - $gperm_names = implode(', ', $this->getValidItems($modid, $id)); |
|
128 | + // Get user's groups |
|
129 | + $groups = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getGroups() : [XOOPS_GROUP_ANONYMOUS]; |
|
130 | + // Create string of groupid's separated by commas, inserted in a set of brackets |
|
131 | + if (count($groups) < 1) { |
|
132 | + return false; |
|
133 | + } |
|
134 | + // Create criteria for getting only the permissions regarding this module and this user's groups |
|
135 | + $criteria = new \CriteriaCompo(new \Criteria('gperm_modid', $modid)); |
|
136 | + $criteria->add(new \Criteria('gperm_groupid', '(' . implode(',', $groups) . ')', 'IN')); |
|
137 | + if ($id) { |
|
138 | + if (is_array($id)) { |
|
139 | + $criteria->add(new \Criteria('gperm_itemid', '(' . implode(',', $id) . ')', 'IN')); |
|
140 | + } else { |
|
141 | + $criteria->add(new \Criteria('gperm_itemid', (int)$id)); |
|
142 | + } |
|
143 | + } |
|
144 | + $gperm_names = implode(', ', $this->getValidItems($modid, $id)); |
|
145 | 145 | |
146 | - // Add criteria for gpermnames |
|
147 | - $criteria->add(new \Criteria('gperm_name', '(' . $gperm_names . ')', 'IN')); |
|
148 | - // Get all permission objects in this module and for this user's groups |
|
149 | - $userpermissions = $this->getObjects($criteria, true); |
|
146 | + // Add criteria for gpermnames |
|
147 | + $criteria->add(new \Criteria('gperm_name', '(' . $gperm_names . ')', 'IN')); |
|
148 | + // Get all permission objects in this module and for this user's groups |
|
149 | + $userpermissions = $this->getObjects($criteria, true); |
|
150 | 150 | |
151 | - // Set the granted permissions to 1 |
|
152 | - foreach ($userpermissions as $gperm_id => $gperm) { |
|
153 | - $permissions[$gperm->getVar('gperm_itemid')][$gperm->getVar('gperm_name')] = 1; |
|
154 | - } |
|
155 | - $userpermissions = null; |
|
156 | - unset($userpermissions); |
|
151 | + // Set the granted permissions to 1 |
|
152 | + foreach ($userpermissions as $gperm_id => $gperm) { |
|
153 | + $permissions[$gperm->getVar('gperm_itemid')][$gperm->getVar('gperm_name')] = 1; |
|
154 | + } |
|
155 | + $userpermissions = null; |
|
156 | + unset($userpermissions); |
|
157 | 157 | |
158 | - // Return the permission array |
|
159 | - return $permissions; |
|
160 | - } |
|
158 | + // Return the permission array |
|
159 | + return $permissions; |
|
160 | + } |
|
161 | 161 | |
162 | - /** |
|
163 | - * @param Forum|int $forum |
|
164 | - * @param bool $topic_locked |
|
165 | - * @param bool $isAdmin |
|
166 | - * @return array |
|
167 | - */ |
|
168 | - public function getPermissionTable($forum = 0, $topic_locked = false, $isAdmin = false) |
|
169 | - { |
|
170 | - $perm = []; |
|
162 | + /** |
|
163 | + * @param Forum|int $forum |
|
164 | + * @param bool $topic_locked |
|
165 | + * @param bool $isAdmin |
|
166 | + * @return array |
|
167 | + */ |
|
168 | + public function getPermissionTable($forum = 0, $topic_locked = false, $isAdmin = false) |
|
169 | + { |
|
170 | + $perm = []; |
|
171 | 171 | |
172 | - $forumId = $forum; |
|
173 | - if (is_object($forum)) { |
|
174 | - $forumId = $forum->getVar('forum_id'); |
|
175 | - } |
|
172 | + $forumId = $forum; |
|
173 | + if (is_object($forum)) { |
|
174 | + $forumId = $forum->getVar('forum_id'); |
|
175 | + } |
|
176 | 176 | |
177 | - $permission_set = $this->getPermissions($forumId); |
|
177 | + $permission_set = $this->getPermissions($forumId); |
|
178 | 178 | |
179 | - $permItems = $this->getValidPerms(); |
|
180 | - foreach ($permItems as $item) { |
|
181 | - if ('access' === $item) { |
|
182 | - continue; |
|
183 | - } |
|
184 | - if ($isAdmin |
|
185 | - || (isset($permission_set[$forumId]['forum_' . $item]) |
|
186 | - && (!$topic_locked |
|
187 | - || 'view' === $item))) { |
|
188 | - $perm[] = constant('_MD_NEWBB_CAN_' . strtoupper($item)); |
|
189 | - } else { |
|
190 | - $perm[] = constant('_MD_NEWBB_CANNOT_' . strtoupper($item)); |
|
191 | - } |
|
192 | - } |
|
179 | + $permItems = $this->getValidPerms(); |
|
180 | + foreach ($permItems as $item) { |
|
181 | + if ('access' === $item) { |
|
182 | + continue; |
|
183 | + } |
|
184 | + if ($isAdmin |
|
185 | + || (isset($permission_set[$forumId]['forum_' . $item]) |
|
186 | + && (!$topic_locked |
|
187 | + || 'view' === $item))) { |
|
188 | + $perm[] = constant('_MD_NEWBB_CAN_' . strtoupper($item)); |
|
189 | + } else { |
|
190 | + $perm[] = constant('_MD_NEWBB_CANNOT_' . strtoupper($item)); |
|
191 | + } |
|
192 | + } |
|
193 | 193 | |
194 | - return $perm; |
|
195 | - } |
|
194 | + return $perm; |
|
195 | + } |
|
196 | 196 | |
197 | - /** |
|
198 | - * @param $forum_id |
|
199 | - * @return bool |
|
200 | - */ |
|
201 | - public function deleteByForum($forum_id) |
|
202 | - { |
|
203 | - $forum_id = (int)$forum_id; |
|
204 | - if (empty($forum_id)) { |
|
205 | - return false; |
|
206 | - } |
|
207 | - $grouppermHandler = xoops_getHandler('groupperm'); |
|
208 | - $criteria = new \CriteriaCompo(new \Criteria('gperm_modid', $GLOBALS['xoopsModule']->getVar('mid'))); |
|
209 | - $items = $this->getValidPerms(true); |
|
210 | - $criteria->add(new \Criteria('gperm_name', "('" . implode("', '", $items) . "')", 'IN')); |
|
211 | - $criteria->add(new \Criteria('gperm_itemid', $forum_id)); |
|
197 | + /** |
|
198 | + * @param $forum_id |
|
199 | + * @return bool |
|
200 | + */ |
|
201 | + public function deleteByForum($forum_id) |
|
202 | + { |
|
203 | + $forum_id = (int)$forum_id; |
|
204 | + if (empty($forum_id)) { |
|
205 | + return false; |
|
206 | + } |
|
207 | + $grouppermHandler = xoops_getHandler('groupperm'); |
|
208 | + $criteria = new \CriteriaCompo(new \Criteria('gperm_modid', $GLOBALS['xoopsModule']->getVar('mid'))); |
|
209 | + $items = $this->getValidPerms(true); |
|
210 | + $criteria->add(new \Criteria('gperm_name', "('" . implode("', '", $items) . "')", 'IN')); |
|
211 | + $criteria->add(new \Criteria('gperm_itemid', $forum_id)); |
|
212 | 212 | |
213 | - return $grouppermHandler->deleteAll($criteria); |
|
214 | - } |
|
213 | + return $grouppermHandler->deleteAll($criteria); |
|
214 | + } |
|
215 | 215 | |
216 | - /** |
|
217 | - * @param $forum |
|
218 | - * @param int $mid |
|
219 | - * @return bool |
|
220 | - */ |
|
221 | - public function applyTemplate($forum, $mid = 0) |
|
222 | - { |
|
223 | - if (!$perm_template = $this->getTemplate()) { |
|
224 | - return false; |
|
225 | - } |
|
216 | + /** |
|
217 | + * @param $forum |
|
218 | + * @param int $mid |
|
219 | + * @return bool |
|
220 | + */ |
|
221 | + public function applyTemplate($forum, $mid = 0) |
|
222 | + { |
|
223 | + if (!$perm_template = $this->getTemplate()) { |
|
224 | + return false; |
|
225 | + } |
|
226 | 226 | |
227 | - if (empty($mid)) { |
|
228 | - if (is_object($GLOBALS['xoopsModule']) && 'newbb' === $GLOBALS['xoopsModule']->getVar('dirname')) { |
|
229 | - $mid = $GLOBALS['xoopsModule']->getVar('mid'); |
|
230 | - } else { |
|
231 | - /** @var \XoopsModuleHandler $moduleHandler */ |
|
232 | - $moduleHandler = xoops_getHandler('module'); |
|
233 | - $newbb = $moduleHandler->getByDirname('newbb'); |
|
234 | - $mid = $newbb->getVar('mid'); |
|
235 | - unset($newbb); |
|
236 | - } |
|
237 | - } |
|
227 | + if (empty($mid)) { |
|
228 | + if (is_object($GLOBALS['xoopsModule']) && 'newbb' === $GLOBALS['xoopsModule']->getVar('dirname')) { |
|
229 | + $mid = $GLOBALS['xoopsModule']->getVar('mid'); |
|
230 | + } else { |
|
231 | + /** @var \XoopsModuleHandler $moduleHandler */ |
|
232 | + $moduleHandler = xoops_getHandler('module'); |
|
233 | + $newbb = $moduleHandler->getByDirname('newbb'); |
|
234 | + $mid = $newbb->getVar('mid'); |
|
235 | + unset($newbb); |
|
236 | + } |
|
237 | + } |
|
238 | 238 | |
239 | - /** @var \XoopsMemberHandler $memberHandler */ |
|
240 | - $memberHandler = xoops_getHandler('member'); |
|
241 | - $glist = $memberHandler->getGroupList(); |
|
242 | - $perms = $this->getValidPerms(true); |
|
243 | - foreach (array_keys($glist) as $group) { |
|
244 | - foreach ($perms as $perm) { |
|
245 | - if (!empty($perm_template[$group][$perm])) { |
|
246 | - $this->validateRight($perm, $forum, $group, $mid); |
|
247 | - } else { |
|
248 | - $this->deleteRight($perm, $forum, $group, $mid); |
|
249 | - } |
|
250 | - } |
|
251 | - } |
|
239 | + /** @var \XoopsMemberHandler $memberHandler */ |
|
240 | + $memberHandler = xoops_getHandler('member'); |
|
241 | + $glist = $memberHandler->getGroupList(); |
|
242 | + $perms = $this->getValidPerms(true); |
|
243 | + foreach (array_keys($glist) as $group) { |
|
244 | + foreach ($perms as $perm) { |
|
245 | + if (!empty($perm_template[$group][$perm])) { |
|
246 | + $this->validateRight($perm, $forum, $group, $mid); |
|
247 | + } else { |
|
248 | + $this->deleteRight($perm, $forum, $group, $mid); |
|
249 | + } |
|
250 | + } |
|
251 | + } |
|
252 | 252 | |
253 | - return true; |
|
254 | - } |
|
253 | + return true; |
|
254 | + } |
|
255 | 255 | |
256 | - /** |
|
257 | - * @return array|false |
|
258 | - */ |
|
259 | - public function getTemplate() |
|
260 | - { |
|
261 | - $perms = \Xmf\Yaml::readWrapped($this->templateFilename); |
|
262 | - return $perms; |
|
263 | - } |
|
256 | + /** |
|
257 | + * @return array|false |
|
258 | + */ |
|
259 | + public function getTemplate() |
|
260 | + { |
|
261 | + $perms = \Xmf\Yaml::readWrapped($this->templateFilename); |
|
262 | + return $perms; |
|
263 | + } |
|
264 | 264 | |
265 | - /** |
|
266 | - * @param array $perms |
|
267 | - * @return bool |
|
268 | - */ |
|
269 | - public function setTemplate($perms) |
|
270 | - { |
|
271 | - return \Xmf\Yaml::saveWrapped($perms, $this->templateFilename); |
|
272 | - } |
|
265 | + /** |
|
266 | + * @param array $perms |
|
267 | + * @return bool |
|
268 | + */ |
|
269 | + public function setTemplate($perms) |
|
270 | + { |
|
271 | + return \Xmf\Yaml::saveWrapped($perms, $this->templateFilename); |
|
272 | + } |
|
273 | 273 | } |
@@ -22,570 +22,570 @@ |
||
22 | 22 | */ |
23 | 23 | class TopicHandler extends \XoopsPersistableObjectHandler |
24 | 24 | { |
25 | - /** |
|
26 | - * @param \XoopsDatabase $db |
|
27 | - */ |
|
28 | - public function __construct(\XoopsDatabase $db = null) |
|
29 | - { |
|
30 | - parent::__construct($db, 'newbb_topics', Topic::class, 'topic_id', 'topic_title'); |
|
31 | - } |
|
32 | - |
|
33 | - /** |
|
34 | - * @param mixed $id |
|
35 | - * @param null|array $fields |
|
36 | - * @return mixed|null |
|
37 | - */ |
|
38 | - public function get($id = null, $fields = null) //get($id, $var = null) |
|
39 | - { |
|
40 | - $var = $fields; |
|
41 | - $ret = null; |
|
42 | - $tags = $var; |
|
43 | - if (!empty($var) && is_string($var)) { |
|
44 | - $tags = [$var]; |
|
45 | - } |
|
46 | - if (!$topicObject = parent::get($id, $tags)) { |
|
47 | - return $ret; |
|
48 | - } |
|
49 | - $ret = $topicObject; |
|
50 | - if (!empty($var) && is_string($var)) { |
|
51 | - $ret = @$topicObject->getVar($var); |
|
52 | - } |
|
53 | - |
|
54 | - return $ret; |
|
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * @param \XoopsObject $object |
|
59 | - * @param bool $force |
|
60 | - * @return mixed |
|
61 | - */ |
|
62 | - public function insert(\XoopsObject $object, $force = true) |
|
63 | - { |
|
64 | - if (!$object->getVar('topic_time')) { |
|
65 | - $object->setVar('topic_time', time()); |
|
66 | - } |
|
67 | - if (!parent::insert($object, $force) || !$object->getVar('approved')) { |
|
68 | - return $object->getVar('topic_id'); |
|
69 | - } |
|
70 | - |
|
71 | - $newbbConfig = newbbLoadConfig(); |
|
72 | - if (!empty($newbbConfig['do_tag']) |
|
73 | - && @require_once $GLOBALS['xoops']->path('modules/tag/include/functions.php')) { |
|
74 | - if ($tagHandler = tag_getTagHandler()) { |
|
75 | - $tagHandler->updateByItem($object->getVar('topic_tags', 'n'), $object->getVar('topic_id'), 'newbb'); |
|
76 | - } |
|
77 | - } |
|
78 | - |
|
79 | - return $object->getVar('topic_id'); |
|
80 | - } |
|
81 | - |
|
82 | - /** |
|
83 | - * @param $object |
|
84 | - * @param bool $force |
|
85 | - * @return bool |
|
86 | - */ |
|
87 | - public function approve($object, $force = false) |
|
88 | - { |
|
89 | - $topic_id = $object->getVar('topic_id'); |
|
90 | - if ($force) { |
|
91 | - $sql = 'UPDATE ' . $this->db->prefix('newbb_topics') . " SET approved = -1 WHERE topic_id = {$topic_id}"; |
|
92 | - } else { |
|
93 | - $sql = 'UPDATE ' . $this->db->prefix('newbb_topics') . " SET approved = 1 WHERE topic_id = {$topic_id}"; |
|
94 | - } |
|
95 | - if (!$result = $this->db->queryF($sql)) { |
|
96 | - //xoops_error($this->db->error()); |
|
97 | - return false; |
|
98 | - } |
|
99 | - $postHandler = Newbb\Helper::getInstance()->getHandler('Post'); |
|
100 | - $postsObject = $postHandler->getAll(new \Criteria('topic_id', $topic_id)); |
|
101 | - foreach (array_keys($postsObject) as $post_id) { |
|
102 | - $postHandler->approve($postsObject[$post_id]); |
|
103 | - } |
|
104 | - unset($postsObject); |
|
105 | - $statsHandler = Newbb\Helper::getInstance()->getHandler('Stats'); |
|
106 | - $statsHandler->update($object->getVar('forum_id'), 'topic'); |
|
107 | - |
|
108 | - return true; |
|
109 | - } |
|
110 | - |
|
111 | - /** |
|
112 | - * get previous/next topic |
|
113 | - * |
|
114 | - * @param integer $topic_id current topic ID |
|
115 | - * @param integer $action |
|
116 | - * <ul> |
|
117 | - * <li> -1: previous </li> |
|
118 | - * <li> 0: current </li> |
|
119 | - * <li> 1: next </li> |
|
120 | - * </ul> |
|
121 | - * @param integer $forum_id the scope for moving |
|
122 | - * <ul> |
|
123 | - * <li> >0 : inside the forum </li> |
|
124 | - * <li> <= 0: global </li> |
|
125 | - * </ul> |
|
126 | - * @access public |
|
127 | - * @return mixed|null|\XoopsObject |
|
128 | - */ |
|
129 | - public function &getByMove($topic_id, $action, $forum_id = 0) |
|
130 | - { |
|
131 | - $topic = null; |
|
132 | - if (!empty($action)) { |
|
133 | - $sql = 'SELECT * FROM ' . $this->table . ' WHERE 1=1' . (($forum_id > 0) ? ' AND forum_id=' . (int)$forum_id : '') . ' AND topic_id ' . (($action > 0) ? '>' : '<') . (int)$topic_id . ' ORDER BY topic_id ' . (($action > 0) ? 'ASC' : 'DESC') . ' LIMIT 1'; |
|
134 | - if ($result = $this->db->query($sql)) { |
|
135 | - if ($row = $this->db->fetchArray($result)) { |
|
136 | - $topic = $this->create(false); |
|
137 | - $topic->assignVars($row); |
|
138 | - |
|
139 | - return $topic; |
|
140 | - } |
|
141 | - } |
|
142 | - } |
|
143 | - $topic = $this->get($topic_id); |
|
144 | - |
|
145 | - return $topic; |
|
146 | - } |
|
147 | - |
|
148 | - /** |
|
149 | - * @param $post_id |
|
150 | - * @return null|\XoopsObject |
|
151 | - */ |
|
152 | - public function &getByPost($post_id) |
|
153 | - { |
|
154 | - $topic = null; |
|
155 | - $sql = 'SELECT t.* FROM ' . $this->db->prefix('newbb_topics') . ' t, ' . $this->db->prefix('newbb_posts') . ' p |
|
25 | + /** |
|
26 | + * @param \XoopsDatabase $db |
|
27 | + */ |
|
28 | + public function __construct(\XoopsDatabase $db = null) |
|
29 | + { |
|
30 | + parent::__construct($db, 'newbb_topics', Topic::class, 'topic_id', 'topic_title'); |
|
31 | + } |
|
32 | + |
|
33 | + /** |
|
34 | + * @param mixed $id |
|
35 | + * @param null|array $fields |
|
36 | + * @return mixed|null |
|
37 | + */ |
|
38 | + public function get($id = null, $fields = null) //get($id, $var = null) |
|
39 | + { |
|
40 | + $var = $fields; |
|
41 | + $ret = null; |
|
42 | + $tags = $var; |
|
43 | + if (!empty($var) && is_string($var)) { |
|
44 | + $tags = [$var]; |
|
45 | + } |
|
46 | + if (!$topicObject = parent::get($id, $tags)) { |
|
47 | + return $ret; |
|
48 | + } |
|
49 | + $ret = $topicObject; |
|
50 | + if (!empty($var) && is_string($var)) { |
|
51 | + $ret = @$topicObject->getVar($var); |
|
52 | + } |
|
53 | + |
|
54 | + return $ret; |
|
55 | + } |
|
56 | + |
|
57 | + /** |
|
58 | + * @param \XoopsObject $object |
|
59 | + * @param bool $force |
|
60 | + * @return mixed |
|
61 | + */ |
|
62 | + public function insert(\XoopsObject $object, $force = true) |
|
63 | + { |
|
64 | + if (!$object->getVar('topic_time')) { |
|
65 | + $object->setVar('topic_time', time()); |
|
66 | + } |
|
67 | + if (!parent::insert($object, $force) || !$object->getVar('approved')) { |
|
68 | + return $object->getVar('topic_id'); |
|
69 | + } |
|
70 | + |
|
71 | + $newbbConfig = newbbLoadConfig(); |
|
72 | + if (!empty($newbbConfig['do_tag']) |
|
73 | + && @require_once $GLOBALS['xoops']->path('modules/tag/include/functions.php')) { |
|
74 | + if ($tagHandler = tag_getTagHandler()) { |
|
75 | + $tagHandler->updateByItem($object->getVar('topic_tags', 'n'), $object->getVar('topic_id'), 'newbb'); |
|
76 | + } |
|
77 | + } |
|
78 | + |
|
79 | + return $object->getVar('topic_id'); |
|
80 | + } |
|
81 | + |
|
82 | + /** |
|
83 | + * @param $object |
|
84 | + * @param bool $force |
|
85 | + * @return bool |
|
86 | + */ |
|
87 | + public function approve($object, $force = false) |
|
88 | + { |
|
89 | + $topic_id = $object->getVar('topic_id'); |
|
90 | + if ($force) { |
|
91 | + $sql = 'UPDATE ' . $this->db->prefix('newbb_topics') . " SET approved = -1 WHERE topic_id = {$topic_id}"; |
|
92 | + } else { |
|
93 | + $sql = 'UPDATE ' . $this->db->prefix('newbb_topics') . " SET approved = 1 WHERE topic_id = {$topic_id}"; |
|
94 | + } |
|
95 | + if (!$result = $this->db->queryF($sql)) { |
|
96 | + //xoops_error($this->db->error()); |
|
97 | + return false; |
|
98 | + } |
|
99 | + $postHandler = Newbb\Helper::getInstance()->getHandler('Post'); |
|
100 | + $postsObject = $postHandler->getAll(new \Criteria('topic_id', $topic_id)); |
|
101 | + foreach (array_keys($postsObject) as $post_id) { |
|
102 | + $postHandler->approve($postsObject[$post_id]); |
|
103 | + } |
|
104 | + unset($postsObject); |
|
105 | + $statsHandler = Newbb\Helper::getInstance()->getHandler('Stats'); |
|
106 | + $statsHandler->update($object->getVar('forum_id'), 'topic'); |
|
107 | + |
|
108 | + return true; |
|
109 | + } |
|
110 | + |
|
111 | + /** |
|
112 | + * get previous/next topic |
|
113 | + * |
|
114 | + * @param integer $topic_id current topic ID |
|
115 | + * @param integer $action |
|
116 | + * <ul> |
|
117 | + * <li> -1: previous </li> |
|
118 | + * <li> 0: current </li> |
|
119 | + * <li> 1: next </li> |
|
120 | + * </ul> |
|
121 | + * @param integer $forum_id the scope for moving |
|
122 | + * <ul> |
|
123 | + * <li> >0 : inside the forum </li> |
|
124 | + * <li> <= 0: global </li> |
|
125 | + * </ul> |
|
126 | + * @access public |
|
127 | + * @return mixed|null|\XoopsObject |
|
128 | + */ |
|
129 | + public function &getByMove($topic_id, $action, $forum_id = 0) |
|
130 | + { |
|
131 | + $topic = null; |
|
132 | + if (!empty($action)) { |
|
133 | + $sql = 'SELECT * FROM ' . $this->table . ' WHERE 1=1' . (($forum_id > 0) ? ' AND forum_id=' . (int)$forum_id : '') . ' AND topic_id ' . (($action > 0) ? '>' : '<') . (int)$topic_id . ' ORDER BY topic_id ' . (($action > 0) ? 'ASC' : 'DESC') . ' LIMIT 1'; |
|
134 | + if ($result = $this->db->query($sql)) { |
|
135 | + if ($row = $this->db->fetchArray($result)) { |
|
136 | + $topic = $this->create(false); |
|
137 | + $topic->assignVars($row); |
|
138 | + |
|
139 | + return $topic; |
|
140 | + } |
|
141 | + } |
|
142 | + } |
|
143 | + $topic = $this->get($topic_id); |
|
144 | + |
|
145 | + return $topic; |
|
146 | + } |
|
147 | + |
|
148 | + /** |
|
149 | + * @param $post_id |
|
150 | + * @return null|\XoopsObject |
|
151 | + */ |
|
152 | + public function &getByPost($post_id) |
|
153 | + { |
|
154 | + $topic = null; |
|
155 | + $sql = 'SELECT t.* FROM ' . $this->db->prefix('newbb_topics') . ' t, ' . $this->db->prefix('newbb_posts') . ' p |
|
156 | 156 | WHERE t.topic_id = p.topic_id AND p.post_id = ' . (int)$post_id; |
157 | - $result = $this->db->query($sql); |
|
158 | - if (!$result) { |
|
159 | - //xoops_error($this->db->error()); |
|
160 | - return $topic; |
|
161 | - } |
|
162 | - $row = $this->db->fetchArray($result); |
|
163 | - $topic = $this->create(false); |
|
164 | - $topic->assignVars($row); |
|
165 | - |
|
166 | - return $topic; |
|
167 | - } |
|
168 | - |
|
169 | - /** |
|
170 | - * @param Topic $topic |
|
171 | - * @param string $type |
|
172 | - * @return mixed |
|
173 | - */ |
|
174 | - public function getPostCount(&$topic, $type = '') |
|
175 | - { |
|
176 | - switch ($type) { |
|
177 | - case 'pending': |
|
178 | - $approved = 0; |
|
179 | - break; |
|
180 | - case 'deleted': |
|
181 | - $approved = -1; |
|
182 | - break; |
|
183 | - default: |
|
184 | - $approved = 1; |
|
185 | - break; |
|
186 | - } |
|
187 | - $criteria = new \CriteriaCompo(new \Criteria('topic_id', $topic->getVar('topic_id'))); |
|
188 | - $criteria->add(new \Criteria('approved', $approved)); |
|
189 | - /** @var Newbb\PostHandler $postHandler */ |
|
190 | - $postHandler = Newbb\Helper::getInstance()->getHandler('Post'); |
|
191 | - $count = $postHandler->getCount($criteria); |
|
192 | - |
|
193 | - return $count; |
|
194 | - } |
|
195 | - |
|
196 | - /** |
|
197 | - * @param $topic_id |
|
198 | - * @return null|Newbb\Post |
|
199 | - */ |
|
200 | - public function &getTopPost($topic_id) |
|
201 | - { |
|
202 | - $post = null; |
|
203 | - $sql = 'SELECT p.*, t.* FROM ' . $this->db->prefix('newbb_posts') . ' p, |
|
157 | + $result = $this->db->query($sql); |
|
158 | + if (!$result) { |
|
159 | + //xoops_error($this->db->error()); |
|
160 | + return $topic; |
|
161 | + } |
|
162 | + $row = $this->db->fetchArray($result); |
|
163 | + $topic = $this->create(false); |
|
164 | + $topic->assignVars($row); |
|
165 | + |
|
166 | + return $topic; |
|
167 | + } |
|
168 | + |
|
169 | + /** |
|
170 | + * @param Topic $topic |
|
171 | + * @param string $type |
|
172 | + * @return mixed |
|
173 | + */ |
|
174 | + public function getPostCount(&$topic, $type = '') |
|
175 | + { |
|
176 | + switch ($type) { |
|
177 | + case 'pending': |
|
178 | + $approved = 0; |
|
179 | + break; |
|
180 | + case 'deleted': |
|
181 | + $approved = -1; |
|
182 | + break; |
|
183 | + default: |
|
184 | + $approved = 1; |
|
185 | + break; |
|
186 | + } |
|
187 | + $criteria = new \CriteriaCompo(new \Criteria('topic_id', $topic->getVar('topic_id'))); |
|
188 | + $criteria->add(new \Criteria('approved', $approved)); |
|
189 | + /** @var Newbb\PostHandler $postHandler */ |
|
190 | + $postHandler = Newbb\Helper::getInstance()->getHandler('Post'); |
|
191 | + $count = $postHandler->getCount($criteria); |
|
192 | + |
|
193 | + return $count; |
|
194 | + } |
|
195 | + |
|
196 | + /** |
|
197 | + * @param $topic_id |
|
198 | + * @return null|Newbb\Post |
|
199 | + */ |
|
200 | + public function &getTopPost($topic_id) |
|
201 | + { |
|
202 | + $post = null; |
|
203 | + $sql = 'SELECT p.*, t.* FROM ' . $this->db->prefix('newbb_posts') . ' p, |
|
204 | 204 | ' . $this->db->prefix('newbb_posts_text') . ' t |
205 | 205 | WHERE |
206 | 206 | p.topic_id = ' . $topic_id . ' AND p.pid = 0 |
207 | 207 | AND t.post_id = p.post_id'; |
208 | 208 | |
209 | - $result = $this->db->query($sql); |
|
210 | - if (!$result) { |
|
211 | - //xoops_error($this->db->error()); |
|
212 | - return $post; |
|
213 | - } |
|
214 | - /** @var Newbb\PostHandler $postHandler */ |
|
215 | - $postHandler = Newbb\Helper::getInstance()->getHandler('Post'); |
|
216 | - $myrow = $this->db->fetchArray($result); |
|
217 | - /** @var Newbb\Post $post */ |
|
218 | - $post = $postHandler->create(false); |
|
219 | - $post->assignVars($myrow); |
|
220 | - |
|
221 | - return $post; |
|
222 | - } |
|
223 | - |
|
224 | - /** |
|
225 | - * @param $topic_id |
|
226 | - * @return bool |
|
227 | - */ |
|
228 | - public function getTopPostId($topic_id) |
|
229 | - { |
|
230 | - $sql = 'SELECT MIN(post_id) AS post_id FROM ' . $this->db->prefix('newbb_posts') . ' WHERE topic_id = ' . $topic_id . ' AND pid = 0'; |
|
231 | - $result = $this->db->query($sql); |
|
232 | - if (!$result) { |
|
233 | - //xoops_error($this->db->error()); |
|
234 | - return false; |
|
235 | - } |
|
236 | - list($post_id) = $this->db->fetchRow($result); |
|
237 | - |
|
238 | - return $post_id; |
|
239 | - } |
|
240 | - |
|
241 | - /** |
|
242 | - * @param $topic |
|
243 | - * @param string $order |
|
244 | - * @param int $perpage |
|
245 | - * @param $start |
|
246 | - * @param int $post_id |
|
247 | - * @param string $type |
|
248 | - * @return array |
|
249 | - */ |
|
250 | - public function &getAllPosts(&$topic, $order = 'ASC', $perpage = 10, &$start, $post_id = 0, $type = '') |
|
251 | - { |
|
252 | - $ret = []; |
|
253 | - $perpage = ((int)$perpage > 0) ? (int)$perpage : (empty($GLOBALS['xoopsModuleConfig']['posts_per_page']) ? 10 : $GLOBALS['xoopsModuleConfig']['posts_per_page']); |
|
254 | - $start = (int)$start; |
|
255 | - switch ($type) { |
|
256 | - case 'pending': |
|
257 | - $approveCriteria = ' AND p.approved = 0'; |
|
258 | - break; |
|
259 | - case 'deleted': |
|
260 | - $approveCriteria = ' AND p.approved = -1'; |
|
261 | - break; |
|
262 | - default: |
|
263 | - $approveCriteria = ' AND p.approved = 1'; |
|
264 | - break; |
|
265 | - } |
|
266 | - |
|
267 | - if ($post_id) { |
|
268 | - if ('DESC' === $order) { |
|
269 | - $operator_for_position = '>'; |
|
270 | - } else { |
|
271 | - $order = 'ASC'; |
|
272 | - $operator_for_position = '<'; |
|
273 | - } |
|
274 | - //$approveCriteria = ' AND approved = 1'; // any others? |
|
275 | - $sql = 'SELECT COUNT(*) FROM ' . $this->db->prefix('newbb_posts') . ' AS p WHERE p.topic_id=' . (int)$topic->getVar('topic_id') . $approveCriteria . " AND p.post_id $operator_for_position $post_id"; |
|
276 | - $result = $this->db->query($sql); |
|
277 | - if (!$result) { |
|
278 | - //xoops_error($this->db->error()); |
|
279 | - return $ret; |
|
280 | - } |
|
281 | - list($position) = $this->db->fetchRow($result); |
|
282 | - $start = (int)($position / $perpage) * $perpage; |
|
283 | - } |
|
284 | - |
|
285 | - $sql = 'SELECT p.*, t.* FROM ' . $this->db->prefix('newbb_posts') . ' p, ' . $this->db->prefix('newbb_posts_text') . ' t WHERE p.topic_id=' . $topic->getVar('topic_id') . ' AND p.post_id = t.post_id' . $approveCriteria . " ORDER BY p.post_id $order"; |
|
286 | - $result = $this->db->query($sql, $perpage, $start); |
|
287 | - if (!$result) { |
|
288 | - //xoops_error($this->db->error()); |
|
289 | - return $ret; |
|
290 | - } |
|
291 | - $postHandler = Newbb\Helper::getInstance()->getHandler('Post'); |
|
292 | - while (false !== ($myrow = $this->db->fetchArray($result))) { |
|
293 | - $post = $postHandler->create(false); |
|
294 | - $post->assignVars($myrow); |
|
295 | - $ret[$myrow['post_id']] = $post; |
|
296 | - unset($post); |
|
297 | - } |
|
298 | - |
|
299 | - return $ret; |
|
300 | - } |
|
301 | - |
|
302 | - /** |
|
303 | - * @param $postArray |
|
304 | - * @param int $pid |
|
305 | - * @return mixed |
|
306 | - */ |
|
307 | - public function &getPostTree(&$postArray, $pid = 0) |
|
308 | - { |
|
309 | - // require_once $GLOBALS['xoops']->path('modules/newbb/class/Tree.php'); |
|
310 | - $NewBBTree = new Newbb\Tree('newbb_posts'); |
|
311 | - $NewBBTree->setPrefix(' '); |
|
312 | - $NewBBTree->setPostArray($postArray); |
|
313 | - $NewBBTree->getPostTree($postsArray, $pid); |
|
314 | - |
|
315 | - return $postsArray; |
|
316 | - } |
|
317 | - |
|
318 | - /** |
|
319 | - * @param $topic |
|
320 | - * @param $postArray |
|
321 | - * @return mixed |
|
322 | - */ |
|
323 | - public function showTreeItem(&$topic, &$postArray) |
|
324 | - { |
|
325 | - global $viewtopic_users, $myts; |
|
326 | - |
|
327 | - $postArray['post_time'] = newbbFormatTimestamp($postArray['post_time']); |
|
328 | - |
|
329 | - if (!empty($postArray['icon'])) { |
|
330 | - $postArray['icon'] = '<img src="' . XOOPS_URL . '/images/subject/' . htmlspecialchars($postArray['icon'], ENT_QUOTES | ENT_HTML5) . '" alt="" />'; |
|
331 | - } else { |
|
332 | - $postArray['icon'] = '<a name="' . $postArray['post_id'] . '"><img src="' . XOOPS_URL . '/images/icons/no_posticon.gif" alt="" /></a>'; |
|
333 | - } |
|
334 | - |
|
335 | - $postArray['subject'] = '<a href="viewtopic.php?viewmode=thread&topic_id=' . $topic->getVar('topic_id') . '&forum=' . $postArray['forum_id'] . '&post_id=' . $postArray['post_id'] . '">' . $postArray['subject'] . '</a>'; |
|
336 | - |
|
337 | - $isActiveUser = false; |
|
338 | - if (isset($viewtopic_users[$postArray['uid']]['name'])) { |
|
339 | - $postArray['poster'] = $viewtopic_users[$postArray['uid']]['name']; |
|
340 | - if ($postArray['uid'] > 0) { |
|
341 | - $postArray['poster'] = '<a href="' . XOOPS_URL . '/userinfo.php?uid=' . $postArray['uid'] . '">' . $viewtopic_users[$postArray['uid']]['name'] . '</a>'; |
|
342 | - } |
|
343 | - } else { |
|
344 | - $postArray['poster'] = empty($postArray['poster_name']) ? $myts->htmlSpecialChars($GLOBALS['xoopsConfig']['anonymous']) : $postArray['poster_name']; |
|
345 | - } |
|
346 | - |
|
347 | - return $postArray; |
|
348 | - } |
|
349 | - |
|
350 | - /** |
|
351 | - * @param $topic |
|
352 | - * @param bool $isApproved |
|
353 | - * @return array |
|
354 | - */ |
|
355 | - public function &getAllPosters(&$topic, $isApproved = true) |
|
356 | - { |
|
357 | - $sql = 'SELECT DISTINCT uid FROM ' . $this->db->prefix('newbb_posts') . ' WHERE topic_id=' . $topic->getVar('topic_id') . ' AND uid>0'; |
|
358 | - if ($isApproved) { |
|
359 | - $sql .= ' AND approved = 1'; |
|
360 | - } |
|
361 | - $result = $this->db->query($sql); |
|
362 | - if (!$result) { |
|
363 | - //xoops_error($this->db->error()); |
|
364 | - return []; |
|
365 | - } |
|
366 | - $ret = []; |
|
367 | - while (false !== ($myrow = $this->db->fetchArray($result))) { |
|
368 | - $ret[] = $myrow['uid']; |
|
369 | - } |
|
370 | - |
|
371 | - return $ret; |
|
372 | - } |
|
373 | - |
|
374 | - /** |
|
375 | - * @param Topic|\XoopsObject $topic |
|
376 | - * @param bool $force |
|
377 | - * @return bool |
|
378 | - */ |
|
379 | - public function delete(\XoopsObject $topic, $force = true) |
|
380 | - { |
|
381 | - $topic_id = is_object($topic) ? $topic->getVar('topic_id') : (int)$topic; |
|
382 | - if (empty($topic_id)) { |
|
383 | - return false; |
|
384 | - } |
|
385 | - $postObject = $this->getTopPost($topic_id); |
|
386 | - /** @var Newbb\PostHandler $postHandler */ |
|
387 | - $postHandler = Newbb\Helper::getInstance()->getHandler('Post'); |
|
388 | - $postHandler->delete($postObject, false, $force); |
|
389 | - |
|
390 | - $newbbConfig = newbbLoadConfig(); |
|
391 | - /** @var \XoopsModules\Tag\TagHandler $tagHandler */ |
|
392 | - if (!empty($newbbConfig['do_tag']) && $tagHandler = Tag\Helper::getInstance()->getHandler('Tag')) { //@xoops_getModuleHandler('tag', 'tag', true)) { |
|
393 | - $tagHandler->updateByItem([], $topic_id, 'newbb'); |
|
394 | - } |
|
395 | - |
|
396 | - return true; |
|
397 | - } |
|
398 | - |
|
399 | - // get permission |
|
400 | - // parameter: $type: 'post', 'view', 'reply', 'edit', 'delete', 'addpoll', 'vote', 'attach' |
|
401 | - // $gperm_names = "'forum_can_post', 'forum_can_view', 'forum_can_reply', 'forum_can_edit', 'forum_can_delete', 'forum_can_addpoll', 'forum_can_vote', 'forum_can_attach', 'forum_can_noapprove'"; |
|
402 | - /** |
|
403 | - * @param Newbb\Forum $forum |
|
404 | - * @param int $topic_locked |
|
405 | - * @param string $type |
|
406 | - * @return bool |
|
407 | - */ |
|
408 | - public function getPermission($forum, $topic_locked = 0, $type = 'view') |
|
409 | - { |
|
410 | - static $_cachedTopicPerms; |
|
411 | - require_once dirname(__DIR__) . '/include/functions.user.php'; |
|
412 | - if (newbbIsAdmin($forum)) { |
|
413 | - return true; |
|
414 | - } |
|
415 | - |
|
416 | - $forum_id = is_object($forum) ? $forum->getVar('forum_id') : (int)$forum; |
|
417 | - if ($forum_id < 1) { |
|
418 | - return false; |
|
419 | - } |
|
420 | - |
|
421 | - if ($topic_locked && 'view' !== $type) { |
|
422 | - $permission = false; |
|
423 | - } else { |
|
424 | - /** var Newbb\PermissionHandler $permHandler */ |
|
425 | - $permHandler = Newbb\Helper::getInstance()->getHandler('Permission'); |
|
426 | - $permission = $permHandler->getPermission('forum', $type, $forum_id); |
|
427 | - } |
|
428 | - |
|
429 | - return $permission; |
|
430 | - } |
|
431 | - |
|
432 | - /** |
|
433 | - * clean orphan items from database |
|
434 | - * |
|
435 | - * @param string $table_link |
|
436 | - * @param string $field_link |
|
437 | - * @param string $field_object |
|
438 | - * @return bool true on success |
|
439 | - */ |
|
440 | - public function cleanOrphan($table_link = '', $field_link = '', $field_object = '') //cleanOrphan() |
|
441 | - { |
|
442 | - $this->deleteAll(new \Criteria('topic_time', 0), true, true); |
|
443 | - parent::cleanOrphan($this->db->prefix('newbb_forums'), 'forum_id'); |
|
444 | - parent::cleanOrphan($this->db->prefix('newbb_posts'), 'topic_id'); |
|
445 | - |
|
446 | - return true; |
|
447 | - } |
|
448 | - |
|
449 | - /** |
|
450 | - * clean expired objects from database |
|
451 | - * |
|
452 | - * @param int $expire time limit for expiration |
|
453 | - * @return bool true on success |
|
454 | - */ |
|
455 | - public function cleanExpires($expire = 0) |
|
456 | - { |
|
457 | - // irmtfan if 0 no cleanup look include/plugin.php |
|
458 | - if (!func_num_args()) { |
|
459 | - $newbbConfig = newbbLoadConfig(); |
|
460 | - $expire = isset($newbbConfig['pending_expire']) ? (int)$newbbConfig['pending_expire'] : 7; |
|
461 | - $expire = $expire * 24 * 3600; // days to seconds |
|
462 | - } |
|
463 | - if (empty($expire)) { |
|
464 | - return false; |
|
465 | - } |
|
466 | - $crit_expire = new \CriteriaCompo(new \Criteria('approved', 0, '<=')); |
|
467 | - $crit_expire->add(new \Criteria('topic_time', time() - (int)$expire, '<')); |
|
468 | - |
|
469 | - return $this->deleteAll($crit_expire, true/*, true*/); |
|
470 | - } |
|
471 | - |
|
472 | - // START irmtfan - rewrite topic synchronization function. add pid sync and remove hard-code db access |
|
473 | - |
|
474 | - /** |
|
475 | - * @param null $object |
|
476 | - * @param bool $force |
|
477 | - * @return bool |
|
478 | - */ |
|
479 | - public function synchronization($object = null, $force = true) |
|
480 | - { |
|
481 | - if (!is_object($object)) { |
|
482 | - $object = $this->get((int)$object); |
|
483 | - } |
|
484 | - if (!is_object($object) || !$object->getVar('topic_id')) { |
|
485 | - return false; |
|
486 | - } |
|
487 | - |
|
488 | - /** @var Newbb\PostHandler $postHandler */ |
|
489 | - $postHandler = Newbb\Helper::getInstance()->getHandler('Post'); |
|
490 | - $criteria = new \CriteriaCompo(); |
|
491 | - $criteria->add(new \Criteria('topic_id', $object->getVar('topic_id')), 'AND'); |
|
492 | - $criteria->add(new \Criteria('approved', 1), 'AND'); |
|
493 | - $post_ids = $postHandler->getIds($criteria); |
|
494 | - if (empty($post_ids)) { |
|
495 | - return false; |
|
496 | - } |
|
497 | - $last_post = max($post_ids); |
|
498 | - $top_post = min($post_ids); |
|
499 | - $topic_replies = count($post_ids) - 1; |
|
500 | - if ($object->getVar('topic_last_post_id') != $last_post) { |
|
501 | - $object->setVar('topic_last_post_id', $last_post); |
|
502 | - } |
|
503 | - if ($object->getVar('topic_replies') != $topic_replies) { |
|
504 | - $object->setVar('topic_replies', $topic_replies); |
|
505 | - } |
|
506 | - $b1 = $this->insert($object, $force); |
|
507 | - $criteria->add(new \Criteria('post_id', $top_post, '<>'), 'AND'); |
|
508 | - $criteria->add(new \Criteria('pid', '(' . implode(', ', $post_ids) . ')', 'NOT IN'), 'AND'); |
|
509 | - $b2 = $postHandler->updateAll('pid', $top_post, $criteria, $force); |
|
510 | - $criteria = new \CriteriaCompo(); |
|
511 | - $criteria->add(new \Criteria('post_id', $top_post, '='), 'AND'); |
|
512 | - $b3 = $postHandler->updateAll('pid', 0, $criteria, $force); |
|
513 | - |
|
514 | - return ($b1 && $b2 && $b3); |
|
515 | - } |
|
516 | - // END irmtfan - rewrite topic synchronization function. add pid sync and remove hard-code db access |
|
517 | - // START irmtfan getActivePolls |
|
518 | - /** |
|
519 | - * get all active poll modules in the current xoops installtion. |
|
520 | - * @access public |
|
521 | - * @return array $pollDirs = array($dirname1=>$dirname1, $dirname2=>$dirname2, ...) dirnames of all active poll modules |
|
522 | - */ |
|
523 | - public function getActivePolls() |
|
524 | - { |
|
525 | - $pollDirs = []; |
|
526 | - $allDirs = xoops_getActiveModules(); |
|
527 | - foreach ($allDirs as $dirname) { |
|
528 | - // pollresults.php file is exist in all xoopspoll versions and umfrage versions |
|
529 | - if (file_exists($GLOBALS['xoops']->path('modules/' . $dirname . '/pollresults.php'))) { |
|
530 | - $pollDirs[$dirname] = $dirname; |
|
531 | - } |
|
532 | - } |
|
533 | - |
|
534 | - return $pollDirs; |
|
535 | - } |
|
536 | - // END irmtfan getActivePolls |
|
537 | - |
|
538 | - // START irmtfan findPollModule |
|
539 | - /** |
|
540 | - * find poll module that is in used in the current newbb installtion. |
|
541 | - * @access public |
|
542 | - * @param array $pollDirs dirnames of all active poll modules |
|
543 | - * @return bool|string $dir_def | true | false |
|
544 | - * $dir_def: dirname of poll module that is in used in the current newbb installtion. |
|
545 | - * true: no poll module is installed | newbb has no topic with poll | newbb has no topic |
|
546 | - * false: errors (see below xoops_errors) |
|
547 | - */ |
|
548 | - public function findPollModule(array $pollDirs = []) |
|
549 | - { |
|
550 | - $dir_def = ''; |
|
551 | - if (empty($pollDirs)) { |
|
552 | - $pollDirs = $this->getActivePolls(); |
|
553 | - } |
|
554 | - if (empty($pollDirs)) { |
|
555 | - return true; |
|
556 | - } |
|
557 | - // if only one active poll module still we need to check!!! |
|
558 | - //if(count($pollDirs) === 1) return end($pollDirs); |
|
559 | - $topicPollObjs = $this->getAll(new \Criteria('topic_haspoll', 1), ['topic_id', 'poll_id']); |
|
560 | - if (empty($topicPollObjs)) { |
|
561 | - return true; |
|
562 | - } // no poll or no topic!!! |
|
563 | - foreach ($topicPollObjs as $tObj) { |
|
564 | - $poll_idInMod = 0; |
|
565 | - foreach ($pollDirs as $dirname) { |
|
566 | - $pollObj = $tObj->getPoll($tObj->getVar('poll_id'), $dirname); |
|
567 | - if (is_object($pollObj) && ($pollObj->getVar('poll_id') == $tObj->getVar('poll_id'))) { |
|
568 | - ++$poll_idInMod; |
|
569 | - $dir_def = $dirname; |
|
570 | - } |
|
571 | - } |
|
572 | - // Only one poll module should has this poll_id |
|
573 | - // if 0 there is an error |
|
574 | - if (0 == $poll_idInMod) { |
|
575 | - xoops_error("Error: Cannot find poll module for poll_id='{$tObj->getVar('poll_id')}'"); |
|
576 | - |
|
577 | - return false; |
|
578 | - } |
|
579 | - // if 1 => $dir_def is correct |
|
580 | - if (1 == $poll_idInMod) { |
|
581 | - return $dir_def; |
|
582 | - } |
|
583 | - // if more than 1 continue |
|
584 | - } |
|
585 | - // if there is some topics but no module or more than one module have polls |
|
586 | - xoops_error("Error: Cannot find poll module that is in used in newbb!!! <br\><br\>You should select the correct poll module yourself in newbb > preferences > poll module setting."); |
|
587 | - |
|
588 | - return false; |
|
589 | - } |
|
590 | - // END irmtfan findPollModule |
|
209 | + $result = $this->db->query($sql); |
|
210 | + if (!$result) { |
|
211 | + //xoops_error($this->db->error()); |
|
212 | + return $post; |
|
213 | + } |
|
214 | + /** @var Newbb\PostHandler $postHandler */ |
|
215 | + $postHandler = Newbb\Helper::getInstance()->getHandler('Post'); |
|
216 | + $myrow = $this->db->fetchArray($result); |
|
217 | + /** @var Newbb\Post $post */ |
|
218 | + $post = $postHandler->create(false); |
|
219 | + $post->assignVars($myrow); |
|
220 | + |
|
221 | + return $post; |
|
222 | + } |
|
223 | + |
|
224 | + /** |
|
225 | + * @param $topic_id |
|
226 | + * @return bool |
|
227 | + */ |
|
228 | + public function getTopPostId($topic_id) |
|
229 | + { |
|
230 | + $sql = 'SELECT MIN(post_id) AS post_id FROM ' . $this->db->prefix('newbb_posts') . ' WHERE topic_id = ' . $topic_id . ' AND pid = 0'; |
|
231 | + $result = $this->db->query($sql); |
|
232 | + if (!$result) { |
|
233 | + //xoops_error($this->db->error()); |
|
234 | + return false; |
|
235 | + } |
|
236 | + list($post_id) = $this->db->fetchRow($result); |
|
237 | + |
|
238 | + return $post_id; |
|
239 | + } |
|
240 | + |
|
241 | + /** |
|
242 | + * @param $topic |
|
243 | + * @param string $order |
|
244 | + * @param int $perpage |
|
245 | + * @param $start |
|
246 | + * @param int $post_id |
|
247 | + * @param string $type |
|
248 | + * @return array |
|
249 | + */ |
|
250 | + public function &getAllPosts(&$topic, $order = 'ASC', $perpage = 10, &$start, $post_id = 0, $type = '') |
|
251 | + { |
|
252 | + $ret = []; |
|
253 | + $perpage = ((int)$perpage > 0) ? (int)$perpage : (empty($GLOBALS['xoopsModuleConfig']['posts_per_page']) ? 10 : $GLOBALS['xoopsModuleConfig']['posts_per_page']); |
|
254 | + $start = (int)$start; |
|
255 | + switch ($type) { |
|
256 | + case 'pending': |
|
257 | + $approveCriteria = ' AND p.approved = 0'; |
|
258 | + break; |
|
259 | + case 'deleted': |
|
260 | + $approveCriteria = ' AND p.approved = -1'; |
|
261 | + break; |
|
262 | + default: |
|
263 | + $approveCriteria = ' AND p.approved = 1'; |
|
264 | + break; |
|
265 | + } |
|
266 | + |
|
267 | + if ($post_id) { |
|
268 | + if ('DESC' === $order) { |
|
269 | + $operator_for_position = '>'; |
|
270 | + } else { |
|
271 | + $order = 'ASC'; |
|
272 | + $operator_for_position = '<'; |
|
273 | + } |
|
274 | + //$approveCriteria = ' AND approved = 1'; // any others? |
|
275 | + $sql = 'SELECT COUNT(*) FROM ' . $this->db->prefix('newbb_posts') . ' AS p WHERE p.topic_id=' . (int)$topic->getVar('topic_id') . $approveCriteria . " AND p.post_id $operator_for_position $post_id"; |
|
276 | + $result = $this->db->query($sql); |
|
277 | + if (!$result) { |
|
278 | + //xoops_error($this->db->error()); |
|
279 | + return $ret; |
|
280 | + } |
|
281 | + list($position) = $this->db->fetchRow($result); |
|
282 | + $start = (int)($position / $perpage) * $perpage; |
|
283 | + } |
|
284 | + |
|
285 | + $sql = 'SELECT p.*, t.* FROM ' . $this->db->prefix('newbb_posts') . ' p, ' . $this->db->prefix('newbb_posts_text') . ' t WHERE p.topic_id=' . $topic->getVar('topic_id') . ' AND p.post_id = t.post_id' . $approveCriteria . " ORDER BY p.post_id $order"; |
|
286 | + $result = $this->db->query($sql, $perpage, $start); |
|
287 | + if (!$result) { |
|
288 | + //xoops_error($this->db->error()); |
|
289 | + return $ret; |
|
290 | + } |
|
291 | + $postHandler = Newbb\Helper::getInstance()->getHandler('Post'); |
|
292 | + while (false !== ($myrow = $this->db->fetchArray($result))) { |
|
293 | + $post = $postHandler->create(false); |
|
294 | + $post->assignVars($myrow); |
|
295 | + $ret[$myrow['post_id']] = $post; |
|
296 | + unset($post); |
|
297 | + } |
|
298 | + |
|
299 | + return $ret; |
|
300 | + } |
|
301 | + |
|
302 | + /** |
|
303 | + * @param $postArray |
|
304 | + * @param int $pid |
|
305 | + * @return mixed |
|
306 | + */ |
|
307 | + public function &getPostTree(&$postArray, $pid = 0) |
|
308 | + { |
|
309 | + // require_once $GLOBALS['xoops']->path('modules/newbb/class/Tree.php'); |
|
310 | + $NewBBTree = new Newbb\Tree('newbb_posts'); |
|
311 | + $NewBBTree->setPrefix(' '); |
|
312 | + $NewBBTree->setPostArray($postArray); |
|
313 | + $NewBBTree->getPostTree($postsArray, $pid); |
|
314 | + |
|
315 | + return $postsArray; |
|
316 | + } |
|
317 | + |
|
318 | + /** |
|
319 | + * @param $topic |
|
320 | + * @param $postArray |
|
321 | + * @return mixed |
|
322 | + */ |
|
323 | + public function showTreeItem(&$topic, &$postArray) |
|
324 | + { |
|
325 | + global $viewtopic_users, $myts; |
|
326 | + |
|
327 | + $postArray['post_time'] = newbbFormatTimestamp($postArray['post_time']); |
|
328 | + |
|
329 | + if (!empty($postArray['icon'])) { |
|
330 | + $postArray['icon'] = '<img src="' . XOOPS_URL . '/images/subject/' . htmlspecialchars($postArray['icon'], ENT_QUOTES | ENT_HTML5) . '" alt="" />'; |
|
331 | + } else { |
|
332 | + $postArray['icon'] = '<a name="' . $postArray['post_id'] . '"><img src="' . XOOPS_URL . '/images/icons/no_posticon.gif" alt="" /></a>'; |
|
333 | + } |
|
334 | + |
|
335 | + $postArray['subject'] = '<a href="viewtopic.php?viewmode=thread&topic_id=' . $topic->getVar('topic_id') . '&forum=' . $postArray['forum_id'] . '&post_id=' . $postArray['post_id'] . '">' . $postArray['subject'] . '</a>'; |
|
336 | + |
|
337 | + $isActiveUser = false; |
|
338 | + if (isset($viewtopic_users[$postArray['uid']]['name'])) { |
|
339 | + $postArray['poster'] = $viewtopic_users[$postArray['uid']]['name']; |
|
340 | + if ($postArray['uid'] > 0) { |
|
341 | + $postArray['poster'] = '<a href="' . XOOPS_URL . '/userinfo.php?uid=' . $postArray['uid'] . '">' . $viewtopic_users[$postArray['uid']]['name'] . '</a>'; |
|
342 | + } |
|
343 | + } else { |
|
344 | + $postArray['poster'] = empty($postArray['poster_name']) ? $myts->htmlSpecialChars($GLOBALS['xoopsConfig']['anonymous']) : $postArray['poster_name']; |
|
345 | + } |
|
346 | + |
|
347 | + return $postArray; |
|
348 | + } |
|
349 | + |
|
350 | + /** |
|
351 | + * @param $topic |
|
352 | + * @param bool $isApproved |
|
353 | + * @return array |
|
354 | + */ |
|
355 | + public function &getAllPosters(&$topic, $isApproved = true) |
|
356 | + { |
|
357 | + $sql = 'SELECT DISTINCT uid FROM ' . $this->db->prefix('newbb_posts') . ' WHERE topic_id=' . $topic->getVar('topic_id') . ' AND uid>0'; |
|
358 | + if ($isApproved) { |
|
359 | + $sql .= ' AND approved = 1'; |
|
360 | + } |
|
361 | + $result = $this->db->query($sql); |
|
362 | + if (!$result) { |
|
363 | + //xoops_error($this->db->error()); |
|
364 | + return []; |
|
365 | + } |
|
366 | + $ret = []; |
|
367 | + while (false !== ($myrow = $this->db->fetchArray($result))) { |
|
368 | + $ret[] = $myrow['uid']; |
|
369 | + } |
|
370 | + |
|
371 | + return $ret; |
|
372 | + } |
|
373 | + |
|
374 | + /** |
|
375 | + * @param Topic|\XoopsObject $topic |
|
376 | + * @param bool $force |
|
377 | + * @return bool |
|
378 | + */ |
|
379 | + public function delete(\XoopsObject $topic, $force = true) |
|
380 | + { |
|
381 | + $topic_id = is_object($topic) ? $topic->getVar('topic_id') : (int)$topic; |
|
382 | + if (empty($topic_id)) { |
|
383 | + return false; |
|
384 | + } |
|
385 | + $postObject = $this->getTopPost($topic_id); |
|
386 | + /** @var Newbb\PostHandler $postHandler */ |
|
387 | + $postHandler = Newbb\Helper::getInstance()->getHandler('Post'); |
|
388 | + $postHandler->delete($postObject, false, $force); |
|
389 | + |
|
390 | + $newbbConfig = newbbLoadConfig(); |
|
391 | + /** @var \XoopsModules\Tag\TagHandler $tagHandler */ |
|
392 | + if (!empty($newbbConfig['do_tag']) && $tagHandler = Tag\Helper::getInstance()->getHandler('Tag')) { //@xoops_getModuleHandler('tag', 'tag', true)) { |
|
393 | + $tagHandler->updateByItem([], $topic_id, 'newbb'); |
|
394 | + } |
|
395 | + |
|
396 | + return true; |
|
397 | + } |
|
398 | + |
|
399 | + // get permission |
|
400 | + // parameter: $type: 'post', 'view', 'reply', 'edit', 'delete', 'addpoll', 'vote', 'attach' |
|
401 | + // $gperm_names = "'forum_can_post', 'forum_can_view', 'forum_can_reply', 'forum_can_edit', 'forum_can_delete', 'forum_can_addpoll', 'forum_can_vote', 'forum_can_attach', 'forum_can_noapprove'"; |
|
402 | + /** |
|
403 | + * @param Newbb\Forum $forum |
|
404 | + * @param int $topic_locked |
|
405 | + * @param string $type |
|
406 | + * @return bool |
|
407 | + */ |
|
408 | + public function getPermission($forum, $topic_locked = 0, $type = 'view') |
|
409 | + { |
|
410 | + static $_cachedTopicPerms; |
|
411 | + require_once dirname(__DIR__) . '/include/functions.user.php'; |
|
412 | + if (newbbIsAdmin($forum)) { |
|
413 | + return true; |
|
414 | + } |
|
415 | + |
|
416 | + $forum_id = is_object($forum) ? $forum->getVar('forum_id') : (int)$forum; |
|
417 | + if ($forum_id < 1) { |
|
418 | + return false; |
|
419 | + } |
|
420 | + |
|
421 | + if ($topic_locked && 'view' !== $type) { |
|
422 | + $permission = false; |
|
423 | + } else { |
|
424 | + /** var Newbb\PermissionHandler $permHandler */ |
|
425 | + $permHandler = Newbb\Helper::getInstance()->getHandler('Permission'); |
|
426 | + $permission = $permHandler->getPermission('forum', $type, $forum_id); |
|
427 | + } |
|
428 | + |
|
429 | + return $permission; |
|
430 | + } |
|
431 | + |
|
432 | + /** |
|
433 | + * clean orphan items from database |
|
434 | + * |
|
435 | + * @param string $table_link |
|
436 | + * @param string $field_link |
|
437 | + * @param string $field_object |
|
438 | + * @return bool true on success |
|
439 | + */ |
|
440 | + public function cleanOrphan($table_link = '', $field_link = '', $field_object = '') //cleanOrphan() |
|
441 | + { |
|
442 | + $this->deleteAll(new \Criteria('topic_time', 0), true, true); |
|
443 | + parent::cleanOrphan($this->db->prefix('newbb_forums'), 'forum_id'); |
|
444 | + parent::cleanOrphan($this->db->prefix('newbb_posts'), 'topic_id'); |
|
445 | + |
|
446 | + return true; |
|
447 | + } |
|
448 | + |
|
449 | + /** |
|
450 | + * clean expired objects from database |
|
451 | + * |
|
452 | + * @param int $expire time limit for expiration |
|
453 | + * @return bool true on success |
|
454 | + */ |
|
455 | + public function cleanExpires($expire = 0) |
|
456 | + { |
|
457 | + // irmtfan if 0 no cleanup look include/plugin.php |
|
458 | + if (!func_num_args()) { |
|
459 | + $newbbConfig = newbbLoadConfig(); |
|
460 | + $expire = isset($newbbConfig['pending_expire']) ? (int)$newbbConfig['pending_expire'] : 7; |
|
461 | + $expire = $expire * 24 * 3600; // days to seconds |
|
462 | + } |
|
463 | + if (empty($expire)) { |
|
464 | + return false; |
|
465 | + } |
|
466 | + $crit_expire = new \CriteriaCompo(new \Criteria('approved', 0, '<=')); |
|
467 | + $crit_expire->add(new \Criteria('topic_time', time() - (int)$expire, '<')); |
|
468 | + |
|
469 | + return $this->deleteAll($crit_expire, true/*, true*/); |
|
470 | + } |
|
471 | + |
|
472 | + // START irmtfan - rewrite topic synchronization function. add pid sync and remove hard-code db access |
|
473 | + |
|
474 | + /** |
|
475 | + * @param null $object |
|
476 | + * @param bool $force |
|
477 | + * @return bool |
|
478 | + */ |
|
479 | + public function synchronization($object = null, $force = true) |
|
480 | + { |
|
481 | + if (!is_object($object)) { |
|
482 | + $object = $this->get((int)$object); |
|
483 | + } |
|
484 | + if (!is_object($object) || !$object->getVar('topic_id')) { |
|
485 | + return false; |
|
486 | + } |
|
487 | + |
|
488 | + /** @var Newbb\PostHandler $postHandler */ |
|
489 | + $postHandler = Newbb\Helper::getInstance()->getHandler('Post'); |
|
490 | + $criteria = new \CriteriaCompo(); |
|
491 | + $criteria->add(new \Criteria('topic_id', $object->getVar('topic_id')), 'AND'); |
|
492 | + $criteria->add(new \Criteria('approved', 1), 'AND'); |
|
493 | + $post_ids = $postHandler->getIds($criteria); |
|
494 | + if (empty($post_ids)) { |
|
495 | + return false; |
|
496 | + } |
|
497 | + $last_post = max($post_ids); |
|
498 | + $top_post = min($post_ids); |
|
499 | + $topic_replies = count($post_ids) - 1; |
|
500 | + if ($object->getVar('topic_last_post_id') != $last_post) { |
|
501 | + $object->setVar('topic_last_post_id', $last_post); |
|
502 | + } |
|
503 | + if ($object->getVar('topic_replies') != $topic_replies) { |
|
504 | + $object->setVar('topic_replies', $topic_replies); |
|
505 | + } |
|
506 | + $b1 = $this->insert($object, $force); |
|
507 | + $criteria->add(new \Criteria('post_id', $top_post, '<>'), 'AND'); |
|
508 | + $criteria->add(new \Criteria('pid', '(' . implode(', ', $post_ids) . ')', 'NOT IN'), 'AND'); |
|
509 | + $b2 = $postHandler->updateAll('pid', $top_post, $criteria, $force); |
|
510 | + $criteria = new \CriteriaCompo(); |
|
511 | + $criteria->add(new \Criteria('post_id', $top_post, '='), 'AND'); |
|
512 | + $b3 = $postHandler->updateAll('pid', 0, $criteria, $force); |
|
513 | + |
|
514 | + return ($b1 && $b2 && $b3); |
|
515 | + } |
|
516 | + // END irmtfan - rewrite topic synchronization function. add pid sync and remove hard-code db access |
|
517 | + // START irmtfan getActivePolls |
|
518 | + /** |
|
519 | + * get all active poll modules in the current xoops installtion. |
|
520 | + * @access public |
|
521 | + * @return array $pollDirs = array($dirname1=>$dirname1, $dirname2=>$dirname2, ...) dirnames of all active poll modules |
|
522 | + */ |
|
523 | + public function getActivePolls() |
|
524 | + { |
|
525 | + $pollDirs = []; |
|
526 | + $allDirs = xoops_getActiveModules(); |
|
527 | + foreach ($allDirs as $dirname) { |
|
528 | + // pollresults.php file is exist in all xoopspoll versions and umfrage versions |
|
529 | + if (file_exists($GLOBALS['xoops']->path('modules/' . $dirname . '/pollresults.php'))) { |
|
530 | + $pollDirs[$dirname] = $dirname; |
|
531 | + } |
|
532 | + } |
|
533 | + |
|
534 | + return $pollDirs; |
|
535 | + } |
|
536 | + // END irmtfan getActivePolls |
|
537 | + |
|
538 | + // START irmtfan findPollModule |
|
539 | + /** |
|
540 | + * find poll module that is in used in the current newbb installtion. |
|
541 | + * @access public |
|
542 | + * @param array $pollDirs dirnames of all active poll modules |
|
543 | + * @return bool|string $dir_def | true | false |
|
544 | + * $dir_def: dirname of poll module that is in used in the current newbb installtion. |
|
545 | + * true: no poll module is installed | newbb has no topic with poll | newbb has no topic |
|
546 | + * false: errors (see below xoops_errors) |
|
547 | + */ |
|
548 | + public function findPollModule(array $pollDirs = []) |
|
549 | + { |
|
550 | + $dir_def = ''; |
|
551 | + if (empty($pollDirs)) { |
|
552 | + $pollDirs = $this->getActivePolls(); |
|
553 | + } |
|
554 | + if (empty($pollDirs)) { |
|
555 | + return true; |
|
556 | + } |
|
557 | + // if only one active poll module still we need to check!!! |
|
558 | + //if(count($pollDirs) === 1) return end($pollDirs); |
|
559 | + $topicPollObjs = $this->getAll(new \Criteria('topic_haspoll', 1), ['topic_id', 'poll_id']); |
|
560 | + if (empty($topicPollObjs)) { |
|
561 | + return true; |
|
562 | + } // no poll or no topic!!! |
|
563 | + foreach ($topicPollObjs as $tObj) { |
|
564 | + $poll_idInMod = 0; |
|
565 | + foreach ($pollDirs as $dirname) { |
|
566 | + $pollObj = $tObj->getPoll($tObj->getVar('poll_id'), $dirname); |
|
567 | + if (is_object($pollObj) && ($pollObj->getVar('poll_id') == $tObj->getVar('poll_id'))) { |
|
568 | + ++$poll_idInMod; |
|
569 | + $dir_def = $dirname; |
|
570 | + } |
|
571 | + } |
|
572 | + // Only one poll module should has this poll_id |
|
573 | + // if 0 there is an error |
|
574 | + if (0 == $poll_idInMod) { |
|
575 | + xoops_error("Error: Cannot find poll module for poll_id='{$tObj->getVar('poll_id')}'"); |
|
576 | + |
|
577 | + return false; |
|
578 | + } |
|
579 | + // if 1 => $dir_def is correct |
|
580 | + if (1 == $poll_idInMod) { |
|
581 | + return $dir_def; |
|
582 | + } |
|
583 | + // if more than 1 continue |
|
584 | + } |
|
585 | + // if there is some topics but no module or more than one module have polls |
|
586 | + xoops_error("Error: Cannot find poll module that is in used in newbb!!! <br\><br\>You should select the correct poll module yourself in newbb > preferences > poll module setting."); |
|
587 | + |
|
588 | + return false; |
|
589 | + } |
|
590 | + // END irmtfan findPollModule |
|
591 | 591 | } |
@@ -22,74 +22,74 @@ discard block |
||
22 | 22 | function newbb_calculateLevel($RPG, $RPGDIFF) |
23 | 23 | { |
24 | 24 | |
25 | - //$RPG = $user->getVar('posts'); |
|
26 | - //$RPGDIFF = $user->getVar('user_regdate'); |
|
27 | - |
|
28 | - $today = time(); |
|
29 | - $diff = $today - $RPGDIFF; |
|
30 | - $exp = round($diff / 86400, 0); |
|
31 | - if ($exp <= 0) { |
|
32 | - $exp = 1; |
|
33 | - } |
|
34 | - $ppd = round($RPG / $exp, 0); |
|
35 | - $level = log10($RPG) ** 3; |
|
36 | - $ep = floor(100 * ($level - floor($level))); |
|
37 | - $showlevel = floor($level + 1); |
|
38 | - $hpmulti = round($ppd / 6, 1); |
|
39 | - if ($hpmulti > 1.5) { |
|
40 | - $hpmulti = 1.5; |
|
41 | - } |
|
42 | - if ($hpmulti < 1) { |
|
43 | - $hpmulti = 1; |
|
44 | - } |
|
45 | - $maxhp = $level * 25 * $hpmulti; |
|
46 | - $hp = $ppd / 5; |
|
47 | - if ($hp >= 1) { |
|
48 | - $hp = $maxhp; |
|
49 | - } else { |
|
50 | - $hp = floor($hp * $maxhp); |
|
51 | - } |
|
52 | - $hp = floor($hp); |
|
53 | - $maxhp = floor($maxhp); |
|
54 | - $zhp = $maxhp; |
|
55 | - if ($maxhp <= 0) { |
|
56 | - $zhp = 1; |
|
57 | - } |
|
58 | - $hpf = floor(100 * ($hp / $zhp)) - 1; |
|
59 | - $maxmp = ($exp * $level) / 5; |
|
60 | - $mp = $RPG / 3; |
|
61 | - if ($mp >= $maxmp) { |
|
62 | - $mp = $maxmp; |
|
63 | - } |
|
64 | - $maxmp = floor($maxmp); |
|
65 | - $mp = floor($mp); |
|
66 | - $zmp = $maxmp; |
|
67 | - if ($maxmp <= 0) { |
|
68 | - $zmp = 1; |
|
69 | - } |
|
70 | - $mpf = floor(100 * ($mp / $zmp)) - 1; |
|
71 | - if ($hpf >= 98) { |
|
72 | - $hpf -= 2; |
|
73 | - } |
|
74 | - if ($ep >= 98) { |
|
75 | - $ep -= 2; |
|
76 | - } |
|
77 | - if ($mpf >= 98) { |
|
78 | - $mpf -= 2; |
|
79 | - } |
|
80 | - |
|
81 | - $level = []; |
|
82 | - $level['level'] = $showlevel; |
|
83 | - $level['exp'] = $ep; |
|
84 | - $level['exp_width'] = $ep . '%'; |
|
85 | - $level['hp'] = $hp; |
|
86 | - $level['hp_max'] = $maxhp; |
|
87 | - $level['hp_width'] = $hpf . '%'; |
|
88 | - $level['mp'] = $mp; |
|
89 | - $level['mp_max'] = $maxmp; |
|
90 | - $level['mp_width'] = $mpf . '%'; |
|
91 | - |
|
92 | - return $level; |
|
25 | + //$RPG = $user->getVar('posts'); |
|
26 | + //$RPGDIFF = $user->getVar('user_regdate'); |
|
27 | + |
|
28 | + $today = time(); |
|
29 | + $diff = $today - $RPGDIFF; |
|
30 | + $exp = round($diff / 86400, 0); |
|
31 | + if ($exp <= 0) { |
|
32 | + $exp = 1; |
|
33 | + } |
|
34 | + $ppd = round($RPG / $exp, 0); |
|
35 | + $level = log10($RPG) ** 3; |
|
36 | + $ep = floor(100 * ($level - floor($level))); |
|
37 | + $showlevel = floor($level + 1); |
|
38 | + $hpmulti = round($ppd / 6, 1); |
|
39 | + if ($hpmulti > 1.5) { |
|
40 | + $hpmulti = 1.5; |
|
41 | + } |
|
42 | + if ($hpmulti < 1) { |
|
43 | + $hpmulti = 1; |
|
44 | + } |
|
45 | + $maxhp = $level * 25 * $hpmulti; |
|
46 | + $hp = $ppd / 5; |
|
47 | + if ($hp >= 1) { |
|
48 | + $hp = $maxhp; |
|
49 | + } else { |
|
50 | + $hp = floor($hp * $maxhp); |
|
51 | + } |
|
52 | + $hp = floor($hp); |
|
53 | + $maxhp = floor($maxhp); |
|
54 | + $zhp = $maxhp; |
|
55 | + if ($maxhp <= 0) { |
|
56 | + $zhp = 1; |
|
57 | + } |
|
58 | + $hpf = floor(100 * ($hp / $zhp)) - 1; |
|
59 | + $maxmp = ($exp * $level) / 5; |
|
60 | + $mp = $RPG / 3; |
|
61 | + if ($mp >= $maxmp) { |
|
62 | + $mp = $maxmp; |
|
63 | + } |
|
64 | + $maxmp = floor($maxmp); |
|
65 | + $mp = floor($mp); |
|
66 | + $zmp = $maxmp; |
|
67 | + if ($maxmp <= 0) { |
|
68 | + $zmp = 1; |
|
69 | + } |
|
70 | + $mpf = floor(100 * ($mp / $zmp)) - 1; |
|
71 | + if ($hpf >= 98) { |
|
72 | + $hpf -= 2; |
|
73 | + } |
|
74 | + if ($ep >= 98) { |
|
75 | + $ep -= 2; |
|
76 | + } |
|
77 | + if ($mpf >= 98) { |
|
78 | + $mpf -= 2; |
|
79 | + } |
|
80 | + |
|
81 | + $level = []; |
|
82 | + $level['level'] = $showlevel; |
|
83 | + $level['exp'] = $ep; |
|
84 | + $level['exp_width'] = $ep . '%'; |
|
85 | + $level['hp'] = $hp; |
|
86 | + $level['hp_max'] = $maxhp; |
|
87 | + $level['hp_width'] = $hpf . '%'; |
|
88 | + $level['mp'] = $mp; |
|
89 | + $level['mp_max'] = $maxmp; |
|
90 | + $level['mp_width'] = $mpf . '%'; |
|
91 | + |
|
92 | + return $level; |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | /** |
@@ -97,179 +97,179 @@ discard block |
||
97 | 97 | */ |
98 | 98 | class User |
99 | 99 | { |
100 | - public $user; |
|
101 | - |
|
102 | - public function __construct() |
|
103 | - { |
|
104 | - } |
|
105 | - |
|
106 | - /** |
|
107 | - * @return array |
|
108 | - */ |
|
109 | - public function getUserbar() |
|
110 | - { |
|
111 | - global $isAdmin; |
|
112 | - |
|
113 | - $userbar = []; |
|
114 | - if (empty($GLOBALS['xoopsModuleConfig']['userbar_enabled'])) { |
|
115 | - return $userbar; |
|
116 | - } |
|
117 | - |
|
118 | - $user = $this->user; |
|
119 | - $userbar['profile'] = [ |
|
120 | - 'link' => XOOPS_URL . '/userinfo.php?uid=' . $user->getVar('uid'), |
|
121 | - 'name' => _PROFILE |
|
122 | - ]; |
|
123 | - |
|
124 | - if (is_object($GLOBALS['xoopsUser'])) { |
|
125 | - $userbar['pm'] = [ |
|
126 | - 'link' => "javascript:void openWithSelfMain('" . XOOPS_URL . '/pmlite.php?send2=1&to_userid=' . $user->getVar('uid') . "', 'pmlite', 450, 380);", |
|
127 | - 'name' => _MD_NEWBB_PM |
|
128 | - ]; |
|
129 | - } |
|
130 | - if ($user->getVar('user_viewemail') || $isAdmin) { |
|
131 | - $userbar['email'] = [ |
|
132 | - 'link' => "javascript:void window.open('mailto:" . $user->getVar('email') . "', 'new');", |
|
133 | - 'name' => _MD_NEWBB_EMAIL |
|
134 | - ]; |
|
135 | - } |
|
136 | - if ($url = $user->getVar('url')) { |
|
137 | - $userbar['url'] = [ |
|
138 | - 'link' => "javascript:void window.open('" . $url . "', 'new');", |
|
139 | - 'name' => _MD_NEWBB_WWW |
|
140 | - ]; |
|
141 | - } |
|
142 | - if ($icq = $user->getVar('user_icq')) { |
|
143 | - $userbar['icq'] = [ |
|
144 | - 'link' => "javascript:void window.open('http://wwp.icq.com/scripts/search.dll?to=" . $icq . "', 'new');", |
|
145 | - 'name' => _MD_NEWBB_ICQ |
|
146 | - ]; |
|
147 | - } |
|
148 | - if ($aim = $user->getVar('user_aim')) { |
|
149 | - $userbar['aim'] = [ |
|
150 | - 'link' => "javascript:void window.open('aim:goim?screenname=" . $aim . '&message=Hi+' . $aim . '+Are+you+there?' . "', 'new');", |
|
151 | - 'name' => _MD_NEWBB_AIM |
|
152 | - ]; |
|
153 | - } |
|
154 | - if ($yim = $user->getVar('user_yim')) { |
|
155 | - $userbar['yim'] = [ |
|
156 | - 'link' => "javascript:void window.open('http://edit.yahoo.com/config/send_webmesg?.target=" . $yim . '&.src=pg' . "', 'new');", |
|
157 | - 'name' => _MD_NEWBB_YIM |
|
158 | - ]; |
|
159 | - } |
|
160 | - if ($msn = $user->getVar('user_msnm')) { |
|
161 | - $userbar['msnm'] = [ |
|
162 | - 'link' => "javascript:void window.open('http://members.msn.com?mem=" . $msn . "', 'new');", |
|
163 | - 'name' => _MD_NEWBB_MSNM |
|
164 | - ]; |
|
165 | - } |
|
166 | - |
|
167 | - return $userbar; |
|
168 | - } |
|
169 | - |
|
170 | - /** |
|
171 | - * @return string |
|
172 | - */ |
|
173 | - public function getLevel() |
|
174 | - { |
|
175 | - global $forumUrl; |
|
176 | - |
|
177 | - $level = newbb_calculateLevel($this->user->getVar('posts'), $this->user->getVar('user_regdate')); |
|
178 | - $info = ''; |
|
179 | - if (2 == $GLOBALS['xoopsModuleConfig']['user_level']) { |
|
180 | - static $rpg_images; |
|
181 | - if (null === $rpg_images) { |
|
182 | - $iconHandler = newbbGetIconHandler(); |
|
183 | - $rpg_path = $iconHandler->getPath('rpg'); |
|
184 | - foreach (['img_left', 'img_backing', 'img_right', 'blue', 'green', 'orange'] as $img) { |
|
185 | - // irmtfan fix: double "/" removed |
|
186 | - $rpg_images[$img] = XOOPS_URL . $rpg_path . '/' . $img . '.gif'; |
|
187 | - } |
|
188 | - } |
|
189 | - // irmtfan hardcore removed align="left" |
|
190 | - $table = "<table class='userlevel'><tr><td class='end'><img src='" |
|
191 | - . $rpg_images['img_left'] |
|
192 | - . "' alt='' /></td><td class='center' background='" |
|
193 | - . $rpg_images['img_backing'] |
|
194 | - . "'><img src='%s' width='%d' alt='' class='icon_left' /></td><td><img src='" |
|
195 | - . $rpg_images['img_right'] |
|
196 | - . "' alt='' /></td></tr></table>"; |
|
197 | - |
|
198 | - $info = _MD_NEWBB_LEVEL . ' ' . $level['level'] . '<br><span title="' . _MD_NEWBB_HP_DESC . '">' . _MD_NEWBB_HP . ' ' . $level['hp'] . ' / ' . $level['hp_max'] . '</span><br>' . sprintf($table, $rpg_images['orange'], $level['hp_width']); |
|
199 | - $info .= '<span title="' . _MD_NEWBB_MP_DESC . '">' . _MD_NEWBB_MP . ' ' . $level['mp'] . ' / ' . $level['mp_max'] . '</span><br>' . sprintf($table, $rpg_images['green'], $level['mp_width']); |
|
200 | - $info .= '<span title="' . _MD_NEWBB_EXP_DESC . '">' . _MD_NEWBB_EXP . ' ' . $level['exp'] . '</span><br>' . sprintf($table, $rpg_images['blue'], $level['exp_width']); |
|
201 | - } else { |
|
202 | - $info = _MD_NEWBB_LEVEL . ' ' . $level['level'] . '; <span title="' . _MD_NEWBB_EXP_DESC . '">' . _MD_NEWBB_EXP . ' ' . $level['exp'] . '</span><br>'; |
|
203 | - $info .= '<span title="' . _MD_NEWBB_HP_DESC . '">' . _MD_NEWBB_HP . ' ' . $level['hp'] . ' / ' . $level['hp_max'] . '</span><br>'; |
|
204 | - $info .= '<span title="' . _MD_NEWBB_MP_DESC . '">' . _MD_NEWBB_MP . ' ' . $level['mp'] . ' / ' . $level['mp_max'] . '</span>'; |
|
205 | - } |
|
206 | - |
|
207 | - return $info; |
|
208 | - } |
|
209 | - |
|
210 | - /** |
|
211 | - * @param \XoopsUser $user |
|
212 | - * @return mixed |
|
213 | - */ |
|
214 | - public function getInfo(&$user) |
|
215 | - { |
|
216 | - global $myts; |
|
217 | - static $name_anonymous; |
|
218 | - |
|
219 | - if (!is_object($user) || !$user->isActive()) { |
|
220 | - if (null === $name_anonymous) { |
|
221 | - $name_anonymous = $myts->htmlSpecialChars($GLOBALS['xoopsConfig']['anonymous']); |
|
222 | - } |
|
223 | - |
|
224 | - return ['name' => $name_anonymous, 'link' => $name_anonymous]; |
|
225 | - } |
|
226 | - |
|
227 | - $this->user = $user; |
|
228 | - |
|
229 | - $userinfo['uid'] = $user->getVar('uid'); |
|
230 | - |
|
231 | - $name = empty($GLOBALS['xoopsModuleConfig']['show_realname']) ? $user->getVar('uname') : $user->getVar('name'); |
|
232 | - $userinfo['name'] = $name ?: $user->getVar('uname'); |
|
233 | - |
|
234 | - $userinfo['link'] = '<a href=\'' . XOOPS_URL . '/userinfo.php?uid=' . $user->getVar('uid') . '\'>' . $userinfo['name'] . '</a>'; |
|
235 | - |
|
236 | - $userinfo['avatar'] = $user->getVar('user_avatar'); |
|
237 | - // START hacked by irmtfan - easier rank getting - consistency with previous version back rank.title and rank.image |
|
238 | - $userrank = $user->rank(); |
|
239 | - $userinfo['rank'] = []; |
|
240 | - if (isset($userrank['image']) && $userrank['image']) { |
|
241 | - $userinfo['rank']['image'] = $userrank['image']; |
|
242 | - $userinfo['rank']['title'] = $userrank['title']; |
|
243 | - } |
|
244 | - // END hacked by irmtfan - easier rank getting - a little correctness dot removed |
|
245 | - // START hacked by irmtfan - easier groups getting - can we use $_SESSION['xoopsUserGroups']??? |
|
246 | - //checks for user's groups |
|
247 | - $userinfo['groups'] = []; |
|
248 | - /** @var \XoopsMemberHandler $memberHandler */ |
|
249 | - $memberHandler = xoops_getHandler('member'); |
|
250 | - $usergroups = $memberHandler->getGroupsByUser($userinfo['uid'], true); |
|
251 | - foreach ($usergroups as $group) { |
|
252 | - $userinfo['groups'][] = $group->getVar('name'); |
|
253 | - } |
|
254 | - // END hacked by irmtfan - easier groups getting - can we use $_SESSION['xoopsUserGroups']??? |
|
255 | - $userinfo['from'] = $user->getVar('user_from'); |
|
256 | - |
|
257 | - require_once dirname(__DIR__) . '/include/functions.time.php'; |
|
258 | - $userinfo['regdate'] = newbbFormatTimestamp($user->getVar('user_regdate'), 'reg'); |
|
259 | - $userinfo['last_login'] = newbbFormatTimestamp($user->getVar('last_login')); // irmtfan add last_login |
|
260 | - |
|
261 | - $userinfo['posts'] = $user->getVar('posts'); |
|
262 | - |
|
263 | - if (!empty($GLOBALS['xoopsModuleConfig']['user_level'])) { |
|
264 | - $userinfo['level'] = $this->getLevel(); |
|
265 | - } |
|
266 | - |
|
267 | - if (!empty($GLOBALS['xoopsModuleConfig']['userbar_enabled'])) { |
|
268 | - $userinfo['userbar'] = $this->getUserbar(); |
|
269 | - } |
|
270 | - |
|
271 | - $userinfo['signature'] = $user->getVar('user_sig'); |
|
272 | - |
|
273 | - return $userinfo; |
|
274 | - } |
|
100 | + public $user; |
|
101 | + |
|
102 | + public function __construct() |
|
103 | + { |
|
104 | + } |
|
105 | + |
|
106 | + /** |
|
107 | + * @return array |
|
108 | + */ |
|
109 | + public function getUserbar() |
|
110 | + { |
|
111 | + global $isAdmin; |
|
112 | + |
|
113 | + $userbar = []; |
|
114 | + if (empty($GLOBALS['xoopsModuleConfig']['userbar_enabled'])) { |
|
115 | + return $userbar; |
|
116 | + } |
|
117 | + |
|
118 | + $user = $this->user; |
|
119 | + $userbar['profile'] = [ |
|
120 | + 'link' => XOOPS_URL . '/userinfo.php?uid=' . $user->getVar('uid'), |
|
121 | + 'name' => _PROFILE |
|
122 | + ]; |
|
123 | + |
|
124 | + if (is_object($GLOBALS['xoopsUser'])) { |
|
125 | + $userbar['pm'] = [ |
|
126 | + 'link' => "javascript:void openWithSelfMain('" . XOOPS_URL . '/pmlite.php?send2=1&to_userid=' . $user->getVar('uid') . "', 'pmlite', 450, 380);", |
|
127 | + 'name' => _MD_NEWBB_PM |
|
128 | + ]; |
|
129 | + } |
|
130 | + if ($user->getVar('user_viewemail') || $isAdmin) { |
|
131 | + $userbar['email'] = [ |
|
132 | + 'link' => "javascript:void window.open('mailto:" . $user->getVar('email') . "', 'new');", |
|
133 | + 'name' => _MD_NEWBB_EMAIL |
|
134 | + ]; |
|
135 | + } |
|
136 | + if ($url = $user->getVar('url')) { |
|
137 | + $userbar['url'] = [ |
|
138 | + 'link' => "javascript:void window.open('" . $url . "', 'new');", |
|
139 | + 'name' => _MD_NEWBB_WWW |
|
140 | + ]; |
|
141 | + } |
|
142 | + if ($icq = $user->getVar('user_icq')) { |
|
143 | + $userbar['icq'] = [ |
|
144 | + 'link' => "javascript:void window.open('http://wwp.icq.com/scripts/search.dll?to=" . $icq . "', 'new');", |
|
145 | + 'name' => _MD_NEWBB_ICQ |
|
146 | + ]; |
|
147 | + } |
|
148 | + if ($aim = $user->getVar('user_aim')) { |
|
149 | + $userbar['aim'] = [ |
|
150 | + 'link' => "javascript:void window.open('aim:goim?screenname=" . $aim . '&message=Hi+' . $aim . '+Are+you+there?' . "', 'new');", |
|
151 | + 'name' => _MD_NEWBB_AIM |
|
152 | + ]; |
|
153 | + } |
|
154 | + if ($yim = $user->getVar('user_yim')) { |
|
155 | + $userbar['yim'] = [ |
|
156 | + 'link' => "javascript:void window.open('http://edit.yahoo.com/config/send_webmesg?.target=" . $yim . '&.src=pg' . "', 'new');", |
|
157 | + 'name' => _MD_NEWBB_YIM |
|
158 | + ]; |
|
159 | + } |
|
160 | + if ($msn = $user->getVar('user_msnm')) { |
|
161 | + $userbar['msnm'] = [ |
|
162 | + 'link' => "javascript:void window.open('http://members.msn.com?mem=" . $msn . "', 'new');", |
|
163 | + 'name' => _MD_NEWBB_MSNM |
|
164 | + ]; |
|
165 | + } |
|
166 | + |
|
167 | + return $userbar; |
|
168 | + } |
|
169 | + |
|
170 | + /** |
|
171 | + * @return string |
|
172 | + */ |
|
173 | + public function getLevel() |
|
174 | + { |
|
175 | + global $forumUrl; |
|
176 | + |
|
177 | + $level = newbb_calculateLevel($this->user->getVar('posts'), $this->user->getVar('user_regdate')); |
|
178 | + $info = ''; |
|
179 | + if (2 == $GLOBALS['xoopsModuleConfig']['user_level']) { |
|
180 | + static $rpg_images; |
|
181 | + if (null === $rpg_images) { |
|
182 | + $iconHandler = newbbGetIconHandler(); |
|
183 | + $rpg_path = $iconHandler->getPath('rpg'); |
|
184 | + foreach (['img_left', 'img_backing', 'img_right', 'blue', 'green', 'orange'] as $img) { |
|
185 | + // irmtfan fix: double "/" removed |
|
186 | + $rpg_images[$img] = XOOPS_URL . $rpg_path . '/' . $img . '.gif'; |
|
187 | + } |
|
188 | + } |
|
189 | + // irmtfan hardcore removed align="left" |
|
190 | + $table = "<table class='userlevel'><tr><td class='end'><img src='" |
|
191 | + . $rpg_images['img_left'] |
|
192 | + . "' alt='' /></td><td class='center' background='" |
|
193 | + . $rpg_images['img_backing'] |
|
194 | + . "'><img src='%s' width='%d' alt='' class='icon_left' /></td><td><img src='" |
|
195 | + . $rpg_images['img_right'] |
|
196 | + . "' alt='' /></td></tr></table>"; |
|
197 | + |
|
198 | + $info = _MD_NEWBB_LEVEL . ' ' . $level['level'] . '<br><span title="' . _MD_NEWBB_HP_DESC . '">' . _MD_NEWBB_HP . ' ' . $level['hp'] . ' / ' . $level['hp_max'] . '</span><br>' . sprintf($table, $rpg_images['orange'], $level['hp_width']); |
|
199 | + $info .= '<span title="' . _MD_NEWBB_MP_DESC . '">' . _MD_NEWBB_MP . ' ' . $level['mp'] . ' / ' . $level['mp_max'] . '</span><br>' . sprintf($table, $rpg_images['green'], $level['mp_width']); |
|
200 | + $info .= '<span title="' . _MD_NEWBB_EXP_DESC . '">' . _MD_NEWBB_EXP . ' ' . $level['exp'] . '</span><br>' . sprintf($table, $rpg_images['blue'], $level['exp_width']); |
|
201 | + } else { |
|
202 | + $info = _MD_NEWBB_LEVEL . ' ' . $level['level'] . '; <span title="' . _MD_NEWBB_EXP_DESC . '">' . _MD_NEWBB_EXP . ' ' . $level['exp'] . '</span><br>'; |
|
203 | + $info .= '<span title="' . _MD_NEWBB_HP_DESC . '">' . _MD_NEWBB_HP . ' ' . $level['hp'] . ' / ' . $level['hp_max'] . '</span><br>'; |
|
204 | + $info .= '<span title="' . _MD_NEWBB_MP_DESC . '">' . _MD_NEWBB_MP . ' ' . $level['mp'] . ' / ' . $level['mp_max'] . '</span>'; |
|
205 | + } |
|
206 | + |
|
207 | + return $info; |
|
208 | + } |
|
209 | + |
|
210 | + /** |
|
211 | + * @param \XoopsUser $user |
|
212 | + * @return mixed |
|
213 | + */ |
|
214 | + public function getInfo(&$user) |
|
215 | + { |
|
216 | + global $myts; |
|
217 | + static $name_anonymous; |
|
218 | + |
|
219 | + if (!is_object($user) || !$user->isActive()) { |
|
220 | + if (null === $name_anonymous) { |
|
221 | + $name_anonymous = $myts->htmlSpecialChars($GLOBALS['xoopsConfig']['anonymous']); |
|
222 | + } |
|
223 | + |
|
224 | + return ['name' => $name_anonymous, 'link' => $name_anonymous]; |
|
225 | + } |
|
226 | + |
|
227 | + $this->user = $user; |
|
228 | + |
|
229 | + $userinfo['uid'] = $user->getVar('uid'); |
|
230 | + |
|
231 | + $name = empty($GLOBALS['xoopsModuleConfig']['show_realname']) ? $user->getVar('uname') : $user->getVar('name'); |
|
232 | + $userinfo['name'] = $name ?: $user->getVar('uname'); |
|
233 | + |
|
234 | + $userinfo['link'] = '<a href=\'' . XOOPS_URL . '/userinfo.php?uid=' . $user->getVar('uid') . '\'>' . $userinfo['name'] . '</a>'; |
|
235 | + |
|
236 | + $userinfo['avatar'] = $user->getVar('user_avatar'); |
|
237 | + // START hacked by irmtfan - easier rank getting - consistency with previous version back rank.title and rank.image |
|
238 | + $userrank = $user->rank(); |
|
239 | + $userinfo['rank'] = []; |
|
240 | + if (isset($userrank['image']) && $userrank['image']) { |
|
241 | + $userinfo['rank']['image'] = $userrank['image']; |
|
242 | + $userinfo['rank']['title'] = $userrank['title']; |
|
243 | + } |
|
244 | + // END hacked by irmtfan - easier rank getting - a little correctness dot removed |
|
245 | + // START hacked by irmtfan - easier groups getting - can we use $_SESSION['xoopsUserGroups']??? |
|
246 | + //checks for user's groups |
|
247 | + $userinfo['groups'] = []; |
|
248 | + /** @var \XoopsMemberHandler $memberHandler */ |
|
249 | + $memberHandler = xoops_getHandler('member'); |
|
250 | + $usergroups = $memberHandler->getGroupsByUser($userinfo['uid'], true); |
|
251 | + foreach ($usergroups as $group) { |
|
252 | + $userinfo['groups'][] = $group->getVar('name'); |
|
253 | + } |
|
254 | + // END hacked by irmtfan - easier groups getting - can we use $_SESSION['xoopsUserGroups']??? |
|
255 | + $userinfo['from'] = $user->getVar('user_from'); |
|
256 | + |
|
257 | + require_once dirname(__DIR__) . '/include/functions.time.php'; |
|
258 | + $userinfo['regdate'] = newbbFormatTimestamp($user->getVar('user_regdate'), 'reg'); |
|
259 | + $userinfo['last_login'] = newbbFormatTimestamp($user->getVar('last_login')); // irmtfan add last_login |
|
260 | + |
|
261 | + $userinfo['posts'] = $user->getVar('posts'); |
|
262 | + |
|
263 | + if (!empty($GLOBALS['xoopsModuleConfig']['user_level'])) { |
|
264 | + $userinfo['level'] = $this->getLevel(); |
|
265 | + } |
|
266 | + |
|
267 | + if (!empty($GLOBALS['xoopsModuleConfig']['userbar_enabled'])) { |
|
268 | + $userinfo['userbar'] = $this->getUserbar(); |
|
269 | + } |
|
270 | + |
|
271 | + $userinfo['signature'] = $user->getVar('user_sig'); |
|
272 | + |
|
273 | + return $userinfo; |
|
274 | + } |
|
275 | 275 | } |
@@ -17,37 +17,37 @@ |
||
17 | 17 | define('NEWBB_FUNCTIONS_CONFIG_LOADED', true); |
18 | 18 | |
19 | 19 | if (!defined('NEWBB_FUNCTIONS_CONFIG')) { |
20 | - define('NEWBB_FUNCTIONS_CONFIG', 1); |
|
21 | - |
|
22 | - /** |
|
23 | - * @return array |
|
24 | - * @internal param string $category |
|
25 | - * @internal param string $dirname |
|
26 | - */ |
|
27 | - function newbbLoadConfig() |
|
28 | - { |
|
20 | + define('NEWBB_FUNCTIONS_CONFIG', 1); |
|
21 | + |
|
22 | + /** |
|
23 | + * @return array |
|
24 | + * @internal param string $category |
|
25 | + * @internal param string $dirname |
|
26 | + */ |
|
27 | + function newbbLoadConfig() |
|
28 | + { |
|
29 | 29 | // require_once dirname(__DIR__) . '/class/Helper.php'; |
30 | - //$helper = NewBB::getInstance(); |
|
31 | - /** @var \XoopsModules\Newbb\Helper $helper */ |
|
32 | - $helper = \XoopsModules\Newbb\Helper::getInstance(); |
|
33 | - static $configs = null; |
|
34 | - |
|
35 | - if (null !== $configs) { |
|
36 | - return $configs; |
|
37 | - } |
|
38 | - |
|
39 | - $configs = is_object($helper) ? $helper->getConfig() : []; |
|
40 | - $plugins = require __DIR__ . '/plugin.php'; |
|
41 | - if (is_array($configs) && is_array($plugins)) { |
|
42 | - $configs = array_merge($configs, $plugins); |
|
43 | - } |
|
44 | - if (!isset($GLOBALS['xoopsModuleConfig'])) { |
|
45 | - $GLOBALS['xoopsModuleConfig'] = []; |
|
46 | - } |
|
47 | - if (is_array($configs)) { |
|
48 | - $GLOBALS['xoopsModuleConfig'] = array_merge($GLOBALS['xoopsModuleConfig'], $configs); |
|
49 | - } |
|
50 | - |
|
51 | - return $configs; |
|
52 | - } |
|
30 | + //$helper = NewBB::getInstance(); |
|
31 | + /** @var \XoopsModules\Newbb\Helper $helper */ |
|
32 | + $helper = \XoopsModules\Newbb\Helper::getInstance(); |
|
33 | + static $configs = null; |
|
34 | + |
|
35 | + if (null !== $configs) { |
|
36 | + return $configs; |
|
37 | + } |
|
38 | + |
|
39 | + $configs = is_object($helper) ? $helper->getConfig() : []; |
|
40 | + $plugins = require __DIR__ . '/plugin.php'; |
|
41 | + if (is_array($configs) && is_array($plugins)) { |
|
42 | + $configs = array_merge($configs, $plugins); |
|
43 | + } |
|
44 | + if (!isset($GLOBALS['xoopsModuleConfig'])) { |
|
45 | + $GLOBALS['xoopsModuleConfig'] = []; |
|
46 | + } |
|
47 | + if (is_array($configs)) { |
|
48 | + $GLOBALS['xoopsModuleConfig'] = array_merge($GLOBALS['xoopsModuleConfig'], $configs); |
|
49 | + } |
|
50 | + |
|
51 | + return $configs; |
|
52 | + } |
|
53 | 53 | } |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | |
14 | 14 | use XoopsModules\Newbb; |
15 | 15 | |
16 | -defined('NEWBB_FUNCTIONS_INI') || require __DIR__ . '/functions.ini.php'; |
|
16 | +defined('NEWBB_FUNCTIONS_INI') || require __DIR__.'/functions.ini.php'; |
|
17 | 17 | define('NEWBB_FUNCTIONS_CONFIG_LOADED', true); |
18 | 18 | |
19 | 19 | if (!defined('NEWBB_FUNCTIONS_CONFIG')) { |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | } |
38 | 38 | |
39 | 39 | $configs = is_object($helper) ? $helper->getConfig() : []; |
40 | - $plugins = require __DIR__ . '/plugin.php'; |
|
40 | + $plugins = require __DIR__.'/plugin.php'; |
|
41 | 41 | if (is_array($configs) && is_array($plugins)) { |
42 | 42 | $configs = array_merge($configs, $plugins); |
43 | 43 | } |