Passed
Push — master ( d3e687...4990f6 )
by Michael
02:43
created

header.php (9 issues)

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;
0 ignored issues
show
The type Xmf\Request was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
13
14
include dirname(dirname(__DIR__)) . '/mainfile.php';
15
require_once __DIR__ . '/include/common.php';
16
17
// defined('XOOPS_ROOT_PATH') || die('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...
18
/** @var \XoopsLogger $xoopsLogger */
19
$xoopsLogger->startTime('newBB_Header');
20
// irmtfan assign newbb dirname then replace all. include xoops header.php (now commented and removed)
21
//$dirname = $xoopsModule->getVar('dirname');
22
$moduleDirName = basename(__DIR__);
23
//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...
24
25
if (!empty($GLOBALS['xoopsModuleConfig']['do_rewrite'])) {
26
    include_once __DIR__ . '/seo_url.php';
27
    /* for seo */
28
    $toseo_url = ['index.php', 'viewforum.php', 'viewtopic.php', 'rss.php'];
29
30
    if (!empty($GLOBALS['xoopsModuleConfig']['do_rewrite']) && (!isset($_POST) || count($_POST) <= 0)
31
        && (false === strpos(getenv('REQUEST_URI'), '.html'))) {
32
        $redir = false;
33
        if (true === strpos(getenv('REQUEST_URI'), 'mark_read=') || true === strpos(getenv('REQUEST_URI'), 'mark=')) {
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...
34
            // Mark Forums
35
        } else {
36
            if (in_array(basename(getenv('SCRIPT_NAME')), $toseo_url)) {
37
                //rewrite only for files
38
39
                if ('' !== trim(getenv('SCRIPT_NAME'))) {
40
                    if (false === strpos(getenv('REQUEST_URI'), '/' . SEO_MODULE_NAME . '/')) {
41
                        $redir = true;
42
                    } elseif (getenv('QUERY_STRING')) {
43
                        $redir = true;
44
                    }
45
                }
46
            }
47
        }
48
49
        if (true === $redir) {
50
            $s      = 'http://' . getenv('HTTP_HOST') . getenv('REQUEST_URI');
0 ignored issues
show
Are you sure getenv('HTTP_HOST') of type false|string|array can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

50
            $s      = 'http://' . /** @scrutinizer ignore-type */ getenv('HTTP_HOST') . getenv('REQUEST_URI');
Loading history...
Are you sure getenv('REQUEST_URI') of type false|string|array can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

50
            $s      = 'http://' . getenv('HTTP_HOST') . /** @scrutinizer ignore-type */ getenv('REQUEST_URI');
Loading history...
51
            $s      = str_replace('/' . REAL_MODULE_NAME . '/', '/' . SEO_MODULE_NAME . '/', $s);
52
            $newurl = seo_urls('<a href="' . $s . '"></a>');
53
            $newurl = str_replace('<a href="', '', $newurl);
54
            $newurl = str_replace('"></a>', '', $newurl);
55
            if (!headers_sent()) {
56
                header('HTTP/1.1 301 Moved Permanently');
57
                header("Location: $newurl");
58
                exit();
59
            }
60
        }
61
    }
62
}
63
64
include_once $GLOBALS['xoops']->path('modules/' . $moduleDirName . '/include/vars.php');
65
66
include_once __DIR__ . '/include/functions.user.php';
67
include_once __DIR__ . '/include/functions.topic.php';
68
69
require_once $GLOBALS['xoops']->path('class/xoopsformloader.php');
70
require_once $GLOBALS['xoops']->path('class/module.textsanitizer.php');
71
$myts = \MyTextSanitizer::getInstance();
0 ignored issues
show
The type MyTextSanitizer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
72
73
$menumode       = 0;
74
$menumode_other = [];
75
$menu_url       = htmlspecialchars(preg_replace('/&menumode=[^&]/', '', Request::getString('REQUEST_URI', '', 'SERVER')));
76
$menu_url       .= (false === strpos($menu_url, '?')) ? '?menumode=' : '&amp;menumode=';
77
//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...
78
//    if ($key !== $menumode) {
79
//        $menumode_other[] = array('title' => $val, 'link' => $menu_url . $key);
80
//    }
81
//}
82
83
if (is_object($GLOBALS['xoopsUser']) && !empty($GLOBALS['xoopsModuleConfig']['welcome_forum'])
84
    && !$GLOBALS['xoopsUser']->getVar('posts')) {
85
    include_once __DIR__ . '/include/functions.welcome.php';
86
}
87
// irmtfan for backward compatibility
88
$pollmodules = $GLOBALS['xoopsModuleConfig']['poll_module'];
89
90
/** @var \XoopsModuleHandler $moduleHandler */
91
$moduleHandler = xoops_getHandler('module');
0 ignored issues
show
The function xoops_getHandler was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

91
$moduleHandler = /** @scrutinizer ignore-call */ xoops_getHandler('module');
Loading history...
92
$xoopspoll     = $moduleHandler->getByDirname($pollmodules);
93
94
$xoopsLogger->stopTime('newBB_Header');
95