| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
/////////////////////////////////////////////////////////////////////////// |
|---|
| 4 |
// // |
|---|
| 5 |
// NOTICE OF COPYRIGHT // |
|---|
| 6 |
// // |
|---|
| 7 |
// Moodle - Modular Object-Oriented Dynamic Learning Environment // |
|---|
| 8 |
// http://moodle.com // |
|---|
| 9 |
// // |
|---|
| 10 |
// Copyright (C) 2001-3001 Martin Dougiamas http://dougiamas.com // |
|---|
| 11 |
// (C) 2001-3001 Eloy Lafuente (stronk7) http://contiento.com // |
|---|
| 12 |
// // |
|---|
| 13 |
// This program is free software; you can redistribute it and/or modify // |
|---|
| 14 |
// it under the terms of the GNU General Public License as published by // |
|---|
| 15 |
// the Free Software Foundation; either version 2 of the License, or // |
|---|
| 16 |
// (at your option) any later version. // |
|---|
| 17 |
// // |
|---|
| 18 |
// This program is distributed in the hope that it will be useful, // |
|---|
| 19 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of // |
|---|
| 20 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
|---|
| 21 |
// GNU General Public License for more details: // |
|---|
| 22 |
// // |
|---|
| 23 |
// http://www.gnu.org/copyleft/gpl.html // |
|---|
| 24 |
// // |
|---|
| 25 |
/////////////////////////////////////////////////////////////////////////// |
|---|
| 26 |
|
|---|
| 27 |
/// Required files |
|---|
| 28 |
require_once($CFG->dirroot . 'lib/typo3/class.t3lib_cs.php'); |
|---|
| 29 |
require_once($CFG->dirroot . 'lib/typo3/class.t3lib_div.php'); |
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
if (extension_loaded('iconv')) { |
|---|
| 33 |
$GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_convMethod'] = 'iconv'; |
|---|
| 34 |
iconv_set_encoding('internal_encoding','utf-8'); |
|---|
| 35 |
|
|---|
| 36 |
} else if (extension_loaded('mbstring')) { |
|---|
| 37 |
$GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_convMethod'] = 'mbstring'; |
|---|
| 38 |
mb_internal_encoding('utf-8'); |
|---|
| 39 |
|
|---|
| 40 |
$GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_convMethod'] = ''; |
|---|
| 41 |
|
|---|
| 42 |
|
|---|
| 43 |
|
|---|
| 44 |
if (extension_loaded('mbstring')) { |
|---|
| 45 |
$GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_utils'] = 'mbstring'; |
|---|
| 46 |
|
|---|
| 47 |
$GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_utils'] = ''; |
|---|
| 48 |
|
|---|
| 49 |
|
|---|
| 50 |
make_upload_directory('temp/typo3temp/cs'); |
|---|
| 51 |
|
|---|
| 52 |
|
|---|
| 53 |
|
|---|
| 54 |
$GLOBALS['TYPO3_CONF_VARS']['BE']['fileCreateMask'] = $CFG->directorypermissions; |
|---|
| 55 |
|
|---|
| 56 |
|
|---|
| 57 |
|
|---|
| 58 |
define ('PATH_t3lib', str_replace('\\','/', $CFG->dirroot.'lib/typo3/')); |
|---|
| 59 |
define ('PATH_typo3', str_replace('\\','/', $CFG->dirroot.'lib/typo3/')); |
|---|
| 60 |
define ('PATH_site', str_replace('\\','/', $CFG->dataroot.'temp/')); |
|---|
| 61 |
define ('TYPO3_OS', stristr(PHP_OS,'win')&&!stristr(PHP_OS,'darwin')?'WIN':''); |
|---|
| 62 |
|
|---|
| 63 |
|
|---|
| 64 |
|
|---|
| 65 |
|
|---|
| 66 |
|
|---|
| 67 |
|
|---|
| 68 |
|
|---|
| 69 |
|
|---|
| 70 |
|
|---|
| 71 |
function textlib_get_instance () { |
|---|
| 72 |
static $instance; |
|---|
| 73 |
if (!is_object($instance)) { |
|---|
| 74 |
$instance = new textlib(); |
|---|
| 75 |
} |
|---|
| 76 |
return $instance; |
|---|
| 77 |
} |
|---|
| 78 |
|
|---|
| 79 |
|
|---|
| 80 |
|
|---|
| 81 |
|
|---|
| 82 |
|
|---|
| 83 |
|
|---|
| 84 |
|
|---|
| 85 |
|
|---|
| 86 |
|
|---|
| 87 |
|
|---|
| 88 |
|
|---|
| 89 |
|
|---|
| 90 |
class textlib { |
|---|
| 91 |
|
|---|
| 92 |
var $typo3cs; |
|---|
| 93 |
|
|---|
| 94 |
|
|---|
| 95 |
* a new t3lib_cs object to have all their functions ready. |
|---|
| 96 |
* |
|---|
| 97 |
* Instead of istantiating a lot of objects of this class everytime |
|---|
| 98 |
* some of their functions is going to be used, you can invoke the: |
|---|
| 99 |
* textlib_get_instance() function, avoiding the creation of them |
|---|
| 100 |
* (following the singleton pattern) |
|---|
| 101 |
*/ |
|---|
| 102 |
function textlib() { |
|---|
| 103 |
|
|---|
| 104 |
/// reference to $this and cannot be executed in a static context |
|---|
| 105 |
$this->typo3cs = new t3lib_cs(); |
|---|
| 106 |
} |
|---|
| 107 |
|
|---|
| 108 |
|
|---|
| 109 |
* or internal (typo3) methods to try such conversion. Returns false if fails. |
|---|
| 110 |
*/ |
|---|
| 111 |
function convert($text, $fromCS, $toCS='utf-8') { |
|---|
| 112 |
|
|---|
| 113 |
$oldlevel = error_reporting(E_PARSE); |
|---|
| 114 |
|
|---|
| 115 |
$result = $this->typo3cs->conv($text, strtolower($fromCS), strtolower($toCS)); |
|---|
| 116 |
|
|---|
| 117 |
error_reporting($oldlevel); |
|---|
| 118 |
return $result; |
|---|
| 119 |
} |
|---|
| 120 |
|
|---|
| 121 |
|
|---|
| 122 |
function substr($text, $start, $len=null, $charset='utf-8') { |
|---|
| 123 |
|
|---|
| 124 |
return $this->typo3cs->substr(strtolower($charset),$text,$start,$len); |
|---|
| 125 |
} |
|---|
| 126 |
|
|---|
| 127 |
|
|---|
| 128 |
function strlen($text, $charset='utf-8') { |
|---|
| 129 |
|
|---|
| 130 |
$oldlevel = error_reporting(E_PARSE); |
|---|
| 131 |
|
|---|
| 132 |
$result = $this->typo3cs->strlen(strtolower($charset),$text); |
|---|
| 133 |
|
|---|
| 134 |
error_reporting($oldlevel); |
|---|
| 135 |
return $result; |
|---|
| 136 |
} |
|---|
| 137 |
|
|---|
| 138 |
|
|---|
| 139 |
function strtolower($text, $charset='utf-8') { |
|---|
| 140 |
|
|---|
| 141 |
$oldlevel = error_reporting(E_PARSE); |
|---|
| 142 |
|
|---|
| 143 |
$result = $this->typo3cs->conv_case(strtolower($charset),$text,'toLower'); |
|---|
| 144 |
|
|---|
| 145 |
error_reporting($oldlevel); |
|---|
| 146 |
return $result; |
|---|
| 147 |
} |
|---|
| 148 |
|
|---|
| 149 |
|
|---|
| 150 |
function strtoupper($text, $charset='utf-8') { |
|---|
| 151 |
|
|---|
| 152 |
$oldlevel = error_reporting(E_PARSE); |
|---|
| 153 |
|
|---|
| 154 |
$result = $this->typo3cs->conv_case(strtolower($charset),$text,'toUpper'); |
|---|
| 155 |
|
|---|
| 156 |
error_reporting($oldlevel); |
|---|
| 157 |
return $result; |
|---|
| 158 |
} |
|---|
| 159 |
|
|---|
| 160 |
|
|---|
| 161 |
function strpos($haystack,$needle,$offset=0) { |
|---|
| 162 |
|
|---|
| 163 |
return $this->typo3cs->utf8_strpos($haystack,$needle,$offset); |
|---|
| 164 |
} |
|---|
| 165 |
|
|---|
| 166 |
|
|---|
| 167 |
function strrpos($haystack,$needle) { |
|---|
| 168 |
|
|---|
| 169 |
return $this->typo3cs->utf8_strrpos($haystack,$needle); |
|---|
| 170 |
} |
|---|
| 171 |
|
|---|
| 172 |
} |
|---|
| 173 |
?> |
|---|
| 174 |
|
|---|