public function run() { $this->_config = w3_instance('W3_Config'); if ($this->_config->get_boolean('cdn.enabled')) { add_filter('wpseo_xml_sitemap_img_src', array($this, 'wpseo_cdn_filter')); } }
/** * @param W3_Config $config * @param W3_ConfigAdmin $config_admin * @return string */ function notifications($config) { /** * @var $nerser W3_NewRelicService */ $nerser = w3_instance('W3_NewRelicService'); try { $pl = $nerser->get_frontend_response_time(); if ($pl > 0.3) { $nr_recommends = array(); if (!$config->get_boolean('pgcache.enabled')) { $nr_recommends[] = __('Page Cache', 'w3-total-cache'); } if (!$config->get_boolean('minify.enabled')) { $nr_recommends[] = __('Minify', 'w3-total-cache'); } if (!$config->get_boolean('cdn.enabled')) { $nr_recommends[] = __('CDN', 'w3-total-cache'); } if (!$config->get_boolean('browsercache.enabled')) { $nr_recommends[] = __('Browser Cache and use compression', 'w3-total-cache'); } if ($nr_recommends) { $message = sprintf(__('Application monitoring has detected that your page load time is higher than 300ms. It is recommended that you enable the following features: %s %s', 'w3-total-cache'), implode(', ', $nr_recommends), w3_button_hide_note('Hide this message', 'new_relic_page_load_notification', '', true)); return $message; } } } catch (Exception $ex) { } return ''; }
/** * PHP5-style constructor */ function __construct() { $this->_config = w3_instance('W3_Config'); $this->_debug = $this->_config->get_boolean('varnish.debug'); $this->_servers = $this->_config->get_array('varnish.servers'); $this->_timeout = $this->_config->get_integer('timelimit.varnish_purge'); }
function __construct() { $this->_config = w3_instance('W3_Config'); $this->_caches['objectcache'] = w3_instance('W3_ObjectCache'); if ($this->_config->get_boolean('fragmentcache.enabled')) { $this->_caches['fragmentcache'] = w3_instance('W3_Pro_FragmentCache'); } }
function run() { $this->_config = w3_instance('W3_Config'); if ($this->_config->get_boolean('cdn.enabled')) { add_action('includes_url', array(&$this, 'filter_includes_url'), 10, 2); add_action('ngg_get_image_url', array(&$this, 'action_ngg_get_image_url'), 10, 3); } }
/** * Store the output buffer per page/post hook basis. */ function cache_genesis_end() { $keys = $this->_get_id_group(current_filter()); if (is_null($keys)) { return; } list($id, $group) = $keys; w3tc_fragmentcache_end($id, $group, $this->_config->get_boolean('fragmentcache.debug')); }
function generate() { $pages = $this->generate_menu_array(); add_menu_page(__('Performance', 'w3-total-cache'), __('Performance', 'w3-total-cache'), 'manage_options', 'w3tc_dashboard', '', 'div'); $submenu_pages = array(); foreach ($pages as $slug => $titles) { if ($this->_config_admin->get_boolean('common.visible_by_master_only') && $titles['network_show'] || (!$this->_config_admin->get_boolean('common.visible_by_master_only') || is_super_admin() && (!w3_force_master() || is_network_admin()))) { $submenu_pages[] = add_submenu_page('w3tc_dashboard', $titles[0] . ' | W3 Total Cache', $titles[1], 'manage_options', $slug, array(&$this, 'options')); } } return $submenu_pages; }
/** * Fixes environment in each wp-admin request * * @param W3_Config $config * @param bool $force_all_checks * @throws SelfTestExceptions **/ public function fix_on_wpadmin_request($config, $force_all_checks) { $exs = new SelfTestExceptions(); if ($config->get_boolean('config.check') || $force_all_checks) { if (!$config->get_boolean('newrelic.enabled') || $config->get_boolean('newrelic.enabled') && $config->get_boolean('newrelic.use_php_function')) { $this->rules_remove($exs); } } if (count($exs->exceptions()) > 0) { throw $exs; } }
function action_save_new_relic() { if ($this->_config->get_boolean('newrelic.enabled')) { /** * @var $nerser W3_NewRelicService */ $nerser = w3_instance('W3_NewRelicService'); $application = W3_Request::get_array('application'); $application['alerts_enabled'] = $application['alerts_enabled'] == 1 ? 'true' : 'false'; $application['rum_enabled'] = $application['rum_enabled'] == 1 ? 'true' : 'false'; $result = $nerser->update_application_settings($application); w3_admin_redirect(array('w3tc_note' => 'new_relic_save'), true); } }
/** * @param W3_Config $config * @param W3_Config $config_master * @param bool $do_merge if to merge with network main site * @return string */ public static function get_wordpress_appname($config, $config_master, $do_merge = true) { if (w3_is_network()) { if ($config_master->get_boolean('newrelic.use_network_wide_id')) { $appname = $config_master->get_string('newrelic.appname'); } else { $merge = $config->get_boolean('newrelic.merge_with_network'); $merge_name = ''; if ($do_merge && $merge && w3_get_blog_id() != 0) { $merge_name = ';' . $config_master->get_string('newrelic.appname'); } if (w3_get_blog_id() != 0 && !$config->get_boolean('common.force_master')) { $appname = $config->get_string('newrelic.appname', ''); if (empty($appname)) { $prefix = $config->get_string('newrelic.appname_prefix'); $appname = $prefix . trim(w3_get_home_domain() . w3_get_site_path(), '/'); } } else { if (w3_get_blog_id() != 0) { $prefix = $config->get_string('newrelic.appname_prefix'); $appname = $prefix . trim(w3_get_home_domain() . w3_get_site_path(), '/'); } else { $appname = $config->get_string('newrelic.appname'); } } $appname = $appname . $merge_name; } } else { $appname = $config->get_string('newrelic.appname'); } return $appname; }
/** * Flush browsers cache */ function flush_browser_cache() { if ($this->_config->get_boolean('browsercache.enabled')) { $this->_config->set('browsercache.timestamp', time()); $this->_config->save(); } }
/** * Check if caching allowed on init * * @return boolean */ function _can_cache() { /** * Skip if disabled */ if (!$this->_config->get_boolean('objectcache.enabled')) { if (function_exists('__')) { $this->cache_reject_reason = __('Object caching is disabled', 'w3-total-cache'); } else { $this->cache_reject_reason = 'Object caching is disabled'; } return false; } /** * Check for DONOTCACHEOBJECT constant */ if (defined('DONOTCACHEOBJECT') && DONOTCACHEOBJECT) { if (function_exists('__')) { $this->cache_reject_reason = __('DONOTCACHEOBJECT constant is defined', 'w3-total-cache'); } else { $this->cache_reject_reason = 'DONOTCACHEOBJECT constant is defined'; } return false; } return true; }
/** * 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': require_once W3TC_LIB_W3_DIR . '/Cache/Memcached.php'; require_once W3TC_LIB_MINIFY_DIR . '/Minify/Cache/Memcache.php'; $this->_memcached =& new W3_Cache_Memcached(array('servers' => $this->_config->get_array('minify.memcached.servers'), 'persistant' => $this->_config->get_boolean('minify.memcached.persistant'))); $cache[0] =& new Minify_Cache_Memcache($this->_memcached); break; case 'apc': require_once W3TC_LIB_MINIFY_DIR . '/Minify/Cache/APC.php'; $cache[0] =& new Minify_Cache_APC(); break; case 'eaccelerator': require_once W3TC_LIB_MINIFY_DIR . '/Minify/Cache/Eaccelerator.php'; $cache[0] =& new Minify_Cache_Eaccelerator(); break; case 'xcache': require_once W3TC_LIB_MINIFY_DIR . '/Minify/Cache/XCache.php'; $cache[0] =& new Minify_Cache_XCache(); break; case 'file': default: require_once W3TC_LIB_MINIFY_DIR . '/Minify/Cache/File.php'; if (!is_dir(W3TC_CACHE_FILE_MINIFY_DIR)) { $this->log(sprintf('Cache directory %s does not exist', W3TC_CACHE_FILE_MINIFY_DIR)); } $cache[0] =& new Minify_Cache_File(W3TC_CACHE_FILE_MINIFY_DIR, $this->_config->get_boolean('minify.file.locking')); break; } } return $cache[0]; }
private function _criteria_matched($criteria) { if (is_array($criteria)) { $enabled = true; $compare = '&&'; foreach ($criteria as $val) { if (is_array($val)) { if ($val[1] == '!=') { $enabled = $this->_compare_criteria_values($enabled, $this->_config->get_string($val[0]) != $val[2], $compare); } elseif ($val[1] == '==') { $enabled = $this->_compare_criteria_values($enabled, $this->_config->get_string($val[0]) == $val[2], $compare); } else { $enabled = $enabled || $this->_criteria_matched($val); } } elseif ($val != '||' && $val != '&&') { $enabled = $this->_compare_criteria_values($enabled, $this->_config->get_boolean($val), $compare); } else { $compare = $val; } } } else { $enabled = is_null($criteria) || $this->_config->get_boolean($criteria); } return $enabled; }
/** * Check if can cache sql, checks which have constant results during whole request * * @return boolean */ function _can_cache_once_per_request() { /** * Skip if disabled */ if (!$this->_config->get_boolean('dbcache.enabled')) { $this->cache_reject_reason = 'dbcache.disabled'; return false; } /** * Skip if request URI is rejected */ if (!$this->_check_request_uri()) { $this->cache_reject_reason = 'request'; return false; } /** * Skip if cookie is rejected */ if (!$this->_check_cookies()) { $this->cache_reject_reason = 'cookie'; return false; } return true; }
/** * Checks if can we do cache logic * * @param string $buffer * @return boolean */ function _can_cache2() { /** * Skip if caching is disabled */ if (!$this->_caching) { 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; } return true; }
/** * Check if we can start OB * * @return boolean */ function _can_ob() { /** * Database cache should be enabled */ if (!$this->_config->get_boolean('dbcache.enabled')) { return false; } /** * Debug should be enabled */ if (!$this->_config->get_boolean('dbcache.debug')) { return false; } /** * Skip if admin */ if (defined('WP_ADMIN')) { return false; } /** * Skip if doint AJAX */ if (defined('DOING_AJAX')) { return false; } /** * Skip if doing cron */ if (defined('DOING_CRON')) { return false; } /** * Skip if APP request */ if (defined('APP_REQUEST')) { return false; } /** * Skip if XMLRPC request */ if (defined('XMLRPC_REQUEST')) { return false; } /** * Check for WPMU's and WP's 3.0 short init */ if (defined('SHORTINIT') && SHORTINIT) { return false; } /** * Check User Agent */ if (isset($_SERVER['HTTP_USER_AGENT']) && stristr($_SERVER['HTTP_USER_AGENT'], W3TC_POWERED_BY) !== false) { return false; } return true; }
function generate() { $pages = array('w3tc_dashboard' => array(__('Dashboard', 'w3-total-cache'), __('Dashboard', 'w3-total-cache'), 'network_show' => true), 'w3tc_general' => array(__('General Settings', 'w3-total-cache'), __('General Settings', 'w3-total-cache'), 'network_show' => false), 'w3tc_pgcache' => array(__('Page Cache', 'w3-total-cache'), __('Page Cache', 'w3-total-cache'), 'network_show' => false), 'w3tc_minify' => array(__('Minify', 'w3-total-cache'), __('Minify', 'w3-total-cache'), 'network_show' => false), 'w3tc_dbcache' => array(__('Database Cache', 'w3-total-cache'), __('Database Cache', 'w3-total-cache'), 'network_show' => false), 'w3tc_objectcache' => array(__('Object Cache', 'w3-total-cache'), __('Object Cache', 'w3-total-cache'), 'network_show' => false)); if (w3_is_pro($this->_config) || w3_is_enterprise($this->_config)) { $pages['w3tc_fragmentcache'] = array(__('Fragment Cache', 'w3-total-cache'), __('Fragment Cache', 'w3-total-cache'), 'network_show' => false); } $pages = array_merge($pages, array('w3tc_browsercache' => array(__('Browser Cache', 'w3-total-cache'), __('Browser Cache', 'w3-total-cache'), 'network_show' => false), 'w3tc_mobile' => array(__('User Agent Groups', 'w3-total-cache'), __('User Agent Groups', 'w3-total-cache'), 'network_show' => false), 'w3tc_referrer' => array(__('Referrer Groups', 'w3-total-cache'), __('Referrer Groups', 'w3-total-cache'), 'network_show' => false), 'w3tc_cdn' => array(__('Content Delivery Network', 'w3-total-cache'), __('<acronym title="Content Delivery Network">CDN</acronym>', 'w3-total-cache'), 'network_show' => $this->_config->get_boolean('cdn.enabled')), 'w3tc_monitoring' => array(__('Monitoring', 'w3-total-cache'), __('Monitoring', 'w3-total-cache'), 'network_show' => false))); $pages_tail = array('w3tc_faq' => array(__('FAQ', 'w3-total-cache'), __('FAQ', 'w3-total-cache'), 'network_show' => true), 'w3tc_support' => array(__('Support', 'w3-total-cache'), __('<span style="color: red;">Support</span>', 'w3-total-cache'), 'network_show' => true), 'w3tc_install' => array(__('Install', 'w3-total-cache'), __('Install', 'w3-total-cache'), 'network_show' => false), 'w3tc_about' => array(__('About', 'w3-total-cache'), __('About', 'w3-total-cache'), 'network_show' => true)); $pages = apply_filters('w3tc_menu', $pages, $this->_config, $this->_config_admin); $pages = array_merge($pages, $pages_tail); add_menu_page(__('Performance', 'w3-total-cache'), __('Performance', 'w3-total-cache'), 'manage_options', 'w3tc_dashboard', '', 'div'); $submenu_pages = array(); foreach ($pages as $slug => $titles) { if ($this->_config_admin->get_boolean('common.visible_by_master_only') && $titles['network_show'] || (!$this->_config_admin->get_boolean('common.visible_by_master_only') || is_super_admin() && (!w3_force_master() || is_network_admin()))) { $submenu_pages[] = add_submenu_page('w3tc_dashboard', $titles[0] . ' | W3 Total Cache', $titles[1], 'manage_options', $slug, array(&$this, 'options')); } } return $submenu_pages; }
function check_lasterror() { if ($this->_config->get_boolean('cloudflare.enabled') && self::get_last_error()) { if (!$this->_fault_signaled) { $this->_fault_signaled = true; return sprintf('Unable to communicate with CloudFlare API: %s.', self::get_last_error()); } } return false; }
public function run() { $this->_config = w3_instance('W3_Config'); $this->_config_admin = w3_instance('W3_ConfigAdmin'); w3_require_once(W3TC_INC_FUNCTIONS_DIR . '/admin.php'); w3_require_once(W3TC_INC_FUNCTIONS_DIR . '/admin_ui.php'); $this->_page = w3tc_get_current_page(); if (is_network_admin() || !w3_is_multisite()) { $this->edge_notification(); } if (is_w3tc_admin_page()) { add_action('admin_head', array($this, 'admin_head')); add_action('w3tc_hide_button_custom-edge_mode', array($this, 'hide_edge_mode_notification')); $support_reminder = $this->_config->get_boolean('notes.support_us') && $this->_config_admin->get_integer('common.install') < time() - W3TC_SUPPORT_US_TIMEOUT && $this->_config->get_string('common.support') == '' && !$this->_config->get_boolean('common.tweeted'); if ($support_reminder || w3tc_show_notification('support_us_popup')) { add_action('w3tc-dashboard-head', array($this, 'support_us_nag')); } add_action('w3tc-dashboard-head', array($this, 'edge_nag')); } }
/** * Check if caching allowed on init * * @return boolean */ function _can_cache() { /** * Skip if disabled */ if (!$this->_config->get_boolean('fragmentcache.enabled')) { $this->cache_reject_reason = __('Fragment caching is disabled', 'w3-total-cache'); return false; } return true; }
/** * Returns minifier options * * @param string $engine * @return array */ function get_options($engine) { $options = array(); switch ($engine) { case 'js': $options = array('preserveComments' => !$this->_config->get_boolean('minify.js.strip.comments'), 'stripCrlf' => $this->_config->get_boolean('minify.js.strip.crlf')); break; case 'css': $options = array('preserveComments' => !$this->_config->get_boolean('minify.css.strip.comments'), 'stripCrlf' => $this->_config->get_boolean('minify.css.strip.crlf')); $symlinks = $this->_config->get_array('minify.symlinks'); foreach ($symlinks as $link => $target) { $link = str_replace('//', realpath($_SERVER['DOCUMENT_ROOT']), $link); $link = strtr($link, '/', DIRECTORY_SEPARATOR); $options['symlinks'][$link] = realpath($target); } break; case 'yuijs': $options = array('line-break' => $this->_config->get_integer('minify.yuijs.options.line-break'), 'nomunge' => $this->_config->get_boolean('minify.yuijs.options.nomunge'), 'preserve-semi' => $this->_config->get_boolean('minify.yuijs.options.preserve-semi'), 'disable-optimizations' => $this->_config->get_boolean('minify.yuijs.options.disable-optimizations')); break; case 'yuicss': $options = array('line-break' => $this->_config->get_integer('minify.yuicss.options.line-break')); break; case 'ccjs': $options = array('compilation_level' => $this->_config->get_string('minify.ccjs.options.compilation_level'), 'formatting' => $this->_config->get_string('minify.ccjs.options.formatting')); break; case 'csstidy': $options = array('remove_bslash' => $this->_config->get_boolean('minify.csstidy.options.remove_bslash'), 'compress_colors' => $this->_config->get_boolean('minify.csstidy.options.compress_colors'), 'compress_font-weight' => $this->_config->get_boolean('minify.csstidy.options.compress_font-weight'), 'lowercase_s' => $this->_config->get_boolean('minify.csstidy.options.lowercase_s'), 'optimise_shorthands' => $this->_config->get_integer('minify.csstidy.options.optimise_shorthands'), 'remove_last_;' => $this->_config->get_boolean('minify.csstidy.options.remove_last_;'), 'case_properties' => $this->_config->get_integer('minify.csstidy.options.case_properties'), 'sort_properties' => $this->_config->get_boolean('minify.csstidy.options.sort_properties'), 'sort_selectors' => $this->_config->get_boolean('minify.csstidy.options.sort_selectors'), 'merge_selectors' => $this->_config->get_integer('minify.csstidy.options.merge_selectors'), 'discard_invalid_properties' => $this->_config->get_boolean('minify.csstidy.options.discard_invalid_properties'), 'css_level' => $this->_config->get_string('minify.csstidy.options.css_level'), 'preserve_css' => $this->_config->get_boolean('minify.csstidy.options.preserve_css'), 'timestamp' => $this->_config->get_boolean('minify.csstidy.options.timestamp'), 'template' => $this->_config->get_string('minify.csstidy.options.template')); break; case 'html': case 'htmlxml': $options = array('xhtml' => true, 'stripCrlf' => $this->_config->get_boolean('minify.html.strip.crlf'), 'ignoredComments' => $this->_config->get_array('minify.html.comments.ignore')); break; case 'htmltidy': case 'htmltidyxml': $options = array('clean' => $this->_config->get_boolean('minify.htmltidy.options.clean'), 'hide-comments' => $this->_config->get_boolean('minify.htmltidy.options.hide-comments'), 'wrap' => $this->_config->get_integer('minify.htmltidy.options.wrap')); break; } if ($this->_config->get_boolean('browsercache.enabled') && ($this->_config->get_boolean('browsercache.cssjs.replace') || $this->_config->get_boolean('browsercache.html.replace') || $this->_config->get_boolean('browsercache.other.replace'))) { $w3_plugin_browsercache = w3_instance('W3_Plugin_BrowserCache'); $options = array_merge($options, array('browserCacheId' => $w3_plugin_browsercache->get_replace_id(), 'browserCacheExtensions' => $w3_plugin_browsercache->get_replace_extensions())); } if ($this->_config->get_boolean('cdn.enabled') && $this->_config->get_boolean('cdn.minify.enable')) { $w3_plugin_cdn = w3_instance('W3_Plugin_CdnCommon'); $cdn = $w3_plugin_cdn->get_cdn(); $options = array_merge($options, array('prependAbsolutePathCallback' => array(&$cdn, 'get_prepend_path'))); } return $options; }
/** * Returns true if config section is sealed * @param string $section * @return boolean */ protected function is_sealed($section) { if ($this->_config->is_master()) { return false; } if (w3_is_network() && !$this->_config->is_master() && w3_force_master()) { return true; } // browsercache settings change rules, so not available in child settings if ($section == 'browsercache') { return true; } if ($section == 'minify' && !$this->_config_master->get_boolean('minify.enabled')) { return true; } return $this->_config_admin->get_boolean($section . '.configuration_sealed'); }
/** * Check if caching allowed on init * * @return boolean */ function _can_cache() { /** * Skip if disabled */ if (!$this->_config->get_boolean('objectcache.enabled')) { $this->cache_reject_reason = 'objectcache.disabled'; return false; } /** * Check for DONOTCACHEOBJECT constant */ if (defined('DONOTCACHEOBJECT') && DONOTCACHEOBJECT) { $this->cache_reject_reason = 'DONOTCACHEOBJECT'; return false; } return true; }
/** * Prints checkbox with admin config option value * * @param string $option_id * @param boolean $disabled */ protected function checkbox_admin($option_id, $disabled = false) { if (!$disabled) { $disabled = $this->_config->get_boolean('common.force_master'); } $checked = $this->_config_admin->get_boolean($option_id) || $disabled; if (!$disabled) { echo '<input type="hidden" name="' . $option_id . '" value="0" />'; } echo '<label>'; $id = str_replace('.', '_', $option_id); $class = $disabled ? 'disabled' : 'enabled'; echo '<input id="' . $id . '" class="' . $class . '" type="checkbox" name="' . $option_id . '" value="1"'; checked($checked, true); if ($disabled) { echo ' disabled="disabled"'; } echo ' />'; }
/** * 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('cache_dir' => W3TC_CACHE_FILE_DBCACHE_DIR); break; default: $engineConfig = array(); } require_once W3TC_LIB_W3_DIR . '/Cache.php'; $cache[0] =& W3_Cache::instance($engine, $engineConfig); } return $cache[0]; }
/** * Run deactivate on loaded plugins */ public function deactivate() { w3_require_once(W3TC_INC_DIR . '/functions/activation.php'); $ftp_form = null; try { w3_enable_maintenance_mode(); } catch (Exception $ex) { } $errors = array('errors' => array()); try { if (!$this->_config->get_boolean('pgcache.enabled')) { $plugin = w3_instance('W3_Plugin_PgCache'); $this->_loaded_plugins[] = $plugin; } foreach ($this->_loaded_plugins as $plugin) { $result = $plugin->deactivate(); if ($result) { $plugin_errors = isset($result['errors_short_form']) ? $result['errors_short_form'] : $result['errors']; $errors['errors'] = array_merge($errors['errors'], $plugin_errors); if (isset($result['ftp_form'])) { $errors['ftp_form'] = $result['ftp_form']; } } } } catch (Exception $ex) { $errors['errors'][] = $ex->getMessage(); } $result = $this->delete_files_and_folders(); try { w3_disable_maintenance_mode(); } catch (Exception $ex) { } if ($result['errors']) { $errors['errors'] = array_merge($errors['errors'], $result['errors']); if (isset($result['ftp_form'])) { $errors['ftp_form'] = $result['ftp_form']; } } return $errors; }
/** * Create a NetDNA or MaxCDN pull zone automatically */ function action_cdn_auto_create_netdna_maxcdn_pull_zone() { w3_require_once(W3TC_LIB_NETDNA_DIR . '/NetDNA.php'); w3_require_once(W3TC_INC_FUNCTIONS_DIR . '/admin.php'); $cdn_engine = W3_Request::get_string('type'); $this->validate_cdnengine_is_netdna_maxcdn($cdn_engine); $authorization_key = W3_Request::get_string('authorization_key'); $this->validate_authorization_key($authorization_key); $keys = explode('+', $authorization_key); list($alias, $consumerkey, $consumersecret) = $keys; $url = w3_get_home_url(); try { $api = new NetDNA($alias, $consumerkey, $consumersecret); $disable_cooker_header = $this->_config->get_boolean('browsercache.other.nocookies') || $this->_config->get_boolean('browsercache.cssjs.nocookies'); $zone = $api->create_default_pull_zone($url, null, null, array('ignore_setcookie_header' => $disable_cooker_header)); $name = $zone['name']; $temporary_url = "{$name}.{$alias}.netdna-cdn.com"; $test_result = -1; if (!$this->_config->get_array("cdn.{$cdn_engine}.domain")) { $test_result = $this->test_cdn_url($temporary_url) ? 1 : 0; $this->_config->set("cdn.{$cdn_engine}.zone_id", $zone['id']); if ($test_result) { $this->_config->set("cdn.enabled", true); } $this->_config->set("cdn.{$cdn_engine}.domain", array($temporary_url)); } $this->_config->save(); $config_admin = w3_instance('W3_ConfigAdmin'); $zones = $api->get_pull_zones(); $zone_count = sizeof($zones); w3tc_make_track_call(array('type' => 'cdn', 'data' => array('cdn' => $cdn_engine, 'action' => 'zonecreation', 'creation' => 'manual', 'creationtime' => time(), 'signupclick' => $config_admin->get_integer('track.maxcdn_signup'), 'authorizeclick' => $config_admin->get_integer('track.maxcdn_authorize'), 'validationclick' => $config_admin->get_integer('track.maxcdn_validation'), 'total_zones' => $zone_count, 'test' => $test_result))); $result = array('result' => 'single', 'cnames' => array($temporary_url)); } catch (Exception $ex) { $result = array('result' => 'error', 'message' => sprintf(__('Could not create default zone.' . $ex->getMessage(), 'w3-total-cache'))); } echo json_encode($result); exit; }
/** * Check if can cache sql, checks which have constant results during whole request * * @return boolean */ function _can_cache_once_per_request() { /** * Skip if disabled */ if (!$this->_config->get_boolean('dbcache.enabled')) { if (function_exists('__')) { $this->cache_reject_reason = __('Database caching is disabled', 'w3-total-cache'); } else { $this->cache_reject_reason = 'Database caching is disabled'; } return false; } /** * Skip if request URI is rejected */ if (!$this->_check_request_uri()) { if (function_exists('__')) { $this->cache_reject_reason = __('Request URI is rejected', 'w3-total-cache'); } else { $this->cache_reject_reason = 'Request URI is rejected'; } return false; } /** * Skip if cookie is rejected */ if (!$this->_check_cookies()) { if (function_exists('__')) { $this->cache_reject_reason = __('Cookie is rejected', 'w3-total-cache'); } else { $this->cache_reject_reason = 'Cookie is rejected'; } return false; } return true; }
/** * 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]; }