public function w3tc_config_save($config)
 {
     // frontend activity
     $engine = $config->get_string(array('fragmentcache', 'engine'));
     $is_frontend_active = !empty($engine) && Util_Environment::is_w3tc_pro($config);
     $config->set_extension_active_frontend('fragmentcache', $is_frontend_active);
 }
 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'];
     }
 }
Пример #3
0
 /**
  * Runs plugin
  */
 function run()
 {
     add_filter('cron_schedules', array($this, 'cron_schedules'), 5);
     add_action('init', array($this, 'init'), 1);
     if (Util_Environment::is_w3tc_pro_dev() && Util_Environment::is_w3tc_pro($this->_config)) {
         add_action('wp_footer', array($this, 'pro_dev_mode'));
     }
     add_action('admin_bar_menu', array($this, 'admin_bar_menu'), 150);
     if (isset($_REQUEST['w3tc_theme']) && isset($_SERVER['HTTP_USER_AGENT']) && stristr($_SERVER['HTTP_USER_AGENT'], W3TC_POWERED_BY) !== false) {
         add_filter('template', array($this, 'template_preview'));
         add_filter('stylesheet', array($this, 'stylesheet_preview'));
     } elseif ($this->_config->get_boolean('mobile.enabled') || $this->_config->get_boolean('referrer.enabled')) {
         add_filter('template', array($this, 'template'));
         add_filter('stylesheet', array($this, 'stylesheet'));
     }
     /**
      * Create cookies to flag if a pgcache role was loggedin
      */
     if (!$this->_config->get_boolean('pgcache.reject.logged') && $this->_config->get_array('pgcache.reject.logged_roles')) {
         add_action('set_logged_in_cookie', array($this, 'check_login_action'), 0, 5);
         add_action('clear_auth_cookie', array($this, 'check_login_action'), 0, 5);
     }
     if ($this->_config->get_string('common.support') == 'footer') {
         add_action('wp_footer', array($this, 'footer'));
     }
     if ($this->can_ob()) {
         ob_start(array($this, 'ob_callback'));
     }
 }
 /**
  * Runs plugin
  */
 function run()
 {
     add_action('admin_init', array($this, 'admin_init'));
     add_action('wp_ajax_w3tc_verify_plugin_license_key', array($this, 'action_verify_plugin_license_key'));
     add_action("w3tc_config_ui_save-w3tc_general", array($this, 'possible_state_change'), 2, 10);
     add_action('w3tc_message_action_licensing_upgrade', array($this, 'w3tc_message_action_licensing_upgrade'));
     if (!Util_Environment::is_w3tc_pro($this->_config)) {
         add_filter('w3tc_admin_bar_menu', array($this, 'w3tc_admin_bar_menu'));
     }
 }
 function widget_form()
 {
     $storage = new UsageStatistics_StorageReader();
     $summary_promise = $storage->get_history_summary_promise();
     $c = Dispatcher::config();
     if ($c->get_boolean('stats.enabled') && Util_Environment::is_w3tc_pro($c)) {
         include W3TC_DIR . '/UsageStatistics_Widget_View.php';
     } else {
         include W3TC_DIR . '/UsageStatistics_Widget_View_Disabled.php';
     }
 }
Пример #6
0
 /**
  * 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;
 }
Пример #7
0
 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&amp;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 static function w3tc_notes_wpml($notes)
 {
     if (!self::show_notice()) {
         return $notes;
     }
     $extension_id = 'wpml';
     $config = Dispatcher::config();
     if (!Util_Environment::is_w3tc_pro($config)) {
         $activate_text = 'Available after <a href="#" class="button-buy-plugin">upgrade</a>. ';
     } else {
         $activate_text = sprintf('<a class="button" href="%s">Click here</a> to try it. ', Util_Ui::url(array('w3tc_extensions_activate' => $extension_id)));
     }
     $notes[$extension_id] = sprintf(__('Activating the <a href="%s">WPML</a> extension for W3 Total Cache may be helpful for your site. %s%s', 'w3-total-cache'), Util_Ui::admin_url('admin.php?page=w3tc_extensions#' . $extension_id), $activate_text, Util_Ui::button_link(__('Hide this message', 'w3-total-cache'), Util_Ui::url(array('w3tc_default_config_state' => 'y', 'key' => 'wpml.hide_note_suggest_activation', 'value' => 'true'))));
     return $notes;
 }
 /**
  *
  *
  * @param unknown $extensions
  * @param Config  $config
  * @return mixed
  */
 public static function w3tc_extensions($extensions, $config)
 {
     $requirements = array();
     if (!self::is_theme_found()) {
         $requirements[] = 'Optimizes "Genesis Framework" version >= 1.9.0, which is not active';
     }
     if (empty($requirements) && !Util_Environment::is_w3tc_pro($config)) {
         $requirements[] = 'Available after <a href="#" class="button-buy-plugin">upgrade</a>';
     }
     if (!$config->is_extension_active('fragmentcache')) {
         $requirements[] = 'Activate "Fragment Cache" extension first';
     }
     $extensions['genesis.theme'] = array('name' => 'Genesis Framework by StudioPress', 'author' => 'W3 EDGE', 'description' => 'Provides 30-60% improvement in page generation time for the Genesis Framework by Copyblogger Media.', 'author_uri' => 'https://www.w3-edge.com/', 'extension_uri' => 'https://www.w3-edge.com/', 'extension_id' => 'genesis.theme', 'version' => '0.1', 'enabled' => empty($requirements), 'requirements' => implode(', ', $requirements), 'path' => 'w3-total-cache/Extension_Genesis_Plugin.php');
     return $extensions;
 }
 public function w3tc_ajax_newrelic_list_applications()
 {
     $api_key = $_REQUEST['api_key'];
     $c = Dispatcher::config();
     $details = array('api_key' => $api_key, 'monitoring_type' => $c->get_string(array('newrelic', 'monitoring_type')), 'apm.application_name' => $c->get_string(array('newrelic', 'apm.application_name')), 'browser.application_id' => $c->get_string(array('newrelic', 'browser.application_id')));
     if ($details['monitoring_type'] != 'browser') {
         $details['monitoring_type'] = 'apm';
     }
     $service = new Extension_NewRelic_Service($api_key);
     try {
         $details['apm_applications'] = $service->get_applications();
         $api = new Extension_NewRelic_Api($api_key);
         $details['browser_applications'] = $api->get_browser_applications();
     } catch (\Exception $ex) {
         $details = array('api_key' => $api_key, 'error_message' => 'API key verification failed: ' . $ex->getMessage());
         $this->render_intro($details);
         return;
     }
     $details['browser_disabled'] = !Util_Environment::is_w3tc_pro($c);
     include W3TC_DIR . '/Extension_NewRelic_Popup_View_ListApplications.php';
 }
 /**
  * Runs plugin
  */
 function run()
 {
     add_filter('w3tc_config_default_values', array($this, 'w3tc_config_default_values'));
     $config = Dispatcher::config();
     // remainder only when extension is frontend-active
     if (!$config->is_extension_active_frontend('fragmentcache')) {
         return;
     }
     add_action('init', array($this, 'on_init'), 9999999);
     add_filter('cron_schedules', array($this, 'cron_schedules'));
     add_filter('w3tc_footer_comment', array($this, 'w3tc_footer_comment'));
     if ($this->_config->get_string(array('fragmentcache', 'engine')) == 'file') {
         add_action('w3_fragmentcache_cleanup', array($this, 'cleanup'));
     }
     add_action('switch_blog', array($this, 'switch_blog'), 0, 2);
     $groups = $this->_config->get_array(array('fragmentcache', 'groups'));
     foreach ($groups as $group) {
         $split = explode(',', $group);
         $group = array_shift($split);
         $actions = $split;
         $this->_core->register_group($group, $actions, $this->_config->get_integer(array('fragmentcache', 'lifetime')));
     }
     // handle transients by own cache
     if (Util_Environment::is_w3tc_pro($this->_config)) {
         $wp_cache = Dispatcher::component('ObjectCache_WpObjectCache');
         $fc_cache = Dispatcher::component('Extension_FragmentCache_WpObjectCache');
         $wp_cache->register_cache($fc_cache, array('transient', 'site-transient'));
     }
     // flush operations
     add_action('w3tc_flush_all', array($this, 'w3tc_flush_all'), 300);
     add_action('w3tc_flush_fragmentcache', array($this, 'w3tc_flush_fragmentcache'));
     add_action('w3tc_flush_fragmentcache_group', array($this, 'w3tc_flush_fragmentcache_group'), 10, 2);
     // usage statistics handling
     add_action('w3tc_usage_statistics_of_request', array($this, 'w3tc_usage_statistics_of_request'), 10, 1);
     add_filter('w3tc_usage_statistics_metrics', array($this, 'w3tc_usage_statistics_metrics'));
 }
                    <?php 
$this->checkbox_debug('dbcache.debug');
?>
 <?php 
Util_Ui::e_config_label('dbcache.debug');
?>
</label><br />
                    <?php 
$this->checkbox_debug('objectcache.debug');
?>
 <?php 
Util_Ui::e_config_label('objectcache.debug');
?>
</label><br />
                    <?php 
if (Util_Environment::is_w3tc_pro($this->_config)) {
    ?>
                    <?php 
    $this->checkbox_debug(array('fragmentcache', 'debug'));
    ?>
 <?php 
    _e('Fragment Cache', 'w3-total-cache');
    ?>
</label><br />
                    <?php 
}
?>
                    <?php 
$this->checkbox_debug('cdn.debug');
?>
 <?php 
Пример #13
0
<?php

namespace W3TC;

if (!defined('W3TC')) {
    die;
}
$is_pro = Util_Environment::is_w3tc_pro($this->_config);
$this->checkbox('minify.css.strip.comments', false, 'css_');
?>
 <?php 
Util_Ui::e_config_label('minify.css.strip.comments');
?>
</label><br />
<?php 
$this->checkbox('minify.css.strip.crlf', false, 'css_');
?>
 <?php 
Util_Ui::e_config_label('minify.css.strip.crlf');
?>
</label><br />
<?php 
$this->checkbox('minify.css.embed', !$is_pro, 'csse_', true, $is_pro ? null : false);
?>
 Eliminate render-blocking CSS by moving it to HTML body</label>
<?php 
if (!$is_pro) {
    echo ' (Available after <a href="#" class="button-buy-plugin">upgrade</a>)';
}
?>
<br />
Пример #14
0
 /**
  *
  *
  * @var Config $config
  * @return string
  */
 public static function w3tc_edition($config = null)
 {
     if (Util_Environment::is_w3tc_enterprise($config)) {
         return 'enterprise';
     }
     if (Util_Environment::is_w3tc_pro($config) && Util_Environment::is_w3tc_pro_dev()) {
         return 'pro development';
     }
     if (Util_Environment::is_w3tc_pro($config)) {
         return 'pro';
     }
     return 'community';
 }
 /**
  * Save support us action
  *
  * @return void
  */
 function w3tc_config_save_support_us()
 {
     $support = Util_Request::get_string('support');
     $tweeted = Util_Request::get_boolean('tweeted');
     $signmeup = Util_Request::get_boolean('signmeup');
     $track_usage = Util_Request::get_boolean('track_usage');
     $this->_config->set('common.support', $support);
     $this->_config->set('common.tweeted', $tweeted);
     if ($track_usage) {
         $this->_config->set('common.track_usage', true);
     }
     if ($signmeup) {
         if (Util_Environment::is_w3tc_enterprise($this->_config)) {
             $license = 'enterprise';
         } elseif (Util_Environment::is_w3tc_pro($this->_config)) {
             $license = 'pro';
         } else {
             $license = 'community';
         }
         $email = filter_input(INPUT_POST, 'email', FILTER_SANITIZE_EMAIL);
         wp_remote_post(W3TC_MAILLINGLIST_SIGNUP_URL, array('body' => array('email' => $email, 'license' => $license)));
     }
     $this->_config->save();
     Generic_AdminLinks::link_update($this->_config);
     Util_Admin::redirect(array('w3tc_note' => 'config_save'));
 }
 public function run()
 {
     if (Util_Environment::is_w3tc_pro($this->_config)) {
         add_filter('w3tc_url_to_docroot_filename', array($this, 'w3tc_url_to_docroot_filename'));
     }
 }
 private function _w3tc_save_options_process()
 {
     $data = array('old_config' => $this->_config, 'response_query_string' => array(), 'response_actions' => array(), 'response_errors' => array(), 'response_notes' => array('config_save'));
     // if we are on extension settings page - stay on the same page
     if (Util_Request::get_string('page') == 'w3tc_extensions') {
         $data['response_query_string']['page'] = Util_Request::get_string('page');
         $data['response_query_string']['extension'] = Util_Request::get_string('extension');
         $data['response_query_string']['action'] = Util_Request::get_string('action');
     }
     $capability = apply_filters('w3tc_capability_config_save', 'manage_options');
     if (!current_user_can($capability)) {
         wp_die(__('You do not have the rights to perform this action.', 'w3-total-cache'));
     }
     /**
      * Read config
      * We should use new instance of WP_Config object here
      */
     $config = new Config();
     $this->read_request($config);
     if ($this->_page == 'w3tc_dashboard') {
         if (Util_Request::get_boolean('maxcdn')) {
             $config->set('cdn.enabled', true);
             $config->set('cdn.engine', 'maxcdn');
         }
     }
     /**
      * General tab
      */
     if ($this->_page == 'w3tc_general') {
         $file_nfs = Util_Request::get_boolean('file_nfs');
         $file_locking = Util_Request::get_boolean('file_locking');
         $config->set('pgcache.file.nfs', $file_nfs);
         $config->set('minify.file.nfs', $file_nfs);
         $config->set('dbcache.file.locking', $file_locking);
         $config->set('objectcache.file.locking', $file_locking);
         $config->set('pgcache.file.locking', $file_locking);
         $config->set('minify.file.locking', $file_locking);
         if (is_network_admin()) {
             if ($this->_config->get_boolean('common.force_master') !== $config->get_boolean('common.force_master')) {
                 // blogmap is wrong so empty it
                 @unlink(W3TC_CACHE_BLOGMAP_FILENAME);
                 $blogmap_dir = dirname(W3TC_CACHE_BLOGMAP_FILENAME) . '/' . basename(W3TC_CACHE_BLOGMAP_FILENAME, '.php') . '/';
                 if (@is_dir($blogmap_dir)) {
                     Util_File::rmdir($blogmap_dir);
                 }
             }
         }
         /**
          * Check permalinks for page cache
          */
         if ($config->get_boolean('pgcache.enabled') && $config->get_string('pgcache.engine') == 'file_generic' && !get_option('permalink_structure')) {
             $config->set('pgcache.enabled', false);
             $data['response_errors'][] = 'fancy_permalinks_disabled_pgcache';
         }
         if (!Util_Environment::is_w3tc_pro($this->_config)) {
             delete_transient('w3tc_license_status');
         }
     }
     /**
      * Minify tab
      */
     if ($this->_page == 'w3tc_minify' && !$this->_config->get_boolean('minify.auto')) {
         $js_groups = array();
         $css_groups = array();
         $js_files = Util_Request::get_array('js_files');
         $css_files = Util_Request::get_array('css_files');
         foreach ($js_files as $theme => $templates) {
             foreach ($templates as $template => $locations) {
                 foreach ((array) $locations as $location => $types) {
                     foreach ((array) $types as $files) {
                         foreach ((array) $files as $file) {
                             if (!empty($file)) {
                                 $js_groups[$theme][$template][$location]['files'][] = Util_Environment::normalize_file_minify($file);
                             }
                         }
                     }
                 }
             }
         }
         foreach ($css_files as $theme => $templates) {
             foreach ($templates as $template => $locations) {
                 foreach ((array) $locations as $location => $files) {
                     foreach ((array) $files as $file) {
                         if (!empty($file)) {
                             $css_groups[$theme][$template][$location]['files'][] = Util_Environment::normalize_file_minify($file);
                         }
                     }
                 }
             }
         }
         $config->set('minify.js.groups', $js_groups);
         $config->set('minify.css.groups', $css_groups);
         $js_theme = Util_Request::get_string('js_theme');
         $css_theme = Util_Request::get_string('css_theme');
         $data['response_query_string']['js_theme'] = $js_theme;
         $data['response_query_string']['css_theme'] = $css_theme;
     }
     /**
      * Browser Cache tab
      */
     if ($this->_page == 'w3tc_browsercache') {
         if ($config->get_boolean('browsercache.enabled') && $config->get_boolean('browsercache.no404wp') && !get_option('permalink_structure')) {
             $config->set('browsercache.no404wp', false);
             $data['response_errors'][] = 'fancy_permalinks_disabled_browsercache';
         }
         // todo: move to cdn module
         if (in_array($engine = $this->_config->get_string('cdn.engine'), array('netdna', 'maxcdn'))) {
             require_once W3TC_LIB_NETDNA_DIR . '/NetDNA.php';
             $keys = explode('+', $this->_config->get_string('cdn.' . $engine . '.authorization_key'));
             if (sizeof($keys) == 3) {
                 list($alias, $consumerkey, $consumersecret) = $keys;
                 try {
                     $api = new \NetDNA($alias, $consumerkey, $consumersecret);
                     $disable_cooker_header = $config->get_boolean('browsercache.other.nocookies') || $config->get_boolean('browsercache.cssjs.nocookies');
                     $api->update_pull_zone($this->_config->get_string('cdn.' . $engine . '.zone_id'), array('ignore_setcookie_header' => $disable_cooker_header));
                 } catch (\Exception $ex) {
                 }
             }
         }
     }
     /**
      * Mobile tab
      */
     if ($this->_page == 'w3tc_mobile') {
         $groups = Util_Request::get_array('mobile_groups');
         $mobile_groups = array();
         $cached_mobile_groups = array();
         foreach ($groups as $group => $group_config) {
             $group = strtolower($group);
             $group = preg_replace('~[^0-9a-z_]+~', '_', $group);
             $group = trim($group, '_');
             if ($group) {
                 $theme = isset($group_config['theme']) ? trim($group_config['theme']) : 'default';
                 $enabled = isset($group_config['enabled']) ? (bool) $group_config['enabled'] : true;
                 $redirect = isset($group_config['redirect']) ? trim($group_config['redirect']) : '';
                 $agents = isset($group_config['agents']) ? explode("\r\n", trim($group_config['agents'])) : array();
                 $mobile_groups[$group] = array('theme' => $theme, 'enabled' => $enabled, 'redirect' => $redirect, 'agents' => $agents);
                 $cached_mobile_groups[$group] = $agents;
             }
         }
         /**
          * Allow plugins modify WPSC mobile groups
          */
         $cached_mobile_groups = apply_filters('cached_mobile_groups', $cached_mobile_groups);
         /**
          * Merge existent and delete removed groups
          */
         foreach ($mobile_groups as $group => $group_config) {
             if (isset($cached_mobile_groups[$group])) {
                 $mobile_groups[$group]['agents'] = (array) $cached_mobile_groups[$group];
             } else {
                 unset($mobile_groups[$group]);
             }
         }
         /**
          * Add new groups
          */
         foreach ($cached_mobile_groups as $group => $agents) {
             if (!isset($mobile_groups[$group])) {
                 $mobile_groups[$group] = array('theme' => '', 'enabled' => true, 'redirect' => '', 'agents' => $agents);
             }
         }
         /**
          * Allow plugins modify W3TC mobile groups
          */
         $mobile_groups = apply_filters('w3tc_mobile_groups', $mobile_groups);
         /**
          * Sanitize mobile groups
          */
         foreach ($mobile_groups as $group => $group_config) {
             $mobile_groups[$group] = array_merge(array('theme' => '', 'enabled' => true, 'redirect' => '', 'agents' => array()), $group_config);
             $mobile_groups[$group]['agents'] = array_unique($mobile_groups[$group]['agents']);
             $mobile_groups[$group]['agents'] = array_map('strtolower', $mobile_groups[$group]['agents']);
             sort($mobile_groups[$group]['agents']);
         }
         $enable_mobile = false;
         foreach ($mobile_groups as $group_config) {
             if ($group_config['enabled']) {
                 $enable_mobile = true;
                 break;
             }
         }
         $config->set('mobile.enabled', $enable_mobile);
         $config->set('mobile.rgroups', $mobile_groups);
     }
     /**
      * Referrer tab
      */
     if ($this->_page == 'w3tc_referrer') {
         $groups = Util_Request::get_array('referrer_groups');
         $referrer_groups = array();
         foreach ($groups as $group => $group_config) {
             $group = strtolower($group);
             $group = preg_replace('~[^0-9a-z_]+~', '_', $group);
             $group = trim($group, '_');
             if ($group) {
                 $theme = isset($group_config['theme']) ? trim($group_config['theme']) : 'default';
                 $enabled = isset($group_config['enabled']) ? (bool) $group_config['enabled'] : true;
                 $redirect = isset($group_config['redirect']) ? trim($group_config['redirect']) : '';
                 $referrers = isset($group_config['referrers']) ? explode("\r\n", trim($group_config['referrers'])) : array();
                 $referrer_groups[$group] = array('theme' => $theme, 'enabled' => $enabled, 'redirect' => $redirect, 'referrers' => $referrers);
             }
         }
         /**
          * Allow plugins modify W3TC referrer groups
          */
         $referrer_groups = apply_filters('w3tc_referrer_groups', $referrer_groups);
         /**
          * Sanitize mobile groups
          */
         foreach ($referrer_groups as $group => $group_config) {
             $referrer_groups[$group] = array_merge(array('theme' => '', 'enabled' => true, 'redirect' => '', 'referrers' => array()), $group_config);
             $referrer_groups[$group]['referrers'] = array_unique($referrer_groups[$group]['referrers']);
             $referrer_groups[$group]['referrers'] = array_map('strtolower', $referrer_groups[$group]['referrers']);
             sort($referrer_groups[$group]['referrers']);
         }
         $enable_referrer = false;
         foreach ($referrer_groups as $group_config) {
             if ($group_config['enabled']) {
                 $enable_referrer = true;
                 break;
             }
         }
         $config->set('referrer.enabled', $enable_referrer);
         $config->set('referrer.rgroups', $referrer_groups);
     }
     /**
      * CDN tab
      */
     if ($this->_page == 'w3tc_cdn') {
         $cdn_cnames = Util_Request::get_array('cdn_cnames');
         $cdn_domains = array();
         foreach ($cdn_cnames as $cdn_cname) {
             $cdn_cname = trim($cdn_cname);
             /**
              * Auto expand wildcard domain to 10 subdomains
              */
             $matches = null;
             if (preg_match('~^\\*\\.(.*)$~', $cdn_cname, $matches)) {
                 $cdn_domains = array();
                 for ($i = 1; $i <= 10; $i++) {
                     $cdn_domains[] = sprintf('cdn%d.%s', $i, $matches[1]);
                 }
                 break;
             }
             if ($cdn_cname) {
                 $cdn_domains[] = $cdn_cname;
             }
         }
         switch ($this->_config->get_string('cdn.engine')) {
             case 'ftp':
                 $config->set('cdn.ftp.domain', $cdn_domains);
                 break;
             case 's3':
             case 's3_compatible':
                 $config->set('cdn.s3.cname', $cdn_domains);
                 break;
             case 'cf':
                 $config->set('cdn.cf.cname', $cdn_domains);
                 break;
             case 'cf2':
                 $config->set('cdn.cf2.cname', $cdn_domains);
                 break;
             case 'rackspace_cdn':
                 $config->set('cdn.rackspace_cdn.domains', $cdn_domains);
                 break;
             case 'rscf':
                 $config->set('cdn.rscf.cname', $cdn_domains);
                 break;
             case 'azure':
                 $config->set('cdn.azure.cname', $cdn_domains);
                 break;
             case 'mirror':
                 $config->set('cdn.mirror.domain', $cdn_domains);
                 break;
             case 'maxcdn':
                 $config->set('cdn.maxcdn.domain', $cdn_domains);
                 break;
             case 'netdna':
                 $config->set('cdn.netdna.domain', $cdn_domains);
                 break;
             case 'cotendo':
                 $config->set('cdn.cotendo.domain', $cdn_domains);
                 break;
             case 'edgecast':
                 $config->set('cdn.edgecast.domain', $cdn_domains);
                 break;
             case 'att':
                 $config->set('cdn.att.domain', $cdn_domains);
                 break;
             case 'akamai':
                 $config->set('cdn.akamai.domain', $cdn_domains);
                 break;
             case 'highwinds':
                 $config->set('cdn.highwinds.host.domains', $cdn_domains);
                 break;
         }
     }
     $old_ext_settings = $this->_config->get_array('extensions.settings', array());
     $new_ext_settings = $old_ext_settings;
     $modified = false;
     $extensions = Extensions_Util::get_extensions($config);
     foreach ($extensions as $extension => $descriptor) {
         $request = Util_Request::get_as_array('extensions.settings.' . $extension . '.');
         if (count($request) > 0) {
             if (!isset($new_ext_settings[$extension])) {
                 $new_ext_settings[$extension] = array();
             }
             foreach ($request as $key => $value) {
                 if (!isset($old_ext_settings[$extension]) || !isset($old_ext_settings[$extension][$key]) || $old_ext_settings[$extension][$key] != $value) {
                     $new_ext_settings[$extension][$key] = $value;
                     $modified = true;
                 }
             }
         }
     }
     if ($modified) {
         $config->set("extensions.settings", $new_ext_settings);
     }
     $data['new_config'] = $config;
     $data = apply_filters('w3tc_save_options', $data);
     $config = $data['new_config'];
     do_action('w3tc_config_ui_save', $config, $this->_config);
     do_action("w3tc_config_ui_save-{$this->_page}", $config, $this->_config);
     Util_Admin::config_save($this->_config, $config);
     if ($this->_page == 'w3tc_cdn') {
         /**
          * Handle Set Cookie Domain
          */
         $set_cookie_domain_old = Util_Request::get_boolean('set_cookie_domain_old');
         $set_cookie_domain_new = Util_Request::get_boolean('set_cookie_domain_new');
         if ($set_cookie_domain_old != $set_cookie_domain_new) {
             if ($set_cookie_domain_new) {
                 if (!$this->enable_cookie_domain()) {
                     Util_Admin::redirect(array_merge($data['response_query_string'], array('w3tc_error' => 'enable_cookie_domain')));
                 }
             } else {
                 if (!$this->disable_cookie_domain()) {
                     Util_Admin::redirect(array_merge($data['response_query_string'], array('w3tc_error' => 'disable_cookie_domain')));
                 }
             }
         }
     }
     return array('query_string' => $data['response_query_string'], 'actions' => $data['response_actions'], 'errors' => $data['response_errors'], 'notes' => $data['response_notes']);
 }
 /**
  * Send support request action
  *
  * @return void
  */
 function w3tc_support_send_details()
 {
     $c = Dispatcher::config();
     $post = array();
     foreach ($_GET as $p => $v) {
         $post[$p] = $v;
     }
     $post['user_agent'] = $_SERVER['HTTP_USER_AGENT'];
     $post['version'] = W3TC_VERSION;
     $license_level = 'community';
     if (Util_Environment::is_w3tc_pro($c)) {
         $license_level = 'pro';
     } elseif (Util_Environment::is_w3tc_enterprise($c)) {
         $license_level = 'enterprise';
     }
     $post['license_level'] = $license_level . ' ' . $c->get_string('plugin.license_key');
     /**
      * Add attachments
      */
     $attachments = array();
     $attach_files = array(Util_Environment::wp_config_path(), Util_Rule::get_pgcache_rules_core_path(), Util_Rule::get_pgcache_rules_cache_path(), Util_Rule::get_browsercache_rules_cache_path(), Util_Rule::get_browsercache_rules_no404wp_path(), Util_Rule::get_minify_rules_core_path(), Util_Rule::get_minify_rules_cache_path());
     /**
      * Attach config files
      */
     if ($handle = opendir(W3TC_CONFIG_DIR)) {
         while (($entry = @readdir($handle)) !== false) {
             if ($entry == '.' || $entry == '..' || $entry == 'index.html') {
                 continue;
             }
             $attach_file[] = W3TC_CONFIG_DIR . '/' . $entry;
         }
         closedir($handle);
     }
     foreach ($attach_files as $attach_file) {
         if ($attach_file && file_exists($attach_file) && !in_array($attach_file, $attachments)) {
             $attachments[] = array('filename' => basename($attach_file), 'content' => file_get_contents($attach_file));
         }
     }
     /**
      * Attach server info
      */
     $server_info = print_r($this->get_server_info(), true);
     $server_info = str_replace("\n", "\r\n", $server_info);
     $attachments[] = array('filename' => 'server_info.txt', 'content' => $server_info);
     /**
      * Attach phpinfo
      */
     ob_start();
     phpinfo();
     $php_info = ob_get_contents();
     ob_end_clean();
     $attachments[] = array('filename' => 'php_info.html', 'content' => $php_info);
     /**
      * Attach self-test
      */
     ob_start();
     $this->self_test();
     $self_test = ob_get_contents();
     ob_end_clean();
     $attachments[] = array('filename' => 'self_test.html', 'content' => $self_test);
     $post['attachments'] = $attachments;
     $response = wp_remote_post(W3TC_SUPPORT_REQUEST_URL, array('body' => $post, 'timeout' => $c->get_integer('timelimit.email_send')));
     if (!is_wp_error($response)) {
         $result = $response['response']['code'] == 200 && $response['body'] == 'ok';
     } else {
         $result = false;
     }
     echo $result ? 'ok' : 'error';
 }
<?php

namespace W3TC;

if (!defined('W3TC')) {
    die;
}
?>
<tr>
    <th colspan="2">
        <?php 
$c = Dispatcher::config();
$is_pro = Util_Environment::is_w3tc_pro($c);
$key = 'stats.enabled';
$value = $c->get($key);
if (!$is_pro) {
    $value = false;
}
$name = Util_Ui::config_key_to_http_name($key);
Util_Ui::checkbox($key, $name, $value, $c->is_sealed('common.') || !$is_pro, __('Enable caching statistics (on dashboard)', 'w3-total-cache'));
if (!$is_pro) {
    echo ' (Available after <a href="#" class="button-buy-plugin">upgrade</a>)';
}
?>
    </th>
</tr>
<?php 
Пример #20
0
    <h2 class="logo"><?php 
_e('W3 Total Cache <span>by W3 EDGE <sup>&reg;</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')));
        if (Util_Environment::is_w3tc_pro($config)) {
            $anchors[] = array('id' => 'fragment_cache', 'text' => __('Fragment Cache', 'w3-total-cache'));
        }
        $anchors = array_merge($anchors, array(array('id' => 'browser_cache', 'text' => __('Browser Cache', 'w3-total-cache')), array('id' => 'cdn', 'text' => __('<abbr title="Content Delivery Network">CDN</abbr>', 'w3-total-cache')), array('id' => 'reverse_proxy', 'text' => __('Reverse Proxy', 'w3-total-cache'))));
        if (Util_Environment::is_w3tc_enterprise()) {
            $anchors[] = array('id' => 'amazon_sns', 'text' => __('Amazon <abbr title="Simple Notification Service">SNS</abbr>', 'w3-total-cache'));
        }
        $anchors[] = array('id' => 'monitoring', 'text' => __('Monitoring', 'w3-total-cache'));
        if ($licensing_visible) {
            array('id' => 'licensing', 'text' => __('Licensing', 'w3-total-cache'));
        }
        $link_attrs = array_merge($anchors, $custom_areas, array(array('id' => 'miscellaneous', 'text' => __('Miscellaneous', 'w3-total-cache')), array('id' => 'debug', 'text' => __('Debug', 'w3-total-cache')), array('id' => 'settings', 'text' => __('Import / Export Settings', 'w3-total-cache'))));
        $links = array();
        foreach ($link_attrs as $link) {
            $links[] = "<a href=\"#{$link['id']}\">{$link['text']}</a>";
        }