From: skodak Date: Mon, 16 Jun 2008 15:31:21 +0000 (+0000) Subject: MDL-8246 new typo3 lib imported X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=38a4e1d6647487632afd98f1a5f1da9454122099;p=moodle.git MDL-8246 new typo3 lib imported --- diff --git a/lib/typo3/class.t3lib_cs.php b/lib/typo3/class.t3lib_cs.php index 28f7b1f702..918aaa420c 100644 --- a/lib/typo3/class.t3lib_cs.php +++ b/lib/typo3/class.t3lib_cs.php @@ -2,7 +2,7 @@ /*************************************************************** * Copyright notice * -* (c) 2003-2006 Kasper Skaarhoj (kasperYYYY@typo3.com) +* (c) 2003-2008 Kasper Skaarhoj (kasperYYYY@typo3.com) * All rights reserved * * This script is part of the Typo3 project. The Typo3 project is @@ -24,7 +24,7 @@ /** * Class for conversion between charsets. * - * Typo Id: class.t3lib_cs.php,v 1.56 2006/05/03 08:47:30 masi Exp $ + * Typo Id: class.t3lib_cs.php 3439 2008-03-16 19:16:51Z flyguide $ * Moodle $Id$ * * @author Kasper Skaarhoj @@ -265,6 +265,8 @@ class t3lib_cs { 'fi' => 'west_european', // Finish 'fo' => 'west_european', // Faroese 'fr' => 'west_european', // French + 'ga' => 'west_european', // Galician + 'ge' => 'unicode', // Georgian 'gr' => 'greek', 'he' => 'hebrew', // Hebrew (since 1998) 'hi' => 'unicode', // Hindi @@ -288,6 +290,7 @@ class t3lib_cs { 'sl' => 'east_european', // Slovenian 'sr' => 'cyrillic', // Serbian 'sv' => 'west_european', // Swedish + 'sq' => 'albanian', // Albanian 'th' => 'thai', 'uk' => 'cyrillic', // Ukranian 'vi' => 'vietnamese', @@ -317,6 +320,8 @@ class t3lib_cs { 'frb' => 'west_european', // French (Belgian) 'frc' => 'west_european', // French (Canadian) 'frs' => 'west_european', // French (Swiss) + 'geo' => 'unicode', // Georgian + 'glg' => 'west_european', // Galician 'ell' => 'greek', 'heb' => 'hebrew', 'hin' => 'unicode', // Hindi @@ -346,10 +351,12 @@ class t3lib_cs { 'esm' => 'west_european', // Spanish (Mexican) 'esn' => 'west_european', // Spanish (internat. sort) 'sve' => 'west_european', // Swedish + 'sqi' => 'albanian', // Albanian 'tha' => 'thai', 'trk' => 'turkish', 'ukr' => 'cyrillic', // Ukrainian // English language names + 'albanian' => 'albanian', 'arabic' => 'arabic', 'basque' => 'west_european', 'bosnian' => 'east_european', @@ -367,6 +374,7 @@ class t3lib_cs { 'finnish' => 'west_european', 'french' => 'west_european', 'galician' => 'west_european', + 'georgian' => 'unicode', 'german' => 'west_european', 'greek' => 'greek', 'greenlandic' => 'west_european', @@ -415,6 +423,7 @@ class t3lib_cs { 'trad_chinese' => 'big5', 'vietnamese' => '', 'unicode' => 'utf-8', + 'albanian' => 'utf-8' ); // mapping of language (family) names to charsets on Windows @@ -436,6 +445,8 @@ class t3lib_cs { 'japanese' => 'shift_jis', 'simpl_chinese' => 'gb2312', 'trad_chinese' => 'big5', + 'albanian' => 'windows-1250', + 'unicode' => 'utf-8' ); // mapping of locale names to charsets @@ -496,7 +507,10 @@ class t3lib_cs { 'hi' => 'utf-8', 'fo' => 'utf-8', 'fa' => 'utf-8', - 'sr' => 'utf-8' + 'sr' => 'utf-8', + 'sq' => 'utf-8', + 'ge' => 'utf-8', + 'ga' => '', ); // TYPO3 specific: Array with the iso names used for each system language in TYPO3: @@ -526,7 +540,7 @@ class t3lib_cs { * @author Martin Kutschker */ function parse_charset($charset) { - $charset = strtolower($charset); + $charset = trim(strtolower($charset)); if (isset($this->synonyms[$charset])) $charset = $this->synonyms[$charset]; return $charset; @@ -565,7 +579,7 @@ class t3lib_cs { if (isset($this->lang_to_script[$language])) $script = $this->lang_to_script[$language]; if (TYPO3_OS == 'WIN') { - $cs = $this->script_to_charset_windows[$script] ? $this->script_to_charset_windows[$script] : 'window-1252'; + $cs = $this->script_to_charset_windows[$script] ? $this->script_to_charset_windows[$script] : 'windows-1252'; } else { $cs = $this->script_to_charset_unix[$script] ? $this->script_to_charset_unix[$script] : 'iso-8859-1'; } @@ -609,7 +623,7 @@ class t3lib_cs { break; case 'iconv': - $conv_str = iconv($fromCS,$toCS.'//IGNORE',$str); + $conv_str = iconv($fromCS,$toCS.'//TRANSLIT',$str); if (false !== $conv_str) return $conv_str; break; @@ -1539,7 +1553,7 @@ class t3lib_cs { * @see strtolower(), strtoupper() */ function conv_case($charset,$string,$case) { - if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_utils'] == 'mbstring' && (float)phpversion() >= 4.3) { + if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_utils'] == 'mbstring') { if ($case == 'toLower') { $string = mb_strtolower($string,$charset); } else { diff --git a/lib/typo3/class.t3lib_div.php b/lib/typo3/class.t3lib_div.php index cc2c69e0d0..1b9dbb17de 100644 --- a/lib/typo3/class.t3lib_div.php +++ b/lib/typo3/class.t3lib_div.php @@ -2,7 +2,7 @@ /*************************************************************** * Copyright notice * -* (c) 1999-2005 Kasper Skaarhoj (kasperYYYY@typo3.com) +* (c) 1999-2008 Kasper Skaarhoj (kasperYYYY@typo3.com) * All rights reserved * * This script is part of the TYPO3 project. The TYPO3 project is @@ -27,7 +27,8 @@ /** * Contains the reknown class "t3lib_div" with general purpose functions * - * $Id$ + * Typo Id: class.t3lib_div.php 3797 2008-06-11 06:39:13Z stucki $ + * Moodle $Id$ * Revised for TYPO3 3.6 July/2003 by Kasper Skaarhoj * XHTML compliant * Usage counts are based on search 22/2 2003 through whole source including tslib/ @@ -39,144 +40,165 @@ * * * - * 211: class t3lib_div + * 232: class t3lib_div * * SECTION: GET/POST Variables - * 241: function _GP($var) - * 259: function _GET($var=NULL) - * 276: function _POST($var=NULL) - * 292: function _GETset($inputGet,$key='') - * 315: function GPvar($var,$strip=0) - * 332: function GParrayMerged($var) + * 262: function _GP($var) + * 280: function _GET($var=NULL) + * 297: function _POST($var=NULL) + * 313: function _GETset($inputGet,$key='') + * 336: function GPvar($var,$strip=0) + * 353: function GParrayMerged($var) * * SECTION: IMAGE FUNCTIONS - * 376: function gif_compress($theFile, $type) - * 402: function png_to_gif_by_imagemagick($theFile) - * 426: function read_png_gif($theFile,$output_png=0) + * 397: function gif_compress($theFile, $type) + * 425: function png_to_gif_by_imagemagick($theFile) + * 450: function read_png_gif($theFile,$output_png=0) * * SECTION: STRING FUNCTIONS - * 475: function fixed_lgd($string,$origChars,$preStr='...') - * 500: function fixed_lgd_pre($string,$chars) - * 514: function fixed_lgd_cs($string,$chars) - * 531: function breakTextForEmail($str,$implChar="\n",$charWidth=76) - * 550: function breakLinesForEmail($str,$implChar="\n",$charWidth=76) - * 585: function cmpIP($baseIP, $list) - * 627: function cmpFQDN($baseIP, $list) - * 657: function inList($list,$item) - * 669: function rmFromList($element,$list) - * 687: function intInRange($theInt,$min,$max=2000000000,$zeroValue=0) - * 703: function intval_positive($theInt) - * 716: function int_from_ver($verNumberStr) - * 728: function md5int($str) - * 741: function shortMD5($input, $len=10) - * 754: function uniqueList($in_list, $secondParameter=NULL) - * 768: function split_fileref($fileref) - * 805: function dirname($path) - * 821: function modifyHTMLColor($color,$R,$G,$B) - * 841: function modifyHTMLColorAll($color,$all) - * 852: function rm_endcomma($string) - * 865: function danish_strtoupper($string) - * 880: function convUmlauts($str) - * 893: function testInt($var) - * 905: function isFirstPartOfStr($str,$partStr) - * 921: function formatSize($sizeInBytes,$labels='') - * 956: function convertMicrotime($microtime) - * 970: function splitCalc($string,$operators) - * 992: function calcPriority($string) - * 1032: function calcParenthesis($string) - * 1058: function htmlspecialchars_decode($value) - * 1073: function deHSCentities($str) - * 1086: function slashJS($string,$extended=0,$char="'") - * 1099: function rawUrlEncodeJS($str) - * 1111: function rawUrlEncodeFP($str) - * 1122: function validEmail($email) - * 1137: function formatForTextarea($content) + * 499: function fixed_lgd($string,$origChars,$preStr='...') + * 524: function fixed_lgd_pre($string,$chars) + * 538: function fixed_lgd_cs($string,$chars) + * 555: function breakTextForEmail($str,$implChar="\n",$charWidth=76) + * 574: function breakLinesForEmail($str,$implChar="\n",$charWidth=76) + * 610: function cmpIP($baseIP, $list) + * 626: function cmpIPv4($baseIP, $list) + * 668: function cmpIPv6($baseIP, $list) + * 711: function IPv6Hex2Bin ($hex) + * 726: function normalizeIPv6($address) + * 782: function validIPv6($ip) + * 805: function cmpFQDN($baseIP, $list) + * 835: function inList($list,$item) + * 847: function rmFromList($element,$list) + * 863: function expandList($list) + * 894: function intInRange($theInt,$min,$max=2000000000,$zeroValue=0) + * 910: function intval_positive($theInt) + * 923: function int_from_ver($verNumberStr) + * 934: function compat_version($verNumberStr) + * 952: function md5int($str) + * 965: function shortMD5($input, $len=10) + * 978: function uniqueList($in_list, $secondParameter=NULL) + * 992: function split_fileref($fileref) + * 1030: function dirname($path) + * 1046: function modifyHTMLColor($color,$R,$G,$B) + * 1066: function modifyHTMLColorAll($color,$all) + * 1077: function rm_endcomma($string) + * 1090: function danish_strtoupper($string) + * 1105: function convUmlauts($str) + * 1118: function testInt($var) + * 1130: function isFirstPartOfStr($str,$partStr) + * 1146: function formatSize($sizeInBytes,$labels='') + * 1181: function convertMicrotime($microtime) + * 1195: function splitCalc($string,$operators) + * 1217: function calcPriority($string) + * 1258: function calcParenthesis($string) + * 1284: function htmlspecialchars_decode($value) + * 1299: function deHSCentities($str) + * 1312: function slashJS($string,$extended=0,$char="'") + * 1325: function rawUrlEncodeJS($str) + * 1337: function rawUrlEncodeFP($str) + * 1348: function validEmail($email) + * 1363: function formatForTextarea($content) * * SECTION: ARRAY FUNCTIONS - * 1168: function inArray($in_array,$item) - * 1185: function intExplode($delim, $string) - * 1204: function revExplode($delim, $string, $count=0) - * 1224: function trimExplode($delim, $string, $onlyNonEmptyValues=0) - * 1246: function uniqueArray($valueArray) - * 1258: function removeArrayEntryByValue($array,$cmpValue) - * 1286: function implodeArrayForUrl($name,$theArray,$str='',$skipBlank=0,$rawurlencodeParamName=0) - * 1313: function compileSelectedGetVarsFromArray($varList,$getArray,$GPvarAlt=1) - * 1336: function addSlashesOnArray(&$theArray) - * 1360: function stripSlashesOnArray(&$theArray) - * 1382: function slashArray($arr,$cmd) - * 1399: function array_merge_recursive_overrule($arr0,$arr1,$notAddKeys=0,$includeEmtpyValues=true) - * 1432: function array_merge($arr1,$arr2) - * 1445: function csvValues($row,$delim=',',$quote='"') + * 1394: function inArray($in_array,$item) + * 1411: function intExplode($delim, $string) + * 1430: function revExplode($delim, $string, $count=0) + * 1450: function trimExplode($delim, $string, $onlyNonEmptyValues=0) + * 1472: function uniqueArray($valueArray) + * 1484: function removeArrayEntryByValue($array,$cmpValue) + * 1513: function implodeArrayForUrl($name,$theArray,$str='',$skipBlank=0,$rawurlencodeParamName=0) + * 1538: function explodeUrl2Array($string,$multidim=FALSE) + * 1564: function compileSelectedGetVarsFromArray($varList,$getArray,$GPvarAlt=1) + * 1587: function addSlashesOnArray(&$theArray) + * 1611: function stripSlashesOnArray(&$theArray) + * 1633: function slashArray($arr,$cmd) + * 1650: function array_merge_recursive_overrule($arr0,$arr1,$notAddKeys=0,$includeEmtpyValues=true) + * 1683: function array_merge($arr1,$arr2) + * 1696: function csvValues($row,$delim=',',$quote='"') * * SECTION: HTML/XML PROCESSING - * 1487: function get_tag_attributes($tag) - * 1524: function split_tag_attributes($tag) - * 1558: function implodeAttributes($arr,$xhtmlSafe=FALSE,$dontOmitBlankAttribs=FALSE) - * 1585: function implodeParams($arr,$xhtmlSafe=FALSE,$dontOmitBlankAttribs=FALSE) - * 1600: function wrapJS($string, $linebreak=TRUE) - * 1630: function xml2tree($string,$depth=999) - * 1716: function array2xml($array,$NSprefix='',$level=0,$docTag='phparray',$spaceInd=0, $options=array(),$stackData=array()) - * 1830: function xml2array($string,$NSprefix='',$reportDocTag=FALSE) - * 1940: function xmlRecompileFromStructValArray($vals) - * 1984: function xmlGetHeaderAttribs($xmlData) + * 1738: function get_tag_attributes($tag) + * 1775: function split_tag_attributes($tag) + * 1809: function implodeAttributes($arr,$xhtmlSafe=FALSE,$dontOmitBlankAttribs=FALSE) + * 1836: function implodeParams($arr,$xhtmlSafe=FALSE,$dontOmitBlankAttribs=FALSE) + * 1851: function wrapJS($string, $linebreak=TRUE) + * 1882: function xml2tree($string,$depth=999) + * 1969: function array2xml($array,$NSprefix='',$level=0,$docTag='phparray',$spaceInd=0, $options=array(),$stackData=array()) + * 2088: function xml2array($string,$NSprefix='',$reportDocTag=FALSE) + * 2198: function xmlRecompileFromStructValArray($vals) + * 2242: function xmlGetHeaderAttribs($xmlData) * * SECTION: FILES FUNCTIONS - * 2016: function getURL($url) - * 2058: function writeFile($file,$content) - * 2075: function fixPermissions($file) - * 2092: function writeFileToTypo3tempDir($filepath,$content) - * 2135: function mkdir($theNewFolder) - * 2155: function get_dirs($path) - * 2180: function getFilesInDir($path,$extensionList='',$prependPath=0,$order='') - * 2234: function getAllFilesAndFoldersInPath($fileArr,$path,$extList='',$regDirs=0,$recursivityLevels=99) - * 2257: function removePrefixPathFromList($fileArr,$prefixToRemove) - * 2273: function fixWindowsFilePath($theFile) - * 2285: function resolveBackPath($pathStr) - * 2312: function locationHeaderUrl($path) + * 2275: function getURL($url, $includeHeader=0) + * 2342: function writeFile($file,$content) + * 2367: function fixPermissions($file) + * 2384: function writeFileToTypo3tempDir($filepath,$content) + * 2427: function mkdir($theNewFolder) + * 2446: function mkdir_deep($destination,$deepDir) + * 2468: function get_dirs($path) + * 2493: function getFilesInDir($path,$extensionList='',$prependPath=0,$order='') + * 2547: function getAllFilesAndFoldersInPath($fileArr,$path,$extList='',$regDirs=0,$recursivityLevels=99) + * 2570: function removePrefixPathFromList($fileArr,$prefixToRemove) + * 2586: function fixWindowsFilePath($theFile) + * 2598: function resolveBackPath($pathStr) + * 2626: function locationHeaderUrl($path) * * SECTION: DEBUG helper FUNCTIONS - * 2352: function debug_ordvalue($string,$characters=100) - * 2369: function view_array($array_in) - * 2397: function print_array($array_in) - * 2412: function debug($var="",$brOrHeader=0) + * 2666: function debug_ordvalue($string,$characters=100) + * 2683: function view_array($array_in) + * 2711: function print_array($array_in) + * 2726: function debug($var="",$brOrHeader=0) + * 2757: function debug_trail() + * 2779: function debugRows($rows,$header='') * * SECTION: SYSTEM INFORMATION - * 2481: function getThisUrl() - * 2497: function linkThisScript($getParams=array()) - * 2521: function linkThisUrl($url,$getParams=array()) - * 2546: function getIndpEnv($getEnvName) - * 2735: function milliseconds() - * 2747: function clientInfo($useragent='') + * 2857: function getThisUrl() + * 2873: function linkThisScript($getParams=array()) + * 2897: function linkThisUrl($url,$getParams=array()) + * 2920: function getIndpEnv($getEnvName) + * 3113: function milliseconds() + * 3125: function clientInfo($useragent='') * * SECTION: TYPO3 SPECIFIC FUNCTIONS - * 2834: function getFileAbsFileName($filename,$onlyRelative=1,$relToTYPO3_mainDir=0) - * 2870: function validPathStr($theFile) - * 2881: function isAbsPath($path) - * 2892: function isAllowedAbsPath($path) - * 2909: function verifyFilenameAgainstDenyPattern($filename) - * 2927: function upload_copy_move($source,$destination) - * 2953: function upload_to_tempfile($uploadedFileName) - * 2971: function unlink_tempfile($uploadedTempFileName) - * 2987: function tempnam($filePrefix) - * 3000: function stdAuthCode($uid_or_record,$fields='') - * 3030: function cHashParams($addQueryParams) - * 3059: function loadTCA($table) - * 3079: function resolveSheetDefInDS($dataStructArray,$sheet='sDEF') - * 3109: function resolveAllSheetsInDS($dataStructArray) - * 3138: function callUserFunction($funcName,&$params,&$ref,$checkPrefix='user_',$silent=0) - * 3237: function &getUserObj($classRef,$checkPrefix='user_',$silent=0) - * 3295: function &makeInstance($className) - * 3307: function makeInstanceClassName($className) - * 3321: function &makeInstanceService($serviceType, $serviceSubType='', $excludeServiceKeys=array()) - * 3382: function plainMailEncoded($email,$subject,$message,$headers='',$enc='',$charset='ISO-8859-1',$dontEncodeSubject=0) - * 3427: function quoted_printable($string,$maxlen=76) - * 3471: function substUrlsInPlainText($message,$urlmode='76',$index_script_url='') - * 3505: function makeRedirectUrl($inUrl,$l=0,$index_script_url='') - * 3532: function freetypeDpiComp($font_size) - * 3551: function devLog($msg, $extKey, $severity=0, $dataVar=FALSE) - * 3572: function arrayToLogString($arr, $valueList=array(), $valueLength=20) + * 3212: function getFileAbsFileName($filename,$onlyRelative=1,$relToTYPO3_mainDir=0) + * 3248: function validPathStr($theFile) + * 3259: function isAbsPath($path) + * 3270: function isAllowedAbsPath($path) + * 3287: function verifyFilenameAgainstDenyPattern($filename) + * 3305: function upload_copy_move($source,$destination) + * 3331: function upload_to_tempfile($uploadedFileName) + * 3349: function unlink_tempfile($uploadedTempFileName) + * 3365: function tempnam($filePrefix) + * 3379: function stdAuthCode($uid_or_record,$fields='',$codeLength=8) + * 3410: function cHashParams($addQueryParams) + * 3433: function hideIfNotTranslated($l18n_cfg_fieldValue) + * 3448: function readLLfile($fileRef,$langKey) + * 3472: function readLLXMLfile($fileRef,$langKey) + * 3589: function llXmlAutoFileName($fileRef,$language) + * 3633: function loadTCA($table) + * 3653: function resolveSheetDefInDS($dataStructArray,$sheet='sDEF') + * 3686: function resolveAllSheetsInDS($dataStructArray) + * 3715: function callUserFunction($funcName,&$params,&$ref,$checkPrefix='user_',$silent=0) + * 3813: function &getUserObj($classRef,$checkPrefix='user_',$silent=0) + * 3871: function &makeInstance($className) + * 3883: function makeInstanceClassName($className) + * 3897: function &makeInstanceService($serviceType, $serviceSubType='', $excludeServiceKeys=array()) + * 3961: function plainMailEncoded($email,$subject,$message,$headers='',$enc='',$charset='',$dontEncodeHeader=false) + * 4031: function quoted_printable($string,$maxlen=76) + * 4078: function encodeHeader($line,$enc='',$charset='ISO-8859-1') + * 4121: function substUrlsInPlainText($message,$urlmode='76',$index_script_url='') + * 4155: function makeRedirectUrl($inUrl,$l=0,$index_script_url='') + * 4182: function freetypeDpiComp($font_size) + * 4194: function initSysLog() + * 4251: function sysLog($msg, $extKey, $severity=0) + * 4334: function devLog($msg, $extKey, $severity=0, $dataVar=FALSE) + * 4355: function arrayToLogString($arr, $valueList=array(), $valueLength=20) + * 4378: function imageMagickCommand($command, $parameters, $path='') + * 4425: function unQuoteFilenames($parameters,$unQuote=FALSE) + * 4459: function quoteJSvalue($value, $inScriptTags = false) * - * TOTAL FUNCTIONS: 117 + * TOTAL FUNCTIONS: 138 * (This index is automatically created/updated by the extension "extdeveval") * */ @@ -208,7 +230,14 @@ * @package TYPO3 * @subpackage t3lib */ -class t3lib_div { +final class t3lib_div { + + // Severity constants used by t3lib_div::sysLog() + const SYSLOG_SEVERITY_INFO = 0; + const SYSLOG_SEVERITY_NOTICE = 1; + const SYSLOG_SEVERITY_WARNING = 2; + const SYSLOG_SEVERITY_ERROR = 3; + const SYSLOG_SEVERITY_FATAL = 4; @@ -238,7 +267,7 @@ class t3lib_div { * @return mixed POST var named $var and if not set, the GET var of the same name. * @see GPvar() */ - function _GP($var) { + public static function _GP($var) { if(empty($var)) return; $value = isset($_POST[$var]) ? $_POST[$var] : $_GET[$var]; if (isset($value)) { @@ -256,7 +285,7 @@ class t3lib_div { * @return mixed If $var is set it returns the value of $_GET[$var]. If $var is NULL (default), returns $_GET itself. In any case *slashes are stipped from the output!* * @see _POST(), _GP(), _GETset() */ - function _GET($var=NULL) { + public static function _GET($var=NULL) { $value = ($var === NULL) ? $_GET : (empty($var) ? NULL : $_GET[$var]); if (isset($value)) { // Removes slashes since TYPO3 has added them regardless of magic_quotes setting. if (is_array($value)) { t3lib_div::stripSlashesOnArray($value); } else { $value = stripslashes($value); } @@ -273,7 +302,7 @@ class t3lib_div { * @return mixed If $var is set it returns the value of $_POST[$var]. If $var is NULL (default), returns $_POST itself. In any case *slashes are stipped from the output!* * @see _GET(), _GP() */ - function _POST($var=NULL) { + public static function _POST($var=NULL) { $value = ($var === NULL) ? $_POST : (empty($var) ? NULL : $_POST[$var]); if (isset($value)) { // Removes slashes since TYPO3 has added them regardless of magic_quotes setting. if (is_array($value)) { t3lib_div::stripSlashesOnArray($value); } else { $value = stripslashes($value); } @@ -285,16 +314,20 @@ class t3lib_div { * Writes input value to $_GET * Usage: 2 * - * @param array Array to write to $_GET. Values should NOT be escaped at input time (but will be escaped before writing according to TYPO3 standards). + * @param mixed Array to write to $_GET. Values should NOT be escaped at input time (but will be escaped before writing according to TYPO3 standards). * @param string Alternative key; If set, this will not set the WHOLE GET array, but only the key in it specified by this value! * @return void */ - function _GETset($inputGet,$key='') { + public static function _GETset($inputGet,$key='') { // ADDS slashes since TYPO3 standard currently is that slashes MUST be applied (regardless of magic_quotes setting). if (strcmp($key,'')) { - if (is_array($inputGet)) { t3lib_div::addSlashesOnArray($inputGet); } else { $inputGet = addslashes($inputGet); } + if (is_array($inputGet)) { + t3lib_div::addSlashesOnArray($inputGet); + } else { + $inputGet = addslashes($inputGet); + } $GLOBALS['HTTP_GET_VARS'][$key] = $_GET[$key] = $inputGet; - } elseif (is_array($inputGet)){ + } elseif (is_array($inputGet)) { t3lib_div::addSlashesOnArray($inputGet); $GLOBALS['HTTP_GET_VARS'] = $_GET = $inputGet; } @@ -312,7 +345,7 @@ class t3lib_div { * @deprecated Use t3lib_div::_GP instead (ALWAYS delivers a value with un-escaped values!) * @see _GP() */ - function GPvar($var,$strip=0) { + public static function GPvar($var,$strip=0) { if(empty($var)) return; $value = isset($_POST[$var]) ? $_POST[$var] : $_GET[$var]; if (isset($value) && is_string($value)) { $value = stripslashes($value); } // Originally check '&& get_magic_quotes_gpc() ' but the values of $_GET are always slashed regardless of get_magic_quotes_gpc() because HTTP_POST/GET_VARS are run through addSlashesOnArray in the very beginning of index_ts.php eg. @@ -329,7 +362,7 @@ class t3lib_div { * @ignore * @deprecated */ - function GParrayMerged($var) { + public static function GParrayMerged($var) { $postA = is_array($_POST[$var]) ? $_POST[$var] : array(); $getA = is_array($_GET[$var]) ? $_GET[$var] : array(); $mergedA = t3lib_div::array_merge_recursive_overrule($getA,$postA); @@ -337,6 +370,21 @@ class t3lib_div { return $mergedA; } + /** + * Wrapper for the RemoveXSS function. + * Removes potential XSS code from an input string. + * + * Using an external class by Travis Puderbaugh + * + * @param string Input string + * @return string Input string with potential XSS code removed + */ + public function removeXSS($string) { + require_once(PATH_typo3.'contrib/RemoveXSS/RemoveXSS.php'); + $string = RemoveXSS::RemoveXSS($string); + return $string; + } + @@ -373,7 +421,7 @@ class t3lib_div { * @return string Returns "GD" if GD was used, otherwise "IM" if ImageMagick was used. If nothing done at all, it returns empty string. * @internal */ - function gif_compress($theFile, $type) { + public static function gif_compress($theFile, $type) { $gfxConf = $GLOBALS['TYPO3_CONF_VARS']['GFX']; $returnCode=''; if ($gfxConf['gif_compress'] && strtolower(substr($theFile,-4,4))=='.gif') { // GIF... @@ -401,14 +449,14 @@ class t3lib_div { * @return string new filename * @internal */ - function png_to_gif_by_imagemagick($theFile) { + public static function png_to_gif_by_imagemagick($theFile) { if ($GLOBALS['TYPO3_CONF_VARS']['FE']['png_to_gif'] && $GLOBALS['TYPO3_CONF_VARS']['GFX']['im'] && $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_path_lzw'] && strtolower(substr($theFile,-4,4))=='.png' && @is_file($theFile)) { // IM $newFile = substr($theFile,0,-4).'.gif'; - $cmd = t3lib_div::imageMagickCommand('convert', '"'.$theFile.'" "'.$newFile.'"', $gfxConf['im_path_lzw']); + $cmd = t3lib_div::imageMagickCommand('convert', '"'.$theFile.'" "'.$newFile.'"', $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_path_lzw']); exec($cmd); $theFile = $newFile; // unlink old file?? May be bad idea bacause TYPO3 would then recreate the file every time as TYPO3 thinks the file is not generated because it's missing!! So do not unlink $theFile here!! @@ -426,7 +474,7 @@ class t3lib_div { * @return string If the new image file exists, it's filepath is returned * @internal */ - function read_png_gif($theFile,$output_png=0) { + public static function read_png_gif($theFile,$output_png=0) { if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['im'] && @is_file($theFile)) { $ext = strtolower(substr($theFile,-4,4)); if ( @@ -436,7 +484,8 @@ class t3lib_div { return $theFile; } else { $newFile = PATH_site.'typo3temp/readPG_'.md5($theFile.'|'.filemtime($theFile)).($output_png?'.png':'.gif'); - exec($GLOBALS['TYPO3_CONF_VARS']['GFX']['im_path'].'convert "'.$theFile.'" "'.$newFile.'"'); + $cmd = t3lib_div::imageMagickCommand('convert', '"'.$theFile.'" "'.$newFile.'"', $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_path']); + exec($cmd); if (@is_file($newFile)) return $newFile; } } @@ -466,16 +515,16 @@ class t3lib_div { * Truncate string * Returns a new string of max. $chars length. * If the string is longer, it will be truncated and appended with '...'. - * DEPRECIATED. Works ONLY for single-byte charsets! USE t3lib_div::fixed_lgd_cs() instead * Usage: 39 * - * @param string $string string to truncate - * @param integer $chars must be an integer with an absolute value of at least 4. if negative the string is cropped from the right end. + * @param string string to truncate + * @param integer must be an integer with an absolute value of at least 4. if negative the string is cropped from the right end. * @param string String to append to the output if it is truncated, default is '...' * @return string new string + * @deprecated Works ONLY for single-byte charsets! USE t3lib_div::fixed_lgd_cs() instead * @see fixed_lgd_pre() */ - function fixed_lgd($string,$origChars,$preStr='...') { + public static function fixed_lgd($string,$origChars,$preStr='...') { $chars = abs($origChars); if ($chars >= 4) { if(strlen($string)>$chars) { @@ -492,15 +541,15 @@ class t3lib_div { * Returns a new string of max. $chars length. * If the string is longer, it will be truncated and prepended with '...'. * This works like fixed_lgd, but is truncated in the start of the string instead of the end - * DEPRECIATED. Use either fixed_lgd() or fixed_lgd_cs() (with negative input value for $chars) * Usage: 6 * - * @param string $string string to truncate - * @param integer $chars must be an integer of at least 4 + * @param string string to truncate + * @param integer must be an integer of at least 4 * @return string new string + * @deprecated Use either fixed_lgd() or fixed_lgd_cs() (with negative input value for $chars) * @see fixed_lgd() */ - function fixed_lgd_pre($string,$chars) { + public static function fixed_lgd_pre($string,$chars) { return strrev(t3lib_div::fixed_lgd(strrev($string),$chars)); } @@ -509,12 +558,12 @@ class t3lib_div { * Use only from backend! * Usage: 75 * - * @param string $string string to truncate - * @param integer $chars must be an integer with an absolute value of at least 4. if negative the string is cropped from the right end. + * @param string string to truncate + * @param integer must be an integer with an absolute value of at least 4. if negative the string is cropped from the right end. * @return string New string * @see fixed_lgd() */ - function fixed_lgd_cs($string,$chars) { + public static function fixed_lgd_cs($string,$chars) { if (is_object($GLOBALS['LANG'])) { return $GLOBALS['LANG']->csConvObj->crop($GLOBALS['LANG']->charSet,$string,$chars,'...'); } else { @@ -529,13 +578,14 @@ class t3lib_div { * @param string The string to break up * @param string The string to implode the broken lines with (default/typically \n) * @param integer The line length + * @deprecated Use PHP function wordwrap() * @return string */ - function breakTextForEmail($str,$implChar="\n",$charWidth=76) { + public static function breakTextForEmail($str,$implChar="\n",$charWidth=76) { $lines = explode(chr(10),$str); $outArr=array(); - while(list(,$lStr)=each($lines)) { - $outArr = array_merge($outArr,t3lib_div::breakLinesForEmail($lStr,$implChar,$charWidth)); + foreach ($lines as $lStr) { + $outArr[] = t3lib_div::breakLinesForEmail($lStr,$implChar,$charWidth); } return implode(chr(10),$outArr); } @@ -550,7 +600,7 @@ class t3lib_div { * @return string * @see breakTextForEmail() */ - function breakLinesForEmail($str,$implChar="\n",$charWidth=76) { + public static function breakLinesForEmail($str,$implChar="\n",$charWidth=76) { $lines=array(); $l=$charWidth; $p=0; @@ -579,13 +629,35 @@ class t3lib_div { /** * Match IP number with list of numbers with wildcard + * Dispatcher method for switching into specialised IPv4 and IPv6 methods. * Usage: 10 * * @param string $baseIP is the current remote IP address for instance, typ. REMOTE_ADDR + * @param string $list is a comma-list of IP-addresses to match with. *-wildcard allowed instead of number, plus leaving out parts in the IP number is accepted as wildcard (eg. 192.168.*.* equals 192.168). If list is "*" no check is done and the function returns TRUE immediately. An empty list always returns FALSE. + * @return boolean True if an IP-mask from $list matches $baseIP + */ + public static function cmpIP($baseIP, $list) { + $list = trim($list); + if ($list === '') { + return false; + } elseif ($list === '*') { + return true; + } + if (strpos($baseIP, ':') !== false && t3lib_div::validIPv6($baseIP)) { + return t3lib_div::cmpIPv6($baseIP, $list); + } else { + return t3lib_div::cmpIPv4($baseIP, $list); + } + } + + /** + * Match IPv4 number with list of numbers with wildcard + * + * @param string $baseIP is the current remote IP address for instance, typ. REMOTE_ADDR * @param string $list is a comma-list of IP-addresses to match with. *-wildcard allowed instead of number, plus leaving out parts in the IP number is accepted as wildcard (eg. 192.168.*.* equals 192.168) * @return boolean True if an IP-mask from $list matches $baseIP */ - function cmpIP($baseIP, $list) { + public static function cmpIPv4($baseIP, $list) { $IPpartsReq = explode('.',$baseIP); if (count($IPpartsReq)==4) { $values = t3lib_div::trimExplode(',',$list,1); @@ -606,8 +678,7 @@ class t3lib_div { // "192.168.*.*" $IPparts = explode('.',$test); $yes = 1; - reset($IPparts); - while(list($index,$val)=each($IPparts)) { + foreach ($IPparts as $index => $val) { $val = trim($val); if (strcmp($val,'*') && strcmp($IPpartsReq[$index],$val)) { $yes=0; @@ -620,14 +691,188 @@ class t3lib_div { return false; } + /** + * Match IPv6 address with a list of IPv6 prefixes + * + * @param string $baseIP is the current remote IP address for instance + * @param string $list is a comma-list of IPv6 prefixes, could also contain IPv4 addresses + * @return boolean True if an baseIP matches any prefix + */ + public static function cmpIPv6($baseIP, $list) { + $success = false; // Policy default: Deny connection + $baseIP = t3lib_div::normalizeIPv6($baseIP); + + $values = t3lib_div::trimExplode(',',$list,1); + foreach ($values as $test) { + list($test,$mask) = explode('/',$test); + if (t3lib_div::validIPv6($test)) { + $test = t3lib_div::normalizeIPv6($test); + if (intval($mask)) { + switch ($mask) { // test on /48 /64 + case '48': + $testBin = substr(t3lib_div::IPv6Hex2Bin($test), 0, 48); + $baseIPBin = substr(t3lib_div::IPv6Hex2Bin($baseIP), 0, 48); + $success = strcmp($testBin, $baseIPBin)==0 ? true : false; + break; + case '64': + $testBin = substr(t3lib_div::IPv6Hex2Bin($test), 0, 64); + $baseIPBin = substr(t3lib_div::IPv6Hex2Bin($baseIP), 0, 64); + $success = strcmp($testBin, $baseIPBin)==0 ? true : false; + break; + default: + $success = false; + } + } else { + if (t3lib_div::validIPv6($test)) { // test on full ip address 128 bits + $testBin = t3lib_div::IPv6Hex2Bin($test); + $baseIPBin = t3lib_div::IPv6Hex2Bin($baseIP); + $success = strcmp($testBin, $baseIPBin)==0 ? true : false; + } + } + } + if ($success) return true; + } + return false; + } + + /** + * [Describe function...] + * + * @param [type] $hex: ... + * @return [type] ... + */ + public static function IPv6Hex2Bin ($hex) { + $bin = ''; + $hex = str_replace(':', '', $hex); // Replace colon to nothing + for ($i=0; $i