Test Failed
Pull Request — master (#60)
by
unknown
03:05
created

edit.php (42 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 View Code Duplication
foreach (['forum', 'topic_id', 'post_id', 'order'] as $getint) {
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...
17
    ${$getint} = Request::getInt($getint, 0, 'GET');
18
}
19
20 View Code Duplication
if (!$topic_id && !$post_id) {
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...
$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...
21
    $redirect = empty($forum) ? 'index.php' : "viewforum.php?forum={$forum}";
22
    redirect_header($redirect, 2, _MD_NEWBB_ERRORTOPIC);
23
}
24
25
///** @var \NewbbForumHandler $forumHandler */
26
//$forumHandler = xoops_getModuleHandler('forum', 'newbb');
27
///** @var \NewbbTopicHandler $topicHandler */
28
//$topicHandler = xoops_getModuleHandler('topic', 'newbb');
29
///** @var \NewbbPostHandler $postHandler */
30
//$postHandler = xoops_getModuleHandler('post', 'newbb');
31
32
/** @var \NewbbPost $postObject */
33
$postObject  = $postHandler->get($post_id);
0 ignored issues
show
$post_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
$topicObject = $topicHandler->get($postObject->getVar('topic_id'));
35
$forumObject = $forumHandler->get($postObject->getVar('forum_id'));
36
if (!$forumHandler->getPermission($forumObject)) {
37
    redirect_header('index.php', 2, _MD_NEWBB_NORIGHTTOACCESS);
38
}
39
40
if ($GLOBALS['xoopsModuleConfig']['wol_enabled']) {
41
//    /** @var \NewbbOnlineHandler $onlineHandler */
42
//    $onlineHandler = xoops_getModuleHandler('online', 'newbb');
43
    $onlineHandler->init($forumObject);
44
}
45
$isAdmin = newbbIsAdmin($forumObject);
46
$uid     = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getVar('uid') : 0;
47
48
$topic_id     = $postObject->getVar('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...
49
$topic_status = $topicObject->getVar('topic_status');
0 ignored issues
show
$topic_status 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
$error_msg    = null;
0 ignored issues
show
$error_msg 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
52
if (!$topicHandler->getPermission($forumObject, $topic_status, 'edit') || (!$isAdmin && !$postObject->checkIdentity())) {
0 ignored issues
show
$topic_status 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...
53
    $error_msg = _MD_NEWBB_NORIGHTTOEDIT;
0 ignored issues
show
$error_msg 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...
54
} elseif (!$isAdmin && !$postObject->checkTimelimit('edit_timelimit')) {
55
    $error_msg = _MD_NEWBB_TIMEISUP;
0 ignored issues
show
$error_msg 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...
56
}
57
58
if (!empty($error_msg)) {
0 ignored issues
show
$error_msg 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
    /*
60
     * Build the page query
61
     */
62
    $query_vars  = ['topic_id', 'post_id', 'forum', 'status', 'order', 'mode', 'viewmode'];
0 ignored issues
show
$query_vars 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...
63
    $query_array = [];
0 ignored issues
show
$query_array 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...
64
    foreach ($query_vars as $var) {
0 ignored issues
show
$query_vars 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...
65
        if (Request::getString($var, '', 'GET')) {
66
            $query_array[$var] = "{$var}=" . Request::getString($var, '', 'GET');
0 ignored issues
show
$query_array 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...
67
        }
68
    }
69
    $page_query = htmlspecialchars(implode('&', array_values($query_array)));
0 ignored issues
show
$page_query 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
    unset($query_array);
0 ignored issues
show
$query_array 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...
71
    redirect_header("viewtopic.php?{$page_query}", 2, $error_msg);
0 ignored issues
show
$page_query 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...
72
}
73
74
if ($GLOBALS['xoopsModuleConfig']['wol_enabled']) {
75
//    $onlineHandler = xoops_getModuleHandler('online', 'newbb');
76
    $onlineHandler->init($forumObject);
77
}
78
79
$xoopsOption['template_main']                                        = 'newbb_edit_post.tpl';
80
$GLOBALS['xoopsConfig']['module_cache'][$xoopsModule->getVar('mid')] = 0;
81
// irmtfan include header.php after defining $xoopsOption['template_main']
82
include_once $GLOBALS['xoops']->path('header.php');
83
84
/*
85
$xoopsTpl->assign('lang_forum_index', sprintf(_MD_NEWBB_FORUMINDEX, htmlspecialchars($GLOBALS['xoopsConfig']['sitename'], ENT_QUOTES)));
86
87
$categoryHandler = xoops_getModuleHandler("category");
88
$categoryObject = $categoryHandler->get($forumObject->getVar('cat_id'), array("cat_title"));
89
$xoopsTpl->assign('category', array("id" => $forumObject->getVar('cat_id'), "title" => $categoryObject->getVar('cat_title')));
90
91
$form_title = _EDIT.": <a href=\"viewtopic.php?post_id={$post_id}\">".$postObject->getVar('subject');
92
$xoopsTpl->assign("form_title", $form_title);
93
94
$xoopsTpl->assign("parentforum", $forumHandler->getParents($forumObject));
95
96
$xoopsTpl->assign(array(
97
    'forum_id'             => $forumObject->getVar('forum_id'),
98
    'forum_name'         => $forumObject->getVar('forum_name'),
99
    ));
100
*/
101
102
$dohtml        = $postObject->getVar('dohtml');
103
$dosmiley      = $postObject->getVar('dosmiley');
104
$doxcode       = $postObject->getVar('doxcode');
105
$dobr          = $postObject->getVar('dobr');
106
$icon          = $postObject->getVar('icon');
107
$attachsig     = $postObject->getVar('attachsig');
108
$istopic       = $postObject->isTopic() ? 1 : 0;
109
$isedit        = 1;
110
$subject       = $postObject->getVar('subject', 'E');
111
$message       = $postObject->getVar('post_text', 'E');
112
$poster_name   = $postObject->getVar('poster_name', 'E');
0 ignored issues
show
$poster_name 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...
113
$attachments   = $postObject->getAttachment();
114
$post_karma    = $postObject->getVar('post_karma');
0 ignored issues
show
$post_karma 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...
115
$require_reply = $postObject->getVar('require_reply');
0 ignored issues
show
$require_reply 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...
116
117
$xoopsTpl->assign('error_message', _MD_NEWBB_EDITEDBY . ' ' . $GLOBALS['xoopsUser']->uname());
118
include __DIR__ . '/include/form.post.php';
119
120
///** @var \NewbbKarmaHandler $karmaHandler */
121
//$karmaHandler = xoops_getModuleHandler('karma', 'newbb');
122
$user_karma   = $karmaHandler->getUserKarma();
0 ignored issues
show
$user_karma 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...
123
124
$posts_context     = [];
0 ignored issues
show
$posts_context 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...
125
$posts_contextObject = $istopic ? [] : [$postHandler->get($postObject->getVar('pid'))];
0 ignored issues
show
$posts_contextObject 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 View Code Duplication
foreach ($posts_contextObject as $post_contextObject) {
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...
$posts_contextObject 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
    if ($GLOBALS['xoopsModuleConfig']['enable_karma'] && $post_contextObject->getVar('post_karma') > 0) {
0 ignored issues
show
$post_contextObject 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
        $p_message = sprintf(_MD_NEWBB_KARMA_REQUIREMENT, '***', $post_contextObject->getVar('post_karma')) . '</div>';
0 ignored issues
show
$p_message 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
    } elseif ($GLOBALS['xoopsModuleConfig']['allow_require_reply'] && $post_contextObject->getVar('require_reply')) {
0 ignored issues
show
$post_contextObject 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...
130
        $p_message = _MD_NEWBB_REPLY_REQUIREMENT;
0 ignored issues
show
$p_message 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...
131
    } else {
132
        $p_message = $post_contextObject->getVar('post_text');
0 ignored issues
show
$p_message 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...
133
    }
134
135
    if ($post_contextObject->getVar('uid')) {
0 ignored issues
show
$post_contextObject 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...
136
        $p_name = newbbGetUnameFromId($post_contextObject->getVar('uid'), $GLOBALS['xoopsModuleConfig']['show_realname']);
0 ignored issues
show
$p_name 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...
137
    } else {
138
        $poster_name = $post_contextObject->getVar('poster_name');
0 ignored issues
show
$poster_name 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...
139
        $p_name      = empty($poster_name) ? htmlspecialchars($GLOBALS['xoopsConfig']['anonymous']) : $poster_name;
0 ignored issues
show
$p_name 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...
140
    }
141
    $p_date    = formatTimestamp($post_contextObject->getVar('post_time'));
0 ignored issues
show
$p_date 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...
142
    $p_subject = $post_contextObject->getVar('subject');
0 ignored issues
show
$p_subject 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...
143
144
    $posts_context[] = [
0 ignored issues
show
$posts_context 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...
145
        'subject' => $p_subject,
0 ignored issues
show
$p_subject 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...
146
        'meta'    => _MD_NEWBB_BY . ' ' . $p_name . ' ' . _MD_NEWBB_ON . ' ' . $p_date,
0 ignored issues
show
$p_name 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...
147
        'content' => $p_message
0 ignored issues
show
$p_message 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
    ];
149
}
150
$xoopsTpl->assign_by_ref('posts_context', $posts_context);
0 ignored issues
show
$posts_context 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
// irmtfan move to footer.php
152
include_once __DIR__ . '/footer.php';
153
include $GLOBALS['xoops']->path('footer.php');
154