예제 #1
0
파일: define.php 프로젝트: alx/SBek-Arak
/**
 * Detect WPMU blogname
 *
 * @return string
 */
function w3_get_blogname()
{
    static $blogname = null;
    if ($blogname === null) {
        if (w3_is_wpmu()) {
            $domain = w3_get_domain($_SERVER['HTTP_HOST']);
            if (w3_is_vhost()) {
                $blogname = $domain;
            } else {
                $uri = $_SERVER['REQUEST_URI'];
                $site_path = w3_get_site_path();
                if ($site_path != '' && strpos($uri, $site_path) === 0) {
                    $uri = substr_replace($uri, '/', 0, strlen($site_path));
                }
                $blogname = w3_get_blogname_from_uri($uri);
                if ($blogname != '') {
                    $blogname = $blogname . '.' . $domain;
                } else {
                    $blogname = $domain;
                }
            }
        } else {
            $blogname = '';
        }
    }
    return $blogname;
}
 /**
  * Generates rules for WP dir
  *
  * @return string
  */
 function generate_rules_core()
 {
     global $w3_reserved_blognames;
     /**
      * Auto reject cookies
      */
     $reject_cookies = array('comment_author', 'wp-postpass');
     /**
      * Auto reject URIs
      */
     $reject_uris = array('\\/wp-admin\\/', '\\/xmlrpc.php', '\\/wp-(app|cron|login|register).php');
     /**
      * Reject cache for logged in users
      */
     if ($this->_config->get_boolean('pgcache.reject.logged')) {
         $reject_cookies = array_merge($reject_cookies, array('wordpress_[a-f0-9]+', 'wordpress_logged_in'));
     }
     /**
      * Reject cache for home page
      */
     if (!$this->_config->get_boolean('pgcache.cache.home')) {
         $reject_uris[] = '^(\\/|\\/index.php)$';
     }
     /**
      * Reject cache for feeds
      */
     if (!$this->_config->get_boolean('pgcache.cache.feed')) {
         $reject_uris[] = 'feed';
     }
     /**
      * Custom config
      */
     $reject_cookies = array_merge($reject_cookies, $this->_config->get_array('pgcache.reject.cookie'));
     $reject_uris = array_merge($reject_uris, $this->_config->get_array('pgcache.reject.uri'));
     $reject_user_agents = $this->_config->get_array('pgcache.reject.ua');
     $accept_files = $this->_config->get_array('pgcache.accept.files');
     /**
      * WPMU support
      */
     $is_wpmu = w3_is_wpmu();
     $is_vhost = w3_is_vhost();
     /**
      * Generate directives
      */
     $rules = '';
     $rules .= "# BEGIN W3 Total Cache\n";
     $setenvif_rules = '';
     if ($is_wpmu) {
         $setenvif_rules .= "    SetEnvIfNoCase Host ^(www\\.)?([a-z0-9\\-\\.]+\\.[a-z]+)\\.?(:[0-9]+)?\$ DOMAIN=\$2\n";
         if (!$is_vhost) {
             $setenvif_rules .= "    SetEnvIfNoCase Request_URI ^" . w3_get_site_path() . "([a-z0-9\\-]+)/ BLOGNAME=\$1\n";
         }
     }
     $compression = $this->_config->get_string('pgcache.compression');
     if ($compression != '') {
         $compressions = array();
         if (stristr($compression, 'gzip') !== false) {
             $compressions[] = 'gzip';
         }
         if (stristr($compression, 'deflate') !== false) {
             $compressions[] = 'deflate';
         }
         if (count($compressions)) {
             $setenvif_rules .= "    SetEnvIfNoCase Accept-Encoding (" . implode('|', $compressions) . ") APPEND_EXT=.\$1\n";
         }
     }
     if ($setenvif_rules != '') {
         $rules .= "<IfModule mod_setenvif.c>\n" . ($setenvif_rules .= "</IfModule>\n");
     }
     $rules .= "<IfModule mod_rewrite.c>\n";
     $rules .= "    RewriteEngine On\n";
     $mobile_redirect = $this->_config->get_string('pgcache.mobile.redirect');
     if ($mobile_redirect != '') {
         $mobile_agents = $this->_config->get_array('pgcache.mobile.agents');
         $rules .= "    RewriteCond %{HTTP_USER_AGENT} (" . implode('|', array_map('w3_preg_quote', $mobile_agents)) . ") [NC]\n";
         $rules .= "    RewriteRule .* " . $mobile_redirect . " [R,L]\n";
     }
     $rules .= "    RewriteCond %{REQUEST_URI} \\/\$\n";
     $rules .= "    RewriteCond %{REQUEST_URI} !(" . implode('|', $reject_uris) . ")";
     if (count($accept_files)) {
         $rules .= " [OR]\n    RewriteCond %{REQUEST_URI} (" . implode('|', array_map('w3_preg_quote', $accept_files)) . ") [NC]\n";
     } else {
         $rules .= "\n";
     }
     $rules .= "    RewriteCond %{REQUEST_METHOD} !=POST\n";
     $rules .= "    RewriteCond %{QUERY_STRING} =\"\"\n";
     $rules .= "    RewriteCond %{HTTP_COOKIE} !(" . implode('|', array_map('w3_preg_quote', $reject_cookies)) . ") [NC]\n";
     if (count($reject_user_agents)) {
         $rules .= "    RewriteCond %{HTTP_USER_AGENT} !(" . implode('|', array_map('w3_preg_quote', $reject_user_agents)) . ") [NC]\n";
     }
     if ($is_wpmu) {
         if ($is_vhost) {
             $replacement = '/w3tc-%{ENV:DOMAIN}/';
         } else {
             $rules .= "    RewriteCond %{ENV:BLOGNAME} !^(" . implode('|', $w3_reserved_blognames) . ")\$\n";
             $rules .= "    RewriteCond %{ENV:BLOGNAME} !-f\n";
             $rules .= "    RewriteCond %{ENV:BLOGNAME} !-d\n";
             $replacement = '/w3tc-%{ENV:BLOGNAME}.%{ENV:DOMAIN}/';
         }
         $cache_dir = preg_replace('~/w3tc.*/~U', $replacement, W3TC_CACHE_FILE_PGCACHE_DIR, 1);
     } else {
         $cache_dir = W3TC_CACHE_FILE_PGCACHE_DIR;
     }
     $rules .= "    RewriteCond " . w3_path($cache_dir) . "/\$1/_default_.html%{ENV:APPEND_EXT} -f\n";
     $rules .= "    RewriteRule (.*) " . str_replace(ABSPATH, '', $cache_dir) . "/\$1/_default_.html%{ENV:APPEND_EXT} [L]\n";
     $rules .= "</IfModule>\n";
     $rules .= "# END W3 Total Cache\n\n";
     if (!$this->check_rules_wp()) {
         $rules .= "# BEGIN WordPress\n";
         $rules .= "<IfModule mod_rewrite.c>\n";
         $rules .= "    RewriteEngine On\n";
         $rules .= "    RewriteCond %{REQUEST_FILENAME} !-f\n";
         $rules .= "    RewriteCond %{REQUEST_FILENAME} !-d\n";
         $rules .= "    RewriteRule .* index.php [L]\n";
         $rules .= "</IfModule>\n";
         $rules .= "# END WordPress\n\n";
     }
     return $rules;
 }