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;
 }
 public function w3tc_ajax_pagespeed_widgetdata()
 {
     if (Util_Request::get('cache') != 'no') {
         $response = get_transient('w3tc_pagespeed_widgetdata');
         $response = @json_decode($response, true);
         if (is_array($response) && isset($response['time']) && $response['time'] >= time() - 60) {
             echo json_encode($response);
             return;
         }
     }
     $config = Dispatcher::config();
     $key = $config->get_string('widget.pagespeed.key');
     $w3_pagespeed = new PageSpeed_Api($key);
     $r = $w3_pagespeed->analyze(get_home_url());
     if (!$r) {
         echo json_encode(array('error' => 'API call failed'));
         return;
     }
     $details = '<ul class="w3tc-widget-ps-rules">';
     foreach ($r['rules'] as $index => $rule) {
         if ($index >= 5) {
             break;
         }
         $details .= '<li class="w3tc-widget-ps-rule w3tc-widget-ps-priority-' . $rule['priority'] . '">' . '<div class="w3tc-widget-ps-icon"><div></div></div>' . '<p>' . $rule['name'] . '</p>' . '</li>';
     }
     $details .= '</ul>';
     $response = array('score' => $r['score'] . ' / 100', 'details' => $details, 'time' => time());
     set_transient('w3tc_pagespeed_widgetdata', json_encode($response), 60);
     echo json_encode($response);
 }
 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 action_payment_code()
 {
     $request_type = Util_Request::get_string('request_type');
     $request_id = date('YmdHi');
     $return_url = admin_url('admin.php?page=w3tc_support&request_type=' . $request_type . '&payment=1&request_id=' . $request_id);
     $cancel_url = admin_url('admin.php?page=w3tc_dashboard');
     $form_values = array("cmd" => "_xclick", "business" => W3TC_PAYPAL_BUSINESS, "item_name" => esc_attr(sprintf('%s: %s (#%s)', ucfirst(Util_Environment::host()), $this->_json_request_types[$request_type], $request_id)), "amount" => sprintf('%.2f', $this->_request_prices[$request_type]), "currency_code" => "USD", "no_shipping" => "1", "rm" => "2", "return" => esc_attr($return_url), "cancel_return" => esc_attr($cancel_url));
     echo json_encode($form_values);
     die;
 }
 /**
  *
  *
  * @param Config  $config
  * @return array
  */
 public function w3tc_notes($notes)
 {
     $config = Dispatcher::config();
     $state = Dispatcher::config_state();
     $page = Util_Request::get_string('page');
     if (!Cdn_Util::is_engine_mirror($config->get_string('cdn.engine'))) {
         /**
          * Show notification after theme change
          */
         if ($state->get_boolean('cdn.show_note_theme_changed')) {
             $notes['cdn_theme_changed'] = sprintf(__('The active theme has changed, please %s now to ensure proper operation. %s', 'w3-total-cache'), Util_Ui::button_popup(__('upload active theme files', 'w3-total-cache'), 'cdn_export', 'cdn_export_type=theme'), Util_Ui::button_hide_note2(array('w3tc_default_config_state' => 'y', 'key' => 'cdn.show_note_theme_changed', 'value' => 'false')));
         }
         /**
          * Show notification after WP upgrade
          */
         if ($state->get_boolean('cdn.show_note_wp_upgraded')) {
             $notes['cdn_wp_upgraded'] = sprintf(__('Upgraded WordPress? Please %s files now to ensure proper operation. %s', 'w3-total-cache'), Util_Ui::button_popup('upload wp-includes', 'cdn_export', 'cdn_export_type=includes'), Util_Ui::button_hide_note2(array('w3tc_default_config_state' => 'y', 'key' => 'cdn.show_note_wp_upgraded', 'value' => 'false')));
         }
         /**
          * Show notification after CDN enable
          */
         if ($state->get_boolean('cdn.show_note_cdn_upload') || $state->get_boolean('cdn.show_note_cdn_reupload')) {
             $cdn_upload_buttons = array();
             if ($config->get_boolean('cdn.includes.enable')) {
                 $cdn_upload_buttons[] = Util_Ui::button_popup('wp-includes', 'cdn_export', 'cdn_export_type=includes');
             }
             if ($config->get_boolean('cdn.theme.enable')) {
                 $cdn_upload_buttons[] = Util_Ui::button_popup('theme files', 'cdn_export', 'cdn_export_type=theme');
             }
             if ($config->get_boolean('minify.enabled') && $config->get_boolean('cdn.minify.enable') && !$config->get_boolean('minify.auto')) {
                 $cdn_upload_buttons[] = Util_Ui::button_popup('minify files', 'cdn_export', 'cdn_export_type=minify');
             }
             if ($config->get_boolean('cdn.custom.enable')) {
                 $cdn_upload_buttons[] = Util_Ui::button_popup('custom files', 'cdn_export', 'cdn_export_type=custom');
             }
             if ($state->get_boolean('cdn.show_note_cdn_upload')) {
                 $notes[] = sprintf(__('Make sure to %s and upload the %s, files to the <acronym title="Content Delivery Network">CDN</acronym> to ensure proper operation. %s', 'w3-total-cache'), Util_Ui::button_popup('export the media library', 'cdn_export_library'), implode(', ', $cdn_upload_buttons), Util_Ui::button_hide_note2(array('w3tc_default_config_state' => 'y', 'key' => 'cdn.show_note_cdn_upload', 'value' => 'false')));
             }
             if ($state->get_boolean('cdn.show_note_cdn_reupload')) {
                 $notes[] = sprintf(__('Settings that affect Browser Cache settings for files hosted by the CDN have been changed. To apply the new settings %s and %s. %s', 'w3-total-cache'), Util_Ui::button_popup(__('export the media library', 'w3-total-cache'), 'cdn_export_library'), implode(', ', $cdn_upload_buttons), Util_Ui::button_hide_note2(array('w3tc_default_config_state' => 'y', 'key' => 'cdn.show_note_cdn_reupload', 'value' => 'false')));
             }
         }
     }
     if (in_array($config->get_string('cdn.engine'), array('netdna', 'maxcdn')) && !$state->get_boolean('cdn.hide_note_maxcdn_whitelist_ip') && $state->get_integer('track.maxcdn_authorize') == 0 && $config->get_string('cdn.' . $config->get_string('cdn.engine') . '.authorization_key')) {
         $notes[] = sprintf(__('Make sure to whitelist your servers IPs. Follow the instructions on %s. The IP for this server is %s. %s', 'w3-total-cache'), '<a href="http://support.maxcdn.com/tutorials/how-to-whitelist-your-server-ip-to-use-the-api/">MaxCDN</a>', $_SERVER['SERVER_ADDR'], Util_Ui::button_hide_note2(array('w3tc_default_config_state' => 'y', 'key' => 'cdn.hide_note_maxcdn_whitelist_ip', 'value' => 'true')));
     }
     /**
      * Check CURL extension
      */
     if (!$state->get_boolean('cdn.hide_note_no_curl') && !function_exists('curl_init')) {
         $notes[] = sprintf(__('The <strong>CURL PHP</strong> extension is not available. Please install it to enable S3 or CloudFront functionality. %s', 'w3-total-cache'), Util_Ui::button_hide_note2(array('w3tc_default_config_state' => 'y', 'key' => 'cdn.hide_note_no_curl', 'value' => 'true')));
     }
     return $notes;
 }
 function action_widget_link_support()
 {
     $value = Util_Request::get_string('w3tc_common_support_us');
     $this->_config->set('common.support', $value);
     $this->_config->save();
     Generic_AdminLinks::link_update($this->_config);
     if ($value) {
         _e('Thank you for linking to us!', 'w3-total-cache');
     } else {
         _e('You are no longer linking to us. Please support us in other ways instead!', 'w3-total-cache');
     }
     die;
 }
 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());
 }
Exemple #8
0
 /**
  * Returns hide note button html
  *
  * @param string  $text
  * @param string  $note
  * @param string  $redirect
  * @param boolean $admin         if to use config admin
  * @param string  $page
  * @param string  $custom_method
  * @return string
  */
 public static function button_hide_note($text, $note, $redirect = '', $admin = false, $page = '', $custom_method = 'w3tc_default_hide_note')
 {
     if ($page == '') {
         $page = Util_Request::get_string('page', 'w3tc_dashboard');
     }
     $url = sprintf('admin.php?page=%s&%s&note=%s', $page, $custom_method, $note);
     if ($admin) {
         $url .= '&admin=1';
     }
     if ($redirect != '') {
         $url .= '&redirect=' . urlencode($redirect);
     }
     $url = wp_nonce_url($url, 'w3tc');
     return Util_Ui::button_link($text, $url, false, 'button', 'w3tc_hide_' . $custom_method);
 }
 function recommendations()
 {
     $themes = Util_Theme::get_themes_by_key();
     $current_theme = Util_Theme::get_current_theme_name();
     $current_theme_key = array_search($current_theme, $themes);
     $theme_key = Util_Request::get_string('theme_key', $current_theme_key);
     $theme_name = isset($themes[$theme_key]) ? $themes[$theme_key] : $current_theme;
     $templates = Util_Theme::get_theme_templates($theme_name);
     $recommendations = $this->get_theme_recommendations($theme_name);
     list($js_groups, $css_groups) = $recommendations;
     $minify_js_groups = $this->_config->get_array('minify.js.groups');
     $minify_css_groups = $this->_config->get_array('minify.css.groups');
     $checked_js = array();
     $checked_css = array();
     $locations_js = array();
     if (isset($minify_js_groups[$theme_key])) {
         foreach ((array) $minify_js_groups[$theme_key] as $template => $locations) {
             foreach ((array) $locations as $location => $config) {
                 if (isset($config['files'])) {
                     foreach ((array) $config['files'] as $file) {
                         if (!isset($js_groups[$template]) || !in_array($file, $js_groups[$template])) {
                             $js_groups[$template][] = $file;
                         }
                         $checked_js[$template][$file] = true;
                         $locations_js[$template][$file] = $location;
                     }
                 }
             }
         }
     }
     if (isset($minify_css_groups[$theme_key])) {
         foreach ((array) $minify_css_groups[$theme_key] as $template => $locations) {
             foreach ((array) $locations as $location => $config) {
                 if (isset($config['files'])) {
                     foreach ((array) $config['files'] as $file) {
                         if (!isset($css_groups[$template]) || !in_array($file, $css_groups[$template])) {
                             $css_groups[$template][] = $file;
                         }
                         $checked_css[$template][$file] = true;
                     }
                 }
             }
         }
     }
     include W3TC_INC_DIR . '/lightbox/minify_recommendations.php';
 }
 /**
  * Test minifier action
  *
  * @return void
  */
 function w3tc_test_minifier()
 {
     $engine = Util_Request::get_string('engine');
     $path_java = Util_Request::get_string('path_java');
     $path_jar = Util_Request::get_string('path_jar');
     $result = false;
     $error = '';
     if ($engine != 'googleccjs') {
         if (!$path_java) {
             $error = __('Empty JAVA executable path.', 'w3-total-cache');
         } elseif (!$path_jar) {
             $error = __('Empty JAR file path.', 'w3-total-cache');
         }
     }
     if (empty($error)) {
         switch ($engine) {
             case 'yuijs':
                 Minify_YUICompressor::$tempDir = Util_File::create_tmp_dir();
                 Minify_YUICompressor::$javaExecutable = $path_java;
                 Minify_YUICompressor::$jarFile = $path_jar;
                 $result = Minify_YUICompressor::testJs($error);
                 break;
             case 'yuicss':
                 Minify_YUICompressor::$tempDir = Util_File::create_tmp_dir();
                 Minify_YUICompressor::$javaExecutable = $path_java;
                 Minify_YUICompressor::$jarFile = $path_jar;
                 $result = Minify_YUICompressor::testCss($error);
                 break;
             case 'ccjs':
                 Minify_ClosureCompiler::$tempDir = Util_File::create_tmp_dir();
                 Minify_ClosureCompiler::$javaExecutable = $path_java;
                 Minify_ClosureCompiler::$jarFile = $path_jar;
                 $result = Minify_ClosureCompiler::test($error);
                 break;
             case 'googleccjs':
                 $result = Minify_JS_ClosureCompiler::test($error);
                 break;
             default:
                 $error = __('Invalid engine.', 'w3-total-cache');
                 break;
         }
     }
     $response = array('result' => $result, 'error' => $error);
     echo json_encode($response);
 }
 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;
 }
 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 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;
 }
 function action_verify_plugin_license_key()
 {
     $license = Util_Request::get_string('license_key', '');
     if ($license) {
         $status = edd_w3edge_w3tc_check_license($license, W3TC_VERSION);
         echo $status->license_status;
     } else {
         echo 'invalid';
     }
     exit;
 }
 /**
  * Handle minify error
  *
  * @param string  $error
  * @return void
  */
 function _handle_error($error)
 {
     $notification = $this->_config->get_string('minify.error.notification');
     if ($notification) {
         $file = Util_Request::get_string('file');
         $state = Dispatcher::config_state_master();
         if ($file) {
             $state->set('minify.error.file', $file);
         }
         if (stristr($notification, 'admin') !== false) {
             $state->set('minify.error.last', $error);
             $state->set('minify.show_note_minify_error', true);
         }
         if (stristr($notification, 'email') !== false) {
             $last = $state->get_integer('minify.error.notification.last');
             /**
              * Prevent email flood: send email every 5 min
              */
             if (time() - $last > 300) {
                 $state->set('minify.error.notification.last', time());
                 $this->_send_notification();
             }
         }
         $state->save();
     }
 }
 /**
  * Send CloudFlare API request
  *
  * @return void
  */
 function action_cloudflare_api_request()
 {
     $result = false;
     $response = null;
     $actions = array('dev_mode', 'sec_lvl', 'fpurge_ts');
     $email = Util_Request::get_string('email');
     $key = Util_Request::get_string('key');
     $zone = Util_Request::get_string('zone');
     $action = Util_Request::get_string('command');
     $value = Util_Request::get_string('value');
     $nonce = Util_Request::get_string('_wpnonce');
     if (!wp_verify_nonce($nonce, 'w3tc')) {
         $error = 'Access denied.';
     } elseif (!$email) {
         $error = 'Empty email.';
     } elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
         $error = 'Invalid email.';
     } elseif (!$key) {
         $error = 'Empty key.';
     } elseif (!$zone) {
         $error = 'Empty zone.';
     } elseif (strpos($zone, '.') === false) {
         $error = 'Invalid domain.';
     } elseif (!in_array($action, $actions)) {
         $error = 'Invalid action.';
     } else {
         $config = array('email' => $email, 'key' => $key, 'zone' => $zone);
         @($this->api = new Extension_CloudFlare_Api($config));
         @set_time_limit($this->_config->get_integer(array('cloudflare', 'timelimit.api_request')));
         $response = $this->api->api_request($action, $value);
         if ($response) {
             if ($response->result == 'success') {
                 $result = true;
                 $error = 'OK';
             } else {
                 $error = $response->msg;
             }
         } else {
             $error = 'Unable to make CloudFlare API request.';
         }
     }
     $return = array('result' => $result, 'error' => $error, 'response' => $response);
     echo json_encode($return);
     exit;
 }
Exemple #17
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();
 /**
  * Latest widget control
  *
  * @param integer $widget_id
  * @param array   $form_inputs
  * @return void
  */
 function widget_latest_control($widget_id, $form_inputs = array())
 {
     if ($_SERVER['REQUEST_METHOD'] == 'POST') {
         $this->_config->set('widget.latest.items', Util_Request::get_integer('w3tc_widget_latest_items', 3));
         $this->_config->save();
         delete_transient($this->_widget_latest_cache_key());
     }
     include W3TC_INC_DIR . '/widget/latest_control.php';
 }
 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;
 }
 public function w3tc_ajax_cdn_maxcdn_fsd_configure_zone()
 {
     $api_key = $_REQUEST['api_key'];
     $zone_id = Util_Request::get('zone_id', '');
     $zone = array('name' => Util_Request::get('name'), 'label' => Util_Request::get('name'), 'url' => Util_Request::get('url'), 'use_stale' => 1, 'queries' => 1, 'compress' => 1, 'backend_compress' => 1, 'dns_check' => Util_Request::get('dns_check'), 'ip' => Util_Request::get('ip'));
     $api = \NetDNA::create($api_key);
     try {
         if (empty($zone_id)) {
             $response = $api->create_pull_zone($zone);
             $zone_id = $response['id'];
         } else {
             $response = $api->update_pull_zone($zone_id, $zone);
         }
         $custom_domains = $api->get_custom_domains($zone_id);
         $custom_domain = Util_Request::get('custom_domain');
         $added = false;
         foreach ($custom_domains as $d) {
             if ($d['custom_domain'] == $custom_domain) {
                 $added = true;
                 break;
             }
         }
         if (!$added) {
             $api->create_custom_domain($zone_id, $custom_domain);
         }
     } catch (\Exception $ex) {
         $this->render_intro(array('api_key' => $api_key, 'error_message' => 'Failed to configure custom domain ' . $custom_domain . ': ' . $ex->getMessage()));
         exit;
     }
     $zone_domain = $response['tmp_url'];
     $c = Dispatcher::config();
     $c->set('cdn.maxcdn_fsd.api_key', $api_key);
     $c->set('cdn.maxcdn_fsd.zone_id', $zone_id);
     $c->set('cdn.maxcdn_fsd.zone_domain', $zone_domain);
     $c->save();
     $details = array('name' => $zone['name'], 'home_domain' => Util_Environment::home_url_host(), 'dns_cname_target' => $zone_domain);
     include W3TC_DIR . '/Cdn_MaxCdnFsd_Popup_View_Success.php';
     exit;
 }
 /**
  * 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_cloudfront_fsd_configure_distribution()
 {
     $access_key = $_REQUEST['access_key'];
     $secret_key = $_REQUEST['secret_key'];
     $distribution_id = Util_Request::get('distribution_id', '');
     $origin_id = rand();
     $distribution = array('Comment' => Util_Request::get('distribution_comment'), 'Origins' => array('Quantity' => 1, 'Items' => array('Origin' => array('Id' => $origin_id, 'DomainName' => Util_Request::get('origin'), 'OriginPath' => '', 'CustomOriginConfig' => array('HTTPPort' => 80, 'HTTPSPort' => 443, 'OriginProtocolPolicy' => 'match-viewer')))), 'Aliases' => array('Quantity' => 1, 'Items' => array('CNAME' => Util_Request::get('alias'))), 'DefaultCacheBehavior' => array('TargetOriginId' => $origin_id, 'ForwardedValues' => array('QueryString' => 'true', 'Cookies' => array('Forward' => 'all'), 'Headers' => array('Quantity' => 1, 'Items' => array('Name' => 'Host'))), 'AllowedMethods' => array('Quantity' => 7, 'Items' => array('Method' => array('GET', 'HEAD', 'OPTIONS', 'PUT', 'POST', 'PATCH', 'DELETE')), 'CachedMethods' => array('Quantity' => 2, 'Items' => array('Method' => array('GET', 'HEAD')))), 'MinTTL' => 0));
     try {
         $api = new Cdn_CloudFrontFsd_Api($access_key, $secret_key);
         if (empty($distribution_id)) {
             $distribution['DefaultCacheBehavior']['TrustedSigners'] = array('Enabled' => 'false', 'Quantity' => 0);
             $distribution['DefaultCacheBehavior']['ViewerProtocolPolicy'] = 'allow-all';
             $response = $api->distribution_create($distribution);
             $distribution_id = $response['Id'];
         } else {
             $response = $api->distribution_update($distribution_id, $distribution);
         }
     } catch (\Exception $ex) {
         $this->render_intro(array('error_message' => 'Failed to configure distribution: ' . $ex->getMessage()));
         exit;
     }
     $distribution_domain = $response['DomainName'];
     $c = Dispatcher::config();
     $c->set('cdn.cloudfront_fsd.access_key', $access_key);
     $c->set('cdn.cloudfront_fsd.secret_key', $secret_key);
     $c->set('cdn.cloudfront_fsd.distribution_id', $distribution_id);
     $c->set('cdn.cloudfront_fsd.distribution_domain', $distribution_domain);
     $c->save();
     $details = array('name' => $distribution['Comment'], 'home_domain' => Util_Environment::home_url_host(), 'dns_cname_target' => $distribution_domain);
     include W3TC_DIR . '/Cdn_CloudFrontFsd_Popup_View_Success.php';
     exit;
 }
Exemple #23
0
 /**
  * Returns current WordPress page
  *
  * @return string
  */
 public static function get_current_wp_page()
 {
     return Util_Request::get_string('page');
 }
 /**
  * Reads config from request
  *
  * @param Config  $config
  */
 function read_request($config)
 {
     $request = Util_Request::get_request();
     include W3TC_DIR . '/ConfigKeys.php';
     // define $keys
     foreach ($request as $request_key => $request_value) {
         if (is_array($request_value)) {
             array_map('stripslashes_deep', $request_value);
         } else {
             $request_value = stripslashes($request_value);
         }
         if (strpos($request_key, 'memcached_servers')) {
             $request_value = explode(',', $request_value);
         }
         $key = Util_Ui::config_key_from_http_name($request_key);
         if (is_array($key)) {
             $config->set($key, $request_value);
         } elseif (array_key_exists($key, $keys)) {
             $descriptor = $keys[$key];
             if (isset($descriptor['type']) && $descriptor['type'] == 'array') {
                 if (is_array($request_value)) {
                     $request_value = implode("\n", $request_value);
                 }
                 $request_value = explode("\n", str_replace("\r\n", "\n", $request_value));
             }
             $config->set($key, $request_value);
         }
     }
 }
Exemple #25
0
 /**
  * Checks request URI
  *
  * @return boolean
  */
 function _check_request_uri()
 {
     $reject_uri = $this->_config->get_array('cdn.reject.uri');
     $reject_uri = array_map(array('\\W3TC\\Util_Environment', 'parse_path'), $reject_uri);
     foreach ($reject_uri as $expr) {
         $expr = trim($expr);
         if ($expr != '' && preg_match('~' . $expr . '~i', $_SERVER['REQUEST_URI'])) {
             return false;
         }
     }
     if (Util_Request::get_string('wp_customize')) {
         return false;
     }
     return true;
 }
 /**
  * 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'));
 }
 /**
  * Checks request URI
  *
  * @return boolean
  */
 function check_request_uri()
 {
     $auto_reject_uri = array('wp-login', 'wp-register');
     foreach ($auto_reject_uri as $uri) {
         if (strstr($_SERVER['REQUEST_URI'], $uri) !== false) {
             return false;
         }
     }
     $reject_uri = $this->_config->get_array('minify.reject.uri');
     $reject_uri = array_map(array('\\W3TC\\Util_Environment', 'parse_path'), $reject_uri);
     foreach ($reject_uri as $expr) {
         $expr = trim($expr);
         if ($expr != '' && preg_match('~' . $expr . '~i', $_SERVER['REQUEST_URI'])) {
             return false;
         }
     }
     if (Util_Request::get_string('wp_customize')) {
         return false;
     }
     return true;
 }
 /**
  * Stylesheet filter
  *
  * @param unknown $stylesheet
  * @return string
  */
 function stylesheet_preview($stylesheet)
 {
     $theme_name = Util_Request::get_string('w3tc_theme');
     $theme = Util_Theme::get($theme_name);
     if ($theme) {
         return $theme['Stylesheet'];
     }
     return $stylesheet;
 }
 /**
  * Alters the active state of an extension
  */
 public function change_extension_status()
 {
     $action = Util_Request::get_string('action');
     if (in_array($action, array('activate', 'deactivate'))) {
         $extension = Util_Request::get_string('extension');
         if ('activate' == $action) {
             Extensions_Util::activate_extension($extension, $this->_config);
             wp_redirect(Util_Ui::admin_url(sprintf('admin.php?page=w3tc_extensions&activated=%s', $extension)));
         } elseif ('deactivate' == $action) {
             Extensions_Util::deactivate_extension($extension, $this->_config);
             wp_redirect(Util_Ui::admin_url(sprintf('admin.php?page=w3tc_extensions&deactivated=%s', $extension)));
         }
     }
 }
 /**
  * Configures the plugin to use the zone id provided in request
  */
 function w3tc_cdn_use_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);
     $zone_id = Util_Request::get_integer('zone_id');
     $keys = explode('+', $authorization_key);
     list($alias, $consumer_key, $consumer_secret) = $keys;
     $api = new \NetDNA($alias, $consumer_key, $consumer_secret);
     $this->validate_account($api);
     try {
         $pull_zone = $api->get_zone($zone_id);
         if ($pull_zone) {
             $custom_domains = $api->get_custom_domains($pull_zone['id']);
             if (sizeof($custom_domains) > 0) {
                 $result = array('result' => 'valid', 'cnames' => array($custom_domains));
                 $test = true;
                 foreach ($custom_domains as $url) {
                     $test = $test && $this->test_cdn_url($url);
                 }
                 if ($test) {
                     $this->_config->set("cdn.enabled", true);
                 }
             } else {
                 $name = $pull_zone['name'];
                 $result = array('result' => 'valid', 'cnames' => array("{$name}.{$alias}.netdna-cdn.com"));
                 $test = $this->test_cdn_url("{$name}.{$alias}.netdna-cdn.com");
                 if ($test) {
                     $this->_config->set("cdn.enabled", true);
                 }
             }
             $this->_config->set("cdn.enabled", true);
             $this->_config->set("cdn.{$cdn_engine}.zone_id", $pull_zone['id']);
             $this->_config->set("cdn.{$cdn_engine}.domain", $result['cnames']);
             $this->_config->save();
         } else {
             $result = array('result' => 'error', 'message' => sprintf(__('The provided zone id was not connected to the provided authorization key.', 'w3-total-cache')));
         }
     } catch (\Exception $ex) {
         $result = array('result' => 'error', 'message' => $ex->getMessage());
     }
     echo json_encode($result);
     exit;
 }