private static function _processUriCB($m) { // $m matched either '/@import\\s+([\'"])(.*?)[\'"]/' or '/url\\(\\s*([^\\)\\s]+)\\s*\\)/' $isImport = $m[0][0] === '@'; // determine URI and the quote character (if any) if ($isImport) { $quoteChar = $m[1]; $uri = $m[2]; } else { // $m[1] is either quoted or not $quoteChar = $m[1][0] === "'" || $m[1][0] === '"' ? $m[1][0] : ''; $uri = $quoteChar === '' ? $m[1] : substr($m[1], 1, strlen($m[1]) - 2); } // analyze URI if (false === strpos($uri, '//') && 0 !== strpos($uri, 'data:')) { // prepend if (self::$_prependRelativePath) { if (w3_is_url(self::$_prependRelativePath)) { $parse_url = @parse_url(self::$_prependRelativePath); if ($parse_url && isset($parse_url['host'])) { $scheme = $parse_url['scheme']; $host = $parse_url['host']; $port = isset($parse_url['port']) && $parse_url['port'] != 80 ? ':' . (int) $parse_url['port'] : ''; $path = !empty($parse_url['path']) ? $parse_url['path'] : '/'; $dir_css = preg_replace('~[^/]+$~', '', $path); $dir_obj = preg_replace('~[^/]+$~', '', $uri); $dir = ltrim(strpos($dir_obj, '/') === 0 ? w3_realpath($dir_obj) : w3_realpath($dir_css . $dir_obj), '/'); $file = basename($uri); $uri = sprintf('%s://%s%s/%s/%s', $scheme, $host, $port, $dir, $file); } } else { $uri = self::$_prependRelativePath . $uri; } } else { $uri = self::_rewriteRelative($uri, self::$_currentDir, self::$_docRoot, self::$_symlinks); if (self::$_prependAbsolutePath) { $prependAbsolutePath = self::$_prependAbsolutePath; } elseif (self::$_prependAbsolutePathCallback) { $prependAbsolutePath = call_user_func(self::$_prependAbsolutePathCallback, $uri); } else { $prependAbsolutePath = ''; } if ($prependAbsolutePath) { $uri = rtrim($prependAbsolutePath, '/') . $uri; } } if (self::$_browserCacheId && count(self::$_browserCacheExtensions)) { $matches = null; if (preg_match('~\\.([a-z-_]+)(\\?.*)?$~', $uri, $matches)) { $extension = $matches[1]; $query = isset($matches[2]) ? $matches[2] : ''; if ($extension && in_array($extension, self::$_browserCacheExtensions)) { $uri = w3_remove_query($uri); $uri .= ($query ? '&' : '?') . self::$_browserCacheId; } } } } return $isImport ? "@import {$quoteChar}{$uri}{$quoteChar}" : "url({$quoteChar}{$uri}{$quoteChar})"; }
/** * Checks if path is restricted by open_basedir * * @param string $path * @return boolean */ function w3_check_open_basedir($path) { $path = w3_realpath($path); $open_basedirs = w3_get_open_basedirs(); if (!count($open_basedirs)) { return true; } foreach ($open_basedirs as $open_basedir) { if (strstr($path, $open_basedir) !== false) { return true; } } return false; }
/** * Returns page key * * @param string $request_uri * @param string $compression * @return string */ function _get_page_key($request_uri, $compression) { if ($this->_config->get_string('pgcache.engine') == 'file_pgcache') { $request_uri = preg_replace('~\\?.*$~', '', $request_uri); $request_uri = str_replace('/index.php', '/', $request_uri); $request_uri = preg_replace('~[/\\\\]+~', '/', $request_uri); $request_uri = w3_realpath($request_uri); if (empty($request_uri)) { $request_uri = '/'; } if (substr($request_uri, -1) == '/') { $request_uri .= 'index.html'; } $request_uri = ltrim($request_uri, '/'); $key = sprintf('%s/%s', $_SERVER['HTTP_HOST'], $request_uri); if (!empty($compression)) { $key .= '.' . $compression; } } else { $blog_id = w3_get_blog_id(); if (empty($blog_id)) { $blog_id = $_SERVER['HTTP_HOST']; } $key = sprintf('w3tc_%s_page_%s', md5($blog_id), md5($request_uri)); if (!empty($compression)) { $key .= '_' . $compression; } } return $key; }
private static function _processUriCB($m) { // $m matched either '/@import\\s+([\'"])(.*?)[\'"]/' or '/url\\(\\s*([^\\)\\s]+)\\s*\\)/' $isImport = $m[0][0] === '@'; // determine URI and the quote character (if any) if ($isImport) { $quoteChar = $m[1]; $uri = $m[2]; } else { // $m[1] is either quoted or not $quoteChar = $m[1][0] === "'" || $m[1][0] === '"' ? $m[1][0] : ''; $uri = $quoteChar === '' ? $m[1] : substr($m[1], 1, strlen($m[1]) - 2); } // analyze URI if (false === strpos($uri, '//') && 0 !== strpos($uri, 'data:')) { if (self::$_prependPath !== null) { if (w3_is_url(self::$_prependPath)) { $parse_url = @parse_url(self::$_prependPath); if ($parse_url && isset($parse_url['host'])) { $scheme = $parse_url['scheme']; $host = $parse_url['host']; $port = isset($parse_url['port']) && $parse_url['port'] != 80 ? ':' . (int) $parse_url['port'] : ''; $path = !empty($parse_url['path']) ? $parse_url['path'] : '/'; $dir_css = preg_replace('~[^/]+$~', '', $path); $dir_obj = preg_replace('~[^/]+$~', '', $uri); $dir = ltrim(strpos($dir_obj, '/') === 0 ? w3_realpath($dir_obj) : w3_realpath($dir_css . $dir_obj), '/'); $file = basename($uri); $uri = sprintf('%s://%s%s/%s%s', $scheme, $host, $port, $dir, $file); } } else { $uri = self::$_prependPath . $uri; } } else { $uri = self::rewriteRelative($uri, self::$_currentDir, self::$_docRoot, self::$_symlinks); } } return $isImport ? "@import {$quoteChar}{$uri}{$quoteChar}" : "url({$quoteChar}{$uri}{$quoteChar})"; }