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

reply.php (7 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
//  ------------------------------------------------------------------------ //
4
//                XOOPS - PHP Content Management System                      //
5
//                  Copyright (c) 2000-2016 XOOPS.org                        //
6
//                       <https://xoops.org/>                             //
7
//  ------------------------------------------------------------------------ //
8
//  This program is free software; you can redistribute it and/or modify     //
9
//  it under the terms of the GNU General Public License as published by     //
10
//  the Free Software Foundation; either version 2 of the License, or        //
11
//  (at your option) any later version.                                      //
12
//                                                                           //
13
//  You may not change or alter any portion of this comment or credits       //
14
//  of supporting developers from this source code or any supporting         //
15
//  source code which is considered copyrighted (c) material of the          //
16
//  original comment or credit authors.                                      //
17
//                                                                           //
18
//  This program is distributed in the hope that it will be useful,          //
19
//  but WITHOUT ANY WARRANTY; without even the implied warranty of           //
20
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
21
//  GNU General Public License for more details.                             //
22
//                                                                           //
23
//  You should have received a copy of the GNU General Public License        //
24
//  along with this program; if not, write to the Free Software              //
25
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
26
//  ------------------------------------------------------------------------ //
27
//  Author: phppp (D.J., [email protected])                                  //
28
//  URL: https://xoops.org                                                    //
29
//  Project: Article Project                                                 //
30
//  ------------------------------------------------------------------------ //
31
32
use Xmf\Request;
33
34
include_once __DIR__ . '/header.php';
35
36
$forum    = Request::getInt('forum', 0, 'GET');
37
$topic_id = Request::getInt('topic_id', 0, 'GET');
38
$post_id  = Request::getInt('post_id', 0, 'GET');
39
$order    = Request::getInt('order', 0, 'GET');
40
$start    = Request::getInt('start', 0, 'GET');
41
42 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...
43
    $redirect = empty($forum) ? 'index.php' : "viewforum.php?forum={$forum}";
44
    redirect_header($redirect, 2, _MD_NEWBB_ERRORTOPIC);
45
}
46
47
/** @var NewbbForumHandler $forumHandler */
48
$forumHandler = xoops_getModuleHandler('forum', 'newbb');
49
/** @var NewbbTopicHandler $topicHandler */
50
$topicHandler = xoops_getModuleHandler('topic', 'newbb');
51
/** @var NewbbPostHandler $postHandler */
52
$postHandler = xoops_getModuleHandler('post', 'newbb');
53
54
if (!$pid = $post_id) {
55
    $pid = $topicHandler->getTopPostId($topic_id);
56
}
57
$postParentObject = $postHandler->get($pid);
58
$topic_id        = $postParentObject->getVar('topic_id');
59
$forum           = $postParentObject->getVar('forum_id');
60
$postObject        = $postHandler->create();
61
$postObject->setVar('pid', $pid);
62
$postObject->setVar('topic_id', $topic_id);
63
$postObject->setVar('forum_id', $forum);
64
65
$forumObject = $forumHandler->get($forum);
66
if (!$forumHandler->getPermission($forumObject)) {
67
    redirect_header(XOOPS_URL . '/index.php', 2, _MD_NEWBB_NORIGHTTOACCESS);
68
}
69
70
$topicObject    = $topicHandler->get($topic_id);
71
$topic_status = $topicObject->getVar('topic_status');
72 View Code Duplication
if (!$topicHandler->getPermission($forumObject, $topic_status, 'reply')) {
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...
73
    /*
74
     * Build the page query
75
     */
76
    $query_vars  = ['topic_id', 'post_id', 'status', 'order', 'mode', 'viewmode'];
77
    $query_array = [];
78
    foreach ($query_vars as $var) {
79
        if (Request::getString($var, '', 'GET')) {
80
            $query_array[$var] = "{$var}=" . Request::getString($var, '', 'GET');
81
        }
82
    }
83
    $page_query = htmlspecialchars(implode('&', array_values($query_array)));
84
    unset($query_array);
85
86
    redirect_header("viewtopic.php?{$page_query}", 2, _MD_NEWBB_NORIGHTTOREPLY);
87
}
88
89
if ($GLOBALS['xoopsModuleConfig']['wol_enabled']) {
90
    /** @var NewbbOnlineHandler $onlineHandler */
91
    $onlineHandler = xoops_getModuleHandler('online', 'newbb');
92
    $onlineHandler->init($forumObject);
93
}
94
95
$xoopsOption['template_main']                                        = 'newbb_edit_post.tpl';
96
$GLOBALS['xoopsConfig']['module_cache'][$xoopsModule->getVar('mid')] = 0;
97
// irmtfan remove and move to footer.php
98
//$xoopsOption['xoops_module_header']= $xoops_module_header;
99
// irmtfan include header.php after defining $xoopsOption['template_main']
100
include_once $GLOBALS['xoops']->path('header.php');
101
//$xoopsTpl->assign('xoops_module_header', $xoops_module_header);
0 ignored issues
show
Unused Code Comprehensibility introduced by
80% 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...
102
103
/*
0 ignored issues
show
Unused Code Comprehensibility introduced by
64% 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...
104
$xoopsTpl->assign('lang_forum_index', sprintf(_MD_NEWBB_FORUMINDEX, htmlspecialchars($GLOBALS['xoopsConfig']['sitename'], ENT_QUOTES)));
105
106
$categoryHandler = xoops_getModuleHandler("category");
107
$categoryObject = $categoryHandler->get($forumObject->getVar("cat_id"), array("cat_title"));
108
$xoopsTpl->assign('category', array("id" => $forumObject->getVar("cat_id"), "title" => $categoryObject->getVar('cat_title')));
109
110
$form_title = _MD_NEWBB_REPLY.": <a href=\"viewtopic.php?topic_id={$topic_id}\">".$topicObject->getVar("topic_title");
111
$xoopsTpl->assign("form_title", $form_title);
112
*/
113
114 View Code Duplication
if ((2 == $GLOBALS['xoopsModuleConfig']['disc_show']) || (3 == $GLOBALS['xoopsModuleConfig']['disc_show'])) {
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...
115
    $xoopsTpl->assign('disclaimer', $GLOBALS['xoopsModuleConfig']['disclaimer']);
116
}
117
118
$xoopsTpl->assign('parentforum', $forumHandler->getParents($forumObject));
119
120
$xoopsTpl->assign([
121
                      'forum_id'   => $forumObject->getVar('forum_id'),
122
                      'forum_name' => $forumObject->getVar('forum_name')
123
                  ]);
124
125
if ($postParentObject->getVar('uid')) {
126
    $r_name = newbbGetUnameFromId($postParentObject->getVar('uid'), $GLOBALS['xoopsModuleConfig']['show_realname']);
127
} else {
128
    $poster_name = $postParentObject->getVar('poster_name');
129
    $r_name      = empty($poster_name) ? $myts->htmlSpecialChars($GLOBALS['xoopsConfig']['anonymous']) : $poster_name;
130
}
131
132
$r_subject = $postParentObject->getVar('subject', 'E');
133
134
$subject = $r_subject;
135
if (!preg_match('/^(Re|' . _MD_NEWBB_RE . '):/i', $r_subject)) {
136
    $subject = _MD_NEWBB_RE . ': ' . $r_subject;
137
}
138
139
$q_message = $postParentObject->getVar('post_text', 'e');
140
if ((!$GLOBALS['xoopsModuleConfig']['enable_karma'] || !$postParentObject->getVar('post_karma'))
141
    && (!$GLOBALS['xoopsModuleConfig']['allow_require_reply'] || !$postParentObject->getVar('require_reply'))) {
142
    if (1 === Request::getInt('quotedac', 0, 'GET')) {
143
        $message = "[quote]\n";
144
        $message .= sprintf(_MD_NEWBB_USERWROTE, $r_name);
145
        $message .= "\n" . $q_message . '[/quote]';
146
        $hidden  = '';
147
    } else {
148
        $hidden  = "[quote]\n";
149
        $hidden  .= sprintf(_MD_NEWBB_USERWROTE, $r_name);
150
        $hidden  .= "\n" . $q_message . '[/quote]';
151
        $message = '';
152
    }
153
} else {
154
    $hidden  = '';
155
    $message = '';
156
}
157
158
$isreply       = 1;
159
$istopic       = 0;
160
$dohtml        = 1;
161
$dosmiley      = 1;
162
$doxcode       = 1;
163
$dobr          = 1;
164
$icon          = '';
165
$attachsig     = (is_object($GLOBALS['xoopsUser']) && $GLOBALS['xoopsUser']->getVar('attachsig')) ? 1 : 0;
166
$post_karma    = 0;
167
$require_reply = 0;
168
169
include __DIR__ . '/include/form.post.php';
170
171
/** @var \NewbbKarmaHandler $karmaHandler */
172
$karmaHandler = xoops_getModuleHandler('karma', 'newbb');
173
$user_karma   = $karmaHandler->getUserKarma();
174
175
$posts_context = [];
176
//$posts_contextObject = $postHandler->getByLimit($topic_id, 5); //mb
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% 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...
177
$posts_contextObject = $postHandler->getByLimit(5, 0, null, null, true, $topic_id, 1);
178
/** @var \NewbbPost $post_contextObject */
179 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...
180
    // Sorry, in order to save queries, we have to hide the non-open post_text even if you have replied or have adequate karma, even an admin.
181
    if ($GLOBALS['xoopsModuleConfig']['enable_karma'] && $post_contextObject->getVar('post_karma') > 0) {
182
        $p_message = sprintf(_MD_NEWBB_KARMA_REQUIREMENT, '***', $post_contextObject->getVar('post_karma')) . '</div>';
183
    } elseif ($GLOBALS['xoopsModuleConfig']['allow_require_reply'] && $post_contextObject->getVar('require_reply')) {
184
        $p_message = _MD_NEWBB_REPLY_REQUIREMENT;
185
    } else {
186
        $p_message = $post_contextObject->getVar('post_text');
187
    }
188
189
    if ($post_contextObject->getVar('uid')) {
190
        $p_name = newbbGetUnameFromId($post_contextObject->getVar('uid'), $GLOBALS['xoopsModuleConfig']['show_realname']);
191
    } else {
192
        $poster_name = $post_contextObject->getVar('poster_name');
193
        $p_name      = empty($poster_name) ? htmlspecialchars($GLOBALS['xoopsConfig']['anonymous']) : $poster_name;
194
    }
195
    $p_date    = formatTimestamp($post_contextObject->getVar('post_time'));
196
    $p_subject = $post_contextObject->getVar('subject');
197
198
    $posts_context[] = [
199
        'subject' => $p_subject,
200
        'meta'    => _MD_NEWBB_BY . ' ' . $p_name . ' ' . _MD_NEWBB_ON . ' ' . $p_date,
201
        'content' => $p_message
202
    ];
203
}
204
$xoopsTpl->assign_by_ref('posts_context', $posts_context);
205
// irmtfan move to footer.php
206
include_once __DIR__ . '/footer.php';
207
include $GLOBALS['xoops']->path('footer.php');
208