Exemplo n.º 1
0
 function fix_in_wpadmin($config, $force_all_checks = false)
 {
     $exs = new SelfTestExceptions();
     $fix_on_event = false;
     if (w3_is_multisite() && w3_get_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 (SelfTestExceptions $ex) {
             $exs->push($ex);
         }
     }
     if (count($exs->exceptions()) > 0) {
         throw $exs;
     }
 }
Exemplo n.º 2
0
 /**
  * Runs plugin
  */
 function run()
 {
     add_action('publish_phone', array(&$this, 'on_post_edit'), 20);
     add_action('wp_trash_post', array(&$this, 'on_post_change'), 20);
     add_action('save_post', array(&$this, 'on_post_change'), 20);
     global $wp_version;
     if (version_compare($wp_version, '3.5', '>=')) {
         add_action('clean_post_cache', array(&$this, 'on_post_change'), 20, 2);
     }
     add_action('comment_post', array(&$this, 'on_comment_change'), 20);
     add_action('edit_comment', array(&$this, 'on_comment_change'), 20);
     add_action('delete_comment', array(&$this, 'on_comment_change'), 0);
     add_action('wp_set_comment_status', array(&$this, 'on_comment_status'), 20, 2);
     add_action('trackback_post', array(&$this, 'on_comment_change'), 20);
     add_action('pingback_post', array(&$this, 'on_comment_change'), 20);
     add_action('switch_theme', array(&$this, 'on_change'), 20);
     add_action('wp_update_nav_menu', array(&$this, 'on_change'), 20);
     add_action('edit_user_profile_update', array(&$this, 'on_change'), 20);
     add_action('w3tc_purge_from_pgcache', array(&$this, 'on_post_change'), 20);
     add_action('delete_post', array(&$this, 'on_post_edit'), 20);
     if (w3_is_multisite()) {
         add_action('delete_blog', array(&$this, 'on_change'), 20);
     }
     add_filter('wp_redirect', array(&$this, 'on_redirect_cleanup'), 20, 1);
     add_action('sns_actions_executed', array(&$this, 'flush_post_cleanup'), 20);
 }
Exemplo n.º 3
0
 /**
  * Runs plugin
  */
 function run()
 {
     add_filter('cron_schedules', array(&$this, 'cron_schedules'));
     if ($this->_config->get_string('dbcache.engine') == 'file') {
         add_action('w3_dbcache_cleanup', array(&$this, 'cleanup'));
     }
     add_action('publish_phone', array(&$this, 'on_change'), 0);
     add_action('wp_trash_post', array(&$this, 'on_post_change'), 0);
     add_action('save_post', array(&$this, 'on_post_change'), 0);
     global $wp_version;
     if (version_compare($wp_version, '3.5', '>=')) {
         add_action('clean_post_cache', array(&$this, 'on_post_change'), 0, 2);
     }
     add_action('comment_post', array(&$this, 'on_comment_change'), 0);
     add_action('edit_comment', array(&$this, 'on_comment_change'), 0);
     add_action('delete_comment', array(&$this, 'on_comment_change'), 0);
     add_action('wp_set_comment_status', array(&$this, 'on_comment_status'), 0, 2);
     add_action('trackback_post', array(&$this, 'on_comment_change'), 0);
     add_action('pingback_post', array(&$this, 'on_comment_change'), 0);
     add_action('switch_theme', array(&$this, 'on_change'), 0);
     add_action('edit_user_profile_update', array(&$this, 'on_change'), 0);
     if (w3_is_multisite()) {
         add_action('delete_blog', array(&$this, 'on_change'), 0);
     }
     add_action('delete_post', array(&$this, 'on_post_change'), 0);
 }
Exemplo n.º 4
0
 /**
  * General tab
  *
  * @return void
  */
 function view()
 {
     w3_require_once(W3TC_INC_FUNCTIONS_DIR . '/ui.php');
     global $current_user;
     $config_master = $this->_config_master;
     /**
      * @var $modules W3_ModuleStatus
      */
     $modules = w3_instance('W3_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');
     $fragmentcache_enabled = $modules->is_enabled('fragmentcache');
     $enabled = $modules->plugin_is_enabled();
     $enabled_checkbox = $modules->all_modules_enabled();
     $check_rules = w3_can_check_rules();
     $check_apc = function_exists('apc_store');
     $check_eaccelerator = function_exists('eaccelerator_put');
     $check_xcache = function_exists('xcache_set');
     $check_wincache = function_exists('wincache_ucache_set');
     $check_curl = function_exists('curl_init');
     $check_memcached = class_exists('Memcache');
     $check_ftp = function_exists('ftp_connect');
     $check_tidy = class_exists('tidy');
     $disc_enhanced_enabled = !(!$check_rules || !$this->is_master() && w3_is_network() && $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 = w3_cdn_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');
     w3_require_once(W3TC_LIB_NEWRELIC_DIR . '/NewRelicWrapper.php');
     $newrelic_conf_appname = NewRelicWrapper::get_wordpress_appname($this->_config, $this->_config_master, false);
     $newrelic_applications = array();
     $nerser = w3_instance('W3_NewRelicService');
     $new_relic_installed = $nerser->module_is_enabled();
     $new_relic_running = true;
     if ($this->_config->get_boolean('newrelic.enabled')) {
         $new_relic_configured = $this->_config->get_string('newrelic.api_key') && $this->_config->get_string('newrelic.account_id');
         $newrelic_prefix = '';
         if ($new_relic_configured) {
             if (w3_is_network()) {
                 $newrelic_prefix = $this->_config->get_string('newrelic.appname_prefix');
             }
             try {
                 $newrelic_applications = $nerser->get_applications();
             } catch (Exception $ex) {
             }
             $newrelic_application = $this->_config->get_string('newrelic.application_id');
         }
     }
     $licensing_visible = (!w3_is_multisite() || is_network_admin()) && !ini_get('w3tc.license_key') && get_transient('w3tc_license_status') != 'host_valid';
     $custom_areas = apply_filters("{$this->_page}_anchors", array());
     include W3TC_INC_DIR . '/options/general.php';
 }
Exemplo n.º 5
0
 /**
  * Setup notices actions
  */
 function admin_init()
 {
     if (current_user_can('manage_options')) {
         if (is_admin() && isset($_GET['page']) && strpos($_GET['page'], 'w3tc_') !== false) {
             /**
              * Only admin can see W3TC notices and errors
              */
             if (!w3_is_multisite()) {
                 add_action('admin_notices', array(&$this, 'admin_notices'));
             }
             add_action('network_admin_notices', array(&$this, 'admin_notices'));
         }
     }
 }
Exemplo n.º 6
0
 /**
  * Setup notices actions
  */
 function admin_init()
 {
     if (current_user_can('manage_options')) {
         w3_require_once(W3TC_INC_FUNCTIONS_DIR . '/admin.php');
         if (is_admin() && is_w3tc_admin_page()) {
             /**
              * Only admin can see W3TC notices and errors
              */
             if (!w3_is_multisite()) {
                 add_action('admin_notices', array(&$this, 'admin_notices'));
             }
             add_action('network_admin_notices', array(&$this, 'admin_notices'));
         }
     }
 }
Exemplo n.º 7
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';
 }
Exemplo n.º 8
0
    function print_script()
    {
        ?>
        <script type="text/javascript">
            var w3_use_network_link = <?php 
        echo is_network_admin() || w3_is_multisite() && w3_force_master() ? 'true' : 'false';
        ?>
;
            function w3tc_start_minify_try_solve() {
                var testUrl = '<?php 
        echo w3_filename_to_url(w3_cache_blog_dir('minify') . '/', w3_get_domain(w3_get_home_url()) != w3_get_domain(w3_get_site_url()));
        ?>
';
                w3tc_filename_auto_solve(testUrl);
            }
        </script>
        <?php 
    }
Exemplo n.º 9
0
 /**
  * Runs plugin
  */
 function run()
 {
     add_filter('cron_schedules', array(&$this, 'cron_schedules'));
     if ($this->_config->get_string('pgcache.engine') == 'file' || $this->_config->get_string('pgcache.engine') == 'file_generic') {
         add_action('w3_pgcache_cleanup', array(&$this, 'cleanup'));
     }
     add_action('w3_pgcache_prime', array(&$this, 'prime'));
     add_action('publish_phone', array(&$this, 'on_post_edit'), 0);
     add_action('wp_trash_post', array(&$this, 'on_post_change'), 0);
     add_action('save_post', array(&$this, 'on_post_change'), 0);
     global $wp_version;
     if (version_compare($wp_version, '3.5', '>=')) {
         add_action('clean_post_cache', array(&$this, 'on_post_change'), 0, 2);
     }
     add_action('comment_post', array(&$this, 'on_comment_change'), 0);
     add_action('edit_comment', array(&$this, 'on_comment_change'), 0);
     add_action('delete_comment', array(&$this, 'on_comment_change'), 0);
     add_action('wp_set_comment_status', array(&$this, 'on_comment_status'), 0, 2);
     add_action('trackback_post', array(&$this, 'on_comment_change'), 0);
     add_action('pingback_post', array(&$this, 'on_comment_change'), 0);
     add_action('switch_theme', array(&$this, 'on_change'), 0);
     add_action('wp_update_nav_menu', array(&$this, 'on_change'), 0);
     add_action('edit_user_profile_update', array(&$this, 'on_change'), 0);
     add_filter('comment_cookie_lifetime', array(&$this, 'comment_cookie_lifetime'));
     add_action('w3tc_purge_from_pgcache', array(&$this, 'on_post_change'), 0);
     if (w3_is_multisite()) {
         add_action('delete_blog', array(&$this, 'on_change'), 0);
     }
     add_action('delete_post', array(&$this, 'on_post_edit'), 0);
     if ($this->_config->get_string('pgcache.engine') == 'file_generic') {
         add_action('wp_logout', array(&$this, 'on_logout'), 0);
         add_action('wp_login', array(&$this, 'on_login'), 0);
     }
     add_filter('wp_redirect', array(&$this, 'on_redirect_cleanup'), 0, 1);
     add_action('sns_actions_executed', array(&$this, 'flush_post_cleanup'), 0);
     if ($this->_config->get_boolean('pgcache.prime.post.enabled', false)) {
         add_action('publish_post', array(&$this, 'prime_post'), 30);
     }
     if ($this->_config->get_boolean('pgcache.late_init') && !is_admin()) {
         add_action('init', array($this, 'delayed_cache_print'), 99999);
     }
 }
Exemplo n.º 10
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'));
     }
 }
Exemplo n.º 11
0
 /**
  * Setups actions
  */
 public function admin_init()
 {
     if (current_user_can('manage_options')) {
         /**
          * @var W3_ConfigCompatibility $config_comp
          */
         $config_comp = w3_instance('W3_ConfigCompatibility');
         if ($config_comp->get_old_version() && isset($_GET['page'])) {
             w3_require_once(W3TC_INC_FUNCTIONS_DIR . '/admin.php');
             if (is_w3tc_admin_page() || isset($GLOBALS['pagenow']) && 'plugins.php' === $GLOBALS['pagenow']) {
                 if (!w3_is_multisite() || !w3_force_master()) {
                     add_action('admin_notices', array($this, 'admin_notices'));
                 } else {
                     add_action('network_admin_notices', array($this, 'admin_notices'));
                 }
             }
             $config_comp->setup_settings();
         }
     }
 }
Exemplo n.º 12
0
 /**
  * Called on plugin instantiation
  */
 function run()
 {
     add_filter('w3tc_compatibility_test', array($this, 'verify_compatibility'));
     if (is_admin()) {
         add_action('wp_ajax_admin_w3tc_verify_newrelic_api_key', array($this, 'verify_newrelic_api_key'));
         add_action('wp_ajax_w3tc_verify_newrelic_api_key', array($this, 'verify_newrelic_api_key'));
         add_action('wp_ajax_admin_w3tc_get_newrelic_applications', array($this, 'get_newrelic_applications'));
         add_action('wp_ajax_w3tc_get_newrelic_applications', array($this, 'get_newrelic_applications'));
         $new_relic_enabled = $this->_config->get_boolean('newrelic.enabled');
         if ($new_relic_enabled) {
             global $pagenow;
             w3_require_once(W3TC_LIB_W3_DIR . '/Request.php');
             $page = W3_Request::get_string('page');
             if ($pagenow == 'plugins.php' || strpos($page, 'w3tc_') !== false) {
                 if (!w3_is_multisite() || w3_is_multisite() && !$this->_config->get_boolean('common.force_master')) {
                     add_action('admin_notices', array($this, 'admin_notices'));
                 } else {
                     add_action('network_admin_notices', array($this, 'admin_notices'));
                 }
             }
         }
     }
 }
Exemplo n.º 13
0
 /**
  * Returns minify groups
  *
  * @param string $theme
  * @param string $template
  * @param string $type
  * @return array
  */
 function get_groups($theme, $template, $type)
 {
     $result = array();
     switch ($type) {
         case 'css':
             $groups = $this->_config->get_array('minify.css.groups');
             break;
         case 'js':
             $groups = $this->_config->get_array('minify.js.groups');
             break;
         default:
             return $result;
     }
     if (isset($groups[$theme]['default'])) {
         $locations = (array) $groups[$theme]['default'];
     } else {
         $locations = array();
     }
     if ($template != 'default' && isset($groups[$theme][$template])) {
         $locations = array_merge_recursive($locations, (array) $groups[$theme][$template]);
     }
     foreach ($locations as $location => $config) {
         if (!empty($config['files'])) {
             foreach ((array) $config['files'] as $file) {
                 $file = w3_normalize_file_minify2($file);
                 if (w3_is_url($file)) {
                     $precached_file = $this->_precache_file($file, $type);
                     if ($precached_file) {
                         $result[$location][$file] = $precached_file;
                     } else {
                         $this->error(sprintf('Unable to cache remote file: "%s"', $file));
                     }
                 } else {
                     if (!w3_is_multisite() && strpos(trailingslashit(WP_CONTENT_DIR), trailingslashit(w3_get_site_root())) !== false) {
                         $file = ltrim(w3_get_site_path(), '/') . str_replace(ltrim(w3_get_site_path(), '/'), '', $file);
                     }
                     $path = w3_get_document_root() . '/' . $file;
                     if (file_exists($path)) {
                         $result[$location][$file] = '//' . $file;
                     } else {
                         $this->error(sprintf('File "%s" doesn\'t exist', $path));
                     }
                 }
             }
         }
     }
     return $result;
 }
Exemplo n.º 14
0
/**
 * @return bool
 */
function w3_force_master()
{
    global $w3_force_master;
    if (!is_null($w3_force_master)) {
        return $w3_force_master;
    }
    if (!w3_is_multisite()) {
        $w3_force_master = false;
    } else {
        $blog_data = w3_blogmap_get_blog_data();
        if (is_null($blog_data) || $blog_data[0] != 'm' && $blog_data[0] != 'c') {
            $w3_force_master = true;
        } else {
            $w3_force_master = $blog_data[0] == 'm';
        }
    }
    return $w3_force_master;
}
Exemplo n.º 15
0
 /**
  * Flush cache when user profile is updated
  * @param int $user_id
  */
 function on_change_profile($user_id)
 {
     static $flushed = false;
     if (!$flushed) {
         if (w3_is_multisite()) {
             $blogs = get_blogs_of_user($user_id, true);
             if ($blogs) {
                 global $w3_multisite_blogs;
                 $w3_multisite_blogs = $blogs;
             }
         }
         $flush = w3_instance('W3_CacheFlush');
         $flush->objectcache_flush();
         $flushed = true;
     }
 }
Exemplo n.º 16
0
/**
 * Returns if there is multisite mode
 *
 * @return boolean
 */
function w3_is_network()
{
    return w3_is_wpmu() || w3_is_multisite();
}
Exemplo n.º 17
0
        ?>
 disabled="disabled"<?php 
    }
    ?>
 /> <?php 
    _e('Optimize disk enhanced page and minify disk caching for <acronym title="Network File System">NFS</acronym>', 'w3-total-cache');
    ?>
</label>
                    <br /><span class="description"><?php 
    _e('Try this option if your hosting environment uses a network based file system for a possible performance improvement.', 'w3-total-cache');
    ?>
</span>
                </th>
            </tr>
            <?php 
    if (is_network_admin() || !w3_is_multisite()) {
        ?>
            <tr id="edge_mode">
                <th colspan="2">
                    <?php 
        if (!w3tc_edge_mode()) {
            echo '<a href="' . w3_admin_url('admin.php?page=' . $this->_page . '&w3tc_edge_mode_enable') . '"><strong>' . __('Enable Edge mode', 'w3-total-cache') . '</strong></a>';
        } else {
            echo '<a href="' . w3_admin_url('admin.php?page=' . $this->_page . '&w3tc_edge_mode_disable') . '"><strong>' . __('Disable Edge mode', 'w3-total-cache') . '</strong></a>';
        }
        ?>
                    <br /><span class="description"><?php 
        _e('Enable this to try out new functionality under development. Might cause issues on some sites. If you have issues and can\'t access wp-admin, remove "define(\'W3TC_EDGE_MODE\', true);" from your wp-config.php file and edge mode features will be disabled.', 'w3-total-cache');
        ?>
</span>
                </th>
Exemplo n.º 18
0
 /**
  * Sets New Relic appname for an application if current state meets requirements.
  *
  * @param W3_Config $config
  * @return boolean If appname was set or not
  */
 public function set_newrelic_appname($config)
 {
     if ($config->get_boolean('newrelic.enabled') && !$config->get_boolean('late_init.enabled')) {
         if (w3_is_multisite() && $config->get_boolean('common.force_master')) {
             return false;
         }
         /**
          * @var W3_Plugin_NewRelic $nr
          */
         $nr = w3_instance('W3_Plugin_NewRelic');
         $nr->set_appname();
         return true;
     }
     return false;
 }
Exemplo n.º 19
0
 /**
  * Exports custom files to CDN
  *
  * @return array
  */
 function get_files_custom()
 {
     $files = array();
     $document_root = w3_get_document_root();
     $custom_files = $this->_config->get_array('cdn.custom.files');
     $custom_files = array_map('w3_parse_path', $custom_files);
     $site_root = w3_get_site_root();
     $path = w3_get_site_path();
     if (strstr(WP_CONTENT_DIR, w3_get_site_root()) === false) {
         $site_root = w3_get_document_root();
         $path = '';
     }
     $content_path = trim(substr(WP_CONTENT_DIR, strlen($site_root)), '/\\');
     $wp_content_folder = basename(WP_CONTENT_DIR);
     foreach ($custom_files as $custom_file) {
         if ($custom_file != '') {
             $custom_file = w3_normalize_file($custom_file);
             if (!w3_is_multisite()) {
                 $dir = trim(dirname($path . $custom_file), '/\\');
                 $rel_path = trim(dirname($custom_file), '/\\');
             } else {
                 $rel_path = $dir = trim(dirname($custom_file), '/\\');
             }
             if (strpos($dir, '<currentblog>') != false) {
                 $rel_path = $dir = str_replace('<currentblog>', 'blogs.dir/' . w3_get_blog_id(), $dir);
             }
             if ($content_path && $content_path != $wp_content_folder) {
                 $dir = str_replace($wp_content_folder, $content_path, $dir);
                 $rel_path = str_replace($wp_content_folder, $content_path, $rel_path);
             }
             if ($dir == '.') {
                 $rel_path = $dir = '';
             }
             $mask = basename($custom_file);
             $files = array_merge($files, $this->search_files($document_root . '/' . $dir, $rel_path, $mask));
         }
     }
     return $files;
 }
Exemplo n.º 20
0
    function options()
    {
        $remove_results = array();
        $w3tc_error = array();
        w3_require_once(W3TC_INC_DIR . '/functions/activation.php');
        $preview = $this->_config->is_preview();
        if (w3_is_network() && !$this->is_master()) {
            $this->_config_master = new W3_Config(true);
        } else {
            $this->_config_master = $this->_config;
        }
        /**
         * Check for page cache availability
         */
        $wp_config_edit = false;
        /**
         * Check memcached
         */
        $memcaches_errors = array();
        if ($this->_config->get_boolean('pgcache.enabled') && $this->_config->get_string('pgcache.engine') == 'memcached') {
            $pgcache_memcached_servers = $this->_config->get_array('pgcache.memcached.servers');
            if (!$this->is_memcache_available($pgcache_memcached_servers)) {
                $memcaches_errors[] = sprintf(__('Page Cache: %s.', 'w3-total-cache'), implode(', ', $pgcache_memcached_servers));
            }
        }
        if ($this->_config->get_boolean('minify.enabled') && $this->_config->get_string('minify.engine') == 'memcached') {
            $minify_memcached_servers = $this->_config->get_array('minify.memcached.servers');
            if (!$this->is_memcache_available($minify_memcached_servers)) {
                $memcaches_errors[] = sprintf(__('Minify: %s.', 'w3-total-cache'), implode(', ', $minify_memcached_servers));
            }
        }
        if ($this->_config->get_boolean('dbcache.enabled') && $this->_config->get_string('dbcache.engine') == 'memcached') {
            $dbcache_memcached_servers = $this->_config->get_array('dbcache.memcached.servers');
            if (!$this->is_memcache_available($dbcache_memcached_servers)) {
                $memcaches_errors[] = sprintf(__('Database Cache: %s.', 'w3-total-cache'), implode(', ', $dbcache_memcached_servers));
            }
        }
        if ($this->_config->get_boolean('objectcache.enabled') && $this->_config->get_string('objectcache.engine') == 'memcached') {
            $objectcache_memcached_servers = $this->_config->get_array('objectcache.memcached.servers');
            if (!$this->is_memcache_available($objectcache_memcached_servers)) {
                $memcaches_errors[] = sprintf(__('Object Cache: %s.', 'w3-total-cache'), implode(', ', $objectcache_memcached_servers));
            }
        }
        if (count($memcaches_errors)) {
            $memcache_error = __('The following memcached servers are not responding or not running:</p><ul>', 'w3-total-cache');
            foreach ($memcaches_errors as $memcaches_error) {
                $memcache_error .= '<li>' . $memcaches_error . '</li>';
            }
            $memcache_error .= __('</ul><p>This message will automatically disappear once the issue is resolved.', 'w3-total-cache');
            $this->_errors[] = $memcache_error;
        }
        /**
         * Check CURL extension
         */
        if ($this->_config->get_boolean('notes.no_curl') && $this->_config->get_boolean('cdn.enabled') && !function_exists('curl_init')) {
            $this->_notes[] = sprintf(__('The <strong>CURL PHP</strong> extension is not available. Please install it to enable S3 or CloudFront functionality. %s', 'w3-total-cache'), w3_button_hide_note('Hide this message', 'no_curl'));
        }
        /**
         * Check Zlib extension
         */
        if ($this->_config->get_boolean('notes.no_zlib') && !function_exists('gzencode')) {
            $this->_notes[] = sprintf(__('Unfortunately the PHP installation is incomplete, the <strong>zlib module is missing</strong>. This is a core PHP module. Notify the server administrator. %s', 'w3-total-cache'), w3_button_hide_note(__('Hide this message', 'w3-total-cache'), 'no_zlib'));
        }
        /**
         * Check if Zlib output compression is enabled
         */
        if ($this->_config->get_boolean('notes.zlib_output_compression') && w3_zlib_output_compression()) {
            $this->_notes[] = sprintf(__('Either the PHP configuration, web server configuration or a script in the WordPress installation has <strong>zlib.output_compression</strong> enabled.<br />Please locate and disable this setting to ensure proper HTTP compression behavior. %s', 'w3-total-cache'), w3_button_hide_note(__('Hide this message', 'w3-total-cache'), 'zlib_output_compression'));
        }
        /**
         * Check wp-content permissions
         */
        if (!W3TC_WIN && $this->_config->get_boolean('notes.wp_content_perms')) {
            w3_require_once(W3TC_INC_DIR . '/functions/file.php');
            $wp_content_mode = w3_get_file_permissions(WP_CONTENT_DIR);
            if ($wp_content_mode > 0755) {
                $this->_notes[] = sprintf(__('<strong>%s</strong> is write-able. When finished installing the plugin,
                                        change the permissions back to the default: <strong>chmod 755 %s</strong>.
                                        Permissions are currently %s. %s', 'w3-total-cache'), WP_CONTENT_DIR, WP_CONTENT_DIR, base_convert(w3_get_file_permissions(WP_CONTENT_DIR), 10, 8), w3_button_hide_note(__('Hide this message', 'w3-total-cache'), 'wp_content_perms'));
            }
        }
        /**
         * Check wp-content permissions
         */
        if (!W3TC_WIN && $this->_config->get_boolean('notes.wp_content_changed_perms')) {
            $perm = get_transient('w3tc_prev_permission');
            $current_perm = w3_get_file_permissions(WP_CONTENT_DIR);
            if ($perm && $perm != base_convert($current_perm, 10, 8) && ($current_perm > 0755 || $perm < base_convert($current_perm, 10, 8))) {
                $this->_notes[] = sprintf(__('<strong>%s</strong> permissions were changed during the setup process.
                                        Permissions are currently %s.<br />To restore permissions run
                                        <strong>chmod %s %s</strong>. %s', 'w3-total-cache'), WP_CONTENT_DIR, base_convert($current_perm, 10, 8), $perm, WP_CONTENT_DIR, w3_button_hide_note(__('Hide this message', 'w3-total-cache'), 'wp_content_changed_perms'));
            }
        }
        /**
         * Check permalinks
         */
        if ($this->_config->get_boolean('notes.no_permalink_rules') && ($this->_config->get_boolean('pgcache.enabled') && $this->_config->get_string('pgcache.engine') == 'file_generic' || $this->_config->get_boolean('browsercache.enabled') && $this->_config->get_boolean('browsercache.no404wp')) && !w3_is_permalink_rules()) {
            $this->_errors[] = sprintf(__('The required directives for fancy permalinks could not be detected, please confirm they are available: <a href="http://codex.wordpress.org/Using_Permalinks#Creating_and_editing_.28.htaccess.29">Creating and editing</a> %s', 'w3-total-cache'), w3_button_hide_note(__('Hide this message', 'w3-total-cache'), 'no_permalink_rules'));
        }
        /**
         * CDN
         */
        if ($this->_config->get_boolean('cdn.enabled')) {
            /**
             * Check upload settings
             */
            $upload_info = w3_upload_info();
            if (!$upload_info) {
                $upload_path = get_option('upload_path');
                $upload_path = trim($upload_path);
                if (empty($upload_path)) {
                    $upload_path = WP_CONTENT_DIR . '/uploads';
                    $this->_errors[] = sprintf(__('The uploads directory is not available. Default WordPress directories will be created: <strong>%s</strong>.', 'w3-total-cache'), $upload_path);
                }
                if (!w3_is_multisite()) {
                    $this->_errors[] = sprintf(__('The uploads path found in the database (%s) is inconsistent with the actual path. Please manually adjust the upload path either in miscellaneous settings or if not using a custom path %s automatically to resolve the issue.', 'w3-total-cache'), $upload_path, w3_button_link(__('update the path', 'w3-total-cache'), wp_nonce_url(sprintf('admin.php?page=%s&w3tc_config_update_upload_path', $this->_page), 'w3tc')));
                }
            }
            /**
             * Check CDN settings
             */
            $cdn_engine = $this->_config->get_string('cdn.engine');
            $error = '';
            switch (true) {
                case $cdn_engine == 'ftp' && !count($this->_config->get_array('cdn.ftp.domain')):
                    $this->_errors[] = __('A configuration issue prevents <acronym title="Content Delivery Network">CDN</acronym> from working:
                                            The <strong>"Replace default hostname with"</strong>
                                            field cannot be empty. Enter <acronym
                                            title="Content Delivery Network">CDN</acronym>
                                            provider hostname <a href="?page=w3tc_cdn#configuration">here</a>.
                                            <em>(This is the hostname used in order to view objects
                                            in a browser.)</em>', 'w3-total-cache');
                    break;
                case $cdn_engine == 's3' && ($this->_config->get_string('cdn.s3.key') == '' || $this->_config->get_string('cdn.s3.secret') == '' || $this->_config->get_string('cdn.s3.bucket') == ''):
                    $error = __('The <strong>"Access key", "Secret key" and "Bucket"</strong> fields cannot be empty.', 'w3-total-cache');
                    break;
                case $cdn_engine == 'cf' && ($this->_config->get_string('cdn.cf.key') == '' || $this->_config->get_string('cdn.cf.secret') == '' || $this->_config->get_string('cdn.cf.bucket') == '' || $this->_config->get_string('cdn.cf.id') == '' && !count($this->_config->get_array('cdn.cf.cname'))):
                    $error = __('The <strong>"Access key", "Secret key", "Bucket" and "Replace default hostname with"</strong> fields cannot be empty.', 'w3-total-cache');
                    break;
                case $cdn_engine == 'cf2' && ($this->_config->get_string('cdn.cf2.key') == '' || $this->_config->get_string('cdn.cf2.secret') == '' || $this->_config->get_string('cdn.cf2.id') == '' && !count($this->_config->get_array('cdn.cf2.cname'))):
                    $error = __('The <strong>"Access key", "Secret key" and "Replace default hostname with"</strong> fields cannot be empty.', 'w3-total-cache');
                    break;
                case $cdn_engine == 'rscf' && ($this->_config->get_string('cdn.rscf.user') == '' || $this->_config->get_string('cdn.rscf.key') == '' || $this->_config->get_string('cdn.rscf.container') == '' || !count($this->_config->get_array('cdn.rscf.cname'))):
                    $error = __('The <strong>"Username", "API key", "Container" and "Replace default hostname with"</strong> fields cannot be empty.', 'w3-total-cache');
                    break;
                case $cdn_engine == 'azure' && ($this->_config->get_string('cdn.azure.user') == '' || $this->_config->get_string('cdn.azure.key') == '' || $this->_config->get_string('cdn.azure.container') == ''):
                    $error = __('The <strong>"Account name", "Account key" and "Container"</strong> fields cannot be empty.', 'w3-total-cache');
                    break;
                case $cdn_engine == 'mirror' && !count($this->_config->get_array('cdn.mirror.domain')):
                    $error = __('The <strong>"Replace default hostname with"</strong> field cannot be empty.', 'w3-total-cache');
                    break;
                case $cdn_engine == 'netdna':
                    $fields = array();
                    if ($this->_config->get_string('cdn.netdna.authorization_key') == '') {
                        $fields[] = '"' . __('Authorization key', 'w3-total-cache') . '"';
                    }
                    if (!count($this->_config->get_array('cdn.netdna.domain'))) {
                        $fields[] = '"' . __('Replace default hostname with', 'w3-total-cache') . '"';
                    }
                    if ($fields) {
                        $error = sprintf(__('The <strong>%s</strong> field(s) cannot be empty.', 'w3-total-cache'), implode(__(' and ', 'w3-total-cache'), $fields));
                    }
                    if ($this->_config->get_string('cdn.netdna.authorization_key') != '' && sizeof(explode('+', $this->_config->get_string('cdn.netdna.authorization_key'))) != 3) {
                        $error .= __('The <strong>"Authorization key"</strong> is not correct.', 'w3-total-cache');
                    } elseif ($this->_config->get_integer('cdn.netdna.zone_id', 0) <= 0) {
                        $error .= __('You need to select / create a pull zone.', 'w3-total-cache');
                    }
                    break;
                case $cdn_engine == 'maxcdn':
                    $fields = array();
                    if ($this->_config->get_string('cdn.maxcdn.authorization_key') == '') {
                        $fields[] = '"' . __('Authorization key', 'w3-total-cache') . '"';
                    }
                    if (!count($this->_config->get_array('cdn.maxcdn.domain'))) {
                        $fields[] = '"' . __('Replace default hostname with', 'w3-total-cache') . '"';
                    }
                    if ($fields) {
                        $error = sprintf(__('The <strong>%s</strong> field(s) cannot be empty.', 'w3-total-cache'), implode(__(' and ', 'w3-total-cache'), $fields));
                    }
                    if ($this->_config->get_string('cdn.maxcdn.authorization_key') != '' && sizeof(explode('+', $this->_config->get_string('cdn.maxcdn.authorization_key'))) != 3) {
                        $error .= __('The <strong>"Authorization key"</strong> is not correct.', 'w3-total-cache');
                    } elseif ($this->_config->get_integer('cdn.maxcdn.zone_id', 0) <= 0) {
                        $error .= __('You need to select / create a pull zone.', 'w3-total-cache');
                    }
                    break;
                case $cdn_engine == 'cotendo' && !count($this->_config->get_array('cdn.cotendo.domain')):
                    $error = __('The <strong>"Replace default hostname with"</strong> field cannot be empty.', 'w3-total-cache');
                    break;
                case $cdn_engine == 'edgecast' && !count($this->_config->get_array('cdn.edgecast.domain')):
                    $error = __('The <strong>"Replace default hostname with"</strong> field cannot be empty.', 'w3-total-cache');
                    break;
                case $cdn_engine == 'att' && !count($this->_config->get_array('cdn.att.domain')):
                    $error = __('The <strong>"Replace default hostname with"</strong> field cannot be empty.', 'w3-total-cache');
                    break;
                case $cdn_engine == 'akamai' && !count($this->_config->get_array('cdn.akamai.domain')):
                    $error = 'The <strong>"Replace default hostname with"</strong> field cannot be empty.';
                    break;
            }
            if ($error) {
                $this->_errors[] = __('A configuration issue prevents <acronym title="Content Delivery Network">CDN</acronym> from working: ', 'w3-total-cache') . $error . __(' <a href="?page=w3tc_cdn#configuration">Specify it here</a>.', 'w3-total-cache');
            }
        }
        /**
         * Preview mode
         */
        if ($this->_config->is_preview()) {
            $this->_notes[] = sprintf(__('Preview mode is active: Changed settings will not take effect until preview mode is %s or %s.', 'w3-total-cache'), w3_button_link(__('deploy', 'w3-total-cache'), wp_nonce_url(sprintf('admin.php?page=%s&w3tc_config_preview_deploy', $this->_page), 'w3tc')), w3_button_link(__('disable', 'w3-total-cache'), wp_nonce_url(sprintf('admin.php?page=%s&w3tc_config_preview_disable', $this->_page), 'w3tc'))) . '<br /><span class="description">' . sprintf(__('To preview any changed settings (without deploying): %s', 'w3-total-cache'), w3tc_get_preview_link()) . '</span>';
        }
        /**
         *
         */
        if ($this->_config->get_boolean('notes.root_rules') && count($this->_rule_errors_root) > 0) {
            $this->_rule_errors_root_hide = w3_button_hide_note(__('Hide this message', 'w3-total-cache'), 'root_rules');
        } else {
            $this->_rule_errors_root = array();
        }
        $this->_disable_file_operation_notification = $this->_disable_add_in_files_notification || $this->_disable_cache_write_notification;
        if (!$this->_disable_file_operation_notification && isset($file_operation_exception) && $file_operation_exception) {
            $tech_message = '<ul>';
            $core_rules_perms = '';
            if (w3_get_file_permissions(w3_get_wp_config_path()) != 0644) {
                $core_config_perms = sprintf(__('File permissions are <strong>%s</strong>, however they should be
					<strong>644</strong>.', 'w3-total-cache'), base_convert(w3_get_file_permissions(w3_get_wp_config_path()), 10, 8));
            } else {
                $core_config_perms = sprintf(__('File permissions are <strong>%s</strong>', 'w3-total-cache'), base_convert(w3_get_file_permissions(w3_get_wp_config_path()), 10, 8));
            }
            if (w3_get_file_permissions(w3_get_pgcache_rules_core_path()) != 0644) {
                $core_rules_perms = sprintf(__('File permissions are <strong>%s</strong>, however they should be
											<strong>644</strong>.', 'w3-total-cache'), base_convert(w3_get_file_permissions(w3_get_pgcache_rules_core_path()), 10, 8));
            } else {
                $core_rules_perms = sprintf(__('File permissions are <strong>%s</strong>', 'w3-total-cache'), base_convert(w3_get_file_permissions(w3_get_pgcache_rules_core_path()), 10, 8));
            }
            $wp_content_perms = '';
            if (w3_get_file_permissions(WP_CONTENT_DIR) != 0755) {
                $wp_content_perms = sprintf(__('Directory permissions are <strong>%s</strong>, however they should be
											<strong>755</strong>.', 'w3-total-cache'), base_convert(w3_get_file_permissions(WP_CONTENT_DIR), 10, 8));
            }
            $tech_message .= '<li>' . sprintf(__('File: <strong>%s</strong> %s File owner: %s', 'w3-total-cache'), w3_get_wp_config_path(), $core_config_perms, w3_get_file_owner(w3_get_wp_config_path())) . '</li>';
            $tech_message .= '<li>' . sprintf(__('File: <strong>%s</strong> %s File owner: %s', 'w3-total-cache'), w3_get_pgcache_rules_core_path(), $core_rules_perms, w3_get_file_owner(w3_get_pgcache_rules_core_path())) . '</li>';
            $tech_message .= '<li>' . sprintf(__('Directory: <strong>%s</strong> %s File owner: %s', 'w3-total-cache'), WP_CONTENT_DIR, $wp_content_perms, w3_get_file_owner(WP_CONTENT_DIR)) . '</li>';
            $tech_message .= '<li>' . sprintf(__('Owner of current file: %s', 'w3-total-cache'), w3_get_file_owner()) . '</li>';
            if (!(w3_get_file_owner() == w3_get_file_owner(w3_get_pgcache_rules_core_path()) && w3_get_file_owner() == w3_get_file_owner(WP_CONTENT_DIR))) {
                $tech_message .= __('<li>The files and directories have different ownership, they should have the same ownership.
								 </li>', 'w3-total-cache');
            }
            $tech_message .= '</ul>';
            $tech_message = '<div class="w3tc-technical-info" style="display:none">' . $tech_message . '</div>';
            $w3tc_error[] = sprintf(__('<strong>W3 Total Cache Error:</strong> The plugin tried to edit, %s, but failed.
								Files and directories cannot be modified. Please review your
								<a target="_blank" href="http://codex.wordpress.org/Changing_File_Permissions">
								file permissions</a>. A common cause is %s and %s having different ownership or permissions.
								%s %s', 'w3-total-cache'), $wp_config_edit ? w3_get_wp_config_path() : w3_get_pgcache_rules_core_path(), $wp_config_edit ? basename(w3_get_wp_config_path()) : basename(w3_get_pgcache_rules_core_path()), WP_CONTENT_DIR, w3_button(__('View technical information', 'w3-total-cache'), '', 'w3tc-show-technical-info'), $tech_message);
        }
        /**
         * Remove functions results
         */
        if ($remove_results) {
            foreach ($remove_results as $result) {
                $this->_errors = array_merge($this->_errors, $result['errors']);
                if (!isset($this->_ftp_form) && isset($result['ftp_form'])) {
                    $extra_ftp_message = __('Please enter FTP details <a href="#ftp_upload_form">below</a> to remove the disabled modules. ', 'w3-total-cache');
                    $this->_ftp_form = $result['ftp_form'];
                    $this->_use_ftp_form = true;
                }
            }
            if (isset($extra_ftp_message)) {
                $this->_errors[] = $extra_ftp_message;
            }
        }
        foreach ($w3tc_error as $error) {
            array_unshift($this->_errors, $error);
        }
        if (isset($this->_ftp_form)) {
            $this->_use_ftp_form = true;
        }
        $this->view();
    }
Exemplo n.º 21
0
 /**
  * Options page
  *
  * @return void
  */
 function options()
 {
     /**
      * Check for page cache availability
      */
     if ($this->_config->get_boolean('pgcache.enabled')) {
         if (!$this->advanced_cache_installed()) {
             $this->_errors[] = sprintf('Page caching is not available: %s is not installed. Either the <strong>%s</strong> directory is not write-able or another caching plugin installed. This error message will automatically disappear once the change is successfully made.', W3TC_ADDIN_FILE_ADVANCED_CACHE, WP_CONTENT_DIR);
         } elseif (!$this->advanced_cache_check()) {
             $this->_errors[] = sprintf('Page caching is not available. The current add-in %s is either an incorrect file or an old version. De-activate the plugin, remove the file, then activate the plugin again.', W3TC_ADDIN_FILE_ADVANCED_CACHE);
         } elseif (!defined('WP_CACHE') || !WP_CACHE) {
             $this->_errors[] = sprintf('Page caching is not available: please add: <strong>define(\'WP_CACHE\', true);</strong> to <strong>%swp-config.php</strong>. This error message will automatically disappear once the change is successfully made.', ABSPATH);
         } elseif ($this->_config->get_string('pgcache.engine') == 'file_generic' && $this->_config->get_boolean('config.check') && w3_can_check_rules()) {
             require_once W3TC_LIB_W3_DIR . '/Plugin/PgCache.php';
             $w3_plugin_pgcache =& W3_Plugin_PgCache::instance();
             if ($w3_plugin_pgcache->check_rules_core()) {
                 if (!$this->test_rewrite_pgcache()) {
                     $this->_errors[] = 'It appears Page Cache <acronym title="Uniform Resource Locator">URL</acronym> rewriting is not working. If using apache, verify that the server configuration allows .htaccess or if using nginx verify all configuration files are included in the configuration.';
                 }
             } elseif ($this->_config->get_boolean('notes.pgcache_rules_core')) {
                 $this->_errors[] = sprintf('Disk enhanced page caching is not active. To enable it, add the following rules into the server configuration file (<strong>%s</strong>) of the site above the WordPress directives %s <textarea class="w3tc-rules" cols="120" rows="10" readonly="readonly">%s</textarea>. Or if permission allow this can be done automatically, by clicking here: %s. %s', w3_get_pgcache_rules_core_path(), $this->button('view code', '', 'w3tc-show-rules'), htmlspecialchars($w3_plugin_pgcache->generate_rules_core()), $this->button_link('auto-install', sprintf('admin.php?page=%s&pgcache_write_rules_core', $this->_page)), $this->button_hide_note('Hide this message', 'pgcache_rules_core'));
             }
             if ($this->_config->get_boolean('notes.pgcache_rules_legacy') && $w3_plugin_pgcache->check_rules_legacy()) {
                 $this->_errors[] = sprintf('Legacy Page Cache rewrite rules have been found. To remove them manually, edit the configuration file (<strong>%s</strong>) and remove all lines between and including <strong>%s</strong> and <strong>%s</strong> markers inclusive. Or if permission allow this can be done automatically, by clicking here: %s. %s', w3_get_pgcache_rules_core_path(), W3TC_MARKER_BEGIN_PGCACHE_LEGACY, W3TC_MARKER_END_PGCACHE_LEGACY, $this->button_link('auto-remove', sprintf('admin.php?page=%s&pgcache_remove_rules_legacy', $this->_page)), $this->button_hide_note('Hide this message', 'pgcache_rules_legacy'));
             }
             if ($this->_config->get_boolean('notes.pgcache_rules_wpsc') && $w3_plugin_pgcache->check_rules_wpsc()) {
                 $this->_errors[] = sprintf('WP Super Cache rewrite rules have been found. To remove them manually, edit the configuration file (<strong>%s</strong>) and remove all lines between and including <strong>%s</strong> and <strong>%s</strong> markers inclusive. Or if permission allow this can be done automatically, by clicking here: %s. %s', w3_get_pgcache_rules_core_path(), W3TC_MARKER_BEGIN_PGCACHE_WPSC, W3TC_MARKER_END_PGCACHE_WPSC, $this->button_link('auto-remove', sprintf('admin.php?page=%s&pgcache_remove_rules_wpsc', $this->_page)), $this->button_hide_note('Hide this message', 'pgcache_rules_wpsc'));
             }
             if ($this->_config->get_boolean('notes.pgcache_rules_cache') && !$w3_plugin_pgcache->check_rules_cache()) {
                 $this->_errors[] = sprintf('Disk enhanced page caching is not active. To enable it, add the following rules into the server configuration file (<strong>%s</strong>) of the site %s <textarea class="w3tc-rules" cols="120" rows="10" readonly="readonly">%s</textarea>. This can be done automatically, by clicking here: %s. %s', w3_get_pgcache_rules_cache_path(), $this->button('view code', '', 'w3tc-show-rules'), htmlspecialchars($w3_plugin_pgcache->generate_rules_cache()), $this->button_link('auto-install', sprintf('admin.php?page=%s&pgcache_write_rules_cache', $this->_page)), $this->button_hide_note('Hide this message', 'pgcache_rules_cache'));
             }
         }
     }
     /**
      * Check for browser cache availability
      */
     if ($this->_config->get_boolean('browsercache.enabled') && $this->_config->get_boolean('config.check') && w3_can_check_rules()) {
         require_once W3TC_LIB_W3_DIR . '/Plugin/BrowserCache.php';
         $w3_plugin_browsercache =& W3_Plugin_BrowserCache::instance();
         if ($this->_config->get_boolean('notes.browsercache_rules_cache') && !$w3_plugin_browsercache->check_rules_cache()) {
             $this->_errors[] = sprintf('Browser caching is not active. To enable it, add the following rules into the server configuration file (<strong>%s</strong>) of the site %s <textarea class="w3tc-rules" cols="120" rows="10" readonly="readonly">%s</textarea>. Or if permission allow this can be done automatically, by clicking here: %s. %s', w3_get_browsercache_rules_cache_path(), $this->button('view code', '', 'w3tc-show-rules'), htmlspecialchars($w3_plugin_browsercache->generate_rules_cache()), $this->button_link('auto-install', sprintf('admin.php?page=%s&browsercache_write_rules_cache', $this->_page)), $this->button_hide_note('Hide this message', 'browsercache_rules_cache'));
         }
         if ($this->_config->get_boolean('notes.browsercache_rules_no404wp') && $this->_config->get_boolean('browsercache.no404wp') && !$w3_plugin_browsercache->check_rules_no404wp()) {
             $this->_errors[] = sprintf('"Do not process 404 errors for static objects with WordPress" feature is not active. To enable it, add the following rules into the server configuration file (<strong>%s</strong>) of the site %s <textarea class="w3tc-rules" cols="120" rows="10" readonly="readonly">%s</textarea>. Or if permission allow this can be done automatically, by clicking here: %s. %s', w3_get_browsercache_rules_no404wp_path(), $this->button('view code', '', 'w3tc-show-rules'), htmlspecialchars($w3_plugin_browsercache->generate_rules_no404wp()), $this->button_link('auto-install', sprintf('admin.php?page=%s&browsercache_write_rules_no404wp', $this->_page)), $this->button_hide_note('Hide this message', 'browsercache_rules_no404wp'));
         }
     }
     /**
      * Check for minify availability
      */
     if ($this->_config->get_boolean('minify.enabled')) {
         if ($this->_config->get_boolean('minify.rewrite') && $this->_config->get_boolean('config.check') && w3_can_check_rules()) {
             require_once W3TC_LIB_W3_DIR . '/Plugin/Minify.php';
             $w3_plugin_minify =& W3_Plugin_Minify::instance();
             if ($w3_plugin_minify->check_rules_core()) {
                 if (!$this->test_rewrite_minify()) {
                     $this->_errors[] = 'It appears Minify <acronym title="Uniform Resource Locator">URL</acronym> rewriting is not working. If using apache, verify that the server configuration allows .htaccess or if using nginx verify all configuration files are included in the configuration.';
                 }
             } elseif ($this->_config->get_boolean('notes.minify_rules_core')) {
                 $this->_errors[] = sprintf('Minify is not active. To enable it, add the following rules into the server configuration file (<strong>%s</strong>) of the site %s <textarea class="w3tc-rules" cols="120" rows="10" readonly="readonly">%s</textarea>. This can be done automatically, by clicking here: %s. %s', w3_get_minify_rules_core_path(), $this->button('view code', '', 'w3tc-show-rules'), htmlspecialchars($w3_plugin_minify->generate_rules_core()), $this->button_link('auto-install', sprintf('admin.php?page=%s&minify_write_rules_core', $this->_page)), $this->button_hide_note('Hide this message', 'minify_rules_core'));
             }
             if ($this->_config->get_boolean('notes.minify_rules_legacy') && $w3_plugin_minify->check_rules_legacy()) {
                 $this->_errors[] = sprintf('Legacy Minify rewrite rules have been found. To remove them manually, edit the configuration file (<strong>%s</strong>) and remove all lines between and including <strong>%s</strong> and <strong>%s</strong> markers inclusive. Or if permission allow this can be done automatically, by clicking here: %s. %s', w3_get_minify_rules_core_path(), W3TC_MARKER_BEGIN_MINIFY_LEGACY, W3TC_MARKER_END_MINIFY_LEGACY, $this->button_link('auto-remove', sprintf('admin.php?page=%s&minify_remove_rules_legacy', $this->_page)), $this->button_hide_note('Hide this message', 'minify_rules_legacy'));
             }
             if ($this->_config->get_string('minify.engine') == 'file' && $this->_config->get_boolean('notes.minify_rules_cache') && !$w3_plugin_minify->check_rules_cache()) {
                 $this->_errors[] = sprintf('Minify is not active. To enable it, add the following rules into the server configuration file (<strong>%s</strong>) of the site %s <textarea class="w3tc-rules" cols="120" rows="10" readonly="readonly">%s</textarea>. This can be done automatically, by clicking here: %s. %s', w3_get_minify_rules_cache_path(), $this->button('view code', '', 'w3tc-show-rules'), htmlspecialchars($w3_plugin_minify->generate_rules_cache()), $this->button_link('auto-install', sprintf('admin.php?page=%s&minify_write_rules_cache', $this->_page)), $this->button_hide_note('Hide this message', 'minify_rules_cache'));
             }
         }
         /**
          * Minifiers availability error handling
          */
         $minifiers_errors = array();
         if ($this->_config->get_string('minify.js.engine') == 'yuijs') {
             $path_java = $this->_config->get_string('minify.yuijs.path.java');
             $path_jar = $this->_config->get_string('minify.yuijs.path.jar');
             if (!file_exists($path_java)) {
                 $minifiers_errors[] = sprintf('YUI Compressor (JS): JAVA executable path was not found. The default minifier JSMin will be used instead.');
             } elseif (!file_exists($path_jar)) {
                 $minifiers_errors[] = sprintf('YUI Compressor (JS): JAR file path was not found. The default minifier JSMin will be used instead.');
             }
         }
         if ($this->_config->get_string('minify.css.engine') == 'yuicss') {
             $path_java = $this->_config->get_string('minify.yuicss.path.java');
             $path_jar = $this->_config->get_string('minify.yuicss.path.jar');
             if (!file_exists($path_java)) {
                 $minifiers_errors[] = sprintf('YUI Compressor (CSS): JAVA executable path was not found. The default CSS minifier will be used instead.');
             } elseif (!file_exists($path_jar)) {
                 $minifiers_errors[] = sprintf('YUI Compressor (CSS): JAR file path was not found. The default CSS minifier will be used instead.');
             }
         }
         if ($this->_config->get_string('minify.js.engine') == 'ccjs') {
             $path_java = $this->_config->get_string('minify.ccjs.path.java');
             $path_jar = $this->_config->get_string('minify.ccjs.path.jar');
             if (!file_exists($path_java)) {
                 $minifiers_errors[] = sprintf('Closure Compiler: JAVA executable path was not found. The default minifier JSMin will be used instead.');
             } elseif (!file_exists($path_jar)) {
                 $minifiers_errors[] = sprintf('Closure Compiler: JAR file path was not found. The default minifier JSMin will be used instead.');
             }
         }
         if (count($minifiers_errors)) {
             $minify_error = 'The following minifiers cannot be found or are no longer working:</p><ul>';
             foreach ($minifiers_errors as $minifiers_error) {
                 $minify_error .= '<li>' . $minifiers_error . '</li>';
             }
             $minify_error .= '</ul><p>This message will automatically disappear once the issue is resolved.';
             $this->_errors[] = $minify_error;
         }
     }
     /**
      * Check for database cache availability
      */
     if ($this->_config->get_boolean('dbcache.enabled')) {
         if (!$this->db_installed()) {
             $this->_errors[] = sprintf('Database caching is not available: %s is not installed. Either the <strong>%s</strong> directory is not write-able or another caching plugin is installed. This error message will automatically disappear once the change is successfully made.', W3TC_ADDIN_FILE_DB, WP_CONTENT_DIR);
         } elseif (!$this->db_check()) {
             $this->_errors[] = sprintf('Database caching is not available. The current add-in %s is either an incorrect file or an old version. De-activate the plugin, remove the file, then activate the plugin again.', W3TC_ADDIN_FILE_DB);
         }
     }
     /**
      * Check for object cache availability
      */
     if ($this->_config->get_boolean('objectcache.enabled')) {
         if (!$this->objectcache_installed()) {
             $this->_errors[] = sprintf('Object caching is not available: %s is not installed. Either the <strong>%s</strong> directory is not write-able or another caching plugin is installed. This error message will automatically disappear once the change is successfully made.', W3TC_ADDIN_FILE_OBJECT_CACHE, WP_CONTENT_DIR);
         } elseif (!$this->objectcache_check()) {
             $this->_errors[] = sprintf('Object caching is not available. The current add-in %s is either an incorrect file or an old version. De-activate the plugin, remove the file, then activate the plugin again.', W3TC_ADDIN_FILE_OBJECT_CACHE);
         }
     }
     /**
      * Check memcached
      */
     $memcaches_errors = array();
     if ($this->_config->get_boolean('pgcache.enabled') && $this->_config->get_string('pgcache.engine') == 'memcached') {
         $pgcache_memcached_servers = $this->_config->get_array('pgcache.memcached.servers');
         if (!$this->is_memcache_available($pgcache_memcached_servers)) {
             $this->_errors[] = sprintf('Page Cache: %s.', implode(', ', $pgcache_memcached_servers));
         }
     }
     if ($this->_config->get_boolean('minify.enabled') && $this->_config->get_string('minify.engine') == 'memcached') {
         $minify_memcached_servers = $this->_config->get_array('minify.memcached.servers');
         if (!$this->is_memcache_available($minify_memcached_servers)) {
             $memcaches_errors[] = sprintf('Minify: %s.', implode(', ', $minify_memcached_servers));
         }
     }
     if ($this->_config->get_boolean('dbcache.enabled') && $this->_config->get_string('dbcache.engine') == 'memcached') {
         $dbcache_memcached_servers = $this->_config->get_array('dbcache.memcached.servers');
         if (!$this->is_memcache_available($dbcache_memcached_servers)) {
             $memcaches_errors[] = sprintf('Database Cache: %s.', implode(', ', $dbcache_memcached_servers));
         }
     }
     if ($this->_config->get_boolean('objectcache.enabled') && $this->_config->get_string('objectcache.engine') == 'memcached') {
         $objectcache_memcached_servers = $this->_config->get_array('objectcache.memcached.servers');
         if (!$this->is_memcache_available($objectcache_memcached_servers)) {
             $memcaches_errors[] = sprintf('Object Cache: %s.', implode(', ', $objectcache_memcached_servers));
         }
     }
     if (count($memcaches_errors)) {
         $memcache_error = 'The following memcached servers are not responding or not running:</p><ul>';
         foreach ($memcaches_errors as $memcaches_error) {
             $memcache_error .= '<li>' . $memcaches_error . '</li>';
         }
         $memcache_error .= '</ul><p>This message will automatically disappear once the issue is resolved.';
         $this->_errors[] = $memcache_error;
     }
     /**
      * Check PHP version
      */
     if (!W3TC_PHP5 && $this->_config->get_boolean('notes.php_is_old')) {
         $this->_notes[] = sprintf('Unfortunately, <strong>PHP5</strong> is required for full functionality of this plugin; incompatible features are automatically disabled. Please upgrade if possible. %s', $this->button_hide_note('Hide this message', 'php_is_old'));
     }
     /**
      * Check CURL extension
      */
     if ($this->_config->get_boolean('notes.no_curl') && $this->_config->get_boolean('cdn.enabled') && !function_exists('curl_init')) {
         $this->_notes[] = sprintf('The <strong>CURL PHP</strong> extension is not available. Please install it to enable S3 or CloudFront functionality. %s', $this->button_hide_note('Hide this message', 'no_curl'));
     }
     /**
      * Check Zlib extension
      */
     if ($this->_config->get_boolean('notes.no_zlib') && !function_exists('gzencode')) {
         $this->_notes[] = sprintf('Unfortunately the PHP installation is incomplete, the <strong>zlib module is missing</strong>. This is a core PHP module. Notify the server administrator. %s', $this->button_hide_note('Hide this message', 'no_zlib'));
     }
     /**
      * Check if Zlib output compression is enabled
      */
     if ($this->_config->get_boolean('notes.zlib_output_compression') && w3_zlib_output_compression()) {
         $this->_notes[] = sprintf('Either the PHP configuration, web server configuration or a script in the WordPress installation has <strong>zlib.output_compression</strong> enabled.<br />Please locate and disable this setting to ensure proper HTTP compression behavior. %s', $this->button_hide_note('Hide this message', 'zlib_output_compression'));
     }
     /**
      * Check wp-content permissions
      */
     if (!W3TC_WIN && $this->_config->get_boolean('notes.wp_content_perms')) {
         $wp_content_stat = stat(WP_CONTENT_DIR);
         $wp_content_mode = $wp_content_stat['mode'] & 0777;
         if ($wp_content_mode != 0755) {
             $this->_notes[] = sprintf('<strong>%s</strong> is write-able. When finished installing the plugin, change the permissions back to the default: <strong>chmod 755 %s</strong>. %s', WP_CONTENT_DIR, WP_CONTENT_DIR, $this->button_hide_note('Hide this message', 'wp_content_perms'));
         }
     }
     /**
      * Check permalinks
      */
     if ($this->_config->get_boolean('notes.no_permalink_rules') && ($this->_config->get_boolean('pgcache.enabled') && $this->_config->get_string('pgcache.engine') == 'file_generic' || $this->_config->get_boolean('browsercache.enabled') && $this->_config->get_boolean('browsercache.no404wp')) && !w3_is_permalink_rules()) {
         $this->_errors[] = sprintf('The required directives for fancy permalinks could not be detected, please confirm they are available: <a href="http://codex.wordpress.org/Using_Permalinks#Creating_and_editing_.28.htaccess.29">Creating and editing</a> %s', $this->button_hide_note('Hide this message', 'no_permalink_rules'));
     }
     /**
      * CDN
      */
     if ($this->_config->get_boolean('cdn.enabled')) {
         /**
          * Check upload settings
          */
         $upload_info = w3_upload_info();
         if (!$upload_info) {
             $upload_path = get_option('upload_path');
             $upload_path = trim($upload_path);
             if (empty($upload_path)) {
                 $upload_path = WP_CONTENT_DIR . '/uploads';
                 $this->_errors[] = sprintf('The uploads directory is not available. Default WordPress directories will be created: <strong>%s</strong>.', $upload_path);
             }
             if (!w3_is_multisite()) {
                 $this->_errors[] = sprintf('The uploads path found in the database (%s) is inconsistent with the actual path. Please manually adjust the upload path either in miscellaneous settings or if not using a custom path %s automatically to resolve the issue.', $upload_path, $this->button_link('update the path', sprintf('admin.php?page=%s&update_upload_path', $this->_page)));
             }
         }
         /**
          * Check CDN settings
          */
         $cdn_engine = $this->_config->get_string('cdn.engine');
         switch (true) {
             case $cdn_engine == 'mirror' && !count($this->_config->get_array('cdn.mirror.domain')):
                 $this->_errors[] = 'Content Delivery Network Error: The <strong>"Replace default hostname with"</strong> field must be populated.';
                 break;
             case $cdn_engine == 'netdna' && !count($this->_config->get_array('cdn.netdna.domain')):
                 $this->_errors[] = 'Content Delivery Network Error: The <strong>"Replace default hostname with"</strong> field must be populated.';
                 break;
             case $cdn_engine == 'cotendo' && !count($this->_config->get_array('cdn.cotendo.domain')):
                 $this->_errors[] = 'Content Delivery Network Error: The <strong>"Replace default hostname with"</strong> field must be populated.';
                 break;
             case $cdn_engine == 'ftp' && !count($this->_config->get_array('cdn.ftp.domain')):
                 $this->_errors[] = 'Content Delivery Network Error: The <strong>"Replace default hostname with"</strong> field must be populated. Enter <acronym title="Content Delivery Network">CDN</acronym> provider hostname. <em>(This is the hostname used in order to view objects in a browser.)</em>';
                 break;
             case $cdn_engine == 's3' && ($this->_config->get_string('cdn.s3.key') == '' || $this->_config->get_string('cdn.s3.secret') == '' || $this->_config->get_string('cdn.s3.bucket') == ''):
                 $this->_errors[] = 'Content Delivery Network Error: The <strong>"Access key", "Secret key" and "Bucket"</strong> fields must be populated.';
                 break;
             case $cdn_engine == 'cf' && ($this->_config->get_string('cdn.cf.key') == '' || $this->_config->get_string('cdn.cf.secret') == '' || $this->_config->get_string('cdn.cf.bucket') == '' || $this->_config->get_string('cdn.cf.id') == '' && !count($this->_config->get_array('cdn.cf.cname'))):
                 $this->_errors[] = 'Content Delivery Network Error: The <strong>"Access key", "Secret key", "Bucket" and "Replace default hostname with"</strong> fields must be populated.';
                 break;
             case $cdn_engine == 'cf2' && ($this->_config->get_string('cdn.cf2.key') == '' || $this->_config->get_string('cdn.cf2.secret') == '' || $this->_config->get_string('cdn.cf2.id') == '' && !count($this->_config->get_array('cdn.cf2.cname'))):
                 $this->_errors[] = 'Content Delivery Network Error: The <strong>"Access key", "Secret key" and "Replace default hostname with"</strong> fields must be populated.';
                 break;
             case $cdn_engine == 'rscf' && ($this->_config->get_string('cdn.rscf.user') == '' || $this->_config->get_string('cdn.rscf.key') == '' || $this->_config->get_string('cdn.rscf.container') == '' || !count($this->_config->get_array('cdn.rscf.cname'))):
                 $this->_errors[] = 'Content Delivery Network Error: The <strong>"Username", "API key", "Container" and "Replace default hostname with"</strong> fields must be populated.';
                 break;
             case $cdn_engine == 'azure' && ($this->_config->get_string('cdn.azure.user') == '' || $this->_config->get_string('cdn.azure.key') == '' || $this->_config->get_string('cdn.azure.container') == ''):
                 $this->_errors[] = 'Content Delivery Network Error: The <strong>"Account name", "Account key" and "Container"</strong> fields must be populated.';
                 break;
         }
     }
     /**
      * Preview mode
      */
     if (w3_is_preview_config()) {
         $this->_notes[] = sprintf('Preview mode is active: Changed settings will not take effect until preview mode is %s or %s. %s any changed settings (without deploying), or make additional changes.', $this->button_link('deploy', sprintf('admin.php?page=%s&preview_deploy', $this->_page)), $this->button_link('disable', sprintf('admin.php?page=%s&preview_save&preview=0', $this->_page)), $this->button_link('Preview', w3_get_home_url() . '/?w3tc_preview=1', true));
     }
     /**
      * Show tab
      */
     switch ($this->_page) {
         case 'w3tc_general':
             $this->options_general();
             break;
         case 'w3tc_pgcache':
             $this->options_pgcache();
             break;
         case 'w3tc_minify':
             $this->options_minify();
             break;
         case 'w3tc_dbcache':
             $this->options_dbcache();
             break;
         case 'w3tc_objectcache':
             $this->options_objectcache();
             break;
         case 'w3tc_browsercache':
             $this->options_browsercache();
             break;
         case 'w3tc_mobile':
             $this->options_mobile();
             break;
         case 'w3tc_referrer':
             $this->options_referrer();
             break;
         case 'w3tc_cdn':
             $this->options_cdn();
             break;
         case 'w3tc_faq':
             $this->options_faq();
             break;
         case 'w3tc_support':
             require_once W3TC_LIB_W3_DIR . '/Request.php';
             $request_type = W3_Request::get_string('request_type');
             if (!$request_type || !isset($this->_request_types[$request_type])) {
                 $this->options_support_select();
             } else {
                 $payment = W3_Request::get_boolean('payment');
                 if (isset($this->_request_prices[$request_type]) && !$payment) {
                     $this->options_support_payment();
                 } else {
                     $this->options_support();
                 }
             }
             break;
         case 'w3tc_support_select':
             $this->options_support_select();
             break;
         case 'w3tc_support_payment':
             $this->options_support_payment();
             break;
         case 'w3tc_install':
             $this->options_install();
             break;
         case 'w3tc_about':
             $this->options_about();
             break;
     }
 }
/**
 * Checks if an extension is sealed by Network Admin
 * @param $extension
 * @return bool
 */
function w3_extension_is_sealed($extension)
{
    if (is_network_admin() || !w3_is_multisite()) {
        return false;
    }
    $config_admin = w3_instance('W3_ConfigAdmin');
    $all_checked = $config_admin->get_array('extensions.configuration_sealed');
    return isset($all_checked[$extension]) && $all_checked[$extension];
}
Exemplo n.º 23
0
 /**
  * Convert relative file which is relative to ABSPATH (wp folder on disc) to path uri
  *
  * @param $file
  * @return string
  */
 function docroot_filename_to_uri($file)
 {
     $file = ltrim($file, '/');
     // Translate multisite subsite uploads paths
     $file = str_replace(basename(WP_CONTENT_DIR) . '/blogs.dir/' . w3_get_blog_id() . '/', '', $file);
     if (strpos($file, basename(WP_CONTENT_DIR)) === 0 && !w3_is_multisite()) {
         $remote_path = '';
     } else {
         $remote_path = ltrim(w3_get_site_path(), "/");
     }
     if ($remote_path == substr($file, 0, strlen($remote_path))) {
         return $file;
     }
     return $remote_path . $file;
 }
Exemplo n.º 24
0
 /**
  * Checks if can we do cache logic
  *
  * @param string $buffer
  * @return boolean
  */
 function _can_cache2(&$buffer)
 {
     /**
      * Skip if caching is disabled
      */
     if (!$this->_caching) {
         return false;
     }
     /**
      * Check for database error
      */
     if (w3_is_database_error($buffer)) {
         $this->cache_reject_reason = 'Database error occurred';
         return false;
     }
     /**
      * Check for DONOTCACHEPAGE constant
      */
     if (defined('DONOTCACHEPAGE') && DONOTCACHEPAGE) {
         $this->cache_reject_reason = 'DONOTCACHEPAGE constant is defined';
         return false;
     }
     /**
      * Check hostname
      */
     if ((!w3_is_multisite() || w3_is_multisite() && !w3_force_master()) && $this->_config->get_boolean('pgcache.check.domain') && w3_get_host() != w3_get_home_domain()) {
         $this->cache_reject_reason = 'Hostname mismatch';
         return false;
     }
     /**
      * Don't cache 404 pages
      */
     if (!$this->_config->get_boolean('pgcache.cache.404') && function_exists('is_404') && is_404()) {
         $this->cache_reject_reason = 'Page is 404';
         return false;
     }
     /**
      * Don't cache homepage
      */
     if (!$this->_config->get_boolean('pgcache.cache.home') && function_exists('is_home') && is_home()) {
         $this->cache_reject_reason = is_front_page() && is_home() ? 'Page is front page' : 'Page is posts page';
         return false;
     }
     /**
      * Don't cache front page
      */
     if ($this->_config->get_boolean('pgcache.reject.front_page') && function_exists('is_front_page') && is_front_page() && !is_home()) {
         $this->cache_reject_reason = 'Page is front page';
         return false;
     }
     /**
      * Don't cache feed
      */
     if (!$this->_config->get_boolean('pgcache.cache.feed') && function_exists('is_feed') && is_feed()) {
         $this->cache_reject_reason = 'Page is feed';
         return false;
     }
     /**
      * Check if page contains dynamic tags
      */
     if ($this->_enhanced_mode && $this->_has_dynamic($buffer)) {
         $this->cache_reject_reason = 'Page contains dynamic tags (mfunc or mclude) can not be cached in enhanced mode';
         return false;
     }
     return true;
 }
Exemplo n.º 25
0
<?php

if (!defined('W3TC')) {
    die;
}
?>

<?php 
/**
 * @var array $custom_areas Filter that sets it is located in GeneralAdminVIew
 */
$licensing_visible = (!w3_is_multisite() || is_network_admin()) && !ini_get('w3tc.license_key') && get_transient('w3tc_license_status') != 'host_valid';
?>

<?php 
do_action('w3tc-dashboard-head');
?>
<div class="wrap" id="w3tc">
    <h2 class="logo"><?php 
_e('W3 Total Cache <span>by W3 EDGE <sup>&reg;</sup></span>', 'w3-total-cache');
?>
</h2>
<?php 
if (!(w3_is_pro($this->_config) || w3_is_enterprise($this->_config))) {
    ?>
    <?php 
    include W3TC_INC_OPTIONS_DIR . '/edd/buy.php';
}
?>
    <?php 
foreach ($this->_errors as $error) {
Exemplo n.º 26
0
/**
 * Returns home URL
 *
 * No trailing slash!
 *
 * @return string
 */
function w3_get_home_url()
{
    static $home_url = null;
    if ($home_url === null) {
        $config = w3_instance('W3_Config');
        if (w3_is_multisite() && $config->get_boolean('common.force_master')) {
            $home_url = get_home_url();
        } else {
            // get_option is unusable here, it can cause problem when objCache isn't yet initialized
            // Which is why we save the 'home' option in our ConfigCache
            // We don't just use $config->get_string, because we want the cache to rebuild
            // when 'wordpress.home' is not (yet) present
            $home_url = $config->get_cache_option('wordpress.home');
            $home_url = rtrim($home_url, '/');
        }
    }
    return $home_url;
}
Exemplo n.º 27
0
 function setup()
 {
     /**
      * @var $nerser W3_NewRelicService
      */
     $nerser = w3_instance('W3_NewRelicService');
     w3_require_once(W3TC_LIB_NEWRELIC_DIR . '/NewRelicWrapper.php');
     $config_master = new W3_Config(true);
     $view_application = 0;
     if ($this->_config->get_boolean('newrelic.enabled')) {
         if ($this->_config->get_boolean('newrelic.use_php_function') || w3_is_multisite()) {
             if (!$config_master->get_boolean('newrelic.use_network_wide_id') && (w3_get_blog_id() == 0 || !$this->_config->get_boolean('common.force_master'))) {
                 $view_application = $this->_config->get_string('newrelic.application_id', 0);
             } else {
                 $appname = NewRelicWrapper::get_wordpress_appname($this->_config, $config_master, false);
                 try {
                     $view_application = $nerser->get_application_id($appname);
                     $nerser->set_application_id($view_application);
                 } catch (Exception $ex) {
                 }
             }
         } else {
             $view_application = $this->_config->get_string('newrelic.application_id', 0);
         }
     }
     $this->_application_id = $view_application;
     $this->_account_id = $this->_config->get_string('newrelic.account_id', 0);
 }
 /**
  * Activate plugin action
  *
  * @return void
  */
 function activate()
 {
     require_once W3TC_INC_DIR . '/functions/activation.php';
     /**
      * Disable buggy sitewide activation in WPMU and WP 3.0
      */
     if (w3_is_wpmu() && isset($_GET['sitewide']) || w3_is_multisite() && isset($_GET['networkwide'])) {
         w3_network_activate_error();
     }
     /**
      * Check installation files
      */
     $files = array(W3TC_INSTALL_FILE_ADVANCED_CACHE, W3TC_INSTALL_FILE_DB, W3TC_INSTALL_FILE_OBJECT_CACHE);
     $nonexistent_files = array();
     foreach ($files as $file) {
         if (!file_exists($file)) {
             $nonexistent_files[] = $file;
         }
     }
     if (count($nonexistent_files)) {
         $error = sprintf('Unfortunately core file(s): (<strong>%s</strong>) are missing, so activation will fail. Please re-start the installation process from the beginning.', implode(', ', $nonexistent_files));
         w3_activate_error($error);
     }
     if (!@is_dir(W3TC_CONTENT_DIR) && !@mkdir(W3TC_CONTENT_DIR)) {
         w3_writable_error(W3TC_CONTENT_DIR);
     }
     if (!@is_dir(W3TC_CACHE_FILE_DBCACHE_DIR) && !@mkdir(W3TC_CACHE_FILE_DBCACHE_DIR)) {
         w3_writable_error(W3TC_CACHE_FILE_DBCACHE_DIR);
     }
     if (!@is_dir(W3TC_CACHE_FILE_OBJECTCACHE_DIR) && !@mkdir(W3TC_CACHE_FILE_OBJECTCACHE_DIR)) {
         w3_writable_error(W3TC_CACHE_FILE_OBJECTCACHE_DIR);
     }
     if (!@is_dir(W3TC_CACHE_FILE_PGCACHE_DIR) && !@mkdir(W3TC_CACHE_FILE_PGCACHE_DIR)) {
         w3_writable_error(W3TC_CACHE_FILE_PGCACHE_DIR);
     }
     if (!@is_dir(W3TC_CACHE_FILE_MINIFY_DIR) && !@mkdir(W3TC_CACHE_FILE_MINIFY_DIR)) {
         w3_writable_error(W3TC_CACHE_FILE_MINIFY_DIR);
     }
     if (!@is_dir(W3TC_LOG_DIR) && !@mkdir(W3TC_LOG_DIR)) {
         w3_writable_error(W3TC_LOG_DIR);
     }
     if (!@is_dir(W3TC_TMP_DIR) && !@mkdir(W3TC_TMP_DIR)) {
         w3_writable_error(W3TC_TMP_DIR);
     }
     if (w3_is_network() && file_exists(W3TC_CONFIG_MASTER_PATH)) {
         /**
          * For multisite load master config
          */
         $this->_config->load_master();
         if (!$this->_config->save(false)) {
             w3_writable_error(W3TC_CONFIG_PATH);
         }
     } elseif (!file_exists(W3TC_CONFIG_PATH)) {
         /**
          * Set default settings
          */
         $this->_config->set_defaults();
         /**
          * If config doesn't exist enable preview mode
          */
         if (!$this->_config->save(true)) {
             w3_writable_error(W3TC_CONFIG_PREVIEW_PATH);
         }
     }
     /**
      * Save blognames into file
      */
     if (w3_is_network() && !w3_is_subdomain_install()) {
         if (!w3_save_blognames()) {
             w3_writable_error(W3TC_BLOGNAMES_PATH);
         }
     }
     delete_option('w3tc_request_data');
     add_option('w3tc_request_data', '', null, 'no');
 }
Exemplo n.º 29
0
 /**
  * Flush cache based on regex
  * @param string $regex
  */
 private function _flush_based_on_regex($regex)
 {
     if (w3_is_multisite() && !w3_is_subdomain_install()) {
         $domain = w3_get_home_url();
         $parsed = parse_url($domain);
         $host = $parsed['host'];
         $path = trim($parsed['path'], '/');
         $flush_dir = W3TC_CACHE_PAGE_ENHANCED_DIR . '/' . $host . '/' . $path;
     } else {
         $flush_dir = W3TC_CACHE_PAGE_ENHANCED_DIR . '/' . w3_get_domain(w3_get_host());
     }
     $dir = @opendir($flush_dir);
     if ($dir) {
         while (($entry = @readdir($dir)) !== false) {
             if ($entry == '.' || $entry == '..') {
                 continue;
             }
             if (preg_match('/' . $regex . '/', basename($entry))) {
                 w3_rmdir($flush_dir . DIRECTORY_SEPARATOR . $entry);
             }
         }
         @closedir($dir);
     }
 }
Exemplo n.º 30
0
 /**
  * General tab
  *
  * @return void
  */
 function view()
 {
     global $current_user;
     $config_master = $this->_config_master;
     /**
      * @var $modules W3_ModuleStatus
      */
     $modules = w3_instance('W3_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');
     $cloudflare_enabled = $modules->is_enabled('cloudflare');
     $varnish_enabled = $modules->is_enabled('varnish');
     $fragmentcache_enabled = $modules->is_enabled('fragmentcache');
     $enabled = $modules->plugin_is_enabled();
     $enabled_checkbox = $modules->all_modules_enabled();
     $check_rules = w3_can_check_rules();
     $check_apc = function_exists('apc_store');
     $check_eaccelerator = function_exists('eaccelerator_put');
     $check_xcache = function_exists('xcache_set');
     $check_wincache = function_exists('wincache_ucache_set');
     $check_curl = function_exists('curl_init');
     $check_memcached = class_exists('Memcache');
     $check_ftp = function_exists('ftp_connect');
     $check_tidy = class_exists('tidy');
     $disc_enhanced_enabled = !(!$check_rules || !$this->is_master() && w3_is_network() && $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 = w3_cdn_can_purge_all($modules->get_module_engine('cdn'));
     $cloudflare_signup_email = '';
     $cloudflare_signup_user = '';
     if (is_a($current_user, 'WP_User')) {
         if ($current_user->user_email) {
             $cloudflare_signup_email = $current_user->user_email;
         }
         if ($current_user->user_login && $current_user->user_login != 'admin') {
             $cloudflare_signup_user = $current_user->user_login;
         }
     }
     /**
      * @var $w3_cloudflare W3_CloudFlare
      */
     $w3_cloudflare = w3_instance('W3_CloudFlare');
     $cf_options = $w3_cloudflare->get_options();
     $cloudflare_seclvls = $cf_options['sec_lvl'];
     $cloudflare_devmodes = $cf_options['dev_mode'];
     $cloudflare_rocket_loaders = $cf_options['async'];
     $cloudflare_minifications = $cf_options['minify'];
     $cloudflare_seclvl = 'med';
     $cloudflare_devmode_expire = 0;
     $cloudflare_devmode = 0;
     $cloudflare_rocket_loader = 0;
     $cloudflare_minify = 0;
     if ($cloudflare_enabled && $this->_config->get_string('cloudflare.email') && $this->_config->get_string('cloudflare.key')) {
         $settings = $w3_cloudflare->get_settings();
         $cloudflare_seclvl = $settings['sec_lvl'];
         $cloudflare_devmode_expire = $settings['devmode'];
         $cloudflare_rocket_loader = $settings['async'];
         $cloudflare_devmode = $cloudflare_devmode_expire ? 1 : 0;
         $cloudflare_minify = $settings['minify'];
         $can_empty_cloudflare = true;
     } else {
         $can_empty_cloudflare = false;
     }
     $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');
     w3_require_once(W3TC_LIB_NEWRELIC_DIR . '/NewRelicWrapper.php');
     $newrelic_conf_appname = NewRelicWrapper::get_wordpress_appname($this->_config, $this->_config_master, false);
     $newrelic_applications = array();
     $nerser = w3_instance('W3_NewRelicService');
     $new_relic_installed = $nerser->module_is_enabled();
     $new_relic_running = true;
     if ($this->_config->get_boolean('newrelic.enabled')) {
         $new_relic_configured = $this->_config->get_string('newrelic.api_key') && $this->_config->get_string('newrelic.account_id');
         $newrelic_prefix = '';
         if ($new_relic_configured) {
             if (w3_is_network()) {
                 $newrelic_prefix = $this->_config->get_string('newrelic.appname_prefix');
             }
             try {
                 $newrelic_applications = $nerser->get_applications();
             } catch (Exception $ex) {
             }
             $newrelic_application = $this->_config->get_string('newrelic.application_id');
         }
     }
     $licensing_visible = (!w3_is_multisite() || is_network_admin()) && !ini_get('w3tc.license_key') && get_transient('w3tc_license_status') != 'host_valid';
     include W3TC_INC_DIR . '/options/general.php';
 }