Completed
Pull Request — master (#5)
by
unknown
02:25
created

header.php (4 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 dirname(dirname(__DIR__)) . '/mainfile.php';
15
// defined('XOOPS_ROOT_PATH') || exit('Restricted access.');
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% 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...
16
/** @var \XoopsLogger $xoopsLogger */
17
$xoopsLogger->startTime('newBB_Header');
18
// irmtfan assign newbb dirname then replace all. include xoops header.php (now commented and removed)
19
//$dirname = $xoopsModule->getVar('dirname');
20
$moduleDirName = basename(__DIR__);
21
//include_once $GLOBALS['xoops']->path('header.php');
0 ignored issues
show
Unused Code Comprehensibility introduced by
84% 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...
22
23
if (!empty($GLOBALS['xoopsModuleConfig']['do_rewrite'])) {
24
    include_once __DIR__ . '/seo_url.php';
25
    /* for seo */
26
    $toseo_url = ['index.php', 'viewforum.php', 'viewtopic.php', 'rss.php'];
27
28
    if (!empty($GLOBALS['xoopsModuleConfig']['do_rewrite']) && (!isset($_POST) || count($_POST) <= 0)
29
        && (strpos(getenv('REQUEST_URI'), '.html') === false)) {
30
        $redir = false;
31
        if (strpos(getenv('REQUEST_URI'), 'mark_read=') === true || strpos(getenv('REQUEST_URI'), 'mark=') === true) {
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...
32
            // Mark Forums
33
        } else {
34
            if (in_array(basename(getenv('SCRIPT_NAME')), $toseo_url)) {
35
                //rewrite only for files
36
37
                if (trim(getenv('SCRIPT_NAME')) !== '') {
38
                    if (strpos(getenv('REQUEST_URI'), '/' . SEO_MODULE_NAME . '/') === false) {
39
                        $redir = true;
40
                    } elseif (getenv('QUERY_STRING')) {
41
                        $redir = true;
42
                    }
43
                }
44
            }
45
        }
46
47
        if ($redir === true) {
48
            $s      = 'http://' . getenv('HTTP_HOST') . getenv('REQUEST_URI');
49
            $s      = str_replace('/' . REAL_MODULE_NAME . '/', '/' . SEO_MODULE_NAME . '/', $s);
50
            $newurl = seo_urls('<a href="' . $s . '"></a>');
51
            $newurl = str_replace('<a href="', '', $newurl);
52
            $newurl = str_replace('"></a>', '', $newurl);
53
            if (!headers_sent()) {
54
                header('HTTP/1.1 301 Moved Permanently');
55
                header("Location: $newurl");
56
                exit();
57
            }
58
        }
59
    }
60
}
61
62
include_once $GLOBALS['xoops']->path('modules/' . $moduleDirName . '/include/vars.php');
63
64
include_once __DIR__ . '/include/functions.user.php';
65
include_once __DIR__ . '/include/functions.topic.php';
66
67
require_once $GLOBALS['xoops']->path('class/xoopsformloader.php');
68
require_once $GLOBALS['xoops']->path('class/module.textsanitizer.php');
69
$myts = MyTextSanitizer::getInstance();
70
71
$menumode       = 0;
72
$menumode_other = [];
73
$menu_url       = htmlspecialchars(preg_replace('/&menumode=[^&]/', '', Request::getString('REQUEST_URI', '', 'SERVER')));
74
$menu_url       .= (false === strpos($menu_url, '?')) ? '?menumode=' : '&amp;menumode=';
75
//foreach ($GLOBALS['xoopsModuleConfig']['valid_menumodes'] as $key => $val) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% 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...
76
//    if ($key !== $menumode) {
77
//        $menumode_other[] = array('title' => $val, 'link' => $menu_url . $key);
78
//    }
79
//}
80
81
if (is_object($GLOBALS['xoopsUser']) && !empty($GLOBALS['xoopsModuleConfig']['welcome_forum'])
82
    && !$GLOBALS['xoopsUser']->getVar('posts')) {
83
    include_once __DIR__ . '/include/functions.welcome.php';
84
}
85
// irmtfan for backward compatibility
86
$pollmodules = $GLOBALS['xoopsModuleConfig']['poll_module'];
87
88
/** @var \XoopsModuleHandler $moduleHandler */
89
$moduleHandler = xoops_getHandler('module');
90
$xoopspoll     = $moduleHandler->getByDirname($pollmodules);
91
92
$xoopsLogger->stopTime('newBB_Header');
93