Пример #1
0
 /**
  * Reads legacy config file
  * @param int $blog_id
  * @param bool $force_master
  * @return array
  */
 public function get_imported_legacy_config_keys($blog_id, $force_master = false)
 {
     $suffix = '';
     if ($force_master) {
     } else {
         if ($blog_id > 0) {
             if (w3_is_network()) {
                 if (w3_is_subdomain_install()) {
                     $suffix = '-' . w3_get_domain(w3_get_host());
                 } else {
                     // try subdir blog
                     $request_uri = rtrim($_SERVER['REQUEST_URI'], '/');
                     $site_home_uri = w3_get_base_path();
                     if (substr($request_uri, 0, strlen($site_home_uri)) == $site_home_uri) {
                         $request_path_in_wp = '/' . substr($request_uri, strlen($site_home_uri));
                         $n = strpos($request_path_in_wp, '/', 1);
                         if ($n === false) {
                             $blog_path_in_wp = substr($request_path_in_wp, 1);
                         } else {
                             $blog_path_in_wp = substr($request_path_in_wp, 1, $n - 1);
                         }
                         $suffix = '-' . ($blog_path_in_wp != 'wp-admin' ? $blog_path_in_wp . '.' : '') . w3_get_domain(w3_get_host());
                     }
                 }
             }
         }
     }
     $filename = WP_CONTENT_DIR . '/w3-total-cache-config' . $suffix . '.php';
     $legacy_config = W3_ConfigData::get_array_from_file($filename);
     if (is_array($legacy_config) && isset($legacy_config['pgcache.engine']) && $legacy_config['pgcache.engine'] == 'file_pgcache') {
         $legacy_config['pgcache.engine'] = 'file_generic';
     }
     return $legacy_config;
 }
Пример #2
0
 function cleanup_local()
 {
     $engine = $this->_config->get_string('pgcache.engine');
     switch ($engine) {
         case 'file':
             w3_require_once(W3TC_LIB_W3_DIR . '/Cache/File/Cleaner.php');
             $w3_cache_file_cleaner = new W3_Cache_File_Cleaner(array('cache_dir' => w3_cache_blog_dir('page'), 'clean_timelimit' => $this->_config->get_integer('timelimit.cache_gc')));
             $w3_cache_file_cleaner->clean();
             break;
         case 'file_generic':
             w3_require_once(W3TC_LIB_W3_DIR . '/Cache/File/Cleaner/Generic.php');
             if (w3_get_blog_id() == 0) {
                 $flush_dir = W3TC_CACHE_PAGE_ENHANCED_DIR;
             } else {
                 $flush_dir = W3TC_CACHE_PAGE_ENHANCED_DIR . '/' . w3_get_domain(w3_get_host());
             }
             $w3_cache_file_cleaner_generic = new W3_Cache_File_Cleaner_Generic(array('exclude' => array('.htaccess'), 'cache_dir' => $flush_dir, 'expire' => $this->_config->get_integer('browsercache.html.lifetime'), 'clean_timelimit' => $this->_config->get_integer('timelimit.cache_gc')));
             $w3_cache_file_cleaner_generic->clean();
             break;
     }
 }
Пример #3
0
 /**
  * Flush cache based on regex
  * @param string $regex
  */
 private function _flush_based_on_regex($regex)
 {
     if (w3_is_multisite() && !w3_is_subdomain_install()) {
         $domain = w3_get_home_url();
         $parsed = parse_url($domain);
         $host = $parsed['host'];
         $path = trim($parsed['path'], '/');
         $flush_dir = W3TC_CACHE_PAGE_ENHANCED_DIR . '/' . $host . '/' . $path;
     } else {
         $flush_dir = W3TC_CACHE_PAGE_ENHANCED_DIR . '/' . w3_get_domain(w3_get_host());
     }
     $dir = @opendir($flush_dir);
     if ($dir) {
         while (($entry = @readdir($dir)) !== false) {
             if ($entry == '.' || $entry == '..') {
                 continue;
             }
             if (preg_match('/' . $regex . '/', basename($entry))) {
                 w3_rmdir($flush_dir . DIRECTORY_SEPARATOR . $entry);
             }
         }
         @closedir($dir);
     }
 }
Пример #4
0
 /**
  * Send E-mail notification when error occurred
  *
  * @return boolean
  */
 function _send_notification()
 {
     $from_email = 'wordpress@' . w3_get_domain($_SERVER['SERVER_NAME']);
     $from_name = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
     $to_name = $to_email = get_option('admin_email');
     $body = @file_get_contents(W3TC_INC_DIR . '/email/minify_error_notification.php');
     $headers = array(sprintf('From: "%s" <%s>', addslashes($from_name), $from_email), sprintf('Reply-To: "%s" <%s>', addslashes($to_name), $to_email), 'Content-Type: text/html; charset=UTF-8');
     @set_time_limit($this->_config->get_integer('timelimit.email_send'));
     $result = @wp_mail($to_email, 'W3 Total Cache Error Notification', $body, implode("\n", $headers));
     return $result;
 }
Пример #5
0
/**
 * Parses path
 *
 * @param string $path
 * @return mixed
 */
function w3_parse_path($path)
{
    $path = str_replace(array('%BLOG_ID%', '%POST_ID%', '%BLOGNAME%', '%HOST%', '%DOMAIN%', '%BASE_PATH%'), array(isset($GLOBALS['blog_id']) ? (int) $GLOBALS['blog_id'] : 0, isset($GLOBALS['post_id']) ? (int) $GLOBALS['post_id'] : 0, w3_get_blogname(), w3_get_host(), w3_get_domain(w3_get_host()), trim(w3_get_base_path(), '/')), $path);
    return $path;
}
Пример #6
0
 /**
  * Send support request action
  *
  * @return void
  */
 function action_support_request()
 {
     w3_require_once(W3TC_LIB_W3_DIR . '/Request.php');
     $request_type = W3_Request::get_string('request_type');
     $payment = W3_Request::get_boolean('payment');
     $request_id = W3_Request::get_string('request_id');
     $url = W3_Request::get_string('url');
     $name = W3_Request::get_string('name');
     $email = W3_Request::get_string('email');
     $twitter = W3_Request::get_string('twitter');
     $phone = W3_Request::get_string('phone');
     $subject = W3_Request::get_string('subject');
     $description = W3_Request::get_string('description');
     $templates = W3_Request::get_array('templates');
     $forum_url = W3_Request::get_string('forum_url');
     $wp_login = W3_Request::get_string('wp_login');
     $wp_password = W3_Request::get_string('wp_password');
     $ftp_host = W3_Request::get_string('ftp_host');
     $ftp_login = W3_Request::get_string('ftp_login');
     $ftp_password = W3_Request::get_string('ftp_password');
     $subscribe_releases = W3_Request::get_string('subscribe_releases');
     $subscribe_customer = W3_Request::get_string('subscribe_customer');
     $params = array('request_type' => $request_type, 'payment' => $payment, 'url' => $url, 'name' => $name, 'email' => $email, 'twitter' => $twitter, 'phone' => $phone, 'subject' => $subject, 'description' => $description, 'forum_url' => $forum_url, 'wp_login' => $wp_login, 'wp_password' => $wp_password, 'ftp_host' => $ftp_host, 'ftp_login' => $ftp_login, 'ftp_password' => $ftp_password, 'subscribe_releases' => $subscribe_releases, 'subscribe_customer' => $subscribe_customer);
     $post = $params;
     foreach ($templates as $template_index => $template) {
         $template_key = sprintf('templates[%d]', $template_index);
         $params[$template_key] = $template;
     }
     if (!isset($this->_request_types[$request_type])) {
         w3_admin_redirect(array_merge($params, array('w3tc_error' => 'support_request_type')), false);
     }
     $required = array('bug_report' => 'url,name,email,subject,description', 'new_feature' => 'url,name,email,subject,description', 'email_support' => 'url,name,email,subject,description', 'phone_support' => 'url,name,email,subject,description,phone', 'plugin_config' => 'url,name,email,subject,description,wp_login,wp_password', 'theme_config' => 'url,name,email,subject,description,wp_login,wp_password,ftp_host,ftp_login,ftp_password', 'linux_config' => 'url,name,email,subject,description,wp_login,wp_password,ftp_host,ftp_login,ftp_password');
     if (strstr($required[$request_type], 'url') !== false && $url == '') {
         w3_admin_redirect(array_merge($params, array('w3tc_error' => 'support_request_url')), false);
     }
     if (strstr($required[$request_type], 'name') !== false && $name == '') {
         w3_admin_redirect(array_merge($params, array('w3tc_error' => 'support_request_name')), false);
     }
     if (strstr($required[$request_type], 'email') !== false && !preg_match('~^[a-z0-9_\\-\\.]+@[a-z0-9-\\.]+\\.[a-z]{2,5}$~', $email)) {
         w3_admin_redirect(array_merge($params, array('w3tc_error' => 'support_request_email')), false);
     }
     if (strstr($required[$request_type], 'phone') !== false && !preg_match('~^[0-9\\-\\.\\ \\(\\)\\+]+$~', $phone)) {
         w3_admin_redirect(array_merge($params, array('w3tc_error' => 'support_request_phone')), false);
     }
     if (strstr($required[$request_type], 'subject') !== false && $subject == '') {
         w3_admin_redirect(array_merge($params, array('w3tc_error' => 'support_request_subject')), false);
     }
     if (strstr($required[$request_type], 'description') !== false && $description == '') {
         w3_admin_redirect(array_merge($params, array('w3tc_error' => 'support_request_description')), false);
     }
     if (strstr($required[$request_type], 'wp_login') !== false && $wp_login == '') {
         w3_admin_redirect(array_merge($params, array('w3tc_error' => 'support_request_wp_login')), false);
     }
     if (strstr($required[$request_type], 'wp_password') !== false && $wp_password == '') {
         w3_admin_redirect(array_merge($params, array('w3tc_error' => 'support_request_wp_password')), false);
     }
     if (strstr($required[$request_type], 'ftp_host') !== false && $ftp_host == '') {
         w3_admin_redirect(array_merge($params, array('w3tc_error' => 'support_request_ftp_host')), false);
     }
     if (strstr($required[$request_type], 'ftp_login') !== false && $ftp_login == '') {
         w3_admin_redirect(array_merge($params, array('w3tc_error' => 'support_request_ftp_login')), false);
     }
     if (strstr($required[$request_type], 'ftp_password') !== false && $ftp_password == '') {
         w3_admin_redirect(array_merge($params, array('w3tc_error' => 'support_request_ftp_password')), false);
     }
     /**
      * Add attachments
      */
     $attachments = array();
     $attach_files = array(w3_get_wp_config_path(), w3_cache_blog_dir('log') . '/minify.log', w3_get_pgcache_rules_core_path(), w3_get_pgcache_rules_cache_path(), w3_get_browsercache_rules_cache_path(), w3_get_browsercache_rules_no404wp_path(), w3_get_minify_rules_core_path(), w3_get_minify_rules_cache_path());
     /**
      * Attach config files
      */
     if ($handle = opendir(W3TC_CONFIG_DIR)) {
         while (($entry = @readdir($handle)) !== false) {
             if ($entry == '.' || $entry == '..' || $entry == 'index.html') {
                 continue;
             }
             $attachments[] = W3TC_CONFIG_DIR . '/' . $entry;
         }
         closedir($handle);
     }
     foreach ($attach_files as $attach_file) {
         if ($attach_file && file_exists($attach_file) && !in_array($attach_file, $attachments)) {
             $attachments[] = $attach_file;
         }
     }
     /**
      * Attach server info
      */
     $server_info = print_r($this->get_server_info(), true);
     $server_info = str_replace("\n", "\r\n", $server_info);
     $server_info_path = W3TC_CACHE_TMP_DIR . '/server_info.txt';
     if (@file_put_contents($server_info_path, $server_info)) {
         $attachments[] = $server_info_path;
     }
     /**
      * Attach phpinfo
      */
     ob_start();
     phpinfo();
     $php_info = ob_get_contents();
     ob_end_clean();
     $php_info_path = W3TC_CACHE_TMP_DIR . '/php_info.html';
     if (@file_put_contents($php_info_path, $php_info)) {
         $attachments[] = $php_info_path;
     }
     /**
      * Attach self-test
      */
     ob_start();
     $this->action_self_test();
     $self_test = ob_get_contents();
     ob_end_clean();
     $self_test_path = W3TC_CACHE_TMP_DIR . '/self_test.html';
     if (@file_put_contents($self_test_path, $self_test)) {
         $attachments[] = $self_test_path;
     }
     /**
      * Attach templates
      */
     foreach ($templates as $template) {
         if (!empty($template)) {
             $attachments[] = $template;
         }
     }
     /**
      * Attach other files
      */
     if (!empty($_FILES['files'])) {
         $files = (array) $_FILES['files'];
         for ($i = 0, $l = count($files); $i < $l; $i++) {
             if (isset($files['tmp_name'][$i]) && isset($files['name'][$i]) && isset($files['error'][$i]) && $files['error'][$i] == UPLOAD_ERR_OK) {
                 $path = W3TC_CACHE_TMP_DIR . '/' . $files['name'][$i];
                 if (@move_uploaded_file($files['tmp_name'][$i], $path)) {
                     $attachments[] = $path;
                 }
             }
         }
     }
     $data = array();
     if (!empty($wp_login) && !empty($wp_password)) {
         $data['WP Admin login'] = $wp_login;
         $data['WP Admin password'] = $wp_password;
     }
     if (!empty($ftp_host) && !empty($ftp_login) && !empty($ftp_password)) {
         $data['SSH / FTP host'] = $ftp_host;
         $data['SSH / FTP login'] = $ftp_login;
         $data['SSH / FTP password'] = $ftp_password;
     }
     /**
      * Store request data for future access
      */
     if (count($data)) {
         $hash = md5(microtime());
         $request_data = get_option('w3tc_request_data', array());
         $request_data[$hash] = $data;
         update_option('w3tc_request_data', $request_data);
         $request_data_url = sprintf('%s/w3tc_request_data/%s', w3_get_home_url(), $hash);
     } else {
         $request_data_url = '';
     }
     $nonce = wp_create_nonce('w3tc_support_request');
     if (is_network_admin()) {
         update_site_option('w3tc_support_request', $nonce);
     } else {
         update_option('w3tc_support_request', $nonce);
     }
     $file_access = WP_PLUGIN_URL . '/' . dirname(W3TC_FILE) . '/pub/files.php';
     if (w3_get_domain(w3_get_home_url()) != w3_get_domain(w3_get_site_url())) {
         $file_access = str_replace(w3_get_domain(w3_get_home_url()), w3_get_domain(w3_get_site_url()), $file_access);
     }
     $post['file_access'] = $file_access;
     $post['nonce'] = $nonce;
     $post['request_data_url'] = $request_data_url;
     $post['ip'] = $_SERVER['REMOTE_ADDR'];
     $post['user_agent'] = $_SERVER['HTTP_USER_AGENT'];
     $post['version'] = W3TC_VERSION;
     $post['plugin'] = 'W3 Total Cache';
     $post['request_id'] = $request_id;
     $license_level = 'community';
     if (w3_is_pro($this->_config)) {
         $license_level = 'pro';
     } elseif (w3_is_enterprise($this->_config)) {
         $license_level = 'enterprise';
     }
     $post['license_level'] = $license_level;
     $unset = array('wp_login', 'wp_password', 'ftp_host', 'ftp_login', 'ftp_password');
     foreach ($unset as $key) {
         unset($post[$key]);
     }
     foreach ($attachments as $attachment) {
         if (is_network_admin()) {
             update_site_option('attachment_' . md5($attachment), $attachment);
         } else {
             update_option('attachment_' . md5($attachment), $attachment);
         }
     }
     $post = array_merge($post, array('files' => $attachments));
     if (defined('W3_SUPPORT_DEBUG') && W3_SUPPORT_DEBUG) {
         $data = sprintf("[%s] Post support request\n", date('r'));
         foreach ($post as $key => $value) {
             $data .= sprintf("%s => %s\n", $key, is_array($value) ? implode(',', $value) : $value);
         }
         $filename = w3_cache_blog_dir('log') . '/support.log';
         if (!is_dir(dirname($filename))) {
             w3_mkdir_from(dirname($filename), W3TC_CACHE_DIR);
         }
         @file_put_contents($filename, $data, FILE_APPEND);
     }
     $response = wp_remote_post(W3TC_SUPPORT_REQUEST_URL, array('body' => $post, 'timeout' => $this->_config->get_integer('timelimit.email_send')));
     if (defined('W3_SUPPORT_DEBUG') && W3_SUPPORT_DEBUG) {
         $filename = w3_cache_blog_dir('log') . '/support.log';
         $data = sprintf("[%s] Post response \n%s\n", date('r'), print_r($response, true));
         @file_put_contents($filename, $data, FILE_APPEND);
     }
     if (!is_wp_error($response)) {
         $result = $response['response']['code'] == 200 && $response['body'] == 'Ok';
     } else {
         $result = false;
     }
     /**
      * Remove temporary files
      */
     foreach ($attachments as $attachment) {
         if (strstr($attachment, W3TC_CACHE_TMP_DIR) !== false) {
             @unlink($attachment);
         }
         if (is_network_admin()) {
             delete_site_option('attachment_' . md5($attachment));
         } else {
             delete_option('attachment_' . md5($attachment));
         }
     }
     if (is_network_admin()) {
         delete_site_option('w3tc_support_request');
     } else {
         delete_option('w3tc_support_request');
     }
     if ($result) {
         w3_admin_redirect(array('tab' => 'general', 'w3tc_note' => 'support_request'), false);
     } else {
         w3_admin_redirect(array_merge($params, array('request_type' => $request_type, 'w3tc_error' => 'support_request')), false);
     }
 }
Пример #7
0
 /**
  * Returns cache object
  *
  * @return W3_Cache_Base
  */
 function _get_cache()
 {
     static $cache = array();
     if (!isset($cache[0])) {
         $engine = $this->_config->get_string('pgcache.engine');
         switch ($engine) {
             case 'memcached':
                 $engineConfig = array('servers' => $this->_config->get_array('pgcache.memcached.servers'), 'persistant' => $this->_config->get_boolean('pgcache.memcached.persistant'));
                 break;
             case 'file':
                 $engineConfig = array('section' => 'page', 'flush_parent' => w3_get_blog_id() == 0, 'locking' => $this->_config->get_boolean('pgcache.file.locking'), 'flush_timelimit' => $this->_config->get_integer('timelimit.cache_flush'));
                 break;
             case 'file_generic':
                 if (w3_get_blog_id() == 0) {
                     $flush_dir = W3TC_CACHE_PAGE_ENHANCED_DIR;
                 } else {
                     $flush_dir = W3TC_CACHE_PAGE_ENHANCED_DIR . '/' . w3_get_domain(w3_get_host());
                 }
                 $engineConfig = array('exclude' => array('.htaccess'), 'expire' => $this->_lifetime, 'cache_dir' => W3TC_CACHE_PAGE_ENHANCED_DIR, 'locking' => $this->_config->get_boolean('pgcache.file.locking'), 'flush_timelimit' => $this->_config->get_integer('timelimit.cache_flush'), 'flush_dir' => $flush_dir);
                 break;
             default:
                 $engineConfig = array();
         }
         $engineConfig['use_expired_data'] = true;
         $engineConfig['module'] = 'pgcache';
         $engineConfig['host'] = w3_get_host();
         $engineConfig['instance_id'] = w3_get_instance_id();
         w3_require_once(W3TC_LIB_W3_DIR . '/Cache.php');
         $cache[0] = W3_Cache::instance($engine, $engineConfig);
     }
     return $cache[0];
 }
Пример #8
0
/**
 * 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;
}
Пример #9
0
    function print_script()
    {
        ?>
        <script type="text/javascript">
            var w3_use_network_link = <?php 
        echo is_network_admin() || w3_is_multisite() && w3_force_master() ? 'true' : 'false';
        ?>
;
            function w3tc_start_minify_try_solve() {
                var testUrl = '<?php 
        echo w3_filename_to_url(w3_cache_blog_dir('minify') . '/', w3_get_domain(w3_get_home_url()) != w3_get_domain(w3_get_site_url()));
        ?>
';
                w3tc_filename_auto_solve(testUrl);
            }
        </script>
        <?php 
    }
Пример #10
0
 /**
  * Reads legacy config file
  *
  * @param object $compiled_config
  * @return array
  */
 private function _import_legacy_config($compiled_config)
 {
     $suffix = '';
     if ($this->_blog_id > 0) {
         if (w3_is_network()) {
             if (w3_is_subdomain_install()) {
                 $suffix = '-' . w3_get_domain(w3_get_host());
             } else {
                 // try subdir blog
                 $request_uri = rtrim($_SERVER['REQUEST_URI'], '/');
                 $site_home_uri = w3_get_base_path();
                 if (substr($request_uri, 0, strlen($site_home_uri)) == $site_home_uri) {
                     $request_path_in_wp = '/' . substr($request_uri, strlen($site_home_uri));
                     $n = strpos($request_path_in_wp, '/', 1);
                     if ($n === false) {
                         $blog_path_in_wp = substr($request_path_in_wp, 1);
                     } else {
                         $blog_path_in_wp = substr($request_path_in_wp, 1, $n - 1);
                     }
                     $suffix = '-' . ($blog_path_in_wp != 'wp-admin' ? $blog_path_in_wp . '.' : '') . w3_get_domain(w3_get_host());
                 }
             }
         }
     }
     $filename = WP_CONTENT_DIR . '/w3-total-cache-config' . $suffix . '.php';
     return $compiled_config->get_array_from_file($filename);
 }
Пример #11
0
 /**
  * OB Callback
  *
  * @param string $buffer
  * @return string
  */
 function ob_callback(&$buffer)
 {
     if ($buffer != '' && w3_is_xml($buffer)) {
         if ($this->can_cdn2($buffer)) {
             $regexps = array();
             $site_path = w3_get_site_path();
             $domain_url_regexp = w3_get_domain_url_regexp();
             $site_domain_url_regexp = false;
             if ($domain_url_regexp != w3_get_url_regexp(w3_get_domain(w3_get_site_url()))) {
                 $site_domain_url_regexp = w3_get_url_regexp(w3_get_domain(w3_get_site_url()));
             }
             if ($this->_config->get_boolean('cdn.uploads.enable')) {
                 w3_require_once(W3TC_INC_DIR . '/functions/http.php');
                 $upload_info = w3_upload_info();
                 if ($upload_info) {
                     $baseurl = $upload_info['baseurl'];
                     if (defined('DOMAIN_MAPPING') && DOMAIN_MAPPING) {
                         $parsed = @parse_url($upload_info['baseurl']);
                         $baseurl = home_url() . $parsed['path'];
                     }
                     $regexps = $this->make_uploads_regexes($domain_url_regexp, $baseurl, $upload_info, $regexps);
                     if ($site_domain_url_regexp) {
                         $regexps = $this->make_uploads_regexes($site_domain_url_regexp, $baseurl, $upload_info, $regexps);
                     }
                 }
             }
             if ($this->_config->get_boolean('cdn.includes.enable')) {
                 $mask = $this->_config->get_string('cdn.includes.files');
                 if ($mask != '') {
                     $regexps[] = '~(["\'(])\\s*((' . $domain_url_regexp . ')?(' . w3_preg_quote($site_path . WPINC) . '/(' . $this->get_regexp_by_mask($mask) . ')))~';
                     if ($site_domain_url_regexp) {
                         $regexps[] = '~(["\'(])\\s*((' . $site_domain_url_regexp . ')?(' . w3_preg_quote($site_path . WPINC) . '/(' . $this->get_regexp_by_mask($mask) . ')))~';
                     }
                 }
             }
             if ($this->_config->get_boolean('cdn.theme.enable')) {
                 $theme_dir = preg_replace('~' . $domain_url_regexp . '~i', '', get_theme_root_uri());
                 $mask = $this->_config->get_string('cdn.theme.files');
                 if ($mask != '') {
                     $regexps[] = '~(["\'(])\\s*((' . $domain_url_regexp . ')?(' . w3_preg_quote($theme_dir) . '/(' . $this->get_regexp_by_mask($mask) . ')))~';
                     if ($site_domain_url_regexp) {
                         $theme_dir2 = preg_replace('~' . $site_domain_url_regexp . '~i', '', get_theme_root_uri());
                         $regexps[] = '~(["\'(])\\s*((' . $site_domain_url_regexp . ')?(' . w3_preg_quote($theme_dir) . '/(' . $this->get_regexp_by_mask($mask) . ')))~';
                         $regexps[] = '~(["\'(])\\s*((' . $site_domain_url_regexp . ')?(' . w3_preg_quote($theme_dir2) . '/(' . $this->get_regexp_by_mask($mask) . ')))~';
                     }
                 }
             }
             if ($this->_config->get_boolean('cdn.custom.enable')) {
                 $masks = $this->_config->get_array('cdn.custom.files');
                 $masks = array_map(array($this, '_replace_folder_placeholders'), $masks);
                 $masks = array_map('w3_parse_path', $masks);
                 if (count($masks)) {
                     $mask_regexps = array();
                     foreach ($masks as $mask) {
                         if ($mask != '') {
                             $mask = w3_normalize_file($mask);
                             $mask_regexps[] = $this->get_regexp_by_mask($mask);
                         }
                     }
                     $regexps[] = '~(["\'(])\\s*((' . $domain_url_regexp . ')?(' . w3_preg_quote($site_path) . '(' . implode('|', $mask_regexps) . ')))~i';
                     if ($site_domain_url_regexp) {
                         $regexps[] = '~(["\'(])\\s*((' . $site_domain_url_regexp . ')?(' . w3_preg_quote($site_path) . '(' . implode('|', $mask_regexps) . ')))~i';
                     }
                 }
             }
             foreach ($regexps as $regexp) {
                 $buffer = preg_replace_callback($regexp, array(&$this, 'link_replace_callback'), $buffer);
             }
             if ($this->_config->get_boolean('cdn.minify.enable')) {
                 if ($this->_config->get_boolean('minify.auto')) {
                     $regexp = '~(["\'(])\\s*' . $this->_minify_url_regexp('/[a-zA-Z0-9-_]+\\.(css|js)') . '~U';
                     if (w3_is_cdn_mirror($this->_config->get_string('cdn.engine'))) {
                         $processor = 'link_replace_callback';
                     } else {
                         $processor = 'minify_auto_pushcdn_link_replace_callback';
                     }
                 } else {
                     $regexp = '~(["\'(])\\s*' . $this->_minify_url_regexp('/[a-z0-9]+/.+\\.include(-(footer|body))?(-nb)?\\.[a-f0-9]+\\.(css|js)') . '~U';
                     $processor = 'link_replace_callback';
                 }
                 $buffer = preg_replace_callback($regexp, array(&$this, $processor), $buffer);
             }
         }
         if ($this->_config->get_boolean('cdn.debug')) {
             $buffer .= "\r\n\r\n" . $this->get_debug_info();
         }
     }
     return $buffer;
 }
Пример #12
0
/**
 * Returns blog ID
 *
 * @return string
 */
function w3_get_blog_id()
{
    static $id = null;
    if ($id === null) {
        $wpmu = false;
        if (defined('VHOST')) {
            $wpmu = true;
        } else {
            $wpmu = file_exists(ABSPATH . 'wpmu-settings.php');
        }
        if ($wpmu) {
            if (defined('VHOST') && VHOST === 'yes') {
                $id = w3_get_domain($_SERVER['HTTP_HOST']);
            } else {
                if (defined('PATH_CURRENT_SITE')) {
                    $base = PATH_CURRENT_SITE;
                } elseif (isset($GLOBALS['base'])) {
                    $base = $GLOBALS['base'];
                } else {
                    $base = '/';
                }
                if (empty($base)) {
                    $base = '/';
                }
                $id = strtolower($_SERVER['REQUEST_URI']);
                if (strpos($id, $base) === 0) {
                    $id = substr_replace($id, '', 0, strlen($base));
                }
                if ($pos = strpos($id, '/')) {
                    $id = substr($id, 0, $pos);
                }
                if ($pos = strpos($id, '?')) {
                    $id = substr($id, 0, $pos);
                }
                if ($id != '') {
                    $id = trim($id, '/');
                    if (in_array($id, array('page', 'comments', 'blog', 'wp-admin', 'wp-includes', 'wp-content', 'files', 'feed')) || is_file($id)) {
                        $id = '';
                    } else {
                        $id = $id . '.' . w3_get_domain($_SERVER['HTTP_HOST']);
                    }
                }
            }
        }
    }
    return $id;
}