44 public static function rewrite($css, $currentDir, $docRoot = null, $symlinks = array())
46 self::$_docRoot = self::_realpath(
47 $docRoot ? $docRoot : $_SERVER[
'DOCUMENT_ROOT']
49 self::$_currentDir = self::_realpath($currentDir);
50 self::$_symlinks = array();
53 foreach ($symlinks as $link => $target) {
54 $link = ($link ===
'//')
56 : str_replace(
'//', self::$_docRoot .
'/', $link);
57 $link = strtr($link,
'/', DIRECTORY_SEPARATOR);
58 self::$_symlinks[$link] = self::_realpath($target);
61 self::$debugText .=
"docRoot : " . self::$_docRoot .
"\n"
62 .
"currentDir : " . self::$_currentDir .
"\n";
63 if (self::$_symlinks) {
64 self::$debugText .=
"symlinks : " . var_export(self::$_symlinks, 1) .
"\n";
66 self::$debugText .=
"\n";
68 $css = self::_trimUrls($css);
71 $css = preg_replace_callback(
'/@import\\s+([\'"])(.*?)[\'"]/'
72 ,array(self::$className,
'_processUriCB'), $css);
73 $css = preg_replace_callback(
'/url\\(\\s*([^\\)\\s]+)\\s*\\)/'
74 ,array(self::$className,
'_processUriCB'), $css);
87 public static function prepend($css, $path)
89 self::$_prependPath = $path;
91 $css = self::_trimUrls($css);
94 $css = preg_replace_callback(
'/@import\\s+([\'"])(.*?)[\'"]/'
95 ,array(self::$className,
'_processUriCB'), $css);
96 $css = preg_replace_callback(
'/url\\(\\s*([^\\)\\s]+)\\s*\\)/'
97 ,array(self::$className,
'_processUriCB'), $css);
99 self::$_prependPath = null;
141 public static function rewriteRelative($uri, $realCurrentDir, $realDocRoot, $symlinks = array())
144 $path = strtr($realCurrentDir,
'/', DIRECTORY_SEPARATOR)
145 . DIRECTORY_SEPARATOR . strtr($uri,
'/', DIRECTORY_SEPARATOR);
147 self::$debugText .=
"file-relative URI : {$uri}\n"
148 .
"path prepended : {$path}\n";
151 foreach ($symlinks as $link => $target) {
152 if (0 === strpos($path, $target)) {
154 $path = $link . substr($path, strlen($target));
156 self::$debugText .=
"symlink unresolved : {$path}\n";
162 $path = substr($path, strlen($realDocRoot));
164 self::$debugText .=
"docroot stripped : {$path}\n";
167 $uri = strtr($path,
'/\\',
'//');
168 $uri = self::removeDots($uri);
170 self::$debugText .=
"traversals removed : {$uri}\n\n";
184 $uri = str_replace(
'/./',
'/', $uri);
188 $uri = preg_replace(
'@/[^/]+/\\.\\./@',
'/', $uri, 1, $changed);
189 }
while ($changed &&
$i++<100);
211 $realPath = realpath($path);
212 if ($realPath !==
false) {
215 return rtrim($path,
'/\\');
223 private static $_currentDir =
'';
230 private static $_docRoot =
'';
238 private static $_symlinks = array();
245 private static $_prependPath = null;
252 private static function _trimUrls($css)
254 return preg_replace(
'/
257 ([^\\)]+?) # 1 = URI (assuming does not contain ")")
260 /x',
'url($1)', $css);
268 private static function _processUriCB($m)
271 $isImport = ($m[0][0] ===
'@');
278 $quoteChar = ($m[1][0] ===
"'" || $m[1][0] ===
'"')
281 $uri = ($quoteChar ===
'')
283 : substr($m[1], 1, strlen($m[1]) - 2);
287 &&
false === strpos($uri,
'//')
288 && 0 !== strpos($uri,
'data:')
291 if (self::$_prependPath === null) {
292 $uri = self::rewriteRelative($uri, self::$_currentDir, self::$_docRoot, self::$_symlinks);
294 $uri = self::$_prependPath . $uri;
295 if ($uri[0] ===
'/') {
297 $rootRelative = $uri;
298 $uri = $root . self::removeDots($rootRelative);
299 }
elseif (preg_match(
'@^((https?\:)?//([^/]+))/@', $uri, $m) && (
false !== strpos($m[3],
'.'))) {
301 $rootRelative = substr($uri, strlen($root));
302 $uri = $root . self::removeDots($rootRelative);
307 ?
"@import {$quoteChar}{$uri}{$quoteChar}"
308 :
"url({$quoteChar}{$uri}{$quoteChar})";
static removeDots($uri)
Remove instances of "./" and "../" where possible from a root-relative URI.
static _realpath($path)
Get realpath with any trailing slash removed.
if(strlen($date2)== '10') if($type== 'users-by-age'&&a_priv('admin_users', true)) elseif($type== 'forums-count'&&a_priv('admin_content', true)) elseif($type== 'forums-categories'&&a_priv('admin_content', true)) elseif($type== 'users-count'&&a_priv('admin_users', true)) elseif($type== 'product-categories'&&a_priv('admin_products', true)) elseif($type== 'users-by-sex'&&a_priv('admin_users', true)) elseif($type== 'users-by-country'&&a_priv('admin_users', true)) elseif($type== 'sales'&&a_priv('admin_sales', true))
static rewriteRelative($uri, $realCurrentDir, $realDocRoot, $symlinks=array())
Get a root relative URI from a file relative URI.
static prepend($css, $path)
In CSS content, prepend a path to relative URIs.
static rewrite($css, $currentDir, $docRoot=null, $symlinks=array())
In CSS content, rewrite file relative URIs as root relative.