Completed
Push — master ( 249590...ebae0d )
by Michael
05:58
created

action.topic.php (33 issues)

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 (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
use XoopsModules\Newbb;
14
15
include_once __DIR__ . '/header.php';
16
17
$forum_id = Request::getInt('forum_id', 0, 'POST');
0 ignored issues
show
$forum_id does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
18
$topic_id = Request::getArray('topic_id', null, 'POST');
0 ignored issues
show
$topic_id does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
19
20
$op = Request::getCmd('op', '', 'POST');
21
$op = in_array($op, ['approve', 'delete', 'restore', 'move'], true) ? $op : '';
22
23
if (0 === count($topic_id) || 0 === count($op)) {
0 ignored issues
show
$topic_id does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
24
    // irmtfan - issue with javascript:history.go(-1)
25
    redirect_header(Request::getString('HTTP_REFERER', '', 'SERVER'), 2, _MD_NEWBB_NO_SELECTION);
26
}
27
28
$topic_id = array_values($topic_id);
0 ignored issues
show
$topic_id does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
29
///** @var Newbb\TopicHandler|\XoopsPersistableObjectHandler $topicHandler */
0 ignored issues
show
Unused Code Comprehensibility introduced by
55% 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...
30
//$topicHandler = Newbb\Helper::getInstance()->getHandler('Topic');
31
///** @var Newbb\ForumHandler|\XoopsPersistableObjectHandler $forumHandler */
32
//$forumHandler = Newbb\Helper::getInstance()->getHandler('Forum');
33
34
$isAdmin = newbbIsAdmin($forum_id);
0 ignored issues
show
$forum_id does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
35
36
if (!$isAdmin) {
37
    redirect_header(XOOPS_URL . '/index.php', 2, _MD_NEWBB_NORIGHTTOACCESS);
38
}
39
switch ($op) {
40 View Code Duplication
    case 'restore':
0 ignored issues
show
This code seems to be duplicated across your project.

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.

Loading history...
41
        $forums       = [];
42
        $topicsObject = $topicHandler->getAll(new \Criteria('topic_id', '(' . implode(',', $topic_id) . ')', 'IN'));
0 ignored issues
show
$topic_id does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
43
        foreach (array_keys($topicsObject) as $id) {
44
            /** @var Newbb\Topic $topicObject */
45
            $topicObject = $topicsObject[$id];
46
            $topicHandler->approve($topicObject);
47
            $topicHandler->synchronization($topicObject);
48
            $forums[$topicObject->getVar('forum_id')] = 1;
49
        }
50
        $criteria_forum = new \Criteria('forum_id', '(' . implode(',', array_keys($forums)) . ')', 'IN');
0 ignored issues
show
$criteria_forum does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
51
        $forumsObject   = $forumHandler->getAll($criteria_forum);
0 ignored issues
show
$criteria_forum does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
52
        foreach (array_keys($forumsObject) as $id) {
53
            $forumHandler->synchronization($forumsObject[$id]);
54
        }
55
        unset($topicsObject, $forumsObject);
56
        break;
57
    case 'approve':
58
        $forums       = [];
59
        $topicsObject = $topicHandler->getAll(new \Criteria('topic_id', '(' . implode(',', $topic_id) . ')', 'IN'));
0 ignored issues
show
$topic_id does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
60
        foreach (array_keys($topicsObject) as $id) {
61
            /** @var Newbb\Topic $topicObject */
62
            $topicObject = $topicsObject[$id];
63
            $topicHandler->approve($topicObject);
64
            $topicHandler->synchronization($topicObject);
65
            $forums[$topicObject->getVar('forum_id')] = 1;
66
        }
67
68
        $criteria_forum = new \Criteria('forum_id', '(' . implode(',', array_keys($forums)) . ')', 'IN');
0 ignored issues
show
$criteria_forum does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
69
        $forumsObject   = $forumHandler->getAll($criteria_forum);
0 ignored issues
show
$criteria_forum does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
70
        foreach (array_keys($forumsObject) as $id) {
71
            $forumHandler->synchronization($forumsObject[$id]);
72
        }
73
74
        if (empty($GLOBALS['xoopsModuleConfig']['notification_enabled'])) {
75
            break;
76
        }
77
78
        include_once __DIR__ . '/include/notification.inc.php';
79
        /** @var \XoopsNotificationHandler $notificationHandler */
80
        $notificationHandler = xoops_getHandler('notification');
81
        foreach (array_keys($topicsObject) as $id) {
82
            $topicObject         = $topicsObject[$id];
83
            $tags                = [];
84
            $tags['THREAD_NAME'] = $topicObject->getVar('topic_title');
85
            $tags['THREAD_URL']  = XOOPS_URL . '/modules/' . $moduleDirName . '/viewtopic.php?topic_id=' . $id . '&amp;forum=' . $topicObject->getVar('forum_id');
86
            /** @var Newbb\Forum[] $forumsObject */
87
            $tags['FORUM_NAME'] = $forumsObject[$topicObject->getVar('forum_id')]->getVar('forum_name');
88
            $tags['FORUM_URL']  = XOOPS_URL . '/modules/' . $moduleDirName . '/viewforum.php?forum=' . $topicObject->getVar('forum_id');
89
            $notificationHandler->triggerEvent('global', 0, 'new_thread', $tags);
90
            $notificationHandler->triggerEvent('forum', $topicObject->getVar('forum_id'), 'new_thread', $tags);
91
            $postObject       = $topicHandler->getTopPost($id);
92
            $tags['POST_URL'] = $tags['THREAD_URL'] . '#forumpost' . $postObject->getVar('post_id');
93
            $notificationHandler->triggerEvent('thread', $id, 'new_post', $tags);
94
            $notificationHandler->triggerEvent('forum', $topicObject->getVar('forum_id'), 'new_post', $tags);
95
            $notificationHandler->triggerEvent('global', 0, 'new_post', $tags);
96
            $tags['POST_CONTENT'] = $postObject->getVar('post_text');
97
            $tags['POST_NAME']    = $postObject->getVar('subject');
98
            $notificationHandler->triggerEvent('global', 0, 'new_fullpost', $tags);
99
            $notificationHandler->triggerEvent('forum', $topicObject->getVar('forum_id'), 'new_fullpost', $tags);
100
            unset($postObject);
101
        }
102
        unset($topicsObject, $forumsObject);
103
        break;
104 View Code Duplication
    case 'delete':
0 ignored issues
show
This code seems to be duplicated across your project.

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.

Loading history...
105
        $forums = [];
106
        /** @var Newbb\TopicHandler|\XoopsPersistableObjectHandler $topicHandler */
107
        $topicsObject = $topicHandler->getAll(new \Criteria('topic_id', '(' . implode(',', $topic_id) . ')', 'IN'));
0 ignored issues
show
$topic_id does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
108
        foreach (array_keys($topicsObject) as $id) {
109
            /** @var Newbb\Topic $topicObject */
110
            $topicObject = $topicsObject[$id];
111
            // irmtfan should be set to false to not delete topic from database
112
            $topicHandler->delete($topicObject, false);
113
            $topicHandler->synchronization($topicObject);
114
            $forums[$topicObject->getVar('forum_id')] = 1;
115
        }
116
117
        $criteria_forum = new \Criteria('forum_id', '(' . implode(',', array_keys($forums)) . ')', 'IN');
0 ignored issues
show
$criteria_forum does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
118
        $forumsObject   = $forumHandler->getAll($criteria_forum);
0 ignored issues
show
$criteria_forum does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
119
        foreach (array_keys($forumsObject) as $id) {
120
            $forumHandler->synchronization($forumsObject[$id]);
121
        }
122
        unset($topicsObject, $forumsObject);
123
        break;
124
    case 'move':
125
        if (Request::getInt('newforum', 0, 'POST')
126
            && Request::getInt('newforum', 0, 'POST') !== $forum_id
0 ignored issues
show
$forum_id does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
127
            && $forumHandler->getPermission(Request::getInt('newforum', 0, 'POST'), 'post')) {
128
            $criteria = new \Criteria('topic_id', '(' . implode(',', $topic_id) . ')', 'IN');
0 ignored issues
show
$topic_id does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
129
            //            /** @var Newbb\PostHandler $postHandler */
130
            //            $postHandler = Newbb\Helper::getInstance()->getHandler('Post');
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...
131
            $postHandler->updateAll('forum_id', Request::getInt('newforum', 0, 'POST'), $criteria, true);
132
            $topicHandler->updateAll('forum_id', Request::getInt('newforum', 0, 'POST'), $criteria, true);
133
            $forumHandler->synchronization(Request::getInt('newforum', 0, 'POST'));
134
            $forumHandler->synchronization($forum_id);
0 ignored issues
show
$forum_id does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
135
        } else {
136
            include $GLOBALS['xoops']->path('header.php');
137
            //            /** @var Newbb\CategoryHandler $categoryHandler */
138
            //            $categoryHandler = Newbb\Helper::getInstance()->getHandler('Category');
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...
139
            $categories = $categoryHandler->getByPermission('access');
140
            $forums     = $forumHandler->getForumsByCategory(array_keys($categories), 'post', false);
141
142
            $box = '<select name="newforum" size="1">';
143 View Code Duplication
            if (count($categories) > 0 && count($forums) > 0) {
0 ignored issues
show
This code seems to be duplicated across your project.

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.

Loading history...
144
                foreach (array_keys($forums) as $key) {
145
146
                    /** @var Newbb\Category[] $categories */
147
                    $box .= "<option value='-1'>[" . $categories[$key]->getVar('cat_title') . ']</option>';
148
                    foreach ($forums[$key] as $forumid => $_forum) {
0 ignored issues
show
$_forum does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
149
                        $box .= "<option value='" . $forumid . "'>-- " . $_forum['title'] . '</option>';
0 ignored issues
show
$_forum does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
150
                        if (!isset($_forum['sub'])) {
0 ignored issues
show
$_forum does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
151
                            continue;
152
                        }
153
                        foreach (array_keys($_forum['sub']) as $fid) {
0 ignored issues
show
$_forum does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
154
                            $box .= "<option value='" . $fid . "'>---- " . $_forum['sub'][$fid]['title'] . '</option>';
0 ignored issues
show
$_forum does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
155
                        }
156
                    }
157
                }
158
            } else {
159
                $box .= "<option value='-1'>" . _MD_NEWBB_NOFORUMINDB . '</option>';
160
            }
161
            $box .= '</select>';
162
            unset($forums, $categories);
163
164
            echo "<form action='" . Request::getString('PHP_SELF', '', 'SERVER') . "' method='post'>";
165
            echo "<table border='0' cellpadding='1' cellspacing='0' align='center' width='95%'>";
166
            echo "<tr><td class='bg2'>";
167
            echo "<table border='0' cellpadding='1' cellspacing='1' width='100%'>";
168
            echo '<tr><td class="bg3">' . _MD_NEWBB_MOVETOPICTO . '</td><td class="bg1">';
169
            echo $box;
170
            echo '</td></tr>';
171
            echo '<tr class="bg3"><td colspan="2" align="center">';
172
            echo "<input type='hidden' name='op' value='move' />";
173
            echo "<input type='hidden' name='forum_id' value='{$forum_id}' />";
0 ignored issues
show
$forum_id does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
174
            foreach ($topic_id as $id) {
0 ignored issues
show
$topic_id does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
175
                echo "<input type='hidden' name='topic_id[]' value='" . $id . "' />";
176
            }
177
            echo "<input type='submit' name='submit' value='" . _SUBMIT . "' />";
178
            echo '</td></tr></table></td></tr></table>';
179
            echo '</form>';
180
            include $GLOBALS['xoops']->path('footer.php');
181
            exit();
182
        }
183
        break;
184
}
185
///** @var Newbb\StatsHandler $statsHandler */
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...
186
//$statsHandler = Newbb\Helper::getInstance()->getHandler('Stats');
187
$statsHandler->reset();
188
if (empty($forum_id)) {
0 ignored issues
show
$forum_id does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
189
    redirect_header(XOOPS_URL . '/modules/newbb/list.topic.php', 2, _MD_NEWBB_DBUPDATED);
190
} else {
191
    redirect_header(XOOPS_URL . "/modules/newbb/viewforum.php?forum={$forum_id}", 2, _MD_NEWBB_DBUPDATED);
0 ignored issues
show
$forum_id does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
192
}
193
// irmtfan move to footer.php
194
include_once __DIR__ . '/footer.php';
195
include $GLOBALS['xoops']->path('footer.php');
196