Index: t3lib/class.t3lib_cs.php =================================================================== --- t3lib/class.t3lib_cs.php (revision 8072) +++ t3lib/class.t3lib_cs.php (working copy) @@ -618,6 +618,25 @@ */ function conv($str,$fromCS,$toCS,$useEntityForNoChar=0) { if ($fromCS==$toCS) return $str; + + // autodetect + if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_convMethod'] == 'auto') { + + //check for mbstring support + if (function_exists('mb_convert_encoding')) { + $GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_convMethod'] = 'mbstring'; + + } elseif (function_exists('iconv')) { + $GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_convMethod'] = 'iconv'; + + } elseif (function_exists('recode')) { + $GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_convMethod'] = 'recode'; + + } else { + // clear value for fallback + $GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_convMethod'] = ''; + } + } // PHP-libs don't support fallback to SGML entities, but UTF-8 handles everything if ($toCS=='utf-8' || !$useEntityForNoChar) { @@ -1357,7 +1376,37 @@ return 3; } + + + /** + * This function checks for available string conversions. + * + * @access private + */ + function autodetect_cs_utils_mode() { + + // execute only if necessary + if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_utils'] == 'auto') { + + //check for mbstring support + if (function_exists('mb_convert_encoding')) { + $GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_utils'] = 'mbstring'; + + } elseif (function_exists('iconv')) { + $GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_utils'] = 'iconv'; + + } elseif (function_exists('recode')) { + $GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_utils'] = 'recode'; + + } else { + // clear value for fallback + $GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_utils'] = ''; + + } + } + + } @@ -1373,6 +1422,7 @@ + /******************************************** * * String operation functions @@ -1395,6 +1445,8 @@ if ($len === 0 || $string === '') { return ''; } + + if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_utils'] == 'auto') $this->autodetect_cs_utils_mode(); if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_utils'] == 'mbstring') { // cannot omit $len, when specifying charset @@ -1447,6 +1499,9 @@ * @author Martin Kutschker */ function strlen($charset,$string) { + + if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_utils'] == 'auto') $this->autodetect_cs_utils_mode(); + if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_utils'] == 'mbstring') { return mb_strlen($string,$charset); } elseif ($GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_utils'] == 'iconv') { @@ -1501,6 +1556,9 @@ * @author Martin Kutschker */ function crop($charset,$string,$len,$crop='') { + + if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_utils'] == 'auto') $this->autodetect_cs_utils_mode(); + if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_utils'] == 'mbstring') { return $this->cropMbstring($charset, $string, $len, $crop); } @@ -1559,6 +1617,8 @@ */ function strtrunc($charset,$string,$len) { if ($len <= 0) return ''; + + if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_utils'] == 'auto') $this->autodetect_cs_utils_mode(); if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_utils'] == 'mbstring') { return mb_strcut($string,0,$len,$charset); @@ -1592,6 +1652,9 @@ * @see strtolower(), strtoupper() */ function conv_case($charset,$string,$case) { + + if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_utils'] == 'auto') $this->autodetect_cs_utils_mode(); + if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_utils'] == 'mbstring') { if ($case == 'toLower') { $string = mb_strtolower($string,$charset); @@ -1849,6 +1912,9 @@ * @author Martin Kutschker */ function utf8_strpos($haystack,$needle,$offset=0) { + + if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_utils'] == 'auto') $this->autodetect_cs_utils_mode(); + if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_utils'] == 'mbstring') { return mb_strpos($haystack,$needle,$offset,'utf-8'); } elseif ($GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_utils'] == 'iconv') { @@ -1874,6 +1940,9 @@ * @author Martin Kutschker */ function utf8_strrpos($haystack,$needle) { + + if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_utils'] == 'auto') $this->autodetect_cs_utils_mode(); + if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_utils'] == 'mbstring') { return mb_strrpos($haystack,$needle,'utf-8'); } elseif ($GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_utils'] == 'iconv') { Index: t3lib/config_default.php =================================================================== --- t3lib/config_default.php (revision 8072) +++ t3lib/config_default.php (working copy) @@ -84,8 +84,8 @@ 'T3instID' => 'N/A', // A unique installation ID - not used yet. The idea is that a TYPO3 installation can identify itself by this ID string to the Extension Repository on TYPO3.org so that we can keep a realistic count of serious TYPO3 installations. 'binPath' => '', // String: List of absolute paths where external programs should be searched for. Eg. '/usr/local/webbin/,/home/xyz/bin/'. (ImageMagick path have to be configured separately) 'binSetup' => '', // String (textarea): List of programs (separated by newline or comma). By default programs will be searched in default paths and the special paths defined by 'binPath'. When PHP has openbasedir enabled the programs can not be found and have to be configured here. Example: 'perl=/usr/bin/perl,unzip=/usr/local/bin/unzip' - 't3lib_cs_convMethod' => '', // String (values: "iconv", "recode", "mbstring", default is homemade PHP-code). Defines which of these PHP-features to use for various charset conversion functions in t3lib_cs. Will speed up charset conversion radically. - 't3lib_cs_utils' => '', // String (values: "iconv", "mbstring", default is homemade PHP-code). Defines which of these PHP-features to use for various charset processing functions in t3lib_cs. Will speed up charset functions radically. + 't3lib_cs_convMethod' => 'auto', // String (values: "auto", "iconv", "recode", "mbstring", default is homemade PHP-code). Defines which of these PHP-features to use for various charset conversion functions in t3lib_cs. Will speed up charset conversion radically. Value 'auto' will check for existing functions in the following order: "mbstring" -> "iconv" -> "recode" -> default + 't3lib_cs_utils' => 'auto', // String (values: "auto", "iconv", "mbstring", default is homemade PHP-code). Defines which of these PHP-features to use for various charset processing functions in t3lib_cs. Will speed up charset functions radically. Value 'auto' will check for existing functions in the following order: "mbstring" -> "iconv" -> "recode" -> default 'no_pconnect' => FALSE, // Boolean: If true, "connect" is used instead of "pconnect" when connecting to the database! 'multiplyDBfieldSize' => 1, // Double: 1-5: Amount used to multiply the DB field size when the install tool is evaluating the database size (eg. "2.5"). This is only useful e.g. if your database is iso-8859-1 encoded but you want to use utf-8 for your site. For Western European sites using utf-8 the need should not be for more than twice the normal single-byte size (2) and for Chinese / Asian languages 3 should suffice. NOTICE: It is recommended to change the native database charset instead! (see http://wiki.typo3.org/index.php/UTF-8_support for more information) 'setDBinit' => '', // String (textarea): Commands to send to database right after connecting, separated by newline. Ignored by the DBAL extension except for the 'native' type!