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';
 }
 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']);
 }
Ejemplo n.º 3
0
 /**
  * CDN import library process
  *
  * @return void
  */
 function w3tc_cdn_import_library_process()
 {
     $w3_plugin_cdn = Dispatcher::component('Cdn_Core_Admin');
     $limit = Util_Request::get_integer('limit');
     $offset = Util_Request::get_integer('offset');
     $import_external = Util_Request::get_boolean('cdn_import_external');
     $config_state = Dispatcher::config_state();
     $config_state->set('cdn.import.external', $import_external);
     $config_state->save();
     $count = null;
     $total = null;
     $results = array();
     @$w3_plugin_cdn->import_library($limit, $offset, $count, $total, $results);
     $response = array('limit' => $limit, 'offset' => $offset, 'count' => $count, 'total' => $total, 'results' => $results);
     echo json_encode($response);
 }
Ejemplo n.º 4
0
 /**
  * Init action
  *
  * @return void
  */
 function init()
 {
     // Load plugin text domain
     load_plugin_textdomain(W3TC_TEXT_DOMAIN, null, plugin_basename(W3TC_DIR) . '/languages/');
     if (is_multisite() && !is_network_admin()) {
         global $w3_current_blog_id, $current_blog;
         if ($w3_current_blog_id != $current_blog->blog_id && !isset($GLOBALS['w3tc_blogmap_register_new_item'])) {
             $url = Util_Environment::host_port() . $_SERVER['REQUEST_URI'];
             $pos = strpos($url, '?');
             if ($pos !== false) {
                 $url = substr($url, 0, $pos);
             }
             $GLOBALS['w3tc_blogmap_register_new_item'] = $url;
         }
     }
     if (isset($GLOBALS['w3tc_blogmap_register_new_item'])) {
         $do_redirect = false;
         // true value is a sign to just generate config cache
         if ($GLOBALS['w3tc_blogmap_register_new_item'] != 'cache_options') {
             if (Util_Environment::is_wpmu_subdomain()) {
                 $blog_home_url = $GLOBALS['w3tc_blogmap_register_new_item'];
             } else {
                 $home_url = rtrim(get_home_url(), '/');
                 if (substr($home_url, 0, 7) == 'http://') {
                     $home_url = substr($home_url, 7);
                 } else {
                     if (substr($home_url, 0, 8) == 'https://') {
                         $home_url = substr($home_url, 8);
                     }
                 }
                 if (substr($GLOBALS['w3tc_blogmap_register_new_item'], 0, strlen($home_url)) == $home_url) {
                     $blog_home_url = $home_url;
                 } else {
                     $blog_home_url = $GLOBALS['w3tc_blogmap_register_new_item'];
                 }
             }
             $do_redirect = Util_WpmuBlogmap::register_new_item($blog_home_url, $this->_config);
             // reset cache of blog_id
             global $w3_current_blog_id;
             $w3_current_blog_id = null;
             // change config to actual blog, it was master before
             $this->_config = new Config();
             // fix environment, potentially it's first request to a specific blog
             $environment = Dispatcher::component('Root_Environment');
             $environment->fix_on_event($this->_config, 'first_frontend', $this->_config);
         }
         // need to repeat request processing, since we was not able to realize
         // blog_id before so we are running with master config now.
         // redirect to the same url causes "redirect loop" error in browser,
         // so need to redirect to something a bit different
         if ($do_redirect) {
             if (strpos($_SERVER['REQUEST_URI'], '?') === false) {
                 Util_Environment::redirect_temp($_SERVER['REQUEST_URI'] . '?repeat=w3tc');
             } else {
                 if (strpos($_SERVER['REQUEST_URI'], 'repeat=w3tc') === false) {
                     Util_Environment::redirect_temp($_SERVER['REQUEST_URI'] . '&repeat=w3tc');
                 }
             }
         }
     }
     /**
      * Check for rewrite test request
      */
     $rewrite_test = Util_Request::get_boolean('w3tc_rewrite_test');
     if ($rewrite_test) {
         echo 'OK';
         exit;
     }
     $admin_bar = false;
     if (function_exists('is_admin_bar_showing')) {
         $admin_bar = is_admin_bar_showing();
     }
     if ($admin_bar) {
         add_action('wp_print_scripts', array($this, 'popup_script'));
     }
     // dont add system stuff to search results
     if (isset($_GET['repeat']) && $_GET['repeat'] == 'w3tc' || Util_Environment::is_preview_mode()) {
         header('X-Robots-Tag: noindex');
     }
 }
Ejemplo n.º 5
0
<?php

namespace W3TC;

if (!defined('W3TC')) {
    die;
}
include W3TC_INC_DIR . '/options/common/header.php';
if (Util_Request::get_boolean('payment')) {
    ?>
    <div class="error">
    <p>To complete your support request fill out the form below!</p>
    </div>
<?php 
} else {
    ?>
<p>
    <?php 
    _e('Request premium services, suggest a feature or submit a bug using the form below:', 'w3-total-cache');
    ?>
</p>
<?php 
}
?>
<div id="support_container">
    <?php 
if (!$request_type || !isset($this->_request_types[$request_type])) {
    $this->w3tc_support_select();
} else {
    if (isset($this->_request_prices[$request_type]) && !$payment) {
        $this->w3tc_support_payment();
 /**
  * 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'));
 }