Skip to content
Snippets Groups Projects
Commit 70000e68 authored by Gerhard Killesreiter's avatar Gerhard Killesreiter
Browse files

#58641, filter inserted locale strings, patch by myself.

parent 52379be1
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
...@@ -405,6 +405,7 @@ function _locale_string_edit($lid) { ...@@ -405,6 +405,7 @@ function _locale_string_edit($lid) {
function _locale_string_edit_submit($form_id, $form_values) { function _locale_string_edit_submit($form_id, $form_values) {
$lid = $form_values['lid']; $lid = $form_values['lid'];
foreach ($form_values as $key => $value) { foreach ($form_values as $key => $value) {
$value = filter_xss_admin($value);
$trans = db_fetch_object(db_query("SELECT translation FROM {locales_target} WHERE lid = %d AND locale = '%s'", $lid, $key)); $trans = db_fetch_object(db_query("SELECT translation FROM {locales_target} WHERE lid = %d AND locale = '%s'", $lid, $key));
if (isset($trans->translation)) { if (isset($trans->translation)) {
db_query("UPDATE {locales_target} SET translation = '%s' WHERE lid = %d AND locale = '%s'", $value, $lid, $key); db_query("UPDATE {locales_target} SET translation = '%s' WHERE lid = %d AND locale = '%s'", $value, $lid, $key);
...@@ -645,7 +646,7 @@ function _locale_import_one_string($value, $mode, $lang = NULL) { ...@@ -645,7 +646,7 @@ function _locale_import_one_string($value, $mode, $lang = NULL) {
} }
// Some real string to import // Some real string to import
else { else {
$comments = _locale_import_shorten_comments($value['#']); $comments = filter_xss_admin(_locale_import_shorten_comments($value['#']));
// Handle a translation for some plural string // Handle a translation for some plural string
if (strpos($value['msgid'], "\0")) { if (strpos($value['msgid'], "\0")) {
...@@ -667,11 +668,11 @@ function _locale_import_one_string($value, $mode, $lang = NULL) { ...@@ -667,11 +668,11 @@ function _locale_import_one_string($value, $mode, $lang = NULL) {
db_query("UPDATE {locales_source} SET location = '%s' WHERE lid = %d", $comments, $lid); db_query("UPDATE {locales_source} SET location = '%s' WHERE lid = %d", $comments, $lid);
$trans2 = db_fetch_object(db_query("SELECT lid, translation, plid, plural FROM {locales_target} WHERE lid = %d AND locale = '%s'", $lid, $lang)); $trans2 = db_fetch_object(db_query("SELECT lid, translation, plid, plural FROM {locales_target} WHERE lid = %d AND locale = '%s'", $lid, $lang));
if (!$trans2->lid) { // no translation in current language if (!$trans2->lid) { // no translation in current language
db_query("INSERT INTO {locales_target} (lid, locale, translation, plid, plural) VALUES (%d, '%s', '%s', %d, %d)", $lid, $lang, $trans, $plid, $key); db_query("INSERT INTO {locales_target} (lid, locale, translation, plid, plural) VALUES (%d, '%s', '%s', %d, %d)", $lid, $lang, filter_xss_admin($trans), $plid, $key);
$additions++; $additions++;
} // translation exists } // translation exists
else if ($mode == 'overwrite' || $trans2->translation == '') { else if ($mode == 'overwrite' || $trans2->translation == '') {
db_query("UPDATE {locales_target} SET translation = '%s', plid = %d, plural = %d WHERE locale = '%s' AND lid = %d", $trans, $plid, $key, $lang, $lid); db_query("UPDATE {locales_target} SET translation = '%s', plid = %d, plural = %d WHERE locale = '%s' AND lid = %d", filter_xss_admin($trans), $plid, $key, $lang, $lid);
if ($trans2->translation == '') { if ($trans2->translation == '') {
$additions++; $additions++;
} }
...@@ -681,10 +682,10 @@ function _locale_import_one_string($value, $mode, $lang = NULL) { ...@@ -681,10 +682,10 @@ function _locale_import_one_string($value, $mode, $lang = NULL) {
} }
} }
else { // no string else { // no string
db_query("INSERT INTO {locales_source} (location, source) VALUES ('%s', '%s')", $comments, $english[$key]); db_query("INSERT INTO {locales_source} (location, source) VALUES ('%s', '%s')", $comments, filter_xss_admin($english[$key]));
$loc = db_fetch_object(db_query("SELECT lid FROM {locales_source} WHERE source = '%s'", $english[$key])); $loc = db_fetch_object(db_query("SELECT lid FROM {locales_source} WHERE source = '%s'", $english[$key]));
$lid = $loc->lid; $lid = $loc->lid;
db_query("INSERT INTO {locales_target} (lid, locale, translation, plid, plural) VALUES (%d, '%s', '%s', %d, %d)", $lid, $lang, $trans, $plid, $key); db_query("INSERT INTO {locales_target} (lid, locale, translation, plid, plural) VALUES (%d, '%s', '%s', %d, %d)", $lid, $lang, filter_xss_admin($trans), $plid, $key);
if ($trans != '') { if ($trans != '') {
$additions++; $additions++;
} }
...@@ -704,11 +705,11 @@ function _locale_import_one_string($value, $mode, $lang = NULL) { ...@@ -704,11 +705,11 @@ function _locale_import_one_string($value, $mode, $lang = NULL) {
db_query("UPDATE {locales_source} SET location = '%s' WHERE source = '%s'", $comments, $english); db_query("UPDATE {locales_source} SET location = '%s' WHERE source = '%s'", $comments, $english);
$trans = db_fetch_object(db_query("SELECT lid, translation FROM {locales_target} WHERE lid = %d AND locale = '%s'", $lid, $lang)); $trans = db_fetch_object(db_query("SELECT lid, translation FROM {locales_target} WHERE lid = %d AND locale = '%s'", $lid, $lang));
if (!$trans->lid) { // no translation in current language if (!$trans->lid) { // no translation in current language
db_query("INSERT INTO {locales_target} (lid, locale, translation) VALUES (%d, '%s', '%s')", $lid, $lang, $translation); db_query("INSERT INTO {locales_target} (lid, locale, translation) VALUES (%d, '%s', '%s')", $lid, $lang, filter_xss_admin($translation));
$additions++; $additions++;
} // translation exists } // translation exists
else if ($mode == 'overwrite') { //overwrite in any case else if ($mode == 'overwrite') { //overwrite in any case
db_query("UPDATE {locales_target} SET translation = '%s' WHERE locale = '%s' AND lid = %d", $translation, $lang, $lid); db_query("UPDATE {locales_target} SET translation = '%s' WHERE locale = '%s' AND lid = %d", filter_xss_admin($translation), $lang, $lid);
if ($trans->translation == '') { if ($trans->translation == '') {
$additions++; $additions++;
} }
...@@ -725,7 +726,7 @@ function _locale_import_one_string($value, $mode, $lang = NULL) { ...@@ -725,7 +726,7 @@ function _locale_import_one_string($value, $mode, $lang = NULL) {
db_query("INSERT INTO {locales_source} (location, source) VALUES ('%s', '%s')", $comments, $english); db_query("INSERT INTO {locales_source} (location, source) VALUES ('%s', '%s')", $comments, $english);
$loc = db_fetch_object(db_query("SELECT lid FROM {locales_source} WHERE source = '%s'", $english)); $loc = db_fetch_object(db_query("SELECT lid FROM {locales_source} WHERE source = '%s'", $english));
$lid = $loc->lid; $lid = $loc->lid;
db_query("INSERT INTO {locales_target} (lid, locale, translation) VALUES (%d, '%s', '%s')", $lid, $lang, $translation); db_query("INSERT INTO {locales_target} (lid, locale, translation) VALUES (%d, '%s', '%s')", $lid, $lang, filter_xss_admin($translation));
if ($translation != '') { if ($translation != '') {
$additions++; $additions++;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment