Completed
Push — master ( 98eeb4...22887c )
by Michael
11s
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
 * xLanguage module (eXtensible Language Management For XOOPS)
4
 *
5
 * You may not change or alter any portion of this comment or credits
6
 * of supporting developers from this source code or any supporting source code
7
 * which is considered copyrighted (c) material of the original comment or credit authors.
8
 * This program is distributed in the hope that it will be useful,
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
 *
12
 * @copyright    XOOPS Project (https://xoops.org)
13
 * @license      {@link http://www.gnu.org/licenses/gpl-2.0.html GNU Public License}
14
 * @package      xlanguage
15
 * @since        2.0
16
 * @author       D.J.(phppp) [email protected]
17
 **/
18
19
global $xlanguage;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
20
require_once XOOPS_ROOT_PATH . '/modules/xlanguage/include/vars.php';
21
require_once XOOPS_ROOT_PATH . '/modules/xlanguage/include/functions.php';
22
23
//$cookie_prefix = preg_replace("/[^a-z_0-9]+/i", "_", preg_replace("/(http(s)?:\/\/)?(www.)?/i","",XOOPS_URL));
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...
24
$cookie_var = XLANGUAGE_LANG_TAG;
25
26
$xlanguage['action'] = false;
27
if (!empty($_GET[XLANGUAGE_LANG_TAG])) {
28
    $cookie_path = '/';
29
    setcookie($cookie_var, $_GET[XLANGUAGE_LANG_TAG], time() + 3600 * 24 * 30, $cookie_path, '', 0);
30
    $xlanguage['lang'] = $_GET[XLANGUAGE_LANG_TAG];
31
} elseif (!empty($_COOKIE[$cookie_var])) {
32
    $xlanguage['lang'] = $_COOKIE[$cookie_var];
33
    /* FIXME: shall we remove it? */
34
    /*
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...
35
    if (preg_match("/[&|\?]\b".XLANGUAGE_LANG_TAG."\b=/i",$_SERVER['REQUEST_URI'])) {
36
    } elseif (strpos($_SERVER['REQUEST_URI'], "?")) {
37
        $_SERVER['REQUEST_URI'] .= "&".XLANGUAGE_LANG_TAG."=".$xlanguage["lang"];
38
    } else {
39
        $_SERVER['REQUEST_URI'] .= "?".XLANGUAGE_LANG_TAG."=".$xlanguage["lang"];
40
    }
41
    */
42
} elseif ($lang = xlanguage_detectLang()) {
43
    $xlanguage['lang'] = $lang;
44
} else {
45
    $xlanguage['lang'] = $xoopsConfig['language'];
46
}
47
48
/** @var \XlanguageLanguageHandler $xlanguageHandler */
49
$xlanguageHandler = xoops_getModuleHandler('language', 'xlanguage');
50
$xlanguageHandler->loadConfig();
51
$lang = $xlanguageHandler->getByName($xlanguage['lang']);
52
if (is_object($lang) && strcasecmp($lang->getVar('lang_name'), $xoopsConfig['language'])) {
53
    if ($lang->hasBase()) {
54
        $xoopsConfig['language'] = $lang->getVar('lang_name');
55
    } else {
56
        $lang_base = $xlanguageHandler->getByName($lang->getVar('lang_base'));
57
        if (is_object($lang_base)) {
58
            $xlanguage['charset_base'] = $lang_base->getVar('lang_charset');
59
            $xlanguage['action']       = true;
60
            $xoopsConfig['language']   = $lang_base->getVar('lang_name');
61
            unset($lang_base);
62
        }
63
    }
64
    if ($lang->getVar('lang_charset')) {
65
        $xlanguage['charset'] = $lang->getVar('lang_charset');
66
    }
67
    if ($lang->getVar('lang_code')) {
68
        $xlanguage['code'] = $lang->getVar('lang_code');
69
    }
70
}
71
unset($lang);
72
73
$GLOBALS['xlanguageHandler'] = $xlanguageHandler;
74
75
if ($xlanguage['action']) {
76
    //if (CONV_REQUEST && (!empty($_GET)||!empty($_POST))) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
79% 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...
77
    if (!empty($_POST)) {
78
        $in_charset  = $xlanguage['charset'];
79
        $out_charset = $xlanguage['charset_base'];
80
81
        //$CONV_REQUEST_array=array("_GET", "_POST");
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...
82
        $CONV_REQUEST_array = array('_POST');
83
        foreach ($CONV_REQUEST_array as $HV) {
84
            if (!empty(${$HV})) {
85
                ${$HV} = xlanguage_convert_encoding(${$HV}, $out_charset, $in_charset);
86
            }
87
            $GLOBALS['HTTP' . $HV . '_VARS'] = ${$HV};
88
        }
89
    }
90
    ob_start('xlanguage_encoding');
91
} else {
92
    ob_start('xlanguage_ml');
93
}
94
95
/*
96
 * hardcoded scripts for language switching in theme html files
97
 *
98
 * To use it:
99
 * 1 set "$xlanguage_theme_enable = true;"
100
 * 2 config options "$options = array("images", " ", 5); // display mode, delimitor, number per line"; Options for display mode: image - flag; text - text; dropdown - dropdown selection box with text
101
 * 3 insert "<{$smarty.const.XLANGUAGE_SWITCH_CODE}>" into your theme html anywhere you would like to see it present
102
 */
103
$xlanguage_theme_enable = true;
104
if (!empty($xlanguage_theme_enable)) {
105
    $options = array('dropdown', ' ', 5); // display mode, delimitor, number per line
106
    xlanguage_select_show($options);
107
}
108