Completed
Push — master ( 316fad...4e8684 )
by Michael
02:41
created

index.php (3 issues)

Labels
Severity

Upgrade to new PHP Analysis Engine

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 (http://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
    newbb_setRead_forum($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
    $category_obj = $categoryHandler->get($viewcat);
42
    if ($categoryHandler->getPermission($category_obj)) {
43
        $categories[$viewcat] = $category_obj->getValues();
44
    }
45
    $forum_index_title = sprintf(_MD_NEWBB_FORUMINDEX, htmlspecialchars($GLOBALS['xoopsConfig']['sitename'], ENT_QUOTES));
46
    $xoops_pagetitle   = $category_obj->getVar('cat_title') . ' [' . $xoopsModule->getVar('name') . ']';
47
}
48
49
if (count($categories) === 0) {
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
if (!empty($GLOBALS['xoopsModuleConfig']['wol_enabled'])) {
73
    /** @var \NewbbOnlineHandler $onlineHandler */
74
    $onlineHandler = xoops_getModuleHandler('online', 'newbb');
75
    $onlineHandler->init();
76
    $xoopsTpl->assign('online', $onlineHandler->show_online());
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');
0 ignored issues
show
Are you sure the assignment to $newtopics is correct as $forumHandler->getTopicC...($forums, 0, 'pending') (which targets NewbbForumHandler::getTopicCount()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
118
    $deletetopics = $forumHandler->getTopicCount($forums, 0, 'deleted');
0 ignored issues
show
Are you sure the assignment to $deletetopics is correct as $forumHandler->getTopicC...($forums, 0, 'deleted') (which targets NewbbForumHandler::getTopicCount()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
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        = newbb_getcookie('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
    if ('' !== $cat_image && 'blank.gif' !== $cat_image && 0 !== (int)$cat_image) {
200
        $cat_image = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname', 'n') . '/assets/images/category/' . $cat_image;
201
    }
202
    $category_array[] = [
203
        'cat_id'           => $onecat['cat_id'],
204
        'cat_title'        => $myts->displayTarea($onecat['cat_title'], 1),
205
        'cat_image'        => $cat_image,
206
        'cat_sponsor'      => $cat_sponsor,
207
        'cat_description'  => $myts->displayTarea($onecat['cat_description'], 1),
208
        'cat_element_id'   => $cat_element_id,
209
        'cat_display'      => $cat_display,
210
        'cat_displayImage' => $cat_displayImage,
211
        'forums'           => $forums
212
    ];
213
}
214
215
unset($categories, $forums_array, $forumsByCat);
216
$xoopsTpl->assign_by_ref('category_icon', $category_icon);
217
$xoopsTpl->assign_by_ref('categories', $category_array);
218
$xoopsTpl->assign('notifyicon', $category_icon);
219
220
$xoopsTpl->assign([
221
                      'index_title' => sprintf(_MD_NEWBB_WELCOME, htmlspecialchars($GLOBALS['xoopsConfig']['sitename'], ENT_QUOTES)),
222
                      'index_desc'  => _MD_NEWBB_TOSTART
223
                  ]);
224
225
/* display user stats */
226
if (!empty($GLOBALS['xoopsModuleConfig']['statistik_enabled'])) {
227
    $userstats = [];
228
    if (is_object($GLOBALS['xoopsUser'])) {
229
        /** @var \NewbbUserstatsHandler $userstatsHandler */
230
        $userstatsHandler         = xoops_getModuleHandler('userstats');
231
        $userstats_row            = $userstatsHandler->getStats($GLOBALS['xoopsUser']->getVar('uid'));
0 ignored issues
show
Are you sure the assignment to $userstats_row is correct as $userstatsHandler->getSt...sUser']->getVar('uid')) (which targets NewbbUserstatsHandler::getStats()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
232
        $userstats['topics']      = sprintf(_MD_NEWBB_USER_TOPICS, (int)(@$userstats_row['user_topics']));
233
        $userstats['posts']       = sprintf(_MD_NEWBB_USER_POSTS, (int)(@$userstats_row['user_posts']));
234
        $userstats['digests']     = sprintf(_MD_NEWBB_USER_DIGESTS, (int)(@$userstats_row['user_digests']));
235
        $userstats['currenttime'] = sprintf(_MD_NEWBB_TIMENOW, formatTimestamp(time(), 's')); // irmtfan should be removed because it is for anon users too
236
        $userstats['lastvisit']   = sprintf(_MD_NEWBB_USER_LASTVISIT, formatTimestamp($last_visit, 's')); // irmtfan should be removed because it is for anon users too
237
        $userstats['lastpost']    = empty($userstats_row['user_lastpost']) ? _MD_NEWBB_USER_NOLASTPOST : sprintf(_MD_NEWBB_USER_LASTPOST, formatTimestamp($userstats_row['user_lastpost'], 's'));
238
    }
239
    $xoopsTpl->assign_by_ref('userstats', $userstats);
240
    // irmtfan add lastvisit smarty variable for all users
241
    $xoopsTpl->assign('lastvisit', sprintf(_MD_NEWBB_USER_LASTVISIT, formatTimestamp($last_visit, 'l')));
242
    $xoopsTpl->assign('currenttime', sprintf(_MD_NEWBB_TIMENOW, formatTimestamp(time(), 'm')));
243
}
244
245
/* display forum stats */
246
/** @var \NewbbStatsHandler $statsHandler */
247
$statsHandler = xoops_getModuleHandler('stats');
248
$stats        = $statsHandler->getStats(array_merge([0], $forums_available));
249
$xoopsTpl->assign_by_ref('stats', $stats);
250
$xoopsTpl->assign('subforum_display', $GLOBALS['xoopsModuleConfig']['subforum_display']);
251
$xoopsTpl->assign('mark_read', XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname', 'n') . '/index.php?mark_read=1');
252
$xoopsTpl->assign('mark_unread', XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname', 'n') . '/index.php?mark_read=2');
253
254
$xoopsTpl->assign('all_link', XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname', 'n') . '/list.topic.php?status=all');
255
$xoopsTpl->assign('post_link', XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname', 'n') . '/viewpost.php?status=all');
256
$xoopsTpl->assign('newpost_link', XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname', 'n') . '/viewpost.php?status=new');
257
$xoopsTpl->assign('digest_link', XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname', 'n') . '/list.topic.php?status=digest');
258
$xoopsTpl->assign('unreplied_link', XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname', 'n') . '/list.topic.php?status=unreplied');
259
$xoopsTpl->assign('unread_link', XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname', 'n') . '/list.topic.php?status=unread');
260
$xoopsTpl->assign('menumode', $menumode);
261
$xoopsTpl->assign('menumode_other', $menumode_other);
262
263
$isadmin = $GLOBALS['xoopsUserIsAdmin'];
264
$xoopsTpl->assign('viewer_level', $isadmin ? 2 : is_object($GLOBALS['xoopsUser']));
265
$mode = Request::getInt('mode', 0, 'GET');
266
$xoopsTpl->assign('mode', $mode);
267
268
$xoopsTpl->assign('viewcat', $viewcat);
269
$xoopsTpl->assign('version', $xoopsModule->getVar('version'));
270
271
/* To be removed */
272
if ($isadmin) {
273
    $xoopsTpl->assign('forum_index_cpanel', ['link' => 'admin/index.php', 'name' => _MD_NEWBB_ADMINCP]);
274
}
275
276
if ($GLOBALS['xoopsModuleConfig']['rss_enable'] == 1) {
277
    $xoopsTpl->assign('rss_enable', 1);
278
    $xoopsTpl->assign('rss_button', newbbDisplayImage('rss', 'RSS feed'));
279
}
280
$xoopsTpl->assign([
281
                      'img_forum_new' => newbbDisplayImage('forum_new', _MD_NEWBB_NEWPOSTS),
282
                      'img_forum'     => newbbDisplayImage('forum', _MD_NEWBB_NONEWPOSTS),
283
                      'img_subforum'  => newbbDisplayImage('subforum')
284
                  ]);
285
286
// irmtfan move to footer.php
287
include_once __DIR__ . '/footer.php';
288
include $GLOBALS['xoops']->path('footer.php');
289