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';
 }
 /**
  * Referrer tab
  *
  * @return void
  */
 function view()
 {
     $groups = $this->_config->get_array('referrer.rgroups');
     $w3_referrer = Dispatcher::component('Mobile_Referrer');
     $themes = $w3_referrer->get_themes();
     include W3TC_INC_DIR . '/options/referrer.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) {
     }
 }
 /**
  * General tab
  *
  * @return void
  */
 function view()
 {
     global $current_user;
     $config_master = $this->_config_master;
     /**
      *
      *
      * @var $modules W3_ModuleStatus
      */
     $modules = Dispatcher::component('ModuleStatus');
     $pgcache_enabled = $modules->is_enabled('pgcache');
     $dbcache_enabled = $modules->is_enabled('dbcache');
     $objectcache_enabled = $modules->is_enabled('objectcache');
     $browsercache_enabled = $modules->is_enabled('browsercache');
     $minify_enabled = $modules->is_enabled('minify');
     $cdn_enabled = $modules->is_enabled('cdn');
     $varnish_enabled = $modules->is_enabled('varnish');
     $enabled = $modules->plugin_is_enabled();
     $enabled_checkbox = $modules->all_modules_enabled();
     $check_rules = Util_Rule::can_check_rules();
     $disc_enhanced_enabled = !(!$check_rules || !$this->is_master() && Util_Environment::is_wpmu() && $config_master->get_string('pgcache.engine') != 'file_generic');
     $can_empty_file = $modules->can_empty_file();
     $can_empty_varnish = $modules->can_empty_varnish();
     $cdn_mirror_purge = Cdn_Util::can_purge_all($modules->get_module_engine('cdn'));
     $file_nfs = $this->_config->get_boolean('pgcache.file.nfs') || $this->_config->get_boolean('minify.file.nfs');
     $file_locking = $this->_config->get_boolean('dbcache.file.locking') || $this->_config->get_boolean('objectcache.file.locking') || $this->_config->get_boolean('pgcache.file.locking') || $this->_config->get_boolean('minify.file.locking');
     $licensing_visible = (!Util_Environment::is_wpmu() || is_network_admin()) && !ini_get('w3tc.license_key') && get_transient('w3tc_license_status') != 'host_valid';
     $custom_areas = apply_filters("w3tc_settings_general_anchors", array());
     include W3TC_INC_DIR . '/options/general.php';
 }
 public function run()
 {
     $core = Dispatcher::component('UsageStatistics_Core');
     $core->add_shutdown_handler();
     // usage default 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'));
 }
 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';
 }
 /**
  * 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 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);
 }
 /**
  * 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 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);
     }
 }
 /**
  * Install tab
  *
  * @return void
  */
 function view()
 {
     $rewrite_rules_descriptors = array();
     if (Util_Rule::can_check_rules()) {
         $e = Dispatcher::component('Root_Environment');
         $rewrite_rules_descriptors = $e->get_required_rules($this->_config);
         $other_areas = $e->get_other_instructions($this->_config);
     }
     include W3TC_INC_DIR . '/options/install.php';
 }
 /**
  * Hook into Yoast SEO sitemap image filter.
  *
  * @param unknown $uri
  * @return string
  */
 public function wpseo_cdn_filter($uri)
 {
     $common = Dispatcher::component('Cdn_Core');
     $cdn = $common->get_cdn();
     $parsed = parse_url($uri);
     $path = $parsed['path'];
     $remote_path = $common->uri_to_cdn_uri($path);
     $new_url = $cdn->format_url($remote_path);
     return $new_url;
 }
示例#13
0
 /**
  * Clears global and repeated urls
  */
 function purge_post_cleanup()
 {
     if ($this->flush_operation_requested) {
         $common = Dispatcher::component('Cdn_Core');
         $results = array();
         $common->purge_all($results);
         $count = 999;
         $this->flush_operation_requested = false;
     }
     return $count;
 }
 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);
 }
示例#15
0
 /**
  * CDN tab
  *
  * @return void
  */
 function view()
 {
     $config = Dispatcher::config();
     $cdn_engine = $config->get_string('cdn.engine');
     if (Cdn_Util::is_engine_fsd($cdn_engine)) {
         do_action('w3tc_settings_cdn');
         return;
     }
     $cdn_enabled = $config->get_boolean('cdn.enabled');
     $cdn_mirror = Cdn_Util::is_engine_mirror($cdn_engine);
     $cdn_mirror_purge_all = Cdn_Util::can_purge_all($cdn_engine);
     $cdn_common = Dispatcher::component('Cdn_Core');
     $cdn = $cdn_common->get_cdn();
     $cdn_supports_header = $cdn->headers_support() == W3TC_CDN_HEADER_MIRRORING;
     $minify_enabled = $config->get_boolean('minify.enabled') && Util_Rule::can_check_rules() && $config->get_boolean('minify.rewrite') && (!$config->get_boolean('minify.auto') || Cdn_Util::is_engine_mirror($config->get_string('cdn.engine')));
     $cookie_domain = $this->get_cookie_domain();
     $set_cookie_domain = $this->is_cookie_domain_enabled();
     // Required for Update Media Query String button
     $browsercache_enabled = $config->get_boolean('browsercache.enabled');
     $browsercache_update_media_qs = $config->get_boolean('browsercache.cssjs.replace') || $config->get_boolean('browsercache.other.replace');
     if (in_array($cdn_engine, array('netdna', 'maxcdn'))) {
         $pull_zones = array();
         $authorization_key = $config->get_string("cdn.{$cdn_engine}.authorization_key");
         $zone_id = $config->get_integer("cdn.{$cdn_engine}.zone_id");
         $alias = $consumerkey = $consumersecret = '';
         if ($authorization_key) {
             $keys = explode('+', $authorization_key);
             if (sizeof($keys) == 3) {
                 list($alias, $consumerkey, $consumersecret) = $keys;
             }
         }
         $authorized = $authorization_key != '' && $alias && $consumerkey && $consumersecret;
         $have_zone = $zone_id != 0;
         if ($authorized) {
             require_once W3TC_LIB_NETDNA_DIR . '/NetDNA.php';
             try {
                 $api = new \NetDNA($alias, $consumerkey, $consumersecret);
                 $pull_zones = $api->get_zones_by_url(get_home_url());
             } catch (\Exception $ex) {
                 Util_Ui::error_box('<p>There is an error with your CDN settings: ' . $ex->getMessage() . '</p>');
             }
         }
     }
     include W3TC_INC_DIR . '/options/cdn.php';
 }
 /**
  * Dashboard tab
  */
 function view()
 {
     $module_status = Dispatcher::component('ModuleStatus');
     Util_Widget::setup();
     global $current_user;
     $config_master = $this->_config_master;
     $browsercache_enabled = $module_status->is_enabled('browsercache');
     $enabled = $module_status->plugin_is_enabled();
     $can_empty_memcache = $module_status->can_empty_memcache();
     $can_empty_opcode = $module_status->can_empty_opcode();
     $can_empty_file = $module_status->can_empty_file();
     $can_empty_varnish = $module_status->can_empty_varnish();
     $cdn_enabled = $module_status->is_enabled('cdn');
     $cdn_mirror_purge = Cdn_Util::can_purge_all($module_status->get_module_engine('cdn'));
     // Required for Update Media Query String button
     $browsercache_update_media_qs = $this->_config->get_boolean('browsercache.cssjs.replace') || $this->_config->get_boolean('browsercache.other.replace');
     include W3TC_INC_DIR . '/options/dashboard.php';
 }
 public static function w3tc_settings_cdn_boxarea_configuration()
 {
     $config = Dispatcher::config();
     $api_key = $config->get_string('cdn.rscf.key');
     $authorized = !empty($api_key);
     $cdn_host_http = '';
     $cdn_host_https = '';
     if ($authorized) {
         try {
             $cdn = Dispatcher::component('Cdn_Core')->get_cdn();
             $cdn_host_http = $cdn->get_host_http();
             $cdn_host_https = $cdn->get_host_https();
         } catch (\Exception $ex) {
             $cdn_host_http = 'failed to obtain';
             $cdn_host_https = 'failed to obtain';
         }
     }
     include W3TC_DIR . '/Cdn_RackSpaceCloudFiles_Page_View.php';
 }
 public function render_content()
 {
     $config = Dispatcher::config();
     $monitoring_type = $config->get_string(array('newrelic', 'monitoring_type'));
     if ($monitoring_type == 'browser') {
         return;
     }
     $nerser = Dispatcher::component('Extension_NewRelic_Service');
     $new_relic_configured = $config->get_string(array('newrelic', 'api_key')) && $config->get_string(array('newrelic', 'apm.application_name'));
     $verify_running = $nerser->verify_running();
     $application_settings = array();
     try {
         $application_settings = $nerser->get_application_settings();
     } catch (\Exception $ex) {
         $application_settings = array();
     }
     if ($view_metric = Util_Request::get_boolean('view_metric', false)) {
         $metric_names = $nerser->get_metric_names(Util_Request::get_string('regex', ''));
     }
     include W3TC_DIR . '/Extension_NewRelic_Page_View_Apm.php';
 }
 public static function w3tc_ajax_cdn_highwinds_widgetdata()
 {
     try {
         $core = Dispatcher::component('Cdn_Core');
         $cdn = $core->get_cdn();
         $analytics = $cdn->service_analytics_transfer();
         $sum_mbytes = 0;
         $sum_mbps = 0;
         $sum_rps = 0;
         $graph = array(array('Date', 'Requests'));
         $count = count($analytics);
         foreach ($analytics as $item) {
             $sum_mbytes += $item['xferUsedTotalMB'];
             $sum_mbps += $item['xferRateMeanMbps'];
             $sum_rps += $item['rpsMean'];
             $graph[] = array(gmdate('d M', $item['usageTime'] / 1000), $item['requestsCountTotal']);
         }
         $response = array('transferred_size' => Util_Ui::format_mbytes($sum_mbytes / $count), 'average_mbps' => sprintf('%.2f', $sum_mbps / $count), 'average_rps' => sprintf('%.2f', $sum_rps / $count), 'graph' => $graph);
         echo json_encode($response);
     } catch (\Exception $e) {
         echo json_encode(array('error' => $e->getMessage()));
     }
 }
 /**
  * Change action
  */
 function on_change()
 {
     $cacheFlush = Dispatcher::component('CacheFlush');
     $cacheFlush->flush_posts();
 }
 /**
  * Returns minified content
  *
  * @param array   $files
  * @param string  $type
  * @return array
  */
 function get_minified_content_for_files($files, $type)
 {
     $minify_filename = Minify_Core::urls_for_minification_to_minify_filename($files, $type);
     if (is_null($minify_filename)) {
         return null;
     }
     $minify = Dispatcher::component('Minify_MinifiedFileRequestHandler');
     $m = $minify->process($minify_filename, true);
     if (isset($m['content']['content'])) {
         $style = $m['content']['content'];
     } else {
         $style = '';
     }
     return "<style type=\"text/css\" media=\"all\">{$style}</style>\r\n";
 }
 public function _execute_delayed_operations_varnish($actions_made)
 {
     $o = Dispatcher::component('Varnish_Flush');
     $count_flushed = $o->flush_post_cleanup();
     if ($count_flushed > 0) {
         $actions_made[] = array('module' => 'varnish');
     }
     return $actions_made;
 }
 /**
  * Returns a list of the verification status of the the new relic
  * requirements. To be used on the compatibility page
  *
  * @param unknown $verified_list
  * @return array
  */
 function verify_compatibility($verified_list)
 {
     $nerser = Dispatcher::component('Extension_NewRelic_Service');
     $nr_verified = $nerser->verify_compatibility();
     $verified_list[] = '<strong>New Relic</strong>';
     foreach ($nr_verified as $criteria => $result) {
         $verified_list[] = sprintf("{$criteria}: %s", $result);
     }
     return $verified_list;
 }
 public function w3tc_usage_statistics_summary_from_history($summary, $history)
 {
     // memcached servers
     if ($this->_config->get_string('pgcache.engine') == 'memcached') {
         $summary['memcached_servers']['pgcache'] = array('servers' => $this->_config->get_array('pgcache.memcached.servers'), 'username' => $this->_config->get_boolean('pgcache.memcached.username'), 'password' => $this->_config->get_boolean('pgcache.memcached.password'), 'name' => __('Page Cache', 'w3-total-cache'));
     } elseif ($this->_config->get_string('pgcache.engine') == 'redis') {
         $summary['redis_servers']['pgcache'] = array('servers' => $this->_config->get_array('pgcache.redis.servers'), 'username' => $this->_config->get_boolean('pgcache.redis.username'), 'dbid' => $this->_config->get_boolean('pgcache.redis.dbid'), 'password' => $this->_config->get_boolean('pgcache.redis.password'), 'name' => __('Page Cache', 'w3-total-cache'));
     }
     // total size
     $g = Dispatcher::component('PgCache_ContentGrabber');
     $pagecache = array();
     $e = $this->_config->get_string('pgcache.engine');
     $pagecache['size_visible'] = $e == 'file_generic';
     $pagecache['requests_visible'] = $e != 'file_generic';
     if (isset($summary['period']['timestamp_end'])) {
         // need to return cache size
         if ($pagecache['size_visible']) {
             list($v, $should_count) = Util_UsageStatistics::get_or_init_size_transient('w3tc_ustats_pagecache_size', $summary);
             if ($should_count) {
                 $size = $g->get_cache_stats_size($summary['timeout_time']);
                 $v['size_used'] = Util_UsageStatistics::bytes_to_size2($size, 'bytes');
                 $v['items'] = Util_UsageStatistics::integer2($size, 'items');
                 set_transient('w3tc_ustats_pagecache_size', $v, 120);
             }
             if (isset($v['size_used'])) {
                 $pagecache['size_used'] = $v['size_used'];
                 $pagecache['items'] = $v['items'];
             }
         }
         // counters
         $requests_total = Util_UsageStatistics::sum($history, 'pagecache_requests_total');
         $requests_time_ms = Util_UsageStatistics::sum($history, 'pagecache_requests_time_10ms') * 10;
         $requests_hits = Util_UsageStatistics::sum($history, 'pagecache_requests_hits');
         $pagecache['requests_total'] = Util_UsageStatistics::integer($requests_total);
         $pagecache['request_time_ms'] = Util_UsageStatistics::value_per_period_seconds($requests_time_ms, $summary);
         $pagecache['requests_per_second'] = Util_UsageStatistics::value_per_period_seconds($requests_total, $summary);
         $pagecache['hit_rate'] = Util_UsageStatistics::percent($requests_hits, $requests_total);
     }
     $summary['pagecache'] = $pagecache;
     return $summary;
 }
示例#25
0
 /**
  * Flushes post cache
  *
  * @param string  $url
  * @return boolean
  */
 function w3tc_flush_url($url)
 {
     $pgcacheflush = Dispatcher::component('PgCache_Flush');
     $v = $pgcacheflush->flush_url($url);
     return $v;
 }
 public function w3tc_ajax_newrelic_widgetdata_dbtimes()
 {
     $response = array('content' => '<div class="w3tcnr_topfive_message">No data available</div>');
     try {
         $service = Dispatcher::component('Extension_NewRelic_Service');
         $can_use_metrics = $service->can_get_metrics();
         if ($can_use_metrics) {
             $metric_slow = $service->get_slowest_database();
             if (count($metric_slow) > 0) {
                 $s = '<table class="w3tcnr_slowest">';
                 foreach ($metric_slow as $transaction => $time) {
                     $s .= '<tr><td><span>' . $transaction . '</span></td><td>' . Util_Ui::secs_to_time($time) . '</td></tr>';
                 }
                 $s .= '</table>';
                 $response['content'] = $s;
             }
         }
     } catch (\Exception $e) {
         $response['content'] = '<div class="w3tcnr_topfive_message">Error occurred</div>';
     }
     echo json_encode($response);
 }
 public function w3tc_usage_statistics_of_request($storage)
 {
     $o = Dispatcher::component('Extension_FragmentCache_WpObjectCache');
     $o->w3tc_usage_statistics_of_request($storage);
 }
 /**
  * save&flush all action
  *
  * @return void
  */
 public function w3tc_default_save_and_flush()
 {
     $redirect_data = $this->_w3tc_save_options_process();
     $f = Dispatcher::component('CacheFlush');
     $f->flush_all();
     $state_note = Dispatcher::config_state_note();
     $state_note->set('common.show_note.flush_statics_needed', false);
     $state_note->set('common.show_note.flush_posts_needed', false);
     $state_note->set('common.show_note.plugins_updated', false);
     $state_note->set('minify.show_note.need_flush', false);
     $state_note->set('objectcache.show_note.flush_needed', false);
     Util_Admin::redirect_with_custom_messages2($redirect_data);
 }
 /**
  * Flush all caches except CloudFlare action
  *
  * @return void
  */
 public function w3tc_cloudflare_flush_all_except_cf()
 {
     Dispatcher::component('CacheFlush')->flush_all(array('cloudflare' => 'skip'));
     Util_Admin::redirect(array('w3tc_note' => 'flush_all'), true);
 }
示例#30
0
 /**
  *
  *
  * @return bool
  */
 public function can_empty_opcode()
 {
     $o = Dispatcher::component('SystemOpCache_Core');
     return $o->is_enabled();
 }