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(); }
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; }
/** * Runs plugin */ function run() { // attach w3tc-bundled extensions add_filter('w3tc_extensions', array('\\W3TC\\Extension_CloudFlare_Plugin_Admin', 'w3tc_extensions'), 10, 2); add_filter('w3tc_extensions', array('\\W3TC\\Extension_FeedBurner_Plugin_Admin', 'w3tc_extensions'), 10, 2); add_filter('w3tc_extensions', array('\\W3TC\\Extension_FragmentCache_Plugin_Admin', 'w3tc_extensions'), 10, 2); add_filter('w3tc_extensions', array('\\W3TC\\Extension_Genesis_Plugin_Admin', 'w3tc_extensions'), 10, 2); add_filter('w3tc_extensions_hooks', array('\\W3TC\\Extension_Genesis_Plugin_Admin', 'w3tc_extensions_hooks')); add_filter('w3tc_notes_genesis_theme', array('\\W3TC\\Extension_Genesis_Plugin_Admin', 'w3tc_notes_genesis_theme')); add_filter('w3tc_extensions', array('\\W3TC\\Extension_NewRelic_Plugin_Admin', 'w3tc_extensions'), 10, 2); add_filter('w3tc_extensions', array('\\W3TC\\Extension_WordPressSeo_Plugin_Admin', 'w3tc_extensions'), 10, 2); add_filter('w3tc_extensions_hooks', array('\\W3TC\\Extension_WordPressSeo_Plugin_Admin', 'w3tc_extensions_hooks')); add_action('w3tc_notes_wordpress_seo', array('\\W3TC\\Extension_WordPressSeo_Plugin_Admin', 'w3tc_notes_wordpress_seo')); add_filter('w3tc_extensions', array('\\W3TC\\Extension_Wpml_Plugin_Admin', 'w3tc_extensions'), 10, 2); add_filter('w3tc_extensions', array('\\W3TC\\Extension_Amp_Plugin_Admin', 'w3tc_extensions'), 10, 2); add_filter('w3tc_extensions_hooks', array('\\W3TC\\Extension_Wpml_Plugin_Admin', 'w3tc_extensions_hooks')); add_action('w3tc_notes_wpml', array('\\W3TC\\Extension_Wpml_Plugin_Admin', 'w3tc_notes_wpml')); add_action('admin_init', array($this, 'admin_init'), 1); add_filter('pre_update_option_active_plugins', array($this, 'pre_update_option_active_plugins')); add_filter('w3tc_admin_menu', array($this, 'w3tc_admin_menu'), 10000); add_action('w3tc_settings_page-w3tc_extensions', array($this, 'w3tc_settings_page_w3tc_extensions')); if (Util_Admin::is_w3tc_admin_page()) { if (isset($_GET['extension']) && isset($_GET['action'])) { if (in_array($_GET['action'], array('activate', 'deactivate'))) { add_action('init', array($this, 'change_extension_status')); } } elseif (isset($_POST['checked'])) { add_action('admin_init', array($this, 'change_extensions_status')); } } }
function w3tc_save_new_relic() { $service = Dispatcher::component('Extension_NewRelic_Service'); $application = Util_Request::get_array('application'); $application['alerts_enabled'] = $application['alerts_enabled'] == 1 ? 'true' : 'false'; $application['rum_enabled'] = $application['rum_enabled'] == 1 ? 'true' : 'false'; $result = $service->update_application_settings($application); Util_Admin::redirect(array('w3tc_note' => 'new_relic_save'), true); }
function w3tc_opcache_flush() { $core = Dispatcher::component('SystemOpCache_Core'); $success = $core->flush(); if ($success) { Util_Admin::redirect_with_custom_messages2(array('notes' => array('OPCache was flushed successfully')), true); } else { Util_Admin::redirect_with_custom_messages2(array('errors' => array('Failed to flush OPCache')), true); } }
/** * Runs plugin */ function run() { if (Util_Admin::is_w3tc_admin_page()) { add_action('admin_head', array($this, 'admin_head')); add_action('w3tc_message_action_generic_support_us', array($this, 'w3tc_message_action_generic_support_us')); add_action('w3tc_ajax_generic_support_us', array($this, 'w3tc_ajax_generic_support_us')); add_action('w3tc_message_action_generic_edge', array($this, 'w3tc_message_action_generic_edge')); add_action('w3tc_ajax_generic_edge', array($this, 'w3tc_ajax_generic_edge')); } }
public function w3tc_cloudflare_save_settings() { $api = Extension_CloudFlare_SettingsForUi::api(); $errors = Extension_CloudFlare_SettingsForUi::settings_set($api); if (empty($errors)) { Util_Admin::redirect_with_custom_messages2(array('notes' => array('cloudflare_save_done' => __('CloudFlare settings are successfully updated.', 'w3-total-cache')))); } else { Util_Admin::redirect_with_custom_messages2(array('errors' => array('cloudflare_save_error' => __('Failed to update CloudFlare settings:', 'w3-total-cache') . "<br />\n" . implode("<br />\n", $errors)))); } }
/** * Runs plugin */ function run() { if (Util_Admin::get_current_wp_page() == 'w3tc_dashboard') { add_action('admin_enqueue_scripts', array($this, 'enqueue')); } add_action('w3tc_widget_setup', array($this, 'wp_dashboard_setup')); add_action('w3tc_network_dashboard_setup', array($this, 'wp_dashboard_setup')); if (is_admin()) { add_action('wp_ajax_w3tc_widget_latest_ajax', array($this, 'action_widget_latest_ajax')); } }
/** * Runs plugin */ function run() { if (Util_Admin::get_current_wp_page() == 'w3tc_dashboard') { add_action('admin_enqueue_scripts', array($this, 'enqueue')); } $this->_json_request_types = array('email_support' => sprintf(__('Less than 15 Minute Email Support Response %s', 'w3-total-cache'), '(M-F 9AM - 5PM EDT): $175 USD'), 'phone_support' => sprintf(__('Less than 15 Minute Phone Support Response %s', 'w3-total-cache'), '(M-F 9AM - 5PM EDT): $250 USD'), 'plugin_config' => sprintf(__('Professional Plugin Configuration %s', 'w3-total-cache'), 'Starting @ $200 USD'), 'theme_config' => sprintf(__('Theme Performance Optimization & Plugin Configuration %s', 'w3-total-cache'), 'Starting @ $350 USD'), 'linux_config' => sprintf(__('Linux Server Optimization & Plugin Configuration %s', 'w3-total-cache'), 'Starting @ $450 USD')); $this->_request_types = array('email_support' => sprintf(__('Less than 15 Minute Email Support Response %s', 'w3-total-cache'), '<br /><span>(M-F 9AM - 5PM EDT): $175 USD</span>'), 'phone_support' => sprintf(__('Less than 15 Minute Phone Support Response %s', 'w3-total-cache'), '<br /><span>(M-F 9AM - 5PM EDT): $250 USD</span>'), 'plugin_config' => sprintf(__('Professional Plugin Configuration %s', 'w3-total-cache'), '<br /><span>Starting @ $200 USD</span>'), 'theme_config' => sprintf(__('Theme Performance Optimization & Plugin Configuration %s', 'w3-total-cache'), '<br /><span>Starting @ $350 USD</span>'), 'linux_config' => sprintf(__('Linux Server Optimization & Plugin Configuration %s', 'w3-total-cache'), '<br /><span>Starting @ $450 USD</span>')); add_action('w3tc_widget_setup', array($this, 'wp_dashboard_setup')); add_action('w3tc_network_dashboard_setup', array($this, 'wp_dashboard_setup')); if (is_admin()) { add_action('wp_ajax_w3tc_action_payment_code', array($this, 'action_payment_code')); } }
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()); }
/** * Setup notices actions */ function admin_init() { $capability = apply_filters('w3tc_capability_admin_notices', 'manage_options'); if (current_user_can($capability)) { if (is_admin() && Util_Admin::is_w3tc_admin_page()) { /** * Only admin can see W3TC notices and errors */ if (!Util_Environment::is_wpmu()) { add_action('admin_notices', array($this, 'admin_notices'), 1, 1); } add_action('network_admin_notices', array($this, 'admin_notices'), 1, 1); } } }
function w3tc_cdn_rackspace_cdn_domains_reload() { $c = Dispatcher::config(); $core = Dispatcher::component('Cdn_Core'); $cdn = $core->get_cdn(); try { // try to obtain CNAMEs $domains = $cdn->service_domains_get(); } catch (\Exception $ex) { Util_Admin::redirect_with_custom_messages2(array('errors' => array('Failed to obtain CNAMEs: ' . $ex->getMessage())), true); return; } $c->set('cdn.rackspace_cdn.domains', $domains); $c->save(); Util_Admin::redirect_with_custom_messages2(array('notes' => array('CNAMEs are reloaded successfully')), true); }
function run() { add_filter('w3tc_compatibility_test', array($this, 'verify_compatibility')); add_action('w3tc_config_save', array($this, 'w3tc_config_save'), 10, 1); add_filter('w3tc_admin_actions', array($this, 'w3tc_admin_actions')); add_filter('w3tc_admin_menu', array($this, 'w3tc_admin_menu')); add_filter('w3tc_extension_plugin_links_newrelic', array($this, 'w3tc_extension_plugin_links')); add_action('w3tc_settings_page-w3tc_monitoring', array($this, 'w3tc_settings_page_w3tc_monitoring')); add_action('admin_init_w3tc_general', array('\\W3TC\\Extension_NewRelic_GeneralPage', 'admin_init_w3tc_general')); add_action('w3tc_ajax', array('\\W3TC\\Extension_NewRelic_Popup', 'w3tc_ajax')); if (Util_Admin::is_w3tc_admin_page()) { add_action('admin_notices', array($this, 'admin_notices')); add_action('network_admin_notices', array($this, 'admin_notices')); } add_action('admin_init_w3tc_dashboard', array('\\W3TC\\Extension_NewRelic_Widget', 'admin_init_w3tc_dashboard')); add_action('w3tc_ajax', array('\\W3TC\\Extension_NewRelic_Widget', 'w3tc_ajax')); add_filter('w3tc_notes', array($this, 'w3tc_notes')); }
function w3tc_licensing_reset_rooturi() { $license_key = $this->_config->get_string('plugin.license_key'); delete_transient('w3tc_license_status'); Licensing_Core::activate_license($license_key, W3TC_VERSION); $license = Licensing_Core::check_license($license_key, W3TC_VERSION); if ($license) { $status = $license->license_status; if (substr($status . '.', 0, 7) == 'active.') { Util_Admin::redirect_with_custom_messages2(array('notes' => array('Your license has been reset already. Activated for this website now.')), true); } } $r = Licensing_Core::reset_rooturi($this->_config->get_string('plugin.license_key'), W3TC_VERSION); if (isset($r->status) && $r->status == 'done') { Util_Admin::redirect_with_custom_messages2(array('notes' => array('Email with a link for license reset was sent to you')), true); } else { Util_Admin::redirect_with_custom_messages2(array('errors' => array('Failed to reset license')), true); } }
/** * Runs plugin */ function run() { if (Util_Admin::get_current_wp_page() == 'w3tc_dashboard') { add_action('admin_enqueue_scripts', array($this, 'enqueue')); } add_action('w3tc_widget_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); if ($this->have_zone && $this->authorized && isset($_GET['page']) && strpos($_GET['page'], 'w3tc_dashboard') !== false) { require_once W3TC_LIB_NETDNA_DIR . '/NetDNA.php'; require_once W3TC_LIB_NETDNA_DIR . '/NetDNAPresentation.php'; $authorization_key = $this->_config->get_string('cdn.netdna.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')); } }
/** * Activate plugin action * * @param bool $network_wide * @return void */ public static function activate($network_wide) { // decline non-network activation at WPMU if (Util_Environment::is_wpmu()) { 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; } } } try { $e = Dispatcher::component('Root_Environment'); $config = Dispatcher::config(); $e->fix_on_event($config, 'activate'); Generic_AdminLinks::link_update($config); // try to save config file if needed, optional thing so exceptions // hidden if (!file_exists(Config::util_config_filename(0, false))) { try { // create folders $e->fix_in_wpadmin($config); } catch (\Exception $ex) { } try { Util_Admin::config_save(Dispatcher::config(), $config); } catch (\Exception $ex) { } } } catch (\Exception $e) { Util_Activation::error_on_exception($e); } }
public function w3tc_ajax_newrelic_apply_configuration() { $api_key = $_REQUEST['api_key']; $monitoring_type = Util_Request::get('monitoring_type', 'apm'); $apm_application_name = Util_Request::get('apm_application_name'); $browser_application_id = Util_Request::get('browser_application_id'); $c = Dispatcher::config(); $c->set(array('newrelic', 'api_key'), $api_key); if ($monitoring_type == 'apm') { $c->set(array('newrelic', 'monitoring_type'), 'apm'); $c->set(array('newrelic', 'apm.application_name'), $apm_application_name); } else { $c->set(array('newrelic', 'monitoring_type'), 'browser'); $c->set(array('newrelic', 'browser.application_id'), $browser_application_id); } $c->save(); // flush cached values on api key change to allow to reset it from ui // if something goes wrong update_option('w3tc_nr_account_id', ''); update_option('w3tc_nr_application_id', ''); $postfix = Util_Admin::custom_message_id(array(), array('newrelic_configuration_saved' => 'NewRelic configuration is saved successfully')); echo 'Location admin.php?page=w3tc_general&' . $postfix; }
/** * Enables COOKIE_DOMAIN * * @return bool */ function enable_cookie_domain() { $config_path = Util_Environment::wp_config_path(); $config_data = @file_get_contents($config_path); if ($config_data === false) { return false; } $cookie_domain = Util_Admin::get_cookie_domain(); if ($this->is_cookie_domain_define($config_data)) { $new_config_data = preg_replace(W3TC_PLUGIN_TOTALCACHE_REGEXP_COOKIEDOMAIN, "define('COOKIE_DOMAIN', '" . addslashes($cookie_domain) . "')", $config_data, 1); } else { $new_config_data = preg_replace('~<\\?(php)?~', "\\0\r\ndefine('COOKIE_DOMAIN', '" . addslashes($cookie_domain) . "'); // " . __('Added by W3 Total Cache', 'w3-total-cache') . "\r\n", $config_data, 1); } if ($new_config_data != $config_data) { if (!@file_put_contents($config_path, $new_config_data)) { return false; } } return true; }
public function w3tc_edge_mode_disable() { $this->_config->set('common.edge', false); $this->_config->save(); Util_Admin::redirect(array('w3tc_note' => 'disabled_edge')); }
/** * Options page * * @return void */ function options() { $this->_page = Util_Request::get_string('page'); if (!Util_Admin::is_w3tc_admin_page()) { $this->_page = 'w3tc_dashboard'; } /* * Hidden pages */ if (isset($_REQUEST['w3tc_dbcluster_config'])) { $options_dbcache = new DbCache_Page(); $options_dbcache->dbcluster_config(); } /** * Show tab */ switch ($this->_page) { case 'w3tc_dashboard': $options_dashboard = new Generic_Page_Dashboard(); $options_dashboard->options(); break; case 'w3tc_general': $options_general = new Generic_Page_General(); $options_general->options(); break; case 'w3tc_pgcache': $options_pgcache = new PgCache_Page(); $options_pgcache->options(); break; case 'w3tc_minify': $options_minify = new Minify_Page(); $options_minify->options(); break; case 'w3tc_dbcache': $options_dbcache = new DbCache_Page(); $options_dbcache->options(); break; case 'w3tc_objectcache': $options_objectcache = new ObjectCache_Page(); $options_objectcache->options(); break; case 'w3tc_browsercache': $options_browsercache = new BrowserCache_Page(); $options_browsercache->options(); break; case 'w3tc_mobile': $options_mobile = new Mobile_Page_UserAgentGroups(); $options_mobile->options(); break; case 'w3tc_referrer': $options_referrer = new Mobile_Page_ReferrerGroups(); $options_referrer->options(); break; case 'w3tc_cdn': $options_cdn = new Cdn_Page(); $options_cdn->options(); break; case 'w3tc_faq': $options_faq = new Generic_Page_Faq(); $options_faq->options(); break; case 'w3tc_support': $options_support = new Support_Page(); $options_support->options(); break; case 'w3tc_install': $options_install = new Generic_Page_Install(); $options_install->options(); break; case 'w3tc_about': $options_about = new Generic_Page_About(); $options_about->options(); break; default: // placeholder to make it the only way to show pages // with the time $view = new Base_Page_Settings(); $view->options(); do_action("w3tc_settings_page-{$this->_page}"); $view->render_footer(); break; } }
function __construct() { $this->_config = Dispatcher::config(); $this->_config_master = Dispatcher::config_master(); $this->_page = Util_Admin::get_current_page(); }
public function w3tc_config_overloaded_enable($http_key) { $c = Dispatcher::config(); $key = Util_Ui::config_key_from_http_name($http_key); $c->set($key, true); $c->save(); Util_Admin::redirect(array()); }
<?php namespace W3TC; if (!defined('W3TC')) { die; } $config = Dispatcher::config(); $page = Util_Admin::get_current_page(); $licensing_visible = (!Util_Environment::is_wpmu() || is_network_admin()) && !ini_get('w3tc.license_key') && get_transient('w3tc_license_status') != 'host_valid'; ?> <?php do_action('w3tc-dashboard-head'); ?> <div class="wrap" id="w3tc"> <h2 class="logo"><?php _e('W3 Total Cache <span>by W3 EDGE <sup>®</sup></span>', 'w3-total-cache'); ?> </h2> <?php if (!Util_Environment::is_w3tc_pro($config)) { ?> <?php include W3TC_INC_OPTIONS_DIR . '/edd/buy.php'; } ?> <?php switch ($page) { case 'w3tc_general': $anchors = array(array('id' => 'general', 'text' => __('General', 'w3-total-cache')), array('id' => 'page_cache', 'text' => __('Page Cache', 'w3-total-cache')), array('id' => 'minify', 'text' => 'Minify'), array('id' => 'system_opcache', 'text' => __('Opcode Cache', 'w3-total-cache')), array('id' => 'database_cache', 'text' => __('Database Cache', 'w3-total-cache')), array('id' => 'object_cache', 'text' => __('Object Cache', 'w3-total-cache')));
/** * Save config, can't decline save process. (difference from action_save) * * Do some actions on config keys update * Used in several places such as: * * 1. common config save * 2. import settings * * @param Config $current_config * @param Config $new_config * @return bool * @throws Exception */ public static function config_save($current_config, $new_config) { $master_config = $new_config->is_master() ? $new_config : Dispatcher::config_master(); if ($master_config->get_integer('common.instance_id', 0) == 0) { $master_config->set('common.instance_id', mt_rand()); if (!$new_config->is_master()) { $master_config->save(); } } $old_config = new Config(); $browsercache_dependencies = array(); if ($new_config->get_boolean('browsercache.enabled')) { $browsercache_dependencies = array_merge($browsercache_dependencies, array('browsercache.rewrite', 'browsercache.cssjs.replace', 'browsercache.html.replace', 'browsercache.other.replace')); if ($new_config->get_boolean('browsercache.cssjs.replace')) { $browsercache_dependencies = array_merge($browsercache_dependencies, array('browsercache.cssjs.compression', 'browsercache.cssjs.expires', 'browsercache.cssjs.lifetime', 'browsercache.cssjs.cache.control', 'browsercache.cssjs.cache.policy', 'browsercache.cssjs.etag', 'browsercache.cssjs.w3tc')); } if ($new_config->get_boolean('browsercache.html.replace')) { $browsercache_dependencies = array_merge($browsercache_dependencies, array('browsercache.html.compression', 'browsercache.html.expires', 'browsercache.html.lifetime', 'browsercache.html.cache.control', 'browsercache.html.cache.policy', 'browsercache.html.etag', 'browsercache.html.w3tc')); } if ($new_config->get_boolean('browsercache.other.replace')) { $browsercache_dependencies = array_merge($browsercache_dependencies, array('browsercache.other.compression', 'browsercache.other.expires', 'browsercache.other.lifetime', 'browsercache.other.cache.control', 'browsercache.other.cache.policy', 'browsercache.other.etag', 'browsercache.other.w3tc')); } $old_bc_dependencies_values = array(); $new_bc_dependencies_values = array(); foreach ($browsercache_dependencies as $key) { $old_bc_dependencies_values[] = $old_config->get($key); $new_bc_dependencies_values[] = $new_config->get($key); } if (serialize($old_bc_dependencies_values) != serialize($new_bc_dependencies_values)) { $state_note = Dispatcher::config_state_note(); $state_note->set('common.show_note.flush_statics_needed', true); } } /** * Show need empty page cache notification */ $cache_flush = Dispatcher::component('CacheFlush'); if ($cache_flush->flushable_posts()) { $pgcache_dependencies = array_merge($browsercache_dependencies, array('pgcache.debug', 'pgcache.cache.query', 'pgcache.cache.home', 'pgcache.cache.feed', 'pgcache.cache.nginx_handle_xml', 'pgcache.cache.ssl', 'pgcache.cache.404', 'pgcache.cache.headers', 'pgcache.compatibility', 'pgcache.remove_charset', 'pgcache.accept.uri', 'pgcache.accept.files', 'pgcache.accept.qs', 'pgcache.late_init', 'pgcache.mirrors.enabled', 'pgcache.reject.front_page', 'pgcache.reject.logged', 'pgcache.reject.logged_roles', 'pgcache.reject.uri', 'pgcache.reject.ua', 'pgcache.reject.cookie', 'pgcache.reject.request_head', 'dbcache.enabled', 'objectcache.enabled', 'minify.enabled', 'mobile.enabled', 'referrer.enabled')); if ($new_config->get_boolean('pgcache.mirrors.enabled')) { $pgcache_dependencies = array_merge($pgcache_dependencies, array('pgcache.mirrors.home_urls')); } if ($new_config->get_boolean('dbcache.enabled')) { $pgcache_dependencies = array_merge($pgcache_dependencies, array('dbcache.debug')); } if ($new_config->get_boolean('objectcache.enabled')) { $pgcache_dependencies = array_merge($pgcache_dependencies, array('objectcache.debug')); } if ($new_config->get_boolean('minify.enabled')) { $pgcache_dependencies = array_merge($pgcache_dependencies, array('minify.auto', 'minify.debug', 'minify.rewrite', 'minify.html.enable', 'minify.html.engine', 'minify.html.inline.css', 'minify.html.inline.js', 'minify.html.strip.crlf', 'minify.html.comments.ignore', 'minify.css.enable', 'minify.css.engine', 'minify.css.groups', 'minify.js.enable', 'minify.js.engine', 'minify.js.groups', 'minify.htmltidy.options.clean', 'minify.htmltidy.options.hide-comments', 'minify.htmltidy.options.wrap', 'minify.reject.logged', 'minify.reject.ua', 'minify.reject.uri')); } /** * * * @var W3_ModuleStatus $modules */ $modules = Dispatcher::component('ModuleStatus'); if ($modules->is_running('cdn')) { $pgcache_dependencies = array_merge($pgcache_dependencies, array('cdn.enabled', 'cdn.debug', 'cdn.engine', 'cdn.uploads.enable', 'cdn.includes.enable', 'cdn.includes.files', 'cdn.theme.enable', 'cdn.theme.files', 'cdn.minify.enable', 'cdn.custom.enable', 'cdn.custom.files', 'cdn.ftp.domain', 'cdn.ftp.ssl', 'cdn.s3.cname', 'cdn.s3.ssl', 'cdn.cf.cname', 'cdn.cf.ssl', 'cdn.cf2.cname', 'cdn.cf2.ssl', 'cdn.rscf.cname', 'cdn.rscf.ssl', 'cdn.azure.cname', 'cdn.azure.ssl', 'cdn.mirror.domain', 'cdn.mirror.ssl', 'cdn.netdna.domain', 'cdn.netdna.ssl', 'cdn.cotendo.domain', 'cdn.cotendo.ssl', 'cdn.edgecast.domain', 'cdn.edgecast.ssl', 'cdn.att.domain', 'cdn.att.ssl', 'cdn.reject.logged_roles', 'cdn.reject.roles', 'cdn.reject.ua', 'cdn.reject.uri', 'cdn.reject.files')); } elseif ($old_config->get_boolean('cdn.enabled') && !$new_config->get_boolean('cdn.enabled')) { $pgcache_dependencies = array_merge($pgcache_dependencies, array('cdn.enabled')); } if ($new_config->get_boolean('mobile.enabled')) { $pgcache_dependencies = array_merge($pgcache_dependencies, array('mobile.rgroups')); } if ($new_config->get_boolean('referrer.enabled')) { $pgcache_dependencies = array_merge($pgcache_dependencies, array('referrer.rgroups')); } if ($new_config->get_boolean('browsercache.enabled') && $new_config->get_string('pgcache.engine') == 'file_generic') { $pgcache_dependencies = array_merge($pgcache_dependencies, array('browsercache.html.last_modified', 'browsercache.other.last_modified')); } $old_pgcache_dependencies_values = array(); $new_pgcache_dependencies_values = array(); foreach ($pgcache_dependencies as $pgcache_dependency) { $old_pgcache_dependencies_values[] = $old_config->get($pgcache_dependency); $new_pgcache_dependencies_values[] = $new_config->get($pgcache_dependency); } if (serialize($old_pgcache_dependencies_values) != serialize($new_pgcache_dependencies_values)) { $state_note = Dispatcher::config_state_note(); $state_note->set('common.show_note.flush_posts_needed', true); } } /** * Show need empty minify notification */ if ($current_config->get_boolean('minify.enabled') && $new_config->get_boolean('minify.enabled') && ($new_config->get_boolean('minify.css.enable') && ($new_config->get_boolean('minify.auto') || count($new_config->get_array('minify.css.groups'))) || $new_config->get_boolean('minify.js.enable') && ($new_config->get_boolean('minify.auto') || count($new_config->get_array('minify.js.groups'))))) { $minify_dependencies = array_merge($browsercache_dependencies, array('minify.auto', 'minify.debug', 'minify.options', 'minify.symlinks', 'minify.css.enable', 'minify.js.enable')); if ($new_config->get_boolean('minify.css.enable') && ($new_config->get_boolean('minify.auto') || count($new_config->get_array('minify.css.groups')))) { $minify_dependencies = array_merge($minify_dependencies, array('minify.css.engine', 'minify.css.combine', 'minify.css.strip.comments', 'minify.css.strip.crlf', 'minify.css.imports', 'minify.css.groups', 'minify.yuicss.path.java', 'minify.yuicss.path.jar', 'minify.yuicss.options.line-break', 'minify.csstidy.options.remove_bslash', 'minify.csstidy.options.compress_colors', 'minify.csstidy.options.compress_font-weight', 'minify.csstidy.options.lowercase_s', 'minify.csstidy.options.optimise_shorthands', 'minify.csstidy.options.remove_last_;', 'minify.csstidy.options.case_properties', 'minify.csstidy.options.sort_properties', 'minify.csstidy.options.sort_selectors', 'minify.csstidy.options.merge_selectors', 'minify.csstidy.options.discard_invalid_properties', 'minify.csstidy.options.css_level', 'minify.csstidy.options.preserve_css', 'minify.csstidy.options.timestamp', 'minify.csstidy.options.template')); } if ($new_config->get_boolean('minify.js.enable') && ($new_config->get_boolean('minify.auto') || count($new_config->get_array('minify.js.groups')))) { $minify_dependencies = array_merge($minify_dependencies, array('minify.js.engine', 'minify.js.combine.header', 'minify.js.combine.body', 'minify.js.combine.footer', 'minify.js.strip.comments', 'minify.js.strip.crlf', 'minify.js.groups', 'minify.yuijs.path.java', 'minify.yuijs.path.jar', 'minify.yuijs.options.line-break', 'minify.yuijs.options.nomunge', 'minify.yuijs.options.preserve-semi', 'minify.yuijs.options.disable-optimizations', 'minify.ccjs.path.java', 'minify.ccjs.path.jar', 'minify.ccjs.options.compilation_level', 'minify.ccjs.options.formatting')); } /** * * * @var W3_ModuleStatus $modules */ $modules = Dispatcher::component('ModuleStatus'); if ($modules->is_running('cdn')) { $minify_dependencies = array_merge($minify_dependencies, array('cdn.engine', 'cdn.enabled')); } elseif ($old_config->get_boolean('cdn.enabled') && !$new_config->get_boolean('cdn.enabled')) { $minify_dependencies = array_merge($minify_dependencies, array('cdn.enabled')); } $old_minify_dependencies_values = array(); $new_minify_dependencies_values = array(); foreach ($minify_dependencies as $minify_dependency) { $old_minify_dependencies_values[] = $old_config->get($minify_dependency); $new_minify_dependencies_values[] = $new_config->get($minify_dependency); } if (serialize($old_minify_dependencies_values) != serialize($new_minify_dependencies_values)) { $state_note = Dispatcher::config_state_note(); $state_note->set('minify.show_note.need_flush', true); } } if ($new_config->get_boolean('cdn.enabled') && !Cdn_Util::is_engine_mirror($new_config->get_string('cdn.engine'))) { /** * Show notification when CDN enabled */ if (!$old_config->get_boolean('cdn.enabled')) { $state = Dispatcher::config_state(); $state->set('cdn.show_note_cdn_upload', true); $state->save(); } /** * Show notification when Browser Cache settings changes */ $cdn_dependencies = array('browsercache.enabled'); if ($new_config->get_boolean('cdn.enabled')) { $cdn_dependencies = array('browsercache.cssjs.compression', 'browsercache.cssjs.expires', 'browsercache.cssjs.lifetime', 'browsercache.cssjs.cache.control', 'browsercache.cssjs.cache.policy', 'browsercache.cssjs.etag', 'browsercache.cssjs.w3tc', 'browsercache.html.compression', 'browsercache.html.expires', 'browsercache.html.lifetime', 'browsercache.html.cache.control', 'browsercache.html.cache.policy', 'browsercache.html.etag', 'browsercache.html.w3tc', 'browsercache.other.compression', 'browsercache.other.expires', 'browsercache.other.lifetime', 'browsercache.other.cache.control', 'browsercache.other.cache.policy', 'browsercache.other.etag', 'browsercache.other.w3tc'); } $old_cdn_dependencies_values = array(); $new_cdn_dependencies_values = array(); foreach ($cdn_dependencies as $cdn_dependency) { $old_cdn_dependencies_values[] = $old_config->get($cdn_dependency); $new_cdn_dependencies_values[] = $new_config->get($cdn_dependency); } if (serialize($old_cdn_dependencies_values) != serialize($new_cdn_dependencies_values)) { $state = Dispatcher::config_state(); $state->set('cdn.show_note_cdn_reupload', true); $state->save(); } } /** * Show need empty object cache notification */ if ($current_config->get_boolean('objectcache.enabled')) { $objectcache_dependencies = array('objectcache.groups.global', 'objectcache.groups.nonpersistent'); $old_objectcache_dependencies_values = array(); $new_objectcache_dependencies_values = array(); foreach ($objectcache_dependencies as $objectcache_dependency) { $old_objectcache_dependencies_values[] = $old_config->get($objectcache_dependency); $new_objectcache_dependencies_values[] = $new_config->get($objectcache_dependency); } if (serialize($old_objectcache_dependencies_values) != serialize($new_objectcache_dependencies_values)) { $state_note = Dispatcher::config_state_note(); $state_note->set('objectcache.show_note.flush_needed', true); } } do_action('w3tc_saved_options', $new_config); /** * Save config */ try { $new_config->save(); } catch (\Exception $ex) { // try to fix environment, it potentially can be fixed silently // dont show error here, it will be called again later // in admin_notices try { $environment = Dispatcher::component('Root_Environment'); $environment->fix_in_wpadmin($new_config); } catch (\Exception $ex) { } // retry save process and complain now on failure try { $new_config->save(); } catch (\Exception $ex) { throw new \Exception('<strong>Can\'t change configuration</strong>: ' . $ex->getMessage()); } } $w3_plugin_cdn = Dispatcher::component('Cdn_Core_Admin'); /** * Empty caches on engine change or cache enable/disable */ if ($old_config->get_string('pgcache.engine') != $new_config->get_string('pgcache.engine') || $old_config->get_string('pgcache.enabled') != $new_config->get_string('pgcache.enabled')) { $pgcacheflush = Dispatcher::component('PgCache_Flush'); $v = $pgcacheflush->flush(); } if ($old_config->get_string('dbcache.engine') != $new_config->get_string('dbcache.engine') || $old_config->get_string('dbcache.enabled') != $new_config->get_string('dbcache.enabled')) { w3tc_dbcache_flush(); } if ($old_config->get_string('objectcache.engine') != $new_config->get_string('objectcache.engine') || $old_config->get_string('objectcache.enabled') != $new_config->get_string('objectcache.enabled')) { w3tc_objectcache_flush(); } if ($old_config->get_string('minify.engine') != $new_config->get_string('minify.engine') || $old_config->get_string('minify.enabled') != $new_config->get_string('minify.enabled')) { w3tc_minify_flush(); } /** * Update CloudFront CNAMEs */ $update_cf_cnames = false; if ($new_config->get_boolean('cdn.enabled') && in_array($new_config->get_string('cdn.engine'), array('cf', 'cf2'))) { if ($new_config->get_string('cdn.engine') == 'cf') { $old_cnames = $old_config->get_array('cdn.cf.cname'); $new_cnames = $new_config->get_array('cdn.cf.cname'); } else { $old_cnames = $old_config->get_array('cdn.cf2.cname'); $new_cnames = $new_config->get_array('cdn.cf2.cname'); } if (count($old_cnames) != count($new_cnames) || count(array_diff($old_cnames, $new_cnames))) { $update_cf_cnames = true; } } /** * Refresh config */ $current_config->load(); /** * React to config changes */ $environment = Dispatcher::component('Root_Environment'); $environment->fix_on_event($new_config, 'config_change', $old_config); /** * Update support us option */ Generic_AdminLinks::link_update($current_config); /** * Auto upload browsercache files to CDN */ if ($new_config->get_boolean('cdn.enabled') && $new_config->get_string('cdn.engine') == 'ftp') { Util_Admin::cdn_delete_browsercache($current_config); Util_Admin::cdn_upload_browsercache($current_config); } /** * Update CloudFront CNAMEs */ if ($update_cf_cnames) { $error = null; $w3_plugin_cdn->update_cnames($error); } return true; }
/** * Admin notices action * * @return void */ function admin_notices() { $cookie_domain = Util_Admin::get_cookie_domain(); $error_messages = array('fancy_permalinks_disabled_pgcache' => sprintf(__('Fancy permalinks are disabled. Please %s it first, then re-attempt to enabling enhanced disk mode.', 'w3-total-cache'), Util_Ui::button_link('enable', 'options-permalink.php')), 'fancy_permalinks_disabled_browsercache' => sprintf(__('Fancy permalinks are disabled. Please %s it first, then re-attempt to enabling the \'Do not process 404 errors for static objects with WordPress\'.', 'w3-total-cache'), Util_Ui::button_link('enable', 'options-permalink.php')), 'support_request' => __('Failed to send support request.', 'w3-total-cache'), 'support_request_type' => __('Please select request type.', 'w3-total-cache'), 'support_request_url' => __('Please enter the address of the site in the site <acronym title="Uniform Resource Locator">URL</acronym> field.', 'w3-total-cache'), 'support_request_name' => __('Please enter your name in the Name field', 'w3-total-cache'), 'support_request_email' => __('Please enter valid email address in the E-Mail field.', 'w3-total-cache'), 'support_request_phone' => __('Please enter your phone in the phone field.', 'w3-total-cache'), 'support_request_subject' => __('Please enter subject in the subject field.', 'w3-total-cache'), 'support_request_description' => __('Please describe the issue in the issue description field.', 'w3-total-cache'), 'support_request_wp_login' => __('Please enter an administrator login. Create a temporary one just for this support case if needed.', 'w3-total-cache'), 'support_request_wp_password' => __('Please enter WP Admin password, be sure it\'s spelled correctly.', 'w3-total-cache'), 'support_request_ftp_host' => __('Please enter <acronym title="Secure Shell">SSH</acronym> or <acronym title="File Transfer Protocol">FTP</acronym> host for the site.', 'w3-total-cache'), 'support_request_ftp_login' => __('Please enter <acronym title="Secure Shell">SSH</acronym> or <acronym title="File Transfer Protocol">FTP</acronym> login for the server. Create a temporary one just for this support case if needed.', 'w3-total-cache'), 'support_request_ftp_password' => __('Please enter <acronym title="Secure Shell">SSH</acronym> or <acronym title="File Transfer Protocol">FTP</acronym> password for the <acronym title="File Transfer Protocol">FTP</acronym> account.', 'w3-total-cache'), 'support_request' => __('Unable to send the support request.', 'w3-total-cache'), 'config_import_no_file' => __('Please select config file.', 'w3-total-cache'), 'config_import_upload' => __('Unable to upload config file.', 'w3-total-cache'), 'config_import_import' => __('Configuration file could not be imported.', 'w3-total-cache'), 'config_reset' => sprintf(__('Default settings could not be restored. Please run <strong>chmod 777 %s</strong> to make the configuration file write-able, then try again.', 'w3-total-cache'), W3TC_CONFIG_DIR), 'cdn_purge_attachment' => __('Unable to purge attachment.', 'w3-total-cache'), 'pgcache_purge_post' => __('Unable to purge post.', 'w3-total-cache'), 'enable_cookie_domain' => sprintf(__('<strong>%swp-config.php</strong> could not be written, please edit config and add:<br /><strong style="color:#f00;">define(\'COOKIE_DOMAIN\', \'%s\');</strong> before <strong style="color:#f00;">require_once(ABSPATH . \'wp-settings.php\');</strong>.', 'w3-total-cache'), ABSPATH, addslashes($cookie_domain)), 'disable_cookie_domain' => sprintf(__('<strong>%swp-config.php</strong> could not be written, please edit config and add:<br /><strong style="color:#f00;">define(\'COOKIE_DOMAIN\', false);</strong> before <strong style="color:#f00;">require_once(ABSPATH . \'wp-settings.php\');</strong>.', 'w3-total-cache'), ABSPATH), 'pull_zone' => __('Pull Zone could not be automatically created.', 'w3-total-cache')); $note_messages = array('config_save' => __('Plugin configuration successfully updated.', 'w3-total-cache'), 'flush_all' => __('All caches successfully emptied.', 'w3-total-cache'), 'flush_memcached' => __('Memcached cache(s) successfully emptied.', 'w3-total-cache'), 'flush_opcode' => __('Opcode cache(s) successfully emptied.', 'w3-total-cache'), 'flush_file' => __('Disk cache(s) successfully emptied.', 'w3-total-cache'), 'flush_pgcache' => __('Page cache successfully emptied.', 'w3-total-cache'), 'flush_dbcache' => __('Database cache successfully emptied.', 'w3-total-cache'), 'flush_objectcache' => __('Object cache successfully emptied.', 'w3-total-cache'), 'flush_fragmentcache' => __('Fragment cache successfully emptied.', 'w3-total-cache'), 'flush_minify' => __('Minify cache successfully emptied.', 'w3-total-cache'), 'flush_browser_cache' => __('Media Query string has been successfully updated.', 'w3-total-cache'), 'flush_varnish' => __('Varnish servers successfully purged.', 'w3-total-cache'), 'flush_cdn' => __('CDN was successfully purged.', 'w3-total-cache'), 'support_request' => __('The support request has been successfully sent.', 'w3-total-cache'), 'config_import' => __('Settings successfully imported.', 'w3-total-cache'), 'config_reset' => __('Settings successfully restored.', 'w3-total-cache'), 'preview_enable' => __('Preview mode was successfully enabled', 'w3-total-cache'), 'preview_disable' => __('Preview mode was successfully disabled', 'w3-total-cache'), 'preview_deploy' => __('Preview settings successfully deployed. Preview mode remains enabled until it\'s disabled. Continue testing new settings or disable preview mode if done.', 'w3-total-cache'), 'cdn_purge_attachment' => __('Attachment successfully purged.', 'w3-total-cache'), 'pgcache_purge_post' => __('Post successfully purged.', 'w3-total-cache'), 'new_relic_save' => __('New relic settings have been updated.', 'w3-total-cache'), 'add_in_removed' => __('The add-in has been removed.', 'w3-total-cache'), 'enabled_edge' => __('Edge mode has been enabled.', 'w3-total-cache'), 'disabled_edge' => __('Edge mode has been disabled.', 'w3-total-cache'), 'pull_zone' => __('Pull Zone was automatically created.', 'w3-total-cache')); $errors = array(); $notes = array(); $environment_error_present = false; $error = Util_Request::get_string('w3tc_error'); if (isset($error_messages[$error])) { $errors[$error] = $error_messages[$error]; } $note = Util_Request::get_string('w3tc_note'); if (isset($note_messages[$note])) { $notes[$note] = $note_messages[$note]; } // print errors happened during last request execution, // when we decided to redirect with error message instead of // printing it directly (to avoid reexecution on refresh) if (!is_null($this->w3tc_message)) { $v = $this->w3tc_message; if (isset($v['errors']) && is_array($v['errors'])) { foreach ($v['errors'] as $error) { if (isset($error_messages[$error])) { $errors[] = $error_messages[$error]; } else { $errors[] = $error; } } } if (isset($v['notes']) && is_array($v['notes'])) { foreach ($v['notes'] as $note) { if (isset($note_messages[$note])) { $notes[] = $note_messages[$note]; } else { $notes[] = $note; } } } } /* * Filesystem environment fix, if needed */ try { global $pagenow; if ($pagenow == 'plugins.php' || Util_Admin::is_w3tc_admin_page()) { $environment = Dispatcher::component('Root_Environment'); $environment->fix_in_wpadmin($this->_config); if (isset($_REQUEST['upgrade'])) { $notes[] = __('Required files and directories have been automatically created', 'w3-total-cache'); } } } catch (Util_Environment_Exceptions $exs) { $r = Util_Activation::parse_environment_exceptions($exs); $n = 1; foreach ($r['before_errors'] as $e) { $errors['generic_env_' . $n] = $e; $n++; } if (strlen($r['required_changes']) > 0) { $changes_style = 'border: 1px solid black; ' . 'background: white; ' . 'margin: 10px 30px 10px 30px; ' . 'padding: 10px; display: none'; $ftp_style = 'border: 1px solid black; background: white; ' . 'margin: 10px 30px 10px 30px; ' . 'padding: 10px; display: none'; $ftp_form = str_replace('class="wrap"', '', $exs->credentials_form()); $ftp_form = str_replace('<form ', '<form name="w3tc_ftp_form" ', $ftp_form); $ftp_form = str_replace('<fieldset>', '', $ftp_form); $ftp_form = str_replace('</fieldset>', '', $ftp_form); $ftp_form = str_replace('id="upgrade" class="button"', 'id="upgrade" class="button w3tc-button-save"', $ftp_form); $error = '<strong>W3 Total Cache Error:</strong> ' . 'Files and directories could not be automatically ' . 'created to complete the installation. ' . '<table>' . '<tr>' . '<td>Please execute commands manually</td>' . '<td>' . Util_Ui::button('View required changes', '', 'w3tc-show-required-changes') . '</td>' . '</tr>' . '<tr>' . '<td>or use FTP form to allow ' . '<strong>W3 Total Cache</strong> make it automatically.' . '</td>' . '<td>' . Util_Ui::button('Update via FTP', '', 'w3tc-show-ftp-form') . '</td>' . '</tr></table>' . '<div class="w3tc-required-changes" style="' . $changes_style . '">' . $r['required_changes'] . '</div>' . '<div class="w3tc-ftp-form" style="' . $ftp_style . '">' . $ftp_form . '</div>'; $environment_error_present = true; $errors['generic_ftp'] = $error; } foreach ($r['later_errors'] as $e) { $errors['generic_env_' . $n] = $e; $n++; } } $errors = apply_filters('w3tc_errors', $errors); $notes = apply_filters('w3tc_notes', $notes); /** * Show messages */ foreach ($notes as $key => $note) { echo sprintf('<div class="updated w3tc_note" id="%s"><p>%s</p></div>', $key, $note); } foreach ($errors as $key => $error) { echo sprintf('<div class="error w3tc_error" id="%s"><p>%s</p></div>', $key, $error); } }
public function w3tc_ajax_cdn_highwinds_configure_cnames() { $details = array('cnames' => Util_Request::get_array('cdn_cnames')); $core = Dispatcher::component('Cdn_Core'); $cdn = $core->get_cdn(); try { // try to obtain CNAMEs $cdn->service_cnames_set($details['cnames']); $c = Dispatcher::config(); $c->set('cdn.highwinds.host.domains', $details['cnames']); $c->save(); $postfix = Util_Admin::custom_message_id(array(), array('cdn_cnames_saved' => 'CNAMEs are saved successfully')); echo 'Location admin.php?page=w3tc_cdn&' . $postfix; exit; } catch (\Exception $ex) { $details['error_message'] = $ex->getMessage(); } $this->render_configure_cnames_form($details); exit; }
/** * Create a NetDNA or MaxCDN pull zone automatically */ function w3tc_cdn_auto_create_netdna_maxcdn_pull_zone() { require_once W3TC_LIB_NETDNA_DIR . '/NetDNA.php'; $cdn_engine = Util_Request::get_string('type'); $this->validate_cdnengine_is_netdna_maxcdn($cdn_engine); $authorization_key = Util_Request::get_string('authorization_key'); $this->validate_authorization_key($authorization_key); $keys = explode('+', $authorization_key); list($alias, $consumerkey, $consumersecret) = $keys; $url = 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(); $state = Dispatcher::config_state(); $zones = $api->get_pull_zones(); $zone_count = sizeof($zones); Util_Admin::make_track_call(array('type' => 'cdn', 'data' => array('cdn' => $cdn_engine, 'action' => 'zonecreation', 'creation' => 'manual', 'creationtime' => time(), 'signupclick' => $state->get_integer('track.maxcdn_signup'), 'authorizeclick' => $state->get_integer('track.maxcdn_authorize'), 'validationclick' => $state->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; }
public function w3tc_ajax_cdn_rackspace_containers_done() { $user_name = $_REQUEST['user_name']; $api_key = $_REQUEST['api_key']; $access_token = $_REQUEST['access_token']; $access_region_descriptor = json_decode(strtr($_REQUEST['access_region_descriptor'], '!^', '"\\'), true); $region = $_REQUEST['region']; $container = Util_Request::get('container'); $api_files = new Cdn_RackSpace_Api_CloudFiles(array('access_token' => $access_token, 'access_region_descriptor' => $access_region_descriptor, 'new_access_required' => '')); $api_cdn = new Cdn_RackSpace_Api_CloudFilesCdn(array('access_token' => $access_token, 'access_region_descriptor' => $access_region_descriptor, 'new_access_required' => '')); try { if (empty($container)) { $container_new = $_REQUEST['container_new']; if (empty($container_new)) { throw new \Exception('Please select container'); } $api_files->container_create($container_new); $api_cdn->container_cdn_enable($container_new); $container = $container_new; } } catch (\Exception $ex) { $containers = $api_cdn->containers(); $details = array('user_name' => $user_name, 'api_key' => $api_key, 'access_token' => $access_token, 'access_region_descriptor_serialized' => strtr(json_encode($access_region_descriptor), '"\\', '!^'), 'region' => $region, 'containers' => $containers); $details['error_message'] = $ex->getMessage(); include W3TC_DIR . '/Cdn_RackSpaceCloudFiles_Popup_View_Containers.php'; exit; } $c = Dispatcher::config(); $c->set('cdn.rscf.user', $user_name); $c->set('cdn.rscf.key', $api_key); $c->set('cdn.rscf.location', $region); $c->set('cdn.rscf.container', $container); $c->save(); // reset calculated state $state = Dispatcher::config_state(); $state->set('cdn.rackspace_cf.access_state', ''); $state->save(); $postfix = Util_Admin::custom_message_id(array(), array('cdn_configuration_saved' => 'CDN credentials are saved successfully')); echo 'Location admin.php?page=w3tc_cdn&' . $postfix; exit; }