Passed
Push — master ( 8f67b7...dd6e46 )
by Michael
03:09
created

moderate.php (25 issues)

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;
0 ignored issues
show
The type Xmf\Request was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
13
14
require_once __DIR__ . '/header.php';
15
16
global $xoTheme, $xoopsTpl;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
17
$GLOBALS['xoopsOption']['template_main'] = 'newbb_moderate.tpl';
18
include $GLOBALS['xoops']->path('header.php');
19
20
$forum_userid = Request::getInt('uid', 0);
21
$forum_id     = Request::getInt('forum', 0);
22
$isAdmin      = newbbIsAdmin($forum_id);
23
if (!$isAdmin) {
24
    redirect_header(XOOPS_URL . '/index.php', 2, _MD_NEWBB_NORIGHTTOACCESS);
0 ignored issues
show
The function redirect_header was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

24
    /** @scrutinizer ignore-call */ 
25
    redirect_header(XOOPS_URL . '/index.php', 2, _MD_NEWBB_NORIGHTTOACCESS);
Loading history...
The constant XOOPS_URL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
25
}
26
$is_administrator = $GLOBALS['xoopsUserIsAdmin'];
27
///** @var Newbb\ModerateHandler $moderateHandler */
0 ignored issues
show
Unused Code Comprehensibility introduced by
57% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
28
//$moderateHandler = Newbb\Helper::getInstance()->getHandler('Moderate');
29
30
if (Request::hasVar('submit', 'POST') && Request::getInt('expire', 0, 'POST')) {
31
    $ipWithMask = '';
32
    if (0 == $forum_userid) {
33
        $ipWithMask = Request::getString('ip', null, 'POST');
34
        $mask       = '';
35
        $ipParts    = explode('/', $ipWithMask);
36
        $ip         = new \Xmf\IPAddress($ipParts[0]);
0 ignored issues
show
The type Xmf\IPAddress was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
37
        if (false === $ip->asReadable()) {
38
            $ipWithMask = '';
39
        } else {
40
            $ipWithMask = $ip->asReadable();
41
            $mask       = empty($ipParts[1]) ? 0 : (int)$ipParts[1];
42
            $mask       = ($mask > ((4 === $ip->ipVersion()) ? 32 : 128) || $mask < 8) ? '' : $mask;
43
            $ipWithMask .= empty($mask) ? '' : '/' . $mask;
44
        }
45
    }
46
47
    $mod_end  = time() + Request::getInt('expire', 0, 'POST') * 3600 * 24;
48
    $mod_desc = Request::getString('desc', '', 'POST');
49
50
    $moderateObject = $moderateHandler->create();
51
    $moderateObject->setVar('uid', $forum_userid);
52
    $moderateObject->setVar('ip', $ipWithMask);
53
    $moderateObject->setVar('forum_id', $forum_id);
54
    $moderateObject->setVar('mod_start', time());
55
    $moderateObject->setVar('mod_end', $mod_end);
56
    $moderateObject->setVar('mod_desc', $mod_desc);
57
    $res = $moderateHandler->insert($moderateObject);
58
59
    redirect_header("moderate.php?forum={$forum_id}", 2, _MD_NEWBB_DBUPDATED);
60
} elseif (Request::hasVar('del')) {
61
    $moderateObject = $moderateHandler->get(Request::getInt('del', 0, 'GET'));
62
    if ($is_administrator || $moderateObject->getVar('forum_id') == $forum_id) {
63
        $moderateHandler->delete($moderateObject, true);
64
        redirect_header("moderate.php?forum={$forum_id}", 2, _MD_NEWBB_DBUPDATED);
65
    }
66
}
67
68
$start    = Request::getInt('start', 0, 'GET');
69
$sortname = Request::getString('sort', '', 'GET');
70
71
switch ($sortname) {
72
    case 'uid':
73
        $sort  = 'uid ASC, ip';
74
        $order = 'ASC';
75
        break;
76
    case 'start':
77
        $sort  = 'mod_start';
78
        $order = 'ASC';
79
        break;
80
    case 'expire':
81
        $sort  = 'mod_end';
82
        $order = 'DESC';
83
        break;
84
    default:
85
        $sort  = 'forum_id ASC, uid ASC, ip';
86
        $order = 'ASC';
87
        break;
88
}
89
// show all bans for module admin - for moderator just show its forum_id bans
90
$criteria = new \CriteriaCompo();
0 ignored issues
show
The type CriteriaCompo was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
91
if (!$is_administrator) {
92
    $criteria->add(new \Criteria('forum_id', $forum_id, '='));
0 ignored issues
show
The type Criteria was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
93
}
94
$criteria->setLimit($GLOBALS['xoopsModuleConfig']['topics_per_page']);
95
$criteria->setStart($start);
96
$criteria->setSort($sort);
97
$criteria->setOrder($order);
98
$moderateObjects = $moderateHandler->getObjects($criteria);
99
$moderate_count  = $moderateHandler->getCount($criteria);
100
101
$url = 'moderate.php';
102
if ($forum_id) {
103
    $url .= '?forum=' . $forum_id;
104
}
105
$xoopsTpl->assign('moderate_url', $url);
106
107
if (!empty($moderate_count)) {
108
    $_users = [];
109
    foreach (array_keys($moderateObjects) as $id) {
110
        $_users[$moderateObjects[$id]->getVar('uid')] = 1;
111
    }
112
    $users = newbbGetUnameFromIds(array_keys($_users), $GLOBALS['xoopsModuleConfig']['show_realname'], true);
113
114
    $columnHeaders ['uid']    = [
115
        'url'    => 'moderate.php?forum=' . $forum_id . '&amp;start=' . $start . '&amp;sort=uid',
116
        'header' => _MD_NEWBB_SUSPEND_UID,
117
        'title'  => _MD_NEWBB_SUSPEND_UID,
118
    ];
119
    $columnHeaders ['start']  = [
120
        'url'    => 'moderate.php?forum=' . $forum_id . '&amp;start=' . $start . '&amp;sort=start',
121
        'header' => _MD_NEWBB_SUSPEND_START,
122
        'title'  => _MD_NEWBB_SUSPEND_START,
123
    ];
124
    $columnHeaders['expire']  = [
125
        'url'    => 'moderate.php?forum=' . $forum_id . '&amp;start=' . $start . '&amp;sort=expire',
126
        'header' => _MD_NEWBB_SUSPEND_EXPIRE,
127
        'title'  => _MD_NEWBB_SUSPEND_EXPIRE,
128
    ];
129
    $columnHeaders['forum']   = [
130
        'url'    => 'moderate.php?forum=' . $forum_id . '&amp;start=' . $start . '&amp;sort=forum',
131
        'header' => _MD_NEWBB_SUSPEND_SCOPE,
132
        'title'  => _MD_NEWBB_SUSPEND_SCOPE,
133
    ];
134
    $columnHeaders['desc']    = [
135
        'url'    => false,
136
        'header' => _MD_NEWBB_SUSPEND_DESC,
137
        'title'  => _MD_NEWBB_SUSPEND_DESC,
138
    ];
139
    $columnHeaders['options'] = [
140
        'url'    => false,
141
        'header' => _DELETE,
0 ignored issues
show
The constant _DELETE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
142
        'title'  => _DELETE,
143
    ];
144
    $xoopsTpl->assign('columnHeaders', $columnHeaders);
145
146
    //    /** @var Newbb\ForumHandler $forumHandler */
147
    //    $forumHandler = Newbb\Helper::getInstance()->getHandler('Forum');
0 ignored issues
show
Unused Code Comprehensibility introduced by
57% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
148
    $forum_list = $forumHandler->getAll(null, ['forum_name'], false);
149
150
    $columnRows = [];
151
    foreach (array_keys($moderateObjects) as $id) {
152
        // for anon, show ip instead
153
        $row['uid']     = ($moderateObjects[$id]->getVar('uid') ? (isset($users[$moderateObjects[$id]->getVar('uid')]) ? $users[$moderateObjects[$id]->getVar('uid')] : $moderateObjects[$id]->getVar('uid')) : $moderateObjects[$id]->getVar('ip'));
154
        $row['start']   = formatTimestamp($moderateObjects[$id]->getVar('mod_start'));
0 ignored issues
show
The function formatTimestamp was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

154
        $row['start']   = /** @scrutinizer ignore-call */ formatTimestamp($moderateObjects[$id]->getVar('mod_start'));
Loading history...
155
        $row['expire']  = formatTimestamp($moderateObjects[$id]->getVar('mod_end'));
156
        $row['forum']   = ($moderateObjects[$id]->getVar('forum_id') ? $forum_list[$moderateObjects[$id]->getVar('forum_id')]['forum_name'] : _ALL);
0 ignored issues
show
The constant _ALL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
157
        $row['desc']    = ($moderateObjects[$id]->getVar('mod_desc') ?: _NONE);
0 ignored issues
show
The constant _NONE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
158
        $row['options'] = (($is_administrator
159
                            || $moderateObjects[$id]->getVar('forum_id') == $forum_id) ? '<a href="moderate.php?forum=' . $forum_id . '&amp;del=' . $moderateObjects[$id]->getVar('mod_id') . '">' . _DELETE . '</a>' : '');
160
        $columnRows[]   = $row;
161
    }
162
    $xoopsTpl->assign('columnRows', $columnRows);
163
164
    if ($moderate_count > $GLOBALS['xoopsModuleConfig']['topics_per_page']) {
165
        include $GLOBALS['xoops']->path('class/pagenav.php');
166
        $nav = new \XoopsPageNav($moderate_count, $GLOBALS['xoopsModuleConfig']['topics_per_page'], $start, 'start', 'forum=' . $forum_id . '&amp;sort=' . $sortname);
0 ignored issues
show
The type XoopsPageNav was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
167
        //if (isset($GLOBALS['xoopsModuleConfig']['do_rewrite'])) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
88% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
168
        //    $nav->url = formatURL(Request::getString('SERVER_NAME', '', 'SERVER')) . ' /' . $nav->url;
0 ignored issues
show
Unused Code Comprehensibility introduced by
49% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
169
        //}
170
        $xoopsTpl->assign('moderate_page_nav', $nav->renderNav());
171
    }
172
}
173
174
require_once $GLOBALS['xoops']->path('class/xoopsformloader.php');
175
$forum_form = new \XoopsThemeForm(_ADD, 'suspend_form', 'moderate.php', 'post', true);
0 ignored issues
show
The constant _ADD was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
The type XoopsThemeForm was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
176
$forum_form->addElement(new \XoopsFormSelectUser(_MD_NEWBB_SUSPEND_UID, 'uid', true, $forum_userid, 1, false));
0 ignored issues
show
The type XoopsFormSelectUser was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
177
$forum_form->addElement(new \XoopsFormText(_MD_NEWBB_SUSPEND_IP, 'ip', 50, 50));
0 ignored issues
show
The type XoopsFormText was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
178
$forum_form->addElement(new \XoopsFormText(_MD_NEWBB_SUSPEND_DURATION, 'expire', 20, 25, '5'), true);
179
$forum_form->addElement(new \XoopsFormText(_MD_NEWBB_SUSPEND_DESC, 'desc', 50, 255));
180
require_once __DIR__ . '/include/functions.forum.php';
181
if (newbbIsAdmin()) {
182
    $forumSel = '<select name="forum">';// if user doesn't select, default is "0" all forums
183
    $forumSel .= '<option value="0"';
184
    if (0 == $forum_id) {
185
        $forumSel .= ' selected';
186
    }
187
    $forumSel                         .= '>' . _ALL . '</option>';
188
    $forumSel                         .= newbbForumSelectBox($forum_id, 'access', false); //$accessForums, $permission = "access", $delimitorCategory = true
0 ignored issues
show
Unused Code Comprehensibility introduced by
47% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
189
    $forumSel                         .= '</select>';
190
    $forumEle                         = new \XoopsFormLabel(_MD_NEWBB_SELFORUM, $forumSel);
0 ignored issues
show
The type XoopsFormLabel was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
191
    $forumEle->customValidationCode[] = 'if (document.suspend.forum.value < 0) {return false;} ';
192
    $forum_form->addElement($forumEle);
193
} else {
194
    $forum_form->addElement(new \XoopsFormHidden('forum', $forum_id));
0 ignored issues
show
The type XoopsFormHidden was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
195
}
196
$forum_form->addElement(new \XoopsFormButton('', 'submit', _SUBMIT, 'submit'));
0 ignored issues
show
The constant _SUBMIT was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
The type XoopsFormButton was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
197
$forum_form->assign($xoopsTpl);
198
199
require_once __DIR__ . '/footer.php';
200
include $GLOBALS['xoops']->path('footer.php');
201