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

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