Skip to content
This repository has been archived by the owner on Jan 10, 2020. It is now read-only.

Commit

Permalink
Removing ereg_replace usage in loader since it was deprecated in PHP …
Browse files Browse the repository at this point in the history
…5.3. Swapping with preg_replace() which might also provide a slight speed boost. Also adding a curl availability check to getRemoteContent.
  • Loading branch information
cauld committed Nov 29, 2009
1 parent 7449156 commit 83f912f
Showing 1 changed file with 28 additions and 27 deletions.
55 changes: 28 additions & 27 deletions phploader/loader.php
Expand Up @@ -394,11 +394,11 @@ function YAHOO_util_Loader($yuiVersion, $cacheKey=null, $modules=null, $noYUI=fa
$this->skin[YUI_PREFIX] = "skin-";
$this->filters = array(
YUI_RAW => array(
YUI_SEARCH => "-min\.js",
YUI_SEARCH => "/-min\.js/",
YUI_REPLACE => ".js"
),
YUI_DEBUG => array(
YUI_SEARCH => "-min\.js",
YUI_SEARCH => "/-min\.js/",
YUI_REPLACE => "-debug.js"
)
);
Expand Down Expand Up @@ -923,8 +923,7 @@ function getAllDependencies($mname, $loadOptional=false, $completed=array()) {
if (isset($this->modules[$supersededModule][YUI_REQUIRES])) {
foreach($this->modules[$supersededModule][YUI_REQUIRES] as $supersededModuleReq) {
if (!in_array($supersededModuleReq, $mProvides)) {
if (!isset($reqs[$supersededModuleReq]))
{
if (!isset($reqs[$supersededModuleReq])) {
$reqs[$supersededModuleReq] = true;
$reqs = array_merge($reqs, $this->getAllDependencies($supersededModuleReq, $loadOptional, $reqs));
}
Expand All @@ -939,9 +938,7 @@ function getAllDependencies($mname, $loadOptional=false, $completed=array()) {
$supersededSubreqs = $supersededSubmodule[YUI_REQUIRES];
foreach($supersededSubreqs as $ssr) {
if (!in_array($ssr, $ssmProvides)) {
if (!isset($reqs[$ssr]))
{

if (!isset($reqs[$ssr])) {
$reqs[$ssr] = true;
$reqs = array_merge($reqs, $this->getAllDependencies($ssr, $loadOptional, $reqs));
}
Expand Down Expand Up @@ -1389,7 +1386,7 @@ function getUrl($name) {
// skip the filter
} else if (isset($this->filters[$this->filter])) {
$filter = $this->filters[$this->filter];
$url = ereg_replace($filter[YUI_SEARCH], $filter[YUI_REPLACE], $url);
$url = preg_replace($filter[YUI_SEARCH], $filter[YUI_REPLACE], $url);
}
}

Expand All @@ -1414,27 +1411,31 @@ function getRemoteContent($url) {
}

if (!$remote_content) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);

//Doesn't work in safe mode or with openbase_dir enabled, see http://au.php.net/manual/ro/function.curl-setopt.php#71313.
$open_basedir = ini_get("open_basedir");
if (empty($open_basedir) && !ini_get('safe_mode')) {
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);// allow redirects
}

curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // return into a variable
// curl_setopt($ch, CURLOPT_TIMEOUT, 3); // times out after 4s
if($this->curlAvail === true) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);

//Doesn't work in safe mode or with openbase_dir enabled, see http://au.php.net/manual/ro/function.curl-setopt.php#71313.
$open_basedir = ini_get("open_basedir");
if (empty($open_basedir) && !ini_get('safe_mode')) {
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);// allow redirects
}

$remote_content = curl_exec($ch);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // return into a variable
// curl_setopt($ch, CURLOPT_TIMEOUT, 3); // times out after 4s

// save the contents of the remote url for 30 minutes
if ($this->apcAvail === true) {
apc_store($url, $remote_content, $this->apcttl);
}
$remote_content = curl_exec($ch);

// save the contents of the remote url for 30 minutes
if ($this->apcAvail === true) {
apc_store($url, $remote_content, $this->apcttl);
}

curl_close ($ch);
curl_close ($ch);
} else {
$remote_content = "<!--// cURL was not detected, so the content cannot be fetched -->";
}
}

return $remote_content;
Expand Down Expand Up @@ -1529,7 +1530,7 @@ function getComboLink($type) {
// skip the filter
} else if (isset($this->filters[$this->filter])) {
$filter = $this->filters[$this->filter];
$url = ereg_replace($filter[YUI_SEARCH], $filter[YUI_REPLACE], $url);
$url = preg_replace($filter[YUI_SEARCH], $filter[YUI_REPLACE], $url);
}
}

Expand Down

0 comments on commit 83f912f

Please sign in to comment.