function run() { add_action('w3tc_dashboard_setup', array(&$this, 'wp_dashboard_setup')); add_action('w3tc_network_dashboard_setup', array(&$this, 'wp_dashboard_setup')); // Configure authorize and have_zone $this->_setup($this->_config); /** * Retry setup with main blog */ if (w3_is_network() && is_network_admin() && !$this->authorized) { $this->_config = new W3_Config(false, 1); $this->_setup($this->_config); } if (w3_is_network()) { $conig_admin = w3_instance('W3_ConfigAdmin'); $this->_sealed = $conig_admin->get_boolean('cdn.configuration_sealed'); } if ($this->have_zone && $this->authorized && isset($_GET['page']) && strpos($_GET['page'], 'w3tc_dashboard') !== false) { w3_require_once(W3TC_LIB_NETDNA_DIR . '/NetDNA.php'); w3_require_once(W3TC_LIB_NETDNA_DIR . '/NetDNAPresentation.php'); $authorization_key = $this->_config->get_string('cdn.maxcdn.authorization_key'); $alias = $consumerkey = $consumersecret = ''; $keys = explode('+', $authorization_key); if (sizeof($keys) == 3) { list($alias, $consumerkey, $consumersecret) = $keys; } $this->api = new NetDNA($alias, $consumerkey, $consumersecret); add_action('admin_head', array(&$this, 'admin_head')); } }
/** * Referrer tab * * @return void */ function view() { $groups = $this->_config->get_array('referrer.rgroups'); $w3_referrer = w3_instance('W3_Referrer'); $themes = $w3_referrer->get_themes(); include W3TC_INC_DIR . '/options/referrer.php'; }
/** * Activate plugin action * * @return void */ function activate($network_wide) { w3_require_once(W3TC_INC_DIR . '/functions/activation.php'); if (w3_is_network()) { if ($network_wide) { // we are in network activation } else { if ($_GET['action'] == 'error_scrape' && strpos($_SERVER['REQUEST_URI'], '/network/') !== false) { // workaround for error_scrape page called after error // really we are in network activation and going to throw some error } else { echo 'Please <a href="' . network_admin_url('plugins.php') . '">network activate</a> W3 Total Cache when using WordPress Multisite.'; die; } } } /** * Create cache folder and extension files */ try { w3_activation_create_required_files(); if (!$this->_config->own_config_exists()) { $this->_config->save(); } // save admin config $admin_config = w3_instance('W3_ConfigAdmin'); if (!$admin_config->own_config_exists()) { $admin_config->save(); } } catch (Exception $e) { w3_activation_error_on_exception($e); } delete_option('w3tc_request_data'); add_option('w3tc_request_data', '', null, 'no'); }
/** * Display if caching or not. */ function extension_header() { $config = w3_instance('W3_Config'); echo '<p>'; printf(__('The NextGENGallery extension is currently %s ', 'w3-total-cache'), '<span class="w3tc-enabled">' . __('enabled', 'w3-total-cache') . '</span>'); echo '.</p>'; }
/** * Init of class * * @since 1.0.0 */ public function init() { // get setting from theme options //$this->is_onfly_active = yit_get_option( 'onfly_resize_active' ); // deactive if w3tc if (function_exists('w3_instance')) { $config = w3_instance('W3_Config'); if ($config->get_boolean('cdn.enabled')) { $this->is_onfly_active = false; return; } } $this->is_retina_active = apply_filters('yit_is_retina_active', $this->is_retina_active); $this->use_fast_image = apply_filters('yit_use_fast_image', $this->use_fast_image); // retrocompatibility global $wp_version; if (version_compare($wp_version, YIT_MINIMUM_WP_VERSION, '<')) { $this->is_onfly_active = false; } if (is_admin() && isset($_GET['page']) && $_GET['page'] == 'w3tc_cdn') { return; } // add image size, if above option is true add_action('after_setup_theme', array($this, 'add_image_sizes')); // convert other add_image_sizes from other plugin, to the attribute of the class add_action('init', array($this, 'add_other_image_sizes')); // use yit_image() inside the function get_the_post_thumbnail() //add_filter( 'post_thumbnail_html', array( $this, 'convert_get_the_post_thumbnail' ), 10, 5 ); // use yit_image() inside the function get_the_post_thumbnail() add_filter('image_downsize', array($this, 'convert_image_downsize'), 10, 3); }
/** * @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'); }
/** * Checks W3_Config for the params if they are not provided in the constructor. * @param string $api_key * @param string $account_id * @param string $application_id */ function __construct($api_key = '', $account_id = '', $application_id = '') { /** * @var $config W3_Config */ $config = w3_instance('W3_Config'); if ($api_key) { $this->_api_key = $api_key; } else { $this->_api_key = $config->get_string('newrelic.api_key'); } if ($account_id) { $this->_account_id = $account_id; } else { $this->_account_id = $config->get_string('newrelic.account_id'); } if ($application_id) { $this->_application_id = $application_id; } else { $this->_application_id = $config->get_integer('newrelic.application_id'); } $this->_cache_time = $config->get_integer('newrelic.cache_time', 5); if ($this->_cache_time < 1) { $this->_cache_time = 5; } }
function checkW3TotalCache() { if (!function_exists('w3_instance')) { return; } $agentgroups = array('wp2android_html5' => array('(iPhone|iPod).*Mac\\ OS\\ X', 'Mac\\ OS\\ X.*(iPhone|iPod)', 'Android.*AppleWebKit', 'AppleWebKit.*Android', 'Windows.*IEMobile.*Phone', 'Windows.*Phone.*IEMobile', 'IEMobile.*Windows.*Phone', 'IEMobile.*Phone.*Windows', 'Phone.*Windows.*IEMobile', 'Phone.*IEMobile.*Windows'), 'wp2android_android' => array('wp2android_user_agent=android_app', '72dcc186a8d3d7b3d8554a14256389a4'), 'wp2android_ipad' => array('wp2android_user_agent=ipad_app')); $needed = false; $config = w3_instance('W3_Config'); $groups = $config->get_array('mobile.rgroups'); foreach ($agentgroups as $groupname => $agents) { if (isset($groups[$groupname])) { $group = $groups[$groupname]; if (count($group) === 4 && isset($group['theme']) && isset($group['enabled']) && isset($group['redirect']) && isset($group['agents']) && $group['theme'] === '' && $group['enabled'] === true && $group['redirect'] === '' && count($group['agents']) === count($agents)) { $found = false; foreach ($agents as $agent) { if (!in_array($agent, $group['agents'])) { $found = true; break; } } if (!$found) { /* This group is already present and enabled */ continue; } } } $needed = true; $groups[$groupname] = array('theme' => '', 'enabled' => true, 'redirect' => '', 'agents' => $agents); } if ($needed) { $config->set('mobile.rgroups', $groups); $config->save(false); } }
/** * Returns onject instance. Called by WP engine * * @return W3_Db */ static function instance() { static $instances = array(); if (!isset($instances[0])) { $processors = array(); $call_default_constructor = true; // no caching during activation $is_installing = defined('WP_INSTALLING') && WP_INSTALLING; $config = w3_instance('W3_Config'); if (!$is_installing && $config->get_boolean('dbcache.enabled')) { $processors[] = w3_instance('W3_DbCache'); } if (w3_is_dbcluster()) { $processors[] = w3_instance('W3_Enterprise_DbCluster'); } $processors[] = new W3_DbProcessor(); $class = __CLASS__; $o = new $class($processors); $underlying_manager = new W3_DbCallUnderlying($o); foreach ($processors as $processor) { $processor->manager = $o; $processor->underlying_manager = $underlying_manager; } // initialize after processors configured $o->initialize(); @($instances[0] = $o); } return $instances[0]; }
/** * Mobile tab * * @return void */ function view() { $groups = $this->_config->get_array('mobile.rgroups'); $w3_mobile = w3_instance('W3_Mobile'); $themes = $w3_mobile->get_themes(); include W3TC_INC_DIR . '/options/mobile.php'; }
function __construct() { $this->_config = w3_instance('W3_Config'); $this->_request_types = array('bug_report' => __('Submit a Bug Report', 'w3-total-cache'), 'new_feature' => __('Suggest a New Feature', 'w3-total-cache'), 'email_support' => __('Less than 15 Minute Email Support Response (M-F 9AM - 5PM EDT): $75 USD', 'w3-total-cache'), 'phone_support' => __('Less than 15 Minute Phone Support Response (M-F 9AM - 5PM EDT): $150 USD', 'w3-total-cache'), 'plugin_config' => __('Professional Plugin Configuration: Starting @ $100 USD', 'w3-total-cache'), 'theme_config' => __('Theme Performance Optimization & Plugin Configuration: Starting @ $150 USD', 'w3-total-cache'), 'linux_config' => __('Linux Server Optimization & Plugin Configuration: Starting @ $200 USD', 'w3-total-cache')); w3_require_once(W3TC_INC_FUNCTIONS_DIR . '/admin.php'); $this->_page = w3tc_get_current_page(); }
/** * New Relic tab */ function view() { $applications = array(); $dashboard = ''; /** * @var $nerser W3_NewRelicService */ $nerser = w3_instance('W3_NewRelicService'); $new_relic_configured = $this->_config->get_string('newrelic.account_id') && $this->_config->get_string('newrelic.api_key') && $this->_config->get_string('newrelic.application_id'); $view_application = $this->_config->get_string('newrelic.application_id'); $new_relic_enabled = $this->_config->get_boolean('newrelic.enabled'); $verify_running = $nerser->verify_running(); $application_settings = array(); if (!is_array($verify_running)) { try { $application_settings = $nerser->get_application_settings(); } catch (Exception $ex) { $application_settings = array(); } } if ($view_metric = W3_Request::get_boolean('view_metric', false)) { $metric_names = $nerser->get_metric_names(W3_Request::get_string('regex', '')); } include W3TC_INC_DIR . '/options/new_relic.php'; }
/** * Dashboard tab */ function view() { w3_require_once(W3TC_INC_DIR . '/functions/widgets.php'); /** * @var $module_status W3_ModuleStatus */ $module_status = w3_instance('W3_ModuleStatus'); w3tc_dashboard_setup(); global $current_user; $config_master = $this->_config_master; $browsercache_enabled = $module_status->is_enabled('browsercache'); $cloudflare_enabled = $module_status->is_enabled('cloudflare'); $enabled = $module_status->plugin_is_enabled(); $can_empty_memcache = $module_status->can_empty_memcache(); $can_empty_opcode = $module_status->can_empty_opcode(); $can_empty_apc_system = $module_status->can_empty_apc_system(); $can_empty_file = $module_status->can_empty_file(); $can_empty_varnish = $module_status->can_empty_varnish(); $cdn_enabled = $module_status->is_enabled('cdn'); $cdn_mirror_purge = w3_cdn_can_purge_all($module_status->get_module_engine('cdn')); if ($cloudflare_enabled && $this->_config->get_string('cloudflare.email') && $this->_config->get_string('cloudflare.key')) { $can_empty_cloudflare = true; } else { $can_empty_cloudflare = false; } // Required for Update Media Query String button $browsercache_update_media_qs = $this->_config->get_boolean('browsercache.cssjs.replace') || $this->_config->get_boolean('browsercache.other.replace'); include W3TC_INC_DIR . '/options/dashboard.php'; }
/** * Deactivate plugin action * * @return void */ function deactivate() { try { w3_enable_maintenance_mode(); } catch (Exception $ex) { } try { $e = w3_instance('W3_AdminEnvironment'); $config = w3_instance('W3_Config'); $e->fix_after_deactivation($config); w3_instance('W3_AdminLinks')->link_delete(); } catch (SelfTestExceptions $exs) { $r = w3_parse_selftest_exceptions($exs); if (strlen($r['required_changes']) > 0) { $changes_style = 'border: 1px solid black; ' . 'background: white; ' . 'margin: 10px 30px 10px 30px; ' . 'padding: 10px;'; $error = '<strong>W3 Total Cache Error:</strong> ' . 'Files and directories could not be automatically ' . 'removed to complete the deactivation. ' . '<br />Please execute commands manually:<br />' . '<div style="' . $changes_style . '">' . $r['required_changes'] . '</div>'; // this is not shown since wp redirects from that page // not solved now echo '<div class="error"><p>' . $error . '</p></div>'; } } try { w3_disable_maintenance_mode(); } catch (Exception $ex) { } }
private function _execute($handler, $action) { if (strpos($action, 'action_') === false) { throw new Exception(sprintf(__('%s is not an correct action.'), $action)); } if ($handler == '') { if (method_exists($this->_default, $action)) { call_user_func(array($this->_default, $action)); return; } } else { $handler = ucfirst($handler); $handler_w = explode('_', $handler); $handler = ''; foreach ($handler_w as $w) { $handler .= ucfirst($w); } $handler_class = "W3_AdminActions_{$handler}ActionsAdmin"; $handler_object = w3_instance($handler_class); if (method_exists($handler_object, $action)) { $handler_object->{$action}(); return; } } throw new Exception(sprintf(__('action %s does not exist for %s'), $action, $handler)); }
function fix_on_wpadmin_request($config, $force_all_checks) { $exs = new SelfTestExceptions(); // create add-ins $this->create_required_files($config, $exs); // create folders $this->create_required_folders($exs); $this->add_index_to_folders(); // create wp-loader file $wp_loader = w3_instance('W3_Environment_WpLoader'); if ($wp_loader->should_create()) { try { $wp_loader->create(); } catch (FilesystemOperationException $ex) { $exs->push($ex); } } if (count($exs->exceptions()) <= 0) { $this->notify_no_config_present($config, $exs); $this->notify_config_cache_not_writeable($config, $exs); } if (count($exs->exceptions()) > 0) { throw $exs; } }
/** * Returns required rules for module * @return array */ function get_required_rules() { /** * @var $dispatcher W3_Dispatcher */ $dispatcher = w3_instance('W3_Dispatcher'); return $dispatcher->get_required_rules_for_cloudflare(); }
/** * Instantiate plugin * @param $plugin_descriptor array('class_name' => '', 'enable_options' => '') */ private function _load_plugin($plugin_descriptor) { $criteria = $plugin_descriptor['enable_options']; if ($this->_criteria_matched($criteria)) { $plugin = w3_instance($plugin_descriptor['class_name']); $this->_loaded_plugins[] = $plugin; } }
/** * Loads options page and corresponding view */ public function options() { /** * @var W3_UI_ExtensionsAdminView $options_dashboard */ $options_dashboard = w3_instance('W3_UI_ExtensionsAdminView'); $options_dashboard->options(); }
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'); } }
/** * @param $state * @return bool */ public function send_minify_headers($state) { /** * @var W3_Config $config */ $config = w3_instance('W3_Config'); return $config->get_boolean('cloudflare.enabled') && !$this->cf->minify_enabled(); }
/** * Check if plugin can change the config key * @param $config_key * @param $meta * @return bool */ function can_change($config_key, $meta) { $enabled = w3_instance('W3_Config')->get_boolean('cdn.enabled'); if ($config_key == 'cdn.engine') { return !$enabled; } return true; }
/** * Fragment cache tab * * @return void */ function view() { $fragmentcache_enabled = $this->_config->get_boolean('fragmentcache.enabled'); $w3_plugin_fragmentcache = w3_instance('W3_Pro_Plugin_FragmentCache'); $registered_groups = $w3_plugin_fragmentcache->get_registered_fragment_groups(); $registered_global_groups = $w3_plugin_fragmentcache->get_registered_global_fragment_groups(); include W3TC_INC_DIR . '/options/pro/fragmentcache.php'; }
/** * General tab * * @return void */ function view() { w3_require_once(W3TC_INC_FUNCTIONS_DIR . '/ui.php'); global $current_user; $config_master = $this->_config_master; /** * @var $modules W3_ModuleStatus */ $modules = w3_instance('W3_ModuleStatus'); $pgcache_enabled = $modules->is_enabled('pgcache'); $dbcache_enabled = $modules->is_enabled('dbcache'); $objectcache_enabled = $modules->is_enabled('objectcache'); $browsercache_enabled = $modules->is_enabled('browsercache'); $minify_enabled = $modules->is_enabled('minify'); $cdn_enabled = $modules->is_enabled('cdn'); $varnish_enabled = $modules->is_enabled('varnish'); $fragmentcache_enabled = $modules->is_enabled('fragmentcache'); $enabled = $modules->plugin_is_enabled(); $enabled_checkbox = $modules->all_modules_enabled(); $check_rules = w3_can_check_rules(); $check_apc = function_exists('apc_store'); $check_eaccelerator = function_exists('eaccelerator_put'); $check_xcache = function_exists('xcache_set'); $check_wincache = function_exists('wincache_ucache_set'); $check_curl = function_exists('curl_init'); $check_memcached = class_exists('Memcache'); $check_ftp = function_exists('ftp_connect'); $check_tidy = class_exists('tidy'); $disc_enhanced_enabled = !(!$check_rules || !$this->is_master() && w3_is_network() && $config_master->get_string('pgcache.engine') != 'file_generic'); $can_empty_file = $modules->can_empty_file(); $can_empty_varnish = $modules->can_empty_varnish(); $cdn_mirror_purge = w3_cdn_can_purge_all($modules->get_module_engine('cdn')); $file_nfs = $this->_config->get_boolean('pgcache.file.nfs') || $this->_config->get_boolean('minify.file.nfs'); $file_locking = $this->_config->get_boolean('dbcache.file.locking') || $this->_config->get_boolean('objectcache.file.locking') || $this->_config->get_boolean('pgcache.file.locking') || $this->_config->get_boolean('minify.file.locking'); w3_require_once(W3TC_LIB_NEWRELIC_DIR . '/NewRelicWrapper.php'); $newrelic_conf_appname = NewRelicWrapper::get_wordpress_appname($this->_config, $this->_config_master, false); $newrelic_applications = array(); $nerser = w3_instance('W3_NewRelicService'); $new_relic_installed = $nerser->module_is_enabled(); $new_relic_running = true; if ($this->_config->get_boolean('newrelic.enabled')) { $new_relic_configured = $this->_config->get_string('newrelic.api_key') && $this->_config->get_string('newrelic.account_id'); $newrelic_prefix = ''; if ($new_relic_configured) { if (w3_is_network()) { $newrelic_prefix = $this->_config->get_string('newrelic.appname_prefix'); } try { $newrelic_applications = $nerser->get_applications(); } catch (Exception $ex) { } $newrelic_application = $this->_config->get_string('newrelic.application_id'); } } $licensing_visible = (!w3_is_multisite() || is_network_admin()) && !ini_get('w3tc.license_key') && get_transient('w3tc_license_status') != 'host_valid'; $custom_areas = apply_filters("{$this->_page}_anchors", array()); include W3TC_INC_DIR . '/options/general.php'; }
/** * PHP5 constructor * * @param string $dbuser * @param string $dbpassword * @param string $dbname * @param string $dbhost */ function __construct($dbuser, $dbpassword, $dbname, $dbhost) { $this->_config =& w3_instance('W3_Config'); $this->_lifetime = $this->_config->get_integer('dbcache.lifetime'); if ($this->_can_ob()) { ob_start(array(&$this, 'ob_callback')); } parent::__construct($dbuser, $dbpassword, $dbname, $dbhost); }
/** * PHP5-style constructor * * @param array $config */ function __construct($config = array()) { $this->_config = w3_instance('W3_Config'); if (empty($config)) { $this->_cf_config = array('email' => $this->_config->get_string('cloudflare.email'), 'key' => $this->_config->get_string('cloudflare.key'), 'zone' => $this->_config->get_string('cloudflare.zone')); } else { $this->_cf_config = array_merge(array('email' => '', 'key' => '', 'zone' => ''), $config); } }
public function deactivate() { try { $config = w3_instance('W3_Config'); $config->set('pgcache.prime.enabled', false); $config->save(); } catch (Exception $ex) { } }
/** * Returns nginx rules path * * @return string */ function w3_get_nginx_rules_path() { $config = w3_instance('W3_Config'); $path = $config->get_string('config.path'); if (!$path) { $path = w3_get_document_root() . '/nginx.conf'; } return $path; }
/** * PHP5-style constructor * * @param array $config */ function __construct($config = array()) { $this->_config = w3_instance('W3_Config'); if (empty($config)) { $this->_cf_config = array('email' => w3tc_get_extension_config('cloudflare', 'email'), 'key' => w3tc_get_extension_config('cloudflare', 'key'), 'zone' => w3tc_get_extension_config('cloudflare', 'zone')); } else { $this->_cf_config = array_merge(array('email' => '', 'key' => '', 'zone' => ''), $config); } }