XoopsModules25x /
xlanguage
| 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\{Helper, |
||||
| 21 | LanguageHandler, |
||||
| 22 | Utility |
||||
| 23 | }; |
||||
| 24 | |||||
| 25 | /** @var Helper $helper */ |
||||
| 26 | /** @var Utility $utility */ |
||||
| 27 | /** @var LanguageHandler $languageHandler */ |
||||
| 28 | |||||
| 29 | global $xlanguage, $xoopsConfig; |
||||
| 30 | require_once XOOPS_ROOT_PATH . '/modules/xlanguage/include/vars.php'; |
||||
| 31 | |||||
| 32 | //$cookie_prefix = preg_replace("/[^a-z_0-9]+/i", "_", preg_replace("/(http(s)?:\/\/)?(www.)?/i","",XOOPS_URL)); |
||||
| 33 | $cookie_var = XLANGUAGE_LANG_TAG; |
||||
| 34 | $utility = new Utility(); |
||||
| 35 | |||||
| 36 | $xlanguage['action'] = false; |
||||
| 37 | $langTag = Request::getString(XLANGUAGE_LANG_TAG, '', 'GET'); |
||||
| 38 | if (!empty($langTag)) { |
||||
| 39 | $cookie_path = '/'; |
||||
| 40 | setcookie($cookie_var, $langTag, time() + 3600 * 24 * 30, $cookie_path, '', 0); |
||||
| 41 | $xlanguage['lang'] = $langTag; |
||||
| 42 | } elseif (!empty($_COOKIE[$cookie_var])) { |
||||
| 43 | $xlanguage['lang'] = $_COOKIE[$cookie_var]; |
||||
| 44 | |||||
| 45 | /* FIXME: shall we remove it? */ |
||||
| 46 | |||||
| 47 | // if (preg_match("/[&|\?]\b".XLANGUAGE_LANG_TAG."\b=/i",$_SERVER['REQUEST_URI'])) { |
||||
| 48 | // } elseif (strpos($_SERVER['REQUEST_URI'], "?")) { |
||||
| 49 | // $_SERVER['REQUEST_URI'] .= "&".XLANGUAGE_LANG_TAG."=".$xlanguage["lang"]; |
||||
| 50 | // } else { |
||||
| 51 | // $_SERVER['REQUEST_URI'] .= "?".XLANGUAGE_LANG_TAG."=".$xlanguage["lang"]; |
||||
| 52 | // } |
||||
| 53 | |||||
| 54 | } elseif ($lang = $utility::detectLang()) { |
||||
| 55 | $xlanguage['lang'] = $lang; |
||||
| 56 | } else { |
||||
| 57 | $xlanguage['lang'] = $xoopsConfig['language']; |
||||
| 58 | } |
||||
| 59 | |||||
| 60 | $helper = Helper::getInstance(); |
||||
| 61 | $languageHandler = $helper->getHandler('Language'); |
||||
| 62 | $languageHandler->loadConfig(); |
||||
| 63 | $lang = $languageHandler->getByName($xlanguage['lang']); |
||||
| 64 | if (is_object($lang) && strcasecmp($lang->getVar('lang_name'), $xoopsConfig['language'])) { |
||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
| 65 | if ($lang->hasBase()) { |
||||
| 66 | $xoopsConfig['language'] = $lang->getVar('lang_name'); |
||||
| 67 | } else { |
||||
| 68 | $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
Loading history...
|
|||||
| 69 | if (is_object($lang_base)) { |
||||
| 70 | $xlanguage['charset_base'] = $lang_base->getVar('lang_charset'); |
||||
| 71 | $xlanguage['action'] = true; |
||||
| 72 | $xoopsConfig['language'] = $lang_base->getVar('lang_name'); |
||||
| 73 | unset($lang_base); |
||||
| 74 | } |
||||
| 75 | } |
||||
| 76 | if ($lang->getVar('lang_charset')) { |
||||
| 77 | $xlanguage['charset'] = $lang->getVar('lang_charset'); |
||||
| 78 | } |
||||
| 79 | if ($lang->getVar('lang_code')) { |
||||
| 80 | $xlanguage['code'] = $lang->getVar('lang_code'); |
||||
| 81 | } |
||||
| 82 | } |
||||
| 83 | unset($lang); |
||||
| 84 | |||||
| 85 | $GLOBALS['xlanguageHandler'] = $languageHandler; |
||||
| 86 | |||||
| 87 | if ($xlanguage['action']) { |
||||
| 88 | //if (CONV_REQUEST && (!empty($_GET)||!empty($_POST))) { |
||||
| 89 | if (!empty($_POST)) { |
||||
| 90 | $in_charset = $xlanguage['charset']; |
||||
| 91 | $out_charset = $xlanguage['charset_base']; |
||||
| 92 | |||||
| 93 | //$CONV_REQUEST_array=array("_GET", "_POST"); |
||||
| 94 | $CONV_REQUEST_array = ['_POST']; |
||||
| 95 | foreach ($CONV_REQUEST_array as $HV) { |
||||
| 96 | if (!empty(${$HV})) { |
||||
| 97 | ${$HV} = $utility::convertEncoding(${$HV}, $out_charset, $in_charset); |
||||
| 98 | } |
||||
| 99 | $GLOBALS['HTTP' . $HV . '_VARS'] = ${$HV}; |
||||
| 100 | } |
||||
| 101 | } |
||||
| 102 | ob_start("XoopsModules\Xlanguage\Utility::encodeCharSet"); |
||||
| 103 | } else { |
||||
| 104 | ob_start("XoopsModules\Xlanguage\Utility::cleanMultiLang"); |
||||
| 105 | } |
||||
| 106 | |||||
| 107 | /* |
||||
| 108 | * hardcoded scripts for language switching in theme html files |
||||
| 109 | * |
||||
| 110 | * To use it: |
||||
| 111 | * 1 set "$xlanguage_theme_enable = true;" |
||||
| 112 | * 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 |
||||
| 113 | * 3 insert "<{$smarty.const.XLANGUAGE_SWITCH_CODE}>" into your theme html anywhere you would like to see it present |
||||
| 114 | */ |
||||
| 115 | $xlanguage_theme_enable = true; |
||||
| 116 | if (!empty($xlanguage_theme_enable)) { |
||||
|
0 ignored issues
–
show
|
|||||
| 117 | $options = ['dropdown', ' ', 5]; // display mode, delimitor, number per line |
||||
| 118 | $utility::showSelectedLanguage($options); |
||||
| 119 | } |
||||
| 120 |