Skip to content

Commit

Permalink
MDL-32575 import latest Typo3 libs for textlib and other improvements
Browse files Browse the repository at this point in the history
Includes new textlib reset, new test for faulty integer lower/upper casing.
  • Loading branch information
skodak committed Apr 21, 2012
1 parent ead4f18 commit bc5c10f
Show file tree
Hide file tree
Showing 10 changed files with 1,471 additions and 1,509 deletions.
1 change: 1 addition & 0 deletions lib/moodlelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1427,6 +1427,7 @@ function purge_all_caches() {
js_reset_all_caches();
theme_reset_all_caches();
get_string_manager()->reset_caches();
textlib::reset_caches();

// purge all other caches: rss, simplepie, etc.
remove_dir($CFG->cachedir.'', true);
Expand Down
1 change: 1 addition & 0 deletions lib/phpunit/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,7 @@ public static function reset_all_data($logchanges = false) {
accesslib_clear_all_caches(true);
get_string_manager()->reset_caches();
events_get_handlers('reset');
textlib::reset_caches();
//TODO: add more resets here and probably refactor them to new core function

// purge dataroot directory
Expand Down
4 changes: 4 additions & 0 deletions lib/tests/textlib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,10 @@ public function test_strtolower() {

$str = pack("H*", "bcf2cce5d6d0cec4"); //GB18030
$this->assertSame(textlib::strtolower($str, 'GB18030'), $str);

// typo3 has problems with integers
$str = 1309528800;
$this->assertSame((string)$str, textlib::strtolower($str));
}

/**
Expand Down
36 changes: 31 additions & 5 deletions lib/textlib.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,17 @@ class textlib {
/**
* Return t3lib helper class, which is used for conversion between charsets
*
* @param bool $reset
* @return t3lib_cs
*/
protected static function typo3() {
protected static function typo3($reset = false) {
static $typo3cs = null;

if ($reset) {
$typo3cs = null;
return null;
}

if (isset($typo3cs)) {
return $typo3cs;
}
Expand All @@ -65,6 +71,8 @@ protected static function typo3() {
// Required files
require_once($CFG->libdir.'/typo3/class.t3lib_cs.php');
require_once($CFG->libdir.'/typo3/class.t3lib_div.php');
require_once($CFG->libdir.'/typo3/interface.t3lib_singleton.php');
require_once($CFG->libdir.'/typo3/class.t3lib_l10n_locales.php');

// do not use mbstring or recode because it may return invalid results in some corner cases
$GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_convMethod'] = 'iconv';
Expand All @@ -85,16 +93,26 @@ protected static function typo3() {

// This full path constants must be defined too, transforming backslashes
// to forward slashed because 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->tempdir.'/'));
define ('TYPO3_OS', stristr(PHP_OS,'win')&&!stristr(PHP_OS,'darwin')?'WIN':'');
if (!defined('PATH_t3lib')) {
define('PATH_t3lib', str_replace('\\','/',$CFG->libdir.'/typo3/'));
define('PATH_typo3', str_replace('\\','/',$CFG->libdir.'/typo3/'));
define('PATH_site', str_replace('\\','/',$CFG->tempdir.'/'));
define('TYPO3_OS', stristr(PHP_OS,'win')&&!stristr(PHP_OS,'darwin')?'WIN':'');
}

$typo3cs = new t3lib_cs();

return $typo3cs;
}

/**
* Reset internal textlib caches.
* @static
*/
public static function reset_caches() {
self::typo3(true);
}

/**
* Standardise charset name
*
Expand Down Expand Up @@ -252,6 +270,10 @@ public static function strlen($text, $charset='utf-8') {
public static function strtolower($text, $charset='utf-8') {
$charset = self::parse_charset($charset);

if (is_int($text)) {
return (string)$text;
}

if ($charset === 'utf-8' and function_exists('mb_strtolower')) {
return mb_strtolower($text, 'UTF-8');
}
Expand All @@ -273,6 +295,10 @@ public static function strtolower($text, $charset='utf-8') {
public static function strtoupper($text, $charset='utf-8') {
$charset = self::parse_charset($charset);

if (is_int($text)) {
return (string)$text;
}

if ($charset === 'utf-8' and function_exists('mb_strtoupper')) {
return mb_strtoupper($text, 'UTF-8');
}
Expand Down
2 changes: 1 addition & 1 deletion lib/thirdpartylibs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@
<location>typo3</location>
<name>Typo3</name>
<license>GPL</license>
<version>4.5.0</version>
<version>4.6.8</version>
<licenseversion>2.0+</licenseversion>
</library>
<library>
Expand Down
Loading

0 comments on commit bc5c10f

Please sign in to comment.