directorypermissions; /// This full path constants must be defined too, transforming backslashes /// to forward slashed beacuse Typo3 requires it. define ('PATH_t3lib', str_replace('\\','/',$CFG->libdir.'/typo3/')); define ('PATH_typo3', str_replace('\\','/',$CFG->libdir.'/typo3/')); define ('PATH_site', str_replace('\\','/',$CFG->dataroot.'/temp/')); define ('TYPO3_OS', stristr(PHP_OS,'win')&&!stristr(PHP_OS,'darwin')?'WIN':''); /// As we implement the singleton pattern to use this class (only one instance /// is shared globally), we need this helper function /// IMPORTANT Note: Typo3 libraries always expect lowercase charsets to use 100% /// its capabilities so, don't forget to make the conversion /// from every wrapper function! function textlib_get_instance () { static $instance; if (!is_object($instance)) { $instance = new textlib(); } return $instance; } /** * This class is used to manipulate strings under Moodle 1.6 an later. As * utf-8 text become mandatory a pool of safe functions under this encoding * become necessary. The name of the methods is exactly the * same than their PHP originals. * * A big part of this class acts as a wrapper over the Typo3 charset library, * really a cool group of utilities to handle texts and encoding conversion. * * Take a look to its own copyright and license details. */ class textlib { var $typo3cs; /* Standard constructor of the class. All it does is to instantiate * a new t3lib_cs object to have all their functions ready. * * Instead of istantiating a lot of objects of this class everytime * some of their functions is going to be used, you can invoke the: * textlib_get_instance() function, avoiding the creation of them * (following the singleton pattern) */ function textlib() { /// Instantiate a conversor object some of the methods in typo3 /// reference to $this and cannot be executed in a static context $this->typo3cs = new t3lib_cs(); } /* Converts the text between different encodings. It will use iconv, mbstring * or internal (typo3) methods to try such conversion. Returns false if fails. */ function convert($text, $fromCS, $toCS='utf-8') { /// Avoid some notices from Typo3 code $oldlevel = error_reporting(E_PARSE); /// Call Typo3 conv() function. It will do all the work $result = $this->typo3cs->conv($text, strtolower($fromCS), strtolower($toCS)); /// Restore original debug level error_reporting($oldlevel); return $result; } /* Multibyte safe substr() function, uses mbstring if available. */ function substr($text, $start, $len=null, $charset='utf-8') { /// Avoid some notices from Typo3 code $oldlevel = error_reporting(E_PARSE); /// Call Typo3 substr() function. It will do all the work $result = $this->typo3cs->substr(strtolower($charset),$text,$start,$len); /// Restore original debug level error_reporting($oldlevel); return $result; } /* Multibyte safe strlen() function, uses mbstring if available. */ function strlen($text, $charset='utf-8') { /// Avoid some notices from Typo3 code $oldlevel = error_reporting(E_PARSE); /// Call Typo3 strlen() function. It will do all the work $result = $this->typo3cs->strlen(strtolower($charset),$text); /// Restore original debug level error_reporting($oldlevel); return $result; } /* Multibyte safe strtolower() function, uses mbstring if available. */ function strtolower($text, $charset='utf-8') { /// Avoid some notices from Typo3 code $oldlevel = error_reporting(E_PARSE); /// Call Typo3 conv_case() function. It will do all the work $result = $this->typo3cs->conv_case(strtolower($charset),$text,'toLower'); /// Restore original debug level error_reporting($oldlevel); return $result; } /* Multibyte safe strtoupper() function, uses mbstring if available. */ function strtoupper($text, $charset='utf-8') { /// Avoid some notices from Typo3 code $oldlevel = error_reporting(E_PARSE); /// Call Typo3 conv_case() function. It will do all the work $result = $this->typo3cs->conv_case(strtolower($charset),$text,'toUpper'); /// Restore original debug level error_reporting($oldlevel); return $result; } /* UTF-8 ONLY safe strpos() function, uses mbstring if available. */ function strpos($haystack,$needle,$offset=0) { /// Call Typo3 utf8_strpos() function. It will do all the work return $this->typo3cs->utf8_strpos($haystack,$needle,$offset); } /* UTF-8 ONLY safe strrpos() function, uses mbstring if available. */ function strrpos($haystack,$needle) { /// Call Typo3 utf8_strrpos() function. It will do all the work return $this->typo3cs->utf8_strrpos($haystack,$needle); } /* Try to convert upper unicode characters to plain ascii, * the returned string may cantain unconverted unicode characters. */ function specialtoascii($text,$charset='utf-8') { /// Avoid some notices from Typo3 code $oldlevel = error_reporting(E_PARSE); $result = $this->typo3cs->specCharsToASCII(strtolower($charset),$text); /// Restore original debug level error_reporting($oldlevel); return $result; } } ?>