refactoring streamJSTranslationFile to remove eval use
This commit is contained in:
@@ -827,6 +827,11 @@ class Bootstrap
|
|||||||
$typeName = trim($typeName);
|
$typeName = trim($typeName);
|
||||||
$fileConst = ($typeName == 'translation') ? 'translation.' . $locale : 'translation.' . $typeName . '.' . $locale;
|
$fileConst = ($typeName == 'translation') ? 'translation.' . $locale : 'translation.' . $typeName . '.' . $locale;
|
||||||
|
|
||||||
|
if (!preg_match('/^[a-zA-Z0-9_]+$/', $typeName)) {
|
||||||
|
error_log("Attempted to stream invalid translation type: " . $typeName);
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
if ($typeName == 'translation') {
|
if ($typeName == 'translation') {
|
||||||
$defaultTranslations = array();
|
$defaultTranslations = array();
|
||||||
$foreignTranslations = array();
|
$foreignTranslations = array();
|
||||||
@@ -863,11 +868,16 @@ class Bootstrap
|
|||||||
$newName = implode('.', $typearray);
|
$newName = implode('.', $typearray);
|
||||||
if (file_exists(PATH_LANGUAGECONT . $newName)) {
|
if (file_exists(PATH_LANGUAGECONT . $newName)) {
|
||||||
require_once(PATH_LANGUAGECONT . $newName);
|
require_once(PATH_LANGUAGECONT . $newName);
|
||||||
$return = '';
|
$dynamicTranslationVarName = 'translation' . $typeName;
|
||||||
eval('$return = "var TRANSLATIONS_" . strtoupper($typeName) . " = " . Bootstrap::json_encode($translation' . $typeName . ') . ";";');
|
if (isset($$dynamicTranslationVarName) && is_array($$dynamicTranslationVarName)) {
|
||||||
return $return;
|
$translationToEncode = $$dynamicTranslationVarName;
|
||||||
|
return 'var TRANSLATIONS_' . strtoupper($typeName) . ' = ' . Bootstrap::json_encode($translationToEncode) . ';';
|
||||||
|
} else {
|
||||||
|
error_log("Missing or invalid translation array for type: " . $typeName);
|
||||||
|
return '';
|
||||||
}
|
}
|
||||||
return;
|
}
|
||||||
|
return '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user