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
|
|||
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)); |
||
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 | /* |
||
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))) { |
||
77 | if (!empty($_POST)) { |
||
78 | $in_charset = $xlanguage['charset']; |
||
79 | $out_charset = $xlanguage['charset_base']; |
||
80 | |||
81 | //$CONV_REQUEST_array=array("_GET", "_POST"); |
||
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 |
Instead of relying on
global
state, we recommend one of these alternatives:1. Pass all data via parameters
2. Create a class that maintains your state