示例#1
0
 /**
  * @param W3_Config $config
  * @param W3_ConfigAdmin $config_admin
  * @return string
  */
 function notifications($config)
 {
     /**
      * @var $nerser W3_NewRelicService
      */
     $nerser = w3_instance('W3_NewRelicService');
     try {
         $pl = $nerser->get_frontend_response_time();
         if ($pl > 0.3) {
             $nr_recommends = array();
             if (!$config->get_boolean('pgcache.enabled')) {
                 $nr_recommends[] = __('Page Cache', 'w3-total-cache');
             }
             if (!$config->get_boolean('minify.enabled')) {
                 $nr_recommends[] = __('Minify', 'w3-total-cache');
             }
             if (!$config->get_boolean('cdn.enabled')) {
                 $nr_recommends[] = __('CDN', 'w3-total-cache');
             }
             if (!$config->get_boolean('browsercache.enabled')) {
                 $nr_recommends[] = __('Browser Cache and use compression', 'w3-total-cache');
             }
             if ($nr_recommends) {
                 $message = sprintf(__('Application monitoring has detected that your page load time is
                                                    higher than 300ms. It is recommended that you enable the following
                                                    features: %s %s', 'w3-total-cache'), implode(', ', $nr_recommends), w3_button_hide_note('Hide this message', 'new_relic_page_load_notification', '', true));
                 return $message;
             }
         }
     } catch (Exception $ex) {
     }
     return '';
 }
 /**
  * @param W3_Config $config
  * @param W3_Config $config_master
  * @param bool $do_merge if to merge with network main site
  * @return string
  */
 public static function get_wordpress_appname($config, $config_master, $do_merge = true)
 {
     if (w3_is_network()) {
         if ($config_master->get_boolean('newrelic.use_network_wide_id')) {
             $appname = $config_master->get_string('newrelic.appname');
         } else {
             $merge = $config->get_boolean('newrelic.merge_with_network');
             $merge_name = '';
             if ($do_merge && $merge && w3_get_blog_id() != 0) {
                 $merge_name = ';' . $config_master->get_string('newrelic.appname');
             }
             if (w3_get_blog_id() != 0 && !$config->get_boolean('common.force_master')) {
                 $appname = $config->get_string('newrelic.appname', '');
                 if (empty($appname)) {
                     $prefix = $config->get_string('newrelic.appname_prefix');
                     $appname = $prefix . trim(w3_get_home_domain() . w3_get_site_path(), '/');
                 }
             } else {
                 if (w3_get_blog_id() != 0) {
                     $prefix = $config->get_string('newrelic.appname_prefix');
                     $appname = $prefix . trim(w3_get_home_domain() . w3_get_site_path(), '/');
                 } else {
                     $appname = $config->get_string('newrelic.appname');
                 }
             }
             $appname = $appname . $merge_name;
         }
     } else {
         $appname = $config->get_string('newrelic.appname');
     }
     return $appname;
 }
示例#3
0
 public function run()
 {
     $this->_config = w3_instance('W3_Config');
     if ($this->_config->get_boolean('cdn.enabled')) {
         add_filter('wpseo_xml_sitemap_img_src', array($this, 'wpseo_cdn_filter'));
     }
 }
示例#4
0
 /**
  * @param W3_Config $config
  * @param W3_Config $old_config
  */
 function possible_state_change($config, $old_config)
 {
     if ($old_config->get_string('plugin.license_key') != '' && $config->get_string('plugin.license_key') == '') {
         $result = edd_w3edge_w3tc_deactivate_license($old_config->get_string('plugin.license_key'));
         if ($result) {
             $this->site_inactivated = true;
         }
         delete_transient('w3tc_license_status');
     } else {
         if ($old_config->get_string('plugin.license_key') == '' && $config->get_string('plugin.license_key') != '') {
             $result = edd_w3edge_w3tc_activate_license($config->get_string('plugin.license_key'));
             if ($result) {
                 $this->site_activated = true;
             }
             delete_transient('w3tc_license_status');
         } else {
             if ($old_config->get_string('plugin.license_key') != $config->get_string('plugin.license_key')) {
                 $result = edd_w3edge_w3tc_activate_license($config->get_string('plugin.license_key'));
                 if ($result) {
                     $this->site_activated = true;
                 }
                 delete_transient('w3tc_license_status');
             }
         }
     }
 }
 public function is_cache_configured()
 {
     $cache_configured = true;
     if ($this->is_wp_super_cache_detected()) {
         return $this->is_wp_super_cache_active() && $this->does_wp_super_cache_have_configured_uas() || !$this->is_wp_super_cache_active();
     }
     // Check W3
     if ($this->is_w3_plugin_detected()) {
         $w3_config = new W3_Config(true);
         if ($w3_config) {
             // Check to see if the Page Cache is enabled
             if ($w3_config->get_cache_option('pgcache.enabled')) {
                 // If it's enabled, we need to make sure the user agents have been updated
                 $rejected_user_agents = $w3_config->get_cache_option('pgcache.reject.ua');
                 if (!$this->find_in_array_no_case('iphone', $rejected_user_agents)) {
                     $cache_configured = false;
                 }
                 if (!$cache_configured && ($user_groups = $w3_config->get_array('mobile.rgroups')) && is_array($user_groups) && count($user_groups) > 0) {
                     foreach ($user_groups as $group) {
                         if ($group['enabled'] && $this->find_in_array_no_case('iphone', $group['agents']) && $group['theme'] == '' && $group['redirect'] == '') {
                             $cache_configured = true;
                             add_filter('wptouch_show_mobile_switch_link', '__return_false');
                         }
                     }
                 }
             }
         }
         return $cache_configured;
     }
     if ($this->is_wordfence_detected()) {
         $cache_type = wfConfig::get('cacheType', false);
         if (!$cache_type) {
             $cache_configured = true;
         } else {
             $cookie_set = false;
             $user_agents_set = false;
             $exclusions = wfConfig::get('cacheExclusions', false);
             if ($exclusions) {
                 $exclusions = unserialize($exclusions);
                 if ($exclusions) {
                     foreach ($exclusions as $exclusion) {
                         if ($exclusion['pt'] == 'cc' && ($exclusion['p'] = 'wptouch_switch_toggle')) {
                             $cookie_set = true;
                         } else {
                             if ($exclusion['pt'] == 'uac' && strtolower($exclusion['p']) == 'iphone') {
                                 $user_agents_set = true;
                             }
                         }
                         if ($cookie_set && $user_agents_set) {
                             break;
                         }
                     }
                 }
             }
             $cache_configured = $cookie_set && $user_agents_set;
         }
         return $cache_configured;
     }
     return $cache_configured;
 }
示例#6
0
 /**
  * PHP5-style constructor
  */
 function __construct()
 {
     $this->_config = w3_instance('W3_Config');
     $this->_debug = $this->_config->get_boolean('varnish.debug');
     $this->_servers = $this->_config->get_array('varnish.servers');
     $this->_timeout = $this->_config->get_integer('timelimit.varnish_purge');
 }
 function __construct()
 {
     $this->_config = w3_instance('W3_Config');
     $this->_caches['objectcache'] = w3_instance('W3_ObjectCache');
     if ($this->_config->get_boolean('fragmentcache.enabled')) {
         $this->_caches['fragmentcache'] = w3_instance('W3_Pro_FragmentCache');
     }
 }
 function run()
 {
     $this->_config = w3_instance('W3_Config');
     if ($this->_config->get_boolean('cdn.enabled')) {
         add_action('includes_url', array(&$this, 'filter_includes_url'), 10, 2);
         add_action('ngg_get_image_url', array(&$this, 'action_ngg_get_image_url'), 10, 3);
     }
 }
示例#9
0
 /**
  * Store the output buffer per page/post hook basis.
  */
 function cache_genesis_end()
 {
     $keys = $this->_get_id_group(current_filter());
     if (is_null($keys)) {
         return;
     }
     list($id, $group) = $keys;
     w3tc_fragmentcache_end($id, $group, $this->_config->get_boolean('fragmentcache.debug'));
 }
 /**
  * Fixes environment in each wp-admin request
  *
  * @param W3_Config $config
  * @param bool $force_all_checks
  * @throws SelfTestExceptions
  **/
 public function fix_on_wpadmin_request($config, $force_all_checks)
 {
     $exs = new SelfTestExceptions();
     if ($config->get_boolean('config.check') || $force_all_checks) {
         if (!$config->get_boolean('newrelic.enabled') || $config->get_boolean('newrelic.enabled') && $config->get_boolean('newrelic.use_php_function')) {
             $this->rules_remove($exs);
         }
     }
     if (count($exs->exceptions()) > 0) {
         throw $exs;
     }
 }
示例#11
0
 function generate()
 {
     $pages = $this->generate_menu_array();
     add_menu_page(__('Performance', 'w3-total-cache'), __('Performance', 'w3-total-cache'), 'manage_options', 'w3tc_dashboard', '', 'div');
     $submenu_pages = array();
     foreach ($pages as $slug => $titles) {
         if ($this->_config_admin->get_boolean('common.visible_by_master_only') && $titles['network_show'] || (!$this->_config_admin->get_boolean('common.visible_by_master_only') || is_super_admin() && (!w3_force_master() || is_network_admin()))) {
             $submenu_pages[] = add_submenu_page('w3tc_dashboard', $titles[0] . ' | W3 Total Cache', $titles[1], 'manage_options', $slug, array(&$this, 'options'));
         }
     }
     return $submenu_pages;
 }
示例#12
0
 function action_save_new_relic()
 {
     if ($this->_config->get_boolean('newrelic.enabled')) {
         /**
          * @var $nerser W3_NewRelicService
          */
         $nerser = w3_instance('W3_NewRelicService');
         $application = W3_Request::get_array('application');
         $application['alerts_enabled'] = $application['alerts_enabled'] == 1 ? 'true' : 'false';
         $application['rum_enabled'] = $application['rum_enabled'] == 1 ? 'true' : 'false';
         $result = $nerser->update_application_settings($application);
         w3_admin_redirect(array('w3tc_note' => 'new_relic_save'), true);
     }
 }
示例#13
0
 /**
  * Bad Behavior support
  * @return void
  */
 function _bad_behavior()
 {
     $bb_file = $this->_config->get_cache_option('pgcache.bad_behavior_path');
     if ($bb_file != '') {
         require_once $bb_file;
     }
 }
示例#14
0
 /**
  * Loads extensions stored in config
  */
 function load_extensions()
 {
     $extensions = $this->_config->get_array('extensions.active');
     foreach ($extensions as $extension => $path) {
         include W3TC_EXTENSION_DIR . '/' . trim($path, '/');
     }
 }
示例#15
0
 /**
  * Check
  * @throws FilesystemOperationException
  * @throws FileOperationException
  */
 public function update_ip_ranges()
 {
     w3_require_once(W3TC_INC_DIR . '/functions/http.php');
     $ip4_diff = $ip6_diff = false;
     $response = w3_http_get(W3TC_CLOUDFLARE_IP4_URL);
     $extensions_settings = $this->_config->get_array('extensions.settings', array());
     if (!is_wp_error($response)) {
         $ip4_data = $response['body'];
         $ip4_data = explode("\n", $ip4_data);
         $ip4_data_old = w3tc_get_extension_config('cloudflare', 'ips.ip4', $this->_config, array());
         if ($ip4_diff = array_diff($ip4_data, $ip4_data_old)) {
             $extensions_settings['cloudflare']['ips.ip4'] = $ip4_data;
             $this->_config->set('extensions.settings', $extensions_settings);
         }
     }
     $response = w3_http_get(W3TC_CLOUDFLARE_IP6_URL);
     if (!is_wp_error($response)) {
         $ip6_data = $response['body'];
         $ip6_data = explode("\n", $ip6_data);
         $ip6_data_old = w3tc_get_extension_config('cloudflare', 'ips.ip6', $this->_config, array());
         if ($ip6_diff = array_diff($ip6_data, $ip6_data_old)) {
             $extensions_settings['cloudflare']['ips.ip6'] = $ip6_data;
             $this->_config->set('extensions.settings', $extensions_settings);
         }
     }
     if ($ip4_diff || $ip6_diff) {
         try {
             $this->_config->save();
             $this->_config->refresh_cache();
         } catch (Exception $ex) {
         }
     }
 }
 /**
  * Returns minify cache object
  *
  * @return object
  */
 function &_get_cache()
 {
     static $cache = array();
     if (!isset($cache[0])) {
         switch ($this->_config->get_string('minify.engine')) {
             case 'memcached':
                 require_once W3TC_LIB_W3_DIR . '/Cache/Memcached.php';
                 require_once W3TC_LIB_MINIFY_DIR . '/Minify/Cache/Memcache.php';
                 $this->_memcached =& new W3_Cache_Memcached(array('servers' => $this->_config->get_array('minify.memcached.servers'), 'persistant' => $this->_config->get_boolean('minify.memcached.persistant')));
                 $cache[0] =& new Minify_Cache_Memcache($this->_memcached);
                 break;
             case 'apc':
                 require_once W3TC_LIB_MINIFY_DIR . '/Minify/Cache/APC.php';
                 $cache[0] =& new Minify_Cache_APC();
                 break;
             case 'eaccelerator':
                 require_once W3TC_LIB_MINIFY_DIR . '/Minify/Cache/Eaccelerator.php';
                 $cache[0] =& new Minify_Cache_Eaccelerator();
                 break;
             case 'xcache':
                 require_once W3TC_LIB_MINIFY_DIR . '/Minify/Cache/XCache.php';
                 $cache[0] =& new Minify_Cache_XCache();
                 break;
             case 'file':
             default:
                 require_once W3TC_LIB_MINIFY_DIR . '/Minify/Cache/File.php';
                 if (!is_dir(W3TC_CACHE_FILE_MINIFY_DIR)) {
                     $this->log(sprintf('Cache directory %s does not exist', W3TC_CACHE_FILE_MINIFY_DIR));
                 }
                 $cache[0] =& new Minify_Cache_File(W3TC_CACHE_FILE_MINIFY_DIR, $this->_config->get_boolean('minify.file.locking'));
                 break;
         }
     }
     return $cache[0];
 }
示例#17
0
 /**
  * Flush browsers cache
  */
 function flush_browser_cache()
 {
     if ($this->_config->get_boolean('browsercache.enabled')) {
         $this->_config->set('browsercache.timestamp', time());
         $this->_config->save();
     }
 }
示例#18
0
 /**
  * @throws Exception
  */
 function action_aws_sns_subscribe()
 {
     w3_require_once(W3TC_LIB_W3_DIR . '/Request.php');
     $topic_arn = W3_Request::get_string('cluster_messagebus_sns_topic_arn_subscribe');
     /**
      * @var W3_Enterprise_SnsClient $sns_client
      */
     $sns_client = w3_instance('W3_Enterprise_SnsClient');
     $sns_client->subscribe(plugins_url('pub/sns.php', W3TC_FILE), $topic_arn);
     try {
         $this->_config->set('cluster.messagebus.sns.topic_arn', $topic_arn);
         $this->_config->save();
     } catch (Exception $ex) {
         throw new Exception('<strong>Can\'t change configuration</strong>: ' . $ex->getMessage());
     }
     w3_admin_redirect(array('w3tc_note' => 'sns_subscribed'));
 }
示例#19
0
 /**
  * PHP5-style constructor
  */
 function __construct()
 {
     require_once W3TC_LIB_W3_DIR . '/Config.php';
     $config =& W3_Config::instance();
     $this->_debug = $config->get_boolean('varnish.debug');
     $this->_servers = $config->get_array('varnish.servers');
     $this->_timeout = $config->get_integer('timelimit.varnish_purge');
 }
示例#20
0
 private function _check_query_string()
 {
     $accept_qs = $this->_config->get_array('pgcache.accept.qs');
     foreach ($_GET as $key => $value) {
         if (!in_array(strtolower($key), $accept_qs)) {
             return false;
         }
     }
     return true;
 }
 /**
  * Checks if User Agent is mobile
  * 
  * @return boolean
  */
 function _is_mobile()
 {
     $mobile_agents = $this->_config->get_array('pgcache.mobile.agents');
     foreach ($mobile_agents as $mobile_agent) {
         if (stristr($_SERVER['HTTP_USER_AGENT'], $mobile_agent) !== false) {
             return true;
         }
     }
     return false;
 }
 /**
  * Save support us action
  *
  * @return void
  */
 function action_config_save_support_us()
 {
     $support = W3_Request::get_string('support');
     $tweeted = W3_Request::get_boolean('tweeted');
     $this->_config->set('common.support', $support);
     $this->_config->set('common.tweeted', $tweeted);
     $this->_config->save();
     w3_instance('W3_AdminLinks')->link_update($this->_config);
     w3_admin_redirect(array('w3tc_note' => 'config_save'));
 }
示例#23
0
 function action_cdn_save_activate()
 {
     w3_require_once(W3TC_INC_FUNCTIONS_DIR . '/ui.php');
     try {
         $this->_config->set('cdn.enabled', true);
         $this->_config->save();
     } catch (Exception $ex) {
     }
     w3_redirect(w3_admin_url(sprintf('admin.php?page=w3tc_cdn#configuration')));
 }
示例#24
0
 function generate()
 {
     $pages = array('w3tc_dashboard' => array(__('Dashboard', 'w3-total-cache'), __('Dashboard', 'w3-total-cache'), 'network_show' => true), 'w3tc_general' => array(__('General Settings', 'w3-total-cache'), __('General Settings', 'w3-total-cache'), 'network_show' => false), 'w3tc_pgcache' => array(__('Page Cache', 'w3-total-cache'), __('Page Cache', 'w3-total-cache'), 'network_show' => false), 'w3tc_minify' => array(__('Minify', 'w3-total-cache'), __('Minify', 'w3-total-cache'), 'network_show' => false), 'w3tc_dbcache' => array(__('Database Cache', 'w3-total-cache'), __('Database Cache', 'w3-total-cache'), 'network_show' => false), 'w3tc_objectcache' => array(__('Object Cache', 'w3-total-cache'), __('Object Cache', 'w3-total-cache'), 'network_show' => false));
     if (w3_is_pro($this->_config) || w3_is_enterprise($this->_config)) {
         $pages['w3tc_fragmentcache'] = array(__('Fragment Cache', 'w3-total-cache'), __('Fragment Cache', 'w3-total-cache'), 'network_show' => false);
     }
     $pages = array_merge($pages, array('w3tc_browsercache' => array(__('Browser Cache', 'w3-total-cache'), __('Browser Cache', 'w3-total-cache'), 'network_show' => false), 'w3tc_mobile' => array(__('User Agent Groups', 'w3-total-cache'), __('User Agent Groups', 'w3-total-cache'), 'network_show' => false), 'w3tc_referrer' => array(__('Referrer Groups', 'w3-total-cache'), __('Referrer Groups', 'w3-total-cache'), 'network_show' => false), 'w3tc_cdn' => array(__('Content Delivery Network', 'w3-total-cache'), __('<acronym title="Content Delivery Network">CDN</acronym>', 'w3-total-cache'), 'network_show' => $this->_config->get_boolean('cdn.enabled')), 'w3tc_monitoring' => array(__('Monitoring', 'w3-total-cache'), __('Monitoring', 'w3-total-cache'), 'network_show' => false)));
     $pages_tail = array('w3tc_faq' => array(__('FAQ', 'w3-total-cache'), __('FAQ', 'w3-total-cache'), 'network_show' => true), 'w3tc_support' => array(__('Support', 'w3-total-cache'), __('<span style="color: red;">Support</span>', 'w3-total-cache'), 'network_show' => true), 'w3tc_install' => array(__('Install', 'w3-total-cache'), __('Install', 'w3-total-cache'), 'network_show' => false), 'w3tc_about' => array(__('About', 'w3-total-cache'), __('About', 'w3-total-cache'), 'network_show' => true));
     $pages = apply_filters('w3tc_menu', $pages, $this->_config, $this->_config_admin);
     $pages = array_merge($pages, $pages_tail);
     add_menu_page(__('Performance', 'w3-total-cache'), __('Performance', 'w3-total-cache'), 'manage_options', 'w3tc_dashboard', '', 'div');
     $submenu_pages = array();
     foreach ($pages as $slug => $titles) {
         if ($this->_config_admin->get_boolean('common.visible_by_master_only') && $titles['network_show'] || (!$this->_config_admin->get_boolean('common.visible_by_master_only') || is_super_admin() && (!w3_force_master() || is_network_admin()))) {
             $submenu_pages[] = add_submenu_page('w3tc_dashboard', $titles[0] . ' | W3 Total Cache', $titles[1], 'manage_options', $slug, array(&$this, 'options'));
         }
     }
     return $submenu_pages;
 }
示例#25
0
 public function run()
 {
     $this->_config = w3_instance('W3_Config');
     $this->_config_admin = w3_instance('W3_ConfigAdmin');
     w3_require_once(W3TC_INC_FUNCTIONS_DIR . '/admin.php');
     w3_require_once(W3TC_INC_FUNCTIONS_DIR . '/admin_ui.php');
     $this->_page = w3tc_get_current_page();
     if (is_network_admin() || !w3_is_multisite()) {
         $this->edge_notification();
     }
     if (is_w3tc_admin_page()) {
         add_action('admin_head', array($this, 'admin_head'));
         add_action('w3tc_hide_button_custom-edge_mode', array($this, 'hide_edge_mode_notification'));
         $support_reminder = $this->_config->get_boolean('notes.support_us') && $this->_config_admin->get_integer('common.install') < time() - W3TC_SUPPORT_US_TIMEOUT && $this->_config->get_string('common.support') == '' && !$this->_config->get_boolean('common.tweeted');
         if ($support_reminder || w3tc_show_notification('support_us_popup')) {
             add_action('w3tc-dashboard-head', array($this, 'support_us_nag'));
         }
         add_action('w3tc-dashboard-head', array($this, 'edge_nag'));
     }
 }
 /**
  * Purge the CloudFlare cache
  * @return void
  */
 function flush_cloudflare()
 {
     $response = null;
     w3_require_once(W3TC_LIB_W3_DIR . '/Request.php');
     $email = $this->_config->get_string('email');
     $key = $this->_config->get_string('key');
     $zone = $this->_config->get_string('zone');
     if ($email && $key && $zone) {
         $config = array('email' => $email, 'key' => $key, 'zone' => $zone);
         w3_require_once(W3TC_LIB_W3_DIR . '/CloudFlare.php');
         @($w3_cloudflare = new W3_CloudFlare($config));
         $w3_cloudflare->purge();
     }
 }
示例#27
0
 /**
  * Returns minifier options
  *
  * @param string $engine
  * @return array
  */
 function get_options($engine)
 {
     $options = array();
     switch ($engine) {
         case 'js':
             $options = array('preserveComments' => !$this->_config->get_boolean('minify.js.strip.comments'), 'stripCrlf' => $this->_config->get_boolean('minify.js.strip.crlf'));
             break;
         case 'css':
             $options = array('preserveComments' => !$this->_config->get_boolean('minify.css.strip.comments'), 'stripCrlf' => $this->_config->get_boolean('minify.css.strip.crlf'));
             $symlinks = $this->_config->get_array('minify.symlinks');
             foreach ($symlinks as $link => $target) {
                 $link = str_replace('//', realpath($_SERVER['DOCUMENT_ROOT']), $link);
                 $link = strtr($link, '/', DIRECTORY_SEPARATOR);
                 $options['symlinks'][$link] = realpath($target);
             }
             break;
         case 'yuijs':
             $options = array('line-break' => $this->_config->get_integer('minify.yuijs.options.line-break'), 'nomunge' => $this->_config->get_boolean('minify.yuijs.options.nomunge'), 'preserve-semi' => $this->_config->get_boolean('minify.yuijs.options.preserve-semi'), 'disable-optimizations' => $this->_config->get_boolean('minify.yuijs.options.disable-optimizations'));
             break;
         case 'yuicss':
             $options = array('line-break' => $this->_config->get_integer('minify.yuicss.options.line-break'));
             break;
         case 'ccjs':
             $options = array('compilation_level' => $this->_config->get_string('minify.ccjs.options.compilation_level'), 'formatting' => $this->_config->get_string('minify.ccjs.options.formatting'));
             break;
         case 'csstidy':
             $options = array('remove_bslash' => $this->_config->get_boolean('minify.csstidy.options.remove_bslash'), 'compress_colors' => $this->_config->get_boolean('minify.csstidy.options.compress_colors'), 'compress_font-weight' => $this->_config->get_boolean('minify.csstidy.options.compress_font-weight'), 'lowercase_s' => $this->_config->get_boolean('minify.csstidy.options.lowercase_s'), 'optimise_shorthands' => $this->_config->get_integer('minify.csstidy.options.optimise_shorthands'), 'remove_last_;' => $this->_config->get_boolean('minify.csstidy.options.remove_last_;'), 'case_properties' => $this->_config->get_integer('minify.csstidy.options.case_properties'), 'sort_properties' => $this->_config->get_boolean('minify.csstidy.options.sort_properties'), 'sort_selectors' => $this->_config->get_boolean('minify.csstidy.options.sort_selectors'), 'merge_selectors' => $this->_config->get_integer('minify.csstidy.options.merge_selectors'), 'discard_invalid_properties' => $this->_config->get_boolean('minify.csstidy.options.discard_invalid_properties'), 'css_level' => $this->_config->get_string('minify.csstidy.options.css_level'), 'preserve_css' => $this->_config->get_boolean('minify.csstidy.options.preserve_css'), 'timestamp' => $this->_config->get_boolean('minify.csstidy.options.timestamp'), 'template' => $this->_config->get_string('minify.csstidy.options.template'));
             break;
         case 'html':
         case 'htmlxml':
             $options = array('xhtml' => true, 'stripCrlf' => $this->_config->get_boolean('minify.html.strip.crlf'), 'ignoredComments' => $this->_config->get_array('minify.html.comments.ignore'));
             break;
         case 'htmltidy':
         case 'htmltidyxml':
             $options = array('clean' => $this->_config->get_boolean('minify.htmltidy.options.clean'), 'hide-comments' => $this->_config->get_boolean('minify.htmltidy.options.hide-comments'), 'wrap' => $this->_config->get_integer('minify.htmltidy.options.wrap'));
             break;
     }
     if ($this->_config->get_boolean('browsercache.enabled') && ($this->_config->get_boolean('browsercache.cssjs.replace') || $this->_config->get_boolean('browsercache.html.replace') || $this->_config->get_boolean('browsercache.other.replace'))) {
         $w3_plugin_browsercache = w3_instance('W3_Plugin_BrowserCache');
         $options = array_merge($options, array('browserCacheId' => $w3_plugin_browsercache->get_replace_id(), 'browserCacheExtensions' => $w3_plugin_browsercache->get_replace_extensions()));
     }
     if ($this->_config->get_boolean('cdn.enabled') && $this->_config->get_boolean('cdn.minify.enable')) {
         $w3_plugin_cdn = w3_instance('W3_Plugin_CdnCommon');
         $cdn = $w3_plugin_cdn->get_cdn();
         $options = array_merge($options, array('prependAbsolutePathCallback' => array(&$cdn, 'get_prepend_path')));
     }
     return $options;
 }
示例#28
0
 /**
  * Returns debug info
  *
  * @return string
  */
 function _get_debug_info()
 {
     $debug_info = "<!-- W3 Total Cache: Object Cache debug info:\r\n";
     $debug_info .= sprintf("%s%s\r\n", str_pad('Engine: ', 20), w3_get_engine_name($this->_config->get_string('objectcache.engine')));
     $debug_info .= sprintf("%s%d\r\n", str_pad('Total calls: ', 20), $this->cache_total);
     $debug_info .= sprintf("%s%d\r\n", str_pad('Cache hits: ', 20), $this->cache_hits);
     $debug_info .= sprintf("%s%d\r\n", str_pad('Cache misses: ', 20), $this->cache_misses);
     $debug_info .= sprintf("%s%.4f\r\n", str_pad('Total time: ', 20), $this->time_total);
     $debug_info .= "W3TC Object Cache info:\r\n";
     $debug_info .= sprintf("%s | %s | %s | %s | %s | %s | %s\r\n", str_pad('#', 5, ' ', STR_PAD_LEFT), str_pad('Caching (Reject reason)', 30, ' ', STR_PAD_BOTH), str_pad('Status', 15, ' ', STR_PAD_BOTH), str_pad('Source', 15, ' ', STR_PAD_BOTH), str_pad('Data size (b)', 13, ' ', STR_PAD_LEFT), str_pad('Query time (s)', 14, ' ', STR_PAD_LEFT), 'ID:Group');
     foreach ($this->debug_info as $index => $debug) {
         $debug_info .= sprintf("%s | %s | %s | %s | %s | %s | %s\r\n", str_pad($index + 1, 5, ' ', STR_PAD_LEFT), str_pad($debug['caching'] ? 'enabled' : sprintf('disabled (%s)', $debug['reason']), 30, ' ', STR_PAD_BOTH), str_pad($debug['cached'] ? 'cached' : 'not cached', 15, ' ', STR_PAD_BOTH), str_pad($debug['internal'] ? 'internal' : 'persistent', 15, ' ', STR_PAD_BOTH), str_pad($debug['data_size'], 13, ' ', STR_PAD_LEFT), str_pad(round($debug['time'], 4), 14, ' ', STR_PAD_LEFT), sprintf('%s:%s', $debug['id'], $debug['group']));
     }
     $debug_info .= '-->';
     return $debug_info;
 }
示例#29
0
 /**
  * @param $cf_values
  * @return bool
  */
 public function save_settings($cf_values)
 {
     @set_time_limit($this->_config->get_integer('timelimit.cloudflare_api_request'));
     ksort($cf_values);
     $cf_values = $this->_cleanup_settings($cf_values);
     foreach ($cf_values as $key => $settings) {
         if ($settings['old'] != $settings['new']) {
             $response = $this->api_request($key, $settings['new']);
             if (!$response || $response && $response->result != 'success') {
                 return false;
             }
         }
     }
     delete_transient('w3tc_cloudflare_settings');
     return true;
 }
示例#30
0
 /**
  * Uncompresses a minify auto filename into an array of files.
  * @param $compressed
  * @param $type
  * @return array
  */
 function uncompress_minify_files($compressed, $type)
 {
     $no_type_files = array();
     $compressed = basename($compressed, '.' . $type);
     $uncompressed = $this->_uncompress(base64_decode(strtr($compressed, '-_', '+/')));
     $exploded = explode(',', $uncompressed);
     $replacements = $this->_minify_path_replacements();
     foreach ($exploded as $file) {
         if (!w3_is_url($file)) {
             $prefix = substr($file, 0, 1);
             $after_pre = substr($file, 1, 1);
             if (isset($replacements[$prefix]) && $after_pre == '/') {
                 $file = $replacements[$prefix] . substr($file, 1);
                 $no_type_files[] = $file;
             } else {
                 $no_type_files[] = $file;
             }
         } else {
             $no_type_files[] = $file;
         }
     }
     $files = array();
     foreach ($no_type_files as $no_type_file) {
         $file = !w3_is_url($no_type_file) ? $no_type_file . '.' . $type : $no_type_file;
         $verified = false;
         if (w3_is_url($file)) {
             $external = $this->_config->get_array('minify.cache.files');
             foreach ($external as $ext) {
                 if (preg_match('#' . w3_get_url_regexp($ext) . '#', $file) && !$verified) {
                     $verified = true;
                 }
             }
             if (!$verified) {
                 $this->error(sprintf('Remote file not in external files/libraries list: "%s"', $file));
             }
         } elseif (strpos($file, '..') != false || strpos($file, '//') !== false || strpos($file, '\\') !== false && strtoupper(substr(PHP_OS, 0, 3)) != 'WIN' || preg_match('/(?:^|[^\\.])\\.\\//', $file) || !preg_match('/^[a-zA-Z0-9_.\\/-]|[\\\\]+$/', $file)) {
             $verified = false;
             $this->error(sprintf('File path invalid: "%s"', $file));
         } else {
             $verified = true;
         }
         if ($verified) {
             $files[] = $file;
         }
     }
     return $files;
 }