00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00232 class t3lib_div {
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00262 function _GP($var) {
00263 if(empty($var)) return;
00264 $value = isset($_POST[$var]) ? $_POST[$var] : $_GET[$var];
00265 if (isset($value)) {
00266 if (is_array($value)) { t3lib_div::stripSlashesOnArray($value); } else { $value = stripslashes($value); }
00267 }
00268 return $value;
00269 }
00270
00280 function _GET($var=NULL) {
00281 $value = ($var === NULL) ? $_GET : (empty($var) ? NULL : $_GET[$var]);
00282 if (isset($value)) {
00283 if (is_array($value)) { t3lib_div::stripSlashesOnArray($value); } else { $value = stripslashes($value); }
00284 }
00285 return $value;
00286 }
00287
00297 function _POST($var=NULL) {
00298 $value = ($var === NULL) ? $_POST : (empty($var) ? NULL : $_POST[$var]);
00299 if (isset($value)) {
00300 if (is_array($value)) { t3lib_div::stripSlashesOnArray($value); } else { $value = stripslashes($value); }
00301 }
00302 return $value;
00303 }
00304
00313 function _GETset($inputGet,$key='') {
00314
00315 if (strcmp($key,'')) {
00316 if (is_array($inputGet)) { t3lib_div::addSlashesOnArray($inputGet); } else { $inputGet = addslashes($inputGet); }
00317 $GLOBALS['HTTP_GET_VARS'][$key] = $_GET[$key] = $inputGet;
00318 } elseif (is_array($inputGet)){
00319 t3lib_div::addSlashesOnArray($inputGet);
00320 $GLOBALS['HTTP_GET_VARS'] = $_GET = $inputGet;
00321 }
00322 }
00323
00336 function GPvar($var,$strip=0) {
00337 if(empty($var)) return;
00338 $value = isset($_POST[$var]) ? $_POST[$var] : $_GET[$var];
00339 if (isset($value) && is_string($value)) { $value = stripslashes($value); }
00340 if ($strip && isset($value) && is_array($value)) { t3lib_div::stripSlashesOnArray($value); }
00341 return $value;
00342 }
00343
00353 function GParrayMerged($var) {
00354 $postA = is_array($_POST[$var]) ? $_POST[$var] : array();
00355 $getA = is_array($_GET[$var]) ? $_GET[$var] : array();
00356 $mergedA = t3lib_div::array_merge_recursive_overrule($getA,$postA);
00357 t3lib_div::stripSlashesOnArray($mergedA);
00358 return $mergedA;
00359 }
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00397 function gif_compress($theFile, $type) {
00398 $gfxConf = $GLOBALS['TYPO3_CONF_VARS']['GFX'];
00399 $returnCode='';
00400 if ($gfxConf['gif_compress'] && strtolower(substr($theFile,-4,4))=='.gif') {
00401 if (($type=='IM' || !$type) && $gfxConf['im'] && $gfxConf['im_path_lzw']) {
00402 $cmd = t3lib_div::imageMagickCommand('convert', '"'.$theFile.'" "'.$theFile.'"', $gfxConf['im_path_lzw']);
00403 exec($cmd);
00404
00405 $returnCode='IM';
00406 } elseif (($type=='GD' || !$type) && $gfxConf['gdlib'] && !$gfxConf['gdlib_png']) {
00407 $tempImage = imageCreateFromGif($theFile);
00408 imageGif($tempImage, $theFile);
00409 imageDestroy($tempImage);
00410 $returnCode='GD';
00411 }
00412 }
00413 return $returnCode;
00414 }
00415
00425 function png_to_gif_by_imagemagick($theFile) {
00426 if ($GLOBALS['TYPO3_CONF_VARS']['FE']['png_to_gif']
00427 && $GLOBALS['TYPO3_CONF_VARS']['GFX']['im']
00428 && $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_path_lzw']
00429 && strtolower(substr($theFile,-4,4))=='.png'
00430 && @is_file($theFile)) {
00431 $newFile = substr($theFile,0,-4).'.gif';
00432 $cmd = t3lib_div::imageMagickCommand('convert', '"'.$theFile.'" "'.$newFile.'"', $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_path_lzw']);
00433 exec($cmd);
00434 $theFile = $newFile;
00435
00436 }
00437 return $theFile;
00438 }
00439
00450 function read_png_gif($theFile,$output_png=0) {
00451 if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['im'] && @is_file($theFile)) {
00452 $ext = strtolower(substr($theFile,-4,4));
00453 if (
00454 ((string)$ext=='.png' && $output_png) ||
00455 ((string)$ext=='.gif' && !$output_png)
00456 ) {
00457 return $theFile;
00458 } else {
00459 $newFile = PATH_site.'typo3temp/readPG_'.md5($theFile.'|'.filemtime($theFile)).($output_png?'.png':'.gif');
00460 exec($GLOBALS['TYPO3_CONF_VARS']['GFX']['im_path'].'convert "'.$theFile.'" "'.$newFile.'"');
00461 if (@is_file($newFile)) return $newFile;
00462 }
00463 }
00464 }
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485
00499 function fixed_lgd($string,$origChars,$preStr='...') {
00500 $chars = abs($origChars);
00501 if ($chars >= 4) {
00502 if(strlen($string)>$chars) {
00503 return $origChars < 0 ?
00504 $preStr.trim(substr($string, -($chars-3))) :
00505 trim(substr($string, 0, $chars-3)).$preStr;
00506 }
00507 }
00508 return $string;
00509 }
00510
00524 function fixed_lgd_pre($string,$chars) {
00525 return strrev(t3lib_div::fixed_lgd(strrev($string),$chars));
00526 }
00527
00538 function fixed_lgd_cs($string,$chars) {
00539 if (is_object($GLOBALS['LANG'])) {
00540 return $GLOBALS['LANG']->csConvObj->crop($GLOBALS['LANG']->charSet,$string,$chars,'...');
00541 } else {
00542 return t3lib_div::fixed_lgd($string, $chars);
00543 }
00544 }
00545
00555 function breakTextForEmail($str,$implChar="\n",$charWidth=76) {
00556 $lines = explode(chr(10),$str);
00557 $outArr=array();
00558 while(list(,$lStr)=each($lines)) {
00559 $outArr = array_merge($outArr,t3lib_div::breakLinesForEmail($lStr,$implChar,$charWidth));
00560 }
00561 return implode(chr(10),$outArr);
00562 }
00563
00574 function breakLinesForEmail($str,$implChar="\n",$charWidth=76) {
00575 $lines=array();
00576 $l=$charWidth;
00577 $p=0;
00578 while(strlen($str)>$p) {
00579 $substr=substr($str,$p,$l);
00580 if (strlen($substr)==$l) {
00581 $count = count(explode(' ',trim(strrev($substr))));
00582 if ($count>1) {
00583 $parts = explode(' ',strrev($substr),2);
00584 $theLine = strrev($parts[1]);
00585 } else {
00586 $afterParts = explode(' ',substr($str,$l+$p),2);
00587 $theLine = $substr.$afterParts[0];
00588 }
00589 if (!strlen($theLine)) {break; }
00590 } else {
00591 $theLine=$substr;
00592 }
00593
00594 $lines[]=trim($theLine);
00595 $p+=strlen($theLine);
00596 if (!trim(substr($str,$p,$l))) break;
00597 }
00598 return implode($implChar,$lines);
00599 }
00600
00610 function cmpIP($baseIP, $list) {
00611 if ($list==='*') return TRUE;
00612 if (strstr($baseIP, ':') && t3lib_div::validIPv6($baseIP)) {
00613 return t3lib_div::cmpIPv6($baseIP, $list);
00614 } else {
00615 return t3lib_div::cmpIPv4($baseIP, $list);
00616 }
00617 }
00618
00626 function cmpIPv4($baseIP, $list) {
00627 $IPpartsReq = explode('.',$baseIP);
00628 if (count($IPpartsReq)==4) {
00629 $values = t3lib_div::trimExplode(',',$list,1);
00630
00631 foreach($values as $test) {
00632 list($test,$mask) = explode('/',$test);
00633
00634 if(intval($mask)) {
00635
00636 $lnet = ip2long($test);
00637 $lip = ip2long($baseIP);
00638 $binnet = str_pad( decbin($lnet),32,'0','STR_PAD_LEFT');
00639 $firstpart = substr($binnet,0,$mask);
00640 $binip = str_pad( decbin($lip),32,'0','STR_PAD_LEFT');
00641 $firstip = substr($binip,0,$mask);
00642 $yes = (strcmp($firstpart,$firstip)==0);
00643 } else {
00644
00645 $IPparts = explode('.',$test);
00646 $yes = 1;
00647 reset($IPparts);
00648 while(list($index,$val)=each($IPparts)) {
00649 $val = trim($val);
00650 if (strcmp($val,'*') && strcmp($IPpartsReq[$index],$val)) {
00651 $yes=0;
00652 }
00653 }
00654 }
00655 if ($yes) return true;
00656 }
00657 }
00658 return false;
00659 }
00660
00668 function cmpIPv6($baseIP, $list) {
00669 $success = false;
00670 $baseIP = t3lib_div::normalizeIPv6($baseIP);
00671
00672 $values = t3lib_div::trimExplode(',',$list,1);
00673 foreach ($values as $test) {
00674 list($test,$mask) = explode('/',$test);
00675 if (t3lib_div::validIPv6($test)) {
00676 $test = t3lib_div::normalizeIPv6($test);
00677 if (intval($mask)) {
00678 switch ($mask) {
00679 case '48':
00680 $testBin = substr(t3lib_div::IPv6Hex2Bin($test), 0, 48);
00681 $baseIPBin = substr(t3lib_div::IPv6Hex2Bin($baseIP), 0, 48);
00682 $success = strcmp($testBin, $baseIPBin)==0 ? true : false;
00683 break;
00684 case '64':
00685 $testBin = substr(t3lib_div::IPv6Hex2Bin($test), 0, 64);
00686 $baseIPBin = substr(t3lib_div::IPv6Hex2Bin($baseIP), 0, 64);
00687 $success = strcmp($testBin, $baseIPBin)==0 ? true : false;
00688 break;
00689 default:
00690 $success = false;
00691 }
00692 } else {
00693 if (t3lib_div::validIPv6($test)) {
00694 $testBin = t3lib_div::IPv6Hex2Bin($test);
00695 $baseIPBin = t3lib_div::IPv6Hex2Bin($baseIP);
00696 $success = strcmp($testBin, $baseIPBin)==0 ? true : false;
00697 }
00698 }
00699 }
00700 if ($success) return true;
00701 }
00702 return false;
00703 }
00704
00711 function IPv6Hex2Bin ($hex) {
00712 $bin = '';
00713 $hex = str_replace(':', '', $hex);
00714 for ($i=0; $i<strlen($hex); $i=$i+2) {
00715 $bin.= chr(hexdec(substr($hex, $i, 2)));
00716 }
00717 return $bin;
00718 }
00719
00726 function normalizeIPv6($address) {
00727 $normalizedAddress = '';
00728 $stageOneAddress = '';
00729
00730 $chunks = explode('::', $address);
00731 if (count($chunks)==2) {
00732 $chunksLeft = explode(':', $chunks[0]);
00733 $chunksRight = explode(':', $chunks[1]);
00734 $left = count($chunksLeft);
00735 $right = count($chunksRight);
00736
00737
00738 if ($left==1 && strlen($chunksLeft[0])==0) $left=0;
00739
00740 $hiddenBlocks = 8 - ($left + $right);
00741 $hiddenPart = '';
00742 while ($h<$hiddenBlocks) {
00743 $hiddenPart .= '0000:';
00744 $h++;
00745 }
00746
00747 if ($left == 0) {
00748 $stageOneAddress = $hiddenPart . $chunks[1];
00749 } else {
00750 $stageOneAddress = $chunks[0] . ':' . $hiddenPart . $chunks[1];
00751 }
00752 } else $stageOneAddress = $address;
00753
00754
00755 $blocks = explode(':', $stageOneAddress);
00756 $divCounter = 0;
00757 foreach ($blocks as $block) {
00758 $tmpBlock = '';
00759 $i = 0;
00760 $hiddenZeros = 4 - strlen($block);
00761 while ($i < $hiddenZeros) {
00762 $tmpBlock .= '0';
00763 $i++;
00764 }
00765 $normalizedAddress .= $tmpBlock . $block;
00766 if ($divCounter < 7) {
00767 $normalizedAddress .= ':';
00768 $divCounter++;
00769 }
00770 }
00771 return $normalizedAddress;
00772 }
00773
00782 function validIPv6($ip) {
00783 $uppercaseIP = strtoupper($ip);
00784
00785 $regex = '/^(';
00786 $regex.= '(([\dA-F]{1,4}:){7}[\dA-F]{1,4})|';
00787 $regex.= '(([\dA-F]{1,4}){1}::([\dA-F]{1,4}:){1,5}[\dA-F]{1,4})|';
00788 $regex.= '(([\dA-F]{1,4}:){2}:([\dA-F]{1,4}:){1,4}[\dA-F]{1,4})|';
00789 $regex.= '(([\dA-F]{1,4}:){3}:([\dA-F]{1,4}:){1,3}[\dA-F]{1,4})|';
00790 $regex.= '(([\dA-F]{1,4}:){4}:([\dA-F]{1,4}:){1,2}[\dA-F]{1,4})|';
00791 $regex.= '(([\dA-F]{1,4}:){5}:([\dA-F]{1,4}:){0,1}[\dA-F]{1,4})|';
00792 $regex.= '(::([\dA-F]{1,4}:){0,6}[\dA-F]{1,4})';
00793 $regex.= ')$/';
00794
00795 return preg_match($regex, $uppercaseIP) ? true : false;
00796 }
00797
00805 function cmpFQDN($baseIP, $list) {
00806 if (count(explode('.',$baseIP))==4) {
00807 $resolvedHostName = explode('.', gethostbyaddr($baseIP));
00808 $values = t3lib_div::trimExplode(',',$list,1);
00809
00810 foreach($values as $test) {
00811 $hostNameParts = explode('.',$test);
00812 $yes = 1;
00813
00814 foreach($hostNameParts as $index => $val) {
00815 $val = trim($val);
00816 if (strcmp($val,'*') && strcmp($resolvedHostName[$index],$val)) {
00817 $yes=0;
00818 }
00819 }
00820 if ($yes) return true;
00821 }
00822 }
00823 return false;
00824 }
00825
00835 function inList($list,$item) {
00836 return strstr(','.$list.',', ','.$item.',') ? true : false;
00837 }
00838
00847 function rmFromList($element,$list) {
00848 $items = explode(',',$list);
00849 while(list($k,$v)=each($items)) {
00850 if ($v==$element) {unset($items[$k]);}
00851 }
00852 return implode(',',$items);
00853 }
00854
00863 function expandList($list) {
00864 $items = explode(',',$list);
00865 $list = array();
00866 while(list(,$item)=each($items)) {
00867 $range = explode('-',$item);
00868 if (isset($range[1])) {
00869 $runAwayBrake = 1000;
00870 for ($n=$range[0]; $n<=$range[1]; $n++) {
00871 $list[] = $n;
00872
00873 $runAwayBrake--;
00874 if ($runAwayBrake<=0) break;
00875 }
00876 } else {
00877 $list[] = $item;
00878 }
00879 }
00880
00881 return implode(',',$list);
00882 }
00883
00894 function intInRange($theInt,$min,$max=2000000000,$zeroValue=0) {
00895
00896 $theInt = intval($theInt);
00897 if ($zeroValue && !$theInt) {$theInt=$zeroValue;}
00898 if ($theInt<$min){$theInt=$min;}
00899 if ($theInt>$max){$theInt=$max;}
00900 return $theInt;
00901 }
00902
00910 function intval_positive($theInt) {
00911 $theInt = intval($theInt);
00912 if ($theInt<0){$theInt=0;}
00913 return $theInt;
00914 }
00915
00923 function int_from_ver($verNumberStr) {
00924 $verParts = explode('.',$verNumberStr);
00925 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));
00926 }
00927
00934 function compat_version($verNumberStr) {
00935 global $TYPO3_CONF_VARS;
00936 $currVersionStr = $TYPO3_CONF_VARS['SYS']['compat_version']?$TYPO3_CONF_VARS['SYS']['compat_version']:TYPO3_version;
00937
00938 if (t3lib_div::int_from_ver($currVersionStr) < t3lib_div::int_from_ver($verNumberStr)) {
00939 return FALSE;
00940 } else {
00941 return TRUE;
00942 }
00943 }
00944
00952 function md5int($str) {
00953 return hexdec(substr(md5($str),0,7));
00954 }
00955
00965 function shortMD5($input, $len=10) {
00966 return substr(md5($input),0,$len);
00967 }
00968
00978 function uniqueList($in_list, $secondParameter=NULL) {
00979 if (is_array($in_list)) die('t3lib_div::uniqueList() does NOT support array arguments anymore! Only string comma lists!');
00980 if (isset($secondParameter)) die('t3lib_div::uniqueList() does NOT support more than a single argument value anymore. You have specified more than one.');
00981
00982 return implode(',',array_unique(t3lib_div::trimExplode(',',$in_list,1)));
00983 }
00984
00992 function split_fileref($fileref) {
00993 $reg = array();
00994 if ( ereg('(.*/)(.*)$',$fileref,$reg) ) {
00995 $info['path'] = $reg[1];
00996 $info['file'] = $reg[2];
00997 } else {
00998 $info['path'] = '';
00999 $info['file'] = $fileref;
01000 }
01001 $reg='';
01002 if ( ereg('(.*)\.([^\.]*$)',$info['file'],$reg) ) {
01003 $info['filebody'] = $reg[1];
01004 $info['fileext'] = strtolower($reg[2]);
01005 $info['realFileext'] = $reg[2];
01006 } else {
01007 $info['filebody'] = $info['file'];
01008 $info['fileext'] = '';
01009 }
01010 reset($info);
01011 return $info;
01012 }
01013
01030 function dirname($path) {
01031 $p=t3lib_div::revExplode('/',$path,2);
01032 return count($p)==2?$p[0]:'';
01033 }
01034
01046 function modifyHTMLColor($color,$R,$G,$B) {
01047
01048 $nR = t3lib_div::intInRange(hexdec(substr($color,1,2))+$R,0,255);
01049 $nG = t3lib_div::intInRange(hexdec(substr($color,3,2))+$G,0,255);
01050 $nB = t3lib_div::intInRange(hexdec(substr($color,5,2))+$B,0,255);
01051 return '#'.
01052 substr('0'.dechex($nR),-2).
01053 substr('0'.dechex($nG),-2).
01054 substr('0'.dechex($nB),-2);
01055 }
01056
01066 function modifyHTMLColorAll($color,$all) {
01067 return t3lib_div::modifyHTMLColor($color,$all,$all,$all);
01068 }
01069
01077 function rm_endcomma($string) {
01078 return ereg_replace(',$','',$string);
01079 }
01080
01090 function danish_strtoupper($string) {
01091 $value = strtoupper($string);
01092 return strtr($value, 'áéúíâêûôîæøåäöü', 'ÁÉÚÍÄËÜÖÏÆØÅÄÖÜ');
01093 }
01094
01105 function convUmlauts($str) {
01106 $pat = array ( '/ä/', '/Ä/', '/ö/', '/Ö/', '/ü/', '/Ü/', '/ß/', '/å/', '/Å/', '/ø/', '/Ø/', '/æ/', '/Æ/' );
01107 $repl = array ( 'ae', 'Ae', 'oe', 'Oe', 'ue', 'Ue', 'ss', 'aa', 'AA', 'oe', 'OE', 'ae', 'AE' );
01108 return preg_replace($pat,$repl,$str);
01109 }
01110
01118 function testInt($var) {
01119 return !strcmp($var,intval($var));
01120 }
01121
01130 function isFirstPartOfStr($str,$partStr) {
01131
01132 $psLen = strlen($partStr);
01133 if ($psLen) {
01134 return substr($str,0,$psLen)==(string)$partStr;
01135 } else return false;
01136 }
01137
01146 function formatSize($sizeInBytes,$labels='') {
01147
01148
01149 if (strlen($labels) == 0) {
01150 $labels = ' | K| M| G';
01151 } else {
01152 $labels = str_replace('"','',$labels);
01153 }
01154 $labelArr = explode('|',$labels);
01155
01156
01157 if ($sizeInBytes>900) {
01158 if ($sizeInBytes>900000000) {
01159 $val = $sizeInBytes/(1024*1024*1024);
01160 return number_format($val, (($val<20)?1:0), '.', '').$labelArr[3];
01161 }
01162 elseif ($sizeInBytes>900000) {
01163 $val = $sizeInBytes/(1024*1024);
01164 return number_format($val, (($val<20)?1:0), '.', '').$labelArr[2];
01165 } else {
01166 $val = $sizeInBytes/(1024);
01167 return number_format($val, (($val<20)?1:0), '.', '').$labelArr[1];
01168 }
01169 } else {
01170 return $sizeInBytes.$labelArr[0];
01171 }
01172 }
01173
01181 function convertMicrotime($microtime) {
01182 $parts = explode(' ',$microtime);
01183 return round(($parts[0]+$parts[1])*1000);
01184 }
01185
01195 function splitCalc($string,$operators) {
01196 $res = Array();
01197 $sign='+';
01198 while($string) {
01199 $valueLen=strcspn($string,$operators);
01200 $value=substr($string,0,$valueLen);
01201 $res[] = Array($sign,trim($value));
01202 $sign=substr($string,$valueLen,1);
01203 $string=substr($string,$valueLen+1);
01204 }
01205 reset($res);
01206 return $res;
01207 }
01208
01217 function calcPriority($string) {
01218 $string=ereg_replace('[[:space:]]*','',$string);
01219 $string='+'.$string;
01220 $qm='\*\/\+-^%';
01221 $regex = '(['.$qm.'])(['.$qm.']?[0-9\.]*)';
01222
01223 $reg = array();
01224 preg_match_all('/'.$regex.'/',$string,$reg);
01225
01226 reset($reg[2]);
01227 $number=0;
01228 $Msign='+';
01229 $err='';
01230 $buffer=doubleval(current($reg[2]));
01231 next($reg[2]);
01232 while(list($k,$v)=each($reg[2])) {
01233 $v=doubleval($v);
01234 $sign = $reg[1][$k];
01235 if ($sign=='+' || $sign=='-') {
01236 $number = $Msign=='-' ? $number-=$buffer : $number+=$buffer;
01237 $Msign = $sign;
01238 $buffer=$v;
01239 } else {
01240 if ($sign=='/') {if ($v) $buffer/=$v; else $err='dividing by zero';}
01241 if ($sign=='%') {if ($v) $buffer%=$v; else $err='dividing by zero';}
01242 if ($sign=='*') {$buffer*=$v;}
01243 if ($sign=='^') {$buffer=pow($buffer,$v);}
01244 }
01245 }
01246 $number = $Msign=='-' ? $number-=$buffer : $number+=$buffer;
01247 return $err ? 'ERROR: '.$err : $number;
01248 }
01249
01258 function calcParenthesis($string) {
01259 $securC=100;
01260 do {
01261 $valueLenO=strcspn($string,'(');
01262 $valueLenC=strcspn($string,')');
01263 if ($valueLenC==strlen($string) || $valueLenC < $valueLenO) {
01264 $value = t3lib_div::calcPriority(substr($string,0,$valueLenC));
01265 $string = $value.substr($string,$valueLenC+1);
01266 return $string;
01267 } else {
01268 $string = substr($string,0,$valueLenO).t3lib_div::calcParenthesis(substr($string,$valueLenO+1));
01269 }
01270
01271 $securC--;
01272 if ($securC<=0) break;
01273 } while($valueLenO<strlen($string));
01274 return $string;
01275 }
01276
01284 function htmlspecialchars_decode($value) {
01285 $value = str_replace('>','>',$value);
01286 $value = str_replace('<','<',$value);
01287 $value = str_replace('"','"',$value);
01288 $value = str_replace('&','&',$value);
01289 return $value;
01290 }
01291
01299 function deHSCentities($str) {
01300 return ereg_replace('&([#[:alnum:]]*;)','&\1',$str);
01301 }
01302
01312 function slashJS($string,$extended=0,$char="'") {
01313 if ($extended) {$string = str_replace ("\\", "\\\\", $string);}
01314 return str_replace ($char, "\\".$char, $string);
01315 }
01316
01325 function rawUrlEncodeJS($str) {
01326 return str_replace('%20',' ',rawurlencode($str));
01327 }
01328
01337 function rawUrlEncodeFP($str) {
01338 return str_replace('%2F','/',rawurlencode($str));
01339 }
01340
01348 function validEmail($email) {
01349 $email = trim ($email);
01350 if (strstr($email,' ')) return FALSE;
01351 return ereg('^[A-Za-z0-9\._-]+[@][A-Za-z0-9\._-]+[\.].[A-Za-z0-9]+$',$email) ? TRUE : FALSE;
01352 }
01353
01363 function formatForTextarea($content) {
01364 return chr(10).htmlspecialchars($content);
01365 }
01366
01367
01368
01369
01370
01371
01372
01373
01374
01375
01376
01377
01378 /*************************
01379 *
01380 * ARRAY FUNCTIONS
01381 *
01382 *************************/
01383
01394 function inArray($in_array,$item) {
01395 if (is_array($in_array)) {
01396 while (list(,$val)=each($in_array)) {
01397 if (!is_array($val) && !strcmp($val,$item)) return true;
01398 }
01399 }
01400 }
01401
01411 function intExplode($delim, $string) {
01412 $temp = explode($delim,$string);
01413 while(list($key,$val)=each($temp)) {
01414 $temp[$key]=intval($val);
01415 }
01416 reset($temp);
01417 return $temp;
01418 }
01419
01430 function revExplode($delim, $string, $count=0) {
01431 $temp = explode($delim,strrev($string),$count);
01432 while(list($key,$val)=each($temp)) {
01433 $temp[$key]=strrev($val);
01434 }
01435 $temp=array_reverse($temp);
01436 reset($temp);
01437 return $temp;
01438 }
01439
01450 function trimExplode($delim, $string, $onlyNonEmptyValues=0) {
01451 $temp = explode($delim,$string);
01452 $newtemp=array();
01453 while(list($key,$val)=each($temp)) {
01454 if (!$onlyNonEmptyValues || strcmp('',trim($val))) {
01455 $newtemp[]=trim($val);
01456 }
01457 }
01458 reset($newtemp);
01459 return $newtemp;
01460 }
01461
01472 function uniqueArray($valueArray) {
01473 return array_unique($valueArray);
01474 }
01475
01484 function removeArrayEntryByValue($array,$cmpValue) {
01485 if (is_array($array)) {
01486 reset($array);
01487 while(list($k,$v)=each($array)) {
01488 if (is_array($v)) {
01489 $array[$k] = t3lib_div::removeArrayEntryByValue($v,$cmpValue);
01490 } else {
01491 if (!strcmp($v,$cmpValue)) {
01492 unset($array[$k]);
01493 }
01494 }
01495 }
01496 }
01497 reset($array);
01498 return $array;
01499 }
01500
01513 function implodeArrayForUrl($name,$theArray,$str='',$skipBlank=0,$rawurlencodeParamName=0) {
01514 if (is_array($theArray)) {
01515 foreach($theArray as $Akey => $AVal) {
01516 $thisKeyName = $name ? $name.'['.$Akey.']' : $Akey;
01517 if (is_array($AVal)) {
01518 $str = t3lib_div::implodeArrayForUrl($thisKeyName,$AVal,$str,$skipBlank,$rawurlencodeParamName);
01519 } else {
01520 if (!$skipBlank || strcmp($AVal,'')) {
01521 $str.='&'.($rawurlencodeParamName ? rawurlencode($thisKeyName) : $thisKeyName).
01522 '='.rawurlencode($AVal);
01523 }
01524 }
01525 }
01526 }
01527 return $str;
01528 }
01529
01538 function explodeUrl2Array($string,$multidim=FALSE) {
01539 $output = array();
01540 if ($multidim) {
01541 parse_str($string,$output);
01542 } else {
01543 $p = explode('&',$string);
01544 foreach($p as $v) {
01545 if (strlen($v)) {
01546 list($pK,$pV) = explode('=',$v,2);
01547 $output[rawurldecode($pK)] = rawurldecode($pV);
01548 }
01549 }
01550 }
01551 return $output;
01552 }
01553
01564 function compileSelectedGetVarsFromArray($varList,$getArray,$GPvarAlt=1) {
01565 $keys = t3lib_div::trimExplode(',',$varList,1);
01566 $outArr=array();
01567 foreach($keys as $v) {
01568 if (isset($getArray[$v])) {
01569 $outArr[$v]=$getArray[$v];
01570 } elseif ($GPvarAlt) {
01571 $outArr[$v]=t3lib_div::_GP($v);
01572 }
01573 }
01574 return $outArr;
01575 }
01576
01587 function addSlashesOnArray(&$theArray) {
01588 if (is_array($theArray)) {
01589 reset($theArray);
01590 while(list($Akey,$AVal)=each($theArray)) {
01591 if (is_array($AVal)) {
01592 t3lib_div::addSlashesOnArray($theArray[$Akey]);
01593 } else {
01594 $theArray[$Akey] = addslashes($AVal);
01595 }
01596 }
01597 reset($theArray);
01598 }
01599 }
01600
01611 function stripSlashesOnArray(&$theArray) {
01612 if (is_array($theArray)) {
01613 reset($theArray);
01614 while(list($Akey,$AVal)=each($theArray)) {
01615 if (is_array($AVal)) {
01616 t3lib_div::stripSlashesOnArray($theArray[$Akey]);
01617 } else {
01618 $theArray[$Akey] = stripslashes($AVal);
01619 }
01620 }
01621 reset($theArray);
01622 }
01623 }
01624
01633 function slashArray($arr,$cmd) {
01634 if ($cmd=='strip') t3lib_div::stripSlashesOnArray($arr);
01635 if ($cmd=='add') t3lib_div::addSlashesOnArray($arr);
01636 return $arr;
01637 }
01638
01650 function array_merge_recursive_overrule($arr0,$arr1,$notAddKeys=0,$includeEmtpyValues=true) {
01651 reset($arr1);
01652 while(list($key,$val) = each($arr1)) {
01653 if(is_array($arr0[$key])) {
01654 if (is_array($arr1[$key])) {
01655 $arr0[$key] = t3lib_div::array_merge_recursive_overrule($arr0[$key],$arr1[$key],$notAddKeys);
01656 }
01657 } else {
01658 if ($notAddKeys) {
01659 if (isset($arr0[$key])) {
01660 if ($includeEmtpyValues OR $val) {
01661 $arr0[$key] = $val;
01662 }
01663 }
01664 } else {
01665 if ($includeEmtpyValues OR $val) {
01666 $arr0[$key] = $val;
01667 }
01668 }
01669 }
01670 }
01671 reset($arr0);
01672 return $arr0;
01673 }
01674
01683 function array_merge($arr1,$arr2) {
01684 return $arr2+$arr1;
01685 }
01686
01696 function csvValues($row,$delim=',',$quote='"') {
01697 reset($row);
01698 $out=array();
01699 while(list(,$value)=each($row)) {
01700 list($valPart) = explode(chr(10),$value);
01701 $valPart = trim($valPart);
01702 $out[]=str_replace($quote,$quote.$quote,$valPart);
01703 }
01704 $str = $quote.implode($quote.$delim.$quote,$out).$quote;
01705 return $str;
01706 }
01707
01708
01709
01710
01711
01712
01713
01714
01715
01716
01717
01718
01719
01720
01721
01722
01723
01724
01725
01726
01727
01728
01738 function get_tag_attributes($tag) {
01739 $components = t3lib_div::split_tag_attributes($tag);
01740 $name = '';
01741 $valuemode = '';
01742 if (is_array($components)) {
01743 while (list($key,$val) = each ($components)) {
01744 if ($val != '=') {
01745 if ($valuemode) {
01746 if ($name) {
01747 $attributes[$name] = $val;
01748 $name = '';
01749 }
01750 } else {
01751 if ($key = strtolower(ereg_replace('[^a-zA-Z0-9]','',$val))) {
01752 $attributes[$key] = '';
01753 $name = $key;
01754 }
01755 }
01756 $valuemode = '';
01757 } else {
01758 $valuemode = 'on';
01759 }
01760 }
01761 if (is_array($attributes)) reset($attributes);
01762 return $attributes;
01763 }
01764 }
01765
01775 function split_tag_attributes($tag) {
01776 $tag_tmp = trim(eregi_replace ('^<[^[:space:]]*','',trim($tag)));
01777
01778 $tag_tmp = trim(eregi_replace ('>$','',$tag_tmp));
01779
01780 while (strcmp($tag_tmp,'')) {
01781 $firstChar=substr($tag_tmp,0,1);
01782 if (!strcmp($firstChar,'"') || !strcmp($firstChar,"'")) {
01783 $reg=explode($firstChar,$tag_tmp,3);
01784 $value[]=$reg[1];
01785 $tag_tmp=trim($reg[2]);
01786 } elseif (!strcmp($firstChar,'=')) {
01787 $value[] = '=';
01788 $tag_tmp = trim(substr($tag_tmp,1));
01789 } else {
01790
01791 $reg = split('[[:space:]=]',$tag_tmp,2);
01792 $value[] = trim($reg[0]);
01793 $tag_tmp = trim(substr($tag_tmp,strlen($reg[0]),1).$reg[1]);
01794 }
01795 }
01796 if (is_array($value)) reset($value);
01797 return $value;
01798 }
01799
01809 function implodeAttributes($arr,$xhtmlSafe=FALSE,$dontOmitBlankAttribs=FALSE) {
01810 if (is_array($arr)) {
01811 if ($xhtmlSafe) {
01812 $newArr=array();
01813 foreach($arr as $p => $v) {
01814 if (!isset($newArr[strtolower($p)])) $newArr[strtolower($p)] = htmlspecialchars($v);
01815 }
01816 $arr = $newArr;
01817 }
01818 $list = array();
01819 foreach($arr as $p => $v) {
01820 if (strcmp($v,'') || $dontOmitBlankAttribs) {$list[]=$p.'="'.$v.'"';}
01821 }
01822 return implode(' ',$list);
01823 }
01824 }
01825
01836 function implodeParams($arr,$xhtmlSafe=FALSE,$dontOmitBlankAttribs=FALSE) {
01837 return t3lib_div::implodeAttributes($arr,$xhtmlSafe,$dontOmitBlankAttribs);
01838 }
01839
01851 function wrapJS($string, $linebreak=TRUE) {
01852 if(trim($string)) {
01853
01854 $cr = $linebreak? "\n" : '';
01855
01856
01857 $string = preg_replace ('/^\n+/', '', $string);
01858
01859 $match = array();
01860 if(preg_match('/^(\t+)/',$string,$match)) {
01861 $string = str_replace($match[1],"\t", $string);
01862 }
01863 $string = $cr.'<script type="text/javascript">
01864
01865 '.$string.'
01866
01867 </script>'.$cr;
01868 }
01869 return trim($string);
01870 }
01871
01872
01882 function xml2tree($string,$depth=999) {
01883 $parser = xml_parser_create();
01884 $vals = array();
01885 $index = array();
01886
01887 xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
01888 xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 0);
01889 xml_parse_into_struct($parser, $string, $vals, $index);
01890
01891 if (xml_get_error_code($parser)) return 'Line '.xml_get_current_line_number($parser).': '.xml_error_string(xml_get_error_code($parser));
01892 xml_parser_free($parser);
01893
01894 $stack = array( array() );
01895 $stacktop = 0;
01896 $startPoint=0;
01897
01898
01899 unset($tagi);
01900 foreach($vals as $key => $val) {
01901 $type = $val['type'];
01902
01903
01904 if ($type=='open' || $type=='complete') {
01905 $stack[$stacktop++] = $tagi;
01906
01907 if ($depth==$stacktop) {
01908 $startPoint=$key;
01909 }
01910
01911 $tagi = array('tag' => $val['tag']);
01912
01913 if(isset($val['attributes'])) $tagi['attrs'] = $val['attributes'];
01914 if(isset($val['value'])) $tagi['values'][] = $val['value'];
01915 }
01916
01917 if ($type=='complete' || $type=='close') {
01918 $oldtagi = $tagi;
01919 $tagi = $stack[--$stacktop];
01920 $oldtag = $oldtagi['tag'];
01921 unset($oldtagi['tag']);
01922
01923 if ($depth==($stacktop+1)) {
01924 if ($key-$startPoint > 0) {
01925 $partArray = array_slice(
01926 $vals,
01927 $startPoint+1,
01928 $key-$startPoint-1
01929 );
01930 #$oldtagi=array('XMLvalue'=>t3lib_div::xmlRecompileFromStructValArray($partArray));
01931 $oldtagi['XMLvalue']=t3lib_div::xmlRecompileFromStructValArray($partArray);
01932 } else {
01933 $oldtagi['XMLvalue']=$oldtagi['values'][0];
01934 }
01935 }
01936
01937 $tagi['ch'][$oldtag][] = $oldtagi;
01938 unset($oldtagi);
01939 }
01940
01941 if($type=='cdata') {
01942 $tagi['values'][] = $val['value'];
01943 }
01944 }
01945 return $tagi['ch'];
01946 }
01947
01958 function array2xml_cs($array,$docTag='phparray',$options=array(),$charset='') {
01959
01960
01961 if (!$charset) {
01962 if ($GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset']) {
01963 $charset = $GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset'];
01964 } elseif (is_object($GLOBALS['LANG'])) {
01965 $charset = $GLOBALS['LANG']->charSet;
01966 } else {
01967 $charset = 'iso-8859-1';
01968 }
01969 }
01970
01971
01972 return '<?xml version="1.0" encoding="'.htmlspecialchars($charset).'" standalone="yes" ?>'.chr(10).
01973 t3lib_div::array2xml($array,'',0,$docTag,0, $options);
01974 }
01975
01999 function array2xml($array,$NSprefix='',$level=0,$docTag='phparray',$spaceInd=0, $options=array(),$stackData=array()) {
02000
02001 $binaryChars = chr(0).chr(1).chr(2).chr(3).chr(4).chr(5).chr(6).chr(7).chr(8).
02002 chr(11).chr(12).chr(14).chr(15).chr(16).chr(17).chr(18).chr(19).
02003 chr(20).chr(21).chr(22).chr(23).chr(24).chr(25).chr(26).chr(27).chr(28).chr(29).
02004 chr(30).chr(31);
02005
02006 $indentChar = $spaceInd ? ' ' : chr(9);
02007 $indentN = $spaceInd>0 ? $spaceInd : 1;
02008
02009
02010 $output='';
02011
02012
02013 if (is_array($array)) {
02014 foreach($array as $k=>$v) {
02015 $attr = '';
02016 $tagName = $k;
02017
02018
02019 if(isset($options['grandParentTagMap'][$stackData['grandParentTagName'].'/'.$stackData['parentTagName']])) {
02020 $attr.=' index="'.htmlspecialchars($tagName).'"';
02021 $tagName = (string)$options['grandParentTagMap'][$stackData['grandParentTagName'].'/'.$stackData['parentTagName']];
02022 }elseif(isset($options['parentTagMap'][$stackData['parentTagName'].':_IS_NUM']) && t3lib_div::testInt($tagName)) {
02023 $attr.=' index="'.htmlspecialchars($tagName).'"';
02024 $tagName = (string)$options['parentTagMap'][$stackData['parentTagName'].':_IS_NUM'];
02025 }elseif(isset($options['parentTagMap'][$stackData['parentTagName'].':'.$tagName])) {
02026 $attr.=' index="'.htmlspecialchars($tagName).'"';
02027 $tagName = (string)$options['parentTagMap'][$stackData['parentTagName'].':'.$tagName];
02028 } elseif(isset($options['parentTagMap'][$stackData['parentTagName']])) {
02029 $attr.=' index="'.htmlspecialchars($tagName).'"';
02030 $tagName = (string)$options['parentTagMap'][$stackData['parentTagName']];
02031 } elseif (!strcmp(intval($tagName),$tagName)) {
02032 if ($options['useNindex']) {
02033 $tagName = 'n'.$tagName;
02034 } else {
02035 $attr.=' index="'.$tagName.'"';
02036 $tagName = $options['useIndexTagForNum'] ? $options['useIndexTagForNum'] : 'numIndex';
02037 }
02038 } elseif($options['useIndexTagForAssoc']) {
02039 $attr.=' index="'.htmlspecialchars($tagName).'"';
02040 $tagName = $options['useIndexTagForAssoc'];
02041 }
02042
02043
02044 $tagName = substr(ereg_replace('[^[:alnum:]_-]','',$tagName),0,100);
02045
02046
02047 if (is_array($v)) {
02048
02049
02050 if ($options['alt_options'][$stackData['path'].'/'.$tagName]) {
02051 $subOptions = $options['alt_options'][$stackData['path'].'/'.$tagName];
02052 $clearStackPath = $subOptions['clearStackPath'];
02053 } else {
02054 $subOptions = $options;
02055 $clearStackPath = FALSE;
02056 }
02057
02058 $content = chr(10).
02059 t3lib_div::array2xml(
02060 $v,
02061 $NSprefix,
02062 $level+1,
02063 '',
02064 $spaceInd,
02065 $subOptions,
02066 array(
02067 'parentTagName' => $tagName,
02068 'grandParentTagName' => $stackData['parentTagName'],
02069 'path' => $clearStackPath ? '' : $stackData['path'].'/'.$tagName,
02070 )
02071 ).
02072 str_pad('',($level+1)*$indentN,$indentChar);
02073 if ((int)$options['disableTypeAttrib']!=2) {
02074 $attr.=' type="array"';
02075 }
02076 } else {
02077
02078
02079 if (strcspn($v,$binaryChars) != strlen($v)) {
02080
02081 $content = chr(10).chunk_split(base64_encode($v));
02082 $attr.=' base64="1"';
02083 } else {
02084
02085 $content = htmlspecialchars($v);
02086 $dType = gettype($v);
02087 if ($dType!='string' && !$options['disableTypeAttrib']) { $attr.=' type="'.$dType.'"'; }
02088 }
02089 }
02090
02091
02092 $output.=str_pad('',($level+1)*$indentN,$indentChar).'<'.$NSprefix.$tagName.$attr.'>'.$content.'</'.$NSprefix.$tagName.'>'.chr(10);
02093 }
02094 }
02095
02096
02097 if (!$level) {
02098 $output =
02099 '<'.$docTag.'>'.chr(10).
02100 $output.
02101 '</'.$docTag.'>';
02102 }
02103
02104 return $output;
02105 }
02106
02118 function xml2array($string,$NSprefix='',$reportDocTag=FALSE) {
02119 global $TYPO3_CONF_VARS;
02120
02121
02122 $parser = xml_parser_create();
02123 $vals = array();
02124 $index = array();
02125
02126 xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
02127 xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 0);
02128
02129
02130
02131
02132
02133 if ((double)phpversion()>=5) {
02134 $ereg_result = array();
02135 ereg('^[[:space:]]*<\?xml[^>]*encoding[[:space:]]*=[[:space:]]*"([^"]*)"',substr($string,0,200),$ereg_result);
02136 $theCharset = $ereg_result[1] ? $ereg_result[1] : ($TYPO3_CONF_VARS['BE']['forceCharset'] ? $TYPO3_CONF_VARS['BE']['forceCharset'] : 'iso-8859-1');
02137 xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, $theCharset); // us-ascii / utf-8 / iso-8859-1
02138 }
02139
02140 // Parse content:
02141 xml_parse_into_struct($parser, $string, $vals, $index);
02142
02143 // If error, return error message:
02144 if (xml_get_error_code($parser)) {
02145 return 'Line '.xml_get_current_line_number($parser).': '.xml_error_string(xml_get_error_code($parser));
02146 }
02147 xml_parser_free($parser);
02148
02149 // Init vars:
02150 $stack = array(array());
02151 $stacktop = 0;
02152 $current=array();
02153 $tagName = '';
02154 $documentTag = '';
02155
02156 // Traverse the parsed XML structure:
02157 foreach($vals as $key => $val) {
02158
02159 // First, process the tag-name (which is used in both cases, whether "complete" or "close")
02160 $tagName = $val['tag'];
02161 if (!$documentTag) $documentTag = $tagName;
02162
02163 // Test for name space:
02164 $tagName = ($NSprefix && substr($tagName,0,strlen($NSprefix))==$NSprefix) ? substr($tagName,strlen($NSprefix)) : $tagName;
02165
02166 // Test for numeric tag, encoded on the form "nXXX":
02167 $testNtag = substr($tagName,1); // Closing tag.
02168 $tagName = (substr($tagName,0,1)=='n' && !strcmp(intval($testNtag),$testNtag)) ? intval($testNtag) : $tagName;
02169
02170 // Test for alternative index value:
02171 if (strlen($val['attributes']['index'])) { $tagName = $val['attributes']['index']; }
02172
02173 // Setting tag-values, manage stack:
02174 switch($val['type']) {
02175 case 'open': // If open tag it means there is an array stored in sub-elements. Therefore increase the stackpointer and reset the accumulation array:
02176 $current[$tagName] = array(); // Setting blank place holder
02177 $stack[$stacktop++] = $current;
02178 $current = array();
02179 break;
02180 case 'close': // If the tag is "close" then it is an array which is closing and we decrease the stack pointer.
02181 $oldCurrent = $current;
02182 $current = $stack[--$stacktop];
02183 end($current); // Going to the end of array to get placeholder key, key($current), and fill in array next:
02184 $current[key($current)] = $oldCurrent;
02185 unset($oldCurrent);
02186 break;
02187 case 'complete': // If "complete", then it's a value. If the attribute "base64" is set, then decode the value, otherwise just set it.
02188 if ($val['attributes']['base64']) {
02189 $current[$tagName] = base64_decode($val['value']);
02190 } else {
02191 $current[$tagName] = (string)$val['value']; // Had to cast it as a string - otherwise it would be evaluate false if tested with isset()!!
02192
02193 // Cast type:
02194 switch((string)$val['attributes']['type']) {
02195 case 'integer':
02196 $current[$tagName] = (integer)$current[$tagName];
02197 break;
02198 case 'double':
02199 $current[$tagName] = (double)$current[$tagName];
02200 break;
02201 case 'boolean':
02202 $current[$tagName] = (bool)$current[$tagName];
02203 break;
02204 case 'array':
02205 $current[$tagName] = array(); // MUST be an empty array since it is processed as a value; Empty arrays would end up here because they would have no tags inside...
02206 break;
02207 }
02208 }
02209 break;
02210 }
02211 }
02212
02213 if ($reportDocTag) {
02214 $current[$tagName]['_DOCUMENT_TAG'] = $documentTag;
02215 }
02216
02217 // Finally return the content of the document tag.
02218 return $current[$tagName];
02219 }
02220
02228 function xmlRecompileFromStructValArray($vals) {
02229 $XMLcontent='';
02230
02231 foreach($vals as $val) {
02232 $type = $val['type'];
02233
02234 // open tag:
02235 if ($type=='open' || $type=='complete') {
02236 $XMLcontent.='<'.$val['tag'];
02237 if(isset($val['attributes'])) {
02238 foreach($val['attributes'] as $k => $v) {
02239 $XMLcontent.=' '.$k.'="'.htmlspecialchars($v).'"';
02240 }
02241 }
02242 if ($type=='complete') {
02243 if(isset($val['value'])) {
02244 $XMLcontent.='>'.htmlspecialchars($val['value']).'</'.$val['tag'].'>';
02245 } else $XMLcontent.='/>';
02246 } else $XMLcontent.='>';
02247
02248 if ($type=='open' && isset($val['value'])) {
02249 $XMLcontent.=htmlspecialchars($val['value']);
02250 }
02251 }
02252
02253 if ($type=='close') {
02254 $XMLcontent.='</'.$val['tag'].'>';
02255 }
02256
02257 if($type=='cdata') {
02258 $XMLcontent.=htmlspecialchars($val['value']);
02259 }
02260 }
02261
02262 return $XMLcontent;
02263 }
02264
02272 function xmlGetHeaderAttribs($xmlData) {
02273 $xmlHeader = substr(trim($xmlData),0,200);
02274 $reg=array();
02275 if (eregi('^<\?xml([^>]*)\?\>',$xmlHeader,$reg)) {
02276 return t3lib_div::get_tag_attributes($reg[1]);
02277 }
02278 }
02279
02280
02281
02282
02283
02284
02285
02286
02287
02288
02289
02290
02291
02292
02293
02294
02295
02305 function getURL($url, $includeHeader=0) {
02306 $content = '';
02307
02308
02309 if ((substr($url,0,7)=='http:
02310
02311 $ch = curl_init();
02312 if (!$ch) { return false; }
02313
02314 curl_setopt ($ch,CURLOPT_URL, $url);
02315 curl_setopt ($ch,CURLOPT_HEADER, $includeHeader?1:0);
02316 curl_setopt ($ch,CURLOPT_RETURNTRANSFER, 1);
02317
02318 if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['curlProxyServer']) {
02319 curl_setopt ($ch, CURLOPT_PROXY, $GLOBALS['TYPO3_CONF_VARS']['SYS']['curlProxyServer']);
02320
02321
02322 if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['curlProxyTunnel']) {
02323 curl_setopt ($ch, CURLOPT_HTTPPROXYTUNNEL, $GLOBALS['TYPO3_CONF_VARS']['SYS']['curlProxyTunnel'] );
02324 }
02325 if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['curlProxyUserPass']) {
02326 curl_setopt ($ch, CURLOPT_PROXYUSERPWD, $GLOBALS['TYPO3_CONF_VARS']['SYS']['curlProxyUserPass'] );
02327 }
02328 }
02329 $content=curl_exec ($ch);
02330 curl_close ($ch);
02331
02332 } elseif ($includeHeader) {
02333 $parsedURL = parse_url($url);
02334 if (!t3lib_div::inList('ftp,ftps,http,https,gopher,telnet', $parsedURL['scheme'])) { return false; }
02335
02336 $fp = @fsockopen($parsedURL['host'], ($parsedURL['port']>0 ? $parsedURL['port'] : 80), $errno, $errstr, $timeout=2);
02337 if (!$fp) { return false; }
02338
02339 $msg = 'GET '.$parsedURL['path'].($parsedURL['query'] ? '?'.$parsedURL['query'] : '')." HTTP/1.0\r\nHost: ".$parsedURL['host']."\r\n\r\n";
02340 fputs ($fp, $msg);
02341 while (!feof($fp)) {
02342 $line = fgets ($fp,2048);
02343 $content.=$line;
02344 if ($includeHeader==2 && !strlen(trim($line))) { break; }
02345 }
02346 fclose ($fp);
02347
02348 } elseif (function_exists('file_get_contents')) {
02349 $content = @file_get_contents($url);
02350
02351 } elseif ($fd = @fopen($url,'rb')) {
02352 while (!feof($fd)) {
02353 $content.=fread($fd, 4096);
02354 }
02355 fclose($fd);
02356
02357 } else {
02358 return false;
02359 }
02360
02361 return $content;
02362 }
02363
02372 function writeFile($file,$content) {
02373 if (!@is_file($file)) $changePermissions = true;
02374
02375 if ($fd = fopen($file,'wb')) {
02376 $res = fwrite($fd,$content);
02377 fclose($fd);
02378
02379 if ($res===false) return false;
02380
02381 if ($changePermissions) {
02382 t3lib_div::fixPermissions($file);
02383 }
02384
02385 return true;
02386 }
02387
02388 return false;
02389 }
02390
02397 function fixPermissions($file) {
02398 if (@is_file($file) && TYPO3_OS!='WIN') {
02399 @chmod($file, octdec($GLOBALS['TYPO3_CONF_VARS']['BE']['fileCreateMask']));
02400 if($GLOBALS['TYPO3_CONF_VARS']['BE']['createGroup']) {
02401 @chgrp($file, $GLOBALS['TYPO3_CONF_VARS']['BE']['createGroup']);
02402 }
02403 }
02404 }
02405
02414 function writeFileToTypo3tempDir($filepath,$content) {
02415
02416
02417 $fI = pathinfo($filepath);
02418 $fI['dirname'].= '/';
02419
02420
02421 if (t3lib_div::validPathStr($filepath) && $fI['basename'] && strlen($fI['basename'])<60) {
02422 if (defined('PATH_site')) {
02423 $dirName = PATH_site.'typo3temp/';
02424 if (@is_dir($dirName)) {
02425 if (t3lib_div::isFirstPartOfStr($fI['dirname'],$dirName)) {
02426
02427
02428 $subdir = substr($fI['dirname'],strlen($dirName));
02429 if ($subdir) {
02430 if (ereg('^[[:alnum:]_]+\/$',$subdir) || ereg('^[[:alnum:]_]+\/[[:alnum:]_]+\/$',$subdir)) {
02431 $dirName.= $subdir;
02432 if (!@is_dir($dirName)) {
02433 t3lib_div::mkdir_deep(PATH_site.'typo3temp/', $subdir);
02434 }
02435 } else return 'Subdir, "'.$subdir.'", was NOT on the form "[[:alnum:]_]/" or "[[:alnum:]_]/[[:alnum:]_]/"';
02436 }
02437
02438 if (@is_dir($dirName)) {
02439 if ($filepath == $dirName.$fI['basename']) {
02440 t3lib_div::writeFile($filepath, $content);
02441 if (!@is_file($filepath)) return 'File not written to disk! Write permission error in filesystem?';
02442 } else return 'Calculated filelocation didn\'t match input $filepath!';
02443 } else return '"'.$dirName.'" is not a directory!';
02444 } else return '"'.$fI['dirname'].'" was not within directory PATH_site + "typo3temp/"';
02445 } else return 'PATH_site + "typo3temp/" was not a directory!';
02446 } else return 'PATH_site constant was NOT defined!';
02447 } else return 'Input filepath "'.$filepath.'" was generally invalid!';
02448 }
02449
02457 function mkdir($theNewFolder) {
02458 $theNewFolder = ereg_replace('\/$','',$theNewFolder);
02459 if (mkdir($theNewFolder, octdec($GLOBALS['TYPO3_CONF_VARS']['BE']['folderCreateMask']))){
02460 chmod($theNewFolder, octdec($GLOBALS['TYPO3_CONF_VARS']['BE']['folderCreateMask'])); //added this line, because the mode at 'mkdir' has a strange behaviour sometimes
02461
02462 if($GLOBALS['TYPO3_CONF_VARS']['BE']['createGroup']) { // skip this if createGroup is empty
02463 chgrp($theNewFolder, $GLOBALS['TYPO3_CONF_VARS']['BE']['createGroup']);
02464 }
02465 return TRUE;
02466 }
02467 }
02468
02476 function mkdir_deep($destination,$deepDir) {
02477 $allParts = t3lib_div::trimExplode('/',$deepDir,1);
02478 $root = '';
02479 foreach($allParts as $part) {
02480 $root.= $part.'/';
02481 if (!is_dir($destination.$root)) {
02482 t3lib_div::mkdir($destination.$root);
02483 if (!@is_dir($destination.$root)) {
02484 return 'Error: The directory "'.$destination.$root.'" could not be created...';
02485 }
02486 }
02487 }
02488 }
02489
02498 function get_dirs($path) {
02499 if ($path) {
02500 $d = @dir($path);
02501 if (is_object($d)) {
02502 while($entry=$d->read()) {
02503 if (@is_dir($path.'/'.$entry) && $entry!= '..' && $entry!= '.') {
02504 $filearray[]=$entry;
02505 }
02506 }
02507 $d->close();
02508 } else return 'error';
02509 return $filearray;
02510 }
02511 }
02512
02523 function getFilesInDir($path,$extensionList='',$prependPath=0,$order='') {
02524
02525 // Initialize variabels:
02526 $filearray = array();
02527 $sortarray = array();
02528 $path = ereg_replace('\/$','',$path);
02529
02530 // Find files+directories:
02531 if (@is_dir($path)) {
02532 $extensionList = strtolower($extensionList);
02533 $d = dir($path);
02534 if (is_object($d)) {
02535 while($entry=$d->read()) {
02536 if (@is_file($path.'/'.$entry)) {
02537 $fI = pathinfo($entry);
02538 $key = md5($path.'/'.$entry); // Don't change this ever - extensions may depend on the fact that the hash is an md5 of the path! (import/export extension)
02539 if (!$extensionList || t3lib_div::inList($extensionList,strtolower($fI['extension']))) {
02540 $filearray[$key]=($prependPath?$path.'/':'').$entry;
02541 if ($order=='mtime') {$sortarray[$key]=filemtime($path.'/'.$entry);}
02542 elseif ($order) {$sortarray[$key]=$entry;}
02543 }
02544 }
02545 }
02546 $d->close();
02547 } else return 'error opening path: "'.$path.'"';
02548 }
02549
02550
02551 if ($order) {
02552 asort($sortarray);
02553 reset($sortarray);
02554 $newArr=array();
02555 while(list($k,$v)=each($sortarray)) {
02556 $newArr[$k]=$filearray[$k];
02557 }
02558 $filearray=$newArr;
02559 }
02560
02561
02562 reset($filearray);
02563 return $filearray;
02564 }
02565
02577 function getAllFilesAndFoldersInPath($fileArr,$path,$extList='',$regDirs=0,$recursivityLevels=99) {
02578 if ($regDirs) $fileArr[] = $path;
02579 $fileArr = array_merge($fileArr, t3lib_div::getFilesInDir($path,$extList,1,1));
02580
02581 $dirs = t3lib_div::get_dirs($path);
02582 if (is_array($dirs) && $recursivityLevels>0) {
02583 foreach ($dirs as $subdirs) {
02584 if ((string)$subdirs!='') {
02585 $fileArr = t3lib_div::getAllFilesAndFoldersInPath($fileArr,$path.$subdirs.'/',$extList,$regDirs,$recursivityLevels-1);
02586 }
02587 }
02588 }
02589 return $fileArr;
02590 }
02591
02600 function removePrefixPathFromList($fileArr,$prefixToRemove) {
02601 foreach($fileArr as $k => $absFileRef) {
02602 if(t3lib_div::isFirstPartOfStr($absFileRef,$prefixToRemove)) {
02603 $fileArr[$k] = substr($absFileRef,strlen($prefixToRemove));
02604 } else return 'ERROR: One or more of the files was NOT prefixed with the prefix-path!';
02605 }
02606 return $fileArr;
02607 }
02608
02616 function fixWindowsFilePath($theFile) {
02617 return str_replace('
02618 }
02619
02628 function resolveBackPath($pathStr) {
02629 $parts = explode('/',$pathStr);
02630 $output=array();
02631 $c = 0;
02632 foreach($parts as $pV) {
02633 if ($pV=='..') {
02634 if ($c) {
02635 array_pop($output);
02636 $c--;
02637 } else $output[]=$pV;
02638 } else {
02639 $c++;
02640 $output[]=$pV;
02641 }
02642 }
02643 return implode('/',$output);
02644 }
02645
02656 function locationHeaderUrl($path) {
02657 $uI = parse_url($path);
02658 if (substr($path,0,1)=='/') {
02659 $path = t3lib_div::getIndpEnv('TYPO3_REQUEST_HOST').$path;
02660 } elseif (!$uI['scheme']) {
02661 $path = t3lib_div::getIndpEnv('TYPO3_REQUEST_DIR').$path;
02662 }
02663 return $path;
02664 }
02665
02666
02667
02668
02669
02670
02671
02672
02673
02674
02675
02676
02677
02678
02679
02680
02681
02682
02683
02684
02685
02686
02696 function debug_ordvalue($string,$characters=100) {
02697 if(strlen($string) < $characters) $characters = strlen($string);
02698 for ($i=0; $i<$characters; $i++) {
02699 $valuestring.=' '.ord(substr($string,$i,1));
02700 }
02701 return trim($valuestring);
02702 }
02703
02713 function view_array($array_in) {
02714 if (is_array($array_in)) {
02715 $result='<table border="1" cellpadding="1" cellspacing="0" bgcolor="white">';
02716 if (!count($array_in)) {$result.= '<tr><td><font face="Verdana,Arial" size="1"><b>'.htmlspecialchars("EMPTY!").'</b></font></td></tr>';}
02717 while (list($key,$val)=each($array_in)) {
02718 $result.= '<tr><td valign="top"><font face="Verdana,Arial" size="1">'.htmlspecialchars((string)$key).'</font></td><td>';
02719 if (is_array($array_in[$key])) {
02720 $result.=t3lib_div::view_array($array_in[$key]);
02721 } else
02722 $result.= '<font face="Verdana,Arial" size="1" color="red">'.nl2br(htmlspecialchars((string)$val)).'<br /></font>';
02723 $result.= '</td></tr>';
02724 }
02725 $result.= '</table>';
02726 } else {
02727 $result = false;
02728 }
02729 return $result;
02730 }
02731
02741 function print_array($array_in) {
02742 echo t3lib_div::view_array($array_in);
02743 }
02744
02756 function debug($var="",$brOrHeader=0) {
02757 if ($brOrHeader && !t3lib_div::testInt($brOrHeader)) {
02758 echo '<table class="typo3-debug" border="0" cellpadding="0" cellspacing="0" bgcolor="white" style="border:0px; margin-top:3px; margin-bottom:3px;"><tr><td style="background-color:#bbbbbb; font-family: verdana,arial; font-weight: bold; font-size: 10px;">'.htmlspecialchars((string)$brOrHeader).'</td></tr><tr><td>';
02759 } elseif ($brOrHeader<0) {
02760 for($a=0;$a<abs(intval($brOrHeader));$a++){echo '<br />';}
02761 }
02762
02763 if (is_array($var)) {
02764 t3lib_div::print_array($var);
02765 } elseif (is_object($var)) {
02766 echo '<b>|Object:<pre>';
02767 print_r($var);
02768 echo '</pre>|</b>';
02769 } elseif ((string)$var!='') {
02770 echo '<b>|'.htmlspecialchars((string)$var).'|</b>';
02771 } else {
02772 echo '<b>| debug |</b>';
02773 }
02774
02775 if ($brOrHeader && !t3lib_div::testInt($brOrHeader)) {
02776 echo '</td></tr></table>';
02777 } elseif ($brOrHeader>0) {
02778 for($a=0;$a<intval($brOrHeader);$a++){echo '<br />';}
02779 }
02780 }
02781
02787 function debug_trail() {
02788 if (function_exists('debug_backtrace')) {
02789 $trail = debug_backtrace();
02790 $trail = array_reverse($trail);
02791 array_pop($trail);
02792
02793 $path = array();
02794 foreach($trail as $dat) {
02795 $path[] = $dat['class'].$dat['type'].$dat['function'];
02796 }
02797
02798 return implode('
02799 } else return 'N/A';
02800 }
02801
02809 function debugRows($rows,$header='') {
02810 if (is_array($rows)) {
02811 reset($rows);
02812 $firstEl = current($rows);
02813 if (is_array($firstEl)) {
02814 $headerColumns = array_keys($firstEl);
02815 $tRows = array();
02816
02817
02818 $tRows[] = '<tr><td colspan="'.count($headerColumns).'" style="background-color:#bbbbbb; font-family: verdana,arial; font-weight: bold; font-size: 10px;"><strong>'.htmlspecialchars($header).'</strong></td></tr>';
02819 $tCells = array();
02820 foreach($headerColumns as $key) {
02821 $tCells[] = '
02822 <td><font face="Verdana,Arial" size="1"><strong>'.htmlspecialchars($key).'</strong></font></td>';
02823 }
02824 $tRows[] = '
02825 <tr>'.implode('',$tCells).'
02826 </tr>';
02827
02828
02829 foreach($rows as $singleRow) {
02830 $tCells = array();
02831 foreach($headerColumns as $key) {
02832 $tCells[] = '
02833 <td><font face="Verdana,Arial" size="1">'.htmlspecialchars($singleRow[$key]).'</font></td>';
02834 }
02835 $tRows[] = '
02836 <tr>'.implode('',$tCells).'
02837 </tr>';
02838 }
02839
02840 $table = '
02841 <table border="1" cellpadding="1" cellspacing="0" bgcolor="white">'.implode('',$tRows).'
02842 </table>';
02843 echo $table;
02844 } else debug('Empty array of rows',$header);
02845 } else debug('No array of rows',$header);
02846 }
02847
02848
02849
02850
02851
02852
02853
02854
02855
02856
02857
02858
02859
02860
02861
02862
02863
02864
02865
02866
02867
02868
02869
02870
02871
02872
02873
02874
02875
02876
02877
02878
02879
02880
02887 function getThisUrl() {
02888 $p=parse_url(t3lib_div::getIndpEnv('TYPO3_REQUEST_SCRIPT'));
02889 $dir=t3lib_div::dirname($p['path']).'/';
02890 $url = str_replace('
02891 return $url;
02892 }
02893
02903 function linkThisScript($getParams=array()) {
02904 $parts = t3lib_div::getIndpEnv('SCRIPT_NAME');
02905 $params = t3lib_div::_GET();
02906
02907 foreach($getParams as $k => $v) {
02908 if (strcmp($v,'')) {
02909 $params[$k]=$v;
02910 } else unset($params[$k]);
02911 }
02912
02913 $pString = t3lib_div::implodeArrayForUrl('',$params);
02914
02915 return $pString ? $parts.'?'.ereg_replace('^&','',$pString) : $parts;
02916 }
02917
02927 function linkThisUrl($url,$getParams=array()) {
02928 $parts = parse_url($url);
02929 $getP = array();
02930 if ($parts['query']) {
02931 parse_str($parts['query'],$getP);
02932 }
02933 $getP = t3lib_div::array_merge_recursive_overrule($getP,$getParams);
02934 $uP = explode('?',$url);
02935
02936 $params = t3lib_div::implodeArrayForUrl('',$getP);
02937 $outurl = $uP[0].($params ? '?'.substr($params, 1) : '');
02938
02939 return $outurl;
02940 }
02941
02950 function getIndpEnv($getEnvName) {
02951
02952
02953
02954
02955
02956
02957
02958
02959
02960
02961
02962
02963
02964
02965
02966
02967
02968
02969
02970
02971
02972
02973
02974
02975
02976
02977
02978
02979
02980
02981
02982
02983
02984
02985
02986
02987
02988
02989
02990
02991
02992
02993
02994
02995
02996
02997
02998
02999
03000
03001
03002
03003
03004
03005
03006
03007
03008
03009
03010
03011 # if ($getEnvName=='HTTP_REFERER') return '';
03012
03013 $retVal = '';
03014
03015 switch((string)$getEnvName) {
03016 case 'SCRIPT_NAME':
03017 $retVal = (php_sapi_name()=='cgi'||php_sapi_name()=='cgi-fcgi')&&($_SERVER['ORIG_PATH_INFO']?$_SERVER['ORIG_PATH_INFO']:$_SERVER['PATH_INFO']) ? ($_SERVER['ORIG_PATH_INFO']?$_SERVER['ORIG_PATH_INFO']:$_SERVER['PATH_INFO']) : ($_SERVER['ORIG_SCRIPT_NAME']?$_SERVER['ORIG_SCRIPT_NAME']:$_SERVER['SCRIPT_NAME']);
03018 break;
03019 case 'SCRIPT_FILENAME':
03020 $retVal = str_replace('
03021 break;
03022 case 'REQUEST_URI':
03023
03024 if (!$_SERVER['REQUEST_URI']) {
03025 $retVal = '/'.ereg_replace('^/','',t3lib_div::getIndpEnv('SCRIPT_NAME')).
03026 ($_SERVER['QUERY_STRING']?'?'.$_SERVER['QUERY_STRING']:'');
03027 } else $retVal = $_SERVER['REQUEST_URI'];
03028 break;
03029 case 'PATH_INFO':
03030
03031
03032
03033
03034 if (php_sapi_name()!='cgi'&&php_sapi_name()!='cgi-fcgi') {
03035 $retVal = $_SERVER['PATH_INFO'];
03036 }
03037 break;
03038
03039 case 'REMOTE_ADDR':
03040 case 'REMOTE_HOST':
03041 case 'HTTP_REFERER':
03042 case 'HTTP_HOST':
03043 case 'HTTP_USER_AGENT':
03044 case 'HTTP_ACCEPT_LANGUAGE':
03045 case 'QUERY_STRING':
03046 $retVal = $_SERVER[$getEnvName];
03047 break;
03048 case 'TYPO3_DOCUMENT_ROOT':
03049
03050
03051 $SFN = t3lib_div::getIndpEnv('SCRIPT_FILENAME');
03052 $SN_A = explode('/',strrev(t3lib_div::getIndpEnv('SCRIPT_NAME')));
03053 $SFN_A = explode('/',strrev($SFN));
03054 $acc = array();
03055 while(list($kk,$vv)=each($SN_A)) {
03056 if (!strcmp($SFN_A[$kk],$vv)) {
03057 $acc[] = $vv;
03058 } else break;
03059 }
03060 $commonEnd=strrev(implode('/',$acc));
03061 if (strcmp($commonEnd,'')) { $DR = substr($SFN,0,-(strlen($commonEnd)+1)); }
03062 $retVal = $DR;
03063 break;
03064 case 'TYPO3_HOST_ONLY':
03065 $p = explode(':',$_SERVER['HTTP_HOST']);
03066 $retVal = $p[0];
03067 break;
03068 case 'TYPO3_PORT':
03069 $p = explode(':',$_SERVER['HTTP_HOST']);
03070 $retVal = $p[1];
03071 break;
03072 case 'TYPO3_REQUEST_HOST':
03073 $retVal = (t3lib_div::getIndpEnv('TYPO3_SSL') ? 'https:
03074 $_SERVER['HTTP_HOST'];
03075 break;
03076 case 'TYPO3_REQUEST_URL':
03077 $retVal = t3lib_div::getIndpEnv('TYPO3_REQUEST_HOST').t3lib_div::getIndpEnv('REQUEST_URI');
03078 break;
03079 case 'TYPO3_REQUEST_SCRIPT':
03080 $retVal = t3lib_div::getIndpEnv('TYPO3_REQUEST_HOST').t3lib_div::getIndpEnv('SCRIPT_NAME');
03081 break;
03082 case 'TYPO3_REQUEST_DIR':
03083 $retVal = t3lib_div::getIndpEnv('TYPO3_REQUEST_HOST').t3lib_div::dirname(t3lib_div::getIndpEnv('SCRIPT_NAME')).'/';
03084 break;
03085 case 'TYPO3_SITE_URL':
03086 if (defined('PATH_thisScript') && defined('PATH_site')) {
03087 $lPath = substr(dirname(PATH_thisScript),strlen(PATH_site)).'/';
03088 $url = t3lib_div::getIndpEnv('TYPO3_REQUEST_DIR');
03089 $siteUrl = substr($url,0,-strlen($lPath));
03090 if (substr($siteUrl,-1)!='/') $siteUrl.='/';
03091 $retVal = $siteUrl;
03092 }
03093 break;
03094 case 'TYPO3_SITE_SCRIPT':
03095 $retVal = substr(t3lib_div::getIndpEnv('TYPO3_REQUEST_URL'),strlen(t3lib_div::getIndpEnv('TYPO3_SITE_URL')));
03096 break;
03097 case 'TYPO3_SSL':
03098 $retVal = $_SERVER['SSL_SESSION_ID'] || !strcmp($_SERVER['HTTPS'],'on') ? TRUE : FALSE;
03099 break;
03100 case '_ARRAY':
03101 $out = array();
03102
03103 $envTestVars = t3lib_div::trimExplode(',','
03104 HTTP_HOST,
03105 TYPO3_HOST_ONLY,
03106 TYPO3_PORT,
03107 PATH_INFO,
03108 QUERY_STRING,
03109 REQUEST_URI,
03110 HTTP_REFERER,
03111 TYPO3_REQUEST_HOST,
03112 TYPO3_REQUEST_URL,
03113 TYPO3_REQUEST_SCRIPT,
03114 TYPO3_REQUEST_DIR,
03115 TYPO3_SITE_URL,
03116 TYPO3_SITE_SCRIPT,
03117 TYPO3_SSL,
03118 SCRIPT_NAME,
03119 TYPO3_DOCUMENT_ROOT,
03120 SCRIPT_FILENAME,
03121 REMOTE_ADDR,
03122 REMOTE_HOST,
03123 HTTP_USER_AGENT,
03124 HTTP_ACCEPT_LANGUAGE',1);
03125 reset($envTestVars);
03126 while(list(,$v)=each($envTestVars)) {
03127 $out[$v]=t3lib_div::getIndpEnv($v);
03128 }
03129 reset($out);
03130 $retVal = $out;
03131 break;
03132 }
03133 return $retVal;
03134 }
03135
03143 function milliseconds() {
03144 $p=explode(' ',microtime());
03145 return round(($p[0]+$p[1])*1000);
03146 }
03147
03155 function clientInfo($useragent='') {
03156 if (!$useragent) $useragent=t3lib_div::getIndpEnv('HTTP_USER_AGENT');
03157
03158 $bInfo=array();
03159
03160 if (strstr($useragent,'Konqueror')) {
03161 $bInfo['BROWSER']= 'konqu';
03162 } elseif (strstr($useragent,'Opera')) {
03163 $bInfo['BROWSER']= 'opera';
03164 } elseif (strstr($useragent,'MSIE 4') || strstr($useragent,'MSIE 5') || strstr($useragent,'MSIE 6')) {
03165 $bInfo['BROWSER']= 'msie';
03166 } elseif (strstr($useragent,'Mozilla/4') || strstr($useragent,'Mozilla/5')) {
03167 $bInfo['BROWSER']='net';
03168 }
03169 if ($bInfo['BROWSER']) {
03170
03171 switch($bInfo['BROWSER']) {
03172 case 'net':
03173 $bInfo['VERSION']= doubleval(substr($useragent,8));
03174 if (strstr($useragent,'Netscape6/')) {$bInfo['VERSION']=doubleval(substr(strstr($useragent,'Netscape6/'),10));}
03175 if (strstr($useragent,'Netscape/7')) {$bInfo['VERSION']=doubleval(substr(strstr($useragent,'Netscape/7'),9));}
03176 break;
03177 case 'msie':
03178 $tmp = strstr($useragent,'MSIE');
03179 $bInfo['VERSION'] = doubleval(ereg_replace('^[^0-9]*','',substr($tmp,4)));
03180 break;
03181 case 'opera':
03182 $tmp = strstr($useragent,'Opera');
03183 $bInfo['VERSION'] = doubleval(ereg_replace('^[^0-9]*','',substr($tmp,5)));
03184 break;
03185 case 'konqu':
03186 $tmp = strstr($useragent,'Konqueror/');
03187 $bInfo['VERSION'] = doubleval(substr($tmp,10));
03188 break;
03189 }
03190
03191 if (strstr($useragent,'Win')) {
03192 $bInfo['SYSTEM'] = 'win';
03193 } elseif (strstr($useragent,'Mac')) {
03194 $bInfo['SYSTEM'] = 'mac';
03195 } elseif (strstr($useragent,'Linux') || strstr($useragent,'X11') || strstr($useragent,'SGI') || strstr($useragent,' SunOS ') || strstr($useragent,' HP-UX ')) {
03196 $bInfo['SYSTEM'] = 'unix';
03197 }
03198 }
03199
03200 $bInfo['FORMSTYLE']=($bInfo['BROWSER']=='msie' || ($bInfo['BROWSER']=='net'&&$bInfo['VERSION']>=5) || $bInfo['BROWSER']=='opera' || $bInfo['BROWSER']=='konqu');
03201
03202 return $bInfo;
03203 }
03204
03205
03206
03207
03208
03209
03210
03211
03212
03213
03214
03215
03216
03217
03218
03219
03220
03221
03222
03223
03224
03225
03226
03227
03228
03229
03230
03231
03232
03242 function getFileAbsFileName($filename,$onlyRelative=1,$relToTYPO3_mainDir=0) {
03243 if (!strcmp($filename,'')) return '';
03244
03245 if ($relToTYPO3_mainDir) {
03246 if (!defined('PATH_typo3')) return '';
03247 $relPathPrefix = PATH_typo3;
03248 } else {
03249 $relPathPrefix = PATH_site;
03250 }
03251 if (substr($filename,0,4)=='EXT:') {
03252 list($extKey,$local) = explode('/',substr($filename,4),2);
03253 $filename='';
03254 if (strcmp($extKey,'') && t3lib_extMgm::isLoaded($extKey) && strcmp($local,'')) {
03255 $filename = t3lib_extMgm::extPath($extKey).$local;
03256 }
03257 } elseif (!t3lib_div::isAbsPath($filename)) {
03258 $filename=$relPathPrefix.$filename;
03259 } elseif ($onlyRelative && !t3lib_div::isFirstPartOfStr($filename,$relPathPrefix)) {
03260 $filename='';
03261 }
03262 if (strcmp($filename,'') && t3lib_div::validPathStr($filename)) {
03263 return $filename;
03264 }
03265 }
03266
03278 function validPathStr($theFile) {
03279 if (!strstr($theFile,'
03280 }
03281
03289 function isAbsPath($path) {
03290 return TYPO3_OS=='WIN' ? substr($path,1,2)==':/' : substr($path,0,1)=='/';
03291 }
03292
03300 function isAllowedAbsPath($path) {
03301 if (t3lib_div::isAbsPath($path) &&
03302 t3lib_div::validPathStr($path) &&
03303 ( t3lib_div::isFirstPartOfStr($path,PATH_site)
03304 ||
03305 ($GLOBALS['TYPO3_CONF_VARS']['BE']['lockRootPath'] && t3lib_div::isFirstPartOfStr($path,$GLOBALS['TYPO3_CONF_VARS']['BE']['lockRootPath']))
03306 )
03307 ) return true;
03308 }
03309
03317 function verifyFilenameAgainstDenyPattern($filename) {
03318 if (strcmp($filename,'') && strcmp($GLOBALS['TYPO3_CONF_VARS']['BE']['fileDenyPattern'],'')) {
03319 $result = eregi($GLOBALS['TYPO3_CONF_VARS']['BE']['fileDenyPattern'],$filename);
03320 if ($result) return false;
03321 }
03322 return true;
03323 }
03324
03335 function upload_copy_move($source,$destination) {
03336 if (is_uploaded_file($source)) {
03337 $uploaded = TRUE;
03338
03339 $uploadedResult = move_uploaded_file($source, $destination);
03340 } else {
03341 $uploaded = FALSE;
03342 @copy($source,$destination);
03343 }
03344
03345 t3lib_div::fixPermissions($destination);
03346
03347
03348 return $uploaded ? $uploadedResult : FALSE;
03349 }
03350
03361 function upload_to_tempfile($uploadedFileName) {
03362 if (is_uploaded_file($uploadedFileName)) {
03363 $tempFile = t3lib_div::tempnam('upload_temp_');
03364 move_uploaded_file($uploadedFileName, $tempFile);
03365 return @is_file($tempFile) ? $tempFile : '';
03366 }
03367 }
03368
03379 function unlink_tempfile($uploadedTempFileName) {
03380 if ($uploadedTempFileName && t3lib_div::validPathStr($uploadedTempFileName) && t3lib_div::isFirstPartOfStr($uploadedTempFileName,PATH_site.'typo3temp/') && @is_file($uploadedTempFileName)) {
03381 if (unlink($uploadedTempFileName)) return TRUE;
03382 }
03383 }
03384
03395 function tempnam($filePrefix) {
03396 return tempnam(PATH_site.'typo3temp/',$filePrefix);
03397 }
03398
03409 function stdAuthCode($uid_or_record,$fields='',$codeLength=8) {
03410
03411 if (is_array($uid_or_record)) {
03412 $recCopy_temp=array();
03413 if ($fields) {
03414 $fieldArr = t3lib_div::trimExplode(',',$fields,1);
03415 reset($fieldArr);
03416 while(list($k,$v)=each($fieldArr)) {
03417 $recCopy_temp[$k]=$uid_or_record[$v];
03418 }
03419 } else {
03420 $recCopy_temp=$uid_or_record;
03421 }
03422 $preKey = implode('|',$recCopy_temp);
03423 } else {
03424 $preKey = $uid_or_record;
03425 }
03426
03427 $authCode = $preKey.'||'.$GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'];
03428 $authCode = substr(md5($authCode),0,$codeLength);
03429 return $authCode;
03430 }
03431
03440 function cHashParams($addQueryParams) {
03441 $params = explode('&',substr($addQueryParams,1));
03442
03443
03444 $pA = array();
03445 foreach($params as $theP) {
03446 $pKV = explode('=', $theP);
03447 if (!t3lib_div::inList('id,type,no_cache,cHash,MP,ftu',$pKV[0])) {
03448 $pA[rawurldecode($pKV[0])] = (string)rawurldecode($pKV[1]);
03449 }
03450 }
03451 $pA['encryptionKey'] = $GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'];
03452 ksort($pA);
03453
03454 return $pA;
03455 }
03456
03463 function hideIfNotTranslated($l18n_cfg_fieldValue) {
03464 if ($GLOBALS['TYPO3_CONF_VARS']['FE']['hidePagesIfNotTranslatedByDefault']) {
03465 return $l18n_cfg_fieldValue&2 ? FALSE : TRUE;
03466 } else {
03467 return $l18n_cfg_fieldValue&2 ? TRUE : FALSE;
03468 }
03469 }
03470
03478 function readLLfile($fileRef,$langKey) {
03479
03480 $file = t3lib_div::getFileAbsFileName($fileRef);
03481 if ($file) {
03482 $baseFile = ereg_replace('\.(php|xml)$', '', $file);
03483
03484 if (@is_file($baseFile.'.xml')) {
03485 $LOCAL_LANG = t3lib_div::readLLXMLfile($baseFile.'.xml', $langKey);
03486 } elseif (@is_file($baseFile.'.php')) {
03487 include($baseFile.'.php');
03488 } else die('Filereference, "'.$file.'", not found!');
03489 }
03490
03491 return is_array($LOCAL_LANG)?$LOCAL_LANG:array();
03492 }
03493
03502 function readLLXMLfile($fileRef,$langKey) {
03503
03504 if (is_object($GLOBALS['LANG'])) {
03505 $csConvObj = &$GLOBALS['LANG']->csConvObj;
03506 } elseif (is_object($GLOBALS['TSFE'])) {
03507 $csConvObj = &$GLOBALS['TSFE']->csConvObj;
03508 } else $csConvObj = NULL;
03509
03510 if (@is_file($fileRef) && $langKey && is_object($csConvObj)) {
03511
03512
03513 $origCharset = $csConvObj->parse_charset($csConvObj->charSetArray[$langKey] ? $csConvObj->charSetArray[$langKey] : 'iso-8859-1');
03514
03515
03516 $hashSource = substr($fileRef,strlen(PATH_site)).'|'.date('d-m-Y H:i:s',filemtime($fileRef)).'|version=2.2';
03517 $cacheFileName = PATH_site.'typo3temp/llxml/'.
03518 #str_replace('_','',ereg_replace('^.*\/','',dirname($fileRef))).
03519 #'_'.basename($fileRef).
03520 substr(basename($fileRef),10,15).
03521 '_'.t3lib_div::shortMD5($hashSource).'.'.$langKey.'.'.$origCharset.'.cache';
03522
03523
03524 if (!@is_file($cacheFileName)) {
03525
03526
03527 $xmlString = t3lib_div::getUrl($fileRef);
03528 $xmlContent = t3lib_div::xml2array($xmlString);
03529 if (!is_array($xmlContent)) {
03530 die($fileRef.' was not XML!: '.$xmlContent);
03531 }
03532
03533
03534 $LOCAL_LANG = array();
03535 $LOCAL_LANG['default'] = $xmlContent['data']['default'];
03536
03537
03538
03539
03540
03541
03542 if (is_array($LOCAL_LANG['default'])) {
03543 foreach($LOCAL_LANG['default'] as $labelKey => $labelValue) {
03544 $LOCAL_LANG['default'][$labelKey] = $csConvObj->utf8_decode($labelValue,'iso-8859-1');
03545 }
03546 }
03547
03548
03549
03550 if ($langKey!='default') {
03551
03552
03553 if (!isset($xmlContent['data'][$langKey])) {
03554 $LOCAL_LANG[$langKey] = t3lib_div::llXmlAutoFileName($fileRef, $langKey);
03555 } else {
03556 $LOCAL_LANG[$langKey] = $xmlContent['data'][$langKey];
03557 }
03558
03559
03560 if (is_array($LOCAL_LANG[$langKey]) && $origCharset!='utf-8') {
03561 foreach($LOCAL_LANG[$langKey] as $labelKey => $labelValue) {
03562 $LOCAL_LANG[$langKey][$labelKey] = $csConvObj->utf8_decode($labelValue,$origCharset);
03563 }
03564 }
03565 }
03566
03567
03568 $serContent = array('origFile'=>$hashSource, 'LOCAL_LANG'=>$LOCAL_LANG);
03569 $res = t3lib_div::writeFileToTypo3tempDir($cacheFileName, serialize($serContent));
03570 if ($res) die('ERROR: '.$res);
03571 } else {
03572
03573 $serContent = unserialize(t3lib_div::getUrl($cacheFileName));
03574 $LOCAL_LANG = $serContent['LOCAL_LANG'];
03575 }
03576
03577
03578 if ($langKey!='default' && is_string($LOCAL_LANG[$langKey]) && strlen($LOCAL_LANG[$langKey])) {
03579
03580
03581 $localized_file = t3lib_div::getFileAbsFileName($LOCAL_LANG[$langKey]);
03582 if ($localized_file && @is_file($localized_file)) {
03583
03584
03585 $hashSource = substr($localized_file,strlen(PATH_site)).'|'.date('d-m-Y H:i:s',filemtime($localized_file));
03586 $cacheFileName = PATH_site.'typo3temp/llxml/ext_'.
03587 substr(basename($localized_file),10,15).
03588 '_'.t3lib_div::shortMD5($hashSource).'.'.$langKey.'.'.$origCharset.'.cache';
03589
03590
03591 if (!@is_file($cacheFileName)) {
03592
03593
03594 $local_xmlString = t3lib_div::getUrl($localized_file);
03595 $local_xmlContent = t3lib_div::xml2array($local_xmlString);
03596 $LOCAL_LANG[$langKey] = is_array($local_xmlContent['data'][$langKey]) ? $local_xmlContent['data'][$langKey] : array();
03597
03598
03599 if (is_array($LOCAL_LANG[$langKey]) && $origCharset!='utf-8') {
03600 foreach($LOCAL_LANG[$langKey] as $labelKey => $labelValue) {
03601 $LOCAL_LANG[$langKey][$labelKey] = $csConvObj->utf8_decode($labelValue,$origCharset);
03602 }
03603 }
03604
03605
03606 $serContent = array('extlang'=>$langKey, 'origFile'=>$LOCAL_LANG[$langKey], 'EXT_DATA'=>$LOCAL_LANG[$langKey]);
03607 $res = t3lib_div::writeFileToTypo3tempDir($cacheFileName, serialize($serContent));
03608 if ($res) die('ERROR: '.$res);
03609 } else {
03610
03611 $serContent = unserialize(t3lib_div::getUrl($cacheFileName));
03612 $LOCAL_LANG[$langKey] = $serContent['EXT_DATA'];
03613 }
03614 } else {
03615 $LOCAL_LANG[$langKey] = array();
03616 }
03617 }
03618
03619 return $LOCAL_LANG;
03620 }
03621 }
03622
03630 function llXmlAutoFileName($fileRef,$language) {
03631
03632
03633 $location = 'typo3conf/l10n/'.$language.'/';
03634 if (t3lib_div::isFirstPartOfStr($fileRef,PATH_site.TYPO3_mainDir.'sysext/')) {
03635 $validatedPrefix = PATH_site.TYPO3_mainDir.'sysext/';
03636 #$location = 'EXT:csh_'.$language.'/'; // For system extensions translations are found in "csh_*" extensions (language packs)
03637 } elseif (t3lib_div::isFirstPartOfStr($fileRef,PATH_site.TYPO3_mainDir.'ext/')) {
03638 $validatedPrefix = PATH_site.TYPO3_mainDir.'ext/';
03639 } elseif (t3lib_div::isFirstPartOfStr($fileRef,PATH_site.'typo3conf/ext/')) {
03640 $validatedPrefix = PATH_site.'typo3conf/ext/';
03641 } else {
03642 $validatedPrefix = '';
03643 }
03644
03645 if ($validatedPrefix) {
03646
03647
03648 list($file_extKey,$file_extPath) = explode('/',substr($fileRef,strlen($validatedPrefix)),2);
03649 $temp = t3lib_div::revExplode('/',$file_extPath,2);
03650 if (count($temp)==1) array_unshift($temp,'');
03651 list($file_extPath,$file_fileName) = $temp;
03652
03653
03654 return $location.
03655 $file_extKey.'/'.
03656 ($file_extPath?$file_extPath.'/':'').
03657 $language.'.'.$file_fileName;
03658 } else return NULL;
03659 }
03660
03661
03674 function loadTCA($table) {
03675 global $TCA,$LANG_GENERAL_LABELS;
03676 if (isset($TCA[$table]) && !is_array($TCA[$table]['columns']) && $TCA[$table]['ctrl']['dynamicConfigFile']) {
03677 if (!strcmp(substr($TCA[$table]['ctrl']['dynamicConfigFile'],0,6),'T3LIB:')) {
03678 include(PATH_t3lib.'stddb/'.substr($TCA[$table]['ctrl']['dynamicConfigFile'],6));
03679 } elseif (t3lib_div::isAbsPath($TCA[$table]['ctrl']['dynamicConfigFile']) && @is_file($TCA[$table]['ctrl']['dynamicConfigFile'])) {
03680 include($TCA[$table]['ctrl']['dynamicConfigFile']);
03681 } else include(PATH_typo3conf.$TCA[$table]['ctrl']['dynamicConfigFile']);
03682 }
03683 }
03684
03694 function resolveSheetDefInDS($dataStructArray,$sheet='sDEF') {
03695 if (!is_array ($dataStructArray)) return 'Data structure must be an array';
03696
03697 if (is_array($dataStructArray['sheets'])) {
03698 $singleSheet = FALSE;
03699 if (!isset($dataStructArray['sheets'][$sheet])) {
03700 $sheet='sDEF';
03701 }
03702 $dataStruct = $dataStructArray['sheets'][$sheet];
03703
03704
03705 if ($dataStruct && !is_array($dataStruct)) {
03706 $file = t3lib_div::getFileAbsFileName($dataStruct);
03707 if ($file && @is_file($file)) {
03708 $dataStruct = t3lib_div::xml2array(t3lib_div::getUrl($file));
03709 }
03710 }
03711 } else {
03712 $singleSheet = TRUE;
03713 $dataStruct = $dataStructArray;
03714 if (isset($dataStruct['meta'])) unset($dataStruct['meta']);
03715 $sheet = 'sDEF';
03716 }
03717 return array($dataStruct,$sheet,$singleSheet);
03718 }
03719
03727 function resolveAllSheetsInDS($dataStructArray) {
03728 if (is_array($dataStructArray['sheets'])) {
03729 $out=array('sheets'=>array());
03730 foreach($dataStructArray['sheets'] as $sheetId => $sDat) {
03731 list($ds,$aS) = t3lib_div::resolveSheetDefInDS($dataStructArray,$sheetId);
03732 if ($sheetId==$aS) {
03733 $out['sheets'][$aS]=$ds;
03734 }
03735 }
03736 } else {
03737 list($ds) = t3lib_div::resolveSheetDefInDS($dataStructArray);
03738 $out = array('sheets' => array('sDEF' => $ds));
03739 }
03740 return $out;
03741 }
03742
03756 function callUserFunction($funcName,&$params,&$ref,$checkPrefix='user_',$silent=0) {
03757 global $TYPO3_CONF_VARS;
03758
03759
03760 if (is_array($GLOBALS['T3_VAR']['callUserFunction'][$funcName])) {
03761 return call_user_func(
03762 array(&$GLOBALS['T3_VAR']['callUserFunction'][$funcName]['obj'],
03763 $GLOBALS['T3_VAR']['callUserFunction'][$funcName]['method']),
03764 $params,
03765 $ref
03766 );
03767 }
03768
03769
03770 if (strstr($funcName,':')) {
03771 list($file,$funcRef) = t3lib_div::revExplode(':',$funcName,2);
03772 $requireFile = t3lib_div::getFileAbsFileName($file);
03773 if ($requireFile) require_once($requireFile);
03774 } else {
03775 $funcRef = $funcName;
03776 }
03777
03778
03779 if (substr($funcRef,0,1)=='&') {
03780 $funcRef = substr($funcRef,1);
03781 $storePersistentObject = TRUE;
03782 } else {
03783 $storePersistentObject = FALSE;
03784 }
03785
03786
03787 if ($checkPrefix &&
03788 !t3lib_div::isFirstPartOfStr(trim($funcRef),$checkPrefix) &&
03789 !t3lib_div::isFirstPartOfStr(trim($funcRef),'tx_')
03790 ) {
03791 if (!$silent) debug("Function/Class '".$funcRef."' was not prepended with '".$checkPrefix."'",1);
03792 return FALSE;
03793 }
03794
03795
03796 $parts = explode('->',$funcRef);
03797 if (count($parts)==2) {
03798
03799
03800 if (class_exists($parts[0])) {
03801
03802
03803 if ($storePersistentObject) {
03804 if (!is_object($GLOBALS['T3_VAR']['callUserFunction_classPool'][$parts[0]])) {
03805 $GLOBALS['T3_VAR']['callUserFunction_classPool'][$parts[0]] = &t3lib_div::makeInstance($parts[0]);
03806 }
03807 $classObj = &$GLOBALS['T3_VAR']['callUserFunction_classPool'][$parts[0]];
03808 } else {
03809 $classObj = &t3lib_div::makeInstance($parts[0]);
03810 }
03811
03812 if (method_exists($classObj, $parts[1])) {
03813
03814
03815 if ($storePersistentObject) {
03816 $GLOBALS['T3_VAR']['callUserFunction'][$funcName] = array (
03817 'method' => $parts[1],
03818 'obj' => &$classObj
03819 );
03820 }
03821
03822 $content = call_user_func(
03823 array(&$classObj, $parts[1]),
03824 $params,
03825 $ref
03826 );
03827 } else {
03828 if (!$silent) debug("<strong>ERROR:</strong> No method name '".$parts[1]."' in class ".$parts[0],1);
03829 }
03830 } else {
03831 if (!$silent) debug("<strong>ERROR:</strong> No class named: ".$parts[0],1);
03832 }
03833 } else {
03834 if (function_exists($funcRef)) {
03835 $content = call_user_func($funcRef, $params, $ref);
03836 } else {
03837 if (!$silent) debug("<strong>ERROR:</strong> No function named: ".$funcRef,1);
03838 }
03839 }
03840 return $content;
03841 }
03842
03854 function &getUserObj($classRef,$checkPrefix='user_',$silent=0) {
03855 global $TYPO3_CONF_VARS;
03856
03857 if (is_object($GLOBALS['T3_VAR']['getUserObj'][$classRef])) {
03858 return $GLOBALS['T3_VAR']['getUserObj'][$classRef];
03859 } else {
03860
03861
03862 if (strstr($classRef,':')) {
03863 list($file,$class) = t3lib_div::revExplode(':',$classRef,2);
03864 $requireFile = t3lib_div::getFileAbsFileName($file);
03865 if ($requireFile) require_once($requireFile);
03866 } else {
03867 $class = $classRef;
03868 }
03869
03870
03871 if (substr($class,0,1)=='&') {
03872 $class = substr($class,1);
03873 $storePersistentObject = TRUE;
03874 } else {
03875 $storePersistentObject = FALSE;
03876 }
03877
03878
03879 if ($checkPrefix &&
03880 !t3lib_div::isFirstPartOfStr(trim($class),$checkPrefix) &&
03881 !t3lib_div::isFirstPartOfStr(trim($class),'tx_')
03882 ) {
03883 if (!$silent) debug("Class '".$class."' was not prepended with '".$checkPrefix."'",1);
03884 return FALSE;
03885 }
03886
03887
03888 if (class_exists($class)) {
03889 $classObj = &t3lib_div::makeInstance($class);
03890
03891
03892 if ($storePersistentObject) {
03893 $GLOBALS['T3_VAR']['getUserObj'][$classRef] = &$classObj;
03894 }
03895
03896 return $classObj;
03897 } else {
03898 if (!$silent) debug("<strong>ERROR:</strong> No class named: ".$class,1);
03899 }
03900 }
03901 }
03902
03912 function &makeInstance($className) {
03913 return class_exists('ux_'.$className) ? t3lib_div::makeInstance('ux_'.$className) : new $className;
03914 }
03915
03924 function makeInstanceClassName($className) {
03925 return class_exists('ux_'.$className) ? t3lib_div::makeInstanceClassName('ux_'.$className) : $className;
03926 }
03927
03938 function &makeInstanceService($serviceType, $serviceSubType='', $excludeServiceKeys=array()) {
03939 global $T3_SERVICES, $T3_VAR, $TYPO3_CONF_VARS;
03940
03941 $error = FALSE;
03942
03943 if (!is_array($excludeServiceKeys) ) {
03944 $excludeServiceKeys = t3lib_div::trimExplode(',', $excludeServiceKeys, 1);
03945 }
03946 while ($info = t3lib_extMgm::findService($serviceType, $serviceSubType, $excludeServiceKeys)) {
03947
03948
03949 if (is_object($GLOBALS['T3_VAR']['makeInstanceService'][$info['className']])) {
03950
03951 $T3_VAR['makeInstanceService'][$info['className']]->reset();
03952 return $GLOBALS['T3_VAR']['makeInstanceService'][$info['className']];
03953
03954
03955 } else {
03956 $requireFile = t3lib_div::getFileAbsFileName($info['classFile']);
03957 if (@is_file($requireFile)) {
03958 require_once ($requireFile);
03959 $obj = t3lib_div::makeInstance($info['className']);
03960 if (is_object($obj)) {
03961 if(!@is_callable(array($obj,'init'))) {
03962
03963 die ('Broken service:'.t3lib_div::view_array($info));
03964 }
03965 $obj->info = $info;
03966 if ($obj->init()) {
03967
03968
03969 $T3_VAR['makeInstanceService'][$info['className']] = &$obj;
03970
03971
03972 register_shutdown_function(array(&$obj, '__destruct'));
03973
03974 return $obj;
03975 }
03976 $error = $obj->getLastErrorArray();
03977 unset($obj);
03978 }
03979 }
03980 }
03981
03982 t3lib_extMgm::deactivateService($info['serviceType'],$info['serviceKey']);
03983 }
03984 return $error;
03985 }
03986
04002 function plainMailEncoded($email,$subject,$message,$headers='',$enc='',$charset='',$dontEncodeHeader=false) {
04003 if (!$charset) {
04004 $charset = $GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset'] ? $GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset'] : 'ISO-8859-1';
04005 }
04006
04007 if (!$dontEncodeHeader) {
04008
04009 $newHeaders=array();
04010 foreach (explode(chr(10),$headers) as $line) {
04011 $parts = explode(': ',$line,2);
04012 if (count($parts)==2) {
04013 $parts[1] = t3lib_div::encodeHeader($parts[1],$enc,$charset);
04014 $newHeaders[] = implode(': ',$parts);
04015 } else {
04016 $newHeaders[] = $line;
04017 }
04018 }
04019 $headers = implode(chr(10),$newHeaders);
04020 unset($newHeaders);
04021
04022 $email = t3lib_div::encodeHeader($email,$enc,$charset);
04023 $subject = t3lib_div::encodeHeader($subject,$enc,$charset);
04024 }
04025
04026 switch ((string)$enc) {
04027 case 'base64':
04028 $headers=trim($headers).chr(10).
04029 'Mime-Version: 1.0'.chr(10).
04030 'Content-Type: text/plain; charset="'.$charset.'"'.chr(10).
04031 'Content-Transfer-Encoding: base64';
04032
04033 $message=trim(chunk_split(base64_encode($message.chr(10)))).chr(10);
04034 break;
04035 case '8bit':
04036 $headers=trim($headers).chr(10).
04037 'Mime-Version: 1.0'.chr(10).
04038 'Content-Type: text/plain; charset='.$charset.chr(10).
04039 'Content-Transfer-Encoding: 8bit';
04040 break;
04041 case 'quoted-printable':
04042 default:
04043 $headers=trim($headers).chr(10).
04044 'Mime-Version: 1.0'.chr(10).
04045 'Content-Type: text/plain; charset='.$charset.chr(10).
04046 'Content-Transfer-Encoding: quoted-printable';
04047
04048 $message=t3lib_div::quoted_printable($message);
04049 break;
04050 }
04051
04052 $linebreak = chr(10);
04053 if (TYPO3_OS=='WIN') {
04054 $linebreak = chr(13).chr(10);
04055 }
04056
04057 $headers=trim(implode($linebreak,t3lib_div::trimExplode(chr(10),$headers,1)));
04058
04059 mail($email,$subject,$message,$headers);
04060 }
04061
04072 function quoted_printable($string,$maxlen=76) {
04073
04074 $string = str_replace(chr(13).chr(10), chr(10), $string);
04075 $string = str_replace(chr(13), chr(10), $string);
04076
04077 $linebreak = chr(10);
04078 if (TYPO3_OS=='WIN') {
04079 $linebreak = chr(13).chr(10);
04080 }
04081
04082 $newString = '';
04083 $theLines = explode(chr(10),$string);
04084 foreach ($theLines as $val) {
04085 $newVal = '';
04086 $theValLen = strlen($val);
04087 $len = 0;
04088 for ($index=0; $index < $theValLen; $index++) {
04089 $char = substr($val,$index,1);
04090 $ordVal = ord($char);
04091 if ($len>($maxlen-4) || ($len>(($maxlen-10)-4)&&$ordVal==32)) {
04092 $newVal.='='.$linebreak;
04093 $len=0;
04094 }
04095 if (($ordVal>=33 && $ordVal<=60) || ($ordVal>=62 && $ordVal<=126) || $ordVal==9 || $ordVal==32) {
04096 $newVal.=$char;
04097 $len++;
04098 } else {
04099 $newVal.=sprintf('=%02X',$ordVal);
04100 $len+=3;
04101 }
04102 }
04103 $newVal = preg_replace('/'.chr(32).'$/','=20',$newVal);
04104 $newVal = preg_replace('/'.chr(9).'$/','=09',$newVal);
04105 $newString.=$newVal.$linebreak;
04106 }
04107 return preg_replace('/'.$linebreak.'$/','',$newString);
04108 }
04109
04119 function encodeHeader($line,$enc='',$charset='ISO-8859-1') {
04120
04121 if (strstr($line,'###')) return $line;
04122
04123
04124 if (!preg_match('/[^'.chr(32).'-'.chr(127).']/',$line)) return $line;
04125
04126
04127 $line = preg_replace('/([^ ]+@[^ ]+)/', '###$1###', $line);
04128
04129 $matches = preg_split('/(.?###.+###.?|\(|\))/', $line, -1, PREG_SPLIT_NO_EMPTY);
04130 foreach ($matches as $part) {
04131 $oldPart = $part;
04132 switch ((string)$enc) {
04133 case 'base64':
04134 $part = '=?'.$charset.'?B?'.base64_encode($part).'?=';
04135 break;
04136 case 'quoted-printable':
04137 default:
04138 $qpValue = t3lib_div::quoted_printable($part,1000);
04139 if ($part!=$qpValue) {
04140 $qpValue = str_replace(' ','_',$qpValue);
04141 $part = '=?'.$charset.'?Q?'.$qpValue.'?=';
04142 }
04143 }
04144 $line = str_replace($oldPart, $part, $line);
04145 }
04146 $line = preg_replace('/###(.+?)###/', '$1', $line);
04147
04148 return $line;
04149 }
04150
04162 function substUrlsInPlainText($message,$urlmode='76',$index_script_url='') {
04163
04164 $urlSplit=explode('http:
04165 reset($urlSplit);
04166 while(list($c,$v)=each($urlSplit)) {
04167 if ($c) {
04168 $newParts = preg_split('/\s|[<>"{}|\\\^`()\']/', $v, 2);
04169 $newURL='http://'.$newParts[0];
04170 switch((string)$urlmode) {
04171 case 'all':
04172 $newURL=t3lib_div::makeRedirectUrl($newURL,0,$index_script_url);
04173 break;
04174 case '76':
04175 $newURL=t3lib_div::makeRedirectUrl($newURL,76,$index_script_url);
04176 break;
04177 }
04178 $urlSplit[$c]=$newURL.substr($v,strlen($newParts[0]));
04179 }
04180 }
04181
04182 $message=implode('',$urlSplit);
04183 return $message;
04184 }
04185
04196 function makeRedirectUrl($inUrl,$l=0,$index_script_url='') {
04197 if (strlen($inUrl)>$l) {
04198 $md5 = substr(md5($inUrl),0,20);
04199 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('md5hash', 'cache_md5params', 'md5hash='.$GLOBALS['TYPO3_DB']->fullQuoteStr($md5, 'cache_md5params'));
04200 if (!$GLOBALS['TYPO3_DB']->sql_num_rows($res)) {
04201 $insertFields = array(
04202 'md5hash' => $md5,
04203 'tstamp' => time(),
04204 'type' => 2,
04205 'params' => $inUrl
04206 );
04207
04208 $GLOBALS['TYPO3_DB']->exec_INSERTquery('cache_md5params', $insertFields);
04209 }
04210 $inUrl=($index_script_url ? $index_script_url : t3lib_div::getIndpEnv('TYPO3_REQUEST_DIR').'index.php').
04211 '?RDCT='.$md5;
04212 }
04213 return $inUrl;
04214 }
04215
04223 function freetypeDpiComp($font_size) {
04224 $dpi = intval($GLOBALS['TYPO3_CONF_VARS']['GFX']['TTFdpi']);
04225 if ($dpi!=72) $font_size = $font_size/$dpi*72;
04226 return $font_size;
04227 }
04228
04235 function initSysLog() {
04236 global $TYPO3_CONF_VARS;
04237
04238 // for CLI logging name is <fqdn-hostname>:<TYPO3-path>
04239 if (defined('TYPO3_cliMode') && TYPO3_cliMode) {
04240 // find FQDN
04241 $host = php_uname('n');
04242 if (strpos($host,'.') === FALSE) {
04243 $ip = gethostbyname($host);
04244 $fqdn = gethostbyaddr($ip);
04245 if ($ip != $fqdn) $host = $fqdn;
04246 }
04247 $TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_div.php']['systemLogHost'] = $TYPO3_CONF_VARS['SYS']['systemLogHost'] = $host.':'.PATH_site;
04248 }
04249 // for Web logging name is <protocol>://<request-hostame>
04250 else {
04251 $TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_div.php']['systemLogHost'] = t3lib_div::getIndpEnv('TYPO3_REQUEST_HOST');
04252 }
04253
04254 // init custom logging
04255 if (is_array($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_div.php']['systemLog'])) {
04256 $params = array('initLog'=>TRUE);
04257 $fakeThis = FALSE;
04258 foreach($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_div.php']['systemLog'] as $hookMethod) {
04259 t3lib_div::callUserFunction($hookMethod,$params,$fakeThis);
04260 }
04261 }
04262
04263 // init TYPO3 logging
04264 foreach (explode(';',$TYPO3_CONF_VARS['SYS']['systemLog'],2) as $log) {
04265 list($type,$destination) = explode(',',$log,3);
04266
04267 if ($type == 'syslog') {
04268 define_syslog_variables();
04269 if (TYPO3_OS == 'WIN') {
04270 $facility = LOG_USER;
04271 } else {
04272 $facility = constant('LOG_'.strtoupper($destination));
04273 }
04274 openlog($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_div.php']['systemLogHost'], LOG_ODELAY, $facility);
04275 }
04276 }
04277
04278 $TYPO3_CONF_VARS['SYS']['systemLogLevel'] = t3lib_div::intInRange($TYPO3_CONF_VARS['SYS']['systemLogLevel'],0,4);
04279 $TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_div.php']['systemLogInit'] = TRUE;
04280 }
04281
04292 function sysLog($msg, $extKey, $severity=0) {
04293 global $TYPO3_CONF_VARS;
04294
04295 $severity = t3lib_div::intInRange($severity,0,4);
04296
04297 // is message worth logging?
04298 if (intval($TYPO3_CONF_VARS['SYS']['systemLogLevel']) > $severity) return;
04299
04300 // initialize logging
04301 if (!$TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_div.php']['systemLogInit']) {
04302 t3lib_div::initSysLog();
04303 }
04304
04305 // do custom logging
04306 if (is_array($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_div.php']['systemLog'])) {
04307 $params = array('msg'=>$msg, 'extKey'=>$extKey);
04308 if (function_exists('debug_backtrace')) {
04309 $params['backTrace'] = debug_backtrace();
04310 }
04311 $fakeThis = FALSE;
04312 foreach($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_div.php']['systemLog'] as $hookMethod) {
04313 t3lib_div::callUserFunction($hookMethod,$params,$fakeThis);
04314 }
04315 }
04316
04317 // TYPO3 logging enabled?
04318 if (!$TYPO3_CONF_VARS['SYS']['systemLog']) return;
04319
04320 // use all configured logging options
04321 foreach (explode(';',$TYPO3_CONF_VARS['SYS']['systemLog'],2) as $log) {
04322 list($type,$destination,$level) = explode(',',$log,4);
04323
04324 // is message worth logging for this log type?
04325 if (intval($level) > $severity) continue;
04326
04327 $msgLine = ' - '.$extKey.': '.$msg;
04328
04329 // write message to a file
04330 if ($type == 'file') {
04331 $file = fopen($destination, 'a');
04332 if ($file) {
04333 flock($file, LOCK_EX); // try locking, but ignore if not available (eg. on NFS and FAT)
04334 fwrite($file, date('d/m/Y i:H').$msgLine.char(10));
04335 flock($file, LOCK_UN); // release the lock
04336 fclose($file);
04337 }
04338 }
04339 // send message per mail
04340 elseif ($type == 'mail') {
04341 list($to,$from) = explode('/',$destination);
04342 mail($to, 'Warning - error in TYPO3 installation',
04343 'Host: '.$TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_div.php']['systemLogHost']."\n".
04344 'Extension: '.$extKey."\n".
04345 'Severity: '.$severity."\n".
04346 "\n".$msg,
04347 ($from ? 'From: '.$from : '')
04348 );
04349 }
04350 // use the PHP error log
04351 elseif ($type == 'error_log') {
04352 error_log($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_div.php']['systemLogHost'].$msgLine, 0);
04353 }
04354 // use the system log
04355 elseif ($type == 'syslog') {
04356 $priority = array(LOG_INFO,LOG_NOTICE,LOG_WARNING,LOG_ERR,LOG_CRIT);
04357 syslog($priority[(int)$severity], $msgLine);
04358 }
04359 }
04360 }
04361
04375 function devLog($msg, $extKey, $severity=0, $dataVar=FALSE) {
04376 global $TYPO3_CONF_VARS;
04377
04378 if (is_array($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_div.php']['devLog'])) {
04379 $params = array('msg'=>$msg, 'extKey'=>$extKey, 'severity'=>$severity, 'dataVar'=>$dataVar);
04380 $fakeThis = FALSE;
04381 foreach($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_div.php']['devLog'] as $hookMethod) {
04382 t3lib_div::callUserFunction($hookMethod,$params,$fakeThis);
04383 }
04384 }
04385 }
04386
04396 function arrayToLogString($arr, $valueList=array(), $valueLength=20) {
04397 $str = '';
04398 if(is_array($arr)) {
04399 if (!is_array($valueList)) {
04400 $valueList = explode(',', $valueList);
04401 }
04402 foreach($arr as $key => $value) {
04403 if (!count($valueList) OR (count($valueList) AND in_array($key, $valueList))) {
04404 $str .= (string)$key.trim(': '.t3lib_div::fixed_lgd(str_replace("\n",'|',(string)$value), $valueLength)).'; ';
04405 }
04406 }
04407 }
04408 return $str;
04409 }
04410
04419 function imageMagickCommand($command, $parameters, $path='') {
04420 $gfxConf = $GLOBALS['TYPO3_CONF_VARS']['GFX'];
04421 $isExt = (TYPO3_OS=='WIN' ? '.exe' : '');
04422 $switchCompositeParameters=false;
04423
04424 if(!$path) { $path = $gfxConf['im_path']; }
04425
04426 $im_version = strtolower($gfxConf['im_version_5']);
04427 $combineScript = $gfxConf['im_combine_filename'] ? trim($gfxConf['im_combine_filename']) : 'combine';
04428
04429 if($command==='combine') { // This is only used internally, has no effect outside
04430 $command = 'composite';
04431 }
04432
04433 // Compile the path & command
04434 if($im_version==='gm') {
04435 $switchCompositeParameters=true;
04436 $path .= 'gm'.$isExt.' '.$command;
04437 } else {
04438 if($im_version==='im6') { $switchCompositeParameters=true; }
04439 $path .= (($command=='composite') ? $combineScript : $command).$isExt;
04440 }
04441
04442 $cmdLine = $path.' '.$parameters;
04443
04444 if($command=='composite' && $switchCompositeParameters) { // Because of some weird incompatibilities between ImageMagick 4 and 6 (plus GraphicsMagick), it is needed to change the parameters order under some preconditions
04445 $paramsArr = t3lib_div::unQuoteFilenames($parameters);
04446
04447 if(count($paramsArr)>5) { // The mask image has been specified => swap the parameters
04448 $tmp = $paramsArr[count($paramsArr)-3];
04449 $paramsArr[count($paramsArr)-3] = $paramsArr[count($paramsArr)-4];
04450 $paramsArr[count($paramsArr)-4] = $tmp;
04451 }
04452
04453 $cmdLine = $path.' '.implode(' ', $paramsArr);
04454 }
04455
04456 return $cmdLine;
04457 }
04458
04466 function unQuoteFilenames($parameters,$unQuote=FALSE) {
04467 $paramsArr = explode(' ', trim($parameters));
04468
04469 $quoteActive = -1; // Whenever a quote character (") is found, $quoteActive is set to the element number inside of $params. A value of -1 means that there are not open quotes at the current position.
04470 foreach($paramsArr as $k=>$v) {
04471 if($quoteActive > -1) {
04472 $paramsArr[$quoteActive] .= ' '.$v;
04473 unset($paramsArr[$k]);
04474 if(ereg('"$', $v)) { $quoteActive = -1; }
04475
04476 } elseif(!trim($v)) {
04477 unset($paramsArr[$k]); // Remove empty elements
04478
04479 } elseif(ereg('^"', $v)) {
04480 $quoteActive = $k;
04481 }
04482 }
04483
04484 if($unQuote) {
04485 foreach($paramsArr as $key=>$val) {
04486 $paramsArr[$key]=preg_replace('/(^"|"$)/','',$val);
04487 }
04488 }
04489 return $paramsArr;
04490 }
04491
04492
04500 function quoteJSvalue($value, $inScriptTags = false) {
04501 $value = addcslashes($value, '\''.chr(10).chr(13));
04502 if (!$inScriptTags) {
04503 $value = htmlspecialchars($value);
04504 }
04505 return '\''.$value.'\'';
04506 }
04507
04508
04509 }
04510
04511 ?>