Пример #1
0
 /**
  * Fixes environment
  *
  * @param Config  $config
  * @throws Util_Environment_Exceptions
  */
 function fix_in_wpadmin($config, $force_all_checks = false)
 {
     $exs = new Util_Environment_Exceptions();
     $fix_on_event = false;
     if (Util_Environment::is_wpmu() && Util_Environment::blog_id() != 0) {
         if (get_transient('w3tc_config_changes') != ($md5_string = $config->get_md5())) {
             $fix_on_event = true;
             set_transient('w3tc_config_changes', $md5_string, 3600);
         }
     }
     // call plugin-related handlers
     foreach ($this->get_handlers($config) as $h) {
         try {
             $h->fix_on_wpadmin_request($config, $force_all_checks);
             if ($fix_on_event) {
                 $this->fix_on_event($config, 'admin_request');
             }
         } catch (Util_Environment_Exceptions $ex) {
             $exs->push($ex);
         }
     }
     try {
         do_action('w3tc_environment_fix_on_wpadmin_request', $config, $force_all_checks);
     } catch (Util_Environment_Exceptions $ex) {
         $exs->push($ex);
     }
     if (count($exs->exceptions()) > 0) {
         throw $exs;
     }
 }
Пример #2
0
 /**
  * Returns object instance. Called by WP engine
  *
  * @return DbCache_Wpdb
  */
 static function instance()
 {
     static $instance = null;
     if (is_null($instance)) {
         $processors = array();
         $call_default_constructor = true;
         // no caching during activation
         $is_installing = defined('WP_INSTALLING') && WP_INSTALLING;
         $config = Dispatcher::config();
         if (!$is_installing && $config->get_boolean('dbcache.enabled')) {
             $processors[] = new DbCache_WpdbInjection_QueryCaching();
         }
         if (Util_Environment::is_dbcluster()) {
             $processors[] = new Enterprise_Dbcache_WpdbInjection_Cluster();
         }
         $processors[] = new DbCache_WpdbInjection();
         $class = __CLASS__;
         $o = new $class($processors);
         $next_injection = new _CallUnderlying($o);
         foreach ($processors as $processor) {
             $processor->initialize_injection($o, $next_injection);
         }
         // initialize after processors configured
         $o->initialize();
         $instance = $o;
     }
     return $instance;
 }
 /**
  * General tab
  *
  * @return void
  */
 function view()
 {
     global $current_user;
     $config_master = $this->_config_master;
     /**
      *
      *
      * @var $modules W3_ModuleStatus
      */
     $modules = Dispatcher::component('ModuleStatus');
     $pgcache_enabled = $modules->is_enabled('pgcache');
     $dbcache_enabled = $modules->is_enabled('dbcache');
     $objectcache_enabled = $modules->is_enabled('objectcache');
     $browsercache_enabled = $modules->is_enabled('browsercache');
     $minify_enabled = $modules->is_enabled('minify');
     $cdn_enabled = $modules->is_enabled('cdn');
     $varnish_enabled = $modules->is_enabled('varnish');
     $enabled = $modules->plugin_is_enabled();
     $enabled_checkbox = $modules->all_modules_enabled();
     $check_rules = Util_Rule::can_check_rules();
     $disc_enhanced_enabled = !(!$check_rules || !$this->is_master() && Util_Environment::is_wpmu() && $config_master->get_string('pgcache.engine') != 'file_generic');
     $can_empty_file = $modules->can_empty_file();
     $can_empty_varnish = $modules->can_empty_varnish();
     $cdn_mirror_purge = Cdn_Util::can_purge_all($modules->get_module_engine('cdn'));
     $file_nfs = $this->_config->get_boolean('pgcache.file.nfs') || $this->_config->get_boolean('minify.file.nfs');
     $file_locking = $this->_config->get_boolean('dbcache.file.locking') || $this->_config->get_boolean('objectcache.file.locking') || $this->_config->get_boolean('pgcache.file.locking') || $this->_config->get_boolean('minify.file.locking');
     $licensing_visible = (!Util_Environment::is_wpmu() || is_network_admin()) && !ini_get('w3tc.license_key') && get_transient('w3tc_license_status') != 'host_valid';
     $custom_areas = apply_filters("w3tc_settings_general_anchors", array());
     include W3TC_INC_DIR . '/options/general.php';
 }
Пример #4
0
 /**
  * Return full path to log file for module
  * Path used in priority
  * 1) W3TC_DEBUG_DIR
  * 2) WP_DEBUG_LOG
  * 3) W3TC_CACHE_DIR
  *
  * @param unknown $module
  * @param null    $blog_id
  * @return string
  */
 public static function log_filename($module, $blog_id = null)
 {
     if (is_null($blog_id)) {
         $blog_id = Util_Environment::blog_id();
     }
     $postfix = sprintf('%06d', $blog_id);
     if (defined('W3TC_BLOG_LEVELS')) {
         for ($n = 0; $n < W3TC_BLOG_LEVELS; $n++) {
             $postfix = substr($postfix, strlen($postfix) - 1 - $n, 1) . '/' . $postfix;
         }
     }
     $from_dir = W3TC_CACHE_DIR;
     if (defined('W3TC_DEBUG_DIR') && W3TC_DEBUG_DIR) {
         $dir_path = W3TC_DEBUG_DIR;
         if (!is_dir(W3TC_DEBUG_DIR)) {
             $from_dir = dirname(W3TC_DEBUG_DIR);
         }
     } else {
         $dir_path = Util_Environment::cache_dir('log');
     }
     $filename = $dir_path . '/' . $postfix . '/' . $module . '.log';
     if (!is_dir(dirname($filename))) {
         Util_File::mkdir_from(dirname($filename), $from_dir);
     }
     return $filename;
 }
 public function w3tc_config_save($config)
 {
     // frontend activity
     $engine = $config->get_string(array('fragmentcache', 'engine'));
     $is_frontend_active = !empty($engine) && Util_Environment::is_w3tc_pro($config);
     $config->set_extension_active_frontend('fragmentcache', $is_frontend_active);
 }
Пример #6
0
 /**
  * Returns blog_id by home url
  * If database not initialized yet - returns 0
  *
  * @return integer
  */
 public static function get_current_blog_data()
 {
     $host = Util_Environment::host();
     // subdomain
     if (Util_Environment::is_wpmu_subdomain()) {
         $blog_data = Util_WpmuBlogmap::try_get_current_blog_data($host);
         if (is_null($blog_data)) {
             $GLOBALS['w3tc_blogmap_register_new_item'] = $host;
         }
         return $blog_data;
     } else {
         // try subdir blog
         $url = $host . $_SERVER['REQUEST_URI'];
         $pos = strpos($url, '?');
         if ($pos !== false) {
             $url = substr($url, 0, $pos);
         }
         $url = rtrim($url, '/');
         $start_url = $url;
         for (;;) {
             $blog_data = Util_WpmuBlogmap::try_get_current_blog_data($url);
             if (!is_null($blog_data)) {
                 return $blog_data;
             }
             $pos = strrpos($url, '/');
             if ($pos === false) {
                 break;
             }
             $url = rtrim(substr($url, 0, $pos), '/');
         }
         $GLOBALS['w3tc_blogmap_register_new_item'] = $start_url;
         return null;
     }
 }
 function run()
 {
     add_filter('w3tc_config_default_values', array($this, 'w3tc_config_default_values'));
     add_action('w3tc_register_fragment_groups', array($this, 'register_groups'));
     $this->_config = Dispatcher::config();
     if (Util_Environment::is_w3tc_pro($this->_config)) {
         if (!is_admin()) {
             /**
              * Register the caching of content to specific hooks
              */
             foreach (array('genesis_header', 'genesis_footer', 'genesis_sidebar', 'genesis_loop', 'wp_head', 'wp_footer', 'genesis_comments', 'genesis_pings') as $hook) {
                 add_action($hook, array($this, 'cache_genesis_start'), -999999999);
                 add_action($hook, array($this, 'cache_genesis_end'), 999999999);
             }
             foreach (array('genesis_do_subnav', 'genesis_do_nav') as $filter) {
                 add_filter($filter, array($this, 'cache_genesis_filter_start'), -999999999);
                 add_filter($filter, array($this, 'cache_genesis_filter_end'), 999999999);
             }
         }
         /**
          * Since posts pages etc are cached individually need to be able to flush just those and not all fragment
          */
         add_action('clean_post_cache', array($this, 'flush_post_fragment'));
         add_action('clean_post_cache', array($this, 'flush_terms_fragment'), 0, 0);
         $this->_request_uri = $_SERVER['REQUEST_URI'];
     }
 }
Пример #8
0
 /**
  * Do logic
  */
 function process()
 {
     /**
      * Skip some pages
      */
     switch (true) {
         case defined('DOING_AJAX'):
         case defined('DOING_CRON'):
         case defined('APP_REQUEST'):
         case defined('XMLRPC_REQUEST'):
         case defined('WP_ADMIN'):
         case defined('SHORTINIT') && SHORTINIT:
             return;
     }
     /**
      * Handle mobile or referrer redirects
      */
     if ($this->_mobile || $this->_referrer) {
         $mobile_redirect = $referrer_redirect = '';
         if ($this->_mobile) {
             $mobile_redirect = $this->_mobile->get_redirect();
         }
         if ($this->_referrer) {
             $referrer_redirect = $this->_referrer->get_redirect();
         }
         $redirect = $mobile_redirect ? $mobile_redirect : $referrer_redirect;
         if ($redirect) {
             Util_Environment::redirect($redirect);
             exit;
         }
     }
 }
 /**
  * Print JS required by the support nag.
  */
 function admin_head()
 {
     $state = Dispatcher::config_state_master();
     // support us
     $support_reminder = $state->get_integer('common.support_us_invitations') < 3 && $state->get_integer('common.install') < time() - W3TC_SUPPORT_US_TIMEOUT && $state->get_integer('common.next_support_us_invitation') < time() && $this->_config->get_string('common.support') == '' && !$this->_config->get_boolean('common.tweeted');
     if ($support_reminder) {
         $state->set('common.next_support_us_invitation', time() + W3TC_SUPPORT_US_TIMEOUT);
         $state->set('common.support_us_invitations', $state->get_integer('common.support_us_invitations') + 1);
         $state->save();
         do_action('w3tc_message_action_generic_support_us');
     }
     // edge mode
     $edge_reminder = !$support_reminder && !Util_Environment::is_w3tc_edge($this->_config) && $state->get_integer('common.edge_invitations') < 3 && $state->get_integer('common.install') < time() - W3TC_EDGE_TIMEOUT && $state->get_integer('common.next_edge_invitation') < time();
     if ($edge_reminder) {
         if ($state->get_integer('common.edge_invitations') > 1) {
             $next = time() + 30 * 24 * 60 * 60;
         } else {
             $next = time() + W3TC_EDGE_TIMEOUT;
         }
         $state->set('common.next_edge_invitation', $next);
         $state->set('common.edge_invitations', $state->get_integer('common.edge_invitations') + 1);
         $state->save();
         do_action('w3tc_message_action_generic_edge');
     }
 }
Пример #10
0
 /**
  * Constructor
  *
  * @param array   $config
  */
 function __construct($config = array())
 {
     parent::__construct($config);
     if (isset($config['cache_dir'])) {
         $this->_cache_dir = trim($config['cache_dir']);
     } else {
         $this->_cache_dir = Util_Environment::cache_blog_dir($config['section'], $config['blog_id']);
     }
     $this->_exclude = isset($config['exclude']) ? (array) $config['exclude'] : array();
     $this->_flush_timelimit = isset($config['flush_timelimit']) ? (int) $config['flush_timelimit'] : 180;
     $this->_locking = isset($config['locking']) ? (bool) $config['locking'] : false;
     if (isset($config['flush_dir'])) {
         $this->_flush_dir = $config['flush_dir'];
     } else {
         if ($config['blog_id'] <= 0 && !isset($config['cache_dir'])) {
             // clear whole section if we operate on master cache
             // and in a mode when cache_dir not strictly specified
             $this->_flush_dir = Util_Environment::cache_dir($config['section']);
         } else {
             $this->_flush_dir = $this->_cache_dir;
         }
     }
     if (isset($config['use_wp_hash']) && $config['use_wp_hash']) {
         $this->_use_wp_hash = true;
     }
 }
 public function admin_init()
 {
     $config = Dispatcher::config();
     $groups = $config->get_array('mobile.rgroups');
     if (Util_Environment::is_w3tc_edge($config) && isset($groups['google']) && sizeof($groups['google']['agents']) == 1 && $groups['google']['agents'][0] == 'googlebot') {
         w3tc_delete_user_agent_group('google');
     }
 }
Пример #12
0
 public static function get_suggested_home_ip()
 {
     $ip = gethostbyname(Util_Environment::home_url_host());
     // check if it resolves to local IP, means host cant know its real IP
     if (substr($ip, 0, 4) == '127.' || substr($ip, 0, 3) == '10.' || substr($ip, 0, 8) == '192.168.') {
         return '';
     }
     return $ip;
 }
Пример #13
0
 /**
  * Make API request
  *
  * @param string  $url
  * @return string
  */
 function _request($url)
 {
     $request_url = Util_Environment::url_format(W3TC_PAGESPEED_API_URL, array('url' => $url, 'key' => $this->key));
     $response = Util_Http::get($request_url, array('timeout' => 120));
     if (!is_wp_error($response) && $response['response']['code'] == 200) {
         return $response['body'];
     }
     return false;
 }
Пример #14
0
 /**
  * Returns cache engine instance
  *
  * @param string  $engine
  * @param array   $config
  * @return W3_Cache_Base
  */
 static function instance($engine, $config = array())
 {
     static $instances = array();
     // common configuration data
     if (!isset($config['blog_id'])) {
         $config['blog_id'] = Util_Environment::blog_id();
     }
     $instance_key = sprintf('%s_%s', $engine, md5(serialize($config)));
     if (!isset($instances[$instance_key])) {
         switch ($engine) {
             case 'apc':
                 if (function_exists('apcu_store')) {
                     $instances[$instance_key] = new Cache_Apcu($config);
                 } else {
                     if (function_exists('apc_store')) {
                         $instances[$instance_key] = new Cache_Apc($config);
                     }
                 }
                 break;
             case 'eaccelerator':
                 $instances[$instance_key] = new Cache_Eaccelerator($config);
                 break;
             case 'file':
                 $instances[$instance_key] = new Cache_File($config);
                 break;
             case 'file_generic':
                 $instances[$instance_key] = new Cache_File_Generic($config);
                 break;
             case 'memcached':
                 if (class_exists('\\Memcached')) {
                     $instances[$instance_key] = new Cache_Memcached($config);
                 } else {
                     if (class_exists('\\Memcache')) {
                         $instances[$instance_key] = new Cache_Memcache($config);
                     }
                 }
                 break;
             case 'redis':
                 $instances[$instance_key] = new Cache_Redis($config);
                 break;
             case 'wincache':
                 $instances[$instance_key] = new Cache_Wincache($config);
                 break;
             case 'xcache':
                 $instances[$instance_key] = new Cache_Xcache($config);
                 break;
             default:
                 trigger_error('Incorrect cache engine ' . $engine, E_USER_WARNING);
                 $instances[$instance_key] = new Cache_Base($config);
                 break;
         }
         if (!isset($instances[$instance_key]) || !$instances[$instance_key]->available()) {
             $instances[$instance_key] = new Cache_Base($config);
         }
     }
     return $instances[$instance_key];
 }
Пример #15
0
 /**
  * Returns origin
  *
  * @return string
  */
 function _get_origin()
 {
     if ($this->type == W3TC_CDN_CF_TYPE_S3) {
         $origin = sprintf('%s.s3.amazonaws.com', $this->_config['bucket']);
     } else {
         $origin = Util_Environment::host_port();
     }
     return $origin;
 }
 function action_payment_code()
 {
     $request_type = Util_Request::get_string('request_type');
     $request_id = date('YmdHi');
     $return_url = admin_url('admin.php?page=w3tc_support&request_type=' . $request_type . '&payment=1&request_id=' . $request_id);
     $cancel_url = admin_url('admin.php?page=w3tc_dashboard');
     $form_values = array("cmd" => "_xclick", "business" => W3TC_PAYPAL_BUSINESS, "item_name" => esc_attr(sprintf('%s: %s (#%s)', ucfirst(Util_Environment::host()), $this->_json_request_types[$request_type], $request_id)), "amount" => sprintf('%.2f', $this->_request_prices[$request_type]), "currency_code" => "USD", "no_shipping" => "1", "rm" => "2", "return" => esc_attr($return_url), "cancel_return" => esc_attr($cancel_url));
     echo json_encode($form_values);
     die;
 }
Пример #17
0
 public static function minified_url($minify_filename)
 {
     $path = Util_Environment::cache_blog_minify_dir();
     $filename = $path . '/' . $minify_filename;
     $c = Dispatcher::config();
     if (Util_Rule::can_check_rules() && $c->get_boolean('minify.rewrite')) {
         return Util_Environment::filename_to_url($filename);
     }
     return network_site_url('?w3tc_minify=' . $minify_filename);
 }
Пример #18
0
 /**
  * Database cluster config editor
  *
  * @return void
  */
 function dbcluster_config()
 {
     $this->_page = 'w3tc_dbcluster_config';
     if (Util_Environment::is_dbcluster()) {
         $content = @file_get_contents(W3TC_FILE_DB_CLUSTER_CONFIG);
     } else {
         $content = @file_get_contents(W3TC_DIR . '/ini/dbcluster-config-sample.php');
     }
     include W3TC_INC_OPTIONS_DIR . '/enterprise/dbcluster-config.php';
 }
 function widget_form()
 {
     $storage = new UsageStatistics_StorageReader();
     $summary_promise = $storage->get_history_summary_promise();
     $c = Dispatcher::config();
     if ($c->get_boolean('stats.enabled') && Util_Environment::is_w3tc_pro($c)) {
         include W3TC_DIR . '/UsageStatistics_Widget_View.php';
     } else {
         include W3TC_DIR . '/UsageStatistics_Widget_View_Disabled.php';
     }
 }
 function cleanup()
 {
     $c = Dispatcher::config();
     $engine = $c->get_string(array('fragmentcache', 'engine'));
     switch ($engine) {
         case 'file':
             $w3_cache_file_cleaner = new Cache_File_Cleaner(array('cache_dir' => Util_Environment::cache_blog_dir('fragment'), 'clean_timelimit' => $c->get_integer('timelimit.cache_gc')));
             $w3_cache_file_cleaner->clean();
             break;
     }
 }
Пример #21
0
 /**
  * Parses FAQ XML file into array
  *
  * @return array
  */
 public static function parse()
 {
     $config = Dispatcher::config();
     $faq = array();
     self::parse_file($faq, 'faq', '', '');
     if (Util_Environment::is_w3tc_edge($config)) {
         self::parse_file($faq, 'faq-edge', 'edge', '<b>Edge:</b> ');
     }
     if (Util_Environment::is_w3tc_pro($config)) {
         self::parse_file($faq, 'faq-pro', 'pro', '<b>Pro:</b> ');
     }
     return $faq;
 }
Пример #22
0
 public function w3tc_settings_general_boxarea_cdn()
 {
     $config = Dispatcher::config();
     $engine_optgroups = array();
     $engine_values = array();
     $is_fsd = Util_Environment::is_w3tc_pro($config);
     if ($is_fsd) {
         $engine_optgroups[] = __('Full Site Delivery:', 'w3-total-cache');
         $engine_values['cloudfront_fsd'] = array('label' => __('Amazon CloudFront', 'w3-total-cache'), 'optgroup' => 0);
         $engine_values['maxcdn_fsd'] = array('label' => __('MaxCDN (recommended)', 'w3-total-cache'), 'optgroup' => 0);
         $optgroup_pull = count($engine_optgroups);
         $engine_optgroups[] = __('Origin Pull / Mirror:', 'w3-total-cache');
     } else {
         $optgroup_pull = count($engine_optgroups);
         $engine_optgroups[] = __('Origin Pull / Mirror:', 'w3-total-cache');
     }
     $optgroup_push = count($engine_optgroups);
     $engine_optgroups[] = __('Origin Push:', 'w3-total-cache');
     $engine_values['akamai'] = array('label' => __('Akamai', 'w3-total-cache'), 'optgroup' => $optgroup_pull);
     $engine_values['cf2'] = array('label' => __('Amazon CloudFront', 'w3-total-cache'), 'disabled' => !Util_Installed::curl() ? true : null, 'optgroup' => $optgroup_pull);
     $engine_values['att'] = array('label' => __('AT&amp;T', 'w3-total-cache'), 'optgroup' => $optgroup_pull);
     $engine_values['cotendo'] = array('label' => __('Cotendo (Akamai)', 'w3-total-cache'), 'optgroup' => $optgroup_pull);
     $engine_values['mirror'] = array('label' => __('Generic Mirror', 'w3-total-cache'), 'optgroup' => $optgroup_pull);
     $engine_values['highwinds'] = array('label' => __('Highwinds', 'w3-total-cache'), 'optgroup' => $optgroup_pull);
     $engine_values['maxcdn'] = array('label' => __('MaxCDN', 'w3-total-cache'), 'optgroup' => $optgroup_pull);
     $engine_values['netdna'] = array('label' => __('MaxCDN Enterprise (NetDNA)', 'w3-total-cache'), 'optgroup' => $optgroup_pull);
     $engine_values['rackspace_cdn'] = array('label' => __('RackSpace CDN', 'w3-total-cache'), 'optgroup' => $optgroup_pull);
     $engine_values['edgecast'] = array('label' => __('Verizon Digital Media Services (EdgeCast) / Media Temple ProCDN', 'w3-total-cache'), 'optgroup' => $optgroup_pull);
     $engine_values['cf'] = array('disabled' => !Util_Installed::curl() ? true : null, 'label' => __('Amazon CloudFront', 'w3-total-cache'), 'optgroup' => $optgroup_push);
     $engine_values['s3'] = array('disabled' => !Util_Installed::curl() ? true : null, 'label' => __('Amazon Simple Storage Service (S3)', 'w3-total-cache'), 'optgroup' => $optgroup_push);
     $engine_values['s3_compatible'] = array('disabled' => !Util_Installed::curl() ? true : null, 'label' => __('Amazon Simple Storage Service (S3) Compatible', 'w3-total-cache'), 'optgroup' => $optgroup_push);
     $engine_values['google_drive'] = array('label' => __('Google Drive', 'w3-total-cache'), 'optgroup' => $optgroup_push);
     $engine_values['azure'] = array('label' => __('Microsoft Azure Storage', 'w3-total-cache'), 'optgroup' => $optgroup_push);
     $engine_values['rscf'] = array('disabled' => !Util_Installed::curl() ? true : null, 'label' => __('Rackspace Cloud Files', 'w3-total-cache'), 'optgroup' => $optgroup_push);
     $engine_values['ftp'] = array('disabled' => !Util_Installed::ftp() ? true : null, 'label' => __('Self-hosted / File Transfer Protocol Upload', 'w3-total-cache'), 'optgroup' => $optgroup_push);
     $cdn_enabled = $config->get_boolean('cdn.enabled');
     $cdn_engine = $config->get_string('cdn.engine');
     $tag = '';
     if ($cdn_engine == 'cloudfront_fsd') {
         $tag = '#cdn-fsd-cloudfront';
     } elseif ($cdn_engine == 'maxcdn_fsd') {
         $tag = '#cdn-fsd-maxcdn';
     }
     if (empty($tag)) {
         $cdn_engine_extra_description = '';
     } else {
         $cdn_engine_extra_description = ' See <a href="admin.php?page=w3tc_faq' . $tag . '">setup instructions</a>';
     }
     include W3TC_DIR . '/Cdn_GeneralPage_View.php';
 }
Пример #23
0
 /**
  * Special redirect with ability to pass custom_message_id based on $data
  *   query_string
  *   actions - which actions to call on render
  *   errors
  *   notes
  */
 public static function redirect_with_custom_messages2($data)
 {
     if (!isset($data['query_string']['page'])) {
         $data['query_string']['page'] = Util_Request::get_string('page');
         if ($data['query_string']['page'] == 'w3tc_extensions') {
             $data['query_string']['extension'] = Util_Request::get_string('extension');
             $data['query_string']['action'] = Util_Request::get_string('action');
         }
     }
     $message_id = uniqid();
     set_transient('w3tc_message', array($message_id => $data), 600);
     $data['query_string']['w3tc_message'] = $message_id;
     Util_Environment::redirect('admin.php', $data['query_string']);
 }
Пример #24
0
 function generate($base_capability)
 {
     $pages = $this->generate_menu_array();
     add_menu_page(__('Performance', 'w3-total-cache'), __('Performance', 'w3-total-cache'), apply_filters('w3tc_capability_menu_w3tc_dashboard', $base_capability), 'w3tc_dashboard', '', 'div');
     $submenu_pages = array();
     $is_master = is_network_admin() || !Util_Environment::is_wpmu();
     $remaining_visible = !$this->_config->get_boolean('common.force_master');
     foreach ($pages as $slug => $titles) {
         if ($is_master || $titles['visible_always'] || $remaining_visible) {
             $submenu_pages[] = add_submenu_page('w3tc_dashboard', $titles['page_title'] . ' | W3 Total Cache', $titles['menu_text'], apply_filters('w3tc_capability_menu_' . $slug, $base_capability), $slug, array($this, 'options'));
         }
     }
     return $submenu_pages;
 }
 /**
  *
  *
  * @param unknown $extensions
  * @param Config  $config
  * @return mixed
  */
 public static function w3tc_extensions($extensions, $config)
 {
     $requirements = array();
     if (!self::is_theme_found()) {
         $requirements[] = 'Optimizes "Genesis Framework" version >= 1.9.0, which is not active';
     }
     if (empty($requirements) && !Util_Environment::is_w3tc_pro($config)) {
         $requirements[] = 'Available after <a href="#" class="button-buy-plugin">upgrade</a>';
     }
     if (!$config->is_extension_active('fragmentcache')) {
         $requirements[] = 'Activate "Fragment Cache" extension first';
     }
     $extensions['genesis.theme'] = array('name' => 'Genesis Framework by StudioPress', 'author' => 'W3 EDGE', 'description' => 'Provides 30-60% improvement in page generation time for the Genesis Framework by Copyblogger Media.', 'author_uri' => 'https://www.w3-edge.com/', 'extension_uri' => 'https://www.w3-edge.com/', 'extension_id' => 'genesis.theme', 'version' => '0.1', 'enabled' => empty($requirements), 'requirements' => implode(', ', $requirements), 'path' => 'w3-total-cache/Extension_Genesis_Plugin.php');
     return $extensions;
 }
 public static function w3tc_notes_wpml($notes)
 {
     if (!self::show_notice()) {
         return $notes;
     }
     $extension_id = 'wpml';
     $config = Dispatcher::config();
     if (!Util_Environment::is_w3tc_pro($config)) {
         $activate_text = 'Available after <a href="#" class="button-buy-plugin">upgrade</a>. ';
     } else {
         $activate_text = sprintf('<a class="button" href="%s">Click here</a> to try it. ', Util_Ui::url(array('w3tc_extensions_activate' => $extension_id)));
     }
     $notes[$extension_id] = sprintf(__('Activating the <a href="%s">WPML</a> extension for W3 Total Cache may be helpful for your site. %s%s', 'w3-total-cache'), Util_Ui::admin_url('admin.php?page=w3tc_extensions#' . $extension_id), $activate_text, Util_Ui::button_link(__('Hide this message', 'w3-total-cache'), Util_Ui::url(array('w3tc_default_config_state' => 'y', 'key' => 'wpml.hide_note_suggest_activation', 'value' => 'true'))));
     return $notes;
 }
Пример #27
0
 /**
  * Returns allow-origin rules
  *
  * @param bool    $cdnftp
  * @return string
  */
 public static function allow_origin($cdnftp = false)
 {
     switch (true) {
         case Util_Environment::is_apache():
         case Util_Environment::is_litespeed():
             $r = "<IfModule mod_headers.c>\n";
             $r .= "    Header set Access-Control-Allow-Origin \"*\"\n";
             $r .= "</IfModule>\n";
             if (!$cdnftp) {
                 return $r;
             } else {
                 return "<FilesMatch \"\\.(ttf|ttc|otf|eot|woff|woff2|font.css)\$\">\n" . $r . "</FilesMatch>\n";
             }
     }
     return '';
 }
Пример #28
0
 public function __construct($blog_id = null)
 {
     if (!is_null($blog_id)) {
         $this->_blog_id = $blog_id;
         $this->_is_master = $this->_blog_id == 0;
     } else {
         if (Util_Environment::is_using_master_config()) {
             $this->_blog_id = 0;
         } else {
             $this->_blog_id = Util_Environment::blog_id();
         }
         $this->_is_master = Util_Environment::blog_id() == 0;
     }
     $this->_preview = Util_Environment::is_preview_mode();
     $this->load();
 }
 /**
  * Post changed action
  *
  * @param integer $post_id
  * @param null    $post
  * @return void
  */
 function on_post_change($post_id, $post = null)
 {
     if (is_null($post)) {
         $post = get_post($post_id);
     }
     // if attachment changed - parent post has to be flushed
     // since there are usually attachments content like title
     // on the page (gallery)
     if ($post->post_type == 'attachment') {
         $post_id = $post->post_parent;
         $post = get_post($post_id);
     }
     if (!Util_Environment::is_flushable_post($post, 'posts', Dispatcher::config())) {
         return;
     }
     $cacheflush = Dispatcher::component('CacheFlush');
     $cacheflush->flush_post($post_id);
 }
Пример #30
0
 /**
  * Returns upload info
  *
  * @return array
  */
 public static function upload_info()
 {
     static $upload_info = null;
     if ($upload_info === null) {
         $upload_info = Util_Environment::wp_upload_dir();
         if (empty($upload_info['error'])) {
             $parse_url = @parse_url($upload_info['baseurl']);
             if ($parse_url) {
                 $baseurlpath = !empty($parse_url['path']) ? trim($parse_url['path'], '/') : '';
             } else {
                 $baseurlpath = 'wp-content/uploads';
             }
             $upload_info['baseurlpath'] = '/' . $baseurlpath . '/';
         } else {
             $upload_info = false;
         }
     }
     return $upload_info;
 }