|
Index: t3lib/class.t3lib_div.php
|
|
===================================================================
|
|
RCS file: /cvsroot/typo3/TYPO3core/t3lib/class.t3lib_div.php,v
|
|
retrieving revision 1.100
|
|
diff -u -r1.100 class.t3lib_div.php
|
|
--- t3lib/class.t3lib_div.php 8 Jun 2006 16:07:56 -0000 1.100
|
|
+++ t3lib/class.t3lib_div.php 23 Jun 2006 20:22:58 -0000
|
|
@@ -2299,67 +2299,99 @@
|
|
* Usage: 83
|
|
*
|
|
* @param string Filepath/URL to read
|
|
- * @param integer Whether the HTTP header should be fetched or not. 0=disable, 1=fetch header+content, 2=fetch header only (will be ignored when using CURL)
|
|
+ * @param integer Whether the HTTP header should be fetched or not. 0=disable, 1=fetch header+content, 2=fetch header only
|
|
+ * @param array HTTP headers to be used in the request
|
|
* @return string The content from the resource given as input.
|
|
*/
|
|
- function getURL($url, $includeHeader=0) {
|
|
- $content = '';
|
|
+ function getURL($url, $includeHeader = 0, $requestHeaders = false) {
|
|
+ $content = false;
|
|
|
|
- // (Proxy support implemented by Arco <arco@appeltaart.mine.nu>)
|
|
- if ((substr($url,0,7)=='http://') && ($GLOBALS['TYPO3_CONF_VARS']['SYS']['curlUse']=='1')) {
|
|
- // External URL without error checking.
|
|
- $ch = curl_init();
|
|
- if (!$ch) { return false; }
|
|
+ // (Proxy support implemented by Arco <arco@appeltaart.mine.nu>)
|
|
+ if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['curlUse'] == '1' && preg_match('/^https?:\/\//', $url)) {
|
|
+ // External URL without error checking.
|
|
+ $ch = curl_init();
|
|
+ if (!$ch) {
|
|
+ return false;
|
|
+ }
|
|
+
|
|
+ curl_setopt($ch, CURLOPT_URL, $url);
|
|
+ curl_setopt($ch, CURLOPT_HEADER, $includeHeader ? 1 : 0);
|
|
+ curl_setopt($ch, CURLOPT_NOBODY, $includeHeader == 2 ? 1 : 0);
|
|
+ curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
|
|
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
|
+ if (is_array($requestHeaders)) {
|
|
+ curl_setopt($ch, CURLOPT_HTTPHEADER, $requestHeaders);
|
|
+ }
|
|
+
|
|
+ if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['curlProxyServer']) {
|
|
+ curl_setopt ($ch, CURLOPT_PROXY, $GLOBALS['TYPO3_CONF_VARS']['SYS']['curlProxyServer']);
|
|
+
|
|
+ // I don't know if it will be needed
|
|
+ if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['curlProxyTunnel']) {
|
|
+ curl_setopt ($ch, CURLOPT_HTTPPROXYTUNNEL, $GLOBALS['TYPO3_CONF_VARS']['SYS']['curlProxyTunnel'] );
|
|
+ }
|
|
+ if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['curlProxyUserPass']) {
|
|
+ curl_setopt ($ch, CURLOPT_PROXYUSERPWD, $GLOBALS['TYPO3_CONF_VARS']['SYS']['curlProxyUserPass'] );
|
|
+ }
|
|
+ }
|
|
+ $content = curl_exec($ch);
|
|
+ curl_close($ch);
|
|
+ } elseif ($includeHeader) {
|
|
+ $parsedURL = parse_url($url);
|
|
+ if (!t3lib_div::inList('ftp,ftps,http,https,gopher,telnet', $parsedURL['scheme'])) {
|
|
+ return false;
|
|
+ }
|
|
+
|
|
+ $fp = @fsockopen($parsedURL['host'], ($parsedURL['port'] > 0 ? $parsedURL['port'] : 80), $errno, $errstr, 2.0);
|
|
+ if (!$fp) {
|
|
+ return false;
|
|
+ }
|
|
+
|
|
+ $msg = 'GET ' . $parsedURL['path'] .
|
|
+ ($parsedURL['query'] ? '?' . $parsedURL['query'] : '') .
|
|
+ ' HTTP/1.0' . chr(13) . chr(10) . 'Host: ' .
|
|
+ $parsedURL['host'] . chr(13) . chr(10) . chr(13) . chr(10);
|
|
+ fputs($fp, $msg);
|
|
+ while (!feof($fp)) {
|
|
+ $line = fgets($fp, 2048);
|
|
+ $content = $line;
|
|
+ if ($includeHeader == 2 && !strlen(trim($line))) {
|
|
+ // Stop at the first empty line (= end of header)
|
|
+ break;
|
|
+ }
|
|
+ }
|
|
+ fclose($fp);
|
|
+ } else if (is_array($requestHeaders) && function_exists('stream_context_create')) {
|
|
+ $ctx = stream_context_create(array(
|
|
+ 'http' => array(
|
|
+ 'header' => implode(chr(13) . chr(10), $requestHeaders)
|
|
+ )
|
|
+ )
|
|
+ );
|
|
+ if (false !== ($fd = @fopen($url, 'rb', false, $ctx))) {
|
|
+ $content = '';
|
|
+ while (!feof($fd)) {
|
|
+ $content .= fread($fd, 4096);
|
|
+ }
|
|
+ fclose($fd);
|
|
+ }
|
|
+ elseif (function_exists('file_get_contents')) {
|
|
+ $content = @file_get_contents($url, $ctx);
|
|
+ }
|
|
+ }
|
|
+ elseif (function_exists('file_get_contents')) {
|
|
+ $content = @file_get_contents($url);
|
|
+ }
|
|
+ else if (false !== ($fd = @fopen($url, 'rb'))) {
|
|
+ $content = '';
|
|
+ while (!feof($fd)) {
|
|
+ $content .= fread($fd, 4096);
|
|
+ }
|
|
+ fclose($fd);
|
|
+ }
|
|
|
|
- curl_setopt ($ch,CURLOPT_URL, $url);
|
|
- curl_setopt ($ch,CURLOPT_HEADER, $includeHeader?1:0);
|
|
- curl_setopt ($ch,CURLOPT_RETURNTRANSFER, 1);
|
|
-
|
|
- if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['curlProxyServer']) {
|
|
- curl_setopt ($ch, CURLOPT_PROXY, $GLOBALS['TYPO3_CONF_VARS']['SYS']['curlProxyServer']);
|
|
-
|
|
- // I don't know if it will be needed
|
|
- if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['curlProxyTunnel']) {
|
|
- curl_setopt ($ch, CURLOPT_HTTPPROXYTUNNEL, $GLOBALS['TYPO3_CONF_VARS']['SYS']['curlProxyTunnel'] );
|
|
- }
|
|
- if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['curlProxyUserPass']) {
|
|
- curl_setopt ($ch, CURLOPT_PROXYUSERPWD, $GLOBALS['TYPO3_CONF_VARS']['SYS']['curlProxyUserPass'] );
|
|
- }
|
|
- }
|
|
- $content=curl_exec ($ch);
|
|
- curl_close ($ch);
|
|
-
|
|
- } elseif ($includeHeader) {
|
|
- $parsedURL = parse_url($url);
|
|
- if (!t3lib_div::inList('ftp,ftps,http,https,gopher,telnet', $parsedURL['scheme'])) { return false; }
|
|
-
|
|
- $fp = @fsockopen($parsedURL['host'], ($parsedURL['port']>0 ? $parsedURL['port'] : 80), $errno, $errstr, $timeout=2);
|
|
- if (!$fp) { return false; }
|
|
-
|
|
- $msg = 'GET '.$parsedURL['path'].($parsedURL['query'] ? '?'.$parsedURL['query'] : '')." HTTP/1.0\r\nHost: ".$parsedURL['host']."\r\n\r\n";
|
|
- fputs ($fp, $msg);
|
|
- while (!feof($fp)) {
|
|
- $line = fgets ($fp,2048);
|
|
- $content.=$line;
|
|
- if ($includeHeader==2 && !strlen(trim($line))) { break; } // Stop at the first empty line (= end of header)
|
|
- }
|
|
- fclose ($fp);
|
|
-
|
|
- } elseif (function_exists('file_get_contents')) {
|
|
- $content = @file_get_contents($url);
|
|
-
|
|
- } elseif ($fd = @fopen($url,'rb')) {
|
|
- while (!feof($fd)) {
|
|
- $content.=fread($fd, 4096);
|
|
- }
|
|
- fclose($fd);
|
|
-
|
|
- } else {
|
|
- return false;
|
|
- }
|
|
-
|
|
- return $content;
|
|
- }
|
|
+ return $content;
|
|
+ }
|
|
|
|
/**
|
|
* Writes $content to the file $file
|
|
Index: typo3/sysext/cms/tslib/class.tslib_fe.php
|
|
===================================================================
|
|
RCS file: /cvsroot/typo3/TYPO3core/typo3/sysext/cms/tslib/class.tslib_fe.php,v
|
|
retrieving revision 1.109
|
|
diff -u -r1.109 class.tslib_fe.php
|
|
--- typo3/sysext/cms/tslib/class.tslib_fe.php 7 Jun 2006 09:52:20 -0000 1.109
|
|
+++ typo3/sysext/cms/tslib/class.tslib_fe.php 23 Jun 2006 20:23:06 -0000
|
|
@@ -1273,38 +1273,89 @@
|
|
// Issue header in any case:
|
|
if ($header) {header($header);}
|
|
|
|
- // Create response:
|
|
- if (gettype($code)=='boolean' || !strcmp($code,1)) { // Simply boolean; Just shows TYPO3 error page with reason:
|
|
- $this->printError('The page did not exist or was inaccessible.'.($reason ? ' Reason: '.htmlspecialchars($reason) : ''));
|
|
- exit;
|
|
- } elseif (t3lib_div::isFirstPartOfStr($code,'USER_FUNCTION:')) {
|
|
- $funcRef = trim(substr($code,14));
|
|
- $params = array(
|
|
- 'currentUrl' => t3lib_div::getIndpEnv('REQUEST_URI'),
|
|
- 'reasonText' => $reason,
|
|
- 'pageAccessFailureReasons' => $this->getPageAccessFailureReasons()
|
|
- );
|
|
- echo t3lib_div::callUserFunction($funcRef,$params,$this);
|
|
- exit;
|
|
- } elseif (t3lib_div::isFirstPartOfStr($code,'READFILE:')) {
|
|
- $readFile = t3lib_div::getFileAbsFileName(trim(substr($code,9)));
|
|
- if (@is_file($readFile)) {
|
|
- $fileContent = t3lib_div::getUrl($readFile);
|
|
- $fileContent = str_replace('###CURRENT_URL###', t3lib_div::getIndpEnv('REQUEST_URI'), $fileContent);
|
|
- $fileContent = str_replace('###REASON###', htmlspecialchars($reason), $fileContent);
|
|
- echo $fileContent;
|
|
- } else {
|
|
- $this->printError('Configuration Error: 404 page "'.$readFile.'" could not be found.');
|
|
- }
|
|
- exit;
|
|
- } elseif (strlen($code)) {
|
|
- header('Location: '.t3lib_div::locationHeaderUrl($code));
|
|
- exit;
|
|
- } else {
|
|
- $this->printError('Error.'.($reason ? ' Reason: '.htmlspecialchars($reason) : ''));
|
|
- exit;
|
|
- }
|
|
- }
|
|
+ // Create response:
|
|
+ if (gettype($code)=='boolean' || !strcmp($code,1)) { // Simply boolean; Just shows TYPO3 error page with reason:
|
|
+ $this->printError('The page did not exist or was inaccessible.'.($reason ? ' Reason: '.htmlspecialchars($reason) : ''));
|
|
+ exit;
|
|
+ } elseif (t3lib_div::isFirstPartOfStr($code,'USER_FUNCTION:')) {
|
|
+ $funcRef = trim(substr($code,14));
|
|
+ $params = array(
|
|
+ 'currentUrl' => t3lib_div::getIndpEnv('REQUEST_URI'),
|
|
+ 'reasonText' => $reason,
|
|
+ 'pageAccessFailureReasons' => $this->getPageAccessFailureReasons()
|
|
+ );
|
|
+ echo t3lib_div::callUserFunction($funcRef,$params,$this);
|
|
+ exit;
|
|
+ } elseif (t3lib_div::isFirstPartOfStr($code,'READFILE:')) {
|
|
+ $readFile = t3lib_div::getFileAbsFileName(trim(substr($code,9)));
|
|
+ if (@is_file($readFile)) {
|
|
+ $fileContent = t3lib_div::getUrl($readFile);
|
|
+ $fileContent = str_replace('###CURRENT_URL###', t3lib_div::getIndpEnv('REQUEST_URI'), $fileContent);
|
|
+ $fileContent = str_replace('###REASON###', htmlspecialchars($reason), $fileContent);
|
|
+ echo $fileContent;
|
|
+ } else {
|
|
+ $this->printError('Configuration Error: 404 page "'.$readFile.'" could not be found.');
|
|
+ }
|
|
+ exit;
|
|
+ } elseif (strlen($code)) {
|
|
+ // Check if URL is relative
|
|
+ $url_parts = parse_url($code);
|
|
+ if ($url_parts['host'] == '') {
|
|
+ $url_parts['host'] = t3lib_div::getIndpEnv('HTTP_HOST');
|
|
+ $code = t3lib_div::getIndpEnv('TYPO3_REQUEST_HOST') . $code;
|
|
+ $checkBaseTag = false;
|
|
+ }
|
|
+ else {
|
|
+ $checkBaseTag = true;
|
|
+ }
|
|
+ // Prepare headers
|
|
+ $headers = array(
|
|
+ 'User-agent: ' . t3lib_div::getIndpEnv('HTTP_USER_AGENT'),
|
|
+ 'Referer: ' . t3lib_div::getIndpEnv('TYPO3_REQUEST_URL')
|
|
+ );
|
|
+ $content = t3lib_div::getURL($code, 0, $headers);
|
|
+ if (false === $content) {
|
|
+ // Last chance -- redirect
|
|
+ header('Location: '.t3lib_div::locationHeaderUrl($code));
|
|
+ }
|
|
+ else {
|
|
+ // Put <base> if necesary
|
|
+ if ($checkBaseTag) {
|
|
+ // If content already has <base> tag, we do not need to do anything
|
|
+ if (false === stristr($content, '<base ')) {
|
|
+ // Generate href for base tag
|
|
+ $base = $url_parts['scheme'] . '://';
|
|
+ if ($url_parts['user'] != '') {
|
|
+ $base .= $url_parts['user'];
|
|
+ if ($url_parts['pass'] != '') {
|
|
+ $base .= ':' . $url_parts['pass'];
|
|
+ }
|
|
+ $base .= '@';
|
|
+ }
|
|
+ $base .= $url_parts['host'];
|
|
+
|
|
+ // Add path portion skipping possible file name
|
|
+ $base .= preg_replace('/(.*\/)[^\/]*/', '\1', $url_parts['path']);
|
|
+
|
|
+ // Put it into content (generate also <head> if necessary)
|
|
+ $replacement = chr(10) . '<base href="' . htmlentities($base) . '" />' . chr(10);
|
|
+ if (stristr($content, '<head>')) {
|
|
+ $content = preg_replace('/(<head>)/i', '\1' . $replacement, $content);
|
|
+ }
|
|
+ else {
|
|
+ $content = preg_replace('/(<html[^>]*>)/i', '\1<head>' . $replacement . '</head>', $content);
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+ // Output it
|
|
+ echo $content;
|
|
+ }
|
|
+ exit;
|
|
+ } else {
|
|
+ $this->printError('Error.'.($reason ? ' Reason: '.htmlspecialchars($reason) : ''));
|
|
+ exit;
|
|
+ }
|
|
+ }
|
|
|
|
/**
|
|
* Fetches the integer page id for a page alias.
|