/** * 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; }
/** * Returns origin * * @return string */ function _get_origin() { if ($this->type == W3TC_CDN_CF_TYPE_S3) { $origin = sprintf('%s.s3.amazonaws.com', $this->_config['bucket']); } else { $origin = w3_get_host(); } return $origin; }
function action_payment_code() { w3_require_once(W3TC_LIB_W3_DIR . '/Request.php'); $request_type = W3_Request::get_string('request_type'); $request_id = date('YmdHi'); $return_url = admin_url('admin.php?page=w3tc_support&request_type=' . $request_type . '&payment=1&request_id=' . $request_id); $cancel_url = admin_url('admin.php?page=w3tc_dashboard'); $form_values = array("cmd" => "_xclick", "business" => W3TC_PAYPAL_BUSINESS, "item_name" => esc_attr(sprintf('%s: %s (#%s)', ucfirst(w3_get_host()), $this->_json_request_types[$request_type], $request_id)), "amount" => sprintf('%.2f', $this->_request_prices[$request_type]), "currency_code" => "USD", "no_shipping" => "1", "rm" => "2", "return" => esc_attr($return_url), "cancel_return" => esc_attr($cancel_url)); echo json_encode($form_values); die; }
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; } }
?> </p> <p><strong>Price: <?php echo sprintf('%.2f', $this->_request_prices[$request_type]); ?> USD</strong></p> <p> <input type="hidden" name="cmd" value="_xclick" /> <input type="hidden" name="business" value="<?php echo W3TC_PAYPAL_BUSINESS; ?> " /> <input type="hidden" name="item_name" value="<?php echo htmlspecialchars(sprintf('%s: %s (#%s)', ucfirst(w3_get_host()), $this->_request_types[$request_type], $request_id)); ?> " /> <input type="hidden" name="amount" value="<?php echo sprintf('%.2f', $this->_request_prices[$request_type]); ?> " /> <input type="hidden" name="currency_code" value="USD" /> <input type="hidden" name="no_shipping" value="1" /> <input type="hidden" name="rm" value="2" /> <input type="hidden" name="return" value="<?php echo htmlspecialchars($return_url); ?> " /> <input type="hidden" name="cancel_return" value="<?php echo htmlspecialchars($cancel_url);
</td> </tr> <tr> <th><label for="cloudflare_key"><acronym title="Application Programming Interface">API</acronym> key:</label></th> <td> <input id="cloudflare_key" class="w3tc-ignore-change" type="password" name="cloudflare.key" value="<?php echo htmlspecialchars($this->_config->get_string('cloudflare.key')); ?> " size="60" /> (<a href="https://www.cloudflare.com/my-account.html">find it here</a>) </td> </tr> <tr> <th>Domain:</th> <td> <input id="cloudflare_zone" type="text" name="cloudflare.zone" value="<?php echo htmlspecialchars($this->_config->get_string('cloudflare.zone', w3_get_host())); ?> " size="40" /> </td> </tr> <tr> <th>Security level:</th> <td> <input type="hidden" name="cloudflare_seclvl_old" value="<?php echo $cloudflare_seclvl; ?> " /> <select name="cloudflare_seclvl_new" class="w3tc-ignore-change"> <?php foreach ($cloudflare_seclvls as $cloudflare_seclvl_key => $cloudflare_seclvl_label) { ?>
/** * Returns cache object * * @param null $blog_id * @param string $group * @return W3_Cache_Base */ function _get_cache($blog_id = null, $group = 'transient') { static $cache = array(); if (is_null($blog_id) && $group != 'site-transient') { $blog_id = $this->_blog_id; } else { $blog_id = 0; } if (!isset($cache[$blog_id])) { $engine = $this->_config->get_string('fragmentcache.engine'); switch ($engine) { case 'memcached': $engineConfig = array('servers' => $this->_config->get_array('fragmentcache.memcached.servers'), 'persistant' => $this->_config->get_boolean('fragmentcache.memcached.persistant')); break; case 'file': $engineConfig = array('section' => 'fragment', 'locking' => $this->_config->get_boolean('fragmentcache.file.locking'), 'flush_timelimit' => $this->_config->get_integer('timelimit.cache_flush')); break; default: $engineConfig = array(); } $engineConfig['blog_id'] = $blog_id; $engineConfig['module'] = 'fragmentcache'; $engineConfig['host'] = w3_get_host(); $engineConfig['instance_id'] = w3_get_instance_id(); w3_require_once(W3TC_LIB_W3_DIR . '/Cache.php'); $cache[$blog_id] = W3_Cache::instance($engine, $engineConfig); } return $cache[$blog_id]; }
/** * 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]; }
<td> <input id="cdn_cf2_secret" class="w3tc-ignore-change" <?php $this->sealing_disabled('cdn'); ?> type="password" name="cdn.cf2.secret" value="<?php echo htmlspecialchars($this->_config->get_string('cdn.cf2.secret')); ?> " size="60" /> </td> </tr> <tr> <th>Origin:</th> <td> <?php echo w3_get_host(); ?> <input id="cdn_create_container" <?php $this->sealing_disabled('cdn'); ?> class="button {type: 'cf2', nonce: '<?php echo wp_create_nonce('w3tc'); ?> '}" type="button" value="Create distribution" /> <span id="cdn_create_container_status" class="w3tc-status w3tc-process"></span> </td> </tr> <tr> <th><label for="cdn_cf2_ssl"><acronym title="Secure Sockets Layer">SSL</acronym> support:</label></th> <td>
/** * 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); }
/** * Returns minify cache object * * @return object */ function _get_cache() { static $cache = array(); if (!isset($cache[0])) { switch ($this->_config->get_string('minify.engine')) { case 'memcached': w3_require_once(W3TC_LIB_W3_DIR . '/Cache/Memcached.php'); w3_require_once(W3TC_LIB_MINIFY_DIR . '/Minify/Cache/Memcache.php'); $w3_cache_memcached = new W3_Cache_Memcached(array('blog_id' => w3_get_blog_id(), 'instance_id' => w3_get_instance_id(), 'host' => w3_get_host(), 'module' => 'minify', 'servers' => $this->_config->get_array('minify.memcached.servers'), 'persistant' => $this->_config->get_boolean('minify.memcached.persistant'))); $cache[0] = new Minify_Cache_Memcache($w3_cache_memcached, 0, w3_get_blog_id(), w3_get_instance_id()); break; case 'apc': w3_require_once(W3TC_LIB_MINIFY_DIR . '/Minify/Cache/APC.php'); $cache[0] = new Minify_Cache_APC(0, w3_get_blog_id(), w3_get_instance_id()); break; case 'eaccelerator': w3_require_once(W3TC_LIB_MINIFY_DIR . '/Minify/Cache/Eaccelerator.php'); $cache[0] = new Minify_Cache_Eaccelerator(0, w3_get_blog_id(), w3_get_instance_id()); break; case 'xcache': w3_require_once(W3TC_LIB_MINIFY_DIR . '/Minify/Cache/XCache.php'); $cache[0] = new Minify_Cache_XCache(0, w3_get_blog_id(), w3_get_instance_id()); break; case 'wincache': w3_require_once(W3TC_LIB_MINIFY_DIR . '/Minify/Cache/Wincache.php'); $cache[0] = new Minify_Cache_Wincache(0, w3_get_blog_id(), w3_get_instance_id()); break; case 'file': default: w3_require_once(W3TC_LIB_MINIFY_DIR . '/Minify/Cache/File.php'); $cache[0] = new Minify_Cache_File(w3_cache_blog_dir('minify'), array('.htaccess', 'index.php', '*.old'), $this->_config->get_boolean('minify.file.locking'), $this->_config->get_integer('timelimit.cache_flush'), w3_get_blog_id() == 0 ? W3TC_CACHE_MINIFY_DIR : null); break; } } return $cache[0]; }
/** * Returns cache object * * @return W3_Cache_Base */ function _get_cache() { static $cache = array(); if (!isset($cache[0])) { $engine = $this->_config->get_string('dbcache.engine'); switch ($engine) { case 'memcached': $engineConfig = array('servers' => $this->_config->get_array('dbcache.memcached.servers'), 'persistant' => $this->_config->get_boolean('dbcache.memcached.persistant')); break; case 'file': $engineConfig = array('use_wp_hash', true, 'section' => 'db', 'locking' => $this->_config->get_boolean('dbcache.file.locking'), 'flush_timelimit' => $this->_config->get_integer('timelimit.cache_flush')); break; default: $engineConfig = array(); } $engineConfig['module'] = 'dbcache'; $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]; }
?> </a>) </td> </tr> <tr> <th><?php _e('Domain:', 'w3-total-cache'); ?> </th> <td> <input id="cloudflare_zone" type="text" name="cloudflare.zone" <?php $this->sealing_disabled('cloudflare'); ?> value="<?php echo esc_attr($this->_config->get_string('cloudflare.zone', w3_get_host())); ?> " size="40" /> </td> </tr> <tr> <th><?php _e('Security level:', 'w3-total-cache'); ?> </th> <td> <input type="hidden" name="cloudflare_sec_lvl_old" value="<?php echo $cloudflare_seclvl; ?> " /> <select name="cloudflare_sec_lvl_new"
?> </p> <p><strong><?php echo sprintf(__('Price: %.2f USD', 'w3-total-cache'), $this->_request_prices[$request_type]); ?> </strong></p> <p> <input type="hidden" name="cmd" value="_xclick" /> <input type="hidden" name="business" value="<?php echo W3TC_PAYPAL_BUSINESS; ?> " /> <input type="hidden" name="item_name" value="<?php echo esc_attr(sprintf('%s: %s (#%s)', ucfirst(w3_get_host()), $this->_request_types[$request_type], $request_id)); ?> " /> <input type="hidden" name="amount" value="<?php echo sprintf('%.2f', $this->_request_prices[$request_type]); ?> " /> <input type="hidden" name="currency_code" value="USD" /> <input type="hidden" name="no_shipping" value="1" /> <input type="hidden" name="rm" value="2" /> <input type="hidden" name="return" value="<?php echo esc_attr($return_url); ?> " /> <input type="hidden" name="cancel_return" value="<?php echo esc_attr($cancel_url);
/** * @param $extensions * @param W3_Config $config * @return mixed */ function extension($extensions, $config) { global $current_user; $message = array(); $message[] = 'CloudFlare'; $cloudflare_signup_email = ''; $cloudflare_signup_user = ''; if (is_a($current_user, 'WP_User')) { if ($current_user->user_email) { $cloudflare_signup_email = $current_user->user_email; } if ($current_user->user_login && $current_user->user_login != 'admin') { $cloudflare_signup_user = $current_user->user_login; } } $extensions['cloudflare'] = array('name' => 'CloudFlare', 'author' => 'W3 EDGE', 'description' => sprintf(__('CloudFlare protects and accelerates websites. <a href="%s" target="_blank">Sign up now for free</a> to get started, or if you have an account simply log in to obtain your <abbr title="Application Programming Interface">API</abbr> key from the <a target="_blank" href="https://www.cloudflare.com/my-account">account page</a> to enter it on the General Settings box that appears after plugin activation. Contact the CloudFlare <a href="http://www.cloudflare.com/help.html" target="_blank">support team</a> with any questions.', 'w3-total-cache'), 'https://www.cloudflare.com/sign-up.html?affiliate=w3edge&seed_domain=' . w3_get_host() . '&email=' . htmlspecialchars($cloudflare_signup_email) . '&username='******'author uri' => 'http://www.w3-edge.com/', 'extension uri' => 'http://www.w3-edge.com/', 'extension id' => 'cloudflare', 'version' => '1.0', 'enabled' => true, 'requirements' => implode(', ', $message), 'path' => 'w3-total-cache/extensions/CloudFlare.php'); return $extensions; }
/** * Init action * * @return void */ function init() { // Load plugin text domain load_plugin_textdomain(W3TC_TEXT_DOMAIN, null, plugin_basename(W3TC_DIR) . '/languages/'); if (is_multisite()) { global $w3_current_blog_id, $current_blog; if ($w3_current_blog_id != $current_blog->blog_id && !isset($GLOBALS['w3tc_blogmap_register_new_item'])) { $url = w3_get_host() . $_SERVER['REQUEST_URI']; $pos = strpos($url, '?'); if ($pos !== false) { $url = substr($url, 0, $pos); } $GLOBALS['w3tc_blogmap_register_new_item'] = $url; } } if (isset($GLOBALS['w3tc_blogmap_register_new_item'])) { $do_redirect = false; // true value is a sign to just generate config cache if ($GLOBALS['w3tc_blogmap_register_new_item'] != 'cache_options') { if (w3_is_subdomain_install()) { $blog_home_url = $GLOBALS['w3tc_blogmap_register_new_item']; } else { $home_url = rtrim(get_home_url(), '/'); if (substr($home_url, 0, 7) == 'http://') { $home_url = substr($home_url, 7); } else { if (substr($home_url, 0, 8) == 'https://') { $home_url = substr($home_url, 8); } } if (substr($GLOBALS['w3tc_blogmap_register_new_item'], 0, strlen($home_url)) == $home_url) { $blog_home_url = $home_url; } else { $blog_home_url = $GLOBALS['w3tc_blogmap_register_new_item']; } } w3_require_once(W3TC_INC_DIR . '/functions/multisite.php'); $do_redirect = w3_blogmap_register_new_item($blog_home_url, $this->_config); // reset cache of blog_id global $w3_current_blog_id; $w3_current_blog_id = null; // change config to actual blog, it was master before $this->_config = new W3_Config(); } $do_redirect |= $this->_config->fill_missing_cache_options_and_save(); // need to repeat request processing, since we was not able to realize // blog_id before so we are running with master config now. // redirect to the same url causes "redirect loop" error in browser, // so need to redirect to something a bit different if ($do_redirect) { if (strpos($_SERVER['REQUEST_URI'], '?') === false) { w3_redirect_temp($_SERVER['REQUEST_URI'] . '?repeat=w3tc'); } else { if (strpos($_SERVER['REQUEST_URI'], 'repeat=w3tc') === false) { w3_redirect_temp($_SERVER['REQUEST_URI'] . '&repeat=w3tc'); } } } } /** * Check request and handle w3tc_request_data requests */ $pos = strpos($_SERVER['REQUEST_URI'], '/w3tc_request_data/'); if ($pos !== false) { $hash = substr($_SERVER['REQUEST_URI'], $pos + 19, 32); if (strlen($hash) == 32) { $request_data = (array) get_option('w3tc_request_data'); if (isset($request_data[$hash])) { echo '<pre>'; foreach ($request_data[$hash] as $key => $value) { printf("%s: %s\n", $key, $value); } echo '</pre>'; unset($request_data[$hash]); update_option('w3tc_request_data', $request_data); } else { echo 'Requested hash expired or invalid'; } exit; } } /** * Check for rewrite test request */ w3_require_once(W3TC_LIB_W3_DIR . '/Request.php'); $rewrite_test = W3_Request::get_boolean('w3tc_rewrite_test'); if ($rewrite_test) { echo 'OK'; exit; } $admin_bar = false; if (function_exists('is_admin_bar_showing')) { $admin_bar = is_admin_bar_showing(); } if (current_user_can('manage_options') && $admin_bar) { add_action('wp_print_scripts', array($this, 'popup_script')); } }
/** * 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; }
/** * Returns cache key * * @param string $id * @param string $group * @return string */ function _get_cache_key($id, $group = 'default') { if (!$group) { $group = 'default'; } $blog_id = w3_get_blog_id(); $key_cache_id = $blog_id . $group . $id; if (isset($this->_key_cache[$key_cache_id])) { $key = $this->_key_cache[$key_cache_id]; } else { $host = w3_get_host(); if (in_array($group, $this->global_groups)) { $host_id = $host; } else { $host_id = sprintf('%s_%d', $host, $blog_id); } $key = sprintf('w3tc_%s_object_%s', $host_id, md5($group . $id)); $this->_key_cache[$key_cache_id] = $key; } /** * Allow to modify cache key by W3TC plugins */ $key = w3tc_do_action('w3tc_objectcache_cache_key', $key); return $key; }
/** * 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); } }
/** * Checks if can we do cache logic * * @param string $buffer * @return boolean */ function _can_cache2(&$buffer) { /** * Skip if caching is disabled */ if (!$this->_caching) { return false; } /** * Check for database error */ if (w3_is_database_error($buffer)) { $this->cache_reject_reason = 'Database error occurred'; return false; } /** * Check for DONOTCACHEPAGE constant */ if (defined('DONOTCACHEPAGE') && DONOTCACHEPAGE) { $this->cache_reject_reason = 'DONOTCACHEPAGE constant is defined'; return false; } /** * Check hostname */ if ($this->_config->get_boolean('pgcache.check.domain') && w3_get_host() != w3_get_home_domain()) { $this->cache_reject_reason = 'Hostname mismatch'; return false; } /** * Don't cache 404 pages */ if (!$this->_config->get_boolean('pgcache.cache.404') && function_exists('is_404') && is_404()) { $this->cache_reject_reason = 'Page is 404'; return false; } /** * Don't cache homepage */ if (!$this->_config->get_boolean('pgcache.cache.home') && function_exists('is_home') && is_home()) { $this->cache_reject_reason = 'Page is home'; return false; } /** * Don't cache feed */ if (!$this->_config->get_boolean('pgcache.cache.feed') && function_exists('is_feed') && is_feed()) { $this->cache_reject_reason = 'Page is feed'; return false; } /** * Check if page contains dynamic tags */ if ($this->_enhanced_mode && $this->_has_dynamic($buffer)) { $this->cache_reject_reason = 'Page contains dynamic tags (mfunc or mclude) can not be cached in enhanced mode'; return false; } return true; }