/** * Flush varnish cache */ function flush() { if (!is_network_admin()) { $this->_purge(w3_get_home_url() . '/.*'); } else { global $wpdb; $protocall = w3_is_https() ? 'https://' : 'http://'; // If WPMU Domain Mapping plugin is installed and active if (defined('SUNRISE_LOADED') && SUNRISE_LOADED && isset($wpdb->dmtable) && !empty($wpdb->dmtable)) { $blogs = $wpdb->get_results("SELECT {$wpdb->blogs}.domain, {$wpdb->blogs}.path, {$wpdb->dmtable}.domain AS mapped_domain\n FROM {$wpdb->dmtable}\n RIGHT JOIN {$wpdb->blogs} ON {$wpdb->dmtable}.blog_id = {$wpdb->blogs}.blog_id\n WHERE site_id = {$wpdb->siteid}\n AND spam = 0\n AND deleted = 0\n AND archived = '0'\n "); foreach ($blogs as $blog) { if (!isset($blog->mapped_domain)) { $url = $protocall . $blog->domain . (strlen($blog->path) > 1 ? '/' . trim($blog->path, '/') : '') . '/.*'; } else { $url = $protocall . $blog->mapped_domain . '/.*'; } $this->_purge($url); } } else { if (!w3_is_subdomain_install()) { $this->_purge(w3_get_home_url() . '/.*'); } else { $blogs = $wpdb->get_results("\n SELECT domain, path\n FROM {$wpdb->blogs}\n WHERE site_id = '{$wpdb->siteid}'\n AND spam = 0\n AND deleted = 0\n AND archived = '0'\n "); foreach ($blogs as $blog) { $url = $protocall . $blog->domain . (strlen($blog->path) > 1 ? '/' . trim($blog->path, '/') : '') . '/.*'; $this->_purge($url); } } } } }
/** * Export config action * * @return void */ function action_config_export() { $filename = substr(w3_get_home_url(), strpos(w3_get_home_url(), '//') + 2); @header(sprintf(__('Content-Disposition: attachment; filename=%s.php', 'w3-total-cache'), $filename)); echo $this->_config->export(); die; }
/** * PageSpeed widget * * @return void */ function widget_pagespeed() { w3_require_once(W3TC_LIB_W3_DIR . '/PageSpeed.php'); w3_require_once(W3TC_LIB_W3_DIR . '/Request.php'); $key = $this->_config->get_string('widget.pagespeed.key'); $force = W3_Request::get_boolean('w3tc_widget_pagespeed_force'); $results = null; if ($key) { $w3_pagespeed = new W3_PageSpeed(); $results = $w3_pagespeed->analyze(w3_get_home_url(), $force); } include W3TC_INC_DIR . '/widget/pagespeed.php'; }
/** * CDN tab * * @return void */ function view() { w3_require_once(W3TC_INC_FUNCTIONS_DIR . '/ui.php'); $cdn_enabled = $this->_config->get_boolean('cdn.enabled'); $cdn_engine = $this->_config->get_string('cdn.engine'); $cdn_mirror = w3_is_cdn_mirror($cdn_engine); $cdn_mirror_purge_all = w3_cdn_can_purge_all($cdn_engine); $cdn_common = w3_instance('W3_Plugin_CdnCommon'); $cdn = $cdn_common->get_cdn(); $cdn_supports_header = $cdn->headers_support() == W3TC_CDN_HEADER_MIRRORING; $cdn_supports_full_page_mirroring = $cdn->supports_full_page_mirroring(); $minify_enabled = $this->_config->get_boolean('minify.enabled') && $this->_config->get_boolean('minify.rewrite') && (!$this->_config->get_boolean('minify.auto') || w3_is_cdn_mirror($this->_config->get_string('cdn.engine'))); $cookie_domain = $this->get_cookie_domain(); $set_cookie_domain = $this->is_cookie_domain_enabled(); // Required for Update Media Query String button $browsercache_enabled = $this->_config->get_boolean('browsercache.enabled'); $browsercache_update_media_qs = $this->_config->get_boolean('browsercache.cssjs.replace') || $this->_config->get_boolean('browsercache.other.replace'); if (in_array($cdn_engine, array('netdna', 'maxcdn'))) { $pull_zones = array(); $authorization_key = $this->_config->get_string("cdn.{$cdn_engine}.authorization_key"); $zone_id = $this->_config->get_integer("cdn.{$cdn_engine}.zone_id"); $alias = $consumerkey = $consumersecret = ''; if ($authorization_key) { $keys = explode('+', $authorization_key); if (sizeof($keys) == 3) { list($alias, $consumerkey, $consumersecret) = $keys; } } $authorized = $authorization_key != '' && $alias && $consumerkey && $consumersecret; $have_zone = $zone_id != 0; if ($authorized) { w3_require_once(W3TC_LIB_NETDNA_DIR . '/NetDNA.php'); try { $api = new NetDNA($alias, $consumerkey, $consumersecret); $pull_zones = $api->get_zones_by_url(w3_get_home_url()); } catch (Exception $ex) { w3_require_once(W3TC_INC_FUNCTIONS_DIR . '/ui.php'); w3_e_error_box('<p>There is an error with your CDN settings: ' . $ex->getMessage() . '</p>'); } } } include W3TC_INC_DIR . '/options/cdn.php'; }
/** * Returns path of pgcache cache rules file * Moved to separate file to not load rule.php for each disk enhanced request * * @return string */ function w3_get_pgcache_rules_cache_path() { switch (true) { case w3_is_apache(): case w3_is_litespeed(): if (w3_is_network()) { $url = w3_get_home_url(); $match = null; if (preg_match('~http(s)?://(.+?)(/)?$~', $url, $match)) { $home_path = $match[2]; return W3TC_CACHE_PAGE_ENHANCED_DIR . '/' . $home_path . '/.htaccess'; } } return W3TC_CACHE_PAGE_ENHANCED_DIR . '/.htaccess'; case w3_is_nginx(): return w3_get_nginx_rules_path(); } return false; }
/** * Create NetDNA/MaxCDN pullzone */ function action_cdn_create_netdna_maxcdn_pull_zone() { w3_require_once(W3TC_LIB_W3_DIR . '/Request.php'); $type = W3_Request::get_string('type'); $name = W3_Request::get_string('name'); $label = W3_Request::get_string('label'); w3_require_once(W3TC_LIB_NETDNA_DIR . '/NetDNA.php'); $cdn_engine = $this->_config->get_string('cdn.engine'); $authorization_key = $this->_config->get_string("cdn.{$cdn_engine}.authorization_key"); $alias = $consumerkey = $consumersecret = ''; if ($authorization_key) { $keys = explode('+', $authorization_key); if (sizeof($keys) == 3) { list($alias, $consumerkey, $consumersecret) = $keys; } } $api = new NetDNA($alias, $consumerkey, $consumersecret); $url = w3_get_home_url(); $zone = array(); $zone['name'] = $name; $zone['label'] = $label; $zone['url'] = $url; try { $response = $api->create_pull_zone($zone); try { $this->_config->set('cdn.enabled', true); if (!$this->_config->get_array("cdn.{$cdn_engine}.domain")) { $this->_config->set("cdn.{$cdn_engine}.domain", array("{$name}.{$alias}.netdna-cdn.com")); } $this->_config->save(); } catch (Exception $ex) { } echo json_encode(array('status' => 'success', 'message' => 'Pull Zone created.', 'temporary_url' => "{$name}.{$alias}.netdna-cdn.com", 'data' => $response)); } catch (Exception $ex) { echo json_encode(array('status' => 'error', 'message' => $ex->getMessage())); } }
/** * Purge CDN completely * @param $results * @return bool */ function purge_all(&$results) { if (empty($this->_config['authorization_key'])) { $results = $this->_get_results(array(), W3TC_CDN_RESULT_HALT, __('Empty Authorization Key.', 'w3-total-cache')); return false; } if (empty($this->_config['alias']) || empty($this->_config['consumerkey']) || empty($this->_config['consumersecret'])) { $results = $this->_get_results(array(), W3TC_CDN_RESULT_HALT, __('Malformed Authorization Key.', 'w3-total-cache')); return false; } if (!class_exists('NetDNA')) { w3_require_once(W3TC_LIB_NETDNA_DIR . '/NetDNA.php'); } $api = new NetDNA($this->_config['alias'], $this->_config['consumerkey'], $this->_config['consumersecret']); $results = array(); $local_path = $remote_path = ''; $domain_is_valid = 0; $found_domain = false; try { if ($this->_config['zone_id'] != 0) { $zone_id = $this->_config['zone_id']; } else { $zone_id = $api->get_zone_id(w3_get_home_url()); } if ($zone_id == 0) { $zone_id = $api->get_zone_id(w3_get_domain_url()); } if ($zone_id == 0) { $zone_id = $api->get_zone_id(str_replace('://', '://www.', w3_get_domain_url())); } if ($zone_id == 0 || is_null($zone_id)) { if (w3_get_domain_url() == w3_get_home_url()) { $results[] = $this->_get_result($local_path, $remote_path, W3TC_CDN_RESULT_ERROR, sprintf(__('No zones match site: %s.', 'w3-total-cache'), trim(w3_get_home_url(), '/'))); } else { $results[] = $this->_get_result($local_path, $remote_path, W3TC_CDN_RESULT_ERROR, sprintf(__('No zones match site: %s or %s.', 'w3-total-cache'), trim(w3_get_home_url(), '/'), trim(w3_get_domain_url(), '/'))); } return !$this->_is_error($results); } $pullzone = json_decode($api->get('/zones/pull.json/' . $zone_id)); try { if (preg_match("(200|201)", $pullzone->code)) { $custom_domains_full = json_decode($api->get('/zones/pull/' . $pullzone->data->pullzone->id . '/customdomains.json')); $custom_domains = array(); foreach ($custom_domains_full->data->customdomains as $custom_domain_full) { $custom_domains[] = $custom_domain_full->custom_domain; } $local_path = 'all'; $remote_path = 'all'; $domain_is_valid = 0; $found_domain = false; if ($pullzone->data->pullzone->name . '.' . $this->_config['alias'] . '.' . W3TC_CDN_NETDNA_URL === $this->get_domain($local_path) || in_array($this->get_domain($local_path), $custom_domains)) { try { $params = array('file' => '/' . $local_path); $file_purge = json_decode($api->delete('/zones/pull.json/' . $pullzone->data->pullzone->id . '/cache')); if (preg_match("(200|201)", $file_purge->code)) { $results[] = $this->_get_result($local_path, $remote_path, W3TC_CDN_RESULT_OK, __('OK', 'w3-total-cache')); } else { if (preg_match("(401|500)", $file_purge->code)) { $results[] = $this->_get_result($local_path, $remote_path, W3TC_CDN_RESULT_ERROR, sprintf(__('Failed with error code %s. Please check your alias, consumer key, and private key.', 'w3-total-cache'), $file_purge->code)); } else { $results[] = $this->_get_result($local_path, $remote_path, W3TC_CDN_RESULT_ERROR, __('Failed with error code ', 'w3-total-cache') . $file_purge->code); } } $found_domain = true; } catch (CurlException $e) { $results[] = $this->_get_result($local_path, $remote_path, W3TC_CDN_RESULT_HALT, sprintf(__('Unable to purge (%s).', 'w3-total-cache'), $e->getMessage())); } } else { $results[] = $this->_get_result($local_path, $remote_path, W3TC_CDN_RESULT_ERROR, sprintf(__('No registered CNAMEs match %s.', 'w3-total-cache'), $this->get_domain($local_path))); return !$this->_is_error($results); } } else { if (preg_match("(401|500)", $pullzone->code)) { $results[] = $this->_get_result($local_path, $remote_path, W3TC_CDN_RESULT_ERROR, sprintf(__('Failed with error code %s. Please check your alias, consumer key, and private key.', 'w3-total-cache'), $pullzone->code)); } else { $results[] = $this->_get_result($local_path, $remote_path, W3TC_CDN_RESULT_ERROR, __('Failed with error code ', 'w3-total-cache') . $pullzone->code); } } } catch (CurlException $e) { $results[] = $this->_get_result($local_path, $remote_path, W3TC_CDN_RESULT_HALT, sprintf(__('Unable to purge (%s).', 'w3-total-cache'), $e->getMessage())); } } catch (CurlException $e) { $results[] = $this->_get_result($local_path, $remote_path, W3TC_CDN_RESULT_HALT, __('Failure to pull zone: ', 'w3-total-cache') . $e->getMessage()); } if ($domain_is_valid > 0 && !$found_domain) { $results[] = $this->_get_result($local_path, $remote_path, W3TC_CDN_RESULT_ERROR, __('No zones match custom domain.', 'w3-total-cache')); } elseif (!$found_domain) { $results[] = $this->_get_result($local_path, $remote_path, W3TC_CDN_RESULT_ERROR, sprintf(__('No zones match site: %s.', 'w3-total-cache'), trim(w3_get_home_url(), '/'))); } return !$this->_is_error($results); }
?> </label></th> <td><input type="text" id="name" name="name"/><div class="name_message w3tc-error inline"></div> <p><span class="description"><?php _e('Pull Zone Name. Length: 3-32 chars; only letters, digits, and dash (-) accepted', 'w3-total-cache'); ?> </span></p> </td> </tr> <tr> <th><label for="url"><?php _e('Origin <acronym title="Uniform Resource Indicator">URL</acronym>:', 'w3-total-cache'); ?> </label></th> <td><?php echo w3_get_home_url(); ?> <p><span class="description"><?php _e('Your server\'s hostname or domain', 'w3-total-cache'); ?> </span></p> </td> </tr> <tr> <th><label for="label"><?php _e('Description:', 'w3-total-cache'); ?> </label></th> <td><textarea id="label" name="label" cols="40"></textarea><div class="label_message w3tc-error inline"></div> <p><span class="description"><?php _e('Something that describes your zone. Length: 1-255 chars', 'w3-total-cache');
/** * Returns home path * * Example: * * home=http://domain.com/site/ * siteurl=http://domain.com/site/blog * return /site/ * * With trailing slash! * * @return string */ function w3_get_home_path() { $home_url = w3_get_home_url(); $parse_url = @parse_url($home_url); if ($parse_url && isset($parse_url['path'])) { $home_path = '/' . ltrim($parse_url['path'], '/'); } else { $home_path = '/'; } if (substr($home_path, -1) != '/') { $home_path .= '/'; } return $home_path; }
/** * Send support request action * * @return void */ function action_support_request() { w3_require_once(W3TC_LIB_W3_DIR . '/Request.php'); $request_type = W3_Request::get_string('request_type'); $payment = W3_Request::get_boolean('payment'); $request_id = W3_Request::get_string('request_id'); $url = W3_Request::get_string('url'); $name = W3_Request::get_string('name'); $email = W3_Request::get_string('email'); $twitter = W3_Request::get_string('twitter'); $phone = W3_Request::get_string('phone'); $subject = W3_Request::get_string('subject'); $description = W3_Request::get_string('description'); $templates = W3_Request::get_array('templates'); $forum_url = W3_Request::get_string('forum_url'); $wp_login = W3_Request::get_string('wp_login'); $wp_password = W3_Request::get_string('wp_password'); $ftp_host = W3_Request::get_string('ftp_host'); $ftp_login = W3_Request::get_string('ftp_login'); $ftp_password = W3_Request::get_string('ftp_password'); $subscribe_releases = W3_Request::get_string('subscribe_releases'); $subscribe_customer = W3_Request::get_string('subscribe_customer'); $params = array('request_type' => $request_type, 'payment' => $payment, 'url' => $url, 'name' => $name, 'email' => $email, 'twitter' => $twitter, 'phone' => $phone, 'subject' => $subject, 'description' => $description, 'forum_url' => $forum_url, 'wp_login' => $wp_login, 'wp_password' => $wp_password, 'ftp_host' => $ftp_host, 'ftp_login' => $ftp_login, 'ftp_password' => $ftp_password, 'subscribe_releases' => $subscribe_releases, 'subscribe_customer' => $subscribe_customer); $post = $params; foreach ($templates as $template_index => $template) { $template_key = sprintf('templates[%d]', $template_index); $params[$template_key] = $template; } if (!isset($this->_request_types[$request_type])) { w3_admin_redirect(array_merge($params, array('w3tc_error' => 'support_request_type')), false); } $required = array('bug_report' => 'url,name,email,subject,description', 'new_feature' => 'url,name,email,subject,description', 'email_support' => 'url,name,email,subject,description', 'phone_support' => 'url,name,email,subject,description,phone', 'plugin_config' => 'url,name,email,subject,description,wp_login,wp_password', 'theme_config' => 'url,name,email,subject,description,wp_login,wp_password,ftp_host,ftp_login,ftp_password', 'linux_config' => 'url,name,email,subject,description,wp_login,wp_password,ftp_host,ftp_login,ftp_password'); if (strstr($required[$request_type], 'url') !== false && $url == '') { w3_admin_redirect(array_merge($params, array('w3tc_error' => 'support_request_url')), false); } if (strstr($required[$request_type], 'name') !== false && $name == '') { w3_admin_redirect(array_merge($params, array('w3tc_error' => 'support_request_name')), false); } if (strstr($required[$request_type], 'email') !== false && !preg_match('~^[a-z0-9_\\-\\.]+@[a-z0-9-\\.]+\\.[a-z]{2,5}$~', $email)) { w3_admin_redirect(array_merge($params, array('w3tc_error' => 'support_request_email')), false); } if (strstr($required[$request_type], 'phone') !== false && !preg_match('~^[0-9\\-\\.\\ \\(\\)\\+]+$~', $phone)) { w3_admin_redirect(array_merge($params, array('w3tc_error' => 'support_request_phone')), false); } if (strstr($required[$request_type], 'subject') !== false && $subject == '') { w3_admin_redirect(array_merge($params, array('w3tc_error' => 'support_request_subject')), false); } if (strstr($required[$request_type], 'description') !== false && $description == '') { w3_admin_redirect(array_merge($params, array('w3tc_error' => 'support_request_description')), false); } if (strstr($required[$request_type], 'wp_login') !== false && $wp_login == '') { w3_admin_redirect(array_merge($params, array('w3tc_error' => 'support_request_wp_login')), false); } if (strstr($required[$request_type], 'wp_password') !== false && $wp_password == '') { w3_admin_redirect(array_merge($params, array('w3tc_error' => 'support_request_wp_password')), false); } if (strstr($required[$request_type], 'ftp_host') !== false && $ftp_host == '') { w3_admin_redirect(array_merge($params, array('w3tc_error' => 'support_request_ftp_host')), false); } if (strstr($required[$request_type], 'ftp_login') !== false && $ftp_login == '') { w3_admin_redirect(array_merge($params, array('w3tc_error' => 'support_request_ftp_login')), false); } if (strstr($required[$request_type], 'ftp_password') !== false && $ftp_password == '') { w3_admin_redirect(array_merge($params, array('w3tc_error' => 'support_request_ftp_password')), false); } /** * Add attachments */ $attachments = array(); $attach_files = array(w3_get_wp_config_path(), w3_cache_blog_dir('log') . '/minify.log', w3_get_pgcache_rules_core_path(), w3_get_pgcache_rules_cache_path(), w3_get_browsercache_rules_cache_path(), w3_get_browsercache_rules_no404wp_path(), w3_get_minify_rules_core_path(), w3_get_minify_rules_cache_path()); /** * Attach config files */ if ($handle = opendir(W3TC_CONFIG_DIR)) { while (($entry = @readdir($handle)) !== false) { if ($entry == '.' || $entry == '..' || $entry == 'index.html') { continue; } $attachments[] = W3TC_CONFIG_DIR . '/' . $entry; } closedir($handle); } foreach ($attach_files as $attach_file) { if ($attach_file && file_exists($attach_file) && !in_array($attach_file, $attachments)) { $attachments[] = $attach_file; } } /** * Attach server info */ $server_info = print_r($this->get_server_info(), true); $server_info = str_replace("\n", "\r\n", $server_info); $server_info_path = W3TC_CACHE_TMP_DIR . '/server_info.txt'; if (@file_put_contents($server_info_path, $server_info)) { $attachments[] = $server_info_path; } /** * Attach phpinfo */ ob_start(); phpinfo(); $php_info = ob_get_contents(); ob_end_clean(); $php_info_path = W3TC_CACHE_TMP_DIR . '/php_info.html'; if (@file_put_contents($php_info_path, $php_info)) { $attachments[] = $php_info_path; } /** * Attach self-test */ ob_start(); $this->action_self_test(); $self_test = ob_get_contents(); ob_end_clean(); $self_test_path = W3TC_CACHE_TMP_DIR . '/self_test.html'; if (@file_put_contents($self_test_path, $self_test)) { $attachments[] = $self_test_path; } /** * Attach templates */ foreach ($templates as $template) { if (!empty($template)) { $attachments[] = $template; } } /** * Attach other files */ if (!empty($_FILES['files'])) { $files = (array) $_FILES['files']; for ($i = 0, $l = count($files); $i < $l; $i++) { if (isset($files['tmp_name'][$i]) && isset($files['name'][$i]) && isset($files['error'][$i]) && $files['error'][$i] == UPLOAD_ERR_OK) { $path = W3TC_CACHE_TMP_DIR . '/' . $files['name'][$i]; if (@move_uploaded_file($files['tmp_name'][$i], $path)) { $attachments[] = $path; } } } } $data = array(); if (!empty($wp_login) && !empty($wp_password)) { $data['WP Admin login'] = $wp_login; $data['WP Admin password'] = $wp_password; } if (!empty($ftp_host) && !empty($ftp_login) && !empty($ftp_password)) { $data['SSH / FTP host'] = $ftp_host; $data['SSH / FTP login'] = $ftp_login; $data['SSH / FTP password'] = $ftp_password; } /** * Store request data for future access */ if (count($data)) { $hash = md5(microtime()); $request_data = get_option('w3tc_request_data', array()); $request_data[$hash] = $data; update_option('w3tc_request_data', $request_data); $request_data_url = sprintf('%s/w3tc_request_data/%s', w3_get_home_url(), $hash); } else { $request_data_url = ''; } $nonce = wp_create_nonce('w3tc_support_request'); if (is_network_admin()) { update_site_option('w3tc_support_request', $nonce); } else { update_option('w3tc_support_request', $nonce); } $file_access = WP_PLUGIN_URL . '/' . dirname(W3TC_FILE) . '/pub/files.php'; if (w3_get_domain(w3_get_home_url()) != w3_get_domain(w3_get_site_url())) { $file_access = str_replace(w3_get_domain(w3_get_home_url()), w3_get_domain(w3_get_site_url()), $file_access); } $post['file_access'] = $file_access; $post['nonce'] = $nonce; $post['request_data_url'] = $request_data_url; $post['ip'] = $_SERVER['REMOTE_ADDR']; $post['user_agent'] = $_SERVER['HTTP_USER_AGENT']; $post['version'] = W3TC_VERSION; $post['plugin'] = 'W3 Total Cache'; $post['request_id'] = $request_id; $license_level = 'community'; if (w3_is_pro($this->_config)) { $license_level = 'pro'; } elseif (w3_is_enterprise($this->_config)) { $license_level = 'enterprise'; } $post['license_level'] = $license_level; $unset = array('wp_login', 'wp_password', 'ftp_host', 'ftp_login', 'ftp_password'); foreach ($unset as $key) { unset($post[$key]); } foreach ($attachments as $attachment) { if (is_network_admin()) { update_site_option('attachment_' . md5($attachment), $attachment); } else { update_option('attachment_' . md5($attachment), $attachment); } } $post = array_merge($post, array('files' => $attachments)); if (defined('W3_SUPPORT_DEBUG') && W3_SUPPORT_DEBUG) { $data = sprintf("[%s] Post support request\n", date('r')); foreach ($post as $key => $value) { $data .= sprintf("%s => %s\n", $key, is_array($value) ? implode(',', $value) : $value); } $filename = w3_cache_blog_dir('log') . '/support.log'; if (!is_dir(dirname($filename))) { w3_mkdir_from(dirname($filename), W3TC_CACHE_DIR); } @file_put_contents($filename, $data, FILE_APPEND); } $response = wp_remote_post(W3TC_SUPPORT_REQUEST_URL, array('body' => $post, 'timeout' => $this->_config->get_integer('timelimit.email_send'))); if (defined('W3_SUPPORT_DEBUG') && W3_SUPPORT_DEBUG) { $filename = w3_cache_blog_dir('log') . '/support.log'; $data = sprintf("[%s] Post response \n%s\n", date('r'), print_r($response, true)); @file_put_contents($filename, $data, FILE_APPEND); } if (!is_wp_error($response)) { $result = $response['response']['code'] == 200 && $response['body'] == 'Ok'; } else { $result = false; } /** * Remove temporary files */ foreach ($attachments as $attachment) { if (strstr($attachment, W3TC_CACHE_TMP_DIR) !== false) { @unlink($attachment); } if (is_network_admin()) { delete_site_option('attachment_' . md5($attachment)); } else { delete_option('attachment_' . md5($attachment)); } } if (is_network_admin()) { delete_site_option('w3tc_support_request'); } else { delete_option('w3tc_support_request'); } if ($result) { w3_admin_redirect(array('tab' => 'general', 'w3tc_note' => 'support_request'), false); } else { w3_admin_redirect(array_merge($params, array('request_type' => $request_type, 'w3tc_error' => 'support_request')), false); } }
/** * Page Speed results action * * @return void */ function action_test_pagespeed_results() { w3_require_once(W3TC_LIB_W3_DIR . '/Request.php'); w3_require_once(W3TC_LIB_W3_DIR . '/PageSpeed.php'); $force = W3_Request::get_boolean('force'); $title = 'Google Page Speed'; $w3_pagespeed = new W3_PageSpeed(); $results = $w3_pagespeed->analyze(w3_get_home_url(), $force); if ($force) { w3_admin_redirect(array('w3tc_pagespeed_results' => 1, '_wpnonce' => wp_create_nonce('w3tc'))); } include W3TC_INC_POPUP_DIR . '/pagespeed_results.php'; }
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 }
/** * Returns config value * * @param string $key * @param mixed $default * @return mixed */ function get($key, $default = null) { if (array_key_exists($key, $this->_keys) && array_key_exists($key, $this->_config)) { $value = $this->_config[$key]; } else { if ($default === null && array_key_exists($key, $this->_defaults)) { $value = $this->_defaults[$key]; } else { $value = $default; } } switch ($key) { /** * Check cache engines */ case 'pgcache.engine': case 'dbcache.engine': case 'minify.engine': case 'objectcache.engine': /** * Legacy support */ if ($value == 'file_pgcache') { $value = 'file_generic'; } switch (true) { case $value == 'file_generic' && !w3_can_check_rules(): case $value == 'apc' && !function_exists('apc_store'): case $value == 'eaccelerator' && !function_exists('eaccelerator_put'): case $value == 'xcache' && !function_exists('xcache_set'): case $value == 'wincache' && !function_exists('wincache_ucache_set'): case $value == 'memcached' && !class_exists('Memcache'): return 'file'; } break; /** * Check HTML minifier */ /** * Check HTML minifier */ case 'minify.html.engine': if ($value == 'htmltidy' && !class_exists('tidy')) { return 'html'; } break; /** * Disabled some page cache options when enhanced mode enabled */ /** * Disabled some page cache options when enhanced mode enabled */ case 'pgcache.cache.query': if ($this->get_string('pgcache.engine') == 'file_generic') { return false; } break; /** * Set default value to sitemap file */ /** * Set default value to sitemap file */ case 'pgcache.prime.sitemap': if (!$value) { $value = w3_get_home_url() . '/sitemap.xml'; } break; /** * Disabled minify when PHP5 is not installed */ /** * Disabled minify when PHP5 is not installed */ case 'minify.enabled': if (!W3TC_PHP5) { return false; } break; /** * Disable minify rewrite when server rules are not supported */ /** * Disable minify rewrite when server rules are not supported */ case 'minify.rewrite': if (!w3_can_check_rules()) { return false; } break; /** * Disable minify options for auto mode */ /** * Disable minify options for auto mode */ case 'minify.upload': if ($this->get_boolean('minify.auto')) { return false; } break; /** * Minify groups legacy support */ /** * Minify groups legacy support */ case 'minify.js.groups': case 'minify.css.groups': /** * Support <= 0.8.5.2 versions */ if (is_array($value) && count($value)) { $group = current($value); if (is_array($group) && count($group)) { $location = current($group); if (isset($location['files'])) { if (function_exists('get_theme')) { $theme = get_theme(get_current_theme()); $theme_key = w3_get_theme_key($theme['Theme Root'], $theme['Template'], $theme['Stylesheet']); $value = array($theme_key => $value); return $value; } } } } /** * Support <= 0.9.1.3 versions */ $wp_themes = get_themes(); foreach ($value as $theme_key => $templates) { if (strlen($theme_key) == 5) { break; } foreach ($wp_themes as $wp_theme) { $wp_theme_key = w3_get_theme_key_legacy($wp_theme['Theme Root'], $wp_theme['Template'], $wp_theme['Stylesheet']); if ($theme_key == $wp_theme_key) { $new_theme_key = w3_get_theme_key($wp_theme['Theme Root'], $wp_theme['Template'], $wp_theme['Stylesheet']); $value[$new_theme_key] = $templates; unset($theme_key); break; } } } break; /** * Disable CDN minify when PHP5 is not installed or minify is disabled */ /** * Disable CDN minify when PHP5 is not installed or minify is disabled */ case 'cdn.minify.enable': if (!W3TC_PHP5 || !$this->get_boolean('minify.rewrite') || $this->get_boolean('minify.auto') && !w3_is_cdn_mirror($this->get_string('cdn.engine'))) { return false; } break; /** * Check CDN engines */ /** * Check CDN engines */ case 'cdn.engine': /** * Check for PHP5 */ if (in_array($value, array('rscf', 'azure')) && !W3TC_PHP5) { return 'mirror'; } /** * Check for CURL */ if (in_array($value, array('s3', 'cf', 'cf2', 'rscf')) && !function_exists('curl_init')) { return 'mirror'; } /** * Check for FTP */ if ($value == 'ftp' && !function_exists('ftp_connect')) { return 'mirror'; } /** * Check for SHA 256 functions */ if ($value == 'netdna' && !function_exists('hash') && !function_exists('mhash')) { return 'mirror'; } break; /** * Disable no 404 wp feature when server rules are not supported */ /** * Disable no 404 wp feature when server rules are not supported */ case 'browsercache.no404wp': if (!w3_can_check_rules()) { return false; } break; } return $value; }
/** * Perform minify rules rewrite test * * @return bool */ function test_rewrite_minify() { $url = sprintf('%s/%s/w3tc_rewrite_test', w3_get_home_url(), W3TC_CONTENT_MINIFY_DIR_NAME); return $this->test_rewrite($url); }
</tr> <tr> <th>Preview mode:</th> <td> <?php echo $this->nonce_field('w3tc'); ?> <?php if ($this->_config->is_preview()) { ?> <input type="submit" name="w3tc_preview_disable" class="button-primary" value="<?php _e('Disable', 'w3-total-cache'); ?> " /> <?php echo $this->button_link(__('Preview', 'w3-total-cache'), w3_get_home_url() . '/?w3tc_preview=1', true); ?> <?php echo $this->button_link(__('Deploy', 'w3-total-cache'), wp_nonce_url(sprintf('admin.php?page=%s&w3tc_preview_deploy', $this->_page), 'w3tc')); ?> <?php } else { ?> <input type="submit" name="w3tc_preview_enable" class="button-primary" value="<?php _e('Enable', 'w3-total-cache'); ?> " /> <?php } ?> <br /><span class="description"><?php
/** * @param null $domain_url * @param null $home_url */ function __construct($domain_url = null, $home_url = null) { $this->domain_url = $domain_url ? $domain_url : w3_get_domain_url(); $this->home_url = $home_url ? $home_url : w3_get_home_url(); }
/** * Create a NetDNA or MaxCDN pull zone automatically */ function action_cdn_auto_create_netdna_maxcdn_pull_zone() { w3_require_once(W3TC_LIB_NETDNA_DIR . '/NetDNA.php'); w3_require_once(W3TC_INC_FUNCTIONS_DIR . '/admin.php'); $cdn_engine = W3_Request::get_string('type'); $this->validate_cdnengine_is_netdna_maxcdn($cdn_engine); $authorization_key = W3_Request::get_string('authorization_key'); $this->validate_authorization_key($authorization_key); $keys = explode('+', $authorization_key); list($alias, $consumerkey, $consumersecret) = $keys; $url = w3_get_home_url(); try { $api = new NetDNA($alias, $consumerkey, $consumersecret); $disable_cooker_header = $this->_config->get_boolean('browsercache.other.nocookies') || $this->_config->get_boolean('browsercache.cssjs.nocookies'); $zone = $api->create_default_pull_zone($url, null, null, array('ignore_setcookie_header' => $disable_cooker_header)); $name = $zone['name']; $temporary_url = "{$name}.{$alias}.netdna-cdn.com"; $test_result = -1; if (!$this->_config->get_array("cdn.{$cdn_engine}.domain")) { $test_result = $this->test_cdn_url($temporary_url) ? 1 : 0; $this->_config->set("cdn.{$cdn_engine}.zone_id", $zone['id']); if ($test_result) { $this->_config->set("cdn.enabled", true); } $this->_config->set("cdn.{$cdn_engine}.domain", array($temporary_url)); } $this->_config->save(); $config_admin = w3_instance('W3_ConfigAdmin'); $zones = $api->get_pull_zones(); $zone_count = sizeof($zones); w3tc_make_track_call(array('type' => 'cdn', 'data' => array('cdn' => $cdn_engine, 'action' => 'zonecreation', 'creation' => 'manual', 'creationtime' => time(), 'signupclick' => $config_admin->get_integer('track.maxcdn_signup'), 'authorizeclick' => $config_admin->get_integer('track.maxcdn_authorize'), 'validationclick' => $config_admin->get_integer('track.maxcdn_validation'), 'total_zones' => $zone_count, 'test' => $test_result))); $result = array('result' => 'single', 'cnames' => array($temporary_url)); } catch (Exception $ex) { $result = array('result' => 'error', 'message' => sprintf(__('Could not create default zone.' . $ex->getMessage(), 'w3-total-cache'))); } echo json_encode($result); exit; }
</label> </th> </tr> <tr> <th>Preview Mode:</th> <td> <?php echo $this->nonce_field('w3tc'); ?> <?php if ($preview) { ?> <input type="hidden" name="preview" value="0" /> <input type="submit" name="w3tc_preview_save" class="button-primary" value="Disable" /> <?php echo $this->button_link('Preview', w3_get_home_url() . '/?w3tc_preview=1', true); ?> <?php echo $this->button_link('Deploy', sprintf('admin.php?page=%s&w3tc_preview_deploy', $this->_page)); ?> <?php } else { ?> <input type="hidden" name="preview" value="1" /> <input type="submit" name="w3tc_preview_save" class="button-primary" value="Enable" /> <?php } ?> <br /><span class="description">Use preview mode to test configuration scenarios prior to releasing them (deploy) on the actual site.</span> </td> </tr>
/** * Page Speed results popup * * @return void */ function pagespeed_results() { require_once W3TC_LIB_W3_DIR . '/Request.php'; require_once W3TC_LIB_W3_DIR . '/PageSpeed.php'; $force = W3_Request::get_boolean('force'); $title = 'Google Page Speed'; $w3_pagespeed = new W3_PageSpeed(); $results = $w3_pagespeed->analyze(w3_get_home_url(), $force); if ($force) { $this->redirect(array('w3tc_action' => 'pagespeed_results')); } include W3TC_DIR . '/inc/popup/pagespeed_results.phtml'; }
private function verify_file_generic_rewrite_working() { $url = w3_get_home_url() . '/w3tc_rewrite_test'; if (!$this->test_rewrite($url)) { $key = sprintf('w3tc_rewrite_test_result_%s', substr(md5($url), 0, 16)); $result = get_transient($key); $home_url = w3_get_home_url(); $tech_message = (w3_is_nginx() ? 'nginx configuration file' : '.htaccess file') . ' contains rules to rewrite url ' . $home_url . '/w3tc_rewrite_test into ' . $home_url . '/?w3tc_rewrite_test which, if handled by ' . 'plugin, return "OK" message.<br/>'; $tech_message .= 'The plugin made a request to ' . $home_url . '/w3tc_rewrite_test but received: <br />' . $result . '<br />'; $tech_message .= 'instead of "OK" response. <br />'; $error = '<strong>W3 Total Cache error:</strong> ' . 'It appears Page Cache ' . '<acronym title="Uniform Resource Locator">URL</acronym> ' . 'rewriting is not working. '; if (w3_is_nginx()) { $error .= 'Please verify that all configuration files are ' . 'included in the configuration file ' . '(and that you have reloaded / restarted nginx).'; } else { $error .= 'Please verify that the server configuration ' . 'allows .htaccess'; } $error .= '<br />Unfortunately disk enhanced page caching will ' . 'not function without custom rewrite rules. ' . 'Please ask your server administrator for assistance. ' . 'Also refer to <a href="' . admin_url('admin.php?page=w3tc_install') . '">the install page</a> for the rules for your server.'; throw new SelfTestFailedException($error, $tech_message); } }
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 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 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. %s any changed settings (without deploying), or make additional changes.', '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')), w3_button_link(__('Preview', 'w3-total-cache'), w3_get_home_url() . '/?w3tc_preview=1', true)); } /** * */ 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(); }
/** * Returns array of detected URLs for theme templates * * @param string $theme_name * @return array */ function get_theme_urls($theme_name) { $urls = array(); $theme = w3tc_get_theme($theme_name); if ($theme && isset($theme['Template Files'])) { $front_page_template = false; if (get_option('show_on_front') == 'page') { $front_page_id = get_option('page_on_front'); if ($front_page_id) { $front_page_template_file = get_post_meta($front_page_id, '_wp_page_template', true); if ($front_page_template_file) { $front_page_template = basename($front_page_template_file, '.php'); } } } $home_url = w3_get_home_url(); $template_files = (array) $theme['Template Files']; $mime_types = get_allowed_mime_types(); $custom_mime_types = array(); foreach ($mime_types as $mime_type) { list($type1, $type2) = explode('/', $mime_type); $custom_mime_types = array_merge($custom_mime_types, array($type1, $type2, $type1 . '_' . $type2)); } foreach ($template_files as $template_file) { $link = false; $template = basename($template_file, '.php'); /** * Check common templates */ switch (true) { /** * Handle home.php or index.php or front-page.php */ case !$front_page_template && $template == 'home': case !$front_page_template && $template == 'index': case !$front_page_template && $template == 'front-page': /** * Handle custom home page */ /** * Handle custom home page */ case $template == $front_page_template: $link = $home_url . '/'; break; /** * Handle 404.php */ /** * Handle 404.php */ case $template == '404': $permalink = get_option('permalink_structure'); if ($permalink) { $link = sprintf('%s/%s/', $home_url, '404_test'); } else { $link = sprintf('%s/?p=%d', $home_url, 999999999); } break; /** * Handle search.php */ /** * Handle search.php */ case $template == 'search': $link = sprintf('%s/?s=%s', $home_url, 'search_test'); break; /** * Handle date.php or archive.php */ /** * Handle date.php or archive.php */ case $template == 'date': case $template == 'archive': $posts = get_posts(array('numberposts' => 1, 'orderby' => 'rand')); if (is_array($posts) && count($posts)) { $time = strtotime($posts[0]->post_date); $link = get_day_link(date('Y', $time), date('m', $time), date('d', $time)); } break; /** * Handle author.php */ /** * Handle author.php */ case $template == 'author': $author_id = false; if (function_exists('get_users')) { $users = get_users(); if (is_array($users) && count($users)) { $user = current($users); $author_id = $user->ID; } } else { $author_ids = get_author_user_ids(); if (is_array($author_ids) && count($author_ids)) { $author_id = $author_ids[0]; } } if ($author_id) { $link = get_author_posts_url($author_id); } break; /** * Handle category.php */ /** * Handle category.php */ case $template == 'category': $category_ids = get_all_category_ids(); if (is_array($category_ids) && count($category_ids)) { $link = get_category_link($category_ids[0]); } break; /** * Handle tag.php */ /** * Handle tag.php */ case $template == 'tag': $term_ids = get_terms('post_tag', 'fields=ids'); if (is_array($term_ids) && count($term_ids)) { $link = get_term_link($term_ids[0], 'post_tag'); } break; /** * Handle taxonomy.php */ /** * Handle taxonomy.php */ case $template == 'taxonomy': $taxonomy = ''; if (isset($GLOBALS['wp_taxonomies']) && is_array($GLOBALS['wp_taxonomies'])) { foreach ($GLOBALS['wp_taxonomies'] as $wp_taxonomy) { if (!in_array($wp_taxonomy->name, array('category', 'post_tag', 'link_category'))) { $taxonomy = $wp_taxonomy->name; break; } } } if ($taxonomy) { $terms = get_terms($taxonomy, array('number' => 1)); if (is_array($terms) && count($terms)) { $link = get_term_link($terms[0], $taxonomy); } } break; /** * Handle attachment.php */ /** * Handle attachment.php */ case $template == 'attachment': $attachments = get_posts(array('post_type' => 'attachment', 'numberposts' => 1, 'orderby' => 'rand')); if (is_array($attachments) && count($attachments)) { $link = get_attachment_link($attachments[0]->ID); } break; /** * Handle single.php */ /** * Handle single.php */ case $template == 'single': $posts = get_posts(array('numberposts' => 1, 'orderby' => 'rand')); if (is_array($posts) && count($posts)) { $link = get_permalink($posts[0]->ID); } break; /** * Handle page.php */ /** * Handle page.php */ case $template == 'page': $pages_ids = get_all_page_ids(); if (is_array($pages_ids) && count($pages_ids)) { $link = get_page_link($pages_ids[0]); } break; /** * Handle comments-popup.php */ /** * Handle comments-popup.php */ case $template == 'comments-popup': $posts = get_posts(array('numberposts' => 1, 'orderby' => 'rand')); if (is_array($posts) && count($posts)) { $link = sprintf('%s/?comments_popup=%d', $home_url, $posts[0]->ID); } break; /** * Handle paged.php */ /** * Handle paged.php */ case $template == 'paged': global $wp_rewrite; if ($wp_rewrite->using_permalinks()) { $link = sprintf('%s/page/%d/', $home_url, 1); } else { $link = sprintf('%s/?paged=%d', 1); } break; /** * Handle author-id.php or author-nicename.php */ /** * Handle author-id.php or author-nicename.php */ case preg_match('~^author-(.+)$~', $template, $matches): if (is_numeric($matches[1])) { $link = get_author_posts_url($matches[1]); } else { $link = get_author_posts_url(null, $matches[1]); } break; /** * Handle category-id.php or category-slug.php */ /** * Handle category-id.php or category-slug.php */ case preg_match('~^category-(.+)$~', $template, $matches): if (is_numeric($matches[1])) { $link = get_category_link($matches[1]); } else { $term = get_term_by('slug', $matches[1], 'category'); if (is_object($term)) { $link = get_category_link($term->term_id); } } break; /** * Handle tag-id.php or tag-slug.php */ /** * Handle tag-id.php or tag-slug.php */ case preg_match('~^tag-(.+)$~', $template, $matches): if (is_numeric($matches[1])) { $link = get_tag_link($matches[1]); } else { $term = get_term_by('slug', $matches[1], 'post_tag'); if (is_object($term)) { $link = get_tag_link($term->term_id); } } break; /** * Handle taxonomy-taxonomy-term.php */ /** * Handle taxonomy-taxonomy-term.php */ case preg_match('~^taxonomy-(.+)-(.+)$~', $template, $matches): $link = get_term_link($matches[2], $matches[1]); break; /** * Handle taxonomy-taxonomy.php */ /** * Handle taxonomy-taxonomy.php */ case preg_match('~^taxonomy-(.+)$~', $template, $matches): $terms = get_terms($matches[1], array('number' => 1)); if (is_array($terms) && count($terms)) { $link = get_term_link($terms[0], $matches[1]); } break; /** * Handle MIME_type.php */ /** * Handle MIME_type.php */ case in_array($template, $custom_mime_types): $posts = get_posts(array('post_mime_type' => '%' . $template . '%', 'post_type' => 'attachment', 'numberposts' => 1, 'orderby' => 'rand')); if (is_array($posts) && count($posts)) { $link = get_permalink($posts[0]->ID); } break; /** * Handle single-posttype.php */ /** * Handle single-posttype.php */ case preg_match('~^single-(.+)$~', $template, $matches): $posts = get_posts(array('post_type' => $matches[1], 'numberposts' => 1, 'orderby' => 'rand')); if (is_array($posts) && count($posts)) { $link = get_permalink($posts[0]->ID); } break; /** * Handle page-id.php or page-slug.php */ /** * Handle page-id.php or page-slug.php */ case preg_match('~^page-(.+)$~', $template, $matches): if (is_numeric($matches[1])) { $link = get_permalink($matches[1]); } else { $posts = get_posts(array('pagename' => $matches[1], 'post_type' => 'page', 'numberposts' => 1)); if (is_array($posts) && count($posts)) { $link = get_permalink($posts[0]->ID); } } break; /** * Try to handle custom template */ /** * Try to handle custom template */ default: $posts = get_posts(array('pagename' => $template, 'post_type' => 'page', 'numberposts' => 1)); if (is_array($posts) && count($posts)) { $link = get_permalink($posts[0]->ID); } break; } if ($link && !is_wp_error($link)) { $urls[$template] = $link; } } } return $urls; }
/** * Start previewing */ function action_default_previewing() { setcookie('w3tc_preview', true, 0, '/'); w3_redirect(w3_get_home_url()); }
/** * 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); } }
/** * Perform pgcache rules rewrite test * * @return bool */ function test_rewrite_pgcache() { $url = w3_get_home_url() . '/w3tc_rewrite_test'; return $this->test_rewrite($url); }