Completed
Branch master (61995d)
by Michael
11:22 queued 08:18
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 (http://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) {
17
    ${$getint} = Request::getInt($getint, 0, 'GET');
18
}
19
20 View Code Duplication
if (!$topic_id && !$post_id) {
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 $post_obj */
33
$post_obj  = $postHandler->get($post_id);
34
$topic_obj = $topicHandler->get($post_obj->getVar('topic_id'));
35
$forum_obj = $forumHandler->get($post_obj->getVar('forum_id'));
36
if (!$forumHandler->getPermission($forum_obj)) {
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($forum_obj);
44
}
45
$isadmin = newbb_isAdmin($forum_obj);
46
$uid     = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getVar('uid') : 0;
47
48
$topic_id     = $post_obj->getVar('topic_id');
49
$topic_status = $topic_obj->getVar('topic_status');
50
$error_msg    = null;
51
52
if (!$topicHandler->getPermission($forum_obj, $topic_status, 'edit') || (!$isadmin && !$post_obj->checkIdentity())) {
53
    $error_msg = _MD_NEWBB_NORIGHTTOEDIT;
54
} elseif (!$isadmin && !$post_obj->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($forum_obj);
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
$category_obj = $categoryHandler->get($forum_obj->getVar('cat_id'), array("cat_title"));
89
$xoopsTpl->assign('category', array("id" => $forum_obj->getVar('cat_id'), "title" => $category_obj->getVar('cat_title')));
90
91
$form_title = _EDIT.": <a href=\"viewtopic.php?post_id={$post_id}\">".$post_obj->getVar('subject');
92
$xoopsTpl->assign("form_title", $form_title);
93
94
$xoopsTpl->assign("parentforum", $forumHandler->getParents($forum_obj));
95
96
$xoopsTpl->assign(array(
97
    'forum_id'             => $forum_obj->getVar('forum_id'),
98
    'forum_name'         => $forum_obj->getVar('forum_name'),
99
    ));
100
*/
101
102
$dohtml        = $post_obj->getVar('dohtml');
103
$dosmiley      = $post_obj->getVar('dosmiley');
104
$doxcode       = $post_obj->getVar('doxcode');
105
$dobr          = $post_obj->getVar('dobr');
106
$icon          = $post_obj->getVar('icon');
107
$attachsig     = $post_obj->getVar('attachsig');
108
$istopic       = $post_obj->isTopic() ? 1 : 0;
109
$isedit        = 1;
110
$subject       = $post_obj->getVar('subject', 'E');
111
$message       = $post_obj->getVar('post_text', 'E');
112
$poster_name   = $post_obj->getVar('poster_name', 'E');
113
$attachments   = $post_obj->getAttachment();
114
$post_karma    = $post_obj->getVar('post_karma');
115
$require_reply = $post_obj->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_context_obj = $istopic ? [] : [$postHandler->get($post_obj->getVar('pid'))];
126 View Code Duplication
foreach ($posts_context_obj as $post_context_obj) {
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_context_obj->getVar('post_karma') > 0) {
128
        $p_message = sprintf(_MD_NEWBB_KARMA_REQUIREMENT, '***', $post_context_obj->getVar('post_karma')) . '</div>';
129
    } elseif ($GLOBALS['xoopsModuleConfig']['allow_require_reply'] && $post_context_obj->getVar('require_reply')) {
130
        $p_message = _MD_NEWBB_REPLY_REQUIREMENT;
131
    } else {
132
        $p_message = $post_context_obj->getVar('post_text');
133
    }
134
135
    if ($post_context_obj->getVar('uid')) {
136
        $p_name = newbb_getUnameFromId($post_context_obj->getVar('uid'), $GLOBALS['xoopsModuleConfig']['show_realname']);
137
    } else {
138
        $poster_name = $post_context_obj->getVar('poster_name');
139
        $p_name      = empty($poster_name) ? htmlspecialchars($GLOBALS['xoopsConfig']['anonymous']) : $poster_name;
140
    }
141
    $p_date    = formatTimestamp($post_context_obj->getVar('post_time'));
142
    $p_subject = $post_context_obj->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