Completed
Push — master ( a88ff3...0a3d23 )
by Michael
14s
created

delete.php (27 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
$ok = Request::getInt('ok', 0, 'POST');
17
18
foreach (['forum', 'topic_id', 'post_id', 'order', 'pid', 'act'] as $getint) {
19
    ${$getint} = Request::getInt($getint, 0, 'POST');
20
}
21
22 View Code Duplication
foreach (['forum', 'topic_id', 'post_id', 'order', 'pid', 'act'] 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...
23
    ${$getint} = !empty(${$getint}) ? ${$getint} : Request::getInt($getint, 0, 'GET');
24
}
25
//$viewmode = (isset($_GET['viewmode']) && $_GET['viewmode'] !== 'flat') ? 'thread' : 'flat';
0 ignored issues
show
Unused Code Comprehensibility introduced by
69% 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...
26
//$viewmode = ($viewmode) ? $viewmode: (isset($_POST['viewmode'])?$_POST['viewmode'] : 'flat');
27
28
$viewmode = (Request::getString('viewmode', '', 'GET')
29
             && 'flat' !== Request::getString('viewmode', '', 'GET')) ? 'thread' : 'flat';
30
$viewmode = $viewmode ?: (Request::getString('viewmode', '', 'POST') ?: 'flat');
31
32
///** @var \NewbbForumHandler $forumHandler */
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...
33
//$forumHandler = xoops_getModuleHandler('forum', 'newbb');
34
///** @var \NewbbTopicHandler $topicHandler */
35
//$topicHandler = xoops_getModuleHandler('topic', 'newbb');
36
///** @var \NewbbPostHandler $postHandler */
37
//$postHandler = xoops_getModuleHandler('post', 'newbb');
38
39
if (!empty($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...
40
    $topic = $topicHandler->getByPost($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...
41
} else {
42
    $topic = $topicHandler->get($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...
43
}
44
$topic_id = $topic->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...
45 View Code Duplication
if (!$topic_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...
46
    $redirect = empty($forum) ? 'index.php' : 'viewforum.php?forum=' . $forum;
47
    $redirect = XOOPS_URL . '/modules/newbb/' . $redirect;
48
    redirect_header($redirect, 2, _MD_NEWBB_ERRORTOPIC);
49
}
50
51
$forum     = $topic->getVar('forum_id');
52
$forumObject = $forumHandler->get($forum);
53
if (!$forumHandler->getPermission($forumObject)) {
54
    redirect_header(XOOPS_URL . '/index.php', 2, _MD_NEWBB_NORIGHTTOACCESS);
55
}
56
57
$isAdmin = newbbIsAdmin($forumObject);
58
$uid     = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getVar('uid') : 0;
59
60
/** @var NewbbPost $postObject */
61
$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...
62
$topic_status = $topic->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...
63
if (($postObject->checkIdentity() || $isAdmin)
0 ignored issues
show
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
64
    && $topicHandler->getPermission($topic->getVar('forum_id'), $topic_status, 'delete')) {
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...
65
} else {
66
    redirect_header(XOOPS_URL . "/modules/newbb/viewtopic.php?topic_id=$topic_id&amp;pid=$pid&amp;forum=$forum", 2, _MD_NEWBB_DELNOTALLOWED);
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...
67
}
68
69
if (!$isAdmin && !$postObject->checkTimelimit('delete_timelimit')) {
70
    redirect_header(XOOPS_URL . "/modules/newbb/viewtopic.php?forum=$forum&amp;topic_id=$topic_id&amp;post_id=$post_id&amp;pid=$pid", 2, _MD_NEWBB_TIMEISUPDEL);
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...
71
}
72
73
if ($GLOBALS['xoopsModuleConfig']['wol_enabled']) {
74
//    /** @var \NewbbOnlineHandler $onlineHandler */
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...
75
//    $onlineHandler = xoops_getModuleHandler('online', 'newbb');
76
    $onlineHandler->init($forumObject);
77
}
78
79
if ($ok) {
80
    $isDeleteOne = (1 === $ok);
81
    if ($postObject->isTopic() && 0 == $topic->getVar('topic_replies')) {
82
        $isDeleteOne = false;
83
    }
84
    if ($isDeleteOne && $postObject->isTopic() && $topic->getVar('topic_replies') > 0) {
85
        //$postHandler->emptyTopic($postObject);
0 ignored issues
show
Unused Code Comprehensibility introduced by
86% 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...
86
        redirect_header(XOOPS_URL . "/modules/newbb/viewtopic.php?topic_id=$topic_id&amp;pid=$pid&amp;forum=$forum", 2, _MD_NEWBB_POSTFIRSTWITHREPLYNODELETED);
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...
87
    } else {
88
        if (Request::getString('post_text', '', 'POST')) {
89
            //send a message
90
            /** @var \XoopsMemberHandler $memberHandler */
91
            $memberHandler = xoops_getHandler('member');
92
            $senduser      = $memberHandler->getUser($postObject->getVar('uid'));
93
            if ($senduser->getVar('notify_method') > 0) {
94
                $xoopsMailer = xoops_getMailer();
95
                $xoopsMailer->reset();
96
                if (1 == $senduser->getVar('notify_method')) {
97
                    $xoopsMailer->usePM();
98
                } else {
99
                    $xoopsMailer->useMail();
100
                }
101
                $xoopsMailer->setHTML(true);
102
                $xoopsMailer->setToUsers($senduser);
103
                $xoopsMailer->setFromName($GLOBALS['xoopsUser']->getVar('uname'));
104
                $xoopsMailer->setSubject(_MD_NEWBB_DELEDEDMSG_SUBJECT);
105
                $forenurl = '<a href="' . XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/viewtopic.php?topic_id=' . $postObject->getVar('topic_id') . '">' . $postObject->getVar('subject') . '</a>';
106
                if (!empty($GLOBALS['xoopsModuleConfig']['do_rewrite'])) {
107
                    $forenurl = seo_urls($forenurl);
108
                }
109
                $body = sprintf(_MD_NEWBB_DELEDEDMSG_BODY, $senduser->getVar('uname'), $forenurl, Request::getString('post_text', '', 'POST'), $GLOBALS['xoopsUser']->getVar('uname'), $GLOBALS['xoopsConfig']['sitename'], XOOPS_URL . '/');
110
                $body = $myts->nl2Br($body);
111
                $xoopsMailer->setBody($body);
112
                $xoopsMailer->send();
113
            }
114
        }
115
        $postHandler->delete($postObject, $isDeleteOne);
116
        $forumHandler->synchronization($forum);
117
        $topicHandler->synchronization($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...
118
//        /** @var \NewbbStatsHandler $statsHandler */
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...
119
//        $statsHandler = xoops_getModuleHandler('stats', 'newbb');
120
        $statsHandler->reset();
121
    }
122
123
    //$postObject->loadFilters('delete');
0 ignored issues
show
Unused Code Comprehensibility introduced by
86% 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...
124
    if ($isDeleteOne) {
125
        redirect_header(XOOPS_URL . "/modules/newbb/viewtopic.php?topic_id=$topic_id&amp;order=$order&amp;viewmode=$viewmode&amp;pid=$pid&amp;forum=$forum", 2, _MD_NEWBB_POSTDELETED);
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...
126
    } else {
127
        redirect_header(XOOPS_URL . "/modules/newbb/viewforum.php?forum=$forum", 2, _MD_NEWBB_POSTSDELETED);
128
    }
129
} else {
130
    include $GLOBALS['xoops']->path('header.php');
131
    //xoops_confirm(array('post_id' => $post_id, 'viewmode' => $viewmode, 'order' => $order, 'forum' => $forum, 'topic_id' => $topic_id, 'ok' => 1), 'delete.php', _MD_NEWBB_DEL_ONE);
0 ignored issues
show
Unused Code Comprehensibility introduced by
61% 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...
132
    echo '<div class="confirmMsg">' . _MD_NEWBB_DEL_ONE . '<br>
133
          <form method="post" action="' . XOOPS_URL . '/modules/newbb/delete.php">';
134
    echo _MD_NEWBB_DELEDEDMSG . '<br>';
135
    echo '<textarea name="post_text" cols="50" rows="5"></textarea><br>';
136
    echo '<input type="hidden" name="post_id" value="' . htmlspecialchars($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...
137
    echo '<input type="hidden" name="order" value="' . htmlspecialchars($order) . '" />';
138
    echo '<input type="hidden" name="forum" value="' . htmlspecialchars($forum) . '" />';
139
    echo '<input type="hidden" name="topic_id" value="' . htmlspecialchars($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...
140
    echo '<input type="hidden" name="ok" value="1" />';
141
    echo $GLOBALS['xoopsSecurity']->getTokenHTML();
142
    echo '<input type="submit" name="confirm_submit" value="' . _SUBMIT . '" title="' . _SUBMIT . '"/>
143
          <input type="button" name="confirm_back" value="' . _CANCEL . '" onclick="history.go(-1);" title="' . _CANCEL . '" />
144
          </form>
145
          </div>';
146
    if ($isAdmin) {
147
        xoops_confirm([
148
                          'post_id'  => $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...
149
                          'viewmode' => $viewmode,
150
                          'order'    => $order,
151
                          'forum'    => $forum,
152
                          'topic_id' => $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...
153
                          'ok'       => 99
154
                      ], 'delete.php', _MD_NEWBB_DEL_RELATED);
155
    }
156
    include $GLOBALS['xoops']->path('footer.php');
157
}
158