Project

General

Profile

Bug #22410 » 14050_cleaning_t3lib_div.patch

Administrator Admin, 2010-11-23 19:53

View differences:

t3lib/class.t3lib_div.php (revision )
<?php
/***************************************************************
* Copyright notice
*
* (c) 1999-2010 Kasper Sk?rh?j (kasperYYYY@typo3.com)
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
* A copy is found in the textfile GPL.txt and important notices to the license
* from the author is found in LICENSE.txt distributed with these scripts.
*
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
* Copyright notice
*
* (c) 1999-2010 Kasper Sk?rh?j (kasperYYYY@typo3.com)
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
* A copy is found in the textfile GPL.txt and important notices to the license
* from the author is found in LICENSE.txt distributed with these scripts.
*
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/**
* Contains the reknown class "t3lib_div" with general purpose functions
*
......
*
* 232: class t3lib_div
*
* SECTION: GET/POST Variables
* SECTION: GET/POST Variables
* 262: function _GP($var)
* 262: function _GP($var)
* 280: function _GET($var=NULL)
* 280: function _GET($var=NULL)
* 297: function _POST($var=NULL)
* 297: function _POST($var=NULL)
* 313: function _GETset($inputGet,$key='')
* 313: function _GETset($inputGet,$key='')
* 336: function GPvar($var,$strip=0)
* 336: function GPvar($var,$strip=0)
* 353: function GParrayMerged($var)
* 353: function GParrayMerged($var)
*
* SECTION: IMAGE FUNCTIONS
* SECTION: IMAGE FUNCTIONS
* 397: function gif_compress($theFile, $type)
* 397: function gif_compress($theFile, $type)
* 425: function png_to_gif_by_imagemagick($theFile)
* 425: function png_to_gif_by_imagemagick($theFile)
* 450: function read_png_gif($theFile,$output_png=0)
* 450: function read_png_gif($theFile,$output_png=0)
*
* SECTION: STRING FUNCTIONS
* SECTION: STRING FUNCTIONS
* 499: function fixed_lgd($string,$origChars,$preStr='...')
* 499: function fixed_lgd($string,$origChars,$preStr='...')
* 524: function fixed_lgd_pre($string,$chars)
* 524: function fixed_lgd_pre($string,$chars)
* 538: function fixed_lgd_cs($string,$chars)
* 538: function fixed_lgd_cs($string,$chars)
* 555: function breakTextForEmail($str,$implChar=LF,$charWidth=76)
* 555: function breakTextForEmail($str,$implChar=LF,$charWidth=76)
* 574: function breakLinesForEmail($str,$implChar=LF,$charWidth=76)
* 574: function breakLinesForEmail($str,$implChar=LF,$charWidth=76)
* 610: function cmpIP($baseIP, $list)
* 610: function cmpIP($baseIP, $list)
* 626: function cmpIPv4($baseIP, $list)
* 626: function cmpIPv4($baseIP, $list)
* 668: function cmpIPv6($baseIP, $list)
* 668: function cmpIPv6($baseIP, $list)
* 711: function IPv6Hex2Bin ($hex)
* 711: function IPv6Hex2Bin ($hex)
* 726: function normalizeIPv6($address)
* 726: function normalizeIPv6($address)
* 782: function validIPv6($ip)
* 782: function validIPv6($ip)
* 805: function cmpFQDN($baseIP, $list)
* 805: function cmpFQDN($baseIP, $list)
* 835: function inList($list,$item)
* 835: function inList($list,$item)
* 847: function rmFromList($element,$list)
* 847: function rmFromList($element,$list)
* 863: function expandList($list)
* 863: function expandList($list)
* 894: function intInRange($theInt,$min,$max=2000000000,$zeroValue=0)
* 894: function intInRange($theInt,$min,$max=2000000000,$zeroValue=0)
* 910: function intval_positive($theInt)
* 910: function intval_positive($theInt)
* 923: function int_from_ver($verNumberStr)
* 923: function int_from_ver($verNumberStr)
* 934: function compat_version($verNumberStr)
* 934: function compat_version($verNumberStr)
* 952: function md5int($str)
* 952: function md5int($str)
* 965: function shortMD5($input, $len=10)
* 965: function shortMD5($input, $len=10)
* 978: function uniqueList($in_list, $secondParameter=NULL)
* 978: function uniqueList($in_list, $secondParameter=NULL)
* 992: function split_fileref($fileref)
* 992: function split_fileref($fileref)
* 1030: function dirname($path)
* 1030: function dirname($path)
* 1046: function modifyHTMLColor($color,$R,$G,$B)
* 1046: function modifyHTMLColor($color,$R,$G,$B)
* 1066: function modifyHTMLColorAll($color,$all)
* 1066: function modifyHTMLColorAll($color,$all)
* 1077: function rm_endcomma($string)
* 1077: function rm_endcomma($string)
* 1090: function danish_strtoupper($string)
* 1090: function danish_strtoupper($string)
* 1105: function convUmlauts($str)
* 1105: function convUmlauts($str)
* 1118: function testInt($var)
* 1118: function testInt($var)
* 1130: function isFirstPartOfStr($str,$partStr)
* 1130: function isFirstPartOfStr($str,$partStr)
* 1146: function formatSize($sizeInBytes,$labels='')
* 1146: function formatSize($sizeInBytes,$labels='')
* 1181: function convertMicrotime($microtime)
* 1181: function convertMicrotime($microtime)
* 1195: function splitCalc($string,$operators)
* 1195: function splitCalc($string,$operators)
* 1217: function calcPriority($string)
* 1217: function calcPriority($string)
* 1258: function calcParenthesis($string)
* 1258: function calcParenthesis($string)
* 1284: function htmlspecialchars_decode($value)
* 1284: function htmlspecialchars_decode($value)
* 1299: function deHSCentities($str)
* 1299: function deHSCentities($str)
* 1312: function slashJS($string,$extended=0,$char="'")
* 1312: function slashJS($string,$extended=0,$char="'")
* 1325: function rawUrlEncodeJS($str)
* 1325: function rawUrlEncodeJS($str)
* 1337: function rawUrlEncodeFP($str)
* 1337: function rawUrlEncodeFP($str)
* 1348: function validEmail($email)
* 1348: function validEmail($email)
* 1363: function formatForTextarea($content)
* 1363: function formatForTextarea($content)
*
* SECTION: ARRAY FUNCTIONS
* SECTION: ARRAY FUNCTIONS
* 1394: function inArray($in_array,$item)
* 1394: function inArray($in_array,$item)
* 1411: function intExplode($delim, $string)
* 1411: function intExplode($delim, $string)
* 1430: function revExplode($delim, $string, $count=0)
* 1430: function revExplode($delim, $string, $count=0)
* 1450: function trimExplode($delim, $string, $onlyNonEmptyValues=0)
* 1450: function trimExplode($delim, $string, $onlyNonEmptyValues=0)
* 1472: function uniqueArray($valueArray)
* 1472: function uniqueArray($valueArray)
* 1484: function removeArrayEntryByValue($array,$cmpValue)
* 1484: function removeArrayEntryByValue($array,$cmpValue)
* 1513: function implodeArrayForUrl($name,$theArray,$str='',$skipBlank=0,$rawurlencodeParamName=0)
* 1513: function implodeArrayForUrl($name,$theArray,$str='',$skipBlank=0,$rawurlencodeParamName=0)
* 1538: function explodeUrl2Array($string,$multidim=FALSE)
* 1538: function explodeUrl2Array($string,$multidim=FALSE)
* 1564: function compileSelectedGetVarsFromArray($varList,$getArray,$GPvarAlt=1)
* 1564: function compileSelectedGetVarsFromArray($varList,$getArray,$GPvarAlt=1)
* 1587: function addSlashesOnArray(&$theArray)
* 1587: function addSlashesOnArray(&$theArray)
* 1611: function stripSlashesOnArray(&$theArray)
* 1611: function stripSlashesOnArray(&$theArray)
* 1633: function slashArray($arr,$cmd)
* 1633: function slashArray($arr,$cmd)
* 1650: function array_merge_recursive_overrule($arr0,$arr1,$notAddKeys=0,$includeEmtpyValues=true)
* 1650: function array_merge_recursive_overrule($arr0,$arr1,$notAddKeys=0,$includeEmtpyValues=true)
* 1683: function array_merge($arr1,$arr2)
* 1683: function array_merge($arr1,$arr2)
* 1696: function csvValues($row,$delim=',',$quote='"')
* 1696: function csvValues($row,$delim=',',$quote='"')
*
* SECTION: HTML/XML PROCESSING
* SECTION: HTML/XML PROCESSING
* 1738: function get_tag_attributes($tag)
* 1738: function get_tag_attributes($tag)
* 1775: function split_tag_attributes($tag)
* 1775: function split_tag_attributes($tag)
* 1809: function implodeAttributes($arr,$xhtmlSafe=FALSE,$dontOmitBlankAttribs=FALSE)
* 1809: function implodeAttributes($arr,$xhtmlSafe=FALSE,$dontOmitBlankAttribs=FALSE)
* 1836: function implodeParams($arr,$xhtmlSafe=FALSE,$dontOmitBlankAttribs=FALSE)
* 1836: function implodeParams($arr,$xhtmlSafe=FALSE,$dontOmitBlankAttribs=FALSE)
* 1851: function wrapJS($string, $linebreak=TRUE)
* 1851: function wrapJS($string, $linebreak=TRUE)
* 1882: function xml2tree($string,$depth=999)
* 1882: function xml2tree($string,$depth=999)
* 1969: function array2xml($array,$NSprefix='',$level=0,$docTag='phparray',$spaceInd=0, $options=array(),$stackData=array())
* 1969: function array2xml($array,$NSprefix='',$level=0,$docTag='phparray',$spaceInd=0, $options=array(),$stackData=array())
* 2088: function xml2array($string,$NSprefix='',$reportDocTag=FALSE)
* 2088: function xml2array($string,$NSprefix='',$reportDocTag=FALSE)
* 2198: function xmlRecompileFromStructValArray($vals)
* 2198: function xmlRecompileFromStructValArray($vals)
* 2242: function xmlGetHeaderAttribs($xmlData)
* 2242: function xmlGetHeaderAttribs($xmlData)
*
* SECTION: FILES FUNCTIONS
* SECTION: FILES FUNCTIONS
* 2275: function getURL($url, $includeHeader=0)
* 2275: function getURL($url, $includeHeader=0)
* 2342: function writeFile($file,$content)
* 2342: function writeFile($file,$content)
* 2367: function fixPermissions($file)
* 2367: function fixPermissions($file)
* 2384: function writeFileToTypo3tempDir($filepath,$content)
* 2384: function writeFileToTypo3tempDir($filepath,$content)
* 2427: function mkdir($theNewFolder)
* 2427: function mkdir($theNewFolder)
* 2446: function mkdir_deep($destination,$deepDir)
* 2446: function mkdir_deep($destination,$deepDir)
* 2468: function get_dirs($path)
* 2468: function get_dirs($path)
* 2493: function getFilesInDir($path,$extensionList='',$prependPath=0,$order='')
* 2493: function getFilesInDir($path,$extensionList='',$prependPath=0,$order='')
* 2547: function getAllFilesAndFoldersInPath($fileArr,$path,$extList='',$regDirs=0,$recursivityLevels=99)
* 2547: function getAllFilesAndFoldersInPath($fileArr,$path,$extList='',$regDirs=0,$recursivityLevels=99)
* 2570: function removePrefixPathFromList($fileArr,$prefixToRemove)
* 2570: function removePrefixPathFromList($fileArr,$prefixToRemove)
* 2586: function fixWindowsFilePath($theFile)
* 2586: function fixWindowsFilePath($theFile)
* 2598: function resolveBackPath($pathStr)
* 2598: function resolveBackPath($pathStr)
* 2626: function locationHeaderUrl($path)
* 2626: function locationHeaderUrl($path)
*
* SECTION: DEBUG helper FUNCTIONS
* SECTION: DEBUG helper FUNCTIONS
* 2666: function debug_ordvalue($string,$characters=100)
* 2666: function debug_ordvalue($string,$characters=100)
* 2683: function view_array($array_in)
* 2683: function view_array($array_in)
* 2711: function print_array($array_in)
* 2711: function print_array($array_in)
* 2726: function debug($var="",$brOrHeader=0)
* 2726: function debug($var="",$brOrHeader=0)
* 2757: function debug_trail()
* 2757: function debug_trail()
* 2779: function debugRows($rows,$header='')
* 2779: function debugRows($rows,$header='')
*
* SECTION: SYSTEM INFORMATION
* SECTION: SYSTEM INFORMATION
* 2857: function getThisUrl()
* 2857: function getThisUrl()
* 2873: function linkThisScript($getParams=array())
* 2873: function linkThisScript($getParams=array())
* 2897: function linkThisUrl($url,$getParams=array())
* 2897: function linkThisUrl($url,$getParams=array())
* 2920: function getIndpEnv($getEnvName)
* 2920: function getIndpEnv($getEnvName)
* 3113: function milliseconds()
* 3113: function milliseconds()
* 3125: function clientInfo($useragent='')
* 3125: function clientInfo($useragent='')
*
* SECTION: TYPO3 SPECIFIC FUNCTIONS
* SECTION: TYPO3 SPECIFIC FUNCTIONS
* 3212: function getFileAbsFileName($filename,$onlyRelative=1,$relToTYPO3_mainDir=0)
* 3212: function getFileAbsFileName($filename,$onlyRelative=1,$relToTYPO3_mainDir=0)
* 3248: function validPathStr($theFile)
* 3248: function validPathStr($theFile)
* 3259: function isAbsPath($path)
* 3259: function isAbsPath($path)
* 3270: function isAllowedAbsPath($path)
* 3270: function isAllowedAbsPath($path)
* 3287: function verifyFilenameAgainstDenyPattern($filename)
* 3287: function verifyFilenameAgainstDenyPattern($filename)
* 3305: function upload_copy_move($source,$destination)
* 3305: function upload_copy_move($source,$destination)
* 3331: function upload_to_tempfile($uploadedFileName)
* 3331: function upload_to_tempfile($uploadedFileName)
* 3349: function unlink_tempfile($uploadedTempFileName)
* 3349: function unlink_tempfile($uploadedTempFileName)
* 3365: function tempnam($filePrefix)
* 3365: function tempnam($filePrefix)
* 3379: function stdAuthCode($uid_or_record,$fields='',$codeLength=8)
* 3379: function stdAuthCode($uid_or_record,$fields='',$codeLength=8)
* 3410: function cHashParams($addQueryParams)
* 3410: function cHashParams($addQueryParams)
* 3433: function hideIfNotTranslated($l18n_cfg_fieldValue)
* 3433: function hideIfNotTranslated($l18n_cfg_fieldValue)
* 3448: function readLLfile($fileRef,$langKey)
* 3448: function readLLfile($fileRef,$langKey)
* 3472: function readLLXMLfile($fileRef,$langKey)
* 3472: function readLLXMLfile($fileRef,$langKey)
* 3589: function llXmlAutoFileName($fileRef,$language)
* 3589: function llXmlAutoFileName($fileRef,$language)
* 3633: function loadTCA($table)
* 3633: function loadTCA($table)
* 3653: function resolveSheetDefInDS($dataStructArray,$sheet='sDEF')
* 3653: function resolveSheetDefInDS($dataStructArray,$sheet='sDEF')
* 3686: function resolveAllSheetsInDS($dataStructArray)
* 3686: function resolveAllSheetsInDS($dataStructArray)
* 3715: function callUserFunction($funcName,&$params,&$ref,$checkPrefix='user_',$silent=0)
* 3715: function callUserFunction($funcName,&$params,&$ref,$checkPrefix='user_',$silent=0)
* 3813: function &getUserObj($classRef,$checkPrefix='user_',$silent=0)
* 3813: function &getUserObj($classRef,$checkPrefix='user_',$silent=0)
* 3871: function &makeInstance($className)
* 3871: function &makeInstance($className)
* 3883: function makeInstanceClassName($className)
* 3883: function makeInstanceClassName($className)
* 3897: function &makeInstanceService($serviceType, $serviceSubType='', $excludeServiceKeys=array())
* 3897: function &makeInstanceService($serviceType, $serviceSubType='', $excludeServiceKeys=array())
* 3961: function plainMailEncoded($email,$subject,$message,$headers='',$enc='',$charset='',$dontEncodeHeader=false)
* 3961: function plainMailEncoded($email,$subject,$message,$headers='',$enc='',$charset='',$dontEncodeHeader=false)
* 4031: function quoted_printable($string,$maxlen=76)
* 4031: function quoted_printable($string,$maxlen=76)
* 4078: function encodeHeader($line,$enc='',$charset='ISO-8859-1')
* 4078: function encodeHeader($line,$enc='',$charset='ISO-8859-1')
* 4121: function substUrlsInPlainText($message,$urlmode='76',$index_script_url='')
* 4121: function substUrlsInPlainText($message,$urlmode='76',$index_script_url='')
* 4155: function makeRedirectUrl($inUrl,$l=0,$index_script_url='')
* 4155: function makeRedirectUrl($inUrl,$l=0,$index_script_url='')
* 4182: function freetypeDpiComp($font_size)
* 4182: function freetypeDpiComp($font_size)
* 4194: function initSysLog()
* 4194: function initSysLog()
* 4251: function sysLog($msg, $extKey, $severity=0)
* 4251: function sysLog($msg, $extKey, $severity=0)
* 4334: function devLog($msg, $extKey, $severity=0, $dataVar=FALSE)
* 4334: function devLog($msg, $extKey, $severity=0, $dataVar=FALSE)
* 4355: function arrayToLogString($arr, $valueList=array(), $valueLength=20)
* 4355: function arrayToLogString($arr, $valueList=array(), $valueLength=20)
* 4378: function imageMagickCommand($command, $parameters, $path='')
* 4378: function imageMagickCommand($command, $parameters, $path='')
* 4425: function unQuoteFilenames($parameters,$unQuote=FALSE)
* 4425: function unQuoteFilenames($parameters,$unQuote=FALSE)
* 4459: function quoteJSvalue($value, $inScriptTags = false)
* 4459: function quoteJSvalue($value, $inScriptTags = false)
*
* TOTAL FUNCTIONS: 138
* (This index is automatically created/updated by the extension "extdeveval")
......
* @param string GET/POST var to return
* @return mixed POST var named $var and if not set, the GET var of the same name.
*/
public static function _GP($var) {
public static function _GP($var) {
if(empty($var)) return;
if (empty($var)) {
return;
}
$value = isset($_POST[$var]) ? $_POST[$var] : $_GET[$var];
if (isset($value)) {
if (isset($value)) {
if (is_array($value)) { self::stripSlashesOnArray($value); } else { $value = stripslashes($value); }
if (is_array($value)) {
self::stripSlashesOnArray($value);
} else {
$value = stripslashes($value);
}
}
}
return $value;
}
......
*/
public static function _GPmerged($parameter) {
$postParameter = (isset($_POST[$parameter]) && is_array($_POST[$parameter])) ? $_POST[$parameter] : array();
$getParameter = (isset($_GET[$parameter]) && is_array($_GET[$parameter])) ? $_GET[$parameter] : array();
$getParameter = (isset($_GET[$parameter]) && is_array($_GET[$parameter])) ? $_GET[$parameter] : array();
$mergedParameters = self::array_merge_recursive_overrule($getParameter, $postParameter);
self::stripSlashesOnArray($mergedParameters);
......
* @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()
*/
public static 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 (isset($value)) { // Removes slashes since TYPO3 has added them regardless of magic_quotes setting.
if (is_array($value)) { self::stripSlashesOnArray($value); } else { $value = stripslashes($value); }
if (is_array($value)) {
self::stripSlashesOnArray($value);
} else {
$value = stripslashes($value);
}
}
}
return $value;
}
......
* @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()
*/
public static 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 (isset($value)) { // Removes slashes since TYPO3 has added them regardless of magic_quotes setting.
if (is_array($value)) { self::stripSlashesOnArray($value); } else { $value = stripslashes($value); }
if (is_array($value)) {
self::stripSlashesOnArray($value);
} else {
$value = stripslashes($value);
}
}
}
return $value;
}
......
* Usage: 2
*
* @param mixed $inputGet
* array or single value to write to $_GET. Values should NOT be
* array or single value to write to $_GET. Values should NOT be
* escaped at input time (but will be escaped before writing
* escaped at input time (but will be escaped before writing
* according to TYPO3 standards).
* according to TYPO3 standards).
* @param string $key
* alternative key; If set, this will not set the WHOLE GET array,
* alternative key; If set, this will not set the WHOLE GET array,
* but only the key in it specified by this value!
* but only the key in it specified by this value!
* You can specify to replace keys on deeper array levels by
* You can specify to replace keys on deeper array levels by
* separating the keys with a pipe.
* separating the keys with a pipe.
* Example: 'parentKey|childKey' will result in
* Example: 'parentKey|childKey' will result in
* array('parentKey' => array('childKey' => $inputGet))
* array('parentKey' => array('childKey' => $inputGet))
*
* @return void
*/
......
* @deprecated since TYPO3 3.6, will be removed in TYPO3 4.6 - Use t3lib_div::_GP instead (ALWAYS delivers a value with un-escaped values!)
* @see _GP()
*/
public static function GPvar($var,$strip=0) {
public static function GPvar($var, $strip = 0) {
self::logDeprecatedFunction();
if(empty($var)) return;
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.
if ($strip && isset($value) && is_array($value)) { self::stripSlashesOnArray($value); }
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.
if ($strip && isset($value) && is_array($value)) {
self::stripSlashesOnArray($value);
}
return $value;
}
......
* @deprecated since TYPO3 3.7, will be removed in TYPO3 4.6 - Use t3lib_div::_GPmerged instead
* @see _GP()
*/
public static function GParrayMerged($var) {
public static function GParrayMerged($var) {
self::logDeprecatedFunction();
return self::_GPmerged($var);
......
* @param string Input string
* @return string Input string with potential XSS code removed
*/
public static function removeXSS($string) {
public static function removeXSS($string) {
require_once(PATH_typo3.'contrib/RemoveXSS/RemoveXSS.php');
require_once(PATH_typo3 . 'contrib/RemoveXSS/RemoveXSS.php');
$string = RemoveXSS::process($string);
return $string;
}
/*************************
*
* IMAGE FUNCTIONS
......
* Compressing a GIF file if not already LZW compressed.
* This function is a workaround for the fact that ImageMagick and/or GD does not compress GIF-files to their minimun size (that is RLE or no compression used)
*
* The function takes a file-reference, $theFile, and saves it again through GD or ImageMagick in order to compress the file
* The function takes a file-reference, $theFile, and saves it again through GD or ImageMagick in order to compress the file
* GIF:
* GIF:
* If $type is not set, the compression is done with ImageMagick (provided that $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_path_lzw'] is pointing to the path of a lzw-enabled version of 'convert') else with GD (should be RLE-enabled!)
* If $type is not set, the compression is done with ImageMagick (provided that $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_path_lzw'] is pointing to the path of a lzw-enabled version of 'convert') else with GD (should be RLE-enabled!)
* If $type is set to either 'IM' or 'GD' the compression is done with ImageMagick and GD respectively
* If $type is set to either 'IM' or 'GD' the compression is done with ImageMagick and GD respectively
* PNG:
* PNG:
* No changes.
* No changes.
*
* $theFile is expected to be a valid GIF-file!
* $theFile is expected to be a valid GIF-file!
* The function returns a code for the operation.
* The function returns a code for the operation.
* Usage: 9
*
* @param string Filepath
* @param string See description of function
* @return string Returns "GD" if GD was used, otherwise "IM" if ImageMagick was used. If nothing done at all, it returns empty string.
*/
public static function gif_compress($theFile, $type) {
public static function gif_compress($theFile, $type) {
$gfxConf = $GLOBALS['TYPO3_CONF_VARS']['GFX'];
$returnCode='';
$returnCode = '';
if ($gfxConf['gif_compress'] && strtolower(substr($theFile,-4,4))=='.gif') { // GIF...
if ($gfxConf['gif_compress'] && strtolower(substr($theFile, -4, 4)) == '.gif') { // GIF...
if (($type=='IM' || !$type) && $gfxConf['im'] && $gfxConf['im_path_lzw']) { // IM
if (($type == 'IM' || !$type) && $gfxConf['im'] && $gfxConf['im_path_lzw']) { // IM
$cmd = self::imageMagickCommand('convert', '"'.$theFile.'" "'.$theFile.'"', $gfxConf['im_path_lzw']);
$cmd = self::imageMagickCommand('convert', '"' . $theFile . '" "' . $theFile . '"', $gfxConf['im_path_lzw']);
exec($cmd);
$returnCode='IM';
$returnCode = 'IM';
} elseif (($type=='GD' || !$type) && $gfxConf['gdlib'] && !$gfxConf['gdlib_png']) { // GD
} elseif (($type == 'GD' || !$type) && $gfxConf['gdlib'] && !$gfxConf['gdlib_png']) { // GD
$tempImage = imageCreateFromGif($theFile);
imageGif($tempImage, $theFile);
imageDestroy($tempImage);
$returnCode='GD';
$returnCode = 'GD';
}
}
return $returnCode;
......
* @param string $theFile the filename with path
* @return string new filename
*/
public static 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']
&& $GLOBALS['TYPO3_CONF_VARS']['GFX']['im']
&& $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_path_lzw']
&& strtolower(substr($theFile,-4,4))=='.png'
&& strtolower(substr($theFile, -4, 4)) == '.png'
&& @is_file($theFile)) { // IM
&& @is_file($theFile)) { // IM
$newFile = substr($theFile,0,-4).'.gif';
$newFile = substr($theFile, 0, -4) . '.gif';
$cmd = self::imageMagickCommand('convert', '"'.$theFile.'" "'.$newFile.'"', $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_path_lzw']);
$cmd = self::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!!
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!!
}
return $theFile;
}
......
* @param boolean If set, then input file is converted to PNG, otherwise to GIF
* @return string If the new image file exists, it's filepath is returned
*/
public static 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)) {
if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['im'] && @is_file($theFile)) {
$ext = strtolower(substr($theFile,-4,4));
$ext = strtolower(substr($theFile, -4, 4));
if (
((string)$ext=='.png' && $output_png) ||
((string) $ext == '.png' && $output_png) ||
((string)$ext=='.gif' && !$output_png)
((string) $ext == '.gif' && !$output_png)
) {
) {
return $theFile;
} else {
$newFile = PATH_site.'typo3temp/readPG_'.md5($theFile.'|'.filemtime($theFile)).($output_png?'.png':'.gif');
$newFile = PATH_site . 'typo3temp/readPG_' . md5($theFile . '|' . filemtime($theFile)) . ($output_png ? '.png' : '.gif');
$cmd = self::imageMagickCommand('convert', '"'.$theFile.'" "'.$newFile.'"', $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_path']);
$cmd = self::imageMagickCommand('convert', '"' . $theFile . '" "' . $newFile . '"', $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_path']);
exec($cmd);
if (@is_file($newFile)) return $newFile;
if (@is_file($newFile)) {
return $newFile;
}
}
}
}
}
}
}
/*************************
*
* STRING FUNCTIONS
......
* @deprecated since TYPO3 4.1, will be removed in TYPO3 4.6 - Works ONLY for single-byte charsets! Use t3lib_div::fixed_lgd_cs() instead
* @see fixed_lgd_pre()
*/
public static function fixed_lgd($string,$origChars,$preStr='...') {
public static function fixed_lgd($string, $origChars, $preStr = '...') {
self::logDeprecatedFunction();
$chars = abs($origChars);
if ($chars >= 4) {
if ($chars >= 4) {
if(strlen($string)>$chars) {
if (strlen($string) > $chars) {
return $origChars < 0 ?
$preStr.trim(substr($string, -($chars-3))) :
$preStr . trim(substr($string, -($chars - 3))) :
trim(substr($string, 0, $chars-3)).$preStr;
trim(substr($string, 0, $chars - 3)) . $preStr;
}
}
return $string;
......
* @deprecated since TYPO3 4.1, will be removed in TYPO3 4.6 - Use t3lib_div::fixed_lgd_cs() instead (with negative input value for $chars)
* @see fixed_lgd()
*/
public static function fixed_lgd_pre($string,$chars) {
public static function fixed_lgd_pre($string, $chars) {
self::logDeprecatedFunction();
return strrev(self::fixed_lgd(strrev($string),$chars));
return strrev(self::fixed_lgd(strrev($string), $chars));
}
/**
......
* @param string appendix to the truncated string
* @return string cropped string
*/
public static function fixed_lgd_cs($string, $chars, $appendString='...') {
public static function fixed_lgd_cs($string, $chars, $appendString = '...') {
if (is_object($GLOBALS['LANG'])) {
return $GLOBALS['LANG']->csConvObj->crop($GLOBALS['LANG']->charSet, $string, $chars, $appendString);
} elseif (is_object($GLOBALS['TSFE'])) {
......
* @deprecated since TYPO3 4.1, will be removed in TYPO3 4.6 - Use PHP function wordwrap()
* @return string
*/
public static function breakTextForEmail($str,$implChar=LF,$charWidth=76) {
public static function breakTextForEmail($str, $implChar = LF, $charWidth = 76) {
self::logDeprecatedFunction();
$lines = explode(LF,$str);
$lines = explode(LF, $str);
$outArr=array();
$outArr = array();
foreach ($lines as $lStr) {
$outArr[] = self::breakLinesForEmail($lStr,$implChar,$charWidth);
$outArr[] = self::breakLinesForEmail($lStr, $implChar, $charWidth);
}
return implode(LF,$outArr);
return implode(LF, $outArr);
}
/**
......
* @return string
* @see breakTextForEmail()
*/
public static function breakLinesForEmail($str,$implChar=LF,$charWidth=76) {
public static function breakLinesForEmail($str, $implChar = LF, $charWidth = 76) {
$lines=array();
$lines = array();
$l=$charWidth;
$l = $charWidth;
$p=0;
$p = 0;
while(strlen($str)>$p) {
while (strlen($str) > $p) {
$substr=substr($str,$p,$l);
$substr = substr($str, $p, $l);
if (strlen($substr)==$l) {
if (strlen($substr) == $l) {
$count = count(explode(' ',trim(strrev($substr))));
$count = count(explode(' ', trim(strrev($substr))));
if ($count>1) { // OK...
if ($count > 1) { // OK...
$parts = explode(' ',strrev($substr),2);
$parts = explode(' ', strrev($substr), 2);
$theLine = strrev($parts[1]);
} else {
$afterParts = explode(' ',substr($str,$l+$p),2);
$afterParts = explode(' ', substr($str, $l + $p), 2);
$theLine = $substr.$afterParts[0];
$theLine = $substr . $afterParts[0];
}
if (!strlen($theLine)) {break; } // Error, because this would keep us in an endless loop.
if (!strlen($theLine)) {
break;
} // Error, because this would keep us in an endless loop.
} else {
$theLine=$substr;
$theLine = $substr;
}
$lines[]=trim($theLine);
$lines[] = trim($theLine);
$p+=strlen($theLine);
$p += strlen($theLine);
if (!trim(substr($str,$p,$l))) break; // added...
if (!trim(substr($str, $p, $l))) {
break;
} // added...
}
return implode($implChar,$lines);
return implode($implChar, $lines);
}
/**
......
* @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) {
public static function cmpIP($baseIP, $list) {
$list = trim($list);
if ($list === '') {
if ($list === '') {
return false;
return FALSE;
} elseif ($list === '*') {
} elseif ($list === '*') {
return true;
return TRUE;
}
if (strpos($baseIP, ':') !== false && self::validIPv6($baseIP)) {
if (strpos($baseIP, ':') !== FALSE && self::validIPv6($baseIP)) {
return self::cmpIPv6($baseIP, $list);
} else {
return self::cmpIPv4($baseIP, $list);
......
* @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
*/
public static function cmpIPv4($baseIP, $list) {
public static function cmpIPv4($baseIP, $list) {
$IPpartsReq = explode('.',$baseIP);
$IPpartsReq = explode('.', $baseIP);
if (count($IPpartsReq)==4) {
if (count($IPpartsReq) == 4) {
$values = self::trimExplode(',',$list,1);
$values = self::trimExplode(',', $list, 1);
foreach($values as $test) {
foreach ($values as $test) {
list($test,$mask) = explode('/',$test);
list($test, $mask) = explode('/', $test);
if(intval($mask)) {
if (intval($mask)) {
// "192.168.3.0/24"
$lnet = ip2long($test);
$lip = ip2long($baseIP);
$binnet = str_pad(decbin($lnet), 32, '0', STR_PAD_LEFT);
$firstpart = substr($binnet,0,$mask);
$firstpart = substr($binnet, 0, $mask);
$binip = str_pad(decbin($lip), 32, '0', STR_PAD_LEFT);
$firstip = substr($binip,0,$mask);
$firstip = substr($binip, 0, $mask);
$yes = (strcmp($firstpart,$firstip)==0);
$yes = (strcmp($firstpart, $firstip) == 0);
} else {
// "192.168.*.*"
$IPparts = explode('.',$test);
$IPparts = explode('.', $test);
$yes = 1;
foreach ($IPparts as $index => $val) {
$val = trim($val);
if (strcmp($val,'*') && strcmp($IPpartsReq[$index],$val)) {
if (strcmp($val, '*') && strcmp($IPpartsReq[$index], $val)) {
$yes=0;
$yes = 0;
}
}
}
if ($yes) return true;
if ($yes) {
return TRUE;
}
}
}
}
return false;
}
}
return FALSE;
}
/**
* Match IPv6 address with a list of IPv6 prefixes
......
* @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) {
public static function cmpIPv6($baseIP, $list) {
$success = false; // Policy default: Deny connection
$success = FALSE; // Policy default: Deny connection
$baseIP = self::normalizeIPv6($baseIP);
$values = self::trimExplode(',',$list,1);
$values = self::trimExplode(',', $list, 1);
foreach ($values as $test) {
foreach ($values as $test) {
list($test,$mask) = explode('/',$test);
list($test, $mask) = explode('/', $test);
if (self::validIPv6($test)) {
if (self::validIPv6($test)) {
$test = self::normalizeIPv6($test);
if (intval($mask)) {
if (intval($mask)) {
switch ($mask) { // test on /48 /64
switch ($mask) { // test on /48 /64
case '48':
$testBin = substr(self::IPv6Hex2Bin($test), 0, 48);
$baseIPBin = substr(self::IPv6Hex2Bin($baseIP), 0, 48);
$success = strcmp($testBin, $baseIPBin)==0 ? true : false;
$success = strcmp($testBin, $baseIPBin) == 0 ? TRUE : FALSE;
break;
break;
case '64':
$testBin = substr(self::IPv6Hex2Bin($test), 0, 64);
$baseIPBin = substr(self::IPv6Hex2Bin($baseIP), 0, 64);
$success = strcmp($testBin, $baseIPBin)==0 ? true : false;
$success = strcmp($testBin, $baseIPBin) == 0 ? TRUE : FALSE;
break;
break;
default:
$success = false;
$success = FALSE;
}
} else {
if (self::validIPv6($test)) { // test on full ip address 128 bits
if (self::validIPv6($test)) { // test on full ip address 128 bits
$testBin = self::IPv6Hex2Bin($test);
$baseIPBin = self::IPv6Hex2Bin($baseIP);
$success = strcmp($testBin, $baseIPBin)==0 ? true : false;
$success = strcmp($testBin, $baseIPBin) == 0 ? TRUE : FALSE;
}
}
}
if ($success) return true;
if ($success) {
return TRUE;
}
}
return false;
}
}
return FALSE;
}
/**
* [Describe function...]
......
* @param [type] $hex: ...
* @return [type] ...
*/
public static function IPv6Hex2Bin ($hex) {
public static function IPv6Hex2Bin($hex) {
$bin = '';
$hex = str_replace(':', '', $hex); // Replace colon to nothing
$hex = str_replace(':', '', $hex); // Replace colon to nothing
for ($i=0; $i<strlen($hex); $i=$i+2) {
for ($i = 0; $i < strlen($hex); $i = $i + 2) {
$bin.= chr(hexdec(substr($hex, $i, 2)));
$bin .= chr(hexdec(substr($hex, $i, 2)));
}
return $bin;
}
......
* @param string Given IPv6 address
* @return string Normalized address
*/
public static function normalizeIPv6($address) {
public static function normalizeIPv6($address) {
$normalizedAddress = '';
$stageOneAddress = '';
$chunks = explode('::', $address); // Count 2 if if address has hidden zero blocks
$chunks = explode('::', $address); // Count 2 if if address has hidden zero blocks
if (count($chunks)==2) {
if (count($chunks) == 2) {
$chunksLeft = explode(':', $chunks[0]);
$chunksRight = explode(':', $chunks[1]);
$left = count($chunksLeft);
$right = count($chunksRight);
// Special case: leading zero-only blocks count to 1, should be 0
if ($left==1 && strlen($chunksLeft[0])==0) $left=0;
if ($left == 1 && strlen($chunksLeft[0]) == 0) {
$left = 0;
}
$hiddenBlocks = 8 - ($left + $right);
$hiddenPart = '';
$h = 0;
while ($h<$hiddenBlocks) {
while ($h < $hiddenBlocks) {
$hiddenPart .= '0000:';
$h++;
}
......
} else {
$stageOneAddress = $chunks[0] . ':' . $hiddenPart . $chunks[1];
}
} else $stageOneAddress = $address;
} else {
$stageOneAddress = $address;
}
// normalize the blocks:
$blocks = explode(':', $stageOneAddress);
$divCounter = 0;
foreach ($blocks as $block) {
foreach ($blocks as $block) {
$tmpBlock = '';
$i = 0;
$hiddenZeros = 4 - strlen($block);
while ($i < $hiddenZeros) {
while ($i < $hiddenZeros) {
$tmpBlock .= '0';
$i++;
}
$normalizedAddress .= $tmpBlock . $block;
if ($divCounter < 7) {
if ($divCounter < 7) {
$normalizedAddress .= ':';
$divCounter++;
}
......
* @return boolean True if $ip is either of IPv4 or IPv6 format.
*/
public static function validIP($ip) {
return (filter_var($ip, FILTER_VALIDATE_IP) !== false);
return (filter_var($ip, FILTER_VALIDATE_IP) !== FALSE);
}
/**
......
* @return boolean True if $ip is of IPv4 format.
*/
public static function validIPv4($ip) {
return (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) !== false);
return (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) !== FALSE);
}
/**
......
* @param string IP address to be tested
* @return boolean True if $ip is of IPv6 format.
*/
public static function validIPv6($ip) {
public static function validIPv6($ip) {
return (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) !== false);
return (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) !== FALSE);
}
/**
......
* @param string A comma-list of domain names to match with. *-wildcard allowed but cannot be part of a string, so it must match the full host name (eg. myhost.*.com => correct, myhost.*domain.com => wrong)
* @return boolean True if a domain name mask from $list matches $baseIP
*/
public static function cmpFQDN($baseIP, $list) {
public static function cmpFQDN($baseIP, $list) {
if (count(explode('.',$baseIP))==4) {
if (count(explode('.', $baseIP)) == 4) {
$resolvedHostName = explode('.', gethostbyaddr($baseIP));
$values = self::trimExplode(',',$list,1);
$values = self::trimExplode(',', $list, 1);
foreach($values as $test) {
foreach ($values as $test) {
$hostNameParts = explode('.',$test);
$hostNameParts = explode('.', $test);
$yes = 1;
foreach($hostNameParts as $index => $val) {
foreach ($hostNameParts as $index => $val) {
$val = trim($val);
if (strcmp($val,'*') && strcmp($resolvedHostName[$index],$val)) {
if (strcmp($val, '*') && strcmp($resolvedHostName[$index], $val)) {
$yes=0;
$yes = 0;
}
}
if ($yes) return true;
if ($yes) {
return TRUE;
}
}
}
}
return false;
}
}
return FALSE;
}
/**
* Checks if a given URL matches the host that currently handles this HTTP request.
......
* @param string item to check for
* @return boolean true if $item is in $list
*/
public static function inList($list, $item) {
public static function inList($list, $item) {
return (strpos(','.$list.',', ','.$item.',')!==false ? true : false);
return (strpos(',' . $list . ',', ',' . $item . ',') !== FALSE ? TRUE : FALSE);
}
/**
......
* @param string comma-separated list of items (string)
* @return string new comma-separated list of items
*/
public static function rmFromList($element,$list) {
public static function rmFromList($element, $list) {
$items = explode(',',$list);
$items = explode(',', $list);
foreach ($items as $k => $v) {
if ($v==$element) {
if ($v == $element) {
unset($items[$k]);
}
}
return implode(',',$items);
return implode(',', $items);
}
/**
......
* @return string new comma-separated list of items
* @author Martin Kutschker <martin.kutschker@activesolution.at>
*/
public static function expandList($list) {
public static function expandList($list) {
$items = explode(',',$list);
$items = explode(',', $list);
$list = array();
foreach ($items as $item) {
$range = explode('-',$item);
$range = explode('-', $item);
if (isset($range[1])) {
if (isset($range[1])) {
$runAwayBrake = 1000;
for ($n=$range[0]; $n<=$range[1]; $n++) {
for ($n = $range[0]; $n <= $range[1]; $n++) {
$list[] = $n;
$runAwayBrake--;
if ($runAwayBrake<=0) break;
if ($runAwayBrake <= 0) {
break;
}
}
}
} else {
$list[] = $item;
}
}
return implode(',',$list);
return implode(',', $list);
}
/**
......
* @param integer Default value if input is false.
* @return integer The input value forced into the boundaries of $min and $max
*/
public static function intInRange($theInt,$min,$max=2000000000,$zeroValue=0) {
public static function intInRange($theInt, $min, $max = 2000000000, $zeroValue = 0) {
// Returns $theInt as an integer in the integerspace from $min to $max
// Returns $theInt as an integer in the integerspace from $min to $max
$theInt = intval($theInt);
if ($zeroValue && !$theInt) {$theInt=$zeroValue;} // If the input value is zero after being converted to integer, zeroValue may set another default value for it.
if ($theInt<$min){$theInt=$min;}
if ($theInt>$max){$theInt=$max;}
if ($zeroValue && !$theInt) {
$theInt = $zeroValue;
} // If the input value is zero after being converted to integer, zeroValue may set another default value for it.
if ($theInt < $min) {
$theInt = $min;
}
if ($theInt > $max) {
$theInt = $max;
}
return $theInt;
}
......
* @param integer Integer string to process
* @return integer
*/
public static function intval_positive($theInt) {
public static function intval_positive($theInt) {
$theInt = intval($theInt);
if ($theInt<0){$theInt=0;}
if ($theInt < 0) {
$theInt = 0;
}
return $theInt;
}
......
* @param string Version number on format x.x.x
* @return integer Integer version of version number (where each part can count to 999)
*/
public static function int_from_ver($verNumberStr) {
public static function int_from_ver($verNumberStr) {
$verParts = explode('.',$verNumberStr);
$verParts = explode('.', $verNumberStr);
return intval((int)$verParts[0].str_pad((int)$verParts[1],3,'0',STR_PAD_LEFT).str_pad((int)$verParts[2],3,'0',STR_PAD_LEFT));
return intval((int) $verParts[0] . str_pad((int) $verParts[1], 3, '0', STR_PAD_LEFT) . str_pad((int) $verParts[2], 3, '0', STR_PAD_LEFT));
}
/**
......
* @return boolean Returns true if this setup is compatible with the provided version number
* @todo Still needs a function to convert versions to branches
*/
public static function compat_version($verNumberStr) {
public static function compat_version($verNumberStr) {
global $TYPO3_CONF_VARS;
$currVersionStr = $TYPO3_CONF_VARS['SYS']['compat_version'] ? $TYPO3_CONF_VARS['SYS']['compat_version'] : TYPO3_branch;
if (self::int_from_ver($currVersionStr) < self::int_from_ver($verNumberStr)) {
if (self::int_from_ver($currVersionStr) < self::int_from_ver($verNumberStr)) {
return FALSE;
} else {
return TRUE;
......
* @param string String to md5-hash
* @return integer Returns 28bit integer-hash
*/
public static function md5int($str) {
public static function md5int($str) {
return hexdec(substr(md5($str),0,7));
return hexdec(substr(md5($str), 0, 7));
}
/**
......
* @param integer The string-length of the output
* @return string Substring of the resulting md5-hash, being $len chars long (from beginning)
*/
public static function shortMD5($input, $len=10) {
public static function shortMD5($input, $len = 10) {
return substr(md5($input),0,$len);
return substr(md5($input), 0, $len);
}
/**
* Returns a proper HMAC on a given input string and secret TYPO3 encryption key.
*
* @param string Input string to create HMAC from
* @param string Input string to create HMAC from
* @return string resulting (hexadecimal) HMAC currently with a length of 40 (HMAC-SHA-1)
* @return string resulting (hexadecimal) HMAC currently with a length of 40 (HMAC-SHA-1)
*/
public static function hmac($input) {
$hashAlgorithm = 'sha1';
......
// keys shorter than blocksize are zero-padded
$key = str_pad($GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'], $hashBlocksize, chr(0x00));
}
$hmac = call_user_func($hashAlgorithm, ($key^$opad) . pack('H*', call_user_func($hashAlgorithm, ($key^$ipad) . $input)));
$hmac = call_user_func($hashAlgorithm, ($key ^ $opad) . pack('H*', call_user_func($hashAlgorithm, ($key ^ $ipad) . $input)));
}
return $hmac;
}
......
* @param mixed $secondParameter: Dummy field, which if set will show a warning!
* @return string Returns the list without any duplicates of values, space around values are trimmed
*/
public static function uniqueList($in_list, $secondParameter=NULL) {
public static function uniqueList($in_list, $secondParameter = NULL) {
if (is_array($in_list)) {
throw new InvalidArgumentException(
'TYPO3 Fatal Error: t3lib_div::uniqueList() does NOT support array arguments anymore! Only string comma lists!',
......
);
}
return implode(',',array_unique(self::trimExplode(',',$in_list,1)));
return implode(',', array_unique(self::trimExplode(',', $in_list, 1)));
}
/**
......
* @param string Filename/filepath to be analysed
* @return array Contains keys [path], [file], [filebody], [fileext], [realFileext]
*/
public static function split_fileref($fileref) {
public static function split_fileref($fileref) {
$reg = array();
if (preg_match('/(.*\/)(.*)$/', $fileref, $reg)) {
$info['path'] = $reg[1];
......
* @param string Directory name / path
* @return string Processed input value. See function description.
*/
public static function dirname($path) {
public static function dirname($path) {
$p = self::revExplode('/',$path,2);
$p = self::revExplode('/', $path, 2);
return count($p)==2 ? $p[0] : '';
return count($p) == 2 ? $p[0] : '';
}
/**
......
* @return string A hexadecimal color code, #xxxxxx, modified according to input vars
* @see modifyHTMLColorAll()
*/
public static function modifyHTMLColor($color,$R,$G,$B) {
public static function modifyHTMLColor($color, $R, $G, $B) {
// This takes a hex-color (# included!) and adds $R, $G and $B to the HTML-color (format: #xxxxxx) and returns the new color
// This takes a hex-color (# included!) and adds $R, $G and $B to the HTML-color (format: #xxxxxx) and returns the new color
$nR = self::intInRange(hexdec(substr($color,1,2))+$R,0,255);
$nR = self::intInRange(hexdec(substr($color, 1, 2)) + $R, 0, 255);
$nG = self::intInRange(hexdec(substr($color,3,2))+$G,0,255);
$nG = self::intInRange(hexdec(substr($color, 3, 2)) + $G, 0, 255);
$nB = self::intInRange(hexdec(substr($color,5,2))+$B,0,255);
$nB = self::intInRange(hexdec(substr($color, 5, 2)) + $B, 0, 255);
return '#'.
return '#' .
substr('0'.dechex($nR),-2).
substr('0' . dechex($nR), -2) .
substr('0'.dechex($nG),-2).
substr('0' . dechex($nG), -2) .
substr('0'.dechex($nB),-2);
substr('0' . dechex($nB), -2);
}
/**
......
* @return string A hexadecimal color code, #xxxxxx, modified according to input vars
* @see modifyHTMLColor()
*/
public static function modifyHTMLColorAll($color,$all) {
public static function modifyHTMLColorAll($color, $all) {
return self::modifyHTMLColor($color,$all,$all,$all);
return self::modifyHTMLColor($color, $all, $all, $all);
}
/**
......
* @return string
* @deprecated since TYPO3 4.5, will be removed in TYPO3 4.7 - Use rtrim() directly
*/
public static function rm_endcomma($string) {
public static function rm_endcomma($string) {
self::logDeprecatedFunction();
return rtrim($string, ',');
......
* @deprecated since TYPO3 3.5, will be removed in TYPO3 4.6 - Use t3lib_cs::conv_case() instead or for HTML output, wrap your content in <span class="uppercase">...</span>)
* @ignore
*/
public static function danish_strtoupper($string) {
public static function danish_strtoupper($string) {
self::logDeprecatedFunction();
$value = strtoupper($string);
......
* @deprecated since TYPO3 4.1, will be removed in TYPO3 4.6 - Works only for western europe single-byte charsets! Use t3lib_cs::specCharsToASCII() instead!
* @return string
*/
public static function convUmlauts($str) {
public static function convUmlauts($str) {
self::logDeprecatedFunction();
$pattern = array (chr(228), chr(196), chr(246), chr(214), chr(252), chr(220), chr(223), chr(229), chr(197), chr(248), chr(216), chr(230), chr(198));
$pattern = array(chr(228), chr(196), chr(246), chr(214), chr(252), chr(220), chr(223), chr(229), chr(197), chr(248), chr(216), chr(230), chr(198));
$replace = array ('ae', 'Ae', 'oe', 'Oe', 'ue', 'Ue', 'ss', 'aa', 'AA', 'oe', 'OE', 'ae', 'AE');
$replace = array('ae', 'Ae', 'oe', 'Oe', 'ue', 'Ue', 'ss', 'aa', 'AA', 'oe', 'OE', 'ae', 'AE');
return str_replace($pattern, $replace, $str);
}
......
if ($var === '') {
return FALSE;
}
return (string)intval($var) === (string)$var;
return (string) intval($var) === (string) $var;
}
/**
......
* @param string Reference string which must be found as the "first part" of the full string
* @return boolean True if $partStr was found to be equal to the first part of $str
*/
public static function isFirstPartOfStr($str,$partStr) {
public static function isFirstPartOfStr($str, $partStr) {
return $partStr != '' && strpos((string) $str, (string) $partStr, 0) === 0;
}
......
* @param string Labels for bytes, kilo, mega and giga separated by vertical bar (|) and possibly encapsulated in "". Eg: " | K| M| G" (which is the default value)
* @return string Formatted representation of the byte number, for output.
*/
public static function formatSize($sizeInBytes,$labels='') {
public static function formatSize($sizeInBytes, $labels = '') {
// Set labels:
if (strlen($labels) == 0) {
$labels = ' | K| M| G';
} else {
$labels = str_replace('"','',$labels);
$labels = str_replace('"', '', $labels);
}
$labelArr = explode('|',$labels);
$labelArr = explode('|', $labels);
// Find size:
if ($sizeInBytes>900) {
if ($sizeInBytes > 900) {
if ($sizeInBytes>900000000) { // GB
if ($sizeInBytes > 900000000) { // GB
$val = $sizeInBytes/(1024*1024*1024);
$val = $sizeInBytes / (1024 * 1024 * 1024);
return number_format($val, (($val<20)?1:0), '.', '').$labelArr[3];
return number_format($val, (($val < 20) ? 1 : 0), '.', '') . $labelArr[3];
}
elseif ($sizeInBytes>900000) { // MB
elseif ($sizeInBytes > 900000) { // MB
$val = $sizeInBytes/(1024*1024);
$val = $sizeInBytes / (1024 * 1024);
return number_format($val, (($val<20)?1:0), '.', '').$labelArr[2];
return number_format($val, (($val < 20) ? 1 : 0), '.', '') . $labelArr[2];
} else { // KB
} else { // KB
$val = $sizeInBytes/(1024);
$val = $sizeInBytes / (1024);
return number_format($val, (($val<20)?1:0), '.', '').$labelArr[1];
return number_format($val, (($val < 20) ? 1 : 0), '.', '') . $labelArr[1];
}
} else { // Bytes
} else { // Bytes
return $sizeInBytes.$labelArr[0];
return $sizeInBytes . $labelArr[0];
}
}
......
* @param string Microtime
* @return integer Microtime input string converted to an integer (milliseconds)
*/
public static function convertMicrotime($microtime) {
public static function convertMicrotime($microtime) {
$parts = explode(' ',$microtime);
$parts = explode(' ', $microtime);
return round(($parts[0]+$parts[1])*1000);
return round(($parts[0] + $parts[1]) * 1000);
}
/**
......
* @return array Array with operators and operands separated.
* @see tslib_cObj::calc(), tslib_gifBuilder::calcOffset()
*/
public static function splitCalc($string,$operators) {
public static function splitCalc($string, $operators) {
$res = Array();
$sign='+';
$sign = '+';
while($string) {
while ($string) {
$valueLen=strcspn($string,$operators);
$valueLen = strcspn($string, $operators);
$value=substr($string,0,$valueLen);
$value = substr($string, 0, $valueLen);
$res[] = Array($sign,trim($value));
$res[] = Array($sign, trim($value));
$sign=substr($string,$valueLen,1);
$sign = substr($string, $valueLen, 1);
$string=substr($string,$valueLen+1);
$string = substr($string, $valueLen + 1);
}
reset($res);
return $res;
......
* @return integer Calculated value. Or error string.
* @see calcParenthesis()
*/
public static function calcPriority($string) {
public static function calcPriority($string) {
$string=preg_replace('/[[:space:]]*/','',$string); // removing all whitespace
$string = preg_replace('/[[:space:]]*/', '', $string); // removing all whitespace
$string='+'.$string; // Ensuring an operator for the first entrance
$string = '+' . $string; // Ensuring an operator for the first entrance
$qm='\*\/\+-^%';
$qm = '\*\/\+-^%';
$regex = '(['.$qm.'])(['.$qm.']?[0-9\.]*)';
$regex = '([' . $qm . '])([' . $qm . ']?[0-9\.]*)';
// split the expression here:
$reg = array();
preg_match_all('/'.$regex.'/',$string,$reg);
preg_match_all('/' . $regex . '/', $string, $reg);
reset($reg[2]);
$number=0;
$number = 0;
$Msign='+';
$Msign = '+';
$err='';
$err = '';
$buffer=doubleval(current($reg[2]));
$buffer = doubleval(current($reg[2]));
next($reg[2]); // Advance pointer
next($reg[2]); // Advance pointer
while(list($k,$v)=each($reg[2])) {
while (list($k, $v) = each($reg[2])) {
$v=doubleval($v);
$v = doubleval($v);
$sign = $reg[1][$k];
if ($sign=='+' || $sign=='-') {
if ($sign == '+' || $sign == '-') {
$number = $Msign=='-' ? $number-=$buffer : $number+=$buffer;
$number = $Msign == '-' ? $number -= $buffer : $number += $buffer;
$Msign = $sign;
$buffer=$v;
$buffer = $v;
} else {
if ($sign=='/') {if ($v) $buffer/=$v; else $err='dividing by zero';}
if ($sign=='%') {if ($v) $buffer%=$v; else $err='dividing by zero';}
if ($sign=='*') {$buffer*=$v;}
if ($sign=='^') {$buffer=pow($buffer,$v);}
if ($sign == '/') {
if ($v) {
$buffer /= $v;
} else {
$err = 'dividing by zero';
}
}
... This diff was truncated because it exceeds the maximum size that can be displayed.
(1-1/93)