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()); }
/** * 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¬e=%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 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'; }
/** * 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; }
/** * 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; }
/** * 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); } }
/** * 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')); }
private function _w3tc_save_options_process() { $data = array('old_config' => $this->_config, 'response_query_string' => array(), 'response_actions' => array(), 'response_errors' => array(), 'response_notes' => array('config_save')); // if we are on extension settings page - stay on the same page if (Util_Request::get_string('page') == 'w3tc_extensions') { $data['response_query_string']['page'] = Util_Request::get_string('page'); $data['response_query_string']['extension'] = Util_Request::get_string('extension'); $data['response_query_string']['action'] = Util_Request::get_string('action'); } $capability = apply_filters('w3tc_capability_config_save', 'manage_options'); if (!current_user_can($capability)) { wp_die(__('You do not have the rights to perform this action.', 'w3-total-cache')); } /** * Read config * We should use new instance of WP_Config object here */ $config = new Config(); $this->read_request($config); if ($this->_page == 'w3tc_dashboard') { if (Util_Request::get_boolean('maxcdn')) { $config->set('cdn.enabled', true); $config->set('cdn.engine', 'maxcdn'); } } /** * General tab */ if ($this->_page == 'w3tc_general') { $file_nfs = Util_Request::get_boolean('file_nfs'); $file_locking = Util_Request::get_boolean('file_locking'); $config->set('pgcache.file.nfs', $file_nfs); $config->set('minify.file.nfs', $file_nfs); $config->set('dbcache.file.locking', $file_locking); $config->set('objectcache.file.locking', $file_locking); $config->set('pgcache.file.locking', $file_locking); $config->set('minify.file.locking', $file_locking); if (is_network_admin()) { if ($this->_config->get_boolean('common.force_master') !== $config->get_boolean('common.force_master')) { // blogmap is wrong so empty it @unlink(W3TC_CACHE_BLOGMAP_FILENAME); $blogmap_dir = dirname(W3TC_CACHE_BLOGMAP_FILENAME) . '/' . basename(W3TC_CACHE_BLOGMAP_FILENAME, '.php') . '/'; if (@is_dir($blogmap_dir)) { Util_File::rmdir($blogmap_dir); } } } /** * Check permalinks for page cache */ if ($config->get_boolean('pgcache.enabled') && $config->get_string('pgcache.engine') == 'file_generic' && !get_option('permalink_structure')) { $config->set('pgcache.enabled', false); $data['response_errors'][] = 'fancy_permalinks_disabled_pgcache'; } if (!Util_Environment::is_w3tc_pro($this->_config)) { delete_transient('w3tc_license_status'); } } /** * Minify tab */ if ($this->_page == 'w3tc_minify' && !$this->_config->get_boolean('minify.auto')) { $js_groups = array(); $css_groups = array(); $js_files = Util_Request::get_array('js_files'); $css_files = Util_Request::get_array('css_files'); foreach ($js_files as $theme => $templates) { foreach ($templates as $template => $locations) { foreach ((array) $locations as $location => $types) { foreach ((array) $types as $files) { foreach ((array) $files as $file) { if (!empty($file)) { $js_groups[$theme][$template][$location]['files'][] = Util_Environment::normalize_file_minify($file); } } } } } } foreach ($css_files as $theme => $templates) { foreach ($templates as $template => $locations) { foreach ((array) $locations as $location => $files) { foreach ((array) $files as $file) { if (!empty($file)) { $css_groups[$theme][$template][$location]['files'][] = Util_Environment::normalize_file_minify($file); } } } } } $config->set('minify.js.groups', $js_groups); $config->set('minify.css.groups', $css_groups); $js_theme = Util_Request::get_string('js_theme'); $css_theme = Util_Request::get_string('css_theme'); $data['response_query_string']['js_theme'] = $js_theme; $data['response_query_string']['css_theme'] = $css_theme; } /** * Browser Cache tab */ if ($this->_page == 'w3tc_browsercache') { if ($config->get_boolean('browsercache.enabled') && $config->get_boolean('browsercache.no404wp') && !get_option('permalink_structure')) { $config->set('browsercache.no404wp', false); $data['response_errors'][] = 'fancy_permalinks_disabled_browsercache'; } // todo: move to cdn module if (in_array($engine = $this->_config->get_string('cdn.engine'), array('netdna', 'maxcdn'))) { require_once W3TC_LIB_NETDNA_DIR . '/NetDNA.php'; $keys = explode('+', $this->_config->get_string('cdn.' . $engine . '.authorization_key')); if (sizeof($keys) == 3) { list($alias, $consumerkey, $consumersecret) = $keys; try { $api = new \NetDNA($alias, $consumerkey, $consumersecret); $disable_cooker_header = $config->get_boolean('browsercache.other.nocookies') || $config->get_boolean('browsercache.cssjs.nocookies'); $api->update_pull_zone($this->_config->get_string('cdn.' . $engine . '.zone_id'), array('ignore_setcookie_header' => $disable_cooker_header)); } catch (\Exception $ex) { } } } } /** * Mobile tab */ if ($this->_page == 'w3tc_mobile') { $groups = Util_Request::get_array('mobile_groups'); $mobile_groups = array(); $cached_mobile_groups = array(); foreach ($groups as $group => $group_config) { $group = strtolower($group); $group = preg_replace('~[^0-9a-z_]+~', '_', $group); $group = trim($group, '_'); if ($group) { $theme = isset($group_config['theme']) ? trim($group_config['theme']) : 'default'; $enabled = isset($group_config['enabled']) ? (bool) $group_config['enabled'] : true; $redirect = isset($group_config['redirect']) ? trim($group_config['redirect']) : ''; $agents = isset($group_config['agents']) ? explode("\r\n", trim($group_config['agents'])) : array(); $mobile_groups[$group] = array('theme' => $theme, 'enabled' => $enabled, 'redirect' => $redirect, 'agents' => $agents); $cached_mobile_groups[$group] = $agents; } } /** * Allow plugins modify WPSC mobile groups */ $cached_mobile_groups = apply_filters('cached_mobile_groups', $cached_mobile_groups); /** * Merge existent and delete removed groups */ foreach ($mobile_groups as $group => $group_config) { if (isset($cached_mobile_groups[$group])) { $mobile_groups[$group]['agents'] = (array) $cached_mobile_groups[$group]; } else { unset($mobile_groups[$group]); } } /** * Add new groups */ foreach ($cached_mobile_groups as $group => $agents) { if (!isset($mobile_groups[$group])) { $mobile_groups[$group] = array('theme' => '', 'enabled' => true, 'redirect' => '', 'agents' => $agents); } } /** * Allow plugins modify W3TC mobile groups */ $mobile_groups = apply_filters('w3tc_mobile_groups', $mobile_groups); /** * Sanitize mobile groups */ foreach ($mobile_groups as $group => $group_config) { $mobile_groups[$group] = array_merge(array('theme' => '', 'enabled' => true, 'redirect' => '', 'agents' => array()), $group_config); $mobile_groups[$group]['agents'] = array_unique($mobile_groups[$group]['agents']); $mobile_groups[$group]['agents'] = array_map('strtolower', $mobile_groups[$group]['agents']); sort($mobile_groups[$group]['agents']); } $enable_mobile = false; foreach ($mobile_groups as $group_config) { if ($group_config['enabled']) { $enable_mobile = true; break; } } $config->set('mobile.enabled', $enable_mobile); $config->set('mobile.rgroups', $mobile_groups); } /** * Referrer tab */ if ($this->_page == 'w3tc_referrer') { $groups = Util_Request::get_array('referrer_groups'); $referrer_groups = array(); foreach ($groups as $group => $group_config) { $group = strtolower($group); $group = preg_replace('~[^0-9a-z_]+~', '_', $group); $group = trim($group, '_'); if ($group) { $theme = isset($group_config['theme']) ? trim($group_config['theme']) : 'default'; $enabled = isset($group_config['enabled']) ? (bool) $group_config['enabled'] : true; $redirect = isset($group_config['redirect']) ? trim($group_config['redirect']) : ''; $referrers = isset($group_config['referrers']) ? explode("\r\n", trim($group_config['referrers'])) : array(); $referrer_groups[$group] = array('theme' => $theme, 'enabled' => $enabled, 'redirect' => $redirect, 'referrers' => $referrers); } } /** * Allow plugins modify W3TC referrer groups */ $referrer_groups = apply_filters('w3tc_referrer_groups', $referrer_groups); /** * Sanitize mobile groups */ foreach ($referrer_groups as $group => $group_config) { $referrer_groups[$group] = array_merge(array('theme' => '', 'enabled' => true, 'redirect' => '', 'referrers' => array()), $group_config); $referrer_groups[$group]['referrers'] = array_unique($referrer_groups[$group]['referrers']); $referrer_groups[$group]['referrers'] = array_map('strtolower', $referrer_groups[$group]['referrers']); sort($referrer_groups[$group]['referrers']); } $enable_referrer = false; foreach ($referrer_groups as $group_config) { if ($group_config['enabled']) { $enable_referrer = true; break; } } $config->set('referrer.enabled', $enable_referrer); $config->set('referrer.rgroups', $referrer_groups); } /** * CDN tab */ if ($this->_page == 'w3tc_cdn') { $cdn_cnames = Util_Request::get_array('cdn_cnames'); $cdn_domains = array(); foreach ($cdn_cnames as $cdn_cname) { $cdn_cname = trim($cdn_cname); /** * Auto expand wildcard domain to 10 subdomains */ $matches = null; if (preg_match('~^\\*\\.(.*)$~', $cdn_cname, $matches)) { $cdn_domains = array(); for ($i = 1; $i <= 10; $i++) { $cdn_domains[] = sprintf('cdn%d.%s', $i, $matches[1]); } break; } if ($cdn_cname) { $cdn_domains[] = $cdn_cname; } } switch ($this->_config->get_string('cdn.engine')) { case 'ftp': $config->set('cdn.ftp.domain', $cdn_domains); break; case 's3': case 's3_compatible': $config->set('cdn.s3.cname', $cdn_domains); break; case 'cf': $config->set('cdn.cf.cname', $cdn_domains); break; case 'cf2': $config->set('cdn.cf2.cname', $cdn_domains); break; case 'rackspace_cdn': $config->set('cdn.rackspace_cdn.domains', $cdn_domains); break; case 'rscf': $config->set('cdn.rscf.cname', $cdn_domains); break; case 'azure': $config->set('cdn.azure.cname', $cdn_domains); break; case 'mirror': $config->set('cdn.mirror.domain', $cdn_domains); break; case 'maxcdn': $config->set('cdn.maxcdn.domain', $cdn_domains); break; case 'netdna': $config->set('cdn.netdna.domain', $cdn_domains); break; case 'cotendo': $config->set('cdn.cotendo.domain', $cdn_domains); break; case 'edgecast': $config->set('cdn.edgecast.domain', $cdn_domains); break; case 'att': $config->set('cdn.att.domain', $cdn_domains); break; case 'akamai': $config->set('cdn.akamai.domain', $cdn_domains); break; case 'highwinds': $config->set('cdn.highwinds.host.domains', $cdn_domains); break; } } $old_ext_settings = $this->_config->get_array('extensions.settings', array()); $new_ext_settings = $old_ext_settings; $modified = false; $extensions = Extensions_Util::get_extensions($config); foreach ($extensions as $extension => $descriptor) { $request = Util_Request::get_as_array('extensions.settings.' . $extension . '.'); if (count($request) > 0) { if (!isset($new_ext_settings[$extension])) { $new_ext_settings[$extension] = array(); } foreach ($request as $key => $value) { if (!isset($old_ext_settings[$extension]) || !isset($old_ext_settings[$extension][$key]) || $old_ext_settings[$extension][$key] != $value) { $new_ext_settings[$extension][$key] = $value; $modified = true; } } } } if ($modified) { $config->set("extensions.settings", $new_ext_settings); } $data['new_config'] = $config; $data = apply_filters('w3tc_save_options', $data); $config = $data['new_config']; do_action('w3tc_config_ui_save', $config, $this->_config); do_action("w3tc_config_ui_save-{$this->_page}", $config, $this->_config); Util_Admin::config_save($this->_config, $config); if ($this->_page == 'w3tc_cdn') { /** * Handle Set Cookie Domain */ $set_cookie_domain_old = Util_Request::get_boolean('set_cookie_domain_old'); $set_cookie_domain_new = Util_Request::get_boolean('set_cookie_domain_new'); if ($set_cookie_domain_old != $set_cookie_domain_new) { if ($set_cookie_domain_new) { if (!$this->enable_cookie_domain()) { Util_Admin::redirect(array_merge($data['response_query_string'], array('w3tc_error' => 'enable_cookie_domain'))); } } else { if (!$this->disable_cookie_domain()) { Util_Admin::redirect(array_merge($data['response_query_string'], array('w3tc_error' => 'disable_cookie_domain'))); } } } } return array('query_string' => $data['response_query_string'], 'actions' => $data['response_actions'], 'errors' => $data['response_errors'], 'notes' => $data['response_notes']); }
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; }
/** * Returns current WordPress page * * @return string */ public static function get_current_wp_page() { return Util_Request::get_string('page'); }
/** * 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; }
/** * 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; }
/** * 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; }
/** * 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))); } } }
/** * Options page * * @return void */ function options() { $this->_page = Util_Request::get_string('page'); if (!Util_Admin::is_w3tc_admin_page()) { $this->_page = 'w3tc_dashboard'; } /* * Hidden pages */ if (isset($_REQUEST['w3tc_dbcluster_config'])) { $options_dbcache = new DbCache_Page(); $options_dbcache->dbcluster_config(); } /** * Show tab */ switch ($this->_page) { case 'w3tc_dashboard': $options_dashboard = new Generic_Page_Dashboard(); $options_dashboard->options(); break; case 'w3tc_general': $options_general = new Generic_Page_General(); $options_general->options(); break; case 'w3tc_pgcache': $options_pgcache = new PgCache_Page(); $options_pgcache->options(); break; case 'w3tc_minify': $options_minify = new Minify_Page(); $options_minify->options(); break; case 'w3tc_dbcache': $options_dbcache = new DbCache_Page(); $options_dbcache->options(); break; case 'w3tc_objectcache': $options_objectcache = new ObjectCache_Page(); $options_objectcache->options(); break; case 'w3tc_browsercache': $options_browsercache = new BrowserCache_Page(); $options_browsercache->options(); break; case 'w3tc_mobile': $options_mobile = new Mobile_Page_UserAgentGroups(); $options_mobile->options(); break; case 'w3tc_referrer': $options_referrer = new Mobile_Page_ReferrerGroups(); $options_referrer->options(); break; case 'w3tc_cdn': $options_cdn = new Cdn_Page(); $options_cdn->options(); break; case 'w3tc_faq': $options_faq = new Generic_Page_Faq(); $options_faq->options(); break; case 'w3tc_support': $options_support = new Support_Page(); $options_support->options(); break; case 'w3tc_install': $options_install = new Generic_Page_Install(); $options_install->options(); break; case 'w3tc_about': $options_about = new Generic_Page_About(); $options_about->options(); break; default: // placeholder to make it the only way to show pages // with the time $view = new Base_Page_Settings(); $view->options(); do_action("w3tc_settings_page-{$this->_page}"); $view->render_footer(); break; } }