public function w3tc_ajax_extension_cloudflare_zones_done() { $email = $_REQUEST['email']; $key = $_REQUEST['key']; $zone_id = Util_Request::get('zone_id'); if (empty($zone_id)) { return $this->_render_extension_cloudflare_zones(array('email' => $email, 'key' => $key, 'error_message' => 'Please select zone')); } $zone_name = ''; // get zone name try { $api = new Extension_CloudFlare_Api(array('email' => $email, 'key' => $key)); $zone = $api->zone($zone_id); $zone_name = $zone['name']; } catch (\Exception $ex) { $details['error_message'] = 'Can\'t authenticate: ' . $ex->getMessage(); include W3TC_DIR . '/Extension_CloudFlare_Popup_View_Intro.php'; exit; } $c = Dispatcher::config(); $c->set(array('cloudflare', 'email'), $email); $c->set(array('cloudflare', 'key'), $key); $c->set(array('cloudflare', 'zone_id'), $zone_id); $c->set(array('cloudflare', 'zone_name'), $zone_name); $c->save(); delete_transient('w3tc_cloudflare_stats'); $postfix = Util_Admin::custom_message_id(array(), array('extension_cloudflare_configuration_saved' => 'CloudFlare credentials are saved successfully')); echo 'Location admin.php?page=w3tc_extensions&extension=cloudflare&' . 'action=view&' . $postfix; exit; }
function run() { $c = Dispatcher::config(); $this->api = new Extension_CloudFlare_Api(array('email' => $c->get_string(array('cloudflare', 'email')), 'key' => $c->get_string(array('cloudflare', 'key')), 'zone_id' => $c->get_string(array('cloudflare', 'zone_id')), 'timelimit_api_request' => $c->get_integer(array('cloudflare', 'timelimit.api_request')))); $this->_config = $c; add_filter('w3tc_dashboard_actions', array($this, 'w3tc_dashboard_actions')); $widget = new Extension_CloudFlare_Widget(); $widget->init(); // modify settings page add_filter('w3tc_settings_general_anchors', array($this, 'w3tc_settings_general_anchors')); add_action('w3tc_settings_general_boxarea_cloudflare', array($this, 'w3tc_settings_general_boxarea_cloudflare')); add_action('wp_ajax_w3tc_cloudflare_api_request', array($this, 'action_cloudflare_api_request')); // modify main menu add_action('w3tc_extension_page_cloudflare', array('\\W3TC\\Extension_CloudFlare_Page', 'w3tc_extension_page_cloudflare')); add_filter('w3tc_admin_bar_menu', array($this, 'w3tc_admin_bar_menu')); // dashboard add_action('admin_print_scripts-toplevel_page_w3tc_dashboard', array($this, 'admin_print_scripts_w3tc_dashboard')); add_filter('w3tc_admin_actions', array($this, 'w3tc_admin_actions')); // own settings page add_action('admin_print_scripts-performance_page_w3tc_extensions', array('\\W3TC\\Extension_CloudFlare_Page', 'admin_print_scripts_w3tc_extensions')); add_action('w3tc_ajax', array('\\W3TC\\Extension_CloudFlare_Popup', 'w3tc_ajax')); // add check to comments page add_filter('comment_row_actions', array($this, 'comment_row_actions'), 10, 2); add_action('admin_print_styles-edit-comments.php', array($this, 'admin_print_styles_edit_comments')); add_action('admin_print_scripts-edit-comments.php', array($this, 'admin_print_scripts_edit_comments')); add_action('wp_ajax_w3tc_cloudflare_ip_check', array($this, 'w3tc_cloudflare_ip_check')); // add notices about api health if (Util_Admin::is_w3tc_admin_page()) { add_action('admin_notices', array($this, 'admin_notices')); add_action('network_admin_notices', array($this, 'admin_notices')); } $this->check_ip_versions(); }
/** * Extensions view * * @return void */ function render_content() { $extension = ''; $extension_status = 'all'; if (isset($_GET['extension_status'])) { if (in_array($_GET['extension_status'], array('all', 'active', 'inactive', 'core'))) { $extension_status = $_GET['extension_status']; } } if (isset($_GET['extension'])) { $extension = $_GET['extension']; } $view = isset($_GET['action']) && $_GET['action'] == 'view'; $extensions_active = Extensions_Util::get_active_extensions($this->_config); if ($extension && $view) { $all_settings = $this->_config->get_array('extensions.settings'); $meta = $extensions_active[$extension]; $sub_view = 'settings'; } else { $extensions_all = Extensions_Util::get_extensions($this->_config); $extensions_inactive = Extensions_Util::get_inactive_extensions($this->_config); $var = "extensions_{$extension_status}"; $extensions = ${$var}; $extension_keys = array_keys($extensions); sort($extension_keys); $sub_view = 'list'; $page = 1; } $config = Dispatcher::config(); include W3TC_INC_OPTIONS_DIR . '/extensions.php'; }
function render_content() { $config = Dispatcher::config(); $core = Dispatcher::component('Extension_FragmentCache_Core'); $registered_groups = $core->get_registered_fragment_groups(); include W3TC_DIR . '/Extension_FragmentCache_Page_View.php'; }
/** * Deactivate plugin action * * @return void */ public static function deactivate() { try { Util_Activation::enable_maintenance_mode(); } catch (\Exception $ex) { } try { $e = Dispatcher::component('Root_Environment'); $config = Dispatcher::config(); $e->fix_after_deactivation($config); Generic_AdminLinks::link_delete(); } catch (Util_Environment_Exceptions $exs) { $r = Util_Activation::parse_environment_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 { Util_Activation::disable_maintenance_mode(); } catch (\Exception $ex) { } }
function run() { add_filter('w3tc_config_default_values', array($this, 'w3tc_config_default_values')); add_action('w3tc_register_fragment_groups', array($this, 'register_groups')); $this->_config = Dispatcher::config(); if (Util_Environment::is_w3tc_pro($this->_config)) { if (!is_admin()) { /** * Register the caching of content to specific hooks */ foreach (array('genesis_header', 'genesis_footer', 'genesis_sidebar', 'genesis_loop', 'wp_head', 'wp_footer', 'genesis_comments', 'genesis_pings') as $hook) { add_action($hook, array($this, 'cache_genesis_start'), -999999999); add_action($hook, array($this, 'cache_genesis_end'), 999999999); } foreach (array('genesis_do_subnav', 'genesis_do_nav') as $filter) { add_filter($filter, array($this, 'cache_genesis_filter_start'), -999999999); add_filter($filter, array($this, 'cache_genesis_filter_end'), 999999999); } } /** * Since posts pages etc are cached individually need to be able to flush just those and not all fragment */ add_action('clean_post_cache', array($this, 'flush_post_fragment')); add_action('clean_post_cache', array($this, 'flush_terms_fragment'), 0, 0); $this->_request_uri = $_SERVER['REQUEST_URI']; } }
public function get_effective_browser_application() { $c = Dispatcher::config(); $api_key = $c->get(array('newrelic', 'api_key')); $id = $c->get(array('newrelic', 'browser.application_id')); if (empty($api_key) || empty($id)) { return null; } $applications_string = get_option('w3tc_nr_browser_applications'); $applications = @json_decode($applications_string, true); if (!is_array($applications)) { $applications = array(); } if (isset($applications[$id])) { return $applications[$id]; } try { $api = new Extension_NewRelic_Api($api_key); $app = $api->get_browser_application($id); if (!is_null($app)) { $applications[$id] = $app; update_option('w3tc_nr_browser_applications', json_encode($applications)); } return $app; } catch (\Exception $ex) { return null; } }
/** * PHP5-style constructor */ function __construct() { $this->_config = Dispatcher::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'); }
/** * Returns the active extensions * * @param unknown $config * @return array */ public static function get_active_extensions($config) { $extensions = Extensions_Util::get_extensions($config); $extensions_keys = array_keys($extensions); $config = Dispatcher::config(); $active_extensions = $config->get_array('extensions.active'); return array_intersect_key($extensions, $active_extensions); }
public function w3tc_settings_general_boxarea_monitoring() { $config = Dispatcher::config(); $nerser = Dispatcher::component('Extension_NewRelic_Service'); $new_relic_installed = $nerser->module_is_enabled(); $effective_appname = $nerser->get_effective_appname(); include W3TC_DIR . '/Extension_NewRelic_GeneralPage_View.php'; }
public function w3tc_admin_menu($menu) { $c = Dispatcher::config(); $monitoring_type = $c->get_string(array('newrelic', 'monitoring_type')); if ($monitoring_type == 'apm') { $menu = array_merge($menu, array('w3tc_monitoring' => array('page_title' => __('Monitoring', 'w3-total-cache'), 'menu_text' => __('Monitoring', 'w3-total-cache'), 'visible_always' => false))); } return $menu; }
/** * Returns nginx rules path * * @return string */ public static function get_nginx_rules_path() { $config = Dispatcher::config(); $path = $config->get_string('config.path'); if (!$path) { $path = Util_Environment::site_path() . 'nginx.conf'; } return $path; }
/** * Mobile tab * * @return void */ function view() { $c = Dispatcher::config(); $groups = array('value' => $c->get_array('mobile.rgroups'), 'disabled' => $c->is_sealed('mobile.rgroups'), 'description' => '<li>' . __('Enabling even a single user agent group will set a cookie called "w3tc_referrer." It is used to ensure a consistent user experience across page views. Make sure any reverse proxy servers etc respect this cookie for proper operation.', 'w3-total-cache') . '</li>' . '<li>' . __('Per the above, make sure that visitors are notified about the cookie as per any regulations in your market.', 'w3-total-cache') . '</li>'); $groups = apply_filters('w3tc_ui_config_item_mobile.rgroups', $groups); $w3_mobile = Dispatcher::component('Mobile_UserAgent'); $themes = $w3_mobile->get_themes(); include W3TC_INC_DIR . '/options/mobile.php'; }
function __construct() { $c = Dispatcher::config(); $this->_config = $c; $this->_lifetime = $c->get_integer('dbcache.lifetime'); $this->debug = $c->get_boolean('dbcache.debug'); $this->reject_logged = $c->get_boolean('dbcache.reject.logged'); $this->reject_constants = $c->get_array('dbcache.reject.constants'); }
/** * PHP5 Constructor */ function __construct() { $config = Dispatcher::config(); if ($config->get_boolean('mobile.enabled')) { $this->_mobile = Dispatcher::component('Mobile_UserAgent'); } if ($config->get_boolean('referrer.enabled')) { $this->_referrer = Dispatcher::component('Mobile_Referrer'); } }
function set_comment_status($id, $status) { if ($status == "spam") { $comment = get_comment($id); $value = array('a' => $comment->comment_author, 'am' => $comment->comment_author_email, 'ip' => $comment->comment_author_IP, 'con' => substr($comment->comment_content, 0, 100)); $c = Dispatcher::config(); $api = new Extension_CloudFlare_Api(array('email' => $c->get_string(array('cloudflare', 'email')), 'key' => $c->get_string(array('cloudflare', 'key')), 'zone_id' => $c->get_string(array('cloudflare', 'zone_id')), 'timelimit_api_request' => $c->get_integer(array('cloudflare', 'timelimit.api_request')))); $api->external_event('WP_SPAM', json_encode($value)); } }
/** * PHP5-style constructor */ function __construct() { $this->_config = Dispatcher::config(); $this->_region = $this->_config->get_string('cluster.messagebus.sns.region'); $this->_topic_arn = $this->_config->get_string('cluster.messagebus.sns.topic_arn'); $this->_api_key = $this->_config->get_string('cluster.messagebus.sns.api_key'); $this->_api_secret = $this->_config->get_string('cluster.messagebus.sns.api_secret'); $this->_debug = $this->_config->get_boolean('cluster.messagebus.debug'); $this->_api = null; }
function widget_form() { $storage = new UsageStatistics_StorageReader(); $summary_promise = $storage->get_history_summary_promise(); $c = Dispatcher::config(); if ($c->get_boolean('stats.enabled')) { include W3TC_DIR . '/UsageStatistics_Widget_View.php'; } else { include W3TC_DIR . '/UsageStatistics_Widget_View_Disabled.php'; } }
function cleanup() { $c = Dispatcher::config(); $engine = $c->get_string(array('fragmentcache', 'engine')); switch ($engine) { case 'file': $w3_cache_file_cleaner = new Cache_File_Cleaner(array('cache_dir' => Util_Environment::cache_blog_dir('fragment'), 'clean_timelimit' => $c->get_integer('timelimit.cache_gc'))); $w3_cache_file_cleaner->clean(); break; } }
public static function w3tc_settings_cdn_boxarea_configuration() { $config = Dispatcher::config(); $api_key = $config->get_string('cdn.rackspace_cdn.api_key'); $authorized = !empty($api_key); $access_url_full = ''; if ($authorized) { $p = $config->get_string('cdn.rackspace_cdn.service.protocol'); $access_url_full = ($p == 'https' ? 'https://' : 'http://') . $config->get_string('cdn.rackspace_cdn.service.access_url'); } include W3TC_DIR . '/Cdn_RackSpaceCdn_Page_View.php'; }
public function w3tc_monitoring_score($score) { $url = $_SERVER['HTTP_REFERER']; $config = Dispatcher::config(); $key = $config->get_string('widget.pagespeed.key'); $w3_pagespeed = new PageSpeed_Api($key); $r = $w3_pagespeed->analyze($url); if ($r) { $score .= $r['score'] . ' / 100'; } return $score; }
public function w3tc_cloudflare_flush() { $c = Dispatcher::config(); $api = new Extension_CloudFlare_Api(array('email' => $c->get_string(array('cloudflare', 'email')), 'key' => $c->get_string(array('cloudflare', 'key')), 'zone_id' => $c->get_string(array('cloudflare', 'zone_id')), 'timelimit_api_request' => $c->get_integer(array('cloudflare', 'timelimit.api_request')))); try { $v = $api->purge(); } catch (\Exception $ex) { Util_Admin::redirect_with_custom_messages2(array('errors' => array('cloudflare_flush' => __('Failed to flush CloudFlare cache: ', 'w3-total-cache') . $ex->getMessage()))); return; } Util_Admin::redirect_with_custom_messages2(array('notes' => array('cloudflare_flush' => __('CloudFlare cache successfully emptied.', 'w3-total-cache')))); }
public function widget_form() { $c = Dispatcher::config(); $account_hash = $c->get_string('cdn.highwinds.account_hash'); if (empty($account_hash)) { include W3TC_DIR . '/Cdn_Highwinds_Widget_View_NotConfigured.php'; return; } $url_manage = 'https://striketracker3.highwinds.com/accounts/' . $account_hash . '/configure/hosts'; $url_analyze = 'https://striketracker3.highwinds.com/accounts/' . $account_hash . '/analyze/overview'; $url_purge = Util_Ui::url(array('page' => 'w3tc_cdn', 'w3tc_cdn_purge' => 'y')); include W3TC_DIR . '/Cdn_Highwinds_Widget_View.php'; }
/** * Parses FAQ XML file into array * * @return array */ public static function parse() { $config = Dispatcher::config(); $faq = array(); self::parse_file($faq, 'faq', '', ''); if (Util_Environment::is_w3tc_edge($config)) { self::parse_file($faq, 'faq-edge', 'edge', '<b>Edge:</b> '); } if (Util_Environment::is_w3tc_pro($config)) { self::parse_file($faq, 'faq-pro', 'pro', '<b>Pro:</b> '); } return $faq; }
function w3tc_extensions_activate() { $config = Dispatcher::config(); $extension = Util_Request::get_string('w3tc_extensions_activate'); $ext = Extensions_Util::get_extension($config, $extension); if (!is_null($ext)) { if (Extensions_Util::activate_extension($extension, $config)) { Util_Admin::redirect_with_custom_messages2(array('notes' => array(sprintf(__('Extension <strong>%s</strong> has been successfully activated.', 'w3-total-cache'), $ext['name'])))); return; } } Util_Admin::redirect(array()); }
public function w3tc_errors($errors) { $c = Dispatcher::config(); if ($c->get_string('dbcache.engine') == 'memcached') { $memcached_servers = $c->get_array('dbcache.memcached.servers'); if (!Util_Installed::is_memcache_available($memcached_servers)) { if (!isset($errors['memcache_not_responding.details'])) { $errors['memcache_not_responding.details'] = array(); } $errors['memcache_not_responding.details'][] = sprintf(__('Database Cache: %s.', 'w3-total-cache'), implode(', ', $memcached_servers)); } } return $errors; }
public function w3tc_settings_general_boxarea_cdn() { $config = Dispatcher::config(); $engine_optgroups = array(); $engine_values = array(); $is_fsd = Util_Environment::is_w3tc_pro($config); if ($is_fsd) { $engine_optgroups[] = __('Full Site Delivery:', 'w3-total-cache'); $engine_values['cloudfront_fsd'] = array('label' => __('Amazon CloudFront', 'w3-total-cache'), 'optgroup' => 0); $engine_values['maxcdn_fsd'] = array('label' => __('MaxCDN (recommended)', 'w3-total-cache'), 'optgroup' => 0); $optgroup_pull = count($engine_optgroups); $engine_optgroups[] = __('Origin Pull / Mirror:', 'w3-total-cache'); } else { $optgroup_pull = count($engine_optgroups); $engine_optgroups[] = __('Origin Pull / Mirror:', 'w3-total-cache'); } $optgroup_push = count($engine_optgroups); $engine_optgroups[] = __('Origin Push:', 'w3-total-cache'); $engine_values['akamai'] = array('label' => __('Akamai', 'w3-total-cache'), 'optgroup' => $optgroup_pull); $engine_values['cf2'] = array('label' => __('Amazon CloudFront', 'w3-total-cache'), 'disabled' => !Util_Installed::curl() ? true : null, 'optgroup' => $optgroup_pull); $engine_values['att'] = array('label' => __('AT&T', 'w3-total-cache'), 'optgroup' => $optgroup_pull); $engine_values['cotendo'] = array('label' => __('Cotendo (Akamai)', 'w3-total-cache'), 'optgroup' => $optgroup_pull); $engine_values['mirror'] = array('label' => __('Generic Mirror', 'w3-total-cache'), 'optgroup' => $optgroup_pull); $engine_values['highwinds'] = array('label' => __('Highwinds', 'w3-total-cache'), 'optgroup' => $optgroup_pull); $engine_values['maxcdn'] = array('label' => __('MaxCDN', 'w3-total-cache'), 'optgroup' => $optgroup_pull); $engine_values['netdna'] = array('label' => __('MaxCDN Enterprise (NetDNA)', 'w3-total-cache'), 'optgroup' => $optgroup_pull); $engine_values['rackspace_cdn'] = array('label' => __('RackSpace CDN', 'w3-total-cache'), 'optgroup' => $optgroup_pull); $engine_values['edgecast'] = array('label' => __('Verizon Digital Media Services (EdgeCast) / Media Temple ProCDN', 'w3-total-cache'), 'optgroup' => $optgroup_pull); $engine_values['cf'] = array('disabled' => !Util_Installed::curl() ? true : null, 'label' => __('Amazon CloudFront', 'w3-total-cache'), 'optgroup' => $optgroup_push); $engine_values['s3'] = array('disabled' => !Util_Installed::curl() ? true : null, 'label' => __('Amazon Simple Storage Service (S3)', 'w3-total-cache'), 'optgroup' => $optgroup_push); $engine_values['s3_compatible'] = array('disabled' => !Util_Installed::curl() ? true : null, 'label' => __('Amazon Simple Storage Service (S3) Compatible', 'w3-total-cache'), 'optgroup' => $optgroup_push); $engine_values['google_drive'] = array('label' => __('Google Drive', 'w3-total-cache'), 'optgroup' => $optgroup_push); $engine_values['azure'] = array('label' => __('Microsoft Azure Storage', 'w3-total-cache'), 'optgroup' => $optgroup_push); $engine_values['rscf'] = array('disabled' => !Util_Installed::curl() ? true : null, 'label' => __('Rackspace Cloud Files', 'w3-total-cache'), 'optgroup' => $optgroup_push); $engine_values['ftp'] = array('disabled' => !Util_Installed::ftp() ? true : null, 'label' => __('Self-hosted / File Transfer Protocol Upload', 'w3-total-cache'), 'optgroup' => $optgroup_push); $cdn_enabled = $config->get_boolean('cdn.enabled'); $cdn_engine = $config->get_string('cdn.engine'); $tag = ''; if ($cdn_engine == 'cloudfront_fsd') { $tag = '#cdn-fsd-cloudfront'; } elseif ($cdn_engine == 'maxcdn_fsd') { $tag = '#cdn-fsd-maxcdn'; } if (empty($tag)) { $cdn_engine_extra_description = ''; } else { $cdn_engine_extra_description = ' See <a href="admin.php?page=w3tc_faq' . $tag . '">setup instructions</a>'; } include W3TC_DIR . '/Cdn_GeneralPage_View.php'; }
public function __construct($processors = null) { // cant force empty parameter list due to wp requirements if (!is_array($processors)) { throw new Exception('called incorrectly, use instance()'); } $this->processors = $processors; $this->active_processor = $processors[0]; $this->active_processor_number = 0; $c = Dispatcher::config(); $this->debug = $c->get_boolean('dbcache.debug'); if ($this->debug) { $this->_request_time_start = microtime(true); } }
private static function show_notice() { $config = Dispatcher::config(); if ($config->is_extension_active('genesis.theme')) { return false; } if (!self::is_theme_found()) { return false; } $state = Dispatcher::config_state(); if ($state->get_boolean('genesis.theme.hide_note_suggest_activation')) { return false; } return true; }
public static function admin_init_w3tc_dashboard() { $o = new Extension_NewRelic_Widget(); $o->_config = Dispatcher::config(); add_action('w3tc_widget_setup', array($o, 'wp_dashboard_setup')); add_action('w3tc_network_dashboard_setup', array($o, 'wp_dashboard_setup')); $nerser = Dispatcher::component('Extension_NewRelic_Service'); $view_application = $nerser->get_effective_application_id(); $new_relic_configured = $o->_config->get_string(array('newrelic', 'api_key')) && $view_application != 0; $monitoring_type = $o->_config->get_string(array('newrelic', 'monitoring_type')); if ($monitoring_type != 'browser') { wp_enqueue_script('w3tc-widget-newrelic', plugins_url('Extension_NewRelic_Widget_View.js', W3TC_FILE), array(), W3TC_VERSION); } wp_enqueue_style('w3tc-widget-newrelic', plugins_url('Extension_NewRelic_Widget_View.css', W3TC_FILE), array(), W3TC_VERSION); }