Project

General

Profile

Bug #14264 » tslib_cObj.patch

Administrator Admin, 2005-04-12 13:22

View differences:

class.tslib_content.php 2005-04-12 12:09:17.000000000 +0200
reset($value);
while(list(,$Nvalue)=each($value)) {
$JSPart.="
updateForm('".$formName."','".$arrPrefix."[".$fKey."][]',unescape('".rawurlencode($Nvalue)."'))";
updateForm('".$formName."','".$arrPrefix."[".$fKey."][]',". $this->JScharCode($Nvalue) .");";
}
} else {
$JSPart.="
updateForm('".$formName."','".$arrPrefix."[".$fKey."]',unescape('".rawurlencode($value)."'))";
updateForm('".$formName."','".$arrPrefix."[".$fKey."]',". $this->JScharCode($value) .');';
}
}
$JSPart='<script type="text/javascript">
......
}
/**
* Converts the input string to a JavaScript function returning the same string, but charset-safe.
* Used for confirm and alert boxes where we must make sure that any string content does not break the script AND want to make sure the charset is preserved.
* Originally I used the JS function unescape() in combination with PHP function rawurlencode() in order to pass strings in a safe way. This could still be done for iso-8859-1 charsets but now I have applied the same method here for all charsets.
*
* @param string Input string, encoded with $this->charSet
* @return string Output string, a JavaScript function: "String.fromCharCode(......)"
* @see language::JScharcode()
*/
function JScharCode($str,$charSet='') {
// detect charset
if ( $charSet == '' ) {
if ( ! $GLOBALS['TSFE']->lang ) {
$GLOBALS['TSFE']->initLLvars();
}
$charSet = $GLOBALS['TSFE']->siteCharset;
}
// Convert string to UTF-8:
if ($charSet!='utf-8') {
$str = $GLOBALS['TSFE']->csConvObj->utf8_encode($str,$charSet);
}
// Convert the UTF-8 string into a array of char numbers:
$nArr = $GLOBALS['TSFE']->csConvObj->utf8_to_numberarray($str);
return 'String.fromCharCode('.implode(', ',$nArr).')';
}
(3-3/8)