예제 #1
0
 /**
  * New Relic tab
  */
 function view()
 {
     $applications = array();
     $dashboard = '';
     /**
      * @var $nerser W3_NewRelicService
      */
     $nerser = w3_instance('W3_NewRelicService');
     $new_relic_configured = $this->_config->get_string('newrelic.account_id') && $this->_config->get_string('newrelic.api_key') && $this->_config->get_string('newrelic.application_id');
     $view_application = $this->_config->get_string('newrelic.application_id');
     $new_relic_enabled = $this->_config->get_boolean('newrelic.enabled');
     $verify_running = $nerser->verify_running();
     $application_settings = array();
     if (!is_array($verify_running)) {
         try {
             $application_settings = $nerser->get_application_settings();
         } catch (Exception $ex) {
             $application_settings = array();
         }
     }
     if ($view_metric = W3_Request::get_boolean('view_metric', false)) {
         $metric_names = $nerser->get_metric_names(W3_Request::get_string('regex', ''));
     }
     include W3TC_INC_DIR . '/options/new_relic.php';
 }
 /**
  * Support tab
  *
  * @return void
  */
 function view()
 {
     w3_require_once(W3TC_LIB_W3_DIR . '/Request.php');
     $request_type = W3_Request::get_string('request_type');
     $payment = W3_Request::get_boolean('payment');
     include W3TC_INC_DIR . '/options/support.php';
 }
예제 #3
0
function w3tc_cancel_button($note, $classes = '', $custom_method = 'w3tc_default_hide_note')
{
    w3_require_once(W3TC_LIB_W3_DIR . '/Request.php');
    $page = W3_Request::get_string('page', 'w3tc_dashboard');
    $url = sprintf('admin.php?page=%s&%s&note=%s', $page, $custom_method, $note);
    $url = wp_nonce_url($url, 'w3tc');
    return w3_button_link(__('Cancel'), $url, false, $classes);
}
예제 #4
0
 /**
  * @throws Exception
  */
 function action_extensions_activate()
 {
     w3_require_once(W3TC_LIB_W3_DIR . '/Request.php');
     $extension = W3_Request::get_string('w3tc_extensions_activate');
     if ($extension) {
         w3tc_activate_extension($extension, $this->_config);
     }
     w3_admin_redirect(array('w3tc_note' => 'extension_activated'));
 }
예제 #5
0
 /**
  * Latest widget control
  *
  * @param integer $widget_id
  * @param array $form_inputs
  * @return void
  */
 function widget_pagespeed_control($widget_id, $form_inputs = array())
 {
     if ($_SERVER['REQUEST_METHOD'] == 'POST') {
         w3_require_once(W3TC_LIB_W3_DIR . '/Request.php');
         $this->_config->set('widget.pagespeed.key', W3_Request::get_string('w3tc_widget_pagespeed_key'));
         $this->_config->save();
     }
     include W3TC_INC_DIR . '/widget/pagespeed_control.php';
 }
예제 #6
0
 /**
  * New Relic tab
  */
 function action_new_relic_view_new_relic_app()
 {
     $nerser = w3_instance('W3_NewRelicService');
     $view_application = W3_Request::get_integer('view_application', 0);
     $dashboard = '';
     if ($view_application) {
         $dashboard = $nerser->get_dashboard($view_application);
     }
     echo $dashboard;
 }
예제 #7
0
 /**
  * Returns array value
  *
  * @param string $key
  * @param array $default
  * @return array
  */
 function get_array($key, $default = array())
 {
     $value = W3_Request::get($key);
     if (is_array($value)) {
         return $value;
     } elseif ($value != '') {
         return preg_split("/[\r\n,;]+/", trim($value));
     }
     return $default;
 }
예제 #8
0
 function action_payment_code()
 {
     w3_require_once(W3TC_LIB_W3_DIR . '/Request.php');
     $request_type = W3_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(w3_get_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;
 }
예제 #9
0
 function action_widget_link_support()
 {
     w3_require_once(W3TC_LIB_W3_DIR . '/Request.php');
     $value = W3_Request::get_string('w3tc_common_support_us');
     $this->_config->set('common.support', $value);
     $this->_config->save();
     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;
 }
예제 #10
0
 /**
  * @param W3_Config $config
  * @param W3_ConfigAdmin|null $config_admin
  * @return array
  */
 function notifications($config, $config_admin)
 {
     w3_require_once(W3TC_LIB_W3_DIR . '/Request.php');
     $page = W3_Request::get_string('page');
     $notes = array();
     if (!w3_is_cdn_mirror($config->get_string('cdn.engine'))) {
         /**
          * Show notification after theme change
          */
         if ($config->get_boolean('notes.theme_changed')) {
             $notes[] = sprintf(__('The active theme has changed, please %s now to ensure proper operation. %s', 'w3-total-cache'), w3_button_popup(__('upload active theme files', 'w3-total-cache'), 'cdn_export', 'cdn_export_type=theme'), w3_button_hide_note(__('Hide this message', 'w3-total-cache'), 'theme_changed'));
         }
         /**
          * Show notification after WP upgrade
          */
         if ($config->get_boolean('notes.wp_upgraded')) {
             $notes[] = sprintf(__('Upgraded WordPress? Please %s files now to ensure proper operation. %s', 'w3-total-cache'), w3_button_popup('upload wp-includes', 'cdn_export', 'cdn_export_type=includes'), w3_button_hide_note(__('Hide this message', 'w3-total-cache'), 'wp_upgraded'));
         }
         /**
          * Show notification after CDN enable
          */
         if ($config->get_boolean('notes.cdn_upload') || $config->get_boolean('notes.cdn_reupload')) {
             $cdn_upload_buttons = array();
             if ($config->get_boolean('cdn.includes.enable')) {
                 $cdn_upload_buttons[] = w3_button_popup('wp-includes', 'cdn_export', 'cdn_export_type=includes');
             }
             if ($config->get_boolean('cdn.theme.enable')) {
                 $cdn_upload_buttons[] = w3_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[] = w3_button_popup('minify files', 'cdn_export', 'cdn_export_type=minify');
             }
             if ($config->get_boolean('cdn.custom.enable')) {
                 $cdn_upload_buttons[] = w3_button_popup('custom files', 'cdn_export', 'cdn_export_type=custom');
             }
             if ($config->get_boolean('notes.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'), w3_button_popup('export the media library', 'cdn_export_library'), implode(', ', $cdn_upload_buttons), w3_button_hide_note('Hide this message', 'cdn_upload'));
             }
             if ($config->get_boolean('notes.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'), w3_button_popup(__('export the media library', 'w3-total-cache'), 'cdn_export_library'), implode(', ', $cdn_upload_buttons), w3_button_hide_note(__('Hide this message', 'w3-total-cache'), 'cdn_reupload'));
             }
         }
     }
     if (in_array($config->get_string('cdn.engine'), array('netdna', 'maxcdn')) && $config_admin->get_boolean('notes.maxcdn_whitelist_ip') && $config_admin->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'], w3_button_hide_note('Hide this message', 'maxcdn_whitelist_ip', '', true));
     }
     return $notes;
 }
예제 #11
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
 * @return string
 */
function w3_button_hide_note($text, $note, $redirect = '', $admin = false, $page = '')
{
    if ($page == '') {
        w3_require_once(W3TC_LIB_W3_DIR . '/Request.php');
        $page = W3_Request::get_string('page', 'w3tc_dashboard');
    }
    $url = sprintf('admin.php?page=%s&w3tc_default_hide_note&note=%s', $page, $note);
    if ($admin) {
        $url .= '&admin=1';
    }
    if ($redirect != '') {
        $url .= '&redirect=' . urlencode($redirect);
    }
    $url = wp_nonce_url($url, 'w3tc');
    return w3_button_link($text, $url);
}
예제 #12
0
 function recommendations()
 {
     $themes = w3_get_themes();
     $current_theme = w3tc_get_current_theme_name();
     $current_theme_key = array_search($current_theme, $themes);
     w3_require_once(W3TC_LIB_W3_DIR . '/Request.php');
     $theme_key = W3_Request::get_string('theme_key', $current_theme_key);
     $theme_name = isset($themes[$theme_key]) ? $themes[$theme_key] : $current_theme;
     $templates = w3_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';
 }
예제 #13
0
 /**
  * Send CloudFlare API request
  *
  * @return void
  */
 function action_cloudflare_api_request()
 {
     $result = false;
     $response = null;
     $actions = array('devmode', 'sec_lvl', 'fpurge_ts');
     w3_require_once(W3TC_LIB_W3_DIR . '/Request.php');
     $email = W3_Request::get_string('email');
     $key = W3_Request::get_string('key');
     $zone = W3_Request::get_string('zone');
     $action = W3_Request::get_string('command');
     $value = W3_Request::get_string('value');
     $nonce = W3_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);
         w3_require_once(W3TC_LIB_W3_DIR . '/CloudFlare.php');
         @($w3_cloudflare = new W3_CloudFlare($config));
         @set_time_limit($this->_config->get_integer('timelimit.cloudflare_api_request'));
         $response = $w3_cloudflare->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;
 }
예제 #14
0
 /**
  * @throws Exception
  */
 function action_aws_sns_subscribe()
 {
     w3_require_once(W3TC_LIB_W3_DIR . '/Request.php');
     $topic_arn = W3_Request::get_string('cluster_messagebus_sns_topic_arn_subscribe');
     /**
      * @var W3_Enterprise_SnsClient $sns_client
      */
     $sns_client = w3_instance('W3_Enterprise_SnsClient');
     $sns_client->subscribe(plugins_url('pub/sns.php', W3TC_FILE), $topic_arn);
     try {
         $this->_config->set('cluster.messagebus.sns.topic_arn', $topic_arn);
         $this->_config->save();
     } catch (Exception $ex) {
         throw new Exception('<strong>Can\'t change configuration</strong>: ' . $ex->getMessage());
     }
     w3_admin_redirect(array('w3tc_note' => 'sns_subscribed'));
 }
예제 #15
0
 function change_filename_length()
 {
     try {
         w3_require_once(W3TC_LIB_W3_DIR . '/Request.php');
         $new = W3_Request::get_integer('maxlength');
         $this->_config->set('minify.auto.filename_length', $new);
         set_transient('w3tc_minify_tested_filename_length', true, 3600 * 24);
         $this->_config->save();
         w3_require_once(W3TC_LIB_MINIFY_DIR . '/Minify/Cache/File.php');
         $cache = new Minify_Cache_File(w3_cache_blog_dir('minify'), array('.htaccess', 'index.php', '*.old'), $this->_config->get_boolean('minify.file.locking'), $this->_config->get_integer('timelimit.cache_flush'), w3_get_blog_id() == 0 ? W3TC_CACHE_MINIFY_DIR : null);
         $cache->flush();
         echo 1;
     } catch (Exception $ex) {
         echo $ex->getMessage();
     }
     exit;
 }
예제 #16
0
/**
 * Redirects when in WP Admin
 * @param array $params
 * @param bool $check_referrer
 * @param string $page
 */
function w3_admin_redirect($params = array(), $check_referrer = false, $page = '')
{
    w3_require_once(W3TC_LIB_W3_DIR . '/Request.php');
    $url = W3_Request::get_string('redirect');
    $page_url = W3_Request::get_string('page');
    if ($url == '') {
        if ($check_referrer && !empty($_SERVER['HTTP_REFERER'])) {
            $url = $_SERVER['HTTP_REFERER'];
        } else {
            $url = 'admin.php';
            if (empty($page)) {
                $page = $page_url;
            }
            $params = array_merge(array('page' => $page), $params);
        }
    }
    w3_redirect($url, $params);
}
예제 #17
0
 /**
  * @param W3_Config $config
  * @return array
  */
 function notifications($config)
 {
     w3_require_once(W3TC_LIB_W3_DIR . '/Request.php');
     $page = W3_Request::get_string('page');
     $notes = array();
     /**
      * Show notification after theme change
      */
     if ($config->get_boolean('notes.theme_changed')) {
         $notes[] = sprintf(__('The active theme has changed, please %s now to ensure proper operation. %s', 'w3-total-cache'), w3_button_popup(__('upload active theme files', 'w3-total-cache'), 'cdn_export', 'cdn_export_type=theme'), w3_button_hide_note(__('Hide this message', 'w3-total-cache'), 'theme_changed'));
     }
     /**
      * Show notification after WP upgrade
      */
     if ($config->get_boolean('notes.wp_upgraded')) {
         $notes[] = sprintf(__('Upgraded WordPress? Please %s files now to ensure proper operation. %s', 'w3-total-cache'), w3_button_popup('upload wp-includes', 'cdn_export', 'cdn_export_type=includes'), w3_button_hide_note(__('Hide this message', 'w3-total-cache'), 'wp_upgraded'));
     }
     /**
      * Show notification after CDN enable
      */
     if ($config->get_boolean('notes.cdn_upload') || $config->get_boolean('notes.cdn_reupload')) {
         $cdn_upload_buttons = array();
         if ($config->get_boolean('cdn.includes.enable')) {
             $cdn_upload_buttons[] = w3_button_popup('wp-includes', 'cdn_export', 'cdn_export_type=includes');
         }
         if ($config->get_boolean('cdn.theme.enable')) {
             $cdn_upload_buttons[] = w3_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[] = w3_button_popup('minify files', 'cdn_export', 'cdn_export_type=minify');
         }
         if ($config->get_boolean('cdn.custom.enable')) {
             $cdn_upload_buttons[] = w3_button_popup('custom files', 'cdn_export', 'cdn_export_type=custom');
         }
         if ($config->get_boolean('notes.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'), w3_button_popup('export the media library', 'cdn_export_library'), implode(', ', $cdn_upload_buttons), w3_button_hide_note('Hide this message', 'cdn_upload'));
         }
         if ($config->get_boolean('notes.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'), w3_button_popup(__('export the media library', 'w3-total-cache'), 'cdn_export_library'), implode(', ', $cdn_upload_buttons), w3_button_hide_note(__('Hide this message', 'w3-total-cache'), 'cdn_reupload'));
         }
     }
     return $notes;
 }
 /**
  * Retrieves applications. Used in AJAX requests.
  * Requires request param api_key with the API key and account_id with the Account id.
  */
 function get_newrelic_applications()
 {
     w3_require_once(W3TC_LIB_W3_DIR . '/NewRelicService.php');
     $api_key = W3_Request::get_string('api_key');
     $account_id = W3_Request::get_string('account_id');
     if ($api_key == '0') {
         $config_master = new W3_Config(true);
         $api_key = $config_master->get_string('newrelic.api_key');
     }
     $nerser = new W3_NewRelicService($api_key);
     $newrelic_applications = array();
     try {
         if (empty($account_id) || $account_id == '') {
             $account_id = $nerser->get_account_id();
         }
         $newrelic_applications = $nerser->get_applications($account_id);
     } catch (Exception $ex) {
     }
     echo json_encode($newrelic_applications);
     die;
 }
예제 #19
0
 /**
  * Returns the API credentials for the CDN.
  * Exists application and prints message on WP_Error.
  *
  * @return array
  */
 public function get_api_keys()
 {
     $token = W3_Request::get_string('token');
     $token_secret = W3_Request::get_string('token_secret');
     $consumer = new OAuthConsumer($this->key, $this->secret, NULL);
     $auth_token = new OAuthConsumer($token, $token_secret);
     $access_token_req = new OAuthRequest('GET', $this->access_token_url);
     $access_token_req = $access_token_req->from_consumer_and_token($consumer, $auth_token, 'GET', $this->access_token);
     $access_token_req->sign_request(new OAuthSignatureMethod_HMAC_SHA1(), $consumer, $auth_token);
     $after_access_request = wp_remote_get($access_token_req->to_url());
     parse_str($after_access_request['body'], $access_tokens);
     $access_token = new OAuthConsumer($access_tokens['oauth_token'], $access_tokens['oauth_token_secret']);
     $api_request = $access_token_req->from_consumer_and_token($consumer, $access_token, 'GET', $this->create_api_user_url, array('user_id' => $access_tokens['user_id']));
     $api_request->sign_request(new OAuthSignatureMethod_HMAC_SHA1(), $consumer, $access_token);
     $page = wp_remote_get($api_request->to_url());
     if (is_wp_error($page)) {
         $this->handle_error($page);
     }
     //Get API ID and API key
     parse_str($page['body'], $credentials);
     return $credentials;
 }
예제 #20
0
 /**
  * Admin notices action
  *
  * @return void
  */
 function admin_notices()
 {
     w3_require_once(W3TC_INC_FUNCTIONS_DIR . '/admin_ui.php');
     w3_require_once(W3TC_INC_FUNCTIONS_DIR . '/admin.php');
     $cookie_domain = w3_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'), w3_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'), w3_button_link('enable', 'options-permalink.php')), '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'), 'pgcache_purge_page' => __('Unable to purge page.', '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), 'cloudflare_api_request' => __('Unable to make CloudFlare API request.', '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_all_except_cf' => __('All caches except CloudFlare 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_apc_system' => __('APC system cache 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'), 'pgcache_purge_page' => __('Page 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'));
     $errors = array();
     $notes = array();
     $environment_error_present = false;
     // 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)
     $message_id = W3_Request::get_string('w3tc_message');
     if ($message_id) {
         $v = get_transient('w3tc_message.' . $message_id);
         set_transient('w3tc_message.' . $message_id, null);
         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' || substr(W3_Request::get_string('page'), 0, 5) == 'w3tc_') {
             $environment = w3_instance('W3_AdminEnvironment');
             $environment->fix_in_wpadmin($this->_config);
             if (isset($_REQUEST['upgrade'])) {
                 $notes[] = __('Required files and directories have been automatically created', 'w3-total-cache');
             }
         }
     } catch (SelfTestExceptions $exs) {
         $r = w3_parse_selftest_exceptions($exs);
         foreach ($r['before_errors'] as $e) {
             $errors[] = $e;
         }
         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>' . w3_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>' . w3_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[] = $error;
         }
         foreach ($r['later_errors'] as $e) {
             $errors[] = $e;
         }
     }
     /**
      * CloudFlare notifications
      * @var $w3_cloudflare W3_CloudFlare
      */
     $w3_cloudflare = w3_instance('W3_CloudFlare');
     if ($error = $w3_cloudflare->check_lasterror()) {
         $this->_errors[] = $error;
     }
     w3_require_once(W3TC_LIB_W3_DIR . '/Request.php');
     $error = W3_Request::get_string('w3tc_error');
     $note = W3_Request::get_string('w3tc_note');
     /**
      * Handle messages from reqeust
      */
     if ($error == 'cloudflare_api_request' && $w3_cloudflare->get_fault_signaled()) {
         // dont complain twice on cloudflare
     } elseif (isset($error_messages[$error])) {
         $errors[] = $error_messages[$error];
     }
     if (isset($note_messages[$note])) {
         $notes[] = $note_messages[$note];
     }
     /**
      * CDN notifications
      */
     if ($this->_config->get_boolean('cdn.enabled') && !w3_is_cdn_mirror($this->_config->get_string('cdn.engine'))) {
         /**
          * @var $ui_cdn_notes W3_UI_CdnNotes
          */
         $cdn_notes = w3_instance('W3_UI_CdnNotes');
         $this->_notes = array_merge($this->_notes, $cdn_notes->notifications($this->_config));
         $this->_errors = array_merge($this->_errors, $cdn_notes->errors());
     }
     /**
      * Show notification after plugin activate/deactivate
      */
     if ($this->_config->get_boolean('notes.plugins_updated')) {
         $texts = array();
         if ($this->_config->get_boolean('pgcache.enabled')) {
             $texts[] = w3_button_link(__('empty the page cache', 'w3-total-cache'), wp_nonce_url(sprintf('admin.php?page=%s&w3tc_flush_pgcache', $this->_page), 'w3tc'));
         }
         if ($this->_config->get_boolean('minify.enabled')) {
             $texts[] = sprintf(__('check the %s to maintain the desired user experience', 'w3-total-cache'), w3_button_hide_note(__('minify settings', 'w3-total-cache'), 'plugins_updated', 'admin.php?page=w3tc_minify'));
         }
         if (count($texts)) {
             $notes[] = sprintf(__('One or more plugins have been activated or deactivated, please %s. %s', 'w3-total-cache'), implode(__(' and ', 'w3-total-cache'), $texts), w3_button_hide_note(__('Hide this message', 'w3-total-cache'), 'plugins_updated'));
         }
     }
     /**
      * Show notification when page cache needs to be emptied
      */
     if ($this->_config->get_boolean('pgcache.enabled') && $this->_config->get('notes.need_empty_pgcache') && !$this->_config->is_preview()) {
         $notes[] = sprintf('The setting change(s) made either invalidate the cached data or modify the behavior of the site. %s now to provide a consistent user experience.', w3_button_link('Empty the page cache', wp_nonce_url(sprintf('admin.php?page=%s&w3tc_flush_pgcache', $this->_page), 'w3tc')));
     }
     /**
      * Show notification when object cache needs to be emptied
      */
     if ($this->_config->get_boolean('objectcache.enabled') && $this->_config->get('notes.need_empty_objectcache') && !$this->_config->is_preview()) {
         $notes[] = sprintf(__('The setting change(s) made either invalidate the cached data or modify the behavior of the site. %s now to provide a consistent user experience.', 'w3-total-cache'), w3_button_link(__('Empty the object cache', 'w3-total-cache'), wp_nonce_url(sprintf('admin.php?page=%s&w3tc_flush_objectcache', $this->_page), 'w3tc')));
     }
     /**
      * Minify notifications
      */
     if ($this->_config->get_boolean('minify.enabled')) {
         /**
          * Minify error occured
          */
         if ($this->_config_admin->get_boolean('notes.minify_error')) {
             $errors[] = sprintf(__('Recently an error occurred while creating the CSS / JS minify cache: %s. %s', 'w3-total-cache'), $this->_config_admin->get_string('minify.error.last'), w3_button_hide_note(__('Hide this message', 'w3-total-cache'), 'minify_error', '', true));
         }
         /**
          * Show notification when minify needs to be emptied
          */
         if ($this->_config->get_boolean('notes.need_empty_minify') && !$this->_config->is_preview()) {
             $notes[] = sprintf(__('The setting change(s) made either invalidate the cached data or modify the behavior of the site. %s now to provide a consistent user experience.', 'w3-total-cache'), w3_button_link(__('Empty the minify cache', 'w3-total-cache'), wp_nonce_url(sprintf('admin.php?page=%s&w3tc_flush_minify', $this->_page), 'w3tc')));
         }
     }
     if ($this->_config->get_boolean('newrelic.enabled') && $this->_config_admin->get_boolean('notes.new_relic_page_load_notification')) {
         /**
          * @var W3_UI_NewRelicNotes $newrelic_notes
          */
         $newrelic_notes = w3_instance('W3_UI_NewRelicNotes');
         $this->_notes = array_merge($this->_notes, $newrelic_notes->notifications($this->_config));
     }
     /**
      * Show notification if user can remove old w3tc folders
      */
     if ($this->_config_admin->get_boolean('notes.remove_w3tc')) {
         w3_require_once(W3TC_INC_DIR . '/functions/update.php');
         $folders = w3_find_old_folders();
         $folders = array_map('basename', $folders);
         $notes[] = sprintf(__('The directory w3tc can be deleted. %s: %s. However, <em>do not remove the w3tc-config directory</em>. %s', 'w3-total-cache'), WP_CONTENT_DIR, implode(', ', $folders), w3_button_hide_note('Hide this message', 'remove_w3tc', '', true));
     }
     // print errors which happened during current request execution
     foreach ($this->_errors as $error) {
         $errors[] = $error;
     }
     // print notes which happened during current request execution
     foreach ($this->_notes as $note) {
         $notes[] = $note;
     }
     /**
      * Show messages
      */
     foreach ($notes as $note) {
         echo sprintf('<div class="updated fade"><p>%s</p></div>', $note);
     }
     foreach ($errors as $error) {
         echo sprintf('<div class="error"><p>%s</p></div>', $error);
     }
 }
 /**
  * Reads config from request
  */
 function read_request()
 {
     require_once W3TC_LIB_W3_DIR . '/Request.php';
     $request = W3_Request::get_request();
     foreach ($this->_keys as $key => $type) {
         $request_key = str_replace('.', '_', $key);
         if (!isset($request[$request_key])) {
             continue;
         }
         switch ($type) {
             case 'string':
                 $this->set($key, W3_Request::get_string($request_key));
                 break;
             case 'int':
             case 'integer':
                 $this->set($key, W3_Request::get_integer($request_key));
                 break;
             case 'float':
             case 'double':
                 $this->set($key, W3_Request::get_double($request_key));
                 break;
             case 'bool':
             case 'boolean':
                 $this->set($key, W3_Request::get_boolean($request_key));
                 break;
             case 'array':
                 $this->set($key, W3_Request::get_array($request_key));
                 break;
         }
     }
 }
예제 #22
0
 function action_verify_plugin_license_key()
 {
     w3_require_once(W3TC_LIB_W3_DIR . '/Request.php');
     $license = W3_Request::get_string('license_key', '');
     if ($license) {
         $status = edd_w3edge_w3tc_verify_license($license);
         echo $status->license;
     } else {
         echo 'invalid';
     }
     exit;
 }
예제 #23
0
 /**
  * Send support request action
  *
  * @return void
  */
 function action_support_request()
 {
     w3_require_once(W3TC_LIB_W3_DIR . '/Request.php');
     $request_type = W3_Request::get_string('request_type');
     $payment = W3_Request::get_boolean('payment');
     $request_id = W3_Request::get_string('request_id');
     $url = W3_Request::get_string('url');
     $name = W3_Request::get_string('name');
     $email = W3_Request::get_string('email');
     $twitter = W3_Request::get_string('twitter');
     $phone = W3_Request::get_string('phone');
     $subject = W3_Request::get_string('subject');
     $description = W3_Request::get_string('description');
     $templates = W3_Request::get_array('templates');
     $forum_url = W3_Request::get_string('forum_url');
     $wp_login = W3_Request::get_string('wp_login');
     $wp_password = W3_Request::get_string('wp_password');
     $ftp_host = W3_Request::get_string('ftp_host');
     $ftp_login = W3_Request::get_string('ftp_login');
     $ftp_password = W3_Request::get_string('ftp_password');
     $subscribe_releases = W3_Request::get_string('subscribe_releases');
     $subscribe_customer = W3_Request::get_string('subscribe_customer');
     $params = array('request_type' => $request_type, 'payment' => $payment, 'url' => $url, 'name' => $name, 'email' => $email, 'twitter' => $twitter, 'phone' => $phone, 'subject' => $subject, 'description' => $description, 'forum_url' => $forum_url, 'wp_login' => $wp_login, 'wp_password' => $wp_password, 'ftp_host' => $ftp_host, 'ftp_login' => $ftp_login, 'ftp_password' => $ftp_password, 'subscribe_releases' => $subscribe_releases, 'subscribe_customer' => $subscribe_customer);
     $post = $params;
     foreach ($templates as $template_index => $template) {
         $template_key = sprintf('templates[%d]', $template_index);
         $params[$template_key] = $template;
     }
     if (!isset($this->_request_types[$request_type])) {
         w3_admin_redirect(array_merge($params, array('w3tc_error' => 'support_request_type')), false);
     }
     $required = array('bug_report' => 'url,name,email,subject,description', 'new_feature' => 'url,name,email,subject,description', 'email_support' => 'url,name,email,subject,description', 'phone_support' => 'url,name,email,subject,description,phone', 'plugin_config' => 'url,name,email,subject,description,wp_login,wp_password', 'theme_config' => 'url,name,email,subject,description,wp_login,wp_password,ftp_host,ftp_login,ftp_password', 'linux_config' => 'url,name,email,subject,description,wp_login,wp_password,ftp_host,ftp_login,ftp_password');
     if (strstr($required[$request_type], 'url') !== false && $url == '') {
         w3_admin_redirect(array_merge($params, array('w3tc_error' => 'support_request_url')), false);
     }
     if (strstr($required[$request_type], 'name') !== false && $name == '') {
         w3_admin_redirect(array_merge($params, array('w3tc_error' => 'support_request_name')), false);
     }
     if (strstr($required[$request_type], 'email') !== false && !preg_match('~^[a-z0-9_\\-\\.]+@[a-z0-9-\\.]+\\.[a-z]{2,5}$~', $email)) {
         w3_admin_redirect(array_merge($params, array('w3tc_error' => 'support_request_email')), false);
     }
     if (strstr($required[$request_type], 'phone') !== false && !preg_match('~^[0-9\\-\\.\\ \\(\\)\\+]+$~', $phone)) {
         w3_admin_redirect(array_merge($params, array('w3tc_error' => 'support_request_phone')), false);
     }
     if (strstr($required[$request_type], 'subject') !== false && $subject == '') {
         w3_admin_redirect(array_merge($params, array('w3tc_error' => 'support_request_subject')), false);
     }
     if (strstr($required[$request_type], 'description') !== false && $description == '') {
         w3_admin_redirect(array_merge($params, array('w3tc_error' => 'support_request_description')), false);
     }
     if (strstr($required[$request_type], 'wp_login') !== false && $wp_login == '') {
         w3_admin_redirect(array_merge($params, array('w3tc_error' => 'support_request_wp_login')), false);
     }
     if (strstr($required[$request_type], 'wp_password') !== false && $wp_password == '') {
         w3_admin_redirect(array_merge($params, array('w3tc_error' => 'support_request_wp_password')), false);
     }
     if (strstr($required[$request_type], 'ftp_host') !== false && $ftp_host == '') {
         w3_admin_redirect(array_merge($params, array('w3tc_error' => 'support_request_ftp_host')), false);
     }
     if (strstr($required[$request_type], 'ftp_login') !== false && $ftp_login == '') {
         w3_admin_redirect(array_merge($params, array('w3tc_error' => 'support_request_ftp_login')), false);
     }
     if (strstr($required[$request_type], 'ftp_password') !== false && $ftp_password == '') {
         w3_admin_redirect(array_merge($params, array('w3tc_error' => 'support_request_ftp_password')), false);
     }
     /**
      * Add attachments
      */
     $attachments = array();
     $attach_files = array(w3_get_wp_config_path(), w3_cache_blog_dir('log') . '/minify.log', w3_get_pgcache_rules_core_path(), w3_get_pgcache_rules_cache_path(), w3_get_browsercache_rules_cache_path(), w3_get_browsercache_rules_no404wp_path(), w3_get_minify_rules_core_path(), w3_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;
             }
             $attachments[] = 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[] = $attach_file;
         }
     }
     /**
      * Attach server info
      */
     $server_info = print_r($this->get_server_info(), true);
     $server_info = str_replace("\n", "\r\n", $server_info);
     $server_info_path = W3TC_CACHE_TMP_DIR . '/server_info.txt';
     if (@file_put_contents($server_info_path, $server_info)) {
         $attachments[] = $server_info_path;
     }
     /**
      * Attach phpinfo
      */
     ob_start();
     phpinfo();
     $php_info = ob_get_contents();
     ob_end_clean();
     $php_info_path = W3TC_CACHE_TMP_DIR . '/php_info.html';
     if (@file_put_contents($php_info_path, $php_info)) {
         $attachments[] = $php_info_path;
     }
     /**
      * Attach self-test
      */
     ob_start();
     $this->action_self_test();
     $self_test = ob_get_contents();
     ob_end_clean();
     $self_test_path = W3TC_CACHE_TMP_DIR . '/self_test.html';
     if (@file_put_contents($self_test_path, $self_test)) {
         $attachments[] = $self_test_path;
     }
     /**
      * Attach templates
      */
     foreach ($templates as $template) {
         if (!empty($template)) {
             $attachments[] = $template;
         }
     }
     /**
      * Attach other files
      */
     if (!empty($_FILES['files'])) {
         $files = (array) $_FILES['files'];
         for ($i = 0, $l = count($files); $i < $l; $i++) {
             if (isset($files['tmp_name'][$i]) && isset($files['name'][$i]) && isset($files['error'][$i]) && $files['error'][$i] == UPLOAD_ERR_OK) {
                 $path = W3TC_CACHE_TMP_DIR . '/' . $files['name'][$i];
                 if (@move_uploaded_file($files['tmp_name'][$i], $path)) {
                     $attachments[] = $path;
                 }
             }
         }
     }
     $data = array();
     if (!empty($wp_login) && !empty($wp_password)) {
         $data['WP Admin login'] = $wp_login;
         $data['WP Admin password'] = $wp_password;
     }
     if (!empty($ftp_host) && !empty($ftp_login) && !empty($ftp_password)) {
         $data['SSH / FTP host'] = $ftp_host;
         $data['SSH / FTP login'] = $ftp_login;
         $data['SSH / FTP password'] = $ftp_password;
     }
     /**
      * Store request data for future access
      */
     if (count($data)) {
         $hash = md5(microtime());
         $request_data = get_option('w3tc_request_data', array());
         $request_data[$hash] = $data;
         update_option('w3tc_request_data', $request_data);
         $request_data_url = sprintf('%s/w3tc_request_data/%s', w3_get_home_url(), $hash);
     } else {
         $request_data_url = '';
     }
     $nonce = wp_create_nonce('w3tc_support_request');
     if (is_network_admin()) {
         update_site_option('w3tc_support_request', $nonce);
     } else {
         update_option('w3tc_support_request', $nonce);
     }
     $file_access = WP_PLUGIN_URL . '/' . dirname(W3TC_FILE) . '/pub/files.php';
     if (w3_get_domain(w3_get_home_url()) != w3_get_domain(w3_get_site_url())) {
         $file_access = str_replace(w3_get_domain(w3_get_home_url()), w3_get_domain(w3_get_site_url()), $file_access);
     }
     $post['file_access'] = $file_access;
     $post['nonce'] = $nonce;
     $post['request_data_url'] = $request_data_url;
     $post['ip'] = $_SERVER['REMOTE_ADDR'];
     $post['user_agent'] = $_SERVER['HTTP_USER_AGENT'];
     $post['version'] = W3TC_VERSION;
     $post['plugin'] = 'W3 Total Cache';
     $post['request_id'] = $request_id;
     $license_level = 'community';
     if (w3_is_pro($this->_config)) {
         $license_level = 'pro';
     } elseif (w3_is_enterprise($this->_config)) {
         $license_level = 'enterprise';
     }
     $post['license_level'] = $license_level;
     $unset = array('wp_login', 'wp_password', 'ftp_host', 'ftp_login', 'ftp_password');
     foreach ($unset as $key) {
         unset($post[$key]);
     }
     foreach ($attachments as $attachment) {
         if (is_network_admin()) {
             update_site_option('attachment_' . md5($attachment), $attachment);
         } else {
             update_option('attachment_' . md5($attachment), $attachment);
         }
     }
     $post = array_merge($post, array('files' => $attachments));
     if (defined('W3_SUPPORT_DEBUG') && W3_SUPPORT_DEBUG) {
         $data = sprintf("[%s] Post support request\n", date('r'));
         foreach ($post as $key => $value) {
             $data .= sprintf("%s => %s\n", $key, is_array($value) ? implode(',', $value) : $value);
         }
         $filename = w3_cache_blog_dir('log') . '/support.log';
         if (!is_dir(dirname($filename))) {
             w3_mkdir_from(dirname($filename), W3TC_CACHE_DIR);
         }
         @file_put_contents($filename, $data, FILE_APPEND);
     }
     $response = wp_remote_post(W3TC_SUPPORT_REQUEST_URL, array('body' => $post, 'timeout' => $this->_config->get_integer('timelimit.email_send')));
     if (defined('W3_SUPPORT_DEBUG') && W3_SUPPORT_DEBUG) {
         $filename = w3_cache_blog_dir('log') . '/support.log';
         $data = sprintf("[%s] Post response \n%s\n", date('r'), print_r($response, true));
         @file_put_contents($filename, $data, FILE_APPEND);
     }
     if (!is_wp_error($response)) {
         $result = $response['response']['code'] == 200 && $response['body'] == 'Ok';
     } else {
         $result = false;
     }
     /**
      * Remove temporary files
      */
     foreach ($attachments as $attachment) {
         if (strstr($attachment, W3TC_CACHE_TMP_DIR) !== false) {
             @unlink($attachment);
         }
         if (is_network_admin()) {
             delete_site_option('attachment_' . md5($attachment));
         } else {
             delete_option('attachment_' . md5($attachment));
         }
     }
     if (is_network_admin()) {
         delete_site_option('w3tc_support_request');
     } else {
         delete_option('w3tc_support_request');
     }
     if ($result) {
         w3_admin_redirect(array('tab' => 'general', 'w3tc_note' => 'support_request'), false);
     } else {
         w3_admin_redirect(array_merge($params, array('request_type' => $request_type, 'w3tc_error' => 'support_request')), false);
     }
 }
예제 #24
0
파일: apc.php 프로젝트: rongandat/sallumeh
$command = W3_Request::get_string('command');
$nonce = W3_Request::get_string('nonce');
$uri = $_SERVER['REQUEST_URI'];
if (wp_hash($uri) == $nonce) {
    /**
     * @var $w3_cache W3_CacheFlush
     */
    $w3_cache = w3_instance('W3_CacheFlush');
    $result = false;
    switch ($command) {
        case 'delete_files':
            $mask = W3_Request::get_string('mask');
            $result = $w3_cache->apc_delete_files_based_on_regex($mask);
            break;
        case 'reload_files':
            $files = W3_Request::get_array('files');
            $w3_cache->apc_reload_files($files);
            $result = true;
            break;
    }
    if ($result) {
        header($_SERVER["SERVER_PROTOCOL"] . " 200 OK");
        die('Success');
    } else {
        header($_SERVER["SERVER_PROTOCOL"] . " 500 OK");
        die($command . ' could not be executed');
    }
} else {
    header($_SERVER["SERVER_PROTOCOL"] . " 401");
    die("Unauthorized access. ");
}
예제 #25
0
 /**
  * Page Speed results action
  *
  * @return void
  */
 function action_test_pagespeed_results()
 {
     w3_require_once(W3TC_LIB_W3_DIR . '/Request.php');
     w3_require_once(W3TC_LIB_W3_DIR . '/PageSpeed.php');
     $force = W3_Request::get_boolean('force');
     $title = 'Google Page Speed';
     $w3_pagespeed = new W3_PageSpeed();
     $results = $w3_pagespeed->analyze(w3_get_home_url(), $force);
     if ($force) {
         w3_admin_redirect(array('w3tc_pagespeed_results' => 1, '_wpnonce' => wp_create_nonce('w3tc')));
     }
     include W3TC_INC_POPUP_DIR . '/pagespeed_results.php';
 }
 /**
  * Save support us action
  *
  * @return void
  */
 function action_config_save_support_us()
 {
     $support = W3_Request::get_string('support');
     $tweeted = W3_Request::get_boolean('tweeted');
     $this->_config->set('common.support', $support);
     $this->_config->set('common.tweeted', $tweeted);
     $this->_config->save();
     w3_instance('W3_AdminLinks')->link_update($this->_config);
     w3_admin_redirect(array('w3tc_note' => 'config_save'));
 }
예제 #27
0
 /**
  * Handle minify error
  *
  * @param string $error
  * @return void
  */
 function _handle_error($error)
 {
     $notification = $this->_config_admin->get_string('minify.error.notification');
     if ($notification) {
         $file = W3_Request::get_string('file');
         if ($file) {
             $this->_config_admin->set('minify.error.file', $file);
         }
         if (stristr($notification, 'admin') !== false) {
             $this->_config_admin->set('minify.error.last', $error);
             $this->_config_admin->set('notes.minify_error', true);
         }
         if (stristr($notification, 'email') !== false) {
             $last = $this->_config_admin->get_integer('minify.error.notification.last');
             /**
              * Prevent email flood: send email every 5 min
              */
             if (time() - $last > 300) {
                 $this->_config_admin->set('minify.error.notification.last', time());
                 $this->_send_notification();
             }
         }
         $this->_config_admin->save();
     }
 }
예제 #28
0
 /**
  * Stylesheet filter
  *
  * @param $stylesheet
  * @return string
  */
 function stylesheet_preview($stylesheet)
 {
     w3_require_once(W3TC_LIB_W3_DIR . '/Request.php');
     $theme_name = W3_Request::get_string('w3tc_theme');
     $theme = w3tc_get_theme($theme_name);
     if ($theme) {
         return $theme['Stylesheet'];
     }
     return $stylesheet;
 }
예제 #29
0
 /**
  * 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('w3_parse_path', $reject_uri);
     foreach ($reject_uri as $expr) {
         $expr = trim($expr);
         if ($expr != '' && preg_match('~' . $expr . '~i', $_SERVER['REQUEST_URI'])) {
             return false;
         }
     }
     w3_require_once(W3TC_LIB_W3_DIR . '/Request.php');
     if (W3_Request::get_string('wp_customize')) {
         return false;
     }
     return true;
 }
예제 #30
0
 /**
  * PgCache purge page
  *
  * @return void
  */
 function action_flush_pgcache_purge_page()
 {
     w3_require_once(W3TC_LIB_W3_DIR . '/Request.php');
     $post_id = W3_Request::get_integer('post_id');
     do_action('w3tc_purge_from_pgcache', $post_id);
     w3_admin_redirect(array('w3tc_note' => 'pgcache_purge_page'), true);
 }