/** * Sort arrays by label (index 0) * * @param array $arrayA * @param array $arrayB * @return int */ private function sortArray($arrayA, $arrayB) { // Convert labels from current charset system charset $strA = $this->csConvObj->conv($arrayA[0], $GLOBALS['LANG']->charSet, $this->charset); $strB = $this->csConvObj->conv($arrayB[0], $GLOBALS['LANG']->charSet, $this->charset); return strcoll($strA, $strB); }
/** * Extract the page abstract of the current frontend page * * @param \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController $fe Frontend engine * @param string $bodytext Fallback abstract * @return string Page abstract */ protected function _getPageAbstract(\TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController $fe, $abstract = '') { // If there is an description meta tag ... if (($description = $this->_getMetaContent($fe, 'description')) !== null) { $abstract = $description; // Else: Return the page record abstract if given } elseif (isset($fe->page) && is_array($fe->page) && strlen(trim($fe->page['abstract']))) { $abstract = trim($fe->page['abstract']); } return $this->_csObj->strtrunc('utf-8', $abstract, 255); }
/** * Add word to word-array * This function should be used to make sure CJK sequences are split up in the right way * * @param array Array of accumulated words * @param string Complete Input string from where to extract word * @param integer Start position of word in input string * @param integer The Length of the word string from start position * @return void */ function addWords(&$words, &$wordString, $start, $len) { // Get word out of string: $theWord = substr($wordString, $start, $len); // Get next chars unicode number and find type: $bc = 0; $cp = $this->utf8_ord($theWord, $bc); list($cType) = $this->charType($cp); // If string is a CJK sequence we follow this algorithm: /* DESCRIPTION OF (CJK) ALGORITHM Continuous letters and numbers make up words. Spaces and symbols separate letters and numbers into words. This is sufficient for all western text. CJK doesn't use spaces or separators to separate words, so the only way to really find out what constitutes a word would be to have a dictionary and advanced heuristics. Instead, we form pairs from consecutive characters, in such a way that searches will find only characters that appear more-or-less the right sequence. For example: ABCDE => AB BC CD DE This works okay since both the index and the search query is split in the same manner, and since the set of characters is huge so the extra matches are not significant. (Hint taken from ZOPEs chinese user group) [Kasper: As far as I can see this will only work well with or-searches!] */ if ($cType == 'cjk') { // Find total string length: $strlen = $this->csObj->utf8_strlen($theWord); // Traverse string length and add words as pairs of two chars: for ($a = 0; $a < $strlen; $a++) { if ($strlen == 1 || $a < $strlen - 1) { $words[] = $this->csObj->utf8_substr($theWord, $a, 2); } } } else { // Normal "single-byte" chars: // Remove chars: foreach ($this->lexerConf['removeChars'] as $skipJoin) { $theWord = str_replace($this->csObj->UnumberToChar($skipJoin), '', $theWord); } // Add word: $words[] = $theWord; } }
/** * Constructor for initializing the class * * @return void */ function init() { // Initialize GPvars: $this->number = t3lib_div::_GP('number'); $this->target = t3lib_div::_GP('target'); $this->returnUrl = t3lib_div::_GP('returnUrl'); $this->returnUrl = $this->returnUrl ? $this->returnUrl : t3lib_div::getIndpEnv('TYPO3_SITE_URL') . TYPO3_mainDir . 'file_list.php?id=' . rawurlencode($this->target); // set the number of input fields if (empty($this->number)) { $this->number = $GLOBALS['BE_USER']->getTSConfigVal('options.defaultFileUploads'); } $this->number = t3lib_div::intInRange($this->number, 1, $this->uploadNumber); // Init basic-file-functions object: $this->basicff = t3lib_div::makeInstance('t3lib_basicFileFunctions'); $this->basicff->init($GLOBALS['FILEMOUNTS'], $GLOBALS['TYPO3_CONF_VARS']['BE']['fileExtensions']); // Init basic-charset-functions object: $this->charsetConversion = t3lib_div::makeInstance('t3lib_cs'); // Cleaning and checking target $this->target = $this->charsetConversion->conv($this->target, 'utf-8', $GLOBALS['LANG']->charSet); $this->target = $this->basicff->is_directory($this->target); $key = $this->basicff->checkPathAgainstMounts($this->target . '/'); if (!$this->target || !$key) { t3lib_BEfunc::typo3PrintError($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xml:paramError', true), $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xml:targetNoDir', true), ''); exit; } // Finding the icon switch ($GLOBALS['FILEMOUNTS'][$key]['type']) { case 'user': $this->icon = 'gfx/i/_icon_ftp_user.gif'; break; case 'group': $this->icon = 'gfx/i/_icon_ftp_group.gif'; break; default: $this->icon = 'gfx/i/_icon_ftp.gif'; break; } $this->icon = '<img' . t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'], $this->icon, 'width="18" height="16"') . ' title="" alt="" />'; // Relative path to filemount, $key: $this->shortPath = substr($this->target, strlen($GLOBALS['FILEMOUNTS'][$key]['path'])); // Setting title: $this->title = $this->icon . htmlspecialchars($GLOBALS['FILEMOUNTS'][$key]['name']) . ': ' . $this->shortPath; // Setting template object $this->doc = t3lib_div::makeInstance('template'); $this->doc->setModuleTemplate('templates/file_upload.html'); $this->doc->backPath = $GLOBALS['BACK_PATH']; $this->doc->form = '<form action="tce_file.php" method="post" name="editform" enctype="' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['form_enctype'] . '">'; if ($GLOBALS['BE_USER']->jsConfirmation(1)) { $confirm = ' && confirm(' . $GLOBALS['LANG']->JScharCode($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:mess.redraw')) . ')'; } else { $confirm = ''; } $this->doc->JScode = $this->doc->wrapScriptTags(' var path = "' . $this->target . '"; function reload(a) { // if (!changed || (changed ' . $confirm . ')) { var params = "&target="+encodeURIComponent(path)+"&number="+a+"&returnUrl=' . urlencode($this->charsetConversion->conv($this->returnUrl, $GLOBALS['LANG']->charSet, 'utf-8')) . '"; window.location.href = "file_upload.php?"+params; } } function backToList() { // top.goToModule("file_list"); } var changed = 0; '); }
/** * Extracts the sample description text from the content array. * * @param array Content array * @return string Description string */ function bodyDescription($contentArr) { // Setting description $maxL = t3lib_div::intInRange($this->conf['index_descrLgd'], 0, 255, 200); if ($maxL) { // Takes the quadruple lenght first, because whitespace and entities may be removed and thus shorten the string more yet. # $bodyDescription = implode(' ',split('[[:space:],]+',substr(trim($contentArr['body']),0,$maxL*4))); $bodyDescription = str_replace(array(' ', TAB, CR, LF), ' ', $contentArr['body']); // Shorten the string: $bodyDescription = $this->csObj->strtrunc('utf-8', $bodyDescription, $maxL); } return $bodyDescription; }
/** * 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 The text string to split * @param boolean Return Unicode numbers instead of chars. * @return array Numerical array with a char as each value. */ function singleChars($theText, $returnUnicodeNumber = FALSE) { if ($this->nativeCharset) { return $this->csConvObj->utf8_to_numberarray($theText, 1, $returnUnicodeNumber ? 0 : 1); // Get an array of separated UTF-8 chars } else { $output = array(); $c = strlen($theText); for ($a = 0; $a < $c; $a++) { $output[] = substr($theText, $a, 1); } return $output; } }
/** * Constructor function for class * * @return void */ function init() { global $LANG, $BACK_PATH, $TYPO3_CONF_VARS; // Initialize GPvars: $this->number = t3lib_div::_GP('number'); $this->target = t3lib_div::_GP('target'); $this->returnUrl = t3lib_div::sanitizeLocalUrl(t3lib_div::_GP('returnUrl')); // Init basic-file-functions object: $this->basicff = t3lib_div::makeInstance('t3lib_basicFileFunctions'); $this->basicff->init($GLOBALS['FILEMOUNTS'], $TYPO3_CONF_VARS['BE']['fileExtensions']); // Init basic-charset-functions object: $this->charsetConversion = t3lib_div::makeInstance('t3lib_cs'); // Cleaning and checking target $this->target = $this->charsetConversion->conv($this->target, 'utf-8', $GLOBALS['LANG']->charSet); $this->target = $this->basicff->is_directory($this->target); $key = $this->basicff->checkPathAgainstMounts($this->target . '/'); if (!$this->target || !$key) { $title = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xml:paramError', TRUE); $message = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xml:targetNoDir', TRUE); throw new RuntimeException($title . ': ' . $message); } // Finding the icon switch ($GLOBALS['FILEMOUNTS'][$key]['type']) { case 'user': $this->icon = 'gfx/i/_icon_ftp_user.gif'; break; case 'group': $this->icon = 'gfx/i/_icon_ftp_group.gif'; break; default: $this->icon = 'gfx/i/_icon_ftp.gif'; break; } $this->icon = '<img' . t3lib_iconWorks::skinImg($this->backPath, $this->icon, 'width="18" height="16"') . ' title="" alt="" />'; // Relative path to filemount, $key: $this->shortPath = substr($this->target, strlen($GLOBALS['FILEMOUNTS'][$key]['path'])); // Setting title: $this->title = $this->icon . htmlspecialchars($GLOBALS['FILEMOUNTS'][$key]['name']) . ': ' . $this->shortPath; // Setting template object $this->doc = t3lib_div::makeInstance('template'); $this->doc->setModuleTemplate('templates/file_newfolder.html'); $this->doc->backPath = $BACK_PATH; $this->doc->JScode = $this->doc->wrapScriptTags(' var path = "' . $this->target . '"; function reload(a) { // if (!changed || (changed && confirm(' . $LANG->JScharCode($LANG->sL('LLL:EXT:lang/locallang_core.php:mess.redraw')) . '))) { var params = "&target="+encodeURIComponent(path)+"&number="+a+"&returnUrl=' . urlencode($this->charsetConversion->conv($this->returnUrl, $GLOBALS['LANG']->charSet, 'utf-8')) . '"; window.location.href = "file_newfolder.php?"+params; } } function backToList() { // top.goToModule("file_list"); } var changed = 0; '); }
/** * Converts the $_POST array from metaCharset (page HTML charset from input form) to renderCharset (internal processing) IF the two charsets are different. * * @return void */ function convPOSTCharset() { if ($this->renderCharset != $this->metaCharset && is_array($_POST) && count($_POST)) { $this->csConvObj->convArray($_POST, $this->metaCharset, $this->renderCharset); $GLOBALS['HTTP_POST_VARS'] = $_POST; } }
/** * @test */ public function utf8_strlenForNonEmptyAsciiOnlyStringReturnsNumberOfCharacters() { $this->assertEquals(10, $this->fixture->utf8_strlen('good omens')); }
/** * 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(......)" * @access public */ public function JScharCode($str) { // Convert string to UTF-8: if ($this->charSet != 'utf-8') { $str = $this->csConvObj->utf8_encode($str, $this->charSet); } // Convert the UTF-8 string into a array of char numbers: $nArr = $this->csConvObj->utf8_to_numberarray($str); return 'String.fromCharCode(' . implode(',', $nArr) . ')'; }