Passed
Push — master ( 22887c...b0a7cb )
by Michael
04:05 queued 02:12
created
Labels
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
use XoopsModules\Xlanguage;
20
21
global $xlanguage;
22
require_once XOOPS_ROOT_PATH . '/modules/xlanguage/include/vars.php';
23
24
//$cookie_prefix = preg_replace("/[^a-z_0-9]+/i", "_", preg_replace("/(http(s)?:\/\/)?(www.)?/i","",XOOPS_URL));
25
$cookie_var = XLANGUAGE_LANG_TAG;
26
27
$xlanguage['action'] = false;
28
$langTag = \Xmf\Request::getString(XLANGUAGE_LANG_TAG, '', 'GET');
29
if (!empty($langTag)) {
30
    $cookie_path = '/';
31
    setcookie($cookie_var, $langTag, time() + 3600 * 24 * 30, $cookie_path, '', 0);
32
    $xlanguage['lang'] = $langTag;
33
} elseif (!empty($_COOKIE[$cookie_var])) {
34
    $xlanguage['lang'] = $_COOKIE[$cookie_var];
35
36
    /* FIXME: shall we remove it? */
37
38
    //    if (preg_match("/[&|\?]\b".XLANGUAGE_LANG_TAG."\b=/i",$_SERVER['REQUEST_URI'])) {
39
    //    } elseif (strpos($_SERVER['REQUEST_URI'], "?")) {
40
    //        $_SERVER['REQUEST_URI'] .= "&".XLANGUAGE_LANG_TAG."=".$xlanguage["lang"];
41
    //    } else {
42
    //        $_SERVER['REQUEST_URI'] .= "?".XLANGUAGE_LANG_TAG."=".$xlanguage["lang"];
43
    //    }
44
45
} elseif ($lang = Xlanguage\Utility::detectLang()) {
46
    $xlanguage['lang'] = $lang;
47
} else {
48
    $xlanguage['lang'] = $xoopsConfig['language'];
49
}
50
51
/** @var \XoopsModules\Xlanguage\Helper $helper */
52
$helper = \XoopsModules\Xlanguage\Helper::getInstance();
53
/** @var \XoopsModules\Xlanguage\LanguageHandler $xlanguageHandler */
54
$xlanguageHandler = $helper->getHandler('Language');
55
$xlanguageHandler->loadConfig();
56
$lang = $xlanguageHandler->getByName($xlanguage['lang']);
57
if (is_object($lang) && strcasecmp($lang->getVar('lang_name'), $xoopsConfig['language'])) {
0 ignored issues
show
It seems like $lang->getVar('lang_name') can also be of type array and array; however, parameter $str1 of strcasecmp() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

57
if (is_object($lang) && strcasecmp(/** @scrutinizer ignore-type */ $lang->getVar('lang_name'), $xoopsConfig['language'])) {
Loading history...
58
    if ($lang->hasBase()) {
59
        $xoopsConfig['language'] = $lang->getVar('lang_name');
60
    } else {
61
        $lang_base = $xlanguageHandler->getByName($lang->getVar('lang_base'));
0 ignored issues
show
It seems like $lang->getVar('lang_base') can also be of type array and array; however, parameter $name of XoopsModules\Xlanguage\L...ageHandler::getByName() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

61
        $lang_base = $xlanguageHandler->getByName(/** @scrutinizer ignore-type */ $lang->getVar('lang_base'));
Loading history...
62
        if (is_object($lang_base)) {
63
            $xlanguage['charset_base'] = $lang_base->getVar('lang_charset');
64
            $xlanguage['action']       = true;
65
            $xoopsConfig['language']   = $lang_base->getVar('lang_name');
66
            unset($lang_base);
67
        }
68
    }
69
    if ($lang->getVar('lang_charset')) {
70
        $xlanguage['charset'] = $lang->getVar('lang_charset');
71
    }
72
    if ($lang->getVar('lang_code')) {
73
        $xlanguage['code'] = $lang->getVar('lang_code');
74
    }
75
}
76
unset($lang);
77
78
$GLOBALS['xlanguageHandler'] = $xlanguageHandler;
79
80
if ($xlanguage['action']) {
81
    //if (CONV_REQUEST && (!empty($_GET)||!empty($_POST))) {
82
    if (!empty($_POST)) {
83
        $in_charset  = $xlanguage['charset'];
84
        $out_charset = $xlanguage['charset_base'];
85
86
        //$CONV_REQUEST_array=array("_GET", "_POST");
87
        $CONV_REQUEST_array = ['_POST'];
88
        foreach ($CONV_REQUEST_array as $HV) {
89
            if (!empty(${$HV})) {
90
                ${$HV} = Xlanguage\Utility::convertEncoding(${$HV}, $out_charset, $in_charset);
91
            }
92
            $GLOBALS['HTTP' . $HV . '_VARS'] = ${$HV};
93
        }
94
    }
95
    ob_start("XoopsModules\Xlanguage\Utility::encodeCharSet");
96
} else {
97
    ob_start("XoopsModules\Xlanguage\Utility::cleanMultiLang");
98
}
99
100
/*
101
 * hardcoded scripts for language switching in theme html files
102
 *
103
 * To use it:
104
 * 1 set "$xlanguage_theme_enable = true;"
105
 * 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
106
 * 3 insert "<{$smarty.const.XLANGUAGE_SWITCH_CODE}>" into your theme html anywhere you would like to see it present
107
 */
108
$xlanguage_theme_enable = true;
109
if (!empty($xlanguage_theme_enable)) {
0 ignored issues
show
The condition empty($xlanguage_theme_enable) is always false.
Loading history...
110
    $options = ['dropdown', ' ', 5]; // display mode, delimitor, number per line
111
    Xlanguage\Utility::showSelectedLanguage($options);
112
}
113