/**
  * Fixes environment once event occurs
  *
  * @param W3_Config $config
  * @param string $event
  * @param W3_Config|null $old_config
  * @throws SelfTestExceptions
  **/
 public function fix_on_event($config, $event, $old_config = null)
 {
     if ($config->get_boolean('cdn.enabled') && !w3_is_cdn_mirror($config->get_string('cdn.engine'))) {
         if ($old_config != null && $config->get_integer('cdn.queue.interval') != $old_config->get_integer('cdn.queue.interval')) {
             $this->unschedule_queue_process();
         }
         if (!wp_next_scheduled('w3_cdn_cron_queue_process')) {
             wp_schedule_event(current_time('timestamp'), 'w3_cdn_cron_queue_process', 'w3_cdn_cron_queue_process');
         }
     } else {
         $this->unschedule_queue_process();
     }
     if ($config->get_boolean('cdn.enabled') && $config->get_boolean('cdn.autoupload.enabled') && !w3_is_cdn_mirror($config->get_string('cdn.engine'))) {
         if ($old_config != null && $config->get_integer('cdn.autoupload.interval') != $old_config->get_integer('cdn.autoupload.interval')) {
             $this->unschedule_upload();
         }
         if (!wp_next_scheduled('w3_cdn_cron_upload')) {
             wp_schedule_event(current_time('timestamp'), 'w3_cdn_cron_upload', 'w3_cdn_cron_upload');
         }
     } else {
         $this->unschedule_upload();
     }
     $exs = new SelfTestExceptions();
     if ($config->get_boolean('cdn.enabled')) {
         try {
             $this->table_create($event == 'activate');
         } catch (Exception $ex) {
             $exs->push($ex);
         }
     }
     if (count($exs->exceptions()) > 0) {
         throw $exs;
     }
 }
Beispiel #2
0
 /**
  * Schedule upload event
  */
 function schedule_upload()
 {
     if ($this->_config->get_boolean('cdn.enabled') && $this->_config->get_boolean('cdn.autoupload.enabled') && !w3_is_cdn_mirror($this->_config->get_string('cdn.engine'))) {
         if (!nxt_next_scheduled('w3_cdn_cron_upload')) {
             nxt_schedule_event(time(), 'w3_cdn_cron_upload', 'w3_cdn_cron_upload');
         }
     } else {
         $this->unschedule_upload();
     }
 }
Beispiel #3
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;
 }
Beispiel #4
0
 /**
  * Page cache tab
  *
  * @return void
  */
 function view()
 {
     global $wp_rewrite;
     $feeds = $wp_rewrite->feeds;
     $feed_key = array_search('feed', $feeds);
     if ($feed_key !== false) {
         unset($feeds[$feed_key]);
     }
     $default_feed = get_default_feed();
     $pgcache_enabled = $this->_config->get_boolean('pgcache.enabled');
     $permalink_structure = get_option('permalink_structure');
     $varnish_enabled = $this->_config->get_boolean('varnish.enabled');
     $cdn_mirror_purge_enabled = w3_is_cdn_mirror($this->_config->get_string('cdn.engine')) && $this->_config->get_string('cdn.engine') != 'mirror' && $this->_config->get_boolean('cdncache.enabled') && w3tc_edge_mode() && w3_is_pro($this->_config) || w3_is_enterprise();
     $disable_check_domain = w3_is_multisite() && w3_force_master();
     include W3TC_INC_DIR . '/options/pgcache.php';
 }
Beispiel #5
0
 /**
  * CDN tab
  *
  * @return void
  */
 function view()
 {
     w3_require_once(W3TC_INC_FUNCTIONS_DIR . '/ui.php');
     $cdn_enabled = $this->_config->get_boolean('cdn.enabled');
     $cdn_engine = $this->_config->get_string('cdn.engine');
     $cdn_mirror = w3_is_cdn_mirror($cdn_engine);
     $cdn_mirror_purge_all = w3_cdn_can_purge_all($cdn_engine);
     $cdn_common = w3_instance('W3_Plugin_CdnCommon');
     $cdn = $cdn_common->get_cdn();
     $cdn_supports_header = $cdn->headers_support() == W3TC_CDN_HEADER_MIRRORING;
     $cdn_supports_full_page_mirroring = $cdn->supports_full_page_mirroring();
     $minify_enabled = $this->_config->get_boolean('minify.enabled') && $this->_config->get_boolean('minify.rewrite') && (!$this->_config->get_boolean('minify.auto') || w3_is_cdn_mirror($this->_config->get_string('cdn.engine')));
     $cookie_domain = $this->get_cookie_domain();
     $set_cookie_domain = $this->is_cookie_domain_enabled();
     // Required for Update Media Query String button
     $browsercache_enabled = $this->_config->get_boolean('browsercache.enabled');
     $browsercache_update_media_qs = $this->_config->get_boolean('browsercache.cssjs.replace') || $this->_config->get_boolean('browsercache.other.replace');
     if (in_array($cdn_engine, array('netdna', 'maxcdn'))) {
         $pull_zones = array();
         $authorization_key = $this->_config->get_string("cdn.{$cdn_engine}.authorization_key");
         $zone_id = $this->_config->get_integer("cdn.{$cdn_engine}.zone_id");
         $alias = $consumerkey = $consumersecret = '';
         if ($authorization_key) {
             $keys = explode('+', $authorization_key);
             if (sizeof($keys) == 3) {
                 list($alias, $consumerkey, $consumersecret) = $keys;
             }
         }
         $authorized = $authorization_key != '' && $alias && $consumerkey && $consumersecret;
         $have_zone = $zone_id != 0;
         if ($authorized) {
             w3_require_once(W3TC_LIB_NETDNA_DIR . '/NetDNA.php');
             try {
                 $api = new NetDNA($alias, $consumerkey, $consumersecret);
                 $pull_zones = $api->get_zones_by_url(w3_get_home_url());
             } catch (Exception $ex) {
                 w3_require_once(W3TC_INC_FUNCTIONS_DIR . '/ui.php');
                 w3_e_error_box('<p>There is an error with your CDN settings: ' . $ex->getMessage() . '</p>');
             }
         }
     }
     include W3TC_INC_DIR . '/options/cdn.php';
 }
 /**
  * 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);
     }
 }
Beispiel #7
0
 /**
  * Admin bar menu
  *
  * @return void
  */
 function admin_bar_menu()
 {
     global $wp_admin_bar;
     if (current_user_can('manage_options')) {
         /**
          * @var $modules W3_ModuleStatus
          */
         $modules = w3_instance('W3_ModuleStatus');
         $can_empty_memcache = $modules->can_empty_memcache();
         $can_empty_opcode = $modules->can_empty_opcode();
         $can_empty_file = $modules->can_empty_file();
         $can_empty_varnish = $modules->can_empty_varnish();
         $browsercache_update_media_qs = $this->_config->get_boolean('browsercache.cssjs.replace') || $this->_config->get_boolean('browsercache.other.replace');
         //$cdn_enabled = $modules->is_enabled('cdn');
         $cdn_engine = $modules->get_module_engine('cdn');
         $cdn_mirror = w3_is_cdn_mirror($cdn_engine);
         $menu_items = array(array('id' => 'w3tc', 'title' => __('Performance', 'w3-total-cache'), 'href' => admin_url('admin.php?page=w3tc_dashboard')));
         if ($modules->is_enabled('pgcache') && w3_detect_post_id() && (!defined('DOING_AJAX') || !DOING_AJAX)) {
             $menu_items[] = array('id' => 'w3tc-pgcache-purge-post', 'parent' => 'w3tc', 'title' => __('Purge From Cache', 'w3-total-cache'), 'href' => wp_nonce_url(admin_url('admin.php?page=w3tc_dashboard&amp;w3tc_flush_pgcache_purge_post&amp;post_id=' . w3_detect_post_id()), 'w3tc'));
         }
         if ($can_empty_file && ($can_empty_opcode || $can_empty_memcache)) {
             $menu_items[] = array('id' => 'w3tc-flush-file', 'parent' => 'w3tc-empty-caches', 'title' => __('Empty Disc Cache(s)', 'w3-total-cache'), 'href' => wp_nonce_url(admin_url('admin.php?page=w3tc_dashboard&amp;w3tc_flush_file'), 'w3tc'));
         }
         if ($can_empty_opcode && ($can_empty_file || $can_empty_memcache)) {
             $menu_items[] = array('id' => 'w3tc-flush-opcode', 'parent' => 'w3tc-empty-caches', 'title' => __('Empty Opcode Cache', 'w3-total-cache'), 'href' => wp_nonce_url(admin_url('admin.php?page=w3tc_dashboard&amp;w3tc_flush_opcode'), 'w3tc'));
         }
         if ($can_empty_memcache && ($can_empty_file || $can_empty_opcode)) {
             $menu_items[] = array('id' => 'w3tc-flush-memcached', 'parent' => 'w3tc-empty-caches', 'title' => __('Empty Memcached Cache(s)', 'w3-total-cache'), 'href' => wp_nonce_url(admin_url('admin.php?page=w3tc_dashboard&amp;w3tc_flush_memcached'), 'w3tc'));
         }
         if ($modules->is_enabled('browsercache') && $browsercache_update_media_qs) {
             $menu_items[] = array('id' => 'w3tc-update-media-qs', 'parent' => 'w3tc', 'title' => __('Update Media Query String', 'w3-total-cache'), 'href' => wp_nonce_url(admin_url('admin.php?page=w3tc_dashboard&amp;w3tc_flush_browser_cache'), 'w3tc'));
         }
         if ($modules->plugin_is_enabled()) {
             $menu_items[] = array('id' => 'w3tc-empty-caches', 'parent' => 'w3tc', 'title' => __('Empty All Caches', 'w3-total-cache'), 'href' => wp_nonce_url(admin_url('admin.php?page=w3tc_dashboard&amp;w3tc_flush_all'), 'w3tc'));
             $menu_items[] = array('id' => 'w3tc-modules', 'parent' => 'w3tc', 'title' => __('Empty Modules', 'w3-total-cache'));
         }
         if ($modules->is_enabled('pgcache')) {
             $menu_items[] = array('id' => 'w3tc-flush-pgcache', 'parent' => 'w3tc-modules', 'title' => __('Empty Page Cache', 'w3-total-cache'), 'href' => wp_nonce_url(admin_url('admin.php?page=w3tc_dashboard&amp;w3tc_flush_pgcache'), 'w3tc'));
         }
         if ($modules->is_enabled('minify')) {
             $menu_items[] = array('id' => 'w3tc-flush-minify', 'parent' => 'w3tc-modules', 'title' => __('Empty Minify Cache', 'w3-total-cache'), 'href' => wp_nonce_url(admin_url('admin.php?page=w3tc_dashboard&amp;w3tc_flush_minify'), 'w3tc'));
         }
         if ($modules->is_enabled('dbcache')) {
             $menu_items[] = array('id' => 'w3tc-flush-dbcache', 'parent' => 'w3tc-modules', 'title' => __('Empty Database Cache', 'w3-total-cache'), 'href' => wp_nonce_url(admin_url('admin.php?page=w3tc_dashboard&amp;w3tc_flush_dbcache'), 'w3tc'));
         }
         if ($modules->is_enabled('objectcache')) {
             $menu_items[] = array('id' => 'w3tc-flush-objectcache', 'parent' => 'w3tc-modules', 'title' => __('Empty Object Cache', 'w3-total-cache'), 'href' => wp_nonce_url(admin_url('admin.php?page=w3tc_dashboard&amp;w3tc_flush_objectcache'), 'w3tc'));
         }
         if (w3_is_pro($this->_config) || w3_is_enterprise($this->_config)) {
             if ($modules->is_enabled('fragmentcache')) {
                 $menu_items[] = array('id' => 'w3tc-flush-fragmentcache', 'parent' => 'w3tc-modules', 'title' => __('Empty Fragment Cache', 'w3-total-cache'), 'href' => wp_nonce_url(admin_url('admin.php?page=w3tc_dashboard&amp;w3tc_flush_fragmentcache'), 'w3tc'));
             }
         }
         if ($modules->is_enabled('varnish')) {
             $menu_items[] = array('id' => 'w3tc-flush-varnish', 'parent' => 'w3tc-modules', 'title' => __('Purge Varnish Cache', 'w3-total-cache'), 'href' => wp_nonce_url(admin_url('admin.php?page=w3tc_dashboard&amp;w3tc_flush_varnish'), 'w3tc'));
         }
         if ($modules->is_enabled('cdn')) {
             if (w3_can_cdn_purge($cdn_engine)) {
                 $menu_items[] = array('id' => 'w3tc-cdn-purge', 'parent' => 'w3tc', 'title' => __('Purge CDN', 'w3-total-cache'), 'href' => wp_nonce_url(admin_url('admin.php?page=w3tc_cdn&amp;w3tc_cdn_purge'), 'w3tc'), 'meta' => array('onclick' => "w3tc_popupadmin_bar(this.href); return false"));
             }
             if (w3_cdn_can_purge_all($cdn_engine)) {
                 $menu_items[] = array('id' => 'w3tc-cdn-purge-full', 'parent' => 'w3tc', 'title' => __('Purge CDN Completely', 'w3-total-cache'), 'href' => wp_nonce_url(admin_url('admin.php?page=w3tc_cdn&amp;w3tc_flush_cdn'), 'w3tc'));
             }
             if (!$cdn_mirror) {
                 $menu_items[] = array('id' => 'w3tc-cdn-queue', 'parent' => 'w3tc', 'title' => __('Unsuccessful file transfers', 'w3-total-cache'), 'href' => wp_nonce_url(admin_url('admin.php?page=w3tc_cdn&amp;w3tc_cdn_queue'), 'w3tc'), 'meta' => array('onclick' => "w3tc_popupadmin_bar(this.href); return false"));
             }
         }
         $menu_items = array_merge($menu_items, array(array('id' => 'w3tc-faq', 'parent' => 'w3tc', 'title' => __('FAQ', 'w3-total-cache'), 'href' => admin_url('admin.php?page=w3tc_faq')), array('id' => 'w3tc-support', 'parent' => 'w3tc', 'title' => __('<span style="color: red; background: none;">Support</span>', 'w3-total-cache'), 'href' => admin_url('admin.php?page=w3tc_support'))));
         foreach ($menu_items as $menu_item) {
             $wp_admin_bar->add_menu($menu_item);
         }
     }
 }
Beispiel #8
0
 /**
  * Convert local uri path to CDN type specific path
  * @param $local_uri_path
  * @return string
  */
 function uri_to_cdn_uri($local_uri_path)
 {
     if (w3_is_network() && defined('DOMAIN_MAPPING') && DOMAIN_MAPPING) {
         $local_uri_path = str_replace(w3_get_site_url(), '', $local_uri_path);
     }
     $engine = $this->_config->get_string('cdn.engine');
     if (w3_is_cdn_mirror($engine)) {
         if (w3_is_network() && strpos($local_uri_path, 'files') === 0) {
             $upload_dir = wp_upload_dir();
             return ltrim($this->abspath_to_relative_path(dirname($upload_dir['basedir'])) . '/' . $local_uri_path, '/');
         }
     }
     $remote_path = $local_uri_path;
     return ltrim($remote_path, "/");
 }
Beispiel #9
0
/**
 * Save config, can't decline save process. (difference from action_save)
 *
 * Do some actions on config keys update
 * Used in several places such as:
 *
 * 1. common config save
 * 2. import settings
 *
 * @param W3_Config $current_config
 * @param W3_Config $new_config
 * @param W3_ConfigAdmin $new_config_admin
 * @return bool
 * @throws Exception
 */
function w3_config_save($current_config, $new_config, $new_config_admin)
{
    $master_config = $new_config->is_master() ? $new_config : new W3_Config(true);
    if ($master_config->get_integer('common.instance_id', 0) == 0) {
        $master_config->set('common.instance_id', mt_rand());
        if (!$new_config->is_master()) {
            $master_config->save();
        }
    }
    $old_config = new W3_Config();
    $browsercache_dependencies = array();
    if ($new_config->get_boolean('browsercache.enabled')) {
        $browsercache_dependencies = array_merge($browsercache_dependencies, array('browsercache.cssjs.replace', 'browsercache.html.replace', 'browsercache.other.replace'));
        if ($new_config->get_boolean('browsercache.cssjs.replace')) {
            $browsercache_dependencies = array_merge($browsercache_dependencies, array('browsercache.cssjs.compression', 'browsercache.cssjs.expires', 'browsercache.cssjs.lifetime', 'browsercache.cssjs.cache.control', 'browsercache.cssjs.cache.policy', 'browsercache.cssjs.etag', 'browsercache.cssjs.w3tc'));
        }
        if ($new_config->get_boolean('browsercache.html.replace')) {
            $browsercache_dependencies = array_merge($browsercache_dependencies, array('browsercache.html.compression', 'browsercache.html.expires', 'browsercache.html.lifetime', 'browsercache.html.cache.control', 'browsercache.html.cache.policy', 'browsercache.html.etag', 'browsercache.html.w3tc'));
        }
        if ($new_config->get_boolean('browsercache.other.replace')) {
            $browsercache_dependencies = array_merge($browsercache_dependencies, array('browsercache.other.compression', 'browsercache.other.expires', 'browsercache.other.lifetime', 'browsercache.other.cache.control', 'browsercache.other.cache.policy', 'browsercache.other.etag', 'browsercache.other.w3tc'));
        }
    }
    /**
     * Show need empty page cache notification
     */
    if ($new_config->get_boolean('pgcache.enabled')) {
        $pgcache_dependencies = array_merge($browsercache_dependencies, array('pgcache.debug', 'dbcache.enabled', 'objectcache.enabled', 'minify.enabled', 'mobile.enabled', 'referrer.enabled'));
        if ($new_config->get_boolean('dbcache.enabled')) {
            $pgcache_dependencies = array_merge($pgcache_dependencies, array('dbcache.debug'));
        }
        if ($new_config->get_boolean('objectcache.enabled')) {
            $pgcache_dependencies = array_merge($pgcache_dependencies, array('objectcache.debug'));
        }
        if ($new_config->get_boolean('minify.enabled')) {
            $pgcache_dependencies = array_merge($pgcache_dependencies, array('minify.auto', 'minify.debug', 'minify.rewrite', 'minify.html.enable', 'minify.html.engine', 'minify.html.inline.css', 'minify.html.inline.js', 'minify.html.strip.crlf', 'minify.html.comments.ignore', 'minify.css.enable', 'minify.css.engine', 'minify.css.groups', 'minify.js.enable', 'minify.js.engine', 'minify.js.groups', 'minify.htmltidy.options.clean', 'minify.htmltidy.options.hide-comments', 'minify.htmltidy.options.wrap', 'minify.reject.logged', 'minify.reject.ua', 'minify.reject.uri'));
        }
        /**
         * @var W3_ModuleStatus $modules
         */
        $modules = w3_instance('W3_ModuleStatus');
        if ($modules->is_running('cdn')) {
            $pgcache_dependencies = array_merge($pgcache_dependencies, array('cdn.enabled', 'cdn.debug', 'cdn.engine', 'cdn.uploads.enable', 'cdn.includes.enable', 'cdn.includes.files', 'cdn.theme.enable', 'cdn.theme.files', 'cdn.minify.enable', 'cdn.custom.enable', 'cdn.custom.files', 'cdn.ftp.domain', 'cdn.ftp.ssl', 'cdn.s3.cname', 'cdn.s3.ssl', 'cdn.cf.cname', 'cdn.cf.ssl', 'cdn.cf2.cname', 'cdn.cf2.ssl', 'cdn.rscf.cname', 'cdn.rscf.ssl', 'cdn.azure.cname', 'cdn.azure.ssl', 'cdn.mirror.domain', 'cdn.mirror.ssl', 'cdn.netdna.domain', 'cdn.netdna.ssl', 'cdn.cotendo.domain', 'cdn.cotendo.ssl', 'cdn.edgecast.domain', 'cdn.edgecast.ssl', 'cdn.att.domain', 'cdn.att.ssl', 'cdn.reject.logged_roles', 'cdn.reject.roles', 'cdn.reject.ua', 'cdn.reject.uri', 'cdn.reject.files'));
        } elseif ($old_config->get_boolean('cdn.enabled') && !$new_config->get_boolean('cdn.enabled')) {
            $pgcache_dependencies = array_merge($pgcache_dependencies, array('cdn.enabled'));
        }
        if ($new_config->get_boolean('mobile.enabled')) {
            $pgcache_dependencies = array_merge($pgcache_dependencies, array('mobile.rgroups'));
        }
        if ($new_config->get_boolean('referrer.enabled')) {
            $pgcache_dependencies = array_merge($pgcache_dependencies, array('referrer.rgroups'));
        }
        if ($new_config->get_boolean('browsercache.enabled') && $new_config->get_string('pgcache.engine') == 'file_generic') {
            $pgcache_dependencies = array_merge($pgcache_dependencies, array('browsercache.html.last_modified', 'browsercache.other.last_modified'));
        }
        $old_pgcache_dependencies_values = array();
        $new_pgcache_dependencies_values = array();
        foreach ($pgcache_dependencies as $pgcache_dependency) {
            $old_pgcache_dependencies_values[] = $old_config->get($pgcache_dependency);
            $new_pgcache_dependencies_values[] = $new_config->get($pgcache_dependency);
        }
        if (serialize($old_pgcache_dependencies_values) != serialize($new_pgcache_dependencies_values)) {
            $new_config->set('notes.need_empty_pgcache', true);
        }
    }
    /**
     * Show need empty minify notification
     */
    if ($current_config->get_boolean('minify.enabled') && $new_config->get_boolean('minify.enabled') && ($new_config->get_boolean('minify.css.enable') && ($new_config->get_boolean('minify.auto') || count($new_config->get_array('minify.css.groups'))) || $new_config->get_boolean('minify.js.enable') && ($new_config->get_boolean('minify.auto') || count($new_config->get_array('minify.js.groups'))))) {
        $minify_dependencies = array_merge($browsercache_dependencies, array('minify.auto', 'minify.debug', 'minify.options', 'minify.symlinks', 'minify.css.enable', 'minify.js.enable'));
        if ($new_config->get_boolean('minify.css.enable') && ($new_config->get_boolean('minify.auto') || count($new_config->get_array('minify.css.groups')))) {
            $minify_dependencies = array_merge($minify_dependencies, array('minify.css.engine', 'minify.css.combine', 'minify.css.strip.comments', 'minify.css.strip.crlf', 'minify.css.imports', 'minify.css.groups', 'minify.yuicss.path.java', 'minify.yuicss.path.jar', 'minify.yuicss.options.line-break', 'minify.csstidy.options.remove_bslash', 'minify.csstidy.options.compress_colors', 'minify.csstidy.options.compress_font-weight', 'minify.csstidy.options.lowercase_s', 'minify.csstidy.options.optimise_shorthands', 'minify.csstidy.options.remove_last_;', 'minify.csstidy.options.case_properties', 'minify.csstidy.options.sort_properties', 'minify.csstidy.options.sort_selectors', 'minify.csstidy.options.merge_selectors', 'minify.csstidy.options.discard_invalid_properties', 'minify.csstidy.options.css_level', 'minify.csstidy.options.preserve_css', 'minify.csstidy.options.timestamp', 'minify.csstidy.options.template'));
        }
        if ($new_config->get_boolean('minify.js.enable') && ($new_config->get_boolean('minify.auto') || count($new_config->get_array('minify.js.groups')))) {
            $minify_dependencies = array_merge($minify_dependencies, array('minify.js.engine', 'minify.js.combine.header', 'minify.js.combine.body', 'minify.js.combine.footer', 'minify.js.strip.comments', 'minify.js.strip.crlf', 'minify.js.groups', 'minify.yuijs.path.java', 'minify.yuijs.path.jar', 'minify.yuijs.options.line-break', 'minify.yuijs.options.nomunge', 'minify.yuijs.options.preserve-semi', 'minify.yuijs.options.disable-optimizations', 'minify.ccjs.path.java', 'minify.ccjs.path.jar', 'minify.ccjs.options.compilation_level', 'minify.ccjs.options.formatting'));
        }
        /**
         * @var W3_ModuleStatus $modules
         */
        $modules = w3_instance('W3_ModuleStatus');
        if ($modules->is_running('cdn')) {
            $minify_dependencies = array_merge($minify_dependencies, array('cdn.engine', 'cdn.enabled'));
        } elseif ($old_config->get_boolean('cdn.enabled') && !$new_config->get_boolean('cdn.enabled')) {
            $minify_dependencies = array_merge($minify_dependencies, array('cdn.enabled'));
        }
        $old_minify_dependencies_values = array();
        $new_minify_dependencies_values = array();
        foreach ($minify_dependencies as $minify_dependency) {
            $old_minify_dependencies_values[] = $old_config->get($minify_dependency);
            $new_minify_dependencies_values[] = $new_config->get($minify_dependency);
        }
        if (serialize($old_minify_dependencies_values) != serialize($new_minify_dependencies_values)) {
            $new_config->set('notes.need_empty_minify', true);
        }
    }
    if ($new_config->get_boolean('cdn.enabled') && !w3_is_cdn_mirror($new_config->get_string('cdn.engine'))) {
        /**
         * Show notification when CDN enabled
         */
        if (!$old_config->get_boolean('cdn.enabled')) {
            $new_config->set('notes.cdn_upload', true);
        }
        /**
         * Show notification when Browser Cache settings changes
         */
        $cdn_dependencies = array('browsercache.enabled');
        if ($new_config->get_boolean('cdn.enabled')) {
            $cdn_dependencies = array('browsercache.cssjs.compression', 'browsercache.cssjs.expires', 'browsercache.cssjs.lifetime', 'browsercache.cssjs.cache.control', 'browsercache.cssjs.cache.policy', 'browsercache.cssjs.etag', 'browsercache.cssjs.w3tc', 'browsercache.html.compression', 'browsercache.html.expires', 'browsercache.html.lifetime', 'browsercache.html.cache.control', 'browsercache.html.cache.policy', 'browsercache.html.etag', 'browsercache.html.w3tc', 'browsercache.other.compression', 'browsercache.other.expires', 'browsercache.other.lifetime', 'browsercache.other.cache.control', 'browsercache.other.cache.policy', 'browsercache.other.etag', 'browsercache.other.w3tc');
        }
        $old_cdn_dependencies_values = array();
        $new_cdn_dependencies_values = array();
        foreach ($cdn_dependencies as $cdn_dependency) {
            $old_cdn_dependencies_values[] = $old_config->get($cdn_dependency);
            $new_cdn_dependencies_values[] = $new_config->get($cdn_dependency);
        }
        if (serialize($old_cdn_dependencies_values) != serialize($new_cdn_dependencies_values)) {
            $new_config->set('notes.cdn_reupload', true);
        }
    }
    /**
     * Show need empty object cache notification
     */
    if ($current_config->get_boolean('objectcache.enabled')) {
        $objectcache_dependencies = array('objectcache.groups.global', 'objectcache.groups.nonpersistent');
        $old_objectcache_dependencies_values = array();
        $new_objectcache_dependencies_values = array();
        foreach ($objectcache_dependencies as $objectcache_dependency) {
            $old_objectcache_dependencies_values[] = $old_config->get($objectcache_dependency);
            $new_objectcache_dependencies_values[] = $new_config->get($objectcache_dependency);
        }
        if (serialize($old_objectcache_dependencies_values) != serialize($new_objectcache_dependencies_values)) {
            $new_config->set('notes.need_empty_objectcache', true);
        }
    }
    if ($current_config->get_boolean('newrelic.enabled')) {
        if ($current_config->get_boolean('pgcache.enabled')) {
            if (w3_is_network() && $current_config->get_boolean('common.force_master')) {
                $new_config->set('pgcache.late_init', true);
            }
        }
    }
    do_action('w3tc_saved_options', $new_config, $new_config_admin);
    /**
     * Save config
     */
    try {
        $new_config_admin->save();
        $new_config->save();
    } catch (Exception $ex) {
        // try to fix environment, it potentially can be fixed silently
        // dont show error here, it will be called again later
        // in admin_notices
        try {
            $environment = w3_instance('W3_AdminEnvironment');
            $environment->fix_in_wpadmin($new_config);
        } catch (Exception $ex) {
        }
        // retry save process and complain now on failure
        try {
            $new_config_admin->save();
            $new_config->save();
        } catch (Exception $ex) {
            throw new Exception('<strong>Can\'t change configuration</strong>: ' . $ex->getMessage());
        }
    }
    $w3_plugin_cdn = w3_instance('W3_Plugin_CdnAdmin');
    /**
     * Empty caches on engine change or cache enable/disable
     */
    if ($old_config->get_string('pgcache.engine') != $new_config->get_string('pgcache.engine') || $old_config->get_string('pgcache.enabled') != $new_config->get_string('pgcache.enabled')) {
        w3tc_pgcache_flush();
    }
    if ($old_config->get_string('dbcache.engine') != $new_config->get_string('dbcache.engine') || $old_config->get_string('dbcache.enabled') != $new_config->get_string('dbcache.enabled')) {
        w3tc_dbcache_flush();
    }
    if ($old_config->get_string('objectcache.engine') != $new_config->get_string('objectcache.engine') || $old_config->get_string('objectcache.enabled') != $new_config->get_string('objectcache.enabled')) {
        w3tc_objectcache_flush();
    }
    if ($old_config->get_string('minify.engine') != $new_config->get_string('minify.engine') || $old_config->get_string('minify.enabled') != $new_config->get_string('minify.enabled')) {
        w3tc_minify_flush();
    }
    /**
     * Update CloudFront CNAMEs
     */
    $update_cf_cnames = false;
    if ($new_config->get_boolean('cdn.enabled') && in_array($new_config->get_string('cdn.engine'), array('cf', 'cf2'))) {
        if ($new_config->get_string('cdn.engine') == 'cf') {
            $old_cnames = $old_config->get_array('cdn.cf.cname');
            $new_cnames = $new_config->get_array('cdn.cf.cname');
        } else {
            $old_cnames = $old_config->get_array('cdn.cf2.cname');
            $new_cnames = $new_config->get_array('cdn.cf2.cname');
        }
        if (count($old_cnames) != count($new_cnames) || count(array_diff($old_cnames, $new_cnames))) {
            $update_cf_cnames = true;
        }
    }
    /**
     * Refresh config
     */
    $current_config->load();
    /**
     * React to config changes
     */
    $environment = w3_instance('W3_AdminEnvironment');
    $environment->fix_on_event($new_config, 'config_change', $old_config);
    /**
     * Update support us option
     */
    w3_instance('W3_AdminLinks')->link_update($current_config);
    /**
     * Auto upload minify files to CDN
     */
    if ($new_config->get_boolean('minify.enabled') && $new_config->get_boolean('minify.upload') && $new_config->get_boolean('cdn.enabled') && !w3_is_cdn_mirror($new_config->get_string('cdn.engine'))) {
        w3_cdn_upload_minify();
    }
    /**
     * Auto upload browsercache files to CDN
     */
    if ($new_config->get_boolean('cdn.enabled') && $new_config->get_string('cdn.engine') == 'ftp') {
        w3_cdn_delete_browsercache($current_config);
        w3_cdn_upload_browsercache($current_config);
    }
    /**
     * Update CloudFront CNAMEs
     */
    if ($update_cf_cnames) {
        $error = null;
        $w3_plugin_cdn->update_cnames($error);
    }
    return true;
}
Beispiel #10
0
 /**
  * Purges files from CDN
  *
  * @param array $files
  * @param boolean $queue_failed
  * @param array $results
  * @return boolean
  */
 function purge($files, $queue_failed, &$results)
 {
     /**
      * Purge varnish servers before mirror purging
      */
     if (w3_is_cdn_mirror($this->_config->get_string('cdn_engine')) && $this->_config->get_boolean('varnish.enabled')) {
         $varnish =& w3_instance('W3_Varnish');
         foreach ($files as $remote_path) {
             $varnish->purge($remote_path);
         }
     }
     /**
      * Purge CDN
      */
     $cdn =& $this->get_cdn();
     @set_time_limit($this->_config->get_integer('timelimit.cdn_purge'));
     $return = $cdn->purge($files, $results);
     if (!$return && $queue_failed) {
         foreach ($results as $result) {
             if ($result['result'] != W3TC_CDN_RESULT_OK) {
                 $this->queue_add($result['local_path'], $result['remote_path'], W3TC_CDN_COMMAND_PURGE, $result['error']);
             }
         }
     }
     return $return;
 }
Beispiel #11
0
 /**
  * Link replace callback
  *
  * @param array $matches
  * @return string
  */
 function link_replace_callback($matches)
 {
     global $wpdb;
     static $queue = null, $reject_files = null;
     list($match, $quote, $url, , , , $path) = $matches;
     $path = ltrim($path, '/');
     /**
      * Check if URL was already replaced
      */
     if (isset($this->replaced_urls[$url])) {
         return $quote . $this->replaced_urls[$url];
     }
     /**
      * Check URL for rejected files
      */
     if ($reject_files === null) {
         $reject_files = $this->_config->get_array('cdn.reject.files');
     }
     foreach ($reject_files as $reject_file) {
         if ($reject_file != '') {
             $reject_file = w3_normalize_file($reject_file);
             $reject_file_regexp = '~^(' . $this->get_regexp_by_mask($reject_file) . ')~i';
             if (preg_match($reject_file_regexp, $path)) {
                 return $match;
             }
         }
     }
     /**
      * Don't replace URL for files that are in the CDN queue
      */
     if ($queue === null) {
         if (!w3_is_cdn_mirror($this->_config->get_string('cdn.engine'))) {
             $sql = sprintf('SELECT remote_path FROM %s', $wpdb->prefix . W3TC_CDN_TABLE_QUEUE);
             $queue = $wpdb->get_col($sql);
         } else {
             $queue = false;
         }
     }
     if ($queue && in_array($path, $queue)) {
         return $match;
     }
     /**
      * Do replacement
      */
     $cdn =& $this->_get_common()->get_cdn();
     $new_url = $cdn->format_url($path);
     if ($new_url) {
         $this->replaced_urls[$url] = $new_url;
         return $quote . $new_url;
     }
     return $match;
 }
Beispiel #12
0
 /**
  * Save config action
  *
  * Do some actions on config keys update
  * Used in several places such as:
  *
  * 1. common config save
  * 2. import settings
  * 3. enable/disable preview mode
  *
  * @param W3_Config $old_config
  * @param W3_Config $new_config
  * @param boolean $preview
  * @return void
  */
 function config_save(&$old_config, &$new_config, $preview = null)
 {
     $browsercache_dependencies = array();
     if ($new_config->get_boolean('browsercache.enabled')) {
         $browsercache_dependencies = array_merge($browsercache_dependencies, array('browsercache.cssjs.replace', 'browsercache.html.replace', 'browsercache.other.replace'));
         if ($new_config->get_boolean('browsercache.cssjs.replace')) {
             $browsercache_dependencies = array_merge($browsercache_dependencies, array('browsercache.cssjs.compression', 'browsercache.cssjs.expires', 'browsercache.cssjs.lifetime', 'browsercache.cssjs.cache.control', 'browsercache.cssjs.cache.policy', 'browsercache.cssjs.etag', 'browsercache.cssjs.w3tc'));
         }
         if ($new_config->get_boolean('browsercache.html.replace')) {
             $browsercache_dependencies = array_merge($browsercache_dependencies, array('browsercache.html.compression', 'browsercache.html.expires', 'browsercache.html.lifetime', 'browsercache.html.cache.control', 'browsercache.html.cache.policy', 'browsercache.html.etag', 'browsercache.html.w3tc'));
         }
         if ($new_config->get_boolean('browsercache.other.replace')) {
             $browsercache_dependencies = array_merge($browsercache_dependencies, array('browsercache.other.compression', 'browsercache.other.expires', 'browsercache.other.lifetime', 'browsercache.other.cache.control', 'browsercache.other.cache.policy', 'browsercache.other.etag', 'browsercache.other.w3tc'));
         }
     }
     /**
      * Show need empty page cache notification
      */
     if ($new_config->get_boolean('pgcache.enabled')) {
         $pgcache_dependencies = array_merge($browsercache_dependencies, array('pgcache.debug', 'dbcache.enabled', 'objectcache.enabled', 'minify.enabled', 'cdn.enabled', 'mobile.enabled', 'referrer.enabled'));
         if ($new_config->get_boolean('dbcache.enabled')) {
             $pgcache_dependencies = array_merge($pgcache_dependencies, array('dbcache.debug'));
         }
         if ($new_config->get_boolean('objectcache.enabled')) {
             $pgcache_dependencies = array_merge($pgcache_dependencies, array('objectcache.debug'));
         }
         if ($new_config->get_boolean('minify.enabled')) {
             $pgcache_dependencies = array_merge($pgcache_dependencies, array('minify.auto', 'minify.debug', 'minify.rewrite', 'minify.html.enable', 'minify.html.engine', 'minify.html.inline.css', 'minify.html.inline.js', 'minify.html.strip.crlf', 'minify.html.comments.ignore', 'minify.css.enable', 'minify.css.groups', 'minify.js.enable', 'minify.js.groups', 'minify.htmltidy.options.clean', 'minify.htmltidy.options.hide-comments', 'minify.htmltidy.options.wrap', 'minify.reject.logged', 'minify.reject.ua', 'minify.reject.uri'));
         }
         if ($new_config->get_boolean('cdn.enabled')) {
             $pgcache_dependencies = array_merge($pgcache_dependencies, array('cdn.debug', 'cdn.engine', 'cdn.uploads.enable', 'cdn.includes.enable', 'cdn.includes.files', 'cdn.theme.enable', 'cdn.theme.files', 'cdn.minify.enable', 'cdn.custom.enable', 'cdn.custom.files', 'cdn.mirror.domain', 'cdn.mirror.ssl', 'cdn.netdna.domain', 'cdn.netdna.ssl', 'cdn.cotendo.domain', 'cdn.cotendo.ssl', 'cdn.ftp.domain', 'cdn.ftp.ssl', 'cdn.s3.cname', 'cdn.s3.ssl', 'cdn.cf.cname', 'cdn.cf.ssl', 'cdn.cf2.cname', 'cdn.cf2.ssl', 'cdn.rscf.cname', 'cdn.rscf.ssl', 'cdn.azure.cname', 'cdn.azure.ssl', 'cdn.reject.admins', 'cdn.reject.ua', 'cdn.reject.uri', 'cdn.reject.files'));
         }
         if ($new_config->get_boolean('mobile.enabled')) {
             $pgcache_dependencies = array_merge($pgcache_dependencies, array('mobile.rgroups'));
         }
         if ($new_config->get_boolean('referrer.enabled')) {
             $pgcache_dependencies = array_merge($pgcache_dependencies, array('referrer.rgroups'));
         }
         $old_pgcache_dependencies_values = array();
         $new_pgcache_dependencies_values = array();
         foreach ($pgcache_dependencies as $pgcache_dependency) {
             $old_pgcache_dependencies_values[] = $old_config->get($pgcache_dependency);
             $new_pgcache_dependencies_values[] = $new_config->get($pgcache_dependency);
         }
         if (serialize($old_pgcache_dependencies_values) != serialize($new_pgcache_dependencies_values)) {
             $new_config->set('notes.need_empty_pgcache', true);
         }
     }
     /**
      * Show need empty minify notification
      */
     if ($new_config->get_boolean('minify.enabled') && ($new_config->get_boolean('minify.css.enable') && ($new_config->get_boolean('minify.auto') || count($new_config->get_array('minify.css.groups'))) || $new_config->get_boolean('minify.js.enable') && ($new_config->get_boolean('minify.auto') || count($new_config->get_array('minify.js.groups'))))) {
         $minify_dependencies = array_merge($browsercache_dependencies, array('minify.auto', 'minify.debug', 'minify.options', 'minify.symlinks', 'minify.css.enable', 'minify.js.enable'));
         if ($new_config->get_boolean('minify.css.enable') && ($new_config->get_boolean('minify.auto') || count($new_config->get_array('minify.css.groups')))) {
             $minify_dependencies = array_merge($minify_dependencies, array('minify.css.engine', 'minify.css.combine', 'minify.css.strip.comments', 'minify.css.strip.crlf', 'minify.css.imports', 'minify.css.groups', 'minify.yuicss.path.java', 'minify.yuicss.path.jar', 'minify.yuicss.options.line-break', 'minify.csstidy.options.remove_bslash', 'minify.csstidy.options.compress_colors', 'minify.csstidy.options.compress_font-weight', 'minify.csstidy.options.lowercase_s', 'minify.csstidy.options.optimise_shorthands', 'minify.csstidy.options.remove_last_;', 'minify.csstidy.options.case_properties', 'minify.csstidy.options.sort_properties', 'minify.csstidy.options.sort_selectors', 'minify.csstidy.options.merge_selectors', 'minify.csstidy.options.discard_invalid_properties', 'minify.csstidy.options.css_level', 'minify.csstidy.options.preserve_css', 'minify.csstidy.options.timestamp', 'minify.csstidy.options.template'));
         }
         if ($new_config->get_boolean('minify.js.enable') && ($new_config->get_boolean('minify.auto') || count($new_config->get_array('minify.js.groups')))) {
             $minify_dependencies = array_merge($minify_dependencies, array('minify.js.engine', 'minify.js.combine.header', 'minify.js.combine.body', 'minify.js.combine.footer', 'minify.js.strip.comments', 'minify.js.strip.crlf', 'minify.js.groups', 'minify.yuijs.path.java', 'minify.yuijs.path.jar', 'minify.yuijs.options.line-break', 'minify.yuijs.options.nomunge', 'minify.yuijs.options.preserve-semi', 'minify.yuijs.options.disable-optimizations', 'minify.ccjs.path.java', 'minify.ccjs.path.jar', 'minify.ccjs.options.compilation_level', 'minify.ccjs.options.formatting'));
         }
         $old_minify_dependencies_values = array();
         $new_minify_dependencies_values = array();
         foreach ($minify_dependencies as $minify_dependency) {
             $old_minify_dependencies_values[] = $old_config->get($minify_dependency);
             $new_minify_dependencies_values[] = $new_config->get($minify_dependency);
         }
         if (serialize($old_minify_dependencies_values) != serialize($new_minify_dependencies_values)) {
             $new_config->set('notes.need_empty_minify', true);
         }
     }
     if ($new_config->get_boolean('cdn.enabled') && !w3_is_cdn_mirror($new_config->get_string('cdn.engine'))) {
         /**
          * Show notification when CDN enabled
          */
         if (!$old_config->get_boolean('cdn.enabled')) {
             $new_config->set('notes.cdn_upload', true);
         }
         /**
          * Show notification when Browser Cache settings changes
          */
         $cdn_dependencies = array('browsercache.enabled');
         if ($new_config->get_boolean('cdn.enabled')) {
             $cdn_dependencies = array('browsercache.cssjs.compression', 'browsercache.cssjs.expires', 'browsercache.cssjs.lifetime', 'browsercache.cssjs.cache.control', 'browsercache.cssjs.cache.policy', 'browsercache.cssjs.etag', 'browsercache.cssjs.w3tc', 'browsercache.html.compression', 'browsercache.html.expires', 'browsercache.html.lifetime', 'browsercache.html.cache.control', 'browsercache.html.cache.policy', 'browsercache.html.etag', 'browsercache.html.w3tc', 'browsercache.other.compression', 'browsercache.other.expires', 'browsercache.other.lifetime', 'browsercache.other.cache.control', 'browsercache.other.cache.policy', 'browsercache.other.etag', 'browsercache.other.w3tc');
         }
         $old_cdn_dependencies_values = array();
         $new_cdn_dependencies_values = array();
         foreach ($cdn_dependencies as $cdn_dependency) {
             $old_cdn_dependencies_values[] = $old_config->get($cdn_dependency);
             $new_cdn_dependencies_values[] = $new_config->get($cdn_dependency);
         }
         if (serialize($old_cdn_dependencies_values) != serialize($new_cdn_dependencies_values)) {
             $new_config->set('notes.cdn_reupload', true);
         }
     }
     /**
      * Show need empty object cache notification
      */
     if ($this->_config->get_boolean('objectcache.enabled')) {
         $objectcache_dependencies = array('objectcache.reject.admin', 'objectcache.reject.uri', 'objectcache.groups.global', 'objectcache.groups.nonpersistent');
         $old_objectcache_dependencies_values = array();
         $new_objectcache_dependencies_values = array();
         foreach ($objectcache_dependencies as $objectcache_dependency) {
             $old_objectcache_dependencies_values[] = $old_config->get($objectcache_dependency);
             $new_objectcache_dependencies_values[] = $new_config->get($objectcache_dependency);
         }
         if (serialize($old_objectcache_dependencies_values) != serialize($new_objectcache_dependencies_values)) {
             $new_config->set('notes.need_empty_objectcache', true);
         }
     }
     /**
      * Save config
      */
     if ($new_config->save($preview)) {
         require_once W3TC_LIB_W3_DIR . '/Plugin/PgCache.php';
         require_once W3TC_LIB_W3_DIR . '/Plugin/DbCache.php';
         require_once W3TC_LIB_W3_DIR . '/Plugin/ObjectCache.php';
         require_once W3TC_LIB_W3_DIR . '/Plugin/BrowserCache.php';
         require_once W3TC_LIB_W3_DIR . '/Plugin/Cdn.php';
         $w3_plugin_pgcache =& W3_Plugin_PgCache::instance();
         $w3_plugin_dbcache =& W3_Plugin_DbCache::instance();
         $w3_plugin_objectcache =& W3_Plugin_ObjectCache::instance();
         $w3_plugin_browsercache =& W3_Plugin_BrowserCache::instance();
         $w3_plugin_cdn =& W3_Plugin_Cdn::instance();
         if (W3TC_PHP5) {
             require_once W3TC_LIB_W3_DIR . '/Plugin/Minify.php';
             $w3_plugin_minify =& W3_Plugin_Minify::instance();
         }
         /**
          * Empty caches on engine change or cache enable/disable
          */
         if ($old_config->get_string('pgcache.engine') != $new_config->get_string('pgcache.engine') || $old_config->get_string('pgcache.enabled') != $new_config->get_string('pgcache.enabled')) {
             $this->flush_pgcache();
         }
         if ($old_config->get_string('dbcache.engine') != $new_config->get_string('dbcache.engine') || $old_config->get_string('dbcache.enabled') != $new_config->get_string('dbcache.enabled')) {
             $this->flush_dbcache();
         }
         if ($old_config->get_string('objectcache.engine') != $new_config->get_string('objectcache.engine') || $old_config->get_string('objectcache.enabled') != $new_config->get_string('objectcache.enabled')) {
             $this->flush_objectcache();
         }
         if ($old_config->get_string('minify.engine') != $new_config->get_string('minify.engine') || $old_config->get_string('minify.enabled') != $new_config->get_string('minify.enabled')) {
             $this->flush_minify();
         }
         /**
          * Unschedule events if changed file gc interval
          */
         if ($old_config->get_integer('pgcache.file.gc') != $new_config->get_integer('pgcache.file.gc')) {
             $w3_plugin_pgcache->unschedule();
         }
         if ($old_config->get_integer('pgcache.prime.interval') != $new_config->get_integer('pgcache.prime.interval')) {
             $w3_plugin_pgcache->unschedule_prime();
         }
         if ($old_config->get_integer('dbcache.file.gc') != $new_config->get_integer('dbcache.file.gc')) {
             $w3_plugin_dbcache->unschedule();
         }
         if ($old_config->get_integer('objectcache.file.gc') != $new_config->get_integer('objectcache.file.gc')) {
             $w3_plugin_objectcache->unschedule();
         }
         if ($old_config->get_integer('cdn.autoupload.interval') != $new_config->get_integer('cdn.autoupload.interval')) {
             $w3_plugin_cdn->unschedule_upload();
         }
         if (W3TC_PHP5 && $old_config->get_integer('minify.file.gc') != $new_config->get_integer('minify.file.gc')) {
             $w3_plugin_minify->unschedule();
         }
         /**
          * Create CDN queue table
          */
         if (($old_config->get_boolean('cdn.enabled') != $new_config->get_boolean('cdn.enabled') || $old_config->get_string('cdn.engine') != $new_config->get_string('cdn.engine')) && $new_config->get_boolean('cdn.enabled') && !w3_is_cdn_mirror($new_config->get_string('cdn.engine'))) {
             $w3_plugin_cdn->table_create();
         }
         /**
          * Update CloudFront CNAMEs
          */
         $update_cf_cnames = false;
         if ($new_config->get_boolean('cdn.enabled') && in_array($new_config->get_string('cdn.engine'), array('cf', 'cf2'))) {
             if ($new_config->get_string('cdn.engine') == 'cf') {
                 $old_cnames = $old_config->get_array('cdn.cf.cname');
                 $new_cnames = $new_config->get_array('cdn.cf.cname');
             } else {
                 $old_cnames = $old_config->get_array('cdn.cf2.cname');
                 $new_cnames = $new_config->get_array('cdn.cf2.cname');
             }
             if (count($old_cnames) != count($new_cnames) || count(array_diff($old_cnames, $new_cnames))) {
                 $update_cf_cnames = true;
             }
         }
         /**
          * Refresh config
          */
         $old_config->load();
         /**
          * Schedule events
          */
         $w3_plugin_pgcache->schedule();
         $w3_plugin_pgcache->schedule_prime();
         $w3_plugin_dbcache->schedule();
         $w3_plugin_objectcache->schedule();
         $w3_plugin_cdn->schedule();
         $w3_plugin_cdn->schedule_upload();
         if (W3TC_PHP5) {
             $w3_plugin_minify->schedule();
         }
         /**
          * Update support us option
          */
         $this->link_update();
         /**
          * Write page cache rewrite rules
          */
         if ($new_config->get_boolean('pgcache.enabled') && $new_config->get_string('pgcache.engine') == 'file_generic') {
             if (w3_can_modify_rules(w3_get_pgcache_rules_core_path())) {
                 $w3_plugin_pgcache->write_rules_core();
             }
             if (w3_can_modify_rules(w3_get_pgcache_rules_cache_path())) {
                 $w3_plugin_pgcache->write_rules_cache();
             }
         } else {
             if (w3_can_modify_rules(w3_get_pgcache_rules_core_path())) {
                 $w3_plugin_pgcache->remove_rules_core();
             }
             if (w3_can_modify_rules(w3_get_pgcache_rules_cache_path())) {
                 $w3_plugin_pgcache->remove_rules_cache();
             }
         }
         /**
          * Write browsercache rules
          */
         if ($new_config->get_boolean('browsercache.enabled')) {
             if (w3_can_modify_rules(w3_get_browsercache_rules_cache_path())) {
                 $w3_plugin_browsercache->write_rules_cache();
             }
             if ($new_config->get_boolean('browsercache.no404wp')) {
                 if (w3_can_modify_rules(w3_get_browsercache_rules_no404wp_path())) {
                     $w3_plugin_browsercache->write_rules_no404wp();
                 }
             } else {
                 if (w3_can_modify_rules(w3_get_browsercache_rules_no404wp_path())) {
                     $w3_plugin_browsercache->remove_rules_no404wp();
                 }
             }
         } else {
             if (w3_can_modify_rules(w3_get_browsercache_rules_cache_path())) {
                 $w3_plugin_browsercache->remove_rules_cache();
             }
             if (w3_can_modify_rules(w3_get_browsercache_rules_no404wp_path())) {
                 $w3_plugin_browsercache->remove_rules_no404wp();
             }
         }
         /**
          * Write minify rewrite rules
          */
         if (W3TC_PHP5) {
             if ($new_config->get_boolean('minify.enabled') && $new_config->get_boolean('minify.rewrite')) {
                 if (w3_can_modify_rules(w3_get_minify_rules_core_path())) {
                     $w3_plugin_minify->write_rules_core();
                 }
                 if ($this->_config->get_string('minify.engine') == 'file') {
                     if (w3_can_modify_rules(w3_get_minify_rules_cache_path())) {
                         $w3_plugin_minify->write_rules_cache();
                     }
                 } else {
                     if (w3_can_modify_rules(w3_get_minify_rules_cache_path())) {
                         $w3_plugin_minify->remove_rules_cache();
                     }
                 }
             } else {
                 if (w3_can_modify_rules(w3_get_minify_rules_core_path())) {
                     $w3_plugin_minify->remove_rules_core();
                 }
                 if (w3_can_modify_rules(w3_get_minify_rules_cache_path())) {
                     $w3_plugin_minify->remove_rules_cache();
                 }
             }
         }
         /**
          * Auto upload minify files to CDN
          */
         if ($new_config->get_boolean('minify.enabled') && $new_config->get_boolean('minify.upload') && $new_config->get_boolean('cdn.enabled') && !w3_is_cdn_mirror($new_config->get_string('cdn.engine'))) {
             $this->cdn_upload_minify();
         }
         /**
          * Auto upload browsercache files to CDN
          */
         if ($new_config->get_boolean('cdn.enabled') && $new_config->get_string('cdn.engine') == 'ftp') {
             $this->cdn_delete_browsercache();
             if ($new_config->get_boolean('browsercache.enabled')) {
                 $this->cdn_upload_browsercache();
             }
         }
         /**
          * Update CloudFront CNAMEs
          */
         if ($update_cf_cnames) {
             $error = null;
             $cdn = $w3_plugin_cdn->get_cdn();
             $cdn->update_cnames($error);
         }
         /**
          * Save blognames into file
          */
         if (w3_is_network() && !w3_is_subdomain_install()) {
             w3_save_blognames();
         }
         return true;
     }
     return false;
 }
Beispiel #13
0
 /**
  * Returns config value
  *
  * @param string $key
  * @param mixed $default
  * @return mixed
  */
 function get($key, $default = null)
 {
     if (array_key_exists($key, $this->_keys) && array_key_exists($key, $this->_config)) {
         $value = $this->_config[$key];
     } else {
         if ($default === null && array_key_exists($key, $this->_defaults)) {
             $value = $this->_defaults[$key];
         } else {
             $value = $default;
         }
     }
     switch ($key) {
         /**
          * Check cache engines
          */
         case 'pgcache.engine':
         case 'dbcache.engine':
         case 'minify.engine':
         case 'objectcache.engine':
             /**
              * Legacy support
              */
             if ($value == 'file_pgcache') {
                 $value = 'file_generic';
             }
             switch (true) {
                 case $value == 'file_generic' && !w3_can_check_rules():
                 case $value == 'apc' && !function_exists('apc_store'):
                 case $value == 'eaccelerator' && !function_exists('eaccelerator_put'):
                 case $value == 'xcache' && !function_exists('xcache_set'):
                 case $value == 'wincache' && !function_exists('wincache_ucache_set'):
                 case $value == 'memcached' && !class_exists('Memcache'):
                     return 'file';
             }
             break;
             /**
              * Check HTML minifier
              */
         /**
          * Check HTML minifier
          */
         case 'minify.html.engine':
             if ($value == 'htmltidy' && !class_exists('tidy')) {
                 return 'html';
             }
             break;
             /**
              * Disabled some page cache options when enhanced mode enabled
              */
         /**
          * Disabled some page cache options when enhanced mode enabled
          */
         case 'pgcache.cache.query':
             if ($this->get_string('pgcache.engine') == 'file_generic') {
                 return false;
             }
             break;
             /**
              * Set default value to sitemap file
              */
         /**
          * Set default value to sitemap file
          */
         case 'pgcache.prime.sitemap':
             if (!$value) {
                 $value = w3_get_home_url() . '/sitemap.xml';
             }
             break;
             /**
              * Disabled minify when PHP5 is not installed
              */
         /**
          * Disabled minify when PHP5 is not installed
          */
         case 'minify.enabled':
             if (!W3TC_PHP5) {
                 return false;
             }
             break;
             /**
              * Disable minify rewrite when server rules are not supported
              */
         /**
          * Disable minify rewrite when server rules are not supported
          */
         case 'minify.rewrite':
             if (!w3_can_check_rules()) {
                 return false;
             }
             break;
             /**
              * Disable minify options for auto mode
              */
         /**
          * Disable minify options for auto mode
          */
         case 'minify.upload':
             if ($this->get_boolean('minify.auto')) {
                 return false;
             }
             break;
             /**
              * Minify groups legacy support
              */
         /**
          * Minify groups legacy support
          */
         case 'minify.js.groups':
         case 'minify.css.groups':
             /**
              * Support <= 0.8.5.2 versions
              */
             if (is_array($value) && count($value)) {
                 $group = current($value);
                 if (is_array($group) && count($group)) {
                     $location = current($group);
                     if (isset($location['files'])) {
                         if (function_exists('get_theme')) {
                             $theme = get_theme(get_current_theme());
                             $theme_key = w3_get_theme_key($theme['Theme Root'], $theme['Template'], $theme['Stylesheet']);
                             $value = array($theme_key => $value);
                             return $value;
                         }
                     }
                 }
             }
             /**
              * Support <= 0.9.1.3 versions
              */
             $wp_themes = get_themes();
             foreach ($value as $theme_key => $templates) {
                 if (strlen($theme_key) == 5) {
                     break;
                 }
                 foreach ($wp_themes as $wp_theme) {
                     $wp_theme_key = w3_get_theme_key_legacy($wp_theme['Theme Root'], $wp_theme['Template'], $wp_theme['Stylesheet']);
                     if ($theme_key == $wp_theme_key) {
                         $new_theme_key = w3_get_theme_key($wp_theme['Theme Root'], $wp_theme['Template'], $wp_theme['Stylesheet']);
                         $value[$new_theme_key] = $templates;
                         unset($theme_key);
                         break;
                     }
                 }
             }
             break;
             /**
              * Disable CDN minify when PHP5 is not installed or minify is disabled
              */
         /**
          * Disable CDN minify when PHP5 is not installed or minify is disabled
          */
         case 'cdn.minify.enable':
             if (!W3TC_PHP5 || !$this->get_boolean('minify.rewrite') || $this->get_boolean('minify.auto') && !w3_is_cdn_mirror($this->get_string('cdn.engine'))) {
                 return false;
             }
             break;
             /**
              * Check CDN engines
              */
         /**
          * Check CDN engines
          */
         case 'cdn.engine':
             /**
              * Check for PHP5
              */
             if (in_array($value, array('rscf', 'azure')) && !W3TC_PHP5) {
                 return 'mirror';
             }
             /**
              * Check for CURL
              */
             if (in_array($value, array('s3', 'cf', 'cf2', 'rscf')) && !function_exists('curl_init')) {
                 return 'mirror';
             }
             /**
              * Check for FTP
              */
             if ($value == 'ftp' && !function_exists('ftp_connect')) {
                 return 'mirror';
             }
             /**
              * Check for SHA 256 functions
              */
             if ($value == 'netdna' && !function_exists('hash') && !function_exists('mhash')) {
                 return 'mirror';
             }
             break;
             /**
              * Disable no 404 wp feature when server rules are not supported
              */
         /**
          * Disable no 404 wp feature when server rules are not supported
          */
         case 'browsercache.no404wp':
             if (!w3_can_check_rules()) {
                 return false;
             }
             break;
     }
     return $value;
 }
Beispiel #14
0
 /**
  * Link replace callback, basic checks step
  *
  * @param $match
  * @param $quote
  * @param $url
  * @param $path
  * @return null|string
  */
 function _link_replace_callback_checks($match, $quote, $url, $path)
 {
     /**
      * @var wpdb $wpdb
      */
     global $wpdb;
     static $queue = null, $reject_files = null;
     /**
      * Check if URL was already replaced
      */
     if (isset($this->replaced_urls[$url])) {
         return $quote . $this->replaced_urls[$url];
     }
     /**
      * Check URL for rejected files
      */
     if ($reject_files === null) {
         $reject_files = $this->_config->get_array('cdn.reject.files');
     }
     foreach ($reject_files as $reject_file) {
         if ($reject_file != '') {
             $reject_file = $this->_replace_folder_placeholders($reject_file);
             $reject_file = w3_normalize_file($reject_file);
             $reject_file_regexp = '~^(' . $this->get_regexp_by_mask($reject_file) . ')~i';
             if (preg_match($reject_file_regexp, $path)) {
                 return $match;
             }
         }
     }
     /**
      * Don't replace URL for files that are in the CDN queue
      */
     if ($queue === null) {
         if (!w3_is_cdn_mirror($this->_config->get_string('cdn.engine'))) {
             $sql = $wpdb->prepare('SELECT remote_path FROM ' . $wpdb->prefix . W3TC_CDN_TABLE_QUEUE . ' WHERE remote_path = %s', $path);
             $queue = $wpdb->get_var($sql);
         } else {
             $queue = false;
         }
     }
     if ($queue) {
         return $match;
     }
     return null;
 }