Passed
Push — master ( c48d79...0ef847 )
by Michael
05:17
created

action.topic.php (1 issue)

Severity
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 (https://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
use XoopsModules\Newbb\{
14
    Category,
15
    CategoryHandler,
16
    StatsHandler,
17
    Tree,
18
    Topic,
19
    TopicHandler,
20
    Forum,
21
    ForumHandler,
22
    PostHandler
23
};
24
/** @var Category $categories */
25
/** @var CategoryHandler $categoryHandler */
26
/** @var Topic $topicObject */
27
/** @var TopicHandler $topicHandler */
28
/** @var Forum $forumsObject */
29
/** @var ForumHandler $forumHandler */
30
/** @var PostHandler $postHandler */
31
/** @var StatsHandler $statsHandler */
32
33
require_once __DIR__ . '/header.php';
34
35
$forum_id = Request::getInt('forum_id', 0, 'POST');
36
$topic_id = Request::getArray('topic_id', [], 'POST');
37
38
$op = Request::getString('op', '', 'POST');
39
$op = in_array($op, ['approve', 'delete', 'restore', 'move']) ? $op : '';
40
41
if ('' === $op || 0 === count($topic_id)) {
42
    // irmtfan - issue with javascript:history.go(-1)
43
    redirect_header(Request::getString('HTTP_REFERER', '', 'SERVER'), 2, \_MD_NEWBB_NO_SELECTION);
44
}
45
46
$topic_id = array_values($topic_id);
47
///** @var Newbb\TopicHandler|\XoopsPersistableObjectHandler $topicHandler */
48
//$topicHandler = \XoopsModules\Newbb\Helper::getInstance()->getHandler('Topic');
49
///** @var Newbb\ForumHandler|\XoopsPersistableObjectHandler $forumHandler */
50
//$forumHandler = \XoopsModules\Newbb\Helper::getInstance()->getHandler('Forum');
51
52
$isAdmin = newbbIsAdmin($forum_id);
53
54
if (!$isAdmin) {
55
    redirect_header(XOOPS_URL . '/index.php', 2, _MD_NEWBB_NORIGHTTOACCESS);
56
}
57
switch ($op) {
58
    case 'restore':
59
        $forums       = [];
60
        $topicsObject = $topicHandler->getAll(new \Criteria('topic_id', '(' . implode(',', $topic_id) . ')', 'IN'));
61
        foreach (array_keys($topicsObject) as $id) {
62
            /** @var Topic $topicObject */
63
            $topicObject = $topicsObject[$id];
64
            $topicHandler->approve($topicObject);
65
            $topicHandler->synchronization($topicObject);
66
            $forums[$topicObject->getVar('forum_id')] = 1;
67
        }
68
        $criteria_forum = new \Criteria('forum_id', '(' . implode(',', array_keys($forums)) . ')', 'IN');
69
        $forumsObject   = $forumHandler->getAll($criteria_forum);
70
        foreach (array_keys($forumsObject) as $id) {
71
            $forumHandler->synchronization($forumsObject[$id]);
72
        }
73
        unset($topicsObject, $forumsObject);
74
        break;
75
    case 'approve':
76
        $forums       = [];
77
        $topicsObject = $topicHandler->getAll(new \Criteria('topic_id', '(' . implode(',', $topic_id) . ')', 'IN'));
78
        foreach (array_keys($topicsObject) as $id) {
79
            /** @var Topic $topicObject */
80
            $topicObject = $topicsObject[$id];
81
            $topicHandler->approve($topicObject);
82
            $topicHandler->synchronization($topicObject);
83
            $forums[$topicObject->getVar('forum_id')] = 1;
84
        }
85
86
        $criteria_forum = new \Criteria('forum_id', '(' . implode(',', array_keys($forums)) . ')', 'IN');
87
        $forumsObject   = $forumHandler->getAll($criteria_forum);
88
        foreach (array_keys($forumsObject) as $id) {
89
            $forumHandler->synchronization($forumsObject[$id]);
90
        }
91
92
        if (empty($GLOBALS['xoopsModuleConfig']['notification_enabled'])) {
93
            break;
94
        }
95
96
        require_once __DIR__ . '/include/notification.inc.php';
97
        /** @var \XoopsNotificationHandler $notificationHandler */
98
        $notificationHandler = xoops_getHandler('notification');
99
        foreach (array_keys($topicsObject) as $id) {
100
            $topicObject         = $topicsObject[$id];
101
            $tags                = [];
102
            $tags['THREAD_NAME'] = $topicObject->getVar('topic_title');
103
            $tags['THREAD_URL']  = XOOPS_URL . '/modules/' . $moduleDirName . '/viewtopic.php?topic_id=' . $id . '&amp;forum=' . $topicObject->getVar('forum_id');
104
            /** @var Forum[] $forumsObject */
105
            $tags['FORUM_NAME'] = $forumsObject[$topicObject->getVar('forum_id')]->getVar('forum_name');
106
            $tags['FORUM_URL']  = XOOPS_URL . '/modules/' . $moduleDirName . '/viewforum.php?forum=' . $topicObject->getVar('forum_id');
107
            $notificationHandler->triggerEvent('global', 0, 'new_thread', $tags);
108
            $notificationHandler->triggerEvent('forum', $topicObject->getVar('forum_id'), 'new_thread', $tags);
109
            $postObject       = $topicHandler->getTopPost($id);
110
            $tags['POST_URL'] = $tags['THREAD_URL'] . '&topic_id=' . $id . '#forumpost' . $postObject->getVar('post_id');
111
            $notificationHandler->triggerEvent('thread', $id, 'new_post', $tags);
112
            $notificationHandler->triggerEvent('forum', $topicObject->getVar('forum_id'), 'new_post', $tags);
113
            $notificationHandler->triggerEvent('global', 0, 'new_post', $tags);
114
            $tags['POST_CONTENT'] = $postObject->getVar('post_text');
115
            $tags['POST_NAME']    = $postObject->getVar('subject');
116
            $notificationHandler->triggerEvent('global', 0, 'new_fullpost', $tags);
117
            $notificationHandler->triggerEvent('forum', $topicObject->getVar('forum_id'), 'new_fullpost', $tags);
118
            unset($postObject);
119
        }
120
        unset($topicsObject, $forumsObject);
121
        break;
122
    case 'delete':
123
        $forums = [];
124
        /** @var TopicHandler|\XoopsPersistableObjectHandler $topicHandler */
125
        $topicsObject = $topicHandler->getAll(new \Criteria('topic_id', '(' . implode(',', $topic_id) . ')', 'IN'));
126
        foreach (array_keys($topicsObject) as $id) {
127
            /** @var Topic $topicObject */
128
            $topicObject = $topicsObject[$id];
129
            // irmtfan should be set to false to not delete topic from database
130
            $topicHandler->delete($topicObject, false);
131
            $topicHandler->synchronization($topicObject);
0 ignored issues
show
The call to XoopsPersistableObjectHandler::synchronization() has too many arguments starting with $topicObject. ( Ignorable by Annotation )

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

131
            $topicHandler->/** @scrutinizer ignore-call */ 
132
                           synchronization($topicObject);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
132
            $forums[$topicObject->getVar('forum_id')] = 1;
133
        }
134
135
        $criteria_forum = new \Criteria('forum_id', '(' . implode(',', array_keys($forums)) . ')', 'IN');
136
        $forumsObject   = $forumHandler->getAll($criteria_forum);
137
        foreach (array_keys($forumsObject) as $id) {
138
            $forumHandler->synchronization($forumsObject[$id]);
139
        }
140
        unset($topicsObject, $forumsObject);
141
        break;
142
    case 'move':
143
        if (Request::getInt('newforum', 0, 'POST')
144
            && Request::getInt('newforum', 0, 'POST') !== $forum_id
145
            && $forumHandler->getPermission(Request::getInt('newforum', 0, 'POST'), 'post')) {
146
            $criteria = new \Criteria('topic_id', '(' . implode(',', $topic_id) . ')', 'IN');
147
148
            //            $postHandler = \XoopsModules\Newbb\Helper::getInstance()->getHandler('Post');
149
            $postHandler->updateAll('forum_id', Request::getInt('newforum', 0, 'POST'), $criteria, true);
150
            $topicHandler->updateAll('forum_id', Request::getInt('newforum', 0, 'POST'), $criteria, true);
151
            $forumHandler->synchronization(Request::getInt('newforum', 0, 'POST'));
152
            $forumHandler->synchronization($forum_id);
153
        } else {
154
            require_once $GLOBALS['xoops']->path('header.php');
155
             //            $categoryHandler = \XoopsModules\Newbb\Helper::getInstance()->getHandler('Category');
156
            $categories = $categoryHandler->getByPermission('access');
157
            $forums     = $forumHandler->getForumsByCategory(array_keys($categories), 'post', false);
158
159
            $box = '<select name="newforum" size="1">';
160
            if (count($categories) > 0 && count($forums) > 0) {
161
                foreach (array_keys($forums) as $key) {
162
                    /** @var Category[] $categories */
163
                    $box .= "<option value='-1'>[" . $categories[$key]->getVar('cat_title') . ']</option>';
164
                    foreach ($forums[$key] as $forumid => $_forum) {
165
                        $box .= "<option value='" . $forumid . "'>-- " . $_forum['title'] . '</option>';
166
                        if (!isset($_forum['sub'])) {
167
                            continue;
168
                        }
169
                        foreach (array_keys($_forum['sub']) as $fid) {
170
                            $box .= "<option value='" . $fid . "'>---- " . $_forum['sub'][$fid]['title'] . '</option>';
171
                        }
172
                    }
173
                }
174
            } else {
175
                $box .= "<option value='-1'>" . _MD_NEWBB_NOFORUMINDB . '</option>';
176
            }
177
            $box .= '</select>';
178
            unset($forums, $categories);
179
180
            echo "<form action='" . Request::getString('SCRIPT_NAME', '', 'SERVER') . "' method='post'>";
181
            echo "<table border='0' cellpadding='1' cellspacing='0' align='center' width='95%'>";
182
            echo "<tr><td class='bg2'>";
183
            echo "<table border='0' cellpadding='1' cellspacing='1' width='100%'>";
184
            echo '<tr><td class="bg3">' . _MD_NEWBB_MOVETOPICTO . '</td><td class="bg1">';
185
            echo $box;
186
            echo '</td></tr>';
187
            echo '<tr class="bg3"><td colspan="2" align="center">';
188
            echo "<input type='hidden' name='op' value='move' >";
189
            echo "<input type='hidden' name='forum_id' value='{$forum_id}' >";
190
            foreach ($topic_id as $id) {
191
                echo "<input type='hidden' name='topic_id[]' value='" . $id . "' >";
192
            }
193
            echo "<input type='submit' name='submit' value='" . _SUBMIT . "' >";
194
            echo '</td></tr></table></td></tr></table>';
195
            echo '</form>';
196
            require_once $GLOBALS['xoops']->path('footer.php');
197
            exit();
198
        }
199
        break;
200
}
201
///** @var Newbb\StatsHandler $statsHandler */
202
//$statsHandler = \XoopsModules\Newbb\Helper::getInstance()->getHandler('Stats');
203
$statsHandler->reset();
204
if (empty($forum_id)) {
205
    redirect_header(XOOPS_URL . '/modules/newbb/list.topic.php', 2, _MD_NEWBB_DBUPDATED);
206
} else {
207
    redirect_header(XOOPS_URL . "/modules/newbb/viewforum.php?forum={$forum_id}", 2, _MD_NEWBB_DBUPDATED);
208
}
209
// irmtfan move to footer.php
210
require_once __DIR__ . '/footer.php';
211
require_once $GLOBALS['xoops']->path('footer.php');
212