*/ /** * [CLASS/FUNCTION INDEX of SCRIPT] * * * * 232: class t3lib_div * * SECTION: GET/POST Variables * 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 * 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 * 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 * 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 * 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 * 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 * 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 * 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 * 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: 138 * (This index is automatically created/updated by the extension "extdeveval") * */ /** * The legendary "t3lib_div" class - Miscellaneous functions for general purpose. * Most of the functions does not relate specifically to TYPO3 * However a section of functions requires certain TYPO3 features available * See comments in the source. * You are encouraged to use this library in your own scripts! * * USE: * The class is intended to be used without creating an instance of it. * So: Don't instantiate - call functions with "t3lib_div::" prefixed the function name. * So use t3lib_div::[method-name] to refer to the functions, eg. 't3lib_div::milliseconds()' * * @author Kasper Skaarhoj * @package TYPO3 * @subpackage t3lib */ 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; // HTTP Headers, see http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html for Details const HTTP_STATUS_100 = 'HTTP/1.1 100 Continue'; const HTTP_STATUS_101 = 'HTTP/1.1 101 Switching Protocols'; const HTTP_STATUS_200 = 'HTTP/1.1 200 OK'; const HTTP_STATUS_201 = 'HTTP/1.1 201 Created'; const HTTP_STATUS_202 = 'HTTP/1.1 202 Accepted'; const HTTP_STATUS_203 = 'HTTP/1.1 203 Non-Authoritative Information'; const HTTP_STATUS_204 = 'HTTP/1.1 204 No Content'; const HTTP_STATUS_205 = 'HTTP/1.1 205 Reset Content'; const HTTP_STATUS_206 = 'HTTP/1.1 206 Partial Content'; const HTTP_STATUS_300 = 'HTTP/1.1 300 Multiple Choices'; const HTTP_STATUS_301 = 'HTTP/1.1 301 Moved Permanently'; const HTTP_STATUS_302 = 'HTTP/1.1 302 Found'; const HTTP_STATUS_303 = 'HTTP/1.1 303 See Other'; const HTTP_STATUS_304 = 'HTTP/1.1 304 Not Modified'; const HTTP_STATUS_305 = 'HTTP/1.1 305 Use Proxy'; const HTTP_STATUS_307 = 'HTTP/1.1 307 Temporary Redirect'; const HTTP_STATUS_400 = 'HTTP/1.1 400 Bad Request'; const HTTP_STATUS_401 = 'HTTP/1.1 401 Unauthorized'; const HTTP_STATUS_402 = 'HTTP/1.1 402 Payment Required'; const HTTP_STATUS_403 = 'HTTP/1.1 403 Forbidden'; const HTTP_STATUS_404 = 'HTTP/1.1 404 Not Found'; const HTTP_STATUS_405 = 'HTTP/1.1 405 Method Not Allowed'; const HTTP_STATUS_406 = 'HTTP/1.1 406 Not Acceptable'; const HTTP_STATUS_407 = 'HTTP/1.1 407 Proxy Authentication Required'; const HTTP_STATUS_408 = 'HTTP/1.1 408 Request Timeout'; const HTTP_STATUS_409 = 'HTTP/1.1 409 Conflict'; const HTTP_STATUS_410 = 'HTTP/1.1 410 Gone'; const HTTP_STATUS_411 = 'HTTP/1.1 411 Length Required'; const HTTP_STATUS_412 = 'HTTP/1.1 412 Precondition Failed'; const HTTP_STATUS_413 = 'HTTP/1.1 413 Request Entity Too Large'; const HTTP_STATUS_414 = 'HTTP/1.1 414 Request-URI Too Long'; const HTTP_STATUS_415 = 'HTTP/1.1 415 Unsupported Media Type'; const HTTP_STATUS_416 = 'HTTP/1.1 416 Requested Range Not Satisfiable'; const HTTP_STATUS_417 = 'HTTP/1.1 417 Expectation Failed'; const HTTP_STATUS_500 = 'HTTP/1.1 500 Internal Server Error'; const HTTP_STATUS_501 = 'HTTP/1.1 501 Not Implemented'; const HTTP_STATUS_502 = 'HTTP/1.1 502 Bad Gateway'; const HTTP_STATUS_503 = 'HTTP/1.1 503 Service Unavailable'; const HTTP_STATUS_504 = 'HTTP/1.1 504 Gateway Timeout'; const HTTP_STATUS_505 = 'HTTP/1.1 505 Version Not Supported'; /************************* * * GET/POST Variables * * Background: * Input GET/POST variables in PHP may have their quotes escaped with "\" or not depending on configuration. * TYPO3 has always converted quotes to BE escaped if the configuration told that they would not be so. * But the clean solution is that quotes are never escaped and that is what the functions below offers. * Eventually TYPO3 should provide this in the global space as well. * In the transitional phase (or forever..?) we need to encourage EVERY to read and write GET/POST vars through the API functions below. * *************************/ /** * Returns the 'GLOBAL' value of incoming data from POST or GET, with priority to POST (that is equalent to 'GP' order) * Strips slashes from all output, both strings and arrays. * This function substitutes t3lib_div::GPvar() * To enhancement security in your scripts, please consider using t3lib_div::_GET or t3lib_div::_POST if you already know by which method your data is arriving to the scripts! * Usage: 537 * * @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) { if(empty($var)) return; $value = isset($_POST[$var]) ? $_POST[$var] : $_GET[$var]; if (isset($value)) { if (is_array($value)) { t3lib_div::stripSlashesOnArray($value); } else { $value = stripslashes($value); } } return $value; } /** * Returns the global arrays $_GET and $_POST merged with $_POST taking precedence. * * @param string Key (variable name) from GET or POST vars * @return array Returns the GET vars merged recursively onto the POST vars. */ public static function _GPmerged($parameter) { $postParameter = is_array($_POST[$parameter]) ? $_POST[$parameter] : array(); $getParameter = is_array($_GET[$parameter]) ? $_GET[$parameter] : array(); $mergedParameters = t3lib_div::array_merge_recursive_overrule($getParameter, $postParameter); t3lib_div::stripSlashesOnArray($mergedParameters); return $mergedParameters; } /** * Returns the global $_GET array (or value from) normalized to contain un-escaped values. * ALWAYS use this API function to acquire the GET variables! * Usage: 27 * * @param string Optional pointer to value in GET array (basically name of GET var) * @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) { $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); } } return $value; } /** * Returns the global $_POST array (or value from) normalized to contain un-escaped values. * ALWAYS use this API function to acquire the $_POST variables! * Usage: 41 * * @param string Optional pointer to value in POST array (basically name of POST var) * @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) { $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); } } return $value; } /** * Writes input value to $_GET * Usage: 2 * * @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 */ 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); } $GLOBALS['HTTP_GET_VARS'][$key] = $_GET[$key] = $inputGet; } elseif (is_array($inputGet)) { t3lib_div::addSlashesOnArray($inputGet); $GLOBALS['HTTP_GET_VARS'] = $_GET = $inputGet; } } /** * Returns the value of incoming data from globals variable $_POST or $_GET, with priority to $_POST (that is equalent to 'GP' order). * Strips slashes of string-outputs, but not arrays UNLESS $strip is set. If $strip is set all output will have escaped characters unescaped. * Usage: 2 * * @param string GET/POST var to return * @param boolean If set, values are stripped of return values that are *arrays!* - string/integer values returned are always strip-slashed() * @return mixed POST var named $var and if not set, the GET var of the same name. * @deprecated since TYPO3 3.6 - Use t3lib_div::_GP instead (ALWAYS delivers a value with un-escaped values!) * @see _GP() */ public static function GPvar($var,$strip=0) { self::logDeprecatedFunction(); 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)) { t3lib_div::stripSlashesOnArray($value); } return $value; } /** * Returns the global arrays $_GET and $_POST merged with $_POST taking precedence. * Usage: 1 * * @param string Key (variable name) from GET or POST vars * @return array Returns the GET vars merged recursively onto the POST vars. * @deprecated since TYPO3 3.7 - Use t3lib_div::_GPmerged instead * @see _GP() */ public static function GParrayMerged($var) { self::logDeprecatedFunction(); return self::_GPmerged($var); } /** * 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 static function removeXSS($string) { 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 * 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 set to either 'IM' or 'GD' the compression is done with ImageMagick and GD respectively * PNG: * No changes. * * $theFile is expected to be a valid GIF-file! * 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) { $gfxConf = $GLOBALS['TYPO3_CONF_VARS']['GFX']; $returnCode=''; if ($gfxConf['gif_compress'] && strtolower(substr($theFile,-4,4))=='.gif') { // GIF... if (($type=='IM' || !$type) && $gfxConf['im'] && $gfxConf['im_path_lzw']) { // IM $cmd = t3lib_div::imageMagickCommand('convert', '"'.$theFile.'" "'.$theFile.'"', $gfxConf['im_path_lzw']); exec($cmd); $returnCode='IM'; } elseif (($type=='GD' || !$type) && $gfxConf['gdlib'] && !$gfxConf['gdlib_png']) { // GD $tempImage = imageCreateFromGif($theFile); imageGif($tempImage, $theFile); imageDestroy($tempImage); $returnCode='GD'; } } return $returnCode; } /** * Converts a png file to gif. * This converts a png file to gif IF the FLAG $GLOBALS['TYPO3_CONF_VARS']['FE']['png_to_gif'] is set true. * Usage: 5 * * @param string $theFile the filename with path * @return string new filename */ 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.'"', $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!! } return $theFile; } /** * Returns filename of the png/gif version of the input file (which can be png or gif). * If input file type does not match the wanted output type a conversion is made and temp-filename returned. * Usage: 2 * * @param string Filepath of image file * @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) { if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['im'] && @is_file($theFile)) { $ext = strtolower(substr($theFile,-4,4)); if ( ((string)$ext=='.png' && $output_png) || ((string)$ext=='.gif' && !$output_png) ) { return $theFile; } else { $newFile = PATH_site.'typo3temp/readPG_'.md5($theFile.'|'.filemtime($theFile)).($output_png?'.png':'.gif'); $cmd = t3lib_div::imageMagickCommand('convert', '"'.$theFile.'" "'.$newFile.'"', $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_path']); exec($cmd); if (@is_file($newFile)) return $newFile; } } } /************************* * * STRING FUNCTIONS * *************************/ /** * Truncates string. * Returns a new string of max. $chars length. * If the string is longer, it will be truncated and appended with '...'. * Usage: 39 * * @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 since TYPO3 4.1 - 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='...') { self::logDeprecatedFunction(); $chars = abs($origChars); if ($chars >= 4) { if(strlen($string)>$chars) { return $origChars < 0 ? $preStr.trim(substr($string, -($chars-3))) : trim(substr($string, 0, $chars-3)).$preStr; } } return $string; } /** * Truncates string. * 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 * Usage: 6 * * @param string string to truncate * @param integer must be an integer of at least 4 * @return string new string * @deprecated since TYPO3 4.1 - Use either fixed_lgd() or fixed_lgd_cs() (with negative input value for $chars) * @see fixed_lgd() */ public static function fixed_lgd_pre($string,$chars) { self::logDeprecatedFunction(); return strrev(t3lib_div::fixed_lgd(strrev($string),$chars)); } /** * Truncates a string with appended/prepended "..." and takes current character set into consideration. * Usage: 75 * * @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 appendix to the truncated string * @return string cropped string */ 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'])) { return $GLOBALS['TSFE']->csConvObj->crop($GLOBALS['TSFE']->renderCharset, $string, $chars, $appendString); } else { // this case should not happen $csConvObj = t3lib_div::makeInstance('t3lib_cs'); return $csConvObj->crop('iso-8859-1', $string, $chars, $appendString); } } /** * Breaks up the text for emails * Usage: 1 * * @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 since TYPO3 4.1 - Use PHP function wordwrap() * @return string */ public static function breakTextForEmail($str,$implChar="\n",$charWidth=76) { self::logDeprecatedFunction(); $lines = explode(chr(10),$str); $outArr=array(); foreach ($lines as $lStr) { $outArr[] = t3lib_div::breakLinesForEmail($lStr,$implChar,$charWidth); } return implode(chr(10),$outArr); } /** * Breaks up a single line of text for emails * Usage: 5 * * @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 * @return string * @see breakTextForEmail() */ public static function breakLinesForEmail($str,$implChar="\n",$charWidth=76) { $lines=array(); $l=$charWidth; $p=0; while(strlen($str)>$p) { $substr=substr($str,$p,$l); if (strlen($substr)==$l) { $count = count(explode(' ',trim(strrev($substr)))); if ($count>1) { // OK... $parts = explode(' ',strrev($substr),2); $theLine = strrev($parts[1]); } else { $afterParts = explode(' ',substr($str,$l+$p),2); $theLine = $substr.$afterParts[0]; } if (!strlen($theLine)) {break; } // Error, because this would keep us in an endless loop. } else { $theLine=$substr; } $lines[]=trim($theLine); $p+=strlen($theLine); if (!trim(substr($str,$p,$l))) break; // added... } return implode($implChar,$lines); } /** * 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 */ public static function cmpIPv4($baseIP, $list) { $IPpartsReq = explode('.',$baseIP); if (count($IPpartsReq)==4) { $values = t3lib_div::trimExplode(',',$list,1); foreach($values as $test) { list($test,$mask) = explode('/',$test); 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); $binip = str_pad( decbin($lip),32,'0','STR_PAD_LEFT'); $firstip = substr($binip,0,$mask); $yes = (strcmp($firstpart,$firstip)==0); } else { // "192.168.*.*" $IPparts = explode('.',$test); $yes = 1; foreach ($IPparts as $index => $val) { $val = trim($val); if (strcmp($val,'*') && strcmp($IPpartsReq[$index],$val)) { $yes=0; } } } if ($yes) return true; } } 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