/** * 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 $str Input string, encoded with UTF-8 * @return string Output string, a JavaScript function: "String.fromCharCode(......) * @depreacted since 6.2 - will be removed two versions later; use GeneralUtility::quoteJSvalue() instead */ public function JScharCode($str) { GeneralUtility::logDeprecatedFunction(); // Convert the UTF-8 string into a array of char numbers: $nArr = $this->csConvObj->utf8_to_numberarray($str); return 'String.fromCharCode(' . implode(',', $nArr) . ')'; }
/** * Splitting a string for ImageTTFBBox up into an array where each part has its own configuration options. * * @param string $string UTF-8 string * @param array $splitRendering Split-rendering configuration from GIFBUILDER TEXT object. * @param int $fontSize Current fontsize * @param string $fontFile Current font file * @return array Array with input string splitted according to configuration */ public function splitString($string, $splitRendering, $fontSize, $fontFile) { // Initialize by setting the whole string and default configuration as the first entry. $result = array(); $result[] = array('str' => $string, 'fontSize' => $fontSize, 'fontFile' => $fontFile); // Traverse the split-rendering configuration: // Splitting will create more entries in $result with individual configurations. if (is_array($splitRendering)) { $sKeyArray = TemplateService::sortedKeyList($splitRendering); // Traverse configured options: foreach ($sKeyArray as $key) { $cfg = $splitRendering[$key . '.']; // Process each type of split rendering keyword: switch ((string) $splitRendering[$key]) { case 'highlightWord': if ((string) $cfg['value'] !== '') { $newResult = array(); // Traverse the current parts of the result array: foreach ($result as $part) { // Explode the string value by the word value to highlight: $explodedParts = explode($cfg['value'], $part['str']); foreach ($explodedParts as $c => $expValue) { if ((string) $expValue !== '') { $newResult[] = array_merge($part, array('str' => $expValue)); } if ($c + 1 < count($explodedParts)) { $newResult[] = array('str' => $cfg['value'], 'fontSize' => $cfg['fontSize'] ? $cfg['fontSize'] : $part['fontSize'], 'fontFile' => $cfg['fontFile'] ? $cfg['fontFile'] : $part['fontFile'], 'color' => $cfg['color'], 'xSpaceBefore' => $cfg['xSpaceBefore'], 'xSpaceAfter' => $cfg['xSpaceAfter'], 'ySpaceBefore' => $cfg['ySpaceBefore'], 'ySpaceAfter' => $cfg['ySpaceAfter']); } } } // Set the new result as result array: if (!empty($newResult)) { $result = $newResult; } } break; case 'charRange': if ((string) $cfg['value'] !== '') { // Initialize range: $ranges = GeneralUtility::trimExplode(',', $cfg['value'], true); foreach ($ranges as $i => $rangeDef) { $ranges[$i] = GeneralUtility::intExplode('-', $ranges[$i]); if (!isset($ranges[$i][1])) { $ranges[$i][1] = $ranges[$i][0]; } } $newResult = array(); // Traverse the current parts of the result array: foreach ($result as $part) { // Initialize: $currentState = -1; $bankAccum = ''; // Explode the string value by the word value to highlight: $utf8Chars = $this->csConvObj->utf8_to_numberarray($part['str'], true, true); foreach ($utf8Chars as $utfChar) { // Find number and evaluate position: $uNumber = (int) $this->csConvObj->utf8CharToUnumber($utfChar); $inRange = 0; foreach ($ranges as $rangeDef) { if ($uNumber >= $rangeDef[0] && (!$rangeDef[1] || $uNumber <= $rangeDef[1])) { $inRange = 1; break; } } if ($currentState == -1) { $currentState = $inRange; } // Initialize first char // Switch bank: if ($inRange != $currentState && $uNumber !== 9 && $uNumber !== 10 && $uNumber !== 13 && $uNumber !== 32) { // Set result: if ($bankAccum !== '') { $newResult[] = array('str' => $bankAccum, 'fontSize' => $currentState && $cfg['fontSize'] ? $cfg['fontSize'] : $part['fontSize'], 'fontFile' => $currentState && $cfg['fontFile'] ? $cfg['fontFile'] : $part['fontFile'], 'color' => $currentState ? $cfg['color'] : '', 'xSpaceBefore' => $currentState ? $cfg['xSpaceBefore'] : '', 'xSpaceAfter' => $currentState ? $cfg['xSpaceAfter'] : '', 'ySpaceBefore' => $currentState ? $cfg['ySpaceBefore'] : '', 'ySpaceAfter' => $currentState ? $cfg['ySpaceAfter'] : ''); } // Initialize new settings: $currentState = $inRange; $bankAccum = ''; } // Add char to bank: $bankAccum .= $utfChar; } // Set result for FINAL part: if ($bankAccum !== '') { $newResult[] = array('str' => $bankAccum, 'fontSize' => $currentState && $cfg['fontSize'] ? $cfg['fontSize'] : $part['fontSize'], 'fontFile' => $currentState && $cfg['fontFile'] ? $cfg['fontFile'] : $part['fontFile'], 'color' => $currentState ? $cfg['color'] : '', 'xSpaceBefore' => $currentState ? $cfg['xSpaceBefore'] : '', 'xSpaceAfter' => $currentState ? $cfg['xSpaceAfter'] : '', 'ySpaceBefore' => $currentState ? $cfg['ySpaceBefore'] : '', 'ySpaceAfter' => $currentState ? $cfg['ySpaceAfter'] : ''); } } // Set the new result as result array: if (!empty($newResult)) { $result = $newResult; } } break; } } } return $result; }
/** * Split a string into an array of individual characters * The function will look at $this->nativeCharset and if that is set, the input string is expected to be UTF-8 encoded, possibly with entities in it. Otherwise the string is supposed to be a single-byte charset which is just splitted by a for-loop. * * @param string $theText The text string to split * @param bool $returnUnicodeNumber Return Unicode numbers instead of chars. * @return array Numerical array with a char as each value. */ public function singleChars($theText, $returnUnicodeNumber = FALSE) { if ($this->nativeCharset) { // Get an array of separated UTF-8 chars return $this->csConvObj->utf8_to_numberarray($theText, 1, $returnUnicodeNumber ? 0 : 1); } else { $output = array(); $c = strlen($theText); for ($a = 0; $a < $c; $a++) { $output[] = substr($theText, $a, 1); } return $output; } }
/** * 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 $str Input string, encoded with UTF-8 * @return string Output string, a JavaScript function: "String.fromCharCode(......) */ public function JScharCode($str) { // Convert the UTF-8 string into a array of char numbers: $nArr = $this->csConvObj->utf8_to_numberarray($str); return 'String.fromCharCode(' . implode(',', $nArr) . ')'; }