00001 <?php 00002 /*************************************************************** 00003 * Copyright notice 00004 * 00005 * (c) 1999-2008 Kasper Skaarhoj (kasperYYYY@typo3.com) 00006 * All rights reserved 00007 * 00008 * This script is part of the TYPO3 project. The TYPO3 project is 00009 * free software; you can redistribute it and/or modify 00010 * it under the terms of the GNU General Public License as published by 00011 * the Free Software Foundation; either version 2 of the License, or 00012 * (at your option) any later version. 00013 * 00014 * The GNU General Public License can be found at 00015 * http://www.gnu.org/copyleft/gpl.html. 00016 * A copy is found in the textfile GPL.txt and important notices to the license 00017 * from the author is found in LICENSE.txt distributed with these scripts. 00018 * 00019 * 00020 * This script is distributed in the hope that it will be useful, 00021 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00022 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00023 * GNU General Public License for more details. 00024 * 00025 * This copyright notice MUST APPEAR in all copies of the script! 00026 ***************************************************************/ 00027 /** 00028 * Contains the reknown class "t3lib_div" with general purpose functions 00029 * 00030 * $Id: class.t3lib_div.php 4640 2009-01-02 17:47:30Z steffenk $ 00031 * Revised for TYPO3 3.6 July/2003 by Kasper Skaarhoj 00032 * XHTML compliant 00033 * Usage counts are based on search 22/2 2003 through whole source including tslib/ 00034 * 00035 * @author Kasper Skaarhoj <kasperYYYY@typo3.com> 00036 */ 00037 /** 00038 * [CLASS/FUNCTION INDEX of SCRIPT] 00039 * 00040 * 00041 * 00042 * 232: class t3lib_div 00043 * 00044 * SECTION: GET/POST Variables 00045 * 262: function _GP($var) 00046 * 280: function _GET($var=NULL) 00047 * 297: function _POST($var=NULL) 00048 * 313: function _GETset($inputGet,$key='') 00049 * 336: function GPvar($var,$strip=0) 00050 * 353: function GParrayMerged($var) 00051 * 00052 * SECTION: IMAGE FUNCTIONS 00053 * 397: function gif_compress($theFile, $type) 00054 * 425: function png_to_gif_by_imagemagick($theFile) 00055 * 450: function read_png_gif($theFile,$output_png=0) 00056 * 00057 * SECTION: STRING FUNCTIONS 00058 * 499: function fixed_lgd($string,$origChars,$preStr='...') 00059 * 524: function fixed_lgd_pre($string,$chars) 00060 * 538: function fixed_lgd_cs($string,$chars) 00061 * 555: function breakTextForEmail($str,$implChar="\n",$charWidth=76) 00062 * 574: function breakLinesForEmail($str,$implChar="\n",$charWidth=76) 00063 * 610: function cmpIP($baseIP, $list) 00064 * 626: function cmpIPv4($baseIP, $list) 00065 * 668: function cmpIPv6($baseIP, $list) 00066 * 711: function IPv6Hex2Bin ($hex) 00067 * 726: function normalizeIPv6($address) 00068 * 782: function validIPv6($ip) 00069 * 805: function cmpFQDN($baseIP, $list) 00070 * 835: function inList($list,$item) 00071 * 847: function rmFromList($element,$list) 00072 * 863: function expandList($list) 00073 * 894: function intInRange($theInt,$min,$max=2000000000,$zeroValue=0) 00074 * 910: function intval_positive($theInt) 00075 * 923: function int_from_ver($verNumberStr) 00076 * 934: function compat_version($verNumberStr) 00077 * 952: function md5int($str) 00078 * 965: function shortMD5($input, $len=10) 00079 * 978: function uniqueList($in_list, $secondParameter=NULL) 00080 * 992: function split_fileref($fileref) 00081 * 1030: function dirname($path) 00082 * 1046: function modifyHTMLColor($color,$R,$G,$B) 00083 * 1066: function modifyHTMLColorAll($color,$all) 00084 * 1077: function rm_endcomma($string) 00085 * 1090: function danish_strtoupper($string) 00086 * 1105: function convUmlauts($str) 00087 * 1118: function testInt($var) 00088 * 1130: function isFirstPartOfStr($str,$partStr) 00089 * 1146: function formatSize($sizeInBytes,$labels='') 00090 * 1181: function convertMicrotime($microtime) 00091 * 1195: function splitCalc($string,$operators) 00092 * 1217: function calcPriority($string) 00093 * 1258: function calcParenthesis($string) 00094 * 1284: function htmlspecialchars_decode($value) 00095 * 1299: function deHSCentities($str) 00096 * 1312: function slashJS($string,$extended=0,$char="'") 00097 * 1325: function rawUrlEncodeJS($str) 00098 * 1337: function rawUrlEncodeFP($str) 00099 * 1348: function validEmail($email) 00100 * 1363: function formatForTextarea($content) 00101 * 00102 * SECTION: ARRAY FUNCTIONS 00103 * 1394: function inArray($in_array,$item) 00104 * 1411: function intExplode($delim, $string) 00105 * 1430: function revExplode($delim, $string, $count=0) 00106 * 1450: function trimExplode($delim, $string, $onlyNonEmptyValues=0) 00107 * 1472: function uniqueArray($valueArray) 00108 * 1484: function removeArrayEntryByValue($array,$cmpValue) 00109 * 1513: function implodeArrayForUrl($name,$theArray,$str='',$skipBlank=0,$rawurlencodeParamName=0) 00110 * 1538: function explodeUrl2Array($string,$multidim=FALSE) 00111 * 1564: function compileSelectedGetVarsFromArray($varList,$getArray,$GPvarAlt=1) 00112 * 1587: function addSlashesOnArray(&$theArray) 00113 * 1611: function stripSlashesOnArray(&$theArray) 00114 * 1633: function slashArray($arr,$cmd) 00115 * 1650: function array_merge_recursive_overrule($arr0,$arr1,$notAddKeys=0,$includeEmtpyValues=true) 00116 * 1683: function array_merge($arr1,$arr2) 00117 * 1696: function csvValues($row,$delim=',',$quote='"') 00118 * 00119 * SECTION: HTML/XML PROCESSING 00120 * 1738: function get_tag_attributes($tag) 00121 * 1775: function split_tag_attributes($tag) 00122 * 1809: function implodeAttributes($arr,$xhtmlSafe=FALSE,$dontOmitBlankAttribs=FALSE) 00123 * 1836: function implodeParams($arr,$xhtmlSafe=FALSE,$dontOmitBlankAttribs=FALSE) 00124 * 1851: function wrapJS($string, $linebreak=TRUE) 00125 * 1882: function xml2tree($string,$depth=999) 00126 * 1969: function array2xml($array,$NSprefix='',$level=0,$docTag='phparray',$spaceInd=0, $options=array(),$stackData=array()) 00127 * 2088: function xml2array($string,$NSprefix='',$reportDocTag=FALSE) 00128 * 2198: function xmlRecompileFromStructValArray($vals) 00129 * 2242: function xmlGetHeaderAttribs($xmlData) 00130 * 00131 * SECTION: FILES FUNCTIONS 00132 * 2275: function getURL($url, $includeHeader=0) 00133 * 2342: function writeFile($file,$content) 00134 * 2367: function fixPermissions($file) 00135 * 2384: function writeFileToTypo3tempDir($filepath,$content) 00136 * 2427: function mkdir($theNewFolder) 00137 * 2446: function mkdir_deep($destination,$deepDir) 00138 * 2468: function get_dirs($path) 00139 * 2493: function getFilesInDir($path,$extensionList='',$prependPath=0,$order='') 00140 * 2547: function getAllFilesAndFoldersInPath($fileArr,$path,$extList='',$regDirs=0,$recursivityLevels=99) 00141 * 2570: function removePrefixPathFromList($fileArr,$prefixToRemove) 00142 * 2586: function fixWindowsFilePath($theFile) 00143 * 2598: function resolveBackPath($pathStr) 00144 * 2626: function locationHeaderUrl($path) 00145 * 00146 * SECTION: DEBUG helper FUNCTIONS 00147 * 2666: function debug_ordvalue($string,$characters=100) 00148 * 2683: function view_array($array_in) 00149 * 2711: function print_array($array_in) 00150 * 2726: function debug($var="",$brOrHeader=0) 00151 * 2757: function debug_trail() 00152 * 2779: function debugRows($rows,$header='') 00153 * 00154 * SECTION: SYSTEM INFORMATION 00155 * 2857: function getThisUrl() 00156 * 2873: function linkThisScript($getParams=array()) 00157 * 2897: function linkThisUrl($url,$getParams=array()) 00158 * 2920: function getIndpEnv($getEnvName) 00159 * 3113: function milliseconds() 00160 * 3125: function clientInfo($useragent='') 00161 * 00162 * SECTION: TYPO3 SPECIFIC FUNCTIONS 00163 * 3212: function getFileAbsFileName($filename,$onlyRelative=1,$relToTYPO3_mainDir=0) 00164 * 3248: function validPathStr($theFile) 00165 * 3259: function isAbsPath($path) 00166 * 3270: function isAllowedAbsPath($path) 00167 * 3287: function verifyFilenameAgainstDenyPattern($filename) 00168 * 3305: function upload_copy_move($source,$destination) 00169 * 3331: function upload_to_tempfile($uploadedFileName) 00170 * 3349: function unlink_tempfile($uploadedTempFileName) 00171 * 3365: function tempnam($filePrefix) 00172 * 3379: function stdAuthCode($uid_or_record,$fields='',$codeLength=8) 00173 * 3410: function cHashParams($addQueryParams) 00174 * 3433: function hideIfNotTranslated($l18n_cfg_fieldValue) 00175 * 3448: function readLLfile($fileRef,$langKey) 00176 * 3472: function readLLXMLfile($fileRef,$langKey) 00177 * 3589: function llXmlAutoFileName($fileRef,$language) 00178 * 3633: function loadTCA($table) 00179 * 3653: function resolveSheetDefInDS($dataStructArray,$sheet='sDEF') 00180 * 3686: function resolveAllSheetsInDS($dataStructArray) 00181 * 3715: function callUserFunction($funcName,&$params,&$ref,$checkPrefix='user_',$silent=0) 00182 * 3813: function &getUserObj($classRef,$checkPrefix='user_',$silent=0) 00183 * 3871: function &makeInstance($className) 00184 * 3883: function makeInstanceClassName($className) 00185 * 3897: function &makeInstanceService($serviceType, $serviceSubType='', $excludeServiceKeys=array()) 00186 * 3961: function plainMailEncoded($email,$subject,$message,$headers='',$enc='',$charset='',$dontEncodeHeader=false) 00187 * 4031: function quoted_printable($string,$maxlen=76) 00188 * 4078: function encodeHeader($line,$enc='',$charset='ISO-8859-1') 00189 * 4121: function substUrlsInPlainText($message,$urlmode='76',$index_script_url='') 00190 * 4155: function makeRedirectUrl($inUrl,$l=0,$index_script_url='') 00191 * 4182: function freetypeDpiComp($font_size) 00192 * 4194: function initSysLog() 00193 * 4251: function sysLog($msg, $extKey, $severity=0) 00194 * 4334: function devLog($msg, $extKey, $severity=0, $dataVar=FALSE) 00195 * 4355: function arrayToLogString($arr, $valueList=array(), $valueLength=20) 00196 * 4378: function imageMagickCommand($command, $parameters, $path='') 00197 * 4425: function unQuoteFilenames($parameters,$unQuote=FALSE) 00198 * 4459: function quoteJSvalue($value, $inScriptTags = false) 00199 * 00200 * TOTAL FUNCTIONS: 138 00201 * (This index is automatically created/updated by the extension "extdeveval") 00202 * 00203 */ 00204 00205 00206 00207 00208 00209 00210 00211 00212 00213 00214 00215 00216 /** 00217 * The legendary "t3lib_div" class - Miscellaneous functions for general purpose. 00218 * Most of the functions does not relate specifically to TYPO3 00219 * However a section of functions requires certain TYPO3 features available 00220 * See comments in the source. 00221 * You are encouraged to use this library in your own scripts! 00222 * 00223 * USE: 00224 * The class is intended to be used without creating an instance of it. 00225 * So: Don't instantiate - call functions with "t3lib_div::" prefixed the function name. 00226 * So use t3lib_div::[method-name] to refer to the functions, eg. 't3lib_div::milliseconds()' 00227 * 00228 * @author Kasper Skaarhoj <kasperYYYY@typo3.com> 00229 * @package TYPO3 00230 * @subpackage t3lib 00231 */ 00232 final class t3lib_div { 00233 00234 // Severity constants used by t3lib_div::sysLog() 00235 const SYSLOG_SEVERITY_INFO = 0; 00236 const SYSLOG_SEVERITY_NOTICE = 1; 00237 const SYSLOG_SEVERITY_WARNING = 2; 00238 const SYSLOG_SEVERITY_ERROR = 3; 00239 const SYSLOG_SEVERITY_FATAL = 4; 00240 00241 // HTTP Headers, see http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html for Details 00242 const HTTP_STATUS_100 = 'HTTP/1.1 100 Continue'; 00243 const HTTP_STATUS_101 = 'HTTP/1.1 101 Switching Protocols'; 00244 00245 const HTTP_STATUS_200 = 'HTTP/1.1 200 OK'; 00246 const HTTP_STATUS_201 = 'HTTP/1.1 201 Created'; 00247 const HTTP_STATUS_202 = 'HTTP/1.1 202 Accepted'; 00248 const HTTP_STATUS_203 = 'HTTP/1.1 203 Non-Authoritative Information'; 00249 const HTTP_STATUS_204 = 'HTTP/1.1 204 No Content'; 00250 const HTTP_STATUS_205 = 'HTTP/1.1 205 Reset Content'; 00251 const HTTP_STATUS_206 = 'HTTP/1.1 206 Partial Content'; 00252 00253 const HTTP_STATUS_300 = 'HTTP/1.1 300 Multiple Choices'; 00254 const HTTP_STATUS_301 = 'HTTP/1.1 301 Moved Permanently'; 00255 const HTTP_STATUS_302 = 'HTTP/1.1 302 Found'; 00256 const HTTP_STATUS_303 = 'HTTP/1.1 303 See Other'; 00257 const HTTP_STATUS_304 = 'HTTP/1.1 304 Not Modified'; 00258 const HTTP_STATUS_305 = 'HTTP/1.1 305 Use Proxy'; 00259 const HTTP_STATUS_307 = 'HTTP/1.1 307 Temporary Redirect'; 00260 00261 const HTTP_STATUS_400 = 'HTTP/1.1 400 Bad Request'; 00262 const HTTP_STATUS_401 = 'HTTP/1.1 401 Unauthorized'; 00263 const HTTP_STATUS_402 = 'HTTP/1.1 402 Payment Required'; 00264 const HTTP_STATUS_403 = 'HTTP/1.1 403 Forbidden'; 00265 const HTTP_STATUS_404 = 'HTTP/1.1 404 Not Found'; 00266 const HTTP_STATUS_405 = 'HTTP/1.1 405 Method Not Allowed'; 00267 const HTTP_STATUS_406 = 'HTTP/1.1 406 Not Acceptable'; 00268 const HTTP_STATUS_407 = 'HTTP/1.1 407 Proxy Authentication Required'; 00269 const HTTP_STATUS_408 = 'HTTP/1.1 408 Request Timeout'; 00270 const HTTP_STATUS_409 = 'HTTP/1.1 409 Conflict'; 00271 const HTTP_STATUS_410 = 'HTTP/1.1 410 Gone'; 00272 const HTTP_STATUS_411 = 'HTTP/1.1 411 Length Required'; 00273 const HTTP_STATUS_412 = 'HTTP/1.1 412 Precondition Failed'; 00274 const HTTP_STATUS_413 = 'HTTP/1.1 413 Request Entity Too Large'; 00275 const HTTP_STATUS_414 = 'HTTP/1.1 414 Request-URI Too Long'; 00276 const HTTP_STATUS_415 = 'HTTP/1.1 415 Unsupported Media Type'; 00277 const HTTP_STATUS_416 = 'HTTP/1.1 416 Requested Range Not Satisfiable'; 00278 const HTTP_STATUS_417 = 'HTTP/1.1 417 Expectation Failed'; 00279 00280 const HTTP_STATUS_500 = 'HTTP/1.1 500 Internal Server Error'; 00281 const HTTP_STATUS_501 = 'HTTP/1.1 501 Not Implemented'; 00282 const HTTP_STATUS_502 = 'HTTP/1.1 502 Bad Gateway'; 00283 const HTTP_STATUS_503 = 'HTTP/1.1 503 Service Unavailable'; 00284 const HTTP_STATUS_504 = 'HTTP/1.1 504 Gateway Timeout'; 00285 const HTTP_STATUS_505 = 'HTTP/1.1 505 Version Not Supported'; 00286 00287 00288 00289 /************************* 00290 * 00291 * GET/POST Variables 00292 * 00293 * Background: 00294 * Input GET/POST variables in PHP may have their quotes escaped with "\" or not depending on configuration. 00295 * TYPO3 has always converted quotes to BE escaped if the configuration told that they would not be so. 00296 * But the clean solution is that quotes are never escaped and that is what the functions below offers. 00297 * Eventually TYPO3 should provide this in the global space as well. 00298 * In the transitional phase (or forever..?) we need to encourage EVERY to read and write GET/POST vars through the API functions below. 00299 * 00300 *************************/ 00301 00302 /** 00303 * Returns the 'GLOBAL' value of incoming data from POST or GET, with priority to POST (that is equalent to 'GP' order) 00304 * Strips slashes from all output, both strings and arrays. 00305 * This function substitutes t3lib_div::GPvar() 00306 * 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! 00307 * Usage: 537 00308 * 00309 * @param string GET/POST var to return 00310 * @return mixed POST var named $var and if not set, the GET var of the same name. 00311 * @see GPvar() 00312 */ 00313 public static function _GP($var) { 00314 if(empty($var)) return; 00315 $value = isset($_POST[$var]) ? $_POST[$var] : $_GET[$var]; 00316 if (isset($value)) { 00317 if (is_array($value)) { t3lib_div::stripSlashesOnArray($value); } else { $value = stripslashes($value); } 00318 } 00319 return $value; 00320 } 00321 00322 /** 00323 * Returns the global GET array (or value from) normalized to contain un-escaped values. 00324 * ALWAYS use this API function to acquire the GET variables! 00325 * Usage: 27 00326 * 00327 * @param string Optional pointer to value in GET array (basically name of GET var) 00328 * @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!* 00329 * @see _POST(), _GP(), _GETset() 00330 */ 00331 public static function _GET($var=NULL) { 00332 $value = ($var === NULL) ? $_GET : (empty($var) ? NULL : $_GET[$var]); 00333 if (isset($value)) { // Removes slashes since TYPO3 has added them regardless of magic_quotes setting. 00334 if (is_array($value)) { t3lib_div::stripSlashesOnArray($value); } else { $value = stripslashes($value); } 00335 } 00336 return $value; 00337 } 00338 00339 /** 00340 * Returns the global POST array (or value from) normalized to contain un-escaped values. 00341 * ALWAYS use this API function to acquire the POST variables! 00342 * Usage: 41 00343 * 00344 * @param string Optional pointer to value in POST array (basically name of POST var) 00345 * @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!* 00346 * @see _GET(), _GP() 00347 */ 00348 public static function _POST($var=NULL) { 00349 $value = ($var === NULL) ? $_POST : (empty($var) ? NULL : $_POST[$var]); 00350 if (isset($value)) { // Removes slashes since TYPO3 has added them regardless of magic_quotes setting. 00351 if (is_array($value)) { t3lib_div::stripSlashesOnArray($value); } else { $value = stripslashes($value); } 00352 } 00353 return $value; 00354 } 00355 00356 /** 00357 * Writes input value to $_GET 00358 * Usage: 2 00359 * 00360 * @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). 00361 * @param string Alternative key; If set, this will not set the WHOLE GET array, but only the key in it specified by this value! 00362 * @return void 00363 */ 00364 public static function _GETset($inputGet,$key='') { 00365 // ADDS slashes since TYPO3 standard currently is that slashes MUST be applied (regardless of magic_quotes setting). 00366 if (strcmp($key,'')) { 00367 if (is_array($inputGet)) { 00368 t3lib_div::addSlashesOnArray($inputGet); 00369 } else { 00370 $inputGet = addslashes($inputGet); 00371 } 00372 $GLOBALS['HTTP_GET_VARS'][$key] = $_GET[$key] = $inputGet; 00373 } elseif (is_array($inputGet)) { 00374 t3lib_div::addSlashesOnArray($inputGet); 00375 $GLOBALS['HTTP_GET_VARS'] = $_GET = $inputGet; 00376 } 00377 } 00378 00379 /** 00380 * GET/POST variable 00381 * Returns the 'GLOBAL' value of incoming data from POST or GET, with priority to POST (that is equalent to 'GP' order) 00382 * Strips slashes of string-outputs, but not arrays UNLESS $strip is set. If $strip is set all output will have escaped characters unescaped. 00383 * Usage: 2 00384 * 00385 * @param string GET/POST var to return 00386 * @param boolean If set, values are stripped of return values that are *arrays!* - string/integer values returned are always strip-slashed() 00387 * @return mixed POST var named $var and if not set, the GET var of the same name. 00388 * @deprecated since TYPO3 3.7 - Use t3lib_div::_GP instead (ALWAYS delivers a value with un-escaped values!) 00389 * @see _GP() 00390 */ 00391 public static function GPvar($var,$strip=0) { 00392 if(empty($var)) return; 00393 $value = isset($_POST[$var]) ? $_POST[$var] : $_GET[$var]; 00394 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. 00395 if ($strip && isset($value) && is_array($value)) { t3lib_div::stripSlashesOnArray($value); } 00396 return $value; 00397 } 00398 00399 /** 00400 * Returns the GET/POST global arrays merged with POST taking precedence. 00401 * Usage: 1 00402 * 00403 * @param string Key (variable name) from GET or POST vars 00404 * @return array Returns the GET vars merged recursively onto the POST vars. 00405 */ 00406 public static function GParrayMerged($var) { 00407 $postA = is_array($_POST[$var]) ? $_POST[$var] : array(); 00408 $getA = is_array($_GET[$var]) ? $_GET[$var] : array(); 00409 $mergedA = t3lib_div::array_merge_recursive_overrule($getA,$postA); 00410 t3lib_div::stripSlashesOnArray($mergedA); 00411 return $mergedA; 00412 } 00413 00414 /** 00415 * Wrapper for the RemoveXSS function. 00416 * Removes potential XSS code from an input string. 00417 * 00418 * Using an external class by Travis Puderbaugh <kallahar@quickwired.com> 00419 * 00420 * @param string Input string 00421 * @return string Input string with potential XSS code removed 00422 */ 00423 public static function removeXSS($string) { 00424 require_once(PATH_typo3.'contrib/RemoveXSS/RemoveXSS.php'); 00425 $string = RemoveXSS::RemoveXSS($string); 00426 return $string; 00427 } 00428 00429 00430 00431 00432 00433 00434 00435 00436 00437 00438 /************************* 00439 * 00440 * IMAGE FUNCTIONS 00441 * 00442 *************************/ 00443 00444 00445 /** 00446 * Compressing a GIF file if not already LZW compressed 00447 * 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) 00448 * 00449 * The function takes a file-reference, $theFile, and saves it again through GD or ImageMagick in order to compress the file 00450 * GIF: 00451 * 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!) 00452 * If $type is set to either 'IM' or 'GD' the compression is done with ImageMagick and GD respectively 00453 * PNG: 00454 * No changes. 00455 * 00456 * $theFile is expected to be a valid GIF-file! 00457 * The function returns a code for the operation. 00458 * Usage: 9 00459 * 00460 * @param string Filepath 00461 * @param string See description of function 00462 * @return string Returns "GD" if GD was used, otherwise "IM" if ImageMagick was used. If nothing done at all, it returns empty string. 00463 */ 00464 public static function gif_compress($theFile, $type) { 00465 $gfxConf = $GLOBALS['TYPO3_CONF_VARS']['GFX']; 00466 $returnCode=''; 00467 if ($gfxConf['gif_compress'] && strtolower(substr($theFile,-4,4))=='.gif') { // GIF... 00468 if (($type=='IM' || !$type) && $gfxConf['im'] && $gfxConf['im_path_lzw']) { // IM 00469 $cmd = t3lib_div::imageMagickCommand('convert', '"'.$theFile.'" "'.$theFile.'"', $gfxConf['im_path_lzw']); 00470 exec($cmd); 00471 00472 $returnCode='IM'; 00473 } elseif (($type=='GD' || !$type) && $gfxConf['gdlib'] && !$gfxConf['gdlib_png']) { // GD 00474 $tempImage = imageCreateFromGif($theFile); 00475 imageGif($tempImage, $theFile); 00476 imageDestroy($tempImage); 00477 $returnCode='GD'; 00478 } 00479 } 00480 return $returnCode; 00481 } 00482 00483 /** 00484 * Converts a png file to gif 00485 * This converts a png file to gif IF the FLAG $GLOBALS['TYPO3_CONF_VARS']['FE']['png_to_gif'] is set true. 00486 * Usage: 5 00487 * 00488 * @param string $theFile the filename with path 00489 * @return string new filename 00490 */ 00491 public static function png_to_gif_by_imagemagick($theFile) { 00492 if ($GLOBALS['TYPO3_CONF_VARS']['FE']['png_to_gif'] 00493 && $GLOBALS['TYPO3_CONF_VARS']['GFX']['im'] 00494 && $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_path_lzw'] 00495 && strtolower(substr($theFile,-4,4))=='.png' 00496 && @is_file($theFile)) { // IM 00497 $newFile = substr($theFile,0,-4).'.gif'; 00498 $cmd = t3lib_div::imageMagickCommand('convert', '"'.$theFile.'" "'.$newFile.'"', $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_path_lzw']); 00499 exec($cmd); 00500 $theFile = $newFile; 00501 // 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!! 00502 } 00503 return $theFile; 00504 } 00505 00506 /** 00507 * Returns filename of the png/gif version of the input file (which can be png or gif). 00508 * If input file type does not match the wanted output type a conversion is made and temp-filename returned. 00509 * Usage: 2 00510 * 00511 * @param string Filepath of image file 00512 * @param boolean If set, then input file is converted to PNG, otherwise to GIF 00513 * @return string If the new image file exists, it's filepath is returned 00514 */ 00515 public static function read_png_gif($theFile,$output_png=0) { 00516 if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['im'] && @is_file($theFile)) { 00517 $ext = strtolower(substr($theFile,-4,4)); 00518 if ( 00519 ((string)$ext=='.png' && $output_png) || 00520 ((string)$ext=='.gif' && !$output_png) 00521 ) { 00522 return $theFile; 00523 } else { 00524 $newFile = PATH_site.'typo3temp/readPG_'.md5($theFile.'|'.filemtime($theFile)).($output_png?'.png':'.gif'); 00525 $cmd = t3lib_div::imageMagickCommand('convert', '"'.$theFile.'" "'.$newFile.'"', $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_path']); 00526 exec($cmd); 00527 if (@is_file($newFile)) return $newFile; 00528 } 00529 } 00530 } 00531 00532 00533 00534 00535 00536 00537 00538 00539 00540 00541 00542 00543 00544 00545 00546 /************************* 00547 * 00548 * STRING FUNCTIONS 00549 * 00550 *************************/ 00551 00552 /** 00553 * Truncate string 00554 * Returns a new string of max. $chars length. 00555 * If the string is longer, it will be truncated and appended with '...'. 00556 * Usage: 39 00557 * 00558 * @param string string to truncate 00559 * @param integer must be an integer with an absolute value of at least 4. if negative the string is cropped from the right end. 00560 * @param string String to append to the output if it is truncated, default is '...' 00561 * @return string new string 00562 * @deprecated since TYPO3 4.1 - Works ONLY for single-byte charsets! USE t3lib_div::fixed_lgd_cs() instead 00563 * @see fixed_lgd_pre() 00564 */ 00565 public static function fixed_lgd($string,$origChars,$preStr='...') { 00566 $chars = abs($origChars); 00567 if ($chars >= 4) { 00568 if(strlen($string)>$chars) { 00569 return $origChars < 0 ? 00570 $preStr.trim(substr($string, -($chars-3))) : 00571 trim(substr($string, 0, $chars-3)).$preStr; 00572 } 00573 } 00574 return $string; 00575 } 00576 00577 /** 00578 * Truncate string 00579 * Returns a new string of max. $chars length. 00580 * If the string is longer, it will be truncated and prepended with '...'. 00581 * This works like fixed_lgd, but is truncated in the start of the string instead of the end 00582 * Usage: 6 00583 * 00584 * @param string string to truncate 00585 * @param integer must be an integer of at least 4 00586 * @return string new string 00587 * @deprecated since TYPO3 4.1 - Use either fixed_lgd() or fixed_lgd_cs() (with negative input value for $chars) 00588 * @see fixed_lgd() 00589 */ 00590 public static function fixed_lgd_pre($string,$chars) { 00591 return strrev(t3lib_div::fixed_lgd(strrev($string),$chars)); 00592 } 00593 00594 /** 00595 * Truncates a string with appended/prepended "..." and takes backend character set into consideration 00596 * Use only from backend! 00597 * Usage: 75 00598 * 00599 * @param string string to truncate 00600 * @param integer must be an integer with an absolute value of at least 4. if negative the string is cropped from the right end. 00601 * @return string New string 00602 * @see fixed_lgd() 00603 */ 00604 public static function fixed_lgd_cs($string,$chars) { 00605 if (is_object($GLOBALS['LANG'])) { 00606 return $GLOBALS['LANG']->csConvObj->crop($GLOBALS['LANG']->charSet,$string,$chars,'...'); 00607 } else { 00608 return t3lib_div::fixed_lgd($string, $chars); 00609 } 00610 } 00611 00612 /** 00613 * Breaks up the text for emails 00614 * Usage: 1 00615 * 00616 * @param string The string to break up 00617 * @param string The string to implode the broken lines with (default/typically \n) 00618 * @param integer The line length 00619 * @deprecated since TYPO3 4.1 - Use PHP function wordwrap() 00620 * @return string 00621 */ 00622 public static function breakTextForEmail($str,$implChar="\n",$charWidth=76) { 00623 $lines = explode(chr(10),$str); 00624 $outArr=array(); 00625 foreach ($lines as $lStr) { 00626 $outArr[] = t3lib_div::breakLinesForEmail($lStr,$implChar,$charWidth); 00627 } 00628 return implode(chr(10),$outArr); 00629 } 00630 00631 /** 00632 * Breaks up a single line of text for emails 00633 * Usage: 5 00634 * 00635 * @param string The string to break up 00636 * @param string The string to implode the broken lines with (default/typically \n) 00637 * @param integer The line length 00638 * @return string 00639 * @see breakTextForEmail() 00640 */ 00641 public static function breakLinesForEmail($str,$implChar="\n",$charWidth=76) { 00642 $lines=array(); 00643 $l=$charWidth; 00644 $p=0; 00645 while(strlen($str)>$p) { 00646 $substr=substr($str,$p,$l); 00647 if (strlen($substr)==$l) { 00648 $count = count(explode(' ',trim(strrev($substr)))); 00649 if ($count>1) { // OK... 00650 $parts = explode(' ',strrev($substr),2); 00651 $theLine = strrev($parts[1]); 00652 } else { 00653 $afterParts = explode(' ',substr($str,$l+$p),2); 00654 $theLine = $substr.$afterParts[0]; 00655 } 00656 if (!strlen($theLine)) {break; } // Error, because this would keep us in an endless loop. 00657 } else { 00658 $theLine=$substr; 00659 } 00660 00661 $lines[]=trim($theLine); 00662 $p+=strlen($theLine); 00663 if (!trim(substr($str,$p,$l))) break; // added... 00664 } 00665 return implode($implChar,$lines); 00666 } 00667 00668 /** 00669 * Match IP number with list of numbers with wildcard 00670 * Dispatcher method for switching into specialised IPv4 and IPv6 methods. 00671 * Usage: 10 00672 * 00673 * @param string $baseIP is the current remote IP address for instance, typ. REMOTE_ADDR 00674 * @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. 00675 * @return boolean True if an IP-mask from $list matches $baseIP 00676 */ 00677 public static function cmpIP($baseIP, $list) { 00678 $list = trim($list); 00679 if ($list === '') { 00680 return false; 00681 } elseif ($list === '*') { 00682 return true; 00683 } 00684 if (strpos($baseIP, ':') !== false && t3lib_div::validIPv6($baseIP)) { 00685 return t3lib_div::cmpIPv6($baseIP, $list); 00686 } else { 00687 return t3lib_div::cmpIPv4($baseIP, $list); 00688 } 00689 } 00690 00691 /** 00692 * Match IPv4 number with list of numbers with wildcard 00693 * 00694 * @param string $baseIP is the current remote IP address for instance, typ. REMOTE_ADDR 00695 * @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) 00696 * @return boolean True if an IP-mask from $list matches $baseIP 00697 */ 00698 public static function cmpIPv4($baseIP, $list) { 00699 $IPpartsReq = explode('.',$baseIP); 00700 if (count($IPpartsReq)==4) { 00701 $values = t3lib_div::trimExplode(',',$list,1); 00702 00703 foreach($values as $test) { 00704 list($test,$mask) = explode('/',$test); 00705 00706 if(intval($mask)) { 00707 // "192.168.3.0/24" 00708 $lnet = ip2long($test); 00709 $lip = ip2long($baseIP); 00710 $binnet = str_pad( decbin($lnet),32,'0','STR_PAD_LEFT'); 00711 $firstpart = substr($binnet,0,$mask); 00712 $binip = str_pad( decbin($lip),32,'0','STR_PAD_LEFT'); 00713 $firstip = substr($binip,0,$mask); 00714 $yes = (strcmp($firstpart,$firstip)==0); 00715 } else { 00716 // "192.168.*.*" 00717 $IPparts = explode('.',$test); 00718 $yes = 1; 00719 foreach ($IPparts as $index => $val) { 00720 $val = trim($val); 00721 if (strcmp($val,'*') && strcmp($IPpartsReq[$index],$val)) { 00722 $yes=0; 00723 } 00724 } 00725 } 00726 if ($yes) return true; 00727 } 00728 } 00729 return false; 00730 } 00731 00732 /** 00733 * Match IPv6 address with a list of IPv6 prefixes 00734 * 00735 * @param string $baseIP is the current remote IP address for instance 00736 * @param string $list is a comma-list of IPv6 prefixes, could also contain IPv4 addresses 00737 * @return boolean True if an baseIP matches any prefix 00738 */ 00739 public static function cmpIPv6($baseIP, $list) { 00740 $success = false; // Policy default: Deny connection 00741 $baseIP = t3lib_div::normalizeIPv6($baseIP); 00742 00743 $values = t3lib_div::trimExplode(',',$list,1); 00744 foreach ($values as $test) { 00745 list($test,$mask) = explode('/',$test); 00746 if (t3lib_div::validIPv6($test)) { 00747 $test = t3lib_div::normalizeIPv6($test); 00748 if (intval($mask)) { 00749 switch ($mask) { // test on /48 /64 00750 case '48': 00751 $testBin = substr(t3lib_div::IPv6Hex2Bin($test), 0, 48); 00752 $baseIPBin = substr(t3lib_div::IPv6Hex2Bin($baseIP), 0, 48); 00753 $success = strcmp($testBin, $baseIPBin)==0 ? true : false; 00754 break; 00755 case '64': 00756 $testBin = substr(t3lib_div::IPv6Hex2Bin($test), 0, 64); 00757 $baseIPBin = substr(t3lib_div::IPv6Hex2Bin($baseIP), 0, 64); 00758 $success = strcmp($testBin, $baseIPBin)==0 ? true : false; 00759 break; 00760 default: 00761 $success = false; 00762 } 00763 } else { 00764 if (t3lib_div::validIPv6($test)) { // test on full ip address 128 bits 00765 $testBin = t3lib_div::IPv6Hex2Bin($test); 00766 $baseIPBin = t3lib_div::IPv6Hex2Bin($baseIP); 00767 $success = strcmp($testBin, $baseIPBin)==0 ? true : false; 00768 } 00769 } 00770 } 00771 if ($success) return true; 00772 } 00773 return false; 00774 } 00775 00776 /** 00777 * [Describe function...] 00778 * 00779 * @param [type] $hex: ... 00780 * @return [type] ... 00781 */ 00782 public static function IPv6Hex2Bin ($hex) { 00783 $bin = ''; 00784 $hex = str_replace(':', '', $hex); // Replace colon to nothing 00785 for ($i=0; $i<strlen($hex); $i=$i+2) { 00786 $bin.= chr(hexdec(substr($hex, $i, 2))); 00787 } 00788 return $bin; 00789 } 00790 00791 /** 00792 * Normalize an IPv6 address to full length 00793 * 00794 * @param string Given IPv6 address 00795 * @return string Normalized address 00796 */ 00797 public static function normalizeIPv6($address) { 00798 $normalizedAddress = ''; 00799 $stageOneAddress = ''; 00800 00801 $chunks = explode('::', $address); // Count 2 if if address has hidden zero blocks 00802 if (count($chunks)==2) { 00803 $chunksLeft = explode(':', $chunks[0]); 00804 $chunksRight = explode(':', $chunks[1]); 00805 $left = count($chunksLeft); 00806 $right = count($chunksRight); 00807 00808 // Special case: leading zero-only blocks count to 1, should be 0 00809 if ($left==1 && strlen($chunksLeft[0])==0) $left=0; 00810 00811 $hiddenBlocks = 8 - ($left + $right); 00812 $hiddenPart = ''; 00813 while ($h<$hiddenBlocks) { 00814 $hiddenPart .= '0000:'; 00815 $h++; 00816 } 00817 00818 if ($left == 0) { 00819 $stageOneAddress = $hiddenPart . $chunks[1]; 00820 } else { 00821 $stageOneAddress = $chunks[0] . ':' . $hiddenPart . $chunks[1]; 00822 } 00823 } else $stageOneAddress = $address; 00824 00825 // normalize the blocks: 00826 $blocks = explode(':', $stageOneAddress); 00827 $divCounter = 0; 00828 foreach ($blocks as $block) { 00829 $tmpBlock = ''; 00830 $i = 0; 00831 $hiddenZeros = 4 - strlen($block); 00832 while ($i < $hiddenZeros) { 00833 $tmpBlock .= '0'; 00834 $i++; 00835 } 00836 $normalizedAddress .= $tmpBlock . $block; 00837 if ($divCounter < 7) { 00838 $normalizedAddress .= ':'; 00839 $divCounter++; 00840 } 00841 } 00842 return $normalizedAddress; 00843 } 00844 00845 /** 00846 * Validate a given IP address. 00847 * 00848 * Possible format are IPv4 and IPv6. 00849 * 00850 * @param string IP address to be tested 00851 * @return boolean True if $ip is either of IPv4 or IPv6 format. 00852 */ 00853 public static function validIP($ip) { 00854 return (filter_var($ip, FILTER_VALIDATE_IP) !== false); 00855 } 00856 00857 /** 00858 * Validate a given IP address to the IPv4 address format. 00859 * 00860 * Example for possible format: 10.0.45.99 00861 * 00862 * @param string IP address to be tested 00863 * @return boolean True if $ip is of IPv4 format. 00864 */ 00865 public static function validIPv4($ip) { 00866 return (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) !== false); 00867 } 00868 00869 /** 00870 * Validate a given IP address to the IPv6 address format. 00871 * 00872 * Example for possible format: 43FB::BB3F:A0A0:0 | ::1 00873 * 00874 * @param string IP address to be tested 00875 * @return boolean True if $ip is of IPv6 format. 00876 */ 00877 public static function validIPv6($ip) { 00878 return (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) !== false); 00879 } 00880 00881 /** 00882 * Match fully qualified domain name with list of strings with wildcard 00883 * 00884 * @param string The current remote IP address for instance, typ. REMOTE_ADDR 00885 * @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) 00886 * @return boolean True if a domain name mask from $list matches $baseIP 00887 */ 00888 public static function cmpFQDN($baseIP, $list) { 00889 if (count(explode('.',$baseIP))==4) { 00890 $resolvedHostName = explode('.', gethostbyaddr($baseIP)); 00891 $values = t3lib_div::trimExplode(',',$list,1); 00892 00893 foreach($values as $test) { 00894 $hostNameParts = explode('.',$test); 00895 $yes = 1; 00896 00897 foreach($hostNameParts as $index => $val) { 00898 $val = trim($val); 00899 if (strcmp($val,'*') && strcmp($resolvedHostName[$index],$val)) { 00900 $yes=0; 00901 } 00902 } 00903 if ($yes) return true; 00904 } 00905 } 00906 return false; 00907 } 00908 00909 /** 00910 * Check for item in list 00911 * Check if an item exists in a comma-separated list of items. 00912 * Usage: 163 00913 * 00914 * @param string comma-separated list of items (string) 00915 * @param string item to check for 00916 * @return boolean true if $item is in $list 00917 */ 00918 public static function inList($list, $item) { 00919 return (strpos(','.$list.',', ','.$item.',')!==false ? true : false); 00920 } 00921 00922 /** 00923 * Removes an item from a comma-separated list of items. 00924 * Usage: 1 00925 * 00926 * @param string element to remove 00927 * @param string comma-separated list of items (string) 00928 * @return string new comma-separated list of items 00929 */ 00930 public static function rmFromList($element,$list) { 00931 $items = explode(',',$list); 00932 foreach ($items as $k => $v) { 00933 if ($v==$element) { 00934 unset($items[$k]); 00935 } 00936 } 00937 return implode(',',$items); 00938 } 00939 00940 /** 00941 * Expand a comma-separated list of integers with ranges (eg 1,3-5,7 becomes 1,3,4,5,7). 00942 * Ranges are limited to 1000 values per range. 00943 * 00944 * @param string comma-separated list of integers with ranges (string) 00945 * @return string new comma-separated list of items 00946 * @author Martin Kutschker <martin.kutschker@activesolution.at> 00947 */ 00948 public static function expandList($list) { 00949 $items = explode(',',$list); 00950 $list = array(); 00951 foreach ($items as $item) { 00952 $range = explode('-',$item); 00953 if (isset($range[1])) { 00954 $runAwayBrake = 1000; 00955 for ($n=$range[0]; $n<=$range[1]; $n++) { 00956 $list[] = $n; 00957 00958 $runAwayBrake--; 00959 if ($runAwayBrake<=0) break; 00960 } 00961 } else { 00962 $list[] = $item; 00963 } 00964 } 00965 return implode(',',$list); 00966 } 00967 00968 /** 00969 * Forces the integer $theInt into the boundaries of $min and $max. If the $theInt is 'false' then the $zeroValue is applied. 00970 * Usage: 224 00971 * 00972 * @param integer Input value 00973 * @param integer Lower limit 00974 * @param integer Higher limit 00975 * @param integer Default value if input is false. 00976 * @return integer The input value forced into the boundaries of $min and $max 00977 */ 00978 public static function intInRange($theInt,$min,$max=2000000000,$zeroValue=0) { 00979 // Returns $theInt as an integer in the integerspace from $min to $max 00980 $theInt = intval($theInt); 00981 if ($zeroValue && !$theInt) {$theInt=$zeroValue;} // If the input value is zero after being converted to integer, zeroValue may set another default value for it. 00982 if ($theInt<$min){$theInt=$min;} 00983 if ($theInt>$max){$theInt=$max;} 00984 return $theInt; 00985 } 00986 00987 /** 00988 * Returns the $integer if greater than zero, otherwise returns zero. 00989 * Usage: 1 00990 * 00991 * @param integer Integer string to process 00992 * @return integer 00993 */ 00994 public static function intval_positive($theInt) { 00995 $theInt = intval($theInt); 00996 if ($theInt<0){$theInt=0;} 00997 return $theInt; 00998 } 00999 01000 /** 01001 * Returns an integer from a three part version number, eg '4.12.3' -> 4012003 01002 * Usage: 2 01003 * 01004 * @param string Version number on format x.x.x 01005 * @return integer Integer version of version number (where each part can count to 999) 01006 */ 01007 public static function int_from_ver($verNumberStr) { 01008 $verParts = explode('.',$verNumberStr); 01009 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)); 01010 } 01011 01012 /** 01013 * Returns true if the current TYPO3 version (or compatibility version) is compatible to the input version 01014 * Notice that this function compares branches, not versions (4.0.1 would be > 4.0.0 although they use the same compat_version) 01015 * 01016 * @param string Minimum branch number required (format x.y / e.g. "4.0" NOT "4.0.0"!) 01017 * @return boolean Returns true if this setup is compatible with the provided version number 01018 * @todo Still needs a function to convert versions to branches 01019 */ 01020 public static function compat_version($verNumberStr) { 01021 global $TYPO3_CONF_VARS; 01022 $currVersionStr = $TYPO3_CONF_VARS['SYS']['compat_version'] ? $TYPO3_CONF_VARS['SYS']['compat_version'] : TYPO3_branch; 01023 01024 if (t3lib_div::int_from_ver($currVersionStr) < t3lib_div::int_from_ver($verNumberStr)) { 01025 return FALSE; 01026 } else { 01027 return TRUE; 01028 } 01029 } 01030 01031 /** 01032 * Makes a positive integer hash out of the first 7 chars from the md5 hash of the input 01033 * Usage: 5 01034 * 01035 * @param string String to md5-hash 01036 * @return integer Returns 28bit integer-hash 01037 */ 01038 public static function md5int($str) { 01039 return hexdec(substr(md5($str),0,7)); 01040 } 01041 01042 /** 01043 * Returns the first 10 positions of the MD5-hash (changed from 6 to 10 recently) 01044 * 01045 * Usage: 37 01046 * 01047 * @param string Input string to be md5-hashed 01048 * @param integer The string-length of the output 01049 * @return string Substring of the resulting md5-hash, being $len chars long (from beginning) 01050 */ 01051 public static function shortMD5($input, $len=10) { 01052 return substr(md5($input),0,$len); 01053 } 01054 01055 /** 01056 * Takes comma-separated lists and arrays and removes all duplicates 01057 * If a value in the list is trim(empty), the value is ignored. 01058 * Usage: 16 01059 * 01060 * @param string Accept multiple parameters wich can be comma-separated lists of values and arrays. 01061 * @param mixed $secondParameter: Dummy field, which if set will show a warning! 01062 * @return string Returns the list without any duplicates of values, space around values are trimmed 01063 */ 01064 public static function uniqueList($in_list, $secondParameter=NULL) { 01065 if (is_array($in_list)) die('t3lib_div::uniqueList() does NOT support array arguments anymore! Only string comma lists!'); 01066 if (isset($secondParameter)) die('t3lib_div::uniqueList() does NOT support more than a single argument value anymore. You have specified more than one.'); 01067 01068 return implode(',',array_unique(t3lib_div::trimExplode(',',$in_list,1))); 01069 } 01070 01071 /** 01072 * Splits a reference to a file in 5 parts 01073 * Usage: 43 01074 * 01075 * @param string Filename/filepath to be analysed 01076 * @return array Contains keys [path], [file], [filebody], [fileext], [realFileext] 01077 */ 01078 public static function split_fileref($fileref) { 01079 $reg = array(); 01080 if ( ereg('(.*/)(.*)$',$fileref,$reg) ) { 01081 $info['path'] = $reg[1]; 01082 $info['file'] = $reg[2]; 01083 } else { 01084 $info['path'] = ''; 01085 $info['file'] = $fileref; 01086 } 01087 $reg=''; 01088 if ( ereg('(.*)\.([^\.]*$)',$info['file'],$reg) ) { 01089 $info['filebody'] = $reg[1]; 01090 $info['fileext'] = strtolower($reg[2]); 01091 $info['realFileext'] = $reg[2]; 01092 } else