Exemplo n.º 1
0
 /**
  * Link replace callback
  *
  * @param string $matches
  * @return string
  */
 function link_replace_callback($matches)
 {
     static $id = null, $extensions = null, $exceptions = null;
     if ($id === null) {
         $id = $this->get_replace_id();
     }
     if ($extensions === null) {
         $extensions = $this->get_replace_extensions();
     }
     if ($exceptions === null) {
         $exceptions = $this->_config->get_array('browsercache.replace.exceptions');
     }
     list($match, $attr, $url, , , , , $extension) = $matches;
     if (in_array($extension, $extensions)) {
         $url = w3_remove_query($url);
         foreach ($exceptions as $exception) {
             if (preg_match('/' . $exception . '/', $url)) {
                 return $match;
             }
         }
         $url .= (strstr($url, '?') !== false ? '&' : '?') . $id;
         if ($attr != 'w3tc_load_js(') {
             return sprintf('%s="%s"', $attr, $url);
         }
         return sprintf('%s\'%s\'', $attr, $url);
     }
     return $match;
 }
 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})";
 }
Exemplo n.º 3
0
/**
 * Normalizes file name for minify
 *
 * Relative to document root!
 *
 * @param string $file
 * @return string
 */
function w3_normalize_file_minify2($file)
{
    $file = w3_remove_query($file);
    $file = w3_normalize_file_minify($file);
    $file = w3_translate_file($file);
    return $file;
}
Exemplo n.º 4
0
 /**
  * Creates add-in
  * @throws FilesystemOperationException
  */
 private function create_addin()
 {
     $src = W3TC_INSTALL_FILE_DB;
     $dst = W3TC_ADDIN_FILE_DB;
     if ($this->db_installed()) {
         if ($this->is_dbcache_add_in()) {
             $script_data = @file_get_contents($dst);
             if ($script_data == @file_get_contents($src)) {
                 return;
             }
         } elseif (!$this->db_check_old_add_in()) {
             w3_require_once(W3TC_INC_FUNCTIONS_DIR . '/other.php');
             w3_require_once(W3TC_INC_FUNCTIONS_DIR . '/ui.php');
             if (isset($_GET['page'])) {
                 $url = 'admin.php?page=' . $_GET['page'] . '&';
             } else {
                 $url = basename(w3_remove_query($_SERVER['REQUEST_URI'])) . '?page=w3tc_dashboard&';
             }
             $remove_url = w3_admin_url($url . 'w3tc_default_remove_add_in=dbcache');
             throw new FilesystemOperationException(sprintf(__('The Database add-in file db.php is not a W3 Total Cache drop-in.
                 Remove it or disable Database Caching. %s', 'w3-total-cache'), w3tc_button_link(__('Remove it for me', 'w3-total-cache'), wp_nonce_url($remove_url, 'w3tc'))));
         }
     }
     w3_wp_copy_file($src, $dst);
 }
Exemplo n.º 5
0
 /**
  * Link replace callback
  *
  * @param string $matches
  * @return string
  */
 function link_replace_callback($matches)
 {
     static $id = null, $extensions = null;
     if ($id === null) {
         $id = $this->get_replace_id();
     }
     if ($extensions === null) {
         $extensions = $this->get_replace_extensions();
     }
     list($match, $attr, $url, , , , , $extension) = $matches;
     if (in_array($extension, $extensions)) {
         $url = w3_remove_query($url);
         $url .= (strstr($url, '?') !== false ? '&' : '?') . $id;
         return sprintf('%s="%s"', $attr, $url);
     }
     return $match;
 }
Exemplo n.º 6
0
 function _url_has_to_be_replaced($url, $extension)
 {
     static $extensions = null;
     if ($extensions === null) {
         $extensions = $this->get_replace_extensions();
     }
     static $exceptions = null;
     if ($exceptions === null) {
         $exceptions = $this->_config->get_array('browsercache.replace.exceptions');
     }
     if (!in_array($extension, $extensions)) {
         return false;
     }
     $test_url = w3_remove_query($url);
     foreach ($exceptions as $exception) {
         if (trim($exception) && preg_match('/' . $exception . '/', $test_url)) {
             return false;
         }
     }
     return true;
 }