2 namespace TYPO3\CMS\Core\Utility;
139 public static function _GP($var)
144 $value = isset($_POST[$var]) ? $_POST[$var] : $_GET[$var];
146 if (isset($value) && !is_array($value)) {
147 $value = (string)$value;
160 $postParameter = isset($_POST[$parameter]) && is_array($_POST[$parameter]) ? $_POST[$parameter] : array();
161 $getParameter = isset($_GET[$parameter]) && is_array($_GET[$parameter]) ? $_GET[$parameter] : array();
162 $mergedParameters = $getParameter;
164 return $mergedParameters;
176 public static function _GET($var = null)
178 $value = $var === null ? $_GET : (empty($var) ? null : $_GET[$var]);
180 if (isset($value) && !is_array($value)) {
181 $value = (string)$value;
194 public static function _POST($var = null)
196 $value = $var === null ? $_POST : (empty($var) ? null : $_POST[$var]);
198 if (isset($value) && !is_array($value)) {
199 $value = (string)$value;
211 public static function _GETset($inputGet, $key =
'')
214 if (strpos($key,
'|') !==
false) {
215 $pieces = explode(
'|', $key);
218 foreach ($pieces as $piece) {
219 $pointer = &$pointer[$piece];
221 $pointer = $inputGet;
225 $GLOBALS[
'HTTP_GET_VARS'] = $mergedGet;
227 $_GET[$key] = $inputGet;
228 $GLOBALS[
'HTTP_GET_VARS'][$key] = $inputGet;
230 }
elseif (is_array($inputGet)) {
232 $GLOBALS[
'HTTP_GET_VARS'] = $inputGet;
247 return \RemoveXSS::process($string);
276 static::logDeprecatedFunction();
291 static::logDeprecatedFunction();
307 static::logDeprecatedFunction();
325 public static function fixed_lgd_cs($string, $chars, $appendString =
'...')
328 return $GLOBALS[
'LANG']->csConvObj->crop(
$GLOBALS[
'LANG']->charSet, $string, $chars, $appendString);
330 $charSet =
$GLOBALS[
'TSFE']->renderCharset !=
'' ?
$GLOBALS[
'TSFE']->renderCharset :
$GLOBALS[
'TSFE']->defaultCharSet;
331 return $GLOBALS[
'TSFE']->csConvObj->crop($charSet, $string, $chars, $appendString);
334 $csConvObj = self::makeInstance(\TYPO3\CMS\Core\Charset\CharsetConverter::class);
335 return $csConvObj->crop(
'utf-8', $string, $chars, $appendString);
355 if (strpos($baseIP,
':') !==
false && self::validIPv6($baseIP)) {
356 return self::cmpIPv6($baseIP,
$list);
358 return self::cmpIPv4($baseIP,
$list);
371 $IPpartsReq = explode(
'.', $baseIP);
372 if (count($IPpartsReq) === 4) {
373 $values = self::trimExplode(
',',
$list,
true);
374 foreach ($values as $test) {
375 $testList = explode(
'/', $test);
376 if (count($testList) === 2) {
377 list($test, $mask) = $testList;
383 $lnet = ip2long($test);
384 $lip = ip2long($baseIP);
385 $binnet = str_pad(decbin($lnet), 32,
'0', STR_PAD_LEFT);
386 $firstpart = substr($binnet, 0, $mask);
387 $binip = str_pad(decbin($lip), 32,
'0', STR_PAD_LEFT);
388 $firstip = substr($binip, 0, $mask);
389 $yes = $firstpart === $firstip;
392 $IPparts = explode(
'.', $test);
394 foreach ($IPparts as $index => $val) {
396 if ($val !==
'*' && $IPpartsReq[$index] !== $val) {
420 $baseIP = self::normalizeIPv6($baseIP);
421 $values = self::trimExplode(
',',
$list,
true);
422 foreach ($values as $test) {
423 $testList = explode(
'/', $test);
424 if (count($testList) === 2) {
425 list($test, $mask) = $testList;
429 if (self::validIPv6($test)) {
430 $test = self::normalizeIPv6($test);
431 $maskInt = (int)$mask ?: 128;
435 }
elseif ($maskInt == 128) {
436 $success = $test === $baseIP;
438 $testBin = self::IPv6Hex2Bin($test);
439 $baseIPBin = self::IPv6Hex2Bin($baseIP);
442 $maskIntModulo = $maskInt % 8;
443 $numFullCharactersUntilBoundary = (int)($maskInt / 8);
444 if (substr($testBin, 0, $numFullCharactersUntilBoundary) !== substr($baseIPBin, 0, $numFullCharactersUntilBoundary)) {
446 }
elseif ($maskIntModulo > 0) {
448 $testLastBits = str_pad(decbin(ord(substr($testBin, $numFullCharactersUntilBoundary, 1))), 8,
'0', STR_PAD_LEFT);
449 $baseIPLastBits = str_pad(decbin(ord(substr($baseIPBin, $numFullCharactersUntilBoundary, 1))), 8,
'0', STR_PAD_LEFT);
450 if (strncmp($testLastBits, $baseIPLastBits, $maskIntModulo) != 0) {
472 return inet_pton($hex);
484 return inet_ntop($bin);
496 $normalizedAddress =
'';
497 $stageOneAddress =
'';
501 if (strlen($address) == 39) {
506 $chunks = explode(
'::', $address);
507 if (count($chunks) === 2) {
508 $chunksLeft = explode(
':', $chunks[0]);
509 $chunksRight = explode(
':', $chunks[1]);
510 $left = count($chunksLeft);
511 $right = count($chunksRight);
513 if ($left == 1 && strlen($chunksLeft[0]) == 0) {
516 $hiddenBlocks = 8 - ($left + $right);
519 while ($h < $hiddenBlocks) {
520 $hiddenPart .=
'0000:';
524 $stageOneAddress = $hiddenPart . $chunks[1];
526 $stageOneAddress = $chunks[0] .
':' . $hiddenPart . $chunks[1];
529 $stageOneAddress = $address;
532 $blocks = explode(
':', $stageOneAddress);
534 foreach ($blocks as $block) {
537 $hiddenZeros = 4 - strlen($block);
538 while ($i < $hiddenZeros) {
542 $normalizedAddress .= $tmpBlock . $block;
543 if ($divCounter < 7) {
544 $normalizedAddress .=
':';
548 return $normalizedAddress;
560 return inet_ntop(inet_pton($address));
573 return filter_var($ip, FILTER_VALIDATE_IP) !==
false;
586 return filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) !==
false;
599 return filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) !==
false;
611 $baseHost = trim($baseHost);
612 if (empty($baseHost)) {
615 if (self::validIPv4($baseHost) || self::validIPv6($baseHost)) {
619 $baseHostName = gethostbyaddr($baseHost);
620 if ($baseHostName === $baseHost) {
625 $baseHostName = $baseHost;
627 $baseHostNameParts = explode(
'.', $baseHostName);
628 $values = self::trimExplode(
',',
$list,
true);
629 foreach ($values as $test) {
630 $hostNameParts = explode(
'.', $test);
632 $hostNamePartsCount = count($hostNameParts);
633 $baseHostNamePartsCount = count($baseHostNameParts);
634 if ($hostNamePartsCount > $baseHostNamePartsCount) {
638 foreach ($hostNameParts as $index => $val) {
642 $wildcardStart = $index + 1;
644 if ($wildcardStart < $hostNamePartsCount) {
645 $wildcardMatched =
false;
646 $tempHostName = implode(
'.', array_slice($hostNameParts, $index + 1));
647 while ($wildcardStart < $baseHostNamePartsCount && !$wildcardMatched) {
648 $tempBaseHostName = implode(
'.', array_slice($baseHostNameParts, $wildcardStart));
649 $wildcardMatched = self::cmpFQDN($tempBaseHostName, $tempHostName);
652 if ($wildcardMatched) {
659 }
elseif ($baseHostNameParts[$index] !== $val) {
680 return stripos(
$url .
'/', self::getIndpEnv(
'TYPO3_REQUEST_HOST') .
'/') === 0;
693 return strpos(
',' .
$list .
',',
',' . $item .
',') !==
false;
708 $items = explode(
',',
$list);
709 foreach ($items as $k => $v) {
710 if ($v == $element) {
714 return implode(
',', $items);
726 $items = explode(
',',
$list);
728 foreach ($items as $item) {
729 $range = explode(
'-', $item);
730 if (isset($range[1])) {
731 $runAwayBrake = 1000;
732 for ($n = $range[0]; $n <= $range[1]; $n++) {
735 if ($runAwayBrake <= 0) {
743 return implode(
',',
$list);
767 return hexdec(substr(md5($str), 0, 7));
779 return substr(md5($input), 0, $len);
789 public static function hmac($input, $additionalSecret =
'')
791 $hashAlgorithm =
'sha1';
794 $secret =
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'encryptionKey'] . $additionalSecret;
795 if (extension_loaded(
'hash') && function_exists(
'hash_hmac') && function_exists(
'hash_algos') && in_array($hashAlgorithm, hash_algos())) {
796 $hmac = hash_hmac($hashAlgorithm, $input, $secret);
799 $opad = str_repeat(chr(92), $hashBlocksize);
801 $ipad = str_repeat(chr(54), $hashBlocksize);
802 if (strlen($secret) > $hashBlocksize) {
804 $key = str_pad(pack(
'H*', call_user_func($hashAlgorithm, $secret)), $hashBlocksize, chr(0));
807 $key = str_pad($secret, $hashBlocksize, chr(0));
809 $hmac = call_user_func($hashAlgorithm, ($key ^ $opad) . pack(
'H*', call_user_func($hashAlgorithm, (($key ^ $ipad) . $input))));
822 public static function uniqueList($in_list, $secondParameter = null)
824 if (is_array($in_list)) {
825 throw new \InvalidArgumentException(
'TYPO3 Fatal Error: TYPO3\\CMS\\Core\\Utility\\GeneralUtility::uniqueList() does NOT support array arguments anymore! Only string comma lists!', 1270853885);
827 if (isset($secondParameter)) {
828 throw new \InvalidArgumentException(
'TYPO3 Fatal Error: TYPO3\\CMS\\Core\\Utility\\GeneralUtility::uniqueList() does NOT support more than a single argument value anymore. You have specified more than one!', 1270853886);
830 return implode(
',', array_unique(self::trimExplode(
',', $in_list,
true)));
842 if (preg_match(
'/(.*\\/)(.*)$/', $fileNameWithPath, $reg)) {
843 $info[
'path'] = $reg[1];
844 $info[
'file'] = $reg[2];
847 $info[
'file'] = $fileNameWithPath;
851 if (!is_dir($fileNameWithPath) && preg_match(
'/(.*)\\.([^\\.]*$)/', $info[
'file'], $reg)) {
852 $info[
'filebody'] = $reg[1];
854 $info[
'realFileext'] = $reg[2];
856 $info[
'filebody'] = $info[
'file'];
857 $info[
'fileext'] =
'';
880 $p = self::revExplode(
'/', $path, 2);
881 return count($p) === 2 ? $p[0] :
'';
897 self::logDeprecatedFunction();
902 return '#' . substr((
'0' . dechex($nR)), -2) . substr((
'0' . dechex($nG)), -2) . substr((
'0' . dechex($nB)), -2);
916 self::logDeprecatedFunction();
917 return self::modifyHTMLColor($color, $all, $all, $all);
929 return $partStr !=
'' && strpos((
string)$str, (
string)$partStr, 0) === 0;
940 public static function formatSize($sizeInBytes, $labels =
'', $base = 0)
942 $defaultFormats = array(
943 'iec' => array(
'base' => 1024,
'labels' => array(
' ',
' Ki',
' Mi',
' Gi',
' Ti',
' Pi',
' Ei',
' Zi',
' Yi')),
944 'si' => array(
'base' => 1000,
'labels' => array(
' ',
' k',
' M',
' G',
' T',
' P',
' E',
' Z',
' Y')),
947 if (empty($labels)) {
950 if (isset($defaultFormats[$labels])) {
951 $base = $defaultFormats[$labels][
'base'];
952 $labelArr = $defaultFormats[$labels][
'labels'];
955 if ($base !== 1000 && $base !== 1024) {
958 $labelArr = explode(
'|', str_replace(
'"',
'', $labels));
961 $oldLocale = setlocale(LC_NUMERIC, 0);
962 $newLocale = is_object(
$GLOBALS[
'TSFE']) ?
$GLOBALS[
'TSFE']->config[
'config'][
'locale_all'] :
'';
964 setlocale(LC_NUMERIC, $newLocale);
966 $localeInfo = localeconv();
968 setlocale(LC_NUMERIC, $oldLocale);
970 $sizeInBytes = max($sizeInBytes, 0);
971 $multiplier = floor(($sizeInBytes ? log($sizeInBytes) : 0) / log($base));
972 $sizeInUnits = $sizeInBytes / pow($base, $multiplier);
973 if ($sizeInUnits > ($base * .9)) {
976 $multiplier = min($multiplier, count($labelArr) - 1);
977 $sizeInUnits = $sizeInBytes / pow($base, $multiplier);
978 return number_format($sizeInUnits, (($multiplier > 0) && ($sizeInUnits < 20)) ? 2 : 0, $localeInfo[
'decimal_point'],
'') . $labelArr[$multiplier];
989 $parts = explode(
' ', $microtime);
990 return round(($parts[0] + $parts[1]) * 1000);
1006 $valueLen = strcspn($string, $operators);
1007 $value = substr($string, 0, $valueLen);
1008 $res[] = array($sign, trim($value));
1009 $sign = substr($string, $valueLen, 1);
1010 $string = substr($string, $valueLen + 1);
1027 return preg_replace(
'/&([#[:alnum:]]*;)/',
'&\\1', $str);
1038 public static function slashJS($string, $extended =
false, $char =
'\'')
1041 $string = str_replace(
'\\',
'\\\\', $string);
1043 return str_replace($char,
'\\' . $char, $string);
1055 return str_replace(
'%20',
' ', rawurlencode($str));
1067 return str_replace(
'%2F',
'/', rawurlencode($str));
1091 if (!is_string($email)) {
1094 $atPosition = strrpos($email,
'@');
1095 if (!$atPosition || $atPosition + 1 === strlen($email)) {
1099 $domain = substr($email, $atPosition + 1);
1100 $user = substr($email, 0, $atPosition);
1101 if (!preg_match(
'/^[a-z0-9.\\-]*$/i', $domain)) {
1102 $domain = self::idnaEncode($domain);
1104 return filter_var($user .
'@' . $domain, FILTER_VALIDATE_EMAIL) !==
false;
1122 self::logDeprecatedFunction();
1123 return TYPO3_OS ==
'WIN' ||
false !== strpos(ini_get(
'sendmail_path'),
'mini_sendmail');
1135 self::logDeprecatedFunction();
1136 if (self::isBrokenEmailEnvironment() &&
false !== ($pos1 = strrpos($address,
'<'))) {
1137 $pos2 = strpos($address,
'>', $pos1);
1138 $address = substr($address, $pos1 + 1, ($pos2 ? $pos2 : strlen($address)) - $pos1 - 1);
1154 self::logDeprecatedFunction();
1155 return LF . htmlspecialchars($content);
1169 return strtr((
string)$str,
'abcdefghijklmnopqrstuvwxyz',
'ABCDEFGHIJKLMNOPQRSTUVWXYZ');
1183 return strtr((
string)$str,
'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
'abcdefghijklmnopqrstuvwxyz');
1201 $bytesToGenerate = max(4096, $bytesToReturn);
1203 if (!isset($bytes[($bytesToReturn - 1)])) {
1204 if (TYPO3_OS ===
'WIN') {
1206 $bytes .= self::generateRandomBytesMcrypt($bytesToGenerate);
1209 $bytes .= self::generateRandomBytesOpenSsl($bytesToGenerate);
1210 if (!isset($bytes[($bytesToReturn - 1)])) {
1211 $bytes .= self::generateRandomBytesMcrypt($bytesToGenerate);
1214 if (!isset($bytes[($bytesToReturn - 1)])) {
1215 $bytes .= self::generateRandomBytesUrandom($bytesToGenerate);
1219 if (!isset($bytes[($bytesToReturn - 1)])) {
1220 $bytes .= self::generateRandomBytesFallback($bytesToReturn);
1224 $output = substr($bytes, 0, $bytesToReturn);
1225 $bytes = substr($bytes, $bytesToReturn);
1237 if (!function_exists(
'openssl_random_pseudo_bytes')) {
1241 return (
string)openssl_random_pseudo_bytes($bytesToGenerate, $isStrong);
1252 if (!function_exists(
'mcrypt_create_iv')) {
1255 return (
string)(@mcrypt_create_iv($bytesToGenerate, MCRYPT_DEV_URANDOM));
1267 $fh = @fopen(
'/dev/urandom',
'rb');
1272 $bytes = fread($fh, $bytesToGenerate);
1288 $randomState =
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'encryptionKey'] . base_convert(memory_get_usage() % pow(10, 6), 10, 2) . microtime() .
StringUtility::getUniqueId() . getmypid();
1289 while (!isset($bytes[($bytesToReturn - 1)])) {
1290 $randomState = sha1(microtime() . mt_rand() . $randomState);
1291 $bytes .= sha1(mt_rand() . $randomState,
true);
1304 if (isset(self::$idnaStringCache[$value])) {
1305 return self::$idnaStringCache[$value];
1307 if (!self::$idnaConverter) {
1308 self::$idnaConverter = new \idna_convert(array(
'idn_version' => 2008));
1310 self::$idnaStringCache[$value] = self::$idnaConverter->encode($value);
1311 return self::$idnaStringCache[$value];
1323 return substr(bin2hex(self::generateRandomBytes((
int)(($count + 1) / 2))), 0, $count);
1335 $upperCamelCase = str_replace(
' ',
'', ucwords(str_replace(
'_',
' ', self::strtolower($string))));
1336 return $upperCamelCase;
1348 $upperCamelCase = str_replace(
' ',
'', ucwords(str_replace(
'_',
' ', self::strtolower($string))));
1349 $lowerCamelCase = self::lcfirst($upperCamelCase);
1350 return $lowerCamelCase;
1362 return self::strtolower(preg_replace(
'/(?<=\\w)([A-Z])/',
'_\\1', $string));
1374 return self::strtolower($string[0]) . substr($string, 1);
1403 $parsedUrl = parse_url(
$url);
1404 if (!$parsedUrl || !isset($parsedUrl[
'scheme'])) {
1411 if (!self::isFirstPartOfStr(
$url, $parsedUrl[
'scheme'] .
'://')) {
1412 $url = str_replace($parsedUrl[
'scheme'] .
':', $parsedUrl[
'scheme'] .
'://',
$url);
1415 if ($recomposedUrl !==
$url) {
1419 if (isset($parsedUrl[
'host']) && !preg_match(
'/^[a-z0-9.\\-]*$/i', $parsedUrl[
'host'])) {
1420 $parsedUrl[
'host'] = self::idnaEncode($parsedUrl[
'host']);
1453 public static function inArray(array $in_array, $item)
1455 static::logDeprecatedFunction();
1469 public static function intExplode($delimiter, $string, $removeEmptyValues =
false, $limit = 0)
1471 $result = explode($delimiter, $string);
1472 foreach ($result as $key => &$value) {
1473 if ($removeEmptyValues && ($value ===
'' || trim($value) ===
'')) {
1474 unset($result[$key]);
1476 $value = (int)$value;
1482 $result = array_slice($result, 0, $limit);
1483 }
elseif (count($result) > $limit) {
1484 $lastElements = array_slice($result, $limit - 1);
1485 $result = array_slice($result, 0, $limit - 1);
1486 $result[] = implode($delimiter, $lastElements);
1506 public static function revExplode($delimiter, $string, $count = 0)
1510 $position = strrpos($string, strrev($delimiter));
1511 if ($position !==
false) {
1512 return array(substr($string, 0, $position), substr($string, $position + strlen($delimiter)));
1514 return array($string);
1517 return array($string);
1519 $explodedValues = explode($delimiter, strrev($string), $count);
1520 $explodedValues = array_map(
'strrev', $explodedValues);
1521 return array_reverse($explodedValues);
1537 public static function trimExplode($delim, $string, $removeEmptyValues =
false, $limit = 0)
1539 $result = explode($delim, $string);
1540 if ($removeEmptyValues) {
1542 foreach ($result as $value) {
1543 if (trim($value) !==
'') {
1549 if ($limit > 0 && count($result) > $limit) {
1550 $lastElements = array_splice($result, $limit - 1);
1551 $result[] = implode($delim, $lastElements);
1553 $result = array_slice($result, 0, $limit);
1555 $result = array_map(
'trim', $result);
1569 static::logDeprecatedFunction();
1599 static::logDeprecatedFunction();
1614 public static function implodeArrayForUrl($name, array $theArray, $str =
'', $skipBlank =
false, $rawurlencodeParamName =
false)
1616 foreach ($theArray as $Akey => $AVal) {
1617 $thisKeyName = $name ? $name .
'[' . $Akey .
']' : $Akey;
1618 if (is_array($AVal)) {
1619 $str = self::implodeArrayForUrl($thisKeyName, $AVal, $str, $skipBlank, $rawurlencodeParamName);
1621 if (!$skipBlank || (
string)$AVal !==
'') {
1622 $str .=
'&' . ($rawurlencodeParamName ? rawurlencode($thisKeyName) : $thisKeyName) .
'=' . rawurlencode($AVal);
1641 parse_str($string, $output);
1643 $p = explode(
'&', $string);
1644 foreach ($p as $v) {
1646 list($pK, $pV) = explode(
'=', $v, 2);
1647 $output[rawurldecode($pK)] = rawurldecode($pV);
1665 $keys = self::trimExplode(
',', $varList,
true);
1667 foreach ($keys as $v) {
1668 if (isset($getArray[$v])) {
1669 $outArr[$v] = $getArray[$v];
1671 $outArr[$v] = self::_GP($v);
1689 self::logDeprecatedFunction();
1690 foreach ($theArray as &$value) {
1691 if (is_array($value)) {
1692 self::addSlashesOnArray($value);
1694 $value = addslashes($value);
1713 foreach ($theArray as &$value) {
1714 if (is_array($value)) {
1715 self::stripSlashesOnArray($value);
1717 $value = stripslashes($value);
1734 self::logDeprecatedFunction();
1735 if ($cmd ==
'strip') {
1736 self::stripSlashesOnArray($arr);
1738 if ($cmd ==
'add') {
1739 self::addSlashesOnArray($arr);
1753 static::logDeprecatedFunction();
1767 static::logDeprecatedFunction();
1768 return $arr2 + $arr1;
1782 static::logDeprecatedFunction();
1794 public static function csvValues(array $row, $delim =
',', $quote =
'"')
1797 foreach ($row as $value) {
1798 $out[] = str_replace($quote, $quote . $quote, $value);
1800 $str = $quote . implode(($quote . $delim . $quote), $out) . $quote;
1814 foreach ($ts as $key => $value) {
1815 if (is_array($value)) {
1816 $key = rtrim($key,
'.');
1817 $out[$key] = self::removeDotsFromTS($value);
1819 $out[$key] = $value;
1834 static::logDeprecatedFunction();
1853 $components = self::split_tag_attributes($tag);
1857 $attributes = array();
1858 foreach ($components as $key => $val) {
1863 $attributes[$name] = $val;
1867 if ($key =
strtolower(preg_replace(
'/[^[:alnum:]_\\:\\-]/',
'', $val))) {
1868 $attributes[$key] =
'';
1889 $tag_tmp = trim(preg_replace(
'/^<[^[:space:]]*/',
'', trim($tag)));
1891 $tag_tmp = trim(rtrim($tag_tmp,
'>'));
1894 while ($tag_tmp !==
'') {
1895 $firstChar = $tag_tmp[0];
1896 if ($firstChar ===
'"' || $firstChar ===
'\'') {
1897 $reg = explode($firstChar, $tag_tmp, 3);
1899 $tag_tmp = trim($reg[2]);
1900 }
elseif ($firstChar ===
'=') {
1903 $tag_tmp = trim(substr($tag_tmp, 1));
1906 $reg = preg_split(
'/[[:space:]=]/', $tag_tmp, 2);
1907 $value[] = trim($reg[0]);
1908 $tag_tmp = trim(substr($tag_tmp, strlen($reg[0]), 1) . $reg[1]);
1923 public static function implodeAttributes(array $arr, $xhtmlSafe =
false, $dontOmitBlankAttribs =
false)
1927 foreach ($arr as $p => $v) {
1929 $newArr[
strtolower($p)] = htmlspecialchars($v);
1935 foreach ($arr as $p => $v) {
1936 if ((
string)$v !==
'' || $dontOmitBlankAttribs) {
1937 $list[] = $p .
'="' . $v .
'"';
1940 return implode(
' ',
$list);
1952 public static function wrapJS($string, $linebreak =
true)
1954 if (trim($string)) {
1956 $cr = $linebreak ? LF :
'';
1958 $string = preg_replace(
'/^\\n+/',
'', $string);
1961 if (preg_match(
'/^(\\t+)/', $string, $match)) {
1962 $string = str_replace($match[1], TAB, $string);
1964 $string = $cr .
'<script type="text/javascript">
1970 return trim($string);
1981 public static function xml2tree($string, $depth = 999, $parserOptions = array())
1983 $parser = xml_parser_create();
1986 xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
1987 xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 0);
1988 foreach ($parserOptions as $option => $value) {
1989 xml_parser_set_option($parser, $option, $value);
1991 xml_parse_into_struct($parser, $string, $vals, $index);
1992 if (xml_get_error_code($parser)) {
1993 return 'Line ' . xml_get_current_line_number($parser) .
': ' . xml_error_string(xml_get_error_code($parser));
1995 xml_parser_free($parser);
1996 $stack = array(array());
2000 foreach ($vals as $key => $val) {
2001 $type = $val[
'type'];
2003 if ($type ==
'open' || $type ==
'complete') {
2004 $stack[$stacktop++] = $tagi;
2005 if ($depth == $stacktop) {
2008 $tagi = array(
'tag' => $val[
'tag']);
2009 if (isset($val[
'attributes'])) {
2010 $tagi[
'attrs'] = $val[
'attributes'];
2012 if (isset($val[
'value'])) {
2013 $tagi[
'values'][] = $val[
'value'];
2017 if ($type ==
'complete' || $type ==
'close') {
2019 $tagi = $stack[--$stacktop];
2020 $oldtag = $oldtagi[
'tag'];
2021 unset($oldtagi[
'tag']);
2022 if ($depth == $stacktop + 1) {
2023 if ($key - $startPoint > 0) {
2024 $partArray = array_slice($vals, $startPoint + 1, $key - $startPoint - 1);
2025 $oldtagi[
'XMLvalue'] = self::xmlRecompileFromStructValArray($partArray);
2027 $oldtagi[
'XMLvalue'] = $oldtagi[
'values'][0];
2030 $tagi[
'ch'][$oldtag][] = $oldtagi;
2034 if ($type ==
'cdata') {
2035 $tagi[
'values'][] = $val[
'value'];
2051 public static function array2xml_cs(array $array, $docTag =
'phparray', array $options = array(), $charset =
'')
2054 $charset = $charset ?:
'utf-8';
2056 return '<?xml version="1.0" encoding="' . htmlspecialchars($charset) .
'" standalone="yes" ?>' . LF . self::array2xml($array,
'', 0, $docTag, 0, $options);
2081 public static function array2xml(array $array, $NSprefix =
'', $level = 0, $docTag =
'phparray', $spaceInd = 0, array $options = array(), array $stackData = array())
2084 $binaryChars = chr(0) . chr(1) . chr(2) . chr(3) . chr(4) . chr(5) . chr(6) . chr(7) . chr(8) . chr(11) . chr(12) . chr(14) . chr(15) . chr(16) . chr(17) . chr(18) . chr(19) . chr(20) . chr(21) . chr(22) . chr(23) . chr(24) . chr(25) . chr(26) . chr(27) . chr(28) . chr(29) . chr(30) . chr(31);
2086 $indentChar = $spaceInd ?
' ' : TAB;
2087 $indentN = $spaceInd > 0 ? $spaceInd : 1;
2088 $nl = $spaceInd >= 0 ? LF :
'';
2092 foreach ($array as $k => $v) {
2097 if (isset($options[
'grandParentTagMap'][$stackData[
'grandParentTagName'] .
'/' . $stackData[
'parentTagName']])) {
2098 $attr .=
' index="' . htmlspecialchars($tagName) .
'"';
2099 $tagName = (string)$options[
'grandParentTagMap'][($stackData[
'grandParentTagName'] .
'/' . $stackData[
'parentTagName'])];
2102 $attr .=
' index="' . htmlspecialchars($tagName) .
'"';
2103 $tagName = (string)$options[
'parentTagMap'][($stackData[
'parentTagName'] .
':_IS_NUM')];
2104 }
elseif (isset($options[
'parentTagMap'][$stackData[
'parentTagName'] .
':' . $tagName])) {
2106 $attr .=
' index="' . htmlspecialchars($tagName) .
'"';
2107 $tagName = (string)$options[
'parentTagMap'][($stackData[
'parentTagName'] .
':' . $tagName)];
2108 }
elseif (isset($options[
'parentTagMap'][$stackData[
'parentTagName']])) {
2110 $attr .=
' index="' . htmlspecialchars($tagName) .
'"';
2111 $tagName = (string)$options[
'parentTagMap'][$stackData[
'parentTagName']];
2114 if ($options[
'useNindex']) {
2116 $tagName =
'n' . $tagName;
2119 $attr .=
' index="' . $tagName .
'"';
2120 $tagName = $options[
'useIndexTagForNum'] ?:
'numIndex';
2122 }
elseif ($options[
'useIndexTagForAssoc']) {
2124 $attr .=
' index="' . htmlspecialchars($tagName) .
'"';
2125 $tagName = $options[
'useIndexTagForAssoc'];
2128 $tagName = substr(preg_replace(
'/[^[:alnum:]_-]/',
'', $tagName), 0, 100);
2132 if ($options[
'alt_options'][$stackData[
'path'] .
'/' . $tagName]) {
2133 $subOptions = $options[
'alt_options'][$stackData[
'path'] .
'/' . $tagName];
2134 $clearStackPath = $subOptions[
'clearStackPath'];
2136 $subOptions = $options;
2137 $clearStackPath =
false;
2142 $content = $nl . self::array2xml($v, $NSprefix, ($level + 1),
'', $spaceInd, $subOptions, array(
2143 'parentTagName' => $tagName,
2144 'grandParentTagName' => $stackData[
'parentTagName'],
2145 'path' => ($clearStackPath ?
'' : $stackData[
'path'] .
'/' . $tagName)
2146 )) . ($spaceInd >= 0 ? str_pad(
'', ($level + 1) * $indentN, $indentChar) :
'');
2149 if ((
int)$options[
'disableTypeAttrib'] != 2) {
2150 $attr .=
' type="array"';
2157 if ($vLen && strcspn($v, $binaryChars) != $vLen) {
2159 $content = $nl . chunk_split(base64_encode($v));
2160 $attr .=
' base64="1"';
2163 $content = htmlspecialchars($v);
2164 $dType = gettype($v);
2165 if ($dType ==
'string') {
2166 if ($options[
'useCDATA'] && $content != $v) {
2167 $content =
'<![CDATA[' . $v .
']]>';
2169 }
elseif (!$options[
'disableTypeAttrib']) {
2170 $attr .=
' type="' . $dType .
'"';
2174 if ((
string)$tagName !==
'') {
2176 $output .= ($spaceInd >= 0 ? str_pad(
'', ($level + 1) * $indentN, $indentChar) :
'')
2177 .
'<' . $NSprefix . $tagName . $attr .
'>' . $content .
'</' . $NSprefix . $tagName .
'>' . $nl;
2182 $output =
'<' . $docTag .
'>' . $nl . $output .
'</' . $docTag .
'>';
2198 public static function xml2array($string, $NSprefix =
'', $reportDocTag =
false)
2200 static $firstLevelCache = array();
2201 $identifier = md5($string . $NSprefix . ($reportDocTag ?
'1' :
'0'));
2203 if (!empty($firstLevelCache[$identifier])) {
2204 $array = $firstLevelCache[$identifier];
2208 $array = PageRepository::getHash($identifier, 0);
2209 if (!is_array($array)) {
2210 $array = self::xml2arrayProcess($string, $NSprefix, $reportDocTag);
2214 $firstLevelCache[$identifier] = $array;
2232 $parser = xml_parser_create();
2235 xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
2236 xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 0);
2239 preg_match(
'/^[[:space:]]*<\\?xml[^>]*encoding[[:space:]]*=[[:space:]]*"([^"]*)"/', substr($string, 0, 200), $match);
2240 $theCharset = $match[1] ?:
'utf-8';
2242 xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, $theCharset);
2244 xml_parse_into_struct($parser, $string, $vals, $index);
2246 if (xml_get_error_code($parser)) {
2247 return 'Line ' . xml_get_current_line_number($parser) .
': ' . xml_error_string(xml_get_error_code($parser));
2249 xml_parser_free($parser);
2251 $stack = array(array());
2257 foreach ($vals as $key => $val) {
2259 $tagName = $val[
'tag'];
2260 if (!$documentTag) {
2261 $documentTag = $tagName;
2264 $tagName = $NSprefix && substr($tagName, 0, strlen($NSprefix)) == $NSprefix ? substr($tagName, strlen($NSprefix)) : $tagName;
2266 $testNtag = substr($tagName, 1);
2270 if ((
string)$val[
'attributes'][
'index'] !==
'') {
2271 $tagName = $val[
'attributes'][
'index'];
2274 switch ($val[
'type']) {
2278 $current[$tagName] = array();
2279 $stack[$stacktop++] = $current;
2284 $oldCurrent = $current;
2285 $current = $stack[--$stacktop];
2288 $current[key($current)] = $oldCurrent;
2293 if ($val[
'attributes'][
'base64']) {
2294 $current[$tagName] = base64_decode($val[
'value']);
2297 $current[$tagName] = (string)$val[
'value'];
2299 switch ((
string)$val[
'attributes'][
'type']) {
2301 $current[$tagName] = (int)$current[$tagName];
2304 $current[$tagName] = (double) $current[$tagName];
2307 $current[$tagName] = (bool)$current[$tagName];
2310 $current[$tagName] = null;
2314 $current[$tagName] = array();
2321 if ($reportDocTag) {
2322 $current[$tagName][
'_DOCUMENT_TAG'] = $documentTag;
2325 return $current[$tagName];
2337 foreach ($vals as $val) {
2338 $type = $val[
'type'];
2340 if ($type ==
'open' || $type ==
'complete') {
2341 $XMLcontent .=
'<' . $val[
'tag'];
2342 if (isset($val[
'attributes'])) {
2343 foreach ($val[
'attributes'] as $k => $v) {
2344 $XMLcontent .=
' ' . $k .
'="' . htmlspecialchars($v) .
'"';
2347 if ($type ==
'complete') {
2348 if (isset($val[
'value'])) {
2349 $XMLcontent .=
'>' . htmlspecialchars($val[
'value']) .
'</' . $val[
'tag'] .
'>';
2351 $XMLcontent .=
'/>';
2356 if ($type ==
'open' && isset($val[
'value'])) {
2357 $XMLcontent .= htmlspecialchars($val[
'value']);
2361 if ($type ==
'close') {
2362 $XMLcontent .=
'</' . $val[
'tag'] .
'>';
2365 if ($type ==
'cdata') {
2366 $XMLcontent .= htmlspecialchars($val[
'value']);
2381 if (preg_match(
'/^\\s*<\\?xml([^>]*)\\?\\>/', $xmlData, $match)) {
2382 return self::get_tag_attributes($match[1]);
2395 if (is_array(
$GLOBALS[
'TYPO3_CONF_VARS'][
'SC_OPTIONS'][
't3lib/class.t3lib_div.php'][
'minifyJavaScript'])) {
2397 foreach (
$GLOBALS[
'TYPO3_CONF_VARS'][
'SC_OPTIONS'][
't3lib/class.t3lib_div.php'][
'minifyJavaScript'] as $hookMethod) {
2399 $parameters = array(
'script' => $script);
2400 $script = static::callUserFunction($hookMethod, $parameters, $fakeThis);
2402 $errorMessage =
'Error minifying java script: ' . $e->getMessage();
2403 $error .= $errorMessage;
2404 static::devLog($errorMessage, \TYPO3\CMS\Core\Utility\GeneralUtility::class, 2, array(
2405 'JavaScript' => $script,
2406 'Stack trace' => $e->getTrace(),
2407 'hook' => $hookMethod
2430 public static function getUrl(
$url, $includeHeader = 0, $requestHeaders =
false, &$report = null)
2433 if (isset($report)) {
2434 $report[
'error'] = 0;
2435 $report[
'message'] =
'';
2438 if (
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'curlUse'] ==
'1' && preg_match(
'/^(?:http|ftp)s?|s(?:ftp|cp):/',
$url)) {
2439 if (isset($report)) {
2440 $report[
'lib'] =
'cURL';
2443 if (!function_exists(
'curl_init') || !($ch = curl_init())) {
2444 if (isset($report)) {
2445 $report[
'error'] = -1;
2446 $report[
'message'] =
'Couldn\'t initialize cURL.';
2451 $followLocationSucceeded = @curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
2453 curl_setopt($ch, CURLOPT_URL,
$url);
2454 curl_setopt($ch, CURLOPT_HEADER, !$followLocationSucceeded || $includeHeader ? 1 : 0);
2455 curl_setopt($ch, CURLOPT_NOBODY, $includeHeader == 2 ? 1 : 0);
2456 curl_setopt($ch, CURLOPT_HTTPGET, $includeHeader == 2 ?
'HEAD' :
'GET');
2457 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
2458 curl_setopt($ch, CURLOPT_FAILONERROR, 1);
2459 curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, max(0, (
int)
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'curlTimeout']));
2461 if (is_array($requestHeaders)) {
2462 curl_setopt($ch, CURLOPT_HTTPHEADER, $requestHeaders);
2465 if ($GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'curlProxyServer']) {
2466 curl_setopt($ch, CURLOPT_PROXY, $GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'curlProxyServer']);
2467 if ($GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'curlProxyNTLM']) {
2468 curl_setopt($ch, CURLOPT_PROXYAUTH, CURLAUTH_NTLM);
2470 if ($GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'curlProxyTunnel']) {
2471 curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, $GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'curlProxyTunnel']);
2473 if ($GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'curlProxyUserPass']) {
2474 curl_setopt($ch, CURLOPT_PROXYUSERPWD, $GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'curlProxyUserPass']);
2477 $content = curl_exec($ch);
2478 $curlInfo = curl_getinfo($ch);
2480 if (!$followLocationSucceeded) {
2482 if ($curlInfo[
'http_code'] >= 300 && $curlInfo[
'http_code'] < 400) {
2483 $locationUrl = $curlInfo[
'redirect_url'];
2484 if (!$locationUrl) {
2486 $locationUrl = self::getRedirectUrlFromHttpHeaders($content);
2489 $content = self::getUrl($locationUrl, $includeHeader, $requestHeaders, $report);
2490 $followLocationSucceeded =
true;
2496 if ($content && !$includeHeader) {
2497 $content = self::stripHttpHeaders($content);
2501 if (isset($report)) {
2502 if (!$followLocationSucceeded && $curlInfo[
'http_code'] >= 300 && $curlInfo[
'http_code'] < 400) {
2503 $report[
'http_code'] = $curlInfo[
'http_code'];
2504 $report[
'content_type'] = $curlInfo[
'content_type'];
2505 $report[
'error'] = CURLE_GOT_NOTHING;
2506 $report[
'message'] =
'Expected "Location" header but got nothing.';
2507 }
elseif ($content ===
false) {
2508 $report[
'error'] = curl_errno($ch);
2509 $report[
'message'] = curl_error($ch);
2510 }
elseif ($includeHeader) {
2512 $report[
'http_code'] = $curlInfo[
'http_code'];
2513 $report[
'content_type'] = $curlInfo[
'content_type'];
2517 }
elseif ($includeHeader) {
2518 if (isset($report)) {
2519 $report[
'lib'] =
'socket';
2521 $parsedURL = parse_url(
$url);
2522 if (!preg_match(
'/^https?/', $parsedURL[
'scheme'])) {
2523 if (isset($report)) {
2524 $report[
'error'] = -1;
2525 $report[
'message'] =
'Reading headers is not allowed for this protocol.';
2529 $port = (int)$parsedURL[
'port'];
2531 if ($parsedURL[
'scheme'] ==
'http') {
2532 $port = $port > 0 ? $port : 80;
2535 $port = $port > 0 ? $port : 443;
2540 $fp = @fsockopen(($scheme . $parsedURL[
'host']), $port, $errno, $errstr, 2.0);
2541 if (!$fp || $errno > 0) {
2542 if (isset($report)) {
2543 $report[
'error'] = $errno ?: -1;
2544 $report[
'message'] = $errno ? ($errstr ?:
'Socket error.') :
'Socket initialization error.';
2548 $method = $includeHeader == 2 ?
'HEAD' :
'GET';
2549 $msg = $method .
' ' . (isset($parsedURL[
'path']) ? $parsedURL[
'path'] :
'/') . ($parsedURL[
'query'] ?
'?' . $parsedURL[
'query'] :
'') .
' HTTP/1.0' . CRLF .
'Host: ' . $parsedURL[
'host'] .
'
2554 if (is_array($requestHeaders)) {
2555 $msg .= implode(CRLF, $requestHeaders) . CRLF;
2559 while (!feof($fp)) {
2560 $line = fgets($fp, 2048);
2561 if (isset($report)) {
2562 if (preg_match(
'|^HTTP/\\d\\.\\d +(\\d+)|', $line, $status)) {
2563 $report[
'http_code'] = $status[1];
2564 }
elseif (preg_match(
'/^Content-Type: *(.*)/i', $line, $type)) {
2565 $report[
'content_type'] = $type[1];
2569 if (trim($line) ===
'') {
2574 if ($includeHeader != 2) {
2575 $content .= stream_get_contents($fp);
2578 }
elseif (is_array($requestHeaders)) {
2579 if (isset($report)) {
2580 $report[
'lib'] =
'file/context';
2582 $parsedURL = parse_url(
$url);
2583 if (!preg_match(
'/^https?/', $parsedURL[
'scheme'])) {
2584 if (isset($report)) {
2585 $report[
'error'] = -1;
2586 $report[
'message'] =
'Sending request headers is not allowed for this protocol.';
2590 $ctx = stream_context_create(array(
2592 'header' => implode(CRLF, $requestHeaders)
2595 $defaultCtx = stream_context_get_default();
2597 $content = @file_get_contents(
$url);
2599 $content = @file_get_contents(
$url,
false, $ctx);
2601 if ($content ===
false && isset($report)) {
2602 $report[
'error'] = -1;
2603 $report[
'message'] =
'Couldn\'t get URL: ' . (isset($http_response_header) ? implode(LF, $http_response_header) :
$url);
2606 if (isset($report)) {
2607 $report[
'lib'] =
'file';
2609 $content = @file_get_contents(
$url);
2610 if ($content ===
false && isset($report)) {
2611 $report[
'error'] = -1;
2612 $report[
'message'] =
'Couldn\'t get URL: ' . (isset($http_response_header) ? implode(LF, $http_response_header) :
$url);
2628 $headers = explode(
"\r\n", $content);
2629 foreach ($headers as $header) {
2630 if ($header ==
'') {
2633 if (preg_match(
'/^\s*Location\s*:/i', $header)) {
2634 list(, $result) = self::trimExplode(
':', $header,
false, 2);
2636 $result = self::locationHeaderUrl($result);
2652 $headersEndPos = strpos($content,
"\r\n\r\n");
2653 if ($headersEndPos) {
2654 $content = substr($content, $headersEndPos + 4);
2667 public static function writeFile($file, $content, $changePermissions =
false)
2669 if (!@is_file($file)) {
2670 $changePermissions =
true;
2672 if ($fd = fopen($file,
'wb')) {
2673 $res = fwrite($fd, $content);
2675 if ($res ===
false) {
2679 if ($changePermissions) {
2680 static::fixPermissions($file);
2696 if (TYPO3_OS ===
'WIN') {
2701 if (!static::isAbsPath($path)) {
2702 $path = static::getFileAbsFileName($path,
false);
2704 if (static::isAllowedAbsPath($path)) {
2705 if (@is_file($path)) {
2706 $targetPermissions = isset(
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'fileCreateMask'])
2707 ?
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'fileCreateMask']
2709 }
elseif (@is_dir($path)) {
2710 $targetPermissions = isset(
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'folderCreateMask'])
2711 ?
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'folderCreateMask']
2714 if (!empty($targetPermissions)) {
2716 $targetPermissions = str_pad($targetPermissions, 4, 0, STR_PAD_LEFT);
2717 $targetPermissions = octdec($targetPermissions);
2719 $result = @chmod($path, $targetPermissions);
2723 isset(
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'createGroup'])
2724 &&
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'createGroup'] !==
''
2727 $changeGroupResult = @chgrp($path,
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'createGroup']);
2728 $result = $changeGroupResult ? $result :
false;
2731 if ($recursive && @is_dir($path)) {
2732 $handle = opendir($path);
2733 while (($file = readdir($handle)) !==
false) {
2734 $recursionResult = null;
2735 if ($file !==
'.' && $file !==
'..') {
2736 if (@is_file(($path .
'/' . $file))) {
2737 $recursionResult = static::fixPermissions($path .
'/' . $file);
2738 }
elseif (@is_dir(($path .
'/' . $file))) {
2739 $recursionResult = static::fixPermissions($path .
'/' . $file,
true);
2741 if (isset($recursionResult) && !$recursionResult) {
2762 if (!defined(
'PATH_site')) {
2763 return 'PATH_site constant was NOT defined!';
2767 $fI = pathinfo($filepath);
2768 $fI[
'dirname'] .=
'/';
2770 if (!static::validPathStr($filepath) || !$fI[
'basename'] || strlen($fI[
'basename']) >= 60) {
2771 return 'Input filepath "' . $filepath .
'" was generally invalid!';
2774 $dirName = PATH_site .
'typo3temp/';
2775 if (!@is_dir($dirName)) {
2776 return 'PATH_site + "typo3temp/" was not a directory!';
2778 if (!static::isFirstPartOfStr($fI[
'dirname'], $dirName)) {
2779 return '"' . $fI[
'dirname'] .
'" was not within directory PATH_site + "typo3temp/"';
2782 $subdir = substr($fI[
'dirname'], strlen($dirName));
2784 if (preg_match(
'/^[[:alnum:]_]+\\/$/', $subdir) || preg_match(
'/^[[:alnum:]_]+\\/[[:alnum:]_]+\\/$/', $subdir)) {
2785 $dirName .= $subdir;
2786 if (!@is_dir($dirName)) {
2787 static::mkdir_deep(PATH_site .
'typo3temp/', $subdir);
2790 return 'Subdir, "' . $subdir .
'", was NOT on the form "[[:alnum:]_]/" or "[[:alnum:]_]/[[:alnum:]_]/"';
2794 if (@is_dir($dirName)) {
2795 if ($filepath == $dirName . $fI[
'basename']) {
2796 static::writeFile($filepath, $content);
2797 if (!@is_file($filepath)) {
2798 return 'The file was not written to the disk. Please, check that you have write permissions to the typo3temp/ directory.';
2801 return 'Calculated filelocation didn\'t match input "' . $filepath .
'".';
2804 return '"' . $dirName .
'" is not a directory!';
2817 public static function mkdir($newFolder)
2819 $result = @
mkdir($newFolder, octdec(
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'folderCreateMask']));
2821 static::fixPermissions($newFolder);
2836 public static function mkdir_deep($directory, $deepDirectory =
'')
2838 if (!is_string($directory)) {
2839 throw new \InvalidArgumentException(
'The specified directory is of type "' . gettype($directory) .
'" but a string is expected.', 1303662955);
2841 if (!is_string($deepDirectory)) {
2842 throw new \InvalidArgumentException(
'The specified directory is of type "' . gettype($deepDirectory) .
'" but a string is expected.', 1303662956);
2845 $fullPath = rtrim($directory,
'/') .
'/' . ltrim($deepDirectory,
'/');
2846 if ($fullPath !==
'' && !is_dir($fullPath)) {
2847 $firstCreatedPath = static::createDirectoryPath($fullPath);
2848 if ($firstCreatedPath !==
'') {
2849 static::fixPermissions($firstCreatedPath,
true);
2867 $currentPath = $fullDirectoryPath;
2868 $firstCreatedPath =
'';
2869 $permissionMask = octdec(
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'folderCreateMask']);
2870 if (!@is_dir($currentPath)) {
2872 $firstCreatedPath = $currentPath;
2873 $separatorPosition = strrpos($currentPath, DIRECTORY_SEPARATOR);
2874 $currentPath = substr($currentPath, 0, $separatorPosition);
2875 }
while (!is_dir($currentPath) && $separatorPosition !==
false);
2876 $result = @
mkdir($fullDirectoryPath, $permissionMask,
true);
2878 if (!$result && !@is_dir($fullDirectoryPath)) {
2879 throw new \RuntimeException(
'Could not create directory "' . $fullDirectoryPath .
'"!', 1170251401);
2882 return $firstCreatedPath;
2892 public static function rmdir($path, $removeNonEmpty =
false)
2896 $path = preg_replace(
'|/$|',
'', $path);
2897 if (file_exists($path)) {
2899 if (!is_link($path) && is_dir($path)) {
2900 if ($removeNonEmpty ==
true && ($handle = @opendir($path))) {
2901 while ($OK &&
false !== ($file = readdir($handle))) {
2902 if ($file ==
'.' || $file ==
'..') {
2905 $OK = static::rmdir($path .
'/' . $file, $removeNonEmpty);
2910 $OK = @
rmdir($path);
2912 }
elseif (is_link($path) && is_dir($path) && TYPO3_OS ===
'WIN') {
2913 $OK = @
rmdir($path);
2916 $OK = @unlink($path);
2919 }
elseif (is_link($path)) {
2920 $OK = @unlink($path);
2936 public static function flushDirectory($directory, $keepOriginalDirectory =
false, $flushOpcodeCache =
false)
2940 if (is_dir($directory)) {
2942 if (rename($directory, $temporaryDirectory)) {
2943 if ($flushOpcodeCache) {
2946 if ($keepOriginalDirectory) {
2947 static::mkdir($directory);
2950 $result = static::rmdir($temporaryDirectory,
true);
2967 if (is_dir($path)) {
2968 $dir = scandir($path);
2970 foreach ($dir as $entry) {
2971 if (is_dir($path .
'/' . $entry) && $entry !=
'..' && $entry !=
'.') {
2994 public static function getFilesInDir($path, $extensionList =
'', $prependPath =
false, $order =
'', $excludePattern =
'')
2996 $excludePattern = (string)$excludePattern;
2997 $path = rtrim($path,
'/');
2998 if (!@is_dir($path)) {
3002 $rawFileList = scandir($path);
3003 if ($rawFileList ===
false) {
3004 return 'error opening path: "' . $path .
'"';
3007 $pathPrefix = $path .
'/';
3008 $extensionList =
',' . $extensionList .
',';
3010 foreach ($rawFileList as $entry) {
3011 $completePathToEntry = $pathPrefix . $entry;
3012 if (!@is_file($completePathToEntry)) {
3017 ($extensionList ===
',,' || stripos($extensionList,
',' . pathinfo($entry, PATHINFO_EXTENSION) .
',') !==
false)
3018 && ($excludePattern ===
'' || !preg_match((
'/^' . $excludePattern .
'$/'), $entry))
3020 if ($order !==
'mtime') {
3024 $files[$entry] = filemtime($completePathToEntry);
3029 $valueName =
'value';
3030 if ($order ===
'mtime') {
3035 $valuePathPrefix = $prependPath ? $pathPrefix :
'';
3036 $foundFiles = array();
3037 foreach ($files as $key => $value) {
3039 $foundFiles[md5($pathPrefix . ${$valueName})] = $valuePathPrefix . ${$valueName};
3056 public static function getAllFilesAndFoldersInPath(array $fileArr, $path, $extList =
'', $regDirs =
false, $recursivityLevels = 99, $excludePattern =
'')
3059 $fileArr[md5($path)] = $path;
3061 $fileArr =
array_merge($fileArr, self::getFilesInDir($path, $extList, 1, 1, $excludePattern));
3062 $dirs = self::get_dirs($path);
3063 if ($recursivityLevels > 0 && is_array($dirs)) {
3064 foreach ($dirs as $subdirs) {
3065 if ((
string)$subdirs !==
'' && ($excludePattern ===
'' || !preg_match((
'/^' . $excludePattern .
'$/'), $subdirs))) {
3066 $fileArr = self::getAllFilesAndFoldersInPath($fileArr, $path . $subdirs .
'/', $extList, $regDirs, $recursivityLevels - 1, $excludePattern);
3082 foreach ($fileArr as $k => &$absFileRef) {
3083 if (self::isFirstPartOfStr($absFileRef, $prefixToRemove)) {
3084 $absFileRef = substr($absFileRef, strlen($prefixToRemove));
3086 return 'ERROR: One or more of the files was NOT prefixed with the prefix-path!';
3101 return str_replace(array(
'\\',
'//'),
'/', $theFile);
3113 if (strpos($pathStr,
'..') ===
false) {
3116 $parts = explode(
'/', $pathStr);
3119 foreach ($parts as $part) {
3120 if ($part ===
'..') {
3132 return implode(
'/', $output);
3146 $uI = parse_url($path);
3148 if ($path[0] ===
'/') {
3149 $path = self::getIndpEnv(
'TYPO3_REQUEST_HOST') . $path;
3150 }
elseif (!$uI[
'scheme']) {
3152 $path = self::getIndpEnv(
'TYPO3_REQUEST_DIR') . $path;
3167 $phpUploadLimit = self::getBytesFromSizeMeasurement(ini_get(
'upload_max_filesize'));
3169 $phpPostLimit = self::getBytesFromSizeMeasurement(ini_get(
'post_max_size'));
3172 $phpUploadLimit = $phpPostLimit > 0 && $phpPostLimit < $phpUploadLimit ? $phpPostLimit : $phpUploadLimit;
3173 return floor(($phpUploadLimit)) / 1024;
3184 $bytes = doubleval($measurement);
3185 if (stripos($measurement,
'G')) {
3186 $bytes *= 1024 * 1024 * 1024;
3187 }
elseif (stripos($measurement,
'M')) {
3188 $bytes *= 1024 * 1024;
3189 }
elseif (stripos($measurement,
'K')) {
3202 return PHP_MAXPATHLEN;
3223 $lookupFile = explode(
'?', $file);
3224 $path = self::resolveBackPath(self::dirname(PATH_thisScript) .
'/' . $lookupFile[0]);
3227 if (TYPO3_MODE ==
'FE') {
3228 $mode =
strtolower(
$GLOBALS[
'TYPO3_CONF_VARS'][TYPO3_MODE][
'versionNumberInFilename']);
3229 if ($mode ===
'embed') {
3232 if ($mode ===
'querystring') {
3239 $mode =
$GLOBALS[
'TYPO3_CONF_VARS'][TYPO3_MODE][
'versionNumberInFilename'];
3241 if (!file_exists($path) || $doNothing) {
3248 if ($lookupFile[1]) {
3253 $fullName = $file . $separator . filemtime($path);
3256 $name = explode(
'.', $lookupFile[0]);
3257 $extension = array_pop($name);
3258 array_push($name, filemtime($path), $extension);
3259 $fullName = implode(
'.', $name);
3261 $fullName .= $lookupFile[1] ?
'?' . $lookupFile[1] :
'';
3280 self::logDeprecatedFunction();
3282 $p = parse_url(self::getIndpEnv(
'TYPO3_REQUEST_SCRIPT'));
3283 $dir = self::dirname($p[
'path']) .
'/';
3285 $url = str_replace(
'//',
'/', $p[
'host'] . ($p[
'port'] ?
':' . $p[
'port'] :
'') . $dir);
3299 $parts = self::getIndpEnv(
'SCRIPT_NAME');
3300 $params = self::_GET();
3301 foreach ($getParams as $key => $value) {
3302 if ($value !==
'') {
3303 $params[$key] = $value;
3305 unset($params[$key]);
3308 $pString = self::implodeArrayForUrl(
'', $params);
3309 return $pString ? $parts .
'?' . ltrim($pString,
'&') : $parts;
3322 $parts = parse_url(
$url);
3324 if ($parts[
'query']) {
3325 parse_str($parts[
'query'], $getP);
3328 $uP = explode(
'?',
$url);
3329 $params = self::implodeArrayForUrl(
'', $getP);
3330 $outurl = $uP[0] . ($params ?
'?' . substr($params, 1) :
'');
3344 if (isset(self::$indpEnvCache[$getEnvName])) {
3345 return self::$indpEnvCache[$getEnvName];
3392 switch ((
string)$getEnvName) {
3394 $retVal = self::isRunningOnCgiServerApi()
3395 && ($_SERVER[
'ORIG_PATH_INFO'] ?: $_SERVER[
'PATH_INFO'])
3396 ? ($_SERVER[
'ORIG_PATH_INFO'] ?: $_SERVER[
'PATH_INFO'])
3397 : ($_SERVER[
'ORIG_SCRIPT_NAME'] ?: $_SERVER[
'SCRIPT_NAME']);
3399 if (self::cmpIP($_SERVER[
'REMOTE_ADDR'],
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'reverseProxyIP'])) {
3400 if (self::getIndpEnv(
'TYPO3_SSL') &&
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'reverseProxyPrefixSSL']) {
3401 $retVal =
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'reverseProxyPrefixSSL'] . $retVal;
3402 }
elseif (
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'reverseProxyPrefix']) {
3403 $retVal =
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'reverseProxyPrefix'] . $retVal;
3407 case 'SCRIPT_FILENAME':
3408 $retVal = PATH_thisScript;
3412 if (
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'requestURIvar']) {
3414 list($v, $n) = explode(
'|',
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'requestURIvar']);
3416 }
elseif (!$_SERVER[
'REQUEST_URI']) {
3418 $retVal =
'/' . ltrim(self::getIndpEnv(
'SCRIPT_NAME'),
'/') . ($_SERVER[
'QUERY_STRING'] ?
'?' . $_SERVER[
'QUERY_STRING'] :
'');
3420 $retVal =
'/' . ltrim($_SERVER[
'REQUEST_URI'],
'/');
3423 if (self::cmpIP($_SERVER[
'REMOTE_ADDR'],
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'reverseProxyIP'])) {
3424 if (self::getIndpEnv(
'TYPO3_SSL') &&
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'reverseProxyPrefixSSL']) {
3425 $retVal =
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'reverseProxyPrefixSSL'] . $retVal;
3426 }
elseif (
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'reverseProxyPrefix']) {
3427 $retVal =
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'reverseProxyPrefix'] . $retVal;
3440 if (!self::isRunningOnCgiServerApi()) {
3441 $retVal = $_SERVER[
'PATH_INFO'];
3444 case 'TYPO3_REV_PROXY':
3445 $retVal = self::cmpIP($_SERVER[
'REMOTE_ADDR'],
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'reverseProxyIP']);
3448 $retVal = $_SERVER[
'REMOTE_ADDR'];
3449 if (self::cmpIP($_SERVER[
'REMOTE_ADDR'],
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'reverseProxyIP'])) {
3450 $ip = self::trimExplode(
',', $_SERVER[
'HTTP_X_FORWARDED_FOR']);
3453 switch (
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'reverseProxyHeaderMultiValue']) {
3455 $ip = array_pop($ip);
3458 $ip = array_shift($ip);
3466 if (self::validIP($ip)) {
3472 $retVal = $_SERVER[
'HTTP_HOST'];
3473 if (self::cmpIP($_SERVER[
'REMOTE_ADDR'],
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'reverseProxyIP'])) {
3474 $host = self::trimExplode(
',', $_SERVER[
'HTTP_X_FORWARDED_HOST']);
3476 if (!empty($host)) {
3477 switch (
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'reverseProxyHeaderMultiValue']) {
3479 $host = array_pop($host);
3482 $host = array_shift($host);
3494 if (!static::isAllowedHostHeaderValue($retVal)) {
3495 throw new \UnexpectedValueException(
3496 'The current host header value does not match the configured trusted hosts pattern! Check the pattern defined in $GLOBALS[\'TYPO3_CONF_VARS\'][\'SYS\'][\'trustedHostsPattern\'] and adapt it, if you want to allow the current host header \'' . $retVal .
'\' for your installation.
',
3501 case 'HTTP_REFERER
':
3503 case 'HTTP_USER_AGENT
':
3505 case 'HTTP_ACCEPT_ENCODING
':
3507 case 'HTTP_ACCEPT_LANGUAGE
':
3511 case 'QUERY_STRING
':
3513 if (isset($_SERVER[$getEnvName])) {
3514 $retVal = $_SERVER[$getEnvName];
3517 case 'TYPO3_DOCUMENT_ROOT
':
3518 // Get the web root (it is not the root of the TYPO3 installation)
3519 // The absolute path of the script can be calculated with TYPO3_DOCUMENT_ROOT + SCRIPT_FILENAME
3520 // Some CGI-versions (LA13CGI) and mod-rewrite rules on MODULE versions will deliver a 'wrong
' DOCUMENT_ROOT (according to our description). Further various aliases/mod_rewrite rules can disturb this as well.
3521 // Therefore the DOCUMENT_ROOT is now always calculated as the SCRIPT_FILENAME minus the end part shared with SCRIPT_NAME.
3522 $SFN = self::getIndpEnv('SCRIPT_FILENAME
');
3523 $SN_A = explode('/
', strrev(self::getIndpEnv('SCRIPT_NAME
')));
3524 $SFN_A = explode('/
', strrev($SFN));
3526 foreach ($SN_A as $kk => $vv) {
3527 if ((string)$SFN_A[$kk] === (string)$vv) {
3533 $commonEnd = strrev(implode('/
', $acc));
3534 if ((string)$commonEnd !== '') {
3535 $DR = substr($SFN, 0, -(strlen($commonEnd) + 1));
3539 case 'TYPO3_HOST_ONLY
':
3540 $httpHost = self::getIndpEnv('HTTP_HOST
');
3541 $httpHostBracketPosition = strpos($httpHost, ']
');
3542 $httpHostParts = explode(':
', $httpHost);
3543 $retVal = $httpHostBracketPosition !== false ? substr($httpHost, 0, $httpHostBracketPosition + 1) : array_shift($httpHostParts);
3546 $httpHost = self::getIndpEnv('HTTP_HOST
');
3547 $httpHostOnly = self::getIndpEnv('TYPO3_HOST_ONLY
');
3548 $retVal = strlen($httpHost) > strlen($httpHostOnly) ? substr($httpHost, strlen($httpHostOnly) + 1) : '';
3550 case 'TYPO3_REQUEST_HOST
':
3551 $retVal = (self::getIndpEnv('TYPO3_SSL
') ? 'https:
3553 case 'TYPO3_REQUEST_URL':
3554 $retVal = self::getIndpEnv(
'TYPO3_REQUEST_HOST') . self::getIndpEnv(
'REQUEST_URI');
3556 case 'TYPO3_REQUEST_SCRIPT':
3557 $retVal = self::getIndpEnv(
'TYPO3_REQUEST_HOST') . self::getIndpEnv(
'SCRIPT_NAME');
3559 case 'TYPO3_REQUEST_DIR':
3560 $retVal = self::getIndpEnv(
'TYPO3_REQUEST_HOST') . self::dirname(self::getIndpEnv(
'SCRIPT_NAME')) .
'/';
3562 case 'TYPO3_SITE_URL':
3563 $url = self::getIndpEnv(
'TYPO3_REQUEST_DIR');
3565 if (defined(
'TYPO3_PATH_WEB')) {
3567 }
elseif (defined(
'PATH_thisScript') && defined(
'PATH_site')) {
3569 $siteUrl = substr(
$url, 0, -strlen($lPath));
3570 if (substr($siteUrl, -1) !=
'/') {
3576 case 'TYPO3_SITE_PATH':
3577 $retVal = substr(self::getIndpEnv(
'TYPO3_SITE_URL'), strlen(self::getIndpEnv(
'TYPO3_REQUEST_HOST')));
3579 case 'TYPO3_SITE_SCRIPT':
3580 $retVal = substr(self::getIndpEnv(
'TYPO3_REQUEST_URL'), strlen(self::getIndpEnv(
'TYPO3_SITE_URL')));
3583 $proxySSL = trim(
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'reverseProxySSL']);
3584 if ($proxySSL ==
'*') {
3585 $proxySSL =
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'reverseProxyIP'];
3587 if (self::cmpIP($_SERVER[
'REMOTE_ADDR'], $proxySSL)) {
3590 $retVal = $_SERVER[
'SSL_SESSION_ID'] ||
strtolower($_SERVER[
'HTTPS']) ===
'on' || (string)$_SERVER[
'HTTPS'] ===
'1';
3596 $envTestVars = array(
3604 'TYPO3_REQUEST_HOST',
3605 'TYPO3_REQUEST_URL',
3606 'TYPO3_REQUEST_SCRIPT',
3607 'TYPO3_REQUEST_DIR',
3609 'TYPO3_SITE_SCRIPT',
3613 'TYPO3_DOCUMENT_ROOT',
3618 'HTTP_ACCEPT_LANGUAGE'
3620 foreach ($envTestVars as $v) {
3621 $out[$v] = self::getIndpEnv($v);
3627 self::$indpEnvCache[$getEnvName] = $retVal;
3641 if (static::$allowHostHeaderValue ===
true) {
3645 if (static::isInternalRequestType()) {
3646 return static::$allowHostHeaderValue =
true;
3650 if (empty(
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'trustedHostsPattern'])) {
3654 if (
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'trustedHostsPattern'] === self::ENV_TRUSTED_HOSTS_PATTERN_ALLOW_ALL) {
3655 static::$allowHostHeaderValue =
true;
3657 static::$allowHostHeaderValue = static::hostHeaderValueMatchesTrustedHostsPattern($hostHeaderValue);
3660 return static::$allowHostHeaderValue;
3672 if (
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'trustedHostsPattern'] === self::ENV_TRUSTED_HOSTS_PATTERN_SERVER_NAME) {
3675 $defaultPort = self::getIndpEnv(
'TYPO3_SSL') ?
'443' :
'80';
3676 $parsedHostValue = parse_url(
'http://' . $hostHeaderValue);
3677 if (isset($parsedHostValue[
'port'])) {
3678 $hostMatch = (
strtolower($parsedHostValue[
'host']) ===
strtolower($_SERVER[
'SERVER_NAME']) && (string)$parsedHostValue[
'port'] === $_SERVER[
'SERVER_PORT']);
3680 $hostMatch = (
strtolower($hostHeaderValue) ===
strtolower($_SERVER[
'SERVER_NAME']) && $defaultPort === $_SERVER[
'SERVER_PORT']);
3685 $hostMatch = (bool)preg_match(
'/^' .
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'trustedHostsPattern'] .
'$/i', $hostHeaderValue);
3703 return (!defined(
'TYPO3_REQUESTTYPE') || (defined(
'TYPO3_REQUESTTYPE') && TYPO3_REQUESTTYPE & (TYPO3_REQUESTTYPE_INSTALL | TYPO3_REQUESTTYPE_CLI)));
3713 return round(microtime(
true) * 1000);
3725 $useragent = self::getIndpEnv(
'HTTP_USER_AGENT');
3729 if (strpos($useragent,
'Konqueror') !==
false) {
3730 $bInfo[
'BROWSER'] =
'konqu';
3731 }
elseif (strpos($useragent,
'Opera') !==
false) {
3732 $bInfo[
'BROWSER'] =
'opera';
3733 }
elseif (strpos($useragent,
'MSIE') !==
false) {
3734 $bInfo[
'BROWSER'] =
'msie';
3735 }
elseif (strpos($useragent,
'Mozilla') !==
false) {
3736 $bInfo[
'BROWSER'] =
'net';
3737 }
elseif (strpos($useragent,
'Flash') !==
false) {
3738 $bInfo[
'BROWSER'] =
'flash';
3740 if (isset($bInfo[
'BROWSER'])) {
3742 switch ($bInfo[
'BROWSER']) {
3744 $bInfo[
'VERSION'] = doubleval(substr($useragent, 8));
3745 if (strpos($useragent,
'Netscape6/') !==
false) {
3746 $bInfo[
'VERSION'] = doubleval(substr(strstr($useragent,
'Netscape6/'), 10));
3749 if (strpos($useragent,
'Netscape/6') !==
false) {
3750 $bInfo[
'VERSION'] = doubleval(substr(strstr($useragent,
'Netscape/6'), 10));
3752 if (strpos($useragent,
'Netscape/7') !==
false) {
3753 $bInfo[
'VERSION'] = doubleval(substr(strstr($useragent,
'Netscape/7'), 9));
3757 $tmp = strstr($useragent,
'MSIE');
3758 $bInfo[
'VERSION'] = doubleval(preg_replace(
'/^[^0-9]*/',
'', substr($tmp, 4)));
3761 $tmp = strstr($useragent,
'Opera');
3762 $bInfo[
'VERSION'] = doubleval(preg_replace(
'/^[^0-9]*/',
'', substr($tmp, 5)));
3765 $tmp = strstr($useragent,
'Konqueror/');
3766 $bInfo[
'VERSION'] = doubleval(substr($tmp, 10));
3770 if (strpos($useragent,
'Win') !==
false) {
3771 $bInfo[
'SYSTEM'] =
'win';
3772 }
elseif (strpos($useragent,
'Mac') !==
false) {
3773 $bInfo[
'SYSTEM'] =
'mac';
3774 }
elseif (strpos($useragent,
'Linux') !==
false || strpos($useragent,
'X11') !==
false || strpos($useragent,
'SGI') !==
false || strpos($useragent,
' SunOS ') !==
false || strpos($useragent,
' HP-UX ') !==
false) {
3775 $bInfo[
'SYSTEM'] =
'unix';
3792 if ($requestHost && (!defined(
'TYPO3_cliMode') || !TYPO3_cliMode)) {
3793 $host = self::getIndpEnv(
'HTTP_HOST');
3797 $host = @php_uname(
'n');
3799 if (strpos($host,
' ')) {
3804 if ($host && strpos($host,
'.') ===
false) {
3805 $ip = gethostbyname($host);
3808 $fqdn = gethostbyaddr($ip);
3815 $host =
'localhost.localdomain';
3841 $relPathPrefix = PATH_site;
3842 if ($relToTYPO3_mainDir) {
3843 $relPathPrefix = PATH_typo3;
3848 list($extKey, $local) = explode(
'/', substr(
$filename, 4), 2);
3856 }
elseif ($onlyRelative && !static::isFirstPartOfStr(
$filename, $relPathPrefix)) {
3881 return strpos($theFile,
'//') ===
false && strpos($theFile,
'\\') ===
false
3882 && !preg_match(
'#(?:^\\.\\.|/\\.\\./|[[:cntrl:]])#u', $theFile);
3893 return $path[0] ===
'/' || TYPO3_OS ===
'WIN' && (strpos($path,
':/') === 1 || strpos($path,
':\\') === 1);
3904 $lockRootPath =
$GLOBALS[
'TYPO3_CONF_VARS'][
'BE'][
'lockRootPath'];
3905 return static::isAbsPath($path) && static::validPathStr($path)
3906 && (static::isFirstPartOfStr($path, PATH_site)
3907 || $lockRootPath && static::isFirstPartOfStr($path, $lockRootPath));
3921 $pattern =
'/[[:cntrl:]]/';
3922 if ((
string)
$filename !==
'' && (
string)
$GLOBALS[
'TYPO3_CONF_VARS'][
'BE'][
'fileDenyPattern'] !==
'') {
3923 $pattern =
'/(?:[[:cntrl:]]|' .
$GLOBALS[
'TYPO3_CONF_VARS'][
'BE'][
'fileDenyPattern'] .
')/i';
3925 return !preg_match($pattern,
$filename);
3936 if (strpos($source, PATH_site) ===
false) {
3937 $source = PATH_site . $source;
3939 if (strpos($destination, PATH_site) ===
false) {
3940 $destination = PATH_site . $destination;
3942 if (static::isAllowedAbsPath($source) && static::isAllowedAbsPath($destination)) {
3943 $iterator = new \RecursiveIteratorIterator(
3944 new \RecursiveDirectoryIterator($source, \RecursiveDirectoryIterator::SKIP_DOTS),
3945 \RecursiveIteratorIterator::SELF_FIRST
3947 foreach ($iterator as $item) {
3948 $target = $destination .
'/' . $iterator->getSubPathName();
3949 if ($item->isDir()) {
3950 static::mkdir($target);
3952 static::upload_copy_move($item, $target);
3968 $decodedUrl = rawurldecode(
$url);
3969 if (!empty(
$url) && self::removeXSS($decodedUrl) === $decodedUrl) {
3970 $parsedUrl = parse_url($decodedUrl);
3971 $testAbsoluteUrl = self::resolveBackPath($decodedUrl);
3972 $testRelativeUrl = self::resolveBackPath(self::dirname(self::getIndpEnv(
'SCRIPT_NAME')) .
'/' . $decodedUrl);
3974 if (self::isValidUrl($decodedUrl)) {
3975 if (self::isOnCurrentHost($decodedUrl) && strpos($decodedUrl, self::getIndpEnv(
'TYPO3_SITE_URL')) === 0) {
3976 $sanitizedUrl =
$url;
3978 }
elseif (self::isAbsPath($decodedUrl) && self::isAllowedAbsPath($decodedUrl)) {
3979 $sanitizedUrl =
$url;
3980 }
elseif (strpos($testAbsoluteUrl, self::getIndpEnv(
'TYPO3_SITE_PATH')) === 0 && $decodedUrl[0] ===
'/') {
3981 $sanitizedUrl =
$url;
3982 }
elseif (empty($parsedUrl[
'scheme']) && strpos($testRelativeUrl, self::getIndpEnv(
'TYPO3_SITE_PATH')) === 0 && $decodedUrl[0] !==
'/') {
3983 $sanitizedUrl =
$url;
3986 if (!empty(
$url) && empty($sanitizedUrl)) {
3987 self::sysLog(
'The URL "' .
$url .
'" is not considered to be local and was denied.',
'core', self::SYSLOG_SEVERITY_NOTICE);
3989 return $sanitizedUrl;
4002 if (is_uploaded_file($source)) {
4005 $uploadedResult = move_uploaded_file($source, $destination);
4008 @copy($source, $destination);
4011 self::fixPermissions($destination);
4013 return $uploaded ? $uploadedResult :
false;
4027 if (is_uploaded_file($uploadedFileName)) {
4028 $tempFile = self::tempnam(
'upload_temp_');
4029 move_uploaded_file($uploadedFileName, $tempFile);
4030 return @is_file($tempFile) ? $tempFile :
'';
4045 if ($uploadedTempFileName) {
4046 $uploadedTempFileName = self::fixWindowsFilePath($uploadedTempFileName);
4048 self::validPathStr($uploadedTempFileName)
4049 && self::isFirstPartOfStr($uploadedTempFileName, PATH_site .
'typo3temp/')
4050 && @is_file($uploadedTempFileName)
4052 if (unlink($uploadedTempFileName)) {
4069 public static function tempnam($filePrefix, $fileSuffix =
'')
4071 $temporaryPath = PATH_site .
'typo3temp/';
4072 if ($fileSuffix ===
'') {
4073 $tempFileName = static::fixWindowsFilePath(
tempnam($temporaryPath, $filePrefix));
4076 $tempFileName = $temporaryPath . $filePrefix . mt_rand(1, PHP_INT_MAX) . $fileSuffix;
4077 }
while (file_exists($tempFileName));
4078 touch($tempFileName);
4079 clearstatcache(null, $tempFileName);
4081 return $tempFileName;
4092 public static function stdAuthCode($uid_or_record, $fields =
'', $codeLength = 8)
4094 if (is_array($uid_or_record)) {
4095 $recCopy_temp = array();
4097 $fieldArr = self::trimExplode(
',', $fields,
true);
4098 foreach ($fieldArr as $k => $v) {
4099 $recCopy_temp[$k] = $uid_or_record[$v];
4102 $recCopy_temp = $uid_or_record;
4104 $preKey = implode(
'|', $recCopy_temp);
4106 $preKey = $uid_or_record;
4108 $authCode = $preKey .
'||' .
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'encryptionKey'];
4109 $authCode = substr(md5($authCode), 0, $codeLength);
4121 return $GLOBALS[
'TYPO3_CONF_VARS'][
'FE'][
'hidePagesIfNotTranslatedByDefault'] xor ($l18n_cfg_fieldValue & 2);
4133 return (
bool)($localizationConfiguration & 1);
4146 public static function readLLfile($fileRef, $langKey, $charset =
'', $errorMode = 0)
4148 self::logDeprecatedFunction();
4150 $languageFactory = self::makeInstance(\TYPO3\CMS\Core\Localization\LocalizationFactory::class);
4151 return $languageFactory->getParsedData($fileRef, $langKey, $charset, $errorMode);
4165 $fileName = basename($fileRef);
4166 if (self::isFirstPartOfStr($fileName, $language .
'.')) {
4170 if ($sameLocation) {
4171 return str_replace($fileName, $language .
'.' . $fileName, $fileRef);
4176 if (self::isFirstPartOfStr($fileRef, PATH_typo3 .
'sysext/')) {
4177 $validatedPrefix = PATH_typo3 .
'sysext/';
4178 }
elseif (self::isFirstPartOfStr($fileRef, PATH_typo3 .
'ext/')) {
4180 $validatedPrefix = PATH_typo3 .
'ext/';
4181 }
elseif (self::isFirstPartOfStr($fileRef, PATH_typo3conf .
'ext/')) {
4183 $validatedPrefix = PATH_typo3conf .
'ext/';
4185 $validatedPrefix =
'';
4187 if ($validatedPrefix) {
4189 list($file_extKey, $file_extPath) = explode(
'/', substr($fileRef, strlen($validatedPrefix)), 2);
4190 $temp = self::revExplode(
'/', $file_extPath, 2);
4191 if (count($temp) === 1) {
4192 array_unshift($temp,
'');
4195 list($file_extPath, $file_fileName) = $temp;
4197 $location =
'typo3conf/l10n/' . $language .
'/' . $file_extKey .
'/' . ($file_extPath ? $file_extPath .
'/' :
'');
4198 return $location . $language .
'.' . $file_fileName;
4213 if (!is_array($dataStructArray)) {
4214 return 'Data structure must be an array';
4216 if (is_array($dataStructArray[
'sheets'])) {
4217 $singleSheet =
false;
4218 if (!isset($dataStructArray[
'sheets'][$sheet])) {
4221 $dataStruct = $dataStructArray[
'sheets'][$sheet];
4223 if ($dataStruct && !is_array($dataStruct)) {
4224 $file = self::getFileAbsFileName($dataStruct);
4225 if ($file && @is_file($file)) {
4226 $dataStruct = self::xml2array(self::getUrl($file));
4230 $singleSheet =
true;
4231 $dataStruct = $dataStructArray;
4232 if (isset($dataStruct[
'meta'])) {
4233 unset($dataStruct[
'meta']);
4239 return array($dataStruct, $sheet, $singleSheet);
4251 if (is_array($dataStructArray[
'sheets'])) {
4252 $out = array(
'sheets' => array());
4253 foreach ($dataStructArray[
'sheets'] as $sheetId => $sDat) {
4254 list($ds, $aS) = self::resolveSheetDefInDS($dataStructArray, $sheetId);
4255 if ($sheetId == $aS) {
4256 $out[
'sheets'][$aS] = $ds;
4260 list($ds) = self::resolveSheetDefInDS($dataStructArray);
4261 $out = array(
'sheets' => array(
'sDEF' => $ds));
4278 public static function callUserFunction($funcName, &$params, &$ref, $checkPrefix =
'', $errorMode = 0)
4282 if (is_object($funcName) && is_a($funcName,
'Closure')) {
4283 return call_user_func_array($funcName, array(&$params, &$ref));
4286 if (isset(
$GLOBALS[
'T3_VAR'][
'callUserFunction'][$funcName]) && is_array(
$GLOBALS[
'T3_VAR'][
'callUserFunction'][$funcName])) {
4287 return call_user_func_array(array(
4288 &
$GLOBALS[
'T3_VAR'][
'callUserFunction'][$funcName][
'obj'],
4289 $GLOBALS[
'T3_VAR'][
'callUserFunction'][$funcName][
'method']
4290 ), array(&$params, &$ref));
4293 if (strpos($funcName,
':') !==
false) {
4294 list($file, $funcRef) = self::revExplode(
':', $funcName, 2);
4295 $requireFile = self::getFileAbsFileName($file);
4297 self::requireOnce($requireFile);
4300 $funcRef = $funcName;
4303 if ($funcRef[0] ===
'&') {
4304 $funcRef = substr($funcRef, 1);
4305 $storePersistentObject =
true;
4307 $storePersistentObject =
false;
4310 $parts = explode(
'->', $funcRef);
4311 if (count($parts) === 2) {
4314 if (class_exists($parts[0])) {
4316 if ($storePersistentObject) {
4318 if (!is_object(
$GLOBALS[
'T3_VAR'][
'callUserFunction_classPool'][$parts[0]])) {
4319 $GLOBALS[
'T3_VAR'][
'callUserFunction_classPool'][$parts[0]] = self::makeInstance($parts[0]);
4321 $classObj =
$GLOBALS[
'T3_VAR'][
'callUserFunction_classPool'][$parts[0]];
4324 $classObj = self::makeInstance($parts[0]);
4326 if (method_exists($classObj, $parts[1])) {
4328 if ($storePersistentObject) {
4329 $GLOBALS[
'T3_VAR'][
'callUserFunction'][$funcName] = array(
4330 'method' => $parts[1],
4335 $content = call_user_func_array(array(&$classObj, $parts[1]), array(&$params, &$ref));
4337 $errorMsg =
'No method name \'' . $parts[1] .
'\' in
class ' . $parts[0];
4338 if ($errorMode == 2) {
4339 throw new \InvalidArgumentException($errorMsg, 1294585865);
4341 debug($errorMsg, \TYPO3\CMS\Core\Utility\GeneralUtility::class .
'::callUserFunction');
4345 $errorMsg =
'No class named ' . $parts[0];
4346 if ($errorMode == 2) {
4347 throw new \InvalidArgumentException($errorMsg, 1294585866);
4349 debug($errorMsg, \TYPO3\CMS\Core\Utility\GeneralUtility::class .
'::callUserFunction');
4354 if (function_exists($funcRef)) {
4355 $content = call_user_func_array($funcRef, array(&$params, &$ref));
4357 $errorMsg =
'No function named: ' . $funcRef;
4358 if ($errorMode == 2) {
4359 throw new \InvalidArgumentException($errorMsg, 1294585867);
4361 debug($errorMsg, \TYPO3\CMS\Core\Utility\GeneralUtility::class .
'::callUserFunction');
4388 if (is_object(
$GLOBALS[
'T3_VAR'][
'getUserObj'][$classRef])) {
4389 return $GLOBALS[
'T3_VAR'][
'getUserObj'][$classRef];
4392 if (strpos($classRef,
':') !==
false) {
4393 list($file, $class) = self::revExplode(
':', $classRef, 2);
4394 $requireFile = self::getFileAbsFileName($file);
4396 self::requireOnce($requireFile);
4402 if ($class[0] ===
'&') {
4403 self::deprecationLog(
4404 'The persistent functionality of getUserObj(), prepending the class name with & is deprecated since'
4405 .
' TYPO3 CMS 7 and will be removed in TYPO3 CMS 8. To allow this functionality, implement '
4406 .
' the \\TYPO3\\CMS\\Core\\SingletonInterface in the class "' . $classRef .
'" instead.'
4408 $class = substr($class, 1);
4409 $storePersistentObject =
true;
4411 $storePersistentObject =
false;
4414 if (class_exists($class)) {
4415 $classObj = self::makeInstance($class);
4417 if ($storePersistentObject) {
4418 $GLOBALS[
'T3_VAR'][
'getUserObj'][$classRef] = $classObj;
4447 if (!is_string($className) || empty($className)) {
4448 throw new \InvalidArgumentException(
'$className must be a non empty string.', 1288965219);
4451 if ($className[0] ===
'\\') {
4452 throw new \InvalidArgumentException(
4453 '$className "' . $className .
'" must not start with a backslash.', 1420281366
4456 if (isset(static::$finalClassNameCache[$className])) {
4457 $finalClassName = static::$finalClassNameCache[$className];
4459 $finalClassName = self::getClassName($className);
4460 static::$finalClassNameCache[$className] = $finalClassName;
4463 if (isset(self::$singletonInstances[$finalClassName])) {
4464 return self::$singletonInstances[$finalClassName];
4468 isset(self::$nonSingletonInstances[$finalClassName])
4469 && !empty(self::$nonSingletonInstances[$finalClassName])
4471 return array_shift(self::$nonSingletonInstances[$finalClassName]);
4474 $instance = static::instantiateClass($finalClassName, func_get_args());
4477 self::$singletonInstances[$finalClassName] = $instance;
4491 switch (count($arguments)) {
4493 $instance =
new $className();
4496 $instance =
new $className($arguments[1]);
4499 $instance =
new $className($arguments[1], $arguments[2]);
4502 $instance =
new $className($arguments[1], $arguments[2], $arguments[3]);
4505 $instance =
new $className($arguments[1], $arguments[2], $arguments[3], $arguments[4]);
4508 $instance =
new $className($arguments[1], $arguments[2], $arguments[3], $arguments[4], $arguments[5]);
4511 $instance =
new $className($arguments[1], $arguments[2], $arguments[3], $arguments[4], $arguments[5], $arguments[6]);
4514 $instance =
new $className($arguments[1], $arguments[2], $arguments[3], $arguments[4], $arguments[5], $arguments[6], $arguments[7]);
4517 $instance =
new $className($arguments[1], $arguments[2], $arguments[3], $arguments[4], $arguments[5], $arguments[6], $arguments[7], $arguments[8]);
4523 $class = new \ReflectionClass($className);
4524 array_shift($arguments);
4525 $instance = $class->newInstanceArgs($arguments);
4539 if (class_exists($className)) {
4540 while (static::classHasImplementation($className)) {
4541 $className = static::getImplementationForClass($className);
4555 return $GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'Objects'][$className][
'className'];
4567 if (!isset(
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'Objects'])) {
4571 return isset(
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'Objects'][$className])
4572 && is_array(
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'Objects'][$className])
4573 && !empty(
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'Objects'][$className][
'className']);
4596 self::checkInstanceClassName($className, $instance);
4597 self::$singletonInstances[$className] = $instance;
4618 self::checkInstanceClassName($className, $instance);
4619 if (!isset(self::$singletonInstances[$className])) {
4620 throw new \InvalidArgumentException(
'No Instance registered for ' . $className .
'.', 1394099179);
4622 if ($instance !== self::$singletonInstances[$className]) {
4623 throw new \InvalidArgumentException(
'The instance you are trying to remove has not been registered before.', 1394099256);
4625 unset(self::$singletonInstances[$className]);
4644 static::$singletonInstances = array();
4645 foreach ($newSingletonInstances as $className => $instance) {
4646 static::setSingletonInstance($className, $instance);
4664 return static::$singletonInstances;
4684 self::checkInstanceClassName($className, $instance);
4686 throw new \InvalidArgumentException(
'$instance must not be an instance of TYPO3\\CMS\\Core\\SingletonInterface. ' .
'For setting singletons, please use setSingletonInstance.', 1288969325);
4688 if (!isset(self::$nonSingletonInstances[$className])) {
4689 self::$nonSingletonInstances[$className] = array();
4691 self::$nonSingletonInstances[$className][] = $instance;
4705 if ($className ===
'') {
4706 throw new \InvalidArgumentException(
'$className must not be empty.', 1288967479);
4708 if (!$instance instanceof $className) {
4709 throw new \InvalidArgumentException(
'$instance must be an instance of ' . $className .
', but actually is an instance of ' . get_class($instance) .
'.', 1288967686);
4726 self::$singletonInstances = array();
4727 self::$nonSingletonInstances = array();
4740 self::$indpEnvCache = [];
4741 self::$idnaStringCache = [];
4756 if (!is_array($excludeServiceKeys)) {
4757 $excludeServiceKeys = self::trimExplode(
',', $excludeServiceKeys,
true);
4759 $requestInfo = array(
4760 'requestedServiceType' => $serviceType,
4761 'requestedServiceSubType' => $serviceSubType,
4762 'requestedExcludeServiceKeys' => $excludeServiceKeys
4768 if (is_object(
$GLOBALS[
'T3_VAR'][
'makeInstanceService'][$info[
'className']])) {
4770 $GLOBALS[
'T3_VAR'][
'makeInstanceService'][$info[
'className']]->info = $info;
4772 $GLOBALS[
'T3_VAR'][
'makeInstanceService'][$info[
'className']]->reset();
4773 return $GLOBALS[
'T3_VAR'][
'makeInstanceService'][$info[
'className']];
4775 $obj = self::makeInstance($info[
'className']);
4776 if (is_object($obj)) {
4777 if (!@is_callable(array($obj,
'init'))) {
4785 $GLOBALS[
'T3_VAR'][
'makeInstanceService'][$info[
'className']] = $obj;
4788 $error = $obj->getLastErrorArray();
4808 global $T3_SERVICES, $T3_VAR, $TYPO3_CONF_VARS;
4809 require_once $requireFile;
4823 global $T3_SERVICES, $T3_VAR, $TYPO3_CONF_VARS;
4824 require $requireFile;
4838 static::logDeprecatedFunction();
4841 $string = str_replace(CRLF, LF, $string);
4843 $string = str_replace(CR, LF, $string);
4846 if (TYPO3_OS ==
'WIN') {
4852 $theLines = explode(LF, $string);
4853 foreach ($theLines as $val) {
4855 $theValLen = strlen($val);
4858 for ($index = 0; $index < $theValLen; $index++) {
4859 $char = substr($val, $index, 1);
4860 $ordVal = ord($char);
4861 if ($len > $maxlen - 4 || $len > $maxlen - 14 && $ordVal == 32) {
4863 $newVal .=
'=' . $linebreak;
4867 if ($ordVal >= 33 && $ordVal <= 60 || $ordVal >= 62 && $ordVal <= 126 || $ordVal == 9 || $ordVal == 32) {
4873 $newVal .= sprintf(
'=%02X', $ordVal);
4878 $newVal = preg_replace(
'/' . chr(32) .
'$/',
'=20', $newVal);
4880 $newVal = preg_replace(
'/' . TAB .
'$/',
'=09', $newVal);
4881 $newString .= $newVal . $linebreak;
4884 return preg_replace(
'/' . $linebreak .
'$/',
'', $newString);
4897 public static function encodeHeader($line, $enc =
'quoted-printable', $charset =
'utf-8')
4899 static::logDeprecatedFunction();
4901 if (strpos($line,
'###') !==
false) {
4905 if (!preg_match((
'/[^' . chr(32) .
'-' . chr(127) .
']/'), $line)) {
4909 $line = preg_replace(
'/([^ ]+@[^ ]+)/',
'###$1###', $line);
4910 $matches = preg_split(
'/(.?###.+###.?|\\(|\\))/', $line, -1, PREG_SPLIT_NO_EMPTY);
4911 foreach ($matches as $part) {
4913 $partWasQuoted = $part[0] ==
'"';
4914 $part = trim($part,
'"');
4915 switch ((
string)$enc) {
4917 $part =
'=?' . $charset .
'?B?' . base64_encode($part) .
'?=';
4919 case 'quoted-printable':
4922 $qpValue = self::quoted_printable($part, 1000);
4923 if ($part != $qpValue) {
4927 $search = array(
' ',
'?');
4928 $replace = array(
'_',
'=3F');
4929 $qpValue = str_replace($search, $replace, $qpValue);
4930 $part =
'=?' . $charset .
'?Q?' . $qpValue .
'?=';
4933 if ($partWasQuoted) {
4934 $part =
'"' . $part .
'"';
4936 $line = str_replace($oldPart, $part, $line);
4939 $line = preg_replace(
'/###(.+?)###/',
'$1', $line);
4956 static::logDeprecatedFunction();
4957 switch ((
string)$urlmode) {
4959 $lengthLimit =
false;
4967 $lengthLimit = (int)$urlmode;
4969 if ($lengthLimit ===
false) {
4971 $messageSubstituted = $message;
4973 $messageSubstituted = preg_replace_callback(
4974 '/(http|https):\\/\\/.+(?=[\\]\\.\\?]*([\\! \'"()<>]+|$))/iU',
4975 function (array $matches) use ($lengthLimit, $index_script_url) {
4981 return $messageSubstituted;
4994 if (strlen($inUrl) > $l) {
4995 $md5 = substr(md5($inUrl), 0, 20);
4996 $count =
$GLOBALS[
'TYPO3_DB']->exec_SELECTcountRows(
'*',
'cache_md5params',
'md5hash=' .
$GLOBALS[
'TYPO3_DB']->fullQuoteStr($md5,
'cache_md5params'));
4998 $insertFields = array(
5004 $GLOBALS[
'TYPO3_DB']->exec_INSERTquery(
'cache_md5params', $insertFields);
5006 $inUrl = ($index_script_url ? $index_script_url : self::getIndpEnv(
'TYPO3_REQUEST_DIR') .
'index.php') .
'?RDCT=' . $md5;
5022 return $fontSize / $dpi * 72;
5035 if (defined(
'TYPO3_cliMode') && TYPO3_cliMode) {
5036 $GLOBALS[
'TYPO3_CONF_VARS'][
'SC_OPTIONS'][
't3lib/class.t3lib_div.php'][
'systemLogHost'] = self::getHostname(($requestHost =
false)) .
':' . PATH_site;
5038 $GLOBALS[
'TYPO3_CONF_VARS'][
'SC_OPTIONS'][
't3lib/class.t3lib_div.php'][
'systemLogHost'] = self::getIndpEnv(
'TYPO3_SITE_URL');
5041 if (is_array(
$GLOBALS[
'TYPO3_CONF_VARS'][
'SC_OPTIONS'][
't3lib/class.t3lib_div.php'][
'systemLog'])) {
5042 $params = array(
'initLog' =>
true);
5044 foreach (
$GLOBALS[
'TYPO3_CONF_VARS'][
'SC_OPTIONS'][
't3lib/class.t3lib_div.php'][
'systemLog'] as $hookMethod) {
5045 self::callUserFunction($hookMethod, $params, $fakeThis);
5049 foreach (explode(
';',
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'systemLog'], 2) as $log) {
5050 list($type, $destination) = explode(
',', $log, 3);
5051 if ($type ==
'syslog') {
5052 if (TYPO3_OS ==
'WIN') {
5053 $facility = LOG_USER;
5055 $facility = constant(
'LOG_' .
strtoupper($destination));
5057 openlog(
$GLOBALS[
'TYPO3_CONF_VARS'][
'SC_OPTIONS'][
't3lib/class.t3lib_div.php'][
'systemLogHost'], LOG_ODELAY, $facility);
5061 $GLOBALS[
'TYPO3_CONF_VARS'][
'SC_OPTIONS'][
't3lib/class.t3lib_div.php'][
'systemLogInit'] =
true;
5075 public static function sysLog($msg, $extKey, $severity = 0)
5079 if ((
int)
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'systemLogLevel'] > $severity) {
5083 if (!
$GLOBALS[
'TYPO3_CONF_VARS'][
'SC_OPTIONS'][
't3lib/class.t3lib_div.php'][
'systemLogInit']) {
5087 if (isset(
$GLOBALS[
'TYPO3_CONF_VARS'][
'SC_OPTIONS'][
't3lib/class.t3lib_div.php'][
'systemLog']) && is_array(
$GLOBALS[
'TYPO3_CONF_VARS'][
'SC_OPTIONS'][
't3lib/class.t3lib_div.php'][
'systemLog'])) {
5088 $params = array(
'msg' => $msg,
'extKey' => $extKey,
'backTrace' => debug_backtrace(),
'severity' => $severity);
5090 foreach (
$GLOBALS[
'TYPO3_CONF_VARS'][
'SC_OPTIONS'][
't3lib/class.t3lib_div.php'][
'systemLog'] as $hookMethod) {
5091 self::callUserFunction($hookMethod, $params, $fakeThis);
5095 if (!
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'systemLog']) {
5098 $dateFormat =
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'ddmmyy'];
5099 $timeFormat =
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'hhmm'];
5101 foreach (explode(
';',
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'systemLog'], 2) as $log) {
5102 list($type, $destination, $level) = explode(
',', $log, 4);
5104 if ((
int)$level > $severity) {
5107 $msgLine =
' - ' . $extKey .
': ' . $msg;
5109 if ($type ==
'file') {
5110 $file = fopen($destination,
'a');
5112 fwrite($file, date(($dateFormat .
' ' . $timeFormat)) . $msgLine . LF);
5114 self::fixPermissions($destination);
5116 }
elseif ($type ==
'mail') {
5117 list($to, $from) = explode(
'/', $destination);
5118 if (!self::validEmail($from)) {
5122 $mail = self::makeInstance(\TYPO3\CMS\Core\Mail\MailMessage::class);
5123 $mail->setTo($to)->setFrom($from)->setSubject(
'Warning - error in TYPO3 installation')->setBody(
'Host: ' .
$GLOBALS[
'TYPO3_CONF_VARS'][
'SC_OPTIONS'][
't3lib/class.t3lib_div.php'][
'systemLogHost'] . LF .
'Extension: ' . $extKey . LF .
'Severity: ' . $severity . LF . LF . $msg);
5125 }
elseif ($type ==
'error_log') {
5126 error_log(
$GLOBALS[
'TYPO3_CONF_VARS'][
'SC_OPTIONS'][
't3lib/class.t3lib_div.php'][
'systemLogHost'] . $msgLine, 0);
5127 }
elseif ($type ==
'syslog') {
5128 $priority = array(LOG_INFO, LOG_NOTICE, LOG_WARNING, LOG_ERR, LOG_CRIT);
5129 syslog($priority[(
int)$severity], $msgLine);
5148 public static function devLog($msg, $extKey, $severity = 0, $dataVar =
false)
5150 if (is_array(
$GLOBALS[
'TYPO3_CONF_VARS'][
'SC_OPTIONS'][
't3lib/class.t3lib_div.php'][
'devLog'])) {
5151 $params = array(
'msg' => $msg,
'extKey' => $extKey,
'severity' => $severity,
'dataVar' => $dataVar);
5153 foreach (
$GLOBALS[
'TYPO3_CONF_VARS'][
'SC_OPTIONS'][
't3lib/class.t3lib_div.php'][
'devLog'] as $hookMethod) {
5154 self::callUserFunction($hookMethod, $params, $fakeThis);
5167 if (!
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'enableDeprecationLog']) {
5171 $log =
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'enableDeprecationLog'];
5172 if ($log ===
true || $log ==
'1') {
5173 $log = array(
'file');
5175 $log = self::trimExplode(
',',
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'enableDeprecationLog'],
true);
5177 $date = date(
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'ddmmyy'] .
' ' .
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'hhmm'] .
': ');
5178 if (in_array(
'file', $log) !==
false) {
5180 $destination = static::getDeprecationLogFileName();
5181 $file = @fopen($destination,
'a');
5183 @fwrite($file, ($date . $msg . LF));
5185 self::fixPermissions($destination);
5188 if (in_array(
'devlog', $log) !==
false) {
5190 self::devLog($msg,
'Core', self::SYSLOG_SEVERITY_WARNING);
5193 if (in_array(
'console', $log) !==
false && isset($GLOBALS[
'BE_USER']->user[
'uid'])) {
5205 return PATH_typo3conf .
'deprecation_' . self::shortMD5((PATH_site .
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'encryptionKey'])) .
'.log';
5216 if (!
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'enableDeprecationLog']) {
5219 $trail = debug_backtrace();
5220 if ($trail[1][
'type']) {
5221 $function = new \ReflectionMethod($trail[1][
'class'], $trail[1][
'function']);
5223 $function = new \ReflectionFunction($trail[1][
'function']);
5226 if (preg_match(
'/@deprecated\\s+(.*)/', $function->getDocComment(), $match)) {
5230 $logMsg = $trail[1][
'class'] . $trail[1][
'type'] . $trail[1][
'function'];
5233 self::deprecationLog($logMsg);
5248 if (!is_array($valueList)) {
5249 $valueList = self::trimExplode(
',', $valueList,
true);
5251 $valListCnt = count($valueList);
5252 foreach ($arr as $key => $value) {
5253 if (!$valListCnt || in_array($key, $valueList)) {
5254 $str .= (string)$key . trim(
': ' . self::fixed_lgd_cs(str_replace(LF,
'|', (
string)$value), $valueLength)) .
'; ';
5284 $paramsArr = explode(
' ', trim($parameters));
5287 foreach ($paramsArr as $k => $v) {
5288 if ($quoteActive > -1) {
5289 $paramsArr[$quoteActive] .=
' ' . $v;
5290 unset($paramsArr[$k]);
5291 if (substr($v, -1) === $paramsArr[$quoteActive][0]) {
5296 unset($paramsArr[$k]);
5297 }
elseif (preg_match(
'/^(["\'])/', $v) && substr($v, -1) !== $v[0]) {
5302 foreach ($paramsArr as $key => &$val) {
5303 $val = preg_replace(
'/(?:^"|"$)/',
'', $val);
5304 $val = preg_replace(
'/(?:^\'|\'$)/',
'', $val);
5309 return array_values($paramsArr);
5321 json_encode((
string)$value, JSON_HEX_AMP|JSON_HEX_APOS|JSON_HEX_QUOT|JSON_HEX_TAG),
5324 '\\\\' =>
'\\u005C',
5342 self::logDeprecatedFunction();
5343 while (ob_end_clean()) {
5345 header(
'Content-Encoding: None',
true);
5356 while ($content = ob_get_clean()) {
5357 $obContent .= $content;
5360 if (!headers_sent()) {
5361 $headersList = headers_list();
5362 foreach ($headersList as $header) {
5364 list($key, $value) = self::trimExplode(
':', $header,
true);
5367 header(
'Content-Encoding: None');
5387 if (is_null(static::$applicationContext)) {
5390 throw new \RuntimeException(
'Trying to override applicationContext which has already been defined!', 1376084316);
5401 return static::$applicationContext;
5410 return in_array(PHP_SAPI, self::$supportedCgiServerApis,
true);