1
0
mirror of https://github.com/e107inc/e107.git synced 2025-07-30 19:30:25 +02:00

Fix for broken social-share icons when JS/CSS cache was enabled.

This commit is contained in:
Cameron
2016-03-11 19:40:59 -08:00
parent f8ed7ac1d4
commit e9869319f3
3 changed files with 56 additions and 2 deletions

View File

@@ -1523,7 +1523,7 @@ class e_jsmanager
$path = str_replace("../",'',$path);
$basePath = SITEURL.dirname($path)."/";
$basePath = dirname($path)."/";
foreach($match[1] as $k=>$v)
{
@@ -1533,7 +1533,11 @@ class e_jsmanager
continue;
}
$dir = "url(".$basePath.$v.")"; // relative to e_WEB_ABS."cache/";
$path = $this->normalizePath($basePath.$v);
$dir = "url(".SITEURL.$path.")"; // relative to e_WEB_ABS."cache/";
// print_a($dir);
$newpath[$k] = $dir;
}
@@ -1543,6 +1547,54 @@ class e_jsmanager
}
/**
* Normalize a path.
* Replacement for realpath (move to core functions?)
* It will _only_ normalize the path and resolve indirections (.. and .)
* Normalization includes:
* - directiory separator is always /
* - there is never a trailing directory separator
* @param $path
* @return String
*/
private function normalizePath($path)
{
$parts = preg_split(":[\\\/]:", $path); // split on known directory separators
// resolve relative paths
for ($i = 0; $i < count($parts); $i +=1)
{
if ($parts[$i] === "..") // resolve ..
{
if ($i === 0)
{
throw new Exception("Cannot resolve path, path seems invalid: `" . $path . "`");
}
unset($parts[$i - 1]);
unset($parts[$i]);
$parts = array_values($parts);
$i -= 2;
}
elseif ($parts[$i] === ".") // resolve .
{
unset($parts[$i]);
$parts = array_values($parts);
$i -= 1;
}
if ($i > 0 && $parts[$i] === "") // remove empty parts
{
unset($parts[$i]);
$parts = array_values($parts);
}
}
return implode("/", $parts);
}
/**
* Minify JS/CSS for output
* @param string $minify