mambax7 /
newbb5
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * NewBB 5.0x, the forum module for XOOPS project |
||
| 4 | * |
||
| 5 | * @copyright XOOPS Project (https://xoops.org) |
||
| 6 | * @license GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html) |
||
| 7 | * @author Taiwen Jiang (phppp or D.J.) <[email protected]> |
||
| 8 | * @since 4.00 |
||
| 9 | * @package module::newbb |
||
| 10 | */ |
||
| 11 | |||
| 12 | use Xmf\Request; |
||
| 13 | |||
| 14 | include_once __DIR__ . '/header.php'; |
||
| 15 | |||
| 16 | /* deal with marks */ |
||
| 17 | if (Request::getInt('mark_read', 0)) { |
||
| 18 | View Code Duplication | if (1 === Request::getInt('mark_read', 0)) { // marked as read |
|
| 19 | $markvalue = 1; |
||
| 20 | $markresult = _MD_NEWBB_MARK_READ; |
||
| 21 | } else { // marked as unread |
||
| 22 | $markvalue = 0; |
||
| 23 | $markresult = _MD_NEWBB_MARK_UNREAD; |
||
| 24 | } |
||
| 25 | include_once __DIR__ . '/include/functions.read.php'; |
||
| 26 | newbbSetReadForum($markvalue); |
||
| 27 | $url = XOOPS_URL . '/modules/newbb/index.php'; |
||
| 28 | redirect_header($url, 2, _MD_NEWBB_ALL_FORUM_MARKED . ' ' . $markresult); |
||
| 29 | } |
||
| 30 | |||
| 31 | $viewcat = Request::getInt('cat', 0, 'GET');//TODO mb check if this is GET or POST? |
||
| 32 | /** @var \NewbbCategoryHandler $categoryHandler */ |
||
| 33 | $categoryHandler = xoops_getModuleHandler('category', 'newbb'); |
||
| 34 | |||
| 35 | $categories = []; |
||
| 36 | if (!$viewcat) { |
||
| 37 | $categories = $categoryHandler->getByPermission('access', null, false); |
||
| 38 | $forum_index_title = ''; |
||
| 39 | $xoops_pagetitle = $xoopsModule->getVar('name'); |
||
| 40 | } else { |
||
| 41 | $categoryObject = $categoryHandler->get($viewcat); |
||
| 42 | if ($categoryHandler->getPermission($categoryObject)) { |
||
| 43 | $categories[$viewcat] = $categoryObject->getValues(); |
||
| 44 | } |
||
| 45 | $forum_index_title = sprintf(_MD_NEWBB_FORUMINDEX, htmlspecialchars($GLOBALS['xoopsConfig']['sitename'], ENT_QUOTES)); |
||
| 46 | $xoops_pagetitle = $categoryObject->getVar('cat_title') . ' [' . $xoopsModule->getVar('name') . ']'; |
||
| 47 | } |
||
| 48 | |||
| 49 | if (0 === count($categories)) { |
||
| 50 | redirect_header(XOOPS_URL, 2, _MD_NEWBB_NORIGHTTOACCESS); |
||
| 51 | } |
||
| 52 | |||
| 53 | $xoopsOption['template_main'] = 'newbb_index.tpl'; |
||
| 54 | $xoopsOption['xoops_pagetitle'] = $xoops_pagetitle; |
||
| 55 | // irmtfan remove and move to footer.php |
||
| 56 | //$xoopsOption['xoops_module_header'] = $xoops_module_header; |
||
| 57 | // irmtfan include header.php after defining $xoopsOption['template_main'] |
||
| 58 | include_once $GLOBALS['xoops']->path('header.php'); |
||
| 59 | include_once __DIR__ . '/include/functions.render.php'; |
||
| 60 | /* rss feed */ |
||
| 61 | // irmtfan new method |
||
| 62 | View Code Duplication | if (!empty($GLOBALS['xoopsModuleConfig']['rss_enable'])) { |
|
| 63 | $xoopsTpl->assign('xoops_module_header', ' |
||
| 64 | <link rel="alternate" type="application/xml+rss" title="' . $xoopsModule->getVar('name') . '" href="' . XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname', 'n') . '/rss.php" /> |
||
| 65 | ' . @$xoopsTpl->get_template_vars('xoops_module_header')); |
||
| 66 | } |
||
| 67 | $xoopsTpl->assign('xoops_pagetitle', $xoops_pagetitle); |
||
| 68 | // irmtfan remove and move to footer.php |
||
| 69 | //$xoopsTpl->assign('xoops_module_header', $xoops_module_header); |
||
| 70 | $xoopsTpl->assign('forum_index_title', $forum_index_title); |
||
| 71 | //if ($GLOBALS['xoopsModuleConfig']['wol_enabled']) { |
||
| 72 | View Code Duplication | if (!empty($GLOBALS['xoopsModuleConfig']['wol_enabled'])) { |
|
|
0 ignored issues
–
show
|
|||
| 73 | /** @var \NewbbOnlineHandler $onlineHandler */ |
||
| 74 | $onlineHandler = xoops_getModuleHandler('online', 'newbb'); |
||
| 75 | $onlineHandler->init(); |
||
| 76 | $xoopsTpl->assign('online', $onlineHandler->showOnline()); |
||
| 77 | } |
||
| 78 | /** @var \NewbbForumHandler $forumHandler */ |
||
| 79 | $forumHandler = xoops_getModuleHandler('forum', 'newbb'); |
||
| 80 | /** @var \NewbbPostHandler $postHandler */ |
||
| 81 | $postHandler = xoops_getModuleHandler('post', 'newbb'); |
||
| 82 | |||
| 83 | /* Allowed forums */ |
||
| 84 | $forums_allowed = $forumHandler->getIdsByPermission(); |
||
| 85 | |||
| 86 | /* fetch top forums */ |
||
| 87 | $forums_top = []; |
||
| 88 | |||
| 89 | if (!empty($forums_allowed)) { |
||
| 90 | $crit_top = new CriteriaCompo(new Criteria('parent_forum', 0)); |
||
| 91 | $crit_top->add(new Criteria('cat_id', '(' . implode(', ', array_keys($categories)) . ')', 'IN')); |
||
| 92 | $crit_top->add(new Criteria('forum_id', '(' . implode(', ', $forums_allowed) . ')', 'IN')); |
||
| 93 | $forums_top = $forumHandler->getIds($crit_top); |
||
| 94 | } |
||
| 95 | |||
| 96 | /* fetch subforums if required to display */ |
||
| 97 | if ('hidden' === $GLOBALS['xoopsModuleConfig']['subforum_display'] || 0 === count($forums_top)) { |
||
| 98 | $forums_sub = []; |
||
| 99 | } else { |
||
| 100 | $crit_sub = new CriteriaCompo(new Criteria('parent_forum', '(' . implode(', ', $forums_top) . ')', 'IN')); |
||
| 101 | $crit_sub->add(new Criteria('forum_id', '(' . implode(', ', $forums_allowed) . ')', 'IN')); |
||
| 102 | $forums_sub = $forumHandler->getIds($crit_sub); |
||
| 103 | } |
||
| 104 | |||
| 105 | /* Fetch forum data */ |
||
| 106 | $forums_available = array_merge($forums_top, $forums_sub); |
||
| 107 | $forums_array = []; |
||
| 108 | $newtopics = 0; |
||
| 109 | $deletetopics = 0; |
||
| 110 | $newposts = 0; |
||
| 111 | $deleteposts = 0; |
||
| 112 | if (0 !== count($forums_available)) { |
||
| 113 | $crit_forum = new Criteria('forum_id', '(' . implode(', ', $forums_available) . ')', 'IN'); |
||
| 114 | $crit_forum->setSort('cat_id ASC, parent_forum ASC, forum_order'); |
||
| 115 | $crit_forum->setOrder('ASC'); |
||
| 116 | $forums = $forumHandler->getAll($crit_forum, null, false); |
||
| 117 | $newtopics = $forumHandler->getTopicCount($forums, 0, 'pending'); |
||
| 118 | $deletetopics = $forumHandler->getTopicCount($forums, 0, 'deleted'); |
||
| 119 | $forums_array = $forumHandler->display($forums, $GLOBALS['xoopsModuleConfig']['length_title_index'], $GLOBALS['xoopsModuleConfig']['count_subforum']); |
||
| 120 | $crit = new CriteriaCompo(new Criteria('forum_id', '(' . implode(', ', $forums_available) . ')', 'IN')); |
||
| 121 | $crit->add(new Criteria('approved', '-1')); |
||
| 122 | $deleteposts = $postHandler->getCount($crit); |
||
| 123 | $crit = new CriteriaCompo(new Criteria('forum_id', '(' . implode(', ', $forums_available) . ')', 'IN')); |
||
| 124 | $crit->add(new Criteria('approved', '0')); |
||
| 125 | $newposts = $postHandler->getCount($crit); |
||
| 126 | } |
||
| 127 | |||
| 128 | if ($newtopics > 0) { |
||
| 129 | $xoopsTpl->assign('wait_new_topic', $newtopics); |
||
| 130 | } |
||
| 131 | if ($deletetopics > 0) { |
||
| 132 | $xoopsTpl->assign('delete_topic', $deletetopics); |
||
| 133 | } |
||
| 134 | if ($newposts > 0) { |
||
| 135 | $xoopsTpl->assign('wait_new_post', $newposts); |
||
| 136 | } |
||
| 137 | if ($deleteposts > 0) { |
||
| 138 | $xoopsTpl->assign('delete_post', $deleteposts); |
||
| 139 | } |
||
| 140 | |||
| 141 | /** @var \NewbbReportHandler $reportHandler */ |
||
| 142 | $reportHandler = xoops_getModuleHandler('report', 'newbb'); |
||
| 143 | $reported = $reportHandler->getCount(new Criteria('report_result', 0)); |
||
| 144 | $xoopsTpl->assign('reported_count', $reported); |
||
| 145 | if ($reported > 0) { |
||
| 146 | $xoopsTpl->assign('report_post', sprintf(_MD_NEWBB_SEEWAITREPORT, $reported)); |
||
| 147 | } |
||
| 148 | |||
| 149 | if (count($forums_array) > 0) { |
||
| 150 | foreach ($forums_array[0] as $parent => $forum) { |
||
| 151 | if (isset($forums_array[$forum['forum_id']])) { |
||
| 152 | $forum['subforum'] = $forums_array[$forum['forum_id']]; |
||
| 153 | } |
||
| 154 | $forumsByCat[$forum['forum_cid']][] = $forum; |
||
| 155 | } |
||
| 156 | } |
||
| 157 | |||
| 158 | $category_array = []; |
||
| 159 | $toggles = newbbGetCookie('G', true); |
||
| 160 | $iconHandler = newbbGetIconHandler(); |
||
| 161 | $category_icon = [ |
||
| 162 | 'expand' => $iconHandler->getImageSource('minus'), |
||
| 163 | 'collapse' => $iconHandler->getImageSource('plus') |
||
| 164 | ]; |
||
| 165 | |||
| 166 | foreach (array_keys($categories) as $id) { |
||
| 167 | $forums = []; |
||
| 168 | $onecat = $categories[$id]; |
||
| 169 | |||
| 170 | $cat_element_id = 'cat_' . $onecat['cat_id']; |
||
| 171 | $expand = (count($toggles) > 0) ? (in_array($cat_element_id, $toggles) ? false : true) : true; |
||
| 172 | // START irmtfan to improve newbbDisplayImage |
||
| 173 | if ($expand) { |
||
| 174 | $cat_display = 'block'; //irmtfan move semicolon |
||
| 175 | $cat_icon_display = 'minus'; |
||
| 176 | $cat_alt = _MD_NEWBB_HIDE; |
||
| 177 | } else { |
||
| 178 | $cat_display = 'none'; //irmtfan move semicolon |
||
| 179 | $cat_icon_display = 'plus'; |
||
| 180 | $cat_alt = _MD_NEWBB_SEE; |
||
| 181 | } |
||
| 182 | $cat_displayImage = newbbDisplayImage($cat_icon_display, $cat_alt); |
||
| 183 | |||
| 184 | if (isset($forumsByCat[$onecat['cat_id']])) { |
||
| 185 | $forums = $forumsByCat[$onecat['cat_id']]; |
||
| 186 | } |
||
| 187 | |||
| 188 | $cat_sponsor = []; |
||
| 189 | @list($url, $title) = array_map('trim', preg_split('/ /', $onecat['cat_url'], 2)); |
||
| 190 | if ('' === $title) { |
||
| 191 | $title = $url; |
||
| 192 | } |
||
| 193 | $title = $myts->htmlSpecialChars($title); |
||
| 194 | if ('' !== $url) { |
||
| 195 | $cat_sponsor = ['title' => $title, 'link' => formatURL($url)]; |
||
| 196 | } |
||
| 197 | //$cat_image = $onecat['cat_image']; |
||
| 198 | $cat_image = ''; |
||
| 199 | $cat_image = $onecat['cat_image']; |
||
| 200 | if ('' !== $cat_image && 'blank.gif' !== $cat_image && $cat_image) { |
||
| 201 | $cat_image = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname', 'n') . '/assets/images/category/' . $cat_image; |
||
| 202 | } |
||
| 203 | $category_array[] = [ |
||
| 204 | 'cat_id' => $onecat['cat_id'], |
||
| 205 | 'cat_title' => $myts->displayTarea($onecat['cat_title'], 1), |
||
| 206 | 'cat_image' => $cat_image, |
||
| 207 | 'cat_sponsor' => $cat_sponsor, |
||
| 208 | 'cat_description' => $myts->displayTarea($onecat['cat_description'], 1), |
||
| 209 | 'cat_element_id' => $cat_element_id, |
||
| 210 | 'cat_display' => $cat_display, |
||
| 211 | 'cat_displayImage' => $cat_displayImage, |
||
| 212 | 'forums' => $forums |
||
| 213 | ]; |
||
| 214 | } |
||
| 215 | |||
| 216 | unset($categories, $forums_array, $forumsByCat); |
||
| 217 | $xoopsTpl->assign_by_ref('category_icon', $category_icon); |
||
| 218 | $xoopsTpl->assign_by_ref('categories', $category_array); |
||
| 219 | $xoopsTpl->assign('notifyicon', $category_icon); |
||
| 220 | |||
| 221 | $xoopsTpl->assign([ |
||
| 222 | 'index_title' => sprintf(_MD_NEWBB_WELCOME, htmlspecialchars($GLOBALS['xoopsConfig']['sitename'], ENT_QUOTES)), |
||
| 223 | 'index_desc' => _MD_NEWBB_TOSTART |
||
| 224 | ]); |
||
| 225 | |||
| 226 | /* display user stats */ |
||
| 227 | if (!empty($GLOBALS['xoopsModuleConfig']['statistik_enabled'])) { |
||
| 228 | $userstats = []; |
||
| 229 | if (is_object($GLOBALS['xoopsUser'])) { |
||
| 230 | /** @var \NewbbUserstatsHandler $userstatsHandler */ |
||
| 231 | $userstatsHandler = xoops_getModuleHandler('userstats'); |
||
| 232 | $userstats_row = $userstatsHandler->getStats($GLOBALS['xoopsUser']->getVar('uid')); |
||
| 233 | $userstats['topics'] = sprintf(_MD_NEWBB_USER_TOPICS, (int)(@$userstats_row['user_topics'])); |
||
| 234 | $userstats['posts'] = sprintf(_MD_NEWBB_USER_POSTS, (int)(@$userstats_row['user_posts'])); |
||
| 235 | $userstats['digests'] = sprintf(_MD_NEWBB_USER_DIGESTS, (int)(@$userstats_row['user_digests'])); |
||
| 236 | $userstats['currenttime'] = sprintf(_MD_NEWBB_TIMENOW, formatTimestamp(time(), 's')); // irmtfan should be removed because it is for anon users too |
||
| 237 | $userstats['lastvisit'] = sprintf(_MD_NEWBB_USER_LASTVISIT, formatTimestamp($last_visit, 's')); // irmtfan should be removed because it is for anon users too |
||
| 238 | $userstats['lastpost'] = empty($userstats_row['user_lastpost']) ? _MD_NEWBB_USER_NOLASTPOST : sprintf(_MD_NEWBB_USER_LASTPOST, formatTimestamp($userstats_row['user_lastpost'], 's')); |
||
| 239 | } |
||
| 240 | $xoopsTpl->assign_by_ref('userstats', $userstats); |
||
| 241 | // irmtfan add lastvisit smarty variable for all users |
||
| 242 | $xoopsTpl->assign('lastvisit', sprintf(_MD_NEWBB_USER_LASTVISIT, formatTimestamp($last_visit, 'l'))); |
||
| 243 | $xoopsTpl->assign('currenttime', sprintf(_MD_NEWBB_TIMENOW, formatTimestamp(time(), 'm'))); |
||
| 244 | } |
||
| 245 | |||
| 246 | /* display forum stats */ |
||
| 247 | /** @var \NewbbStatsHandler $statsHandler */ |
||
| 248 | $statsHandler = xoops_getModuleHandler('stats'); |
||
| 249 | $stats = $statsHandler->getStats(array_merge([0], $forums_available)); |
||
| 250 | $xoopsTpl->assign_by_ref('stats', $stats); |
||
| 251 | $xoopsTpl->assign('subforum_display', $GLOBALS['xoopsModuleConfig']['subforum_display']); |
||
| 252 | $xoopsTpl->assign('mark_read', XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname', 'n') . '/index.php?mark_read=1'); |
||
| 253 | $xoopsTpl->assign('mark_unread', XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname', 'n') . '/index.php?mark_read=2'); |
||
| 254 | |||
| 255 | $xoopsTpl->assign('all_link', XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname', 'n') . '/list.topic.php?status=all'); |
||
| 256 | $xoopsTpl->assign('post_link', XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname', 'n') . '/viewpost.php?status=all'); |
||
| 257 | $xoopsTpl->assign('newpost_link', XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname', 'n') . '/viewpost.php?status=new'); |
||
| 258 | $xoopsTpl->assign('digest_link', XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname', 'n') . '/list.topic.php?status=digest'); |
||
| 259 | $xoopsTpl->assign('unreplied_link', XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname', 'n') . '/list.topic.php?status=unreplied'); |
||
| 260 | $xoopsTpl->assign('unread_link', XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname', 'n') . '/list.topic.php?status=unread'); |
||
| 261 | $xoopsTpl->assign('menumode', $menumode); |
||
| 262 | $xoopsTpl->assign('menumode_other', $menumode_other); |
||
| 263 | |||
| 264 | $isAdmin = $GLOBALS['xoopsUserIsAdmin']; |
||
| 265 | $xoopsTpl->assign('viewer_level', $isAdmin ? 2 : is_object($GLOBALS['xoopsUser'])); |
||
| 266 | $mode = Request::getInt('mode', 0, 'GET'); |
||
| 267 | $xoopsTpl->assign('mode', $mode); |
||
| 268 | |||
| 269 | $xoopsTpl->assign('viewcat', $viewcat); |
||
| 270 | $xoopsTpl->assign('version', $xoopsModule->getVar('version')); |
||
| 271 | |||
| 272 | /* To be removed */ |
||
| 273 | if ($isAdmin) { |
||
| 274 | $xoopsTpl->assign('forum_index_cpanel', ['link' => 'admin/index.php', 'name' => _MD_NEWBB_ADMINCP]); |
||
| 275 | } |
||
| 276 | |||
| 277 | if (1 == $GLOBALS['xoopsModuleConfig']['rss_enable']) { |
||
| 278 | $xoopsTpl->assign('rss_enable', 1); |
||
| 279 | $xoopsTpl->assign('rss_button', newbbDisplayImage('rss', 'RSS feed')); |
||
| 280 | } |
||
| 281 | $xoopsTpl->assign([ |
||
| 282 | 'img_forum_new' => newbbDisplayImage('forum_new', _MD_NEWBB_NEWPOSTS), |
||
| 283 | 'img_forum' => newbbDisplayImage('forum', _MD_NEWBB_NONEWPOSTS), |
||
| 284 | 'img_subforum' => newbbDisplayImage('subforum') |
||
| 285 | ]); |
||
| 286 | |||
| 287 | // irmtfan move to footer.php |
||
| 288 | include_once __DIR__ . '/footer.php'; |
||
| 289 | include $GLOBALS['xoops']->path('footer.php'); |
||
| 290 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.