issue 2119. supporting php 5.4. frontend file handler, handler and xe http request classes.

git-svn-id: http://xe-core.googlecode.com/svn/branches/maserati@12689 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
flyskyko 2013-02-05 01:42:28 +00:00
parent b69abcca68
commit 7305cebf38
3 changed files with 107 additions and 65 deletions

View file

@ -1,10 +1,12 @@
<?php
/**
* Handle front end files
* @author NHN (developers@xpressengine.com)
* */
class FrontEndFileHandler extends Handler
{
/**
* Map for css
* @var array
@ -48,13 +50,20 @@ class FrontEndFileHandler extends Handler
*/
function isSsl()
{
if ($GLOBAL['__XE_IS_SSL__']) return $GLOBAL['__XE_IS_SSL__'];
if($GLOBAL['__XE_IS_SSL__'])
{
return $GLOBAL['__XE_IS_SSL__'];
}
$url_info = parse_url(Context::getRequestUrl());
if($url_info['scheme'] == 'https')
$GLOBAL['__XE_IS_SSL__'] = true;
{
$GLOBAL['__XE_IS_SSL__'] = TRUE;
}
else
$GLOBAL['__XE_IS_SSL__'] = false;
{
$GLOBAL['__XE_IS_SSL__'] = FALSE;
}
return $GLOBAL['__XE_IS_SSL__'];
}
@ -92,9 +101,12 @@ class FrontEndFileHandler extends Handler
* @param string $cdnVersion CDN version string (ardent1)
* @return void
* */
function loadFile($args, $useCdn = false, $cdnPrefix = '', $cdnVersion = '')
function loadFile($args, $useCdn = FALSE, $cdnPrefix = '', $cdnVersion = '')
{
if (!is_array($args)) $args = array($args);
if(!is_array($args))
{
$args = array($args);
}
$pathInfo = pathinfo($args[0]);
$file = new stdClass();
@ -133,7 +145,10 @@ class FrontEndFileHandler extends Handler
}
$availableExtension = array('css' => 1, 'js' => 1);
if (!isset($availableExtension[$file->fileExtension])) return;
if(!isset($availableExtension[$file->fileExtension]))
{
return;
}
$file->targetIe = $args[2];
$file->index = (int) $args[3];
@ -141,7 +156,10 @@ class FrontEndFileHandler extends Handler
if($file->fileExtension == 'css')
{
$file->media = $args[1];
if (!$file->media) $file->media = 'all';
if(!$file->media)
{
$file->media = 'all';
}
$map = &$this->cssMap;
$mapIndex = &$this->cssMapIndex;
$key = $file->filePath . $file->keyName . "\t" . $file->targetIe . "\t" . $file->media;
@ -264,7 +282,7 @@ class FrontEndFileHandler extends Handler
{
foreach($indexedMap as $file)
{
if ($this->isSsl() == false && $useCdn == 'Y' && $file->useCdn && $file->cdnVersion != '%__XE_CDN_VERSION__%')
if($this->isSsl() == FALSE && $useCdn == 'Y' && $file->useCdn && $file->cdnVersion != '%__XE_CDN_VERSION__%')
{
$fullFilePath = $file->cdnPrefix . $file->cdnVersion . '/' . substr($file->cdnPath, 2) . '/' . $file->fileName;
}
@ -309,7 +327,7 @@ class FrontEndFileHandler extends Handler
{
foreach($indexedMap as $file)
{
if ($this->isSsl() == false && $useCdn == 'Y' && $file->useCdn && $file->cdnVersion != '%__XE_CDN_VERSION__%')
if($this->isSsl() == FALSE && $useCdn == 'Y' && $file->useCdn && $file->cdnVersion != '%__XE_CDN_VERSION__%')
{
$fullFilePath = $file->cdnPrefix . $file->cdnVersion . '/' . substr($file->cdnPath, 2) . '/' . $file->fileName;
}
@ -345,7 +363,7 @@ class FrontEndFileHandler extends Handler
*/
function _normalizeFilePath($path)
{
if (strpos($path, '://') === false && $path{0} != '/' && $path{0} != '.')
if(strpos($path, '://') === FALSE && $path{0} != '/' && $path{0} != '.')
{
$path = './' . $path;
}
@ -409,7 +427,7 @@ class FrontEndFileHandler extends Handler
$cssSortList = array('common' => -100000, 'layouts' => -90000, 'modules' => -80000, 'widgets' => -70000, 'addons' => -60000);
$file->index = $cssSortList[$tmp[0]];
}
}
}
/* End of file FrontEndFileHandler.class.php */
/* Location: ./classes/frontendfile/FrontEndFileHandler.class.php */

View file

@ -1,4 +1,5 @@
<?php
/**
* An abstract class of (*)Handler
*
@ -6,6 +7,7 @@
*/
class Handler
{
}
/* End of file Handler.class.php */
/* Location: ./classes/handler/Handler.class.php */

View file

@ -1,4 +1,5 @@
<?php
/**
* - HttpRequest class
* - a class that is designed to be used for sending out HTTP request to an external server and retrieving response
@ -9,16 +10,19 @@
*/
class XEHttpRequest
{
/**
* target host
* @var string
*/
var $m_host;
/**
* target Port
* @var int
*/
var $m_port;
/**
* target header
* @var array
@ -55,24 +59,33 @@ class XEHttpRequest
* @param array $post_vars variables to send
* @return object Returns an object containing HTTP Response body and HTTP response code
*/
function send($target='/', $method='GET', $timeout=3, $post_vars=null)
function send($target = '/', $method = 'GET', $timeout = 3, $post_vars = NULL)
{
static $allow_methods=null;
static $allow_methods = NULL;
$this->addToHeader('Host', $this->m_host);
$this->addToHeader('Connection', 'close');
$method = strtoupper($method);
if(!$allow_methods) $allow_methods = explode(' ', 'GET POST PUT');
if(!in_array($method, $allow_methods)) $method = $allow_methods[0];
if(!$allow_methods)
{
$allow_methods = explode(' ', 'GET POST PUT');
}
if(!in_array($method, $allow_methods))
{
$method = $allow_methods[0];
}
// $timeout should be an integer that is bigger than zero
$timout = max((int) $timeout, 0);
// list of post variables
if(!is_array($post_vars)) $post_vars = array();
if(!is_array($post_vars))
{
$post_vars = array();
}
if(false && is_callable('curl_init'))
if(FALSE && is_callable('curl_init'))
{
return $this->sendWithCurl($target, $method, $timeout, $post_vars);
}
@ -101,7 +114,10 @@ class XEHttpRequest
}
$headers = $this->m_headers + array();
if(!isset($headers['Accept-Encoding'])) $headers['Accept-Encoding'] = 'identity';
if(!isset($headers['Accept-Encoding']))
{
$headers['Accept-Encoding'] = 'identity';
}
// post body
$post_body = '';
@ -128,13 +144,13 @@ class XEHttpRequest
list($httpver, $code, $status) = preg_split('/ +/', rtrim(fgets($sock)), 3);
// read response headers
$is_chunked = false;
$is_chunked = FALSE;
while(strlen(trim($line = fgets($sock))))
{
list($equiv, $content) = preg_split('/ *: */', rtrim($line), 1);
if(!strcasecmp($equiv, 'Transfer-Encoding') && $content == 'chunked')
{
$is_chunked = true;
$is_chunked = TRUE;
}
}
@ -144,7 +160,10 @@ class XEHttpRequest
if($is_chunked)
{
$chunk_size = hexdec(fgets($sock));
if($chunk_size) $body .= fread($sock, $chunk_size);
if($chunk_size)
{
$body .= fread($sock, $chunk_size);
}
}
else
{
@ -179,16 +198,18 @@ class XEHttpRequest
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "http://{$this->m_host}{$target}");
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_PORT, $this->m_port);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
switch($method)
{
case 'GET': curl_setopt($ch, CURLOPT_HTTPGET, true); break;
case 'PUT': curl_setopt($ch, CURLOPT_PUT, true); break;
case 'GET': curl_setopt($ch, CURLOPT_HTTPGET, true);
break;
case 'PUT': curl_setopt($ch, CURLOPT_PUT, true);
break;
case 'POST':
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_vars);
@ -217,6 +238,7 @@ class XEHttpRequest
return $ret;
}
}
/* End of file XEHttpRequest.class.php */
/* Location: ./classes/httprequest/XEHttpRequest.class.php */