Completed
Push — master ( 525594...a88ff3 )
by Michael
12s
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
14
include_once __DIR__ . '/header.php';
15
16
$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...
17
$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...
18
19
$op = Request::getCmd('op', '', 'POST');
20
$op = in_array($op, ['approve', 'delete', 'restore', 'move'], true) ? $op : '';
21
22
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...
23
    // irmtfan - issue with javascript:history.go(-1)
24
    redirect_header(Request::getString('HTTP_REFERER', '', 'SERVER'), 2, _MD_NEWBB_NO_SELECTION);
25
}
26
27
$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...
28
///** @var \NewbbTopicHandler|XoopsPersistableObjectHandler $topicHandler */
0 ignored issues
show
Unused Code Comprehensibility introduced by
52% 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...
29
//$topicHandler = xoops_getModuleHandler('topic', 'newbb');
30
///** @var \NewbbForumHandler|XoopsPersistableObjectHandler $forumHandler */
31
//$forumHandler = xoops_getModuleHandler('forum', 'newbb');
32
33
$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...
34
35
if (!$isAdmin) {
36
    redirect_header(XOOPS_URL . '/index.php', 2, _MD_NEWBB_NORIGHTTOACCESS);
37
}
38
switch ($op) {
39 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...
40
        $forums     = [];
41
        $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...
42
        foreach (array_keys($topicsObject) as $id) {
43
            /** @var \Topic $topicObject */
44
            $topicObject = $topicsObject[$id];
45
            $topicHandler->approve($topicObject);
46
            $topicHandler->synchronization($topicObject);
47
            $forums[$topicObject->getVar('forum_id')] = 1;
48
        }
49
        $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...
50
        $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...
51
        foreach (array_keys($forumsObject) as $id) {
52
            $forumHandler->synchronization($forumsObject[$id]);
53
        }
54
        unset($topicsObject, $forumsObject);
55
        break;
56
    case 'approve':
57
        $forums     = [];
58
        $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...
59
        foreach (array_keys($topicsObject) as $id) {
60
            /** @var \Topic $topicObject */
61
            $topicObject = $topicsObject[$id];
62
            $topicHandler->approve($topicObject);
63
            $topicHandler->synchronization($topicObject);
64
            $forums[$topicObject->getVar('forum_id')] = 1;
65
        }
66
67
        $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...
68
        $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...
69
        foreach (array_keys($forumsObject) as $id) {
70
            $forumHandler->synchronization($forumsObject[$id]);
71
        }
72
73
        if (empty($GLOBALS['xoopsModuleConfig']['notification_enabled'])) {
74
            break;
75
        }
76
77
        include_once __DIR__ . '/include/notification.inc.php';
78
        /** @var \XoopsNotificationHandler $notificationHandler */
79
        $notificationHandler = xoops_getHandler('notification');
80
        foreach (array_keys($topicsObject) as $id) {
81
            $topicObject           = $topicsObject[$id];
82
            $tags                = [];
83
            $tags['THREAD_NAME'] = $topicObject->getVar('topic_title');
84
            $tags['THREAD_URL']  = XOOPS_URL . '/modules/' . $moduleDirName . '/viewtopic.php?topic_id=' . $id . '&amp;forum=' . $topicObject->getVar('forum_id');
85
            /** @var \NewbbForum[] $forumsObject */
86
            $tags['FORUM_NAME'] = $forumsObject[$topicObject->getVar('forum_id')]->getVar('forum_name');
87
            $tags['FORUM_URL']  = XOOPS_URL . '/modules/' . $moduleDirName . '/viewforum.php?forum=' . $topicObject->getVar('forum_id');
88
            $notificationHandler->triggerEvent('global', 0, 'new_thread', $tags);
89
            $notificationHandler->triggerEvent('forum', $topicObject->getVar('forum_id'), 'new_thread', $tags);
90
            $postObject         = $topicHandler->getTopPost($id);
91
            $tags['POST_URL'] = $tags['THREAD_URL'] . '#forumpost' . $postObject->getVar('post_id');
92
            $notificationHandler->triggerEvent('thread', $id, 'new_post', $tags);
93
            $notificationHandler->triggerEvent('forum', $topicObject->getVar('forum_id'), 'new_post', $tags);
94
            $notificationHandler->triggerEvent('global', 0, 'new_post', $tags);
95
            $tags['POST_CONTENT'] = $postObject->getVar('post_text');
96
            $tags['POST_NAME']    = $postObject->getVar('subject');
97
            $notificationHandler->triggerEvent('global', 0, 'new_fullpost', $tags);
98
            $notificationHandler->triggerEvent('forum', $topicObject->getVar('forum_id'), 'new_fullpost', $tags);
99
            unset($postObject);
100
        }
101
        unset($topicsObject, $forumsObject);
102
        break;
103 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...
104
        $forums     = [];
105
        /** @var \NewbbTopicHandler|XoopsPersistableObjectHandler $topicHandler */
106
        $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...
107
        foreach (array_keys($topicsObject) as $id) {
108
            /** @var Topic $topicObject */
109
            $topicObject = $topicsObject[$id];
110
            // irmtfan should be set to false to not delete topic from database
111
            $topicHandler->delete($topicObject, false);
112
            $topicHandler->synchronization($topicObject);
113
            $forums[$topicObject->getVar('forum_id')] = 1;
114
        }
115
116
        $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...
117
        $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...
118
        foreach (array_keys($forumsObject) as $id) {
119
            $forumHandler->synchronization($forumsObject[$id]);
120
        }
121
        unset($topicsObject, $forumsObject);
122
        break;
123
    case 'move':
124
        if (Request::getInt('newforum', 0, 'POST')
125
            && 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...
126
            && $forumHandler->getPermission(Request::getInt('newforum', 0, 'POST'), 'post')) {
127
            $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...
128
//            /** @var \NewbbPostHandler $postHandler */
0 ignored issues
show
Unused Code Comprehensibility introduced by
42% 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...
129
//            $postHandler = xoops_getModuleHandler('post', 'newbb');
130
            $postHandler->updateAll('forum_id', Request::getInt('newforum', 0, 'POST'), $criteria, true);
131
            $topicHandler->updateAll('forum_id', Request::getInt('newforum', 0, 'POST'), $criteria, true);
132
            $forumHandler->synchronization(Request::getInt('newforum', 0, 'POST'));
133
            $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...
134
        } else {
135
            include $GLOBALS['xoops']->path('header.php');
136
//            /** @var \NewbbCategoryHandler $categoryHandler */
0 ignored issues
show
Unused Code Comprehensibility introduced by
42% 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...
137
//            $categoryHandler = xoops_getModuleHandler('category', 'newbb');
138
            $categories      = $categoryHandler->getByPermission('access');
139
            $forums          = $forumHandler->getForumsByCategory(array_keys($categories), 'post', false);
140
141
            $box = '<select name="newforum" size="1">';
142 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...
143
                foreach (array_keys($forums) as $key) {
144
145
                    /** @var \NewbbCategory[] $categories */
146
                    $box .= "<option value='-1'>[" . $categories[$key]->getVar('cat_title') . ']</option>';
147
                    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...
148
                        $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...
149
                        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...
150
                            continue;
151
                        }
152
                        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...
153
                            $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...
154
                        }
155
                    }
156
                }
157
            } else {
158
                $box .= "<option value='-1'>" . _MD_NEWBB_NOFORUMINDB . '</option>';
159
            }
160
            $box .= '</select>';
161
            unset($forums, $categories);
162
163
            echo "<form action='" . Request::getString('PHP_SELF', '', 'SERVER') . "' method='post'>";
164
            echo "<table border='0' cellpadding='1' cellspacing='0' align='center' width='95%'>";
165
            echo "<tr><td class='bg2'>";
166
            echo "<table border='0' cellpadding='1' cellspacing='1' width='100%'>";
167
            echo '<tr><td class="bg3">' . _MD_NEWBB_MOVETOPICTO . '</td><td class="bg1">';
168
            echo $box;
169
            echo '</td></tr>';
170
            echo '<tr class="bg3"><td colspan="2" align="center">';
171
            echo "<input type='hidden' name='op' value='move' />";
172
            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...
173
            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...
174
                echo "<input type='hidden' name='topic_id[]' value='" . $id . "' />";
175
            }
176
            echo "<input type='submit' name='submit' value='" . _SUBMIT . "' />";
177
            echo '</td></tr></table></td></tr></table>';
178
            echo '</form>';
179
            include $GLOBALS['xoops']->path('footer.php');
180
            exit();
181
        }
182
        break;
183
}
184
///** @var \NewbbStatsHandler $statsHandler */
0 ignored issues
show
Unused Code Comprehensibility introduced by
54% 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...
185
//$statsHandler = xoops_getModuleHandler('stats', 'newbb');
186
$statsHandler->reset();
187
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...
188
    redirect_header(XOOPS_URL . '/modules/newbb/list.topic.php', 2, _MD_NEWBB_DBUPDATED);
189
} else {
190
    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...
191
}
192
// irmtfan move to footer.php
193
include_once __DIR__ . '/footer.php';
194
include $GLOBALS['xoops']->path('footer.php');
195