Completed
Push — master ( 79fdd3...3fb69b )
by Michael
12s
created

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...
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);
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');
49
$topic_status = $topicObject->getVar('topic_status');
50
$error_msg    = null;
51
52
if (!$topicHandler->getPermission($forumObject, $topic_status, 'edit') || (!$isAdmin && !$postObject->checkIdentity())) {
53
    $error_msg = _MD_NEWBB_NORIGHTTOEDIT;
54
} elseif (!$isAdmin && !$postObject->checkTimelimit('edit_timelimit')) {
55
    $error_msg = _MD_NEWBB_TIMEISUP;
56
}
57
58
if (!empty($error_msg)) {
59
    /*
60
     * Build the page query
61
     */
62
    $query_vars  = ['topic_id', 'post_id', 'forum', 'status', 'order', 'mode', 'viewmode'];
63
    $query_array = [];
64
    foreach ($query_vars as $var) {
65
        if (Request::getString($var, '', 'GET')) {
66
            $query_array[$var] = "{$var}=" . Request::getString($var, '', 'GET');
67
        }
68
    }
69
    $page_query = htmlspecialchars(implode('&', array_values($query_array)));
70
    unset($query_array);
71
    redirect_header("viewtopic.php?{$page_query}", 2, $error_msg);
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
/*
0 ignored issues
show
Unused Code Comprehensibility introduced by
65% 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...
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');
113
$attachments   = $postObject->getAttachment();
114
$post_karma    = $postObject->getVar('post_karma');
115
$require_reply = $postObject->getVar('require_reply');
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();
123
124
$posts_context     = [];
125
$posts_contextObject = $istopic ? [] : [$postHandler->get($postObject->getVar('pid'))];
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...
127
    if ($GLOBALS['xoopsModuleConfig']['enable_karma'] && $post_contextObject->getVar('post_karma') > 0) {
128
        $p_message = sprintf(_MD_NEWBB_KARMA_REQUIREMENT, '***', $post_contextObject->getVar('post_karma')) . '</div>';
129
    } elseif ($GLOBALS['xoopsModuleConfig']['allow_require_reply'] && $post_contextObject->getVar('require_reply')) {
130
        $p_message = _MD_NEWBB_REPLY_REQUIREMENT;
131
    } else {
132
        $p_message = $post_contextObject->getVar('post_text');
133
    }
134
135
    if ($post_contextObject->getVar('uid')) {
136
        $p_name = newbbGetUnameFromId($post_contextObject->getVar('uid'), $GLOBALS['xoopsModuleConfig']['show_realname']);
137
    } else {
138
        $poster_name = $post_contextObject->getVar('poster_name');
139
        $p_name      = empty($poster_name) ? htmlspecialchars($GLOBALS['xoopsConfig']['anonymous']) : $poster_name;
140
    }
141
    $p_date    = formatTimestamp($post_contextObject->getVar('post_time'));
142
    $p_subject = $post_contextObject->getVar('subject');
143
144
    $posts_context[] = [
145
        'subject' => $p_subject,
146
        'meta'    => _MD_NEWBB_BY . ' ' . $p_name . ' ' . _MD_NEWBB_ON . ' ' . $p_date,
147
        'content' => $p_message
148
    ];
149
}
150
$xoopsTpl->assign_by_ref('posts_context', $posts_context);
151
// irmtfan move to footer.php
152
include_once __DIR__ . '/footer.php';
153
include $GLOBALS['xoops']->path('footer.php');
154