Passed
Push — master ( 7c14af...676210 )
by Michael
05:14 queued 03:11
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 https://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 Xmf\Request;
20
use XoopsModules\Xlanguage\{
21
    Helper,
22
    LanguageHandler,
23
    Utility
24
};
25
26
/** @var Helper $helper */
27
/** @var Utility $utility */
28
/** @var LanguageHandler $languageHandler */
29
30
global $xlanguage, $xoopsConfig;
31
require_once XOOPS_ROOT_PATH . '/modules/xlanguage/include/vars.php';
32
33
//$cookie_prefix = preg_replace("/[^a-z_0-9]+/i", "_", preg_replace("/(http(s)?:\/\/)?(www.)?/i","",XOOPS_URL));
34
$cookie_var = XLANGUAGE_LANG_TAG;
35
$utility    = new Utility();
36
37
$xlanguage['action'] = false;
38
$langTag             = Request::getString(XLANGUAGE_LANG_TAG, '', 'GET');
39
if (!empty($langTag)) {
40
    $cookie_path = '/';
41
    setcookie($cookie_var, $langTag, time() + 3600 * 24 * 30, $cookie_path, '', 0);
42
    $xlanguage['lang'] = $langTag;
43
} elseif (!empty($_COOKIE[$cookie_var])) {
44
    $xlanguage['lang'] = $_COOKIE[$cookie_var];
45
46
    /* FIXME: shall we remove it? */
47
48
    //    if (preg_match("/[&|\?]\b".XLANGUAGE_LANG_TAG."\b=/i",$_SERVER['REQUEST_URI'])) {
49
    //    } elseif (strpos($_SERVER['REQUEST_URI'], "?")) {
50
    //        $_SERVER['REQUEST_URI'] .= "&".XLANGUAGE_LANG_TAG."=".$xlanguage["lang"];
51
    //    } else {
52
    //        $_SERVER['REQUEST_URI'] .= "?".XLANGUAGE_LANG_TAG."=".$xlanguage["lang"];
53
    //    }
54
55
} elseif ($lang = $utility::detectLang()) {
56
    $xlanguage['lang'] = $lang;
57
} else {
58
    $xlanguage['lang'] = $xoopsConfig['language'];
59
}
60
61
$helper          = Helper::getInstance();
62
$languageHandler = $helper->getHandler('Language');
63
$languageHandler->loadConfig();
64
$lang = $languageHandler->getByName($xlanguage['lang']);
65
if (is_object($lang) && strcasecmp($lang->getVar('lang_name'), $xoopsConfig['language'])) {
66
    if ($lang->hasBase()) {
67
        $xoopsConfig['language'] = $lang->getVar('lang_name');
68
    } else {
69
        $lang_base = $languageHandler->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

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