/**
  * Check cache rules
  *
  * @return boolean
  */
 function check_rules_cache()
 {
     $path = w3_get_browsercache_rules_cache_path();
     $search = $this->generate_rules_cache();
     return ($data = @file_get_contents($path)) && strstr(w3_clean_rules($data), w3_clean_rules($search)) !== false;
 }
Exemplo n.º 2
0
 /**
  * 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);
     }
 }
Exemplo n.º 3
0
 /**
  * Plugin action links filter
  *
  * @param array $links
  * @return array
  */
 function plugin_action_links($links)
 {
     array_unshift($links, '<a class="edit" href="admin.php?page=w3tc_general">Settings</a>');
     w3_require_once(W3TC_INC_DIR . '/functions/rule.php');
     if (!is_writable(WP_CONTENT_DIR) || !is_writable(w3_get_browsercache_rules_cache_path())) {
         $delete_link = '<a href="' . wp_nonce_url(admin_url('plugins.php?action=w3tc_deactivate_plugin'), 'w3tc') . '">Uninstall</a>';
         array_unshift($links, $delete_link);
     }
     return $links;
 }
 /**
  * @return array
  */
 function remove_rules_no404wp_with_message($verify_config = false, $hide_button = '')
 {
     $ftp_form = null;
     $errors = array();
     $errors_short_form = array();
     $remove = $verify_config ? !$this->_config->get_boolean('browsercache.no404wp') : true;
     if ($remove && $this->check_rules_no404wp()) {
         try {
             $this->remove_rules_no404wp();
         } catch (Exception $e) {
             $errors[] = sprintf('"Do not process 404 errors for static objects with WordPress" feature is still <em>active</em>. To disable it, edit the rules in the server configuration file (<strong>%s</strong>) of the site and remove all lines between and including <strong>%s</strong> and <strong>%s</strong> markers inclusive.%s', w3_get_browsercache_rules_cache_path(), W3TC_MARKER_BEGIN_BROWSERCACHE_NO404WP, W3TC_MARKER_END_BROWSERCACHE_NO404WP, $hide_button);
             $errors_short_form[] = sprintf('Edit file (<strong>%s</strong>) and remove all lines between and including <strong>%s</strong> and <strong>%s</strong> markers inclusive.', w3_get_browsercache_rules_cache_path(), W3TC_MARKER_BEGIN_BROWSERCACHE_NO404WP, W3TC_MARKER_END_BROWSERCACHE_NO404WP);
             if (!isset($ftp_form) && $e instanceof FilesystemCredentialException) {
                 $ftp_form = $e->ftp_form();
             }
         }
     }
     return array('errors' => $errors, 'ftp_form' => $ftp_form, 'errors_short_form' => $errors_short_form);
 }
 /**
  * Removes Page Cache core directives
  *
  * @throws FilesystemOperationException with S/FTP form if it can't get the required filesystem credentials
  * @throws FileOperationException
  */
 private function rules_wpmu_subfolder_remove($exs)
 {
     w3_remove_rules($exs, w3_get_browsercache_rules_cache_path(), W3TC_MARKER_BEGIN_MINIFY_CACHE, W3TC_MARKER_END_MINIFY_CACHE);
 }
Exemplo n.º 6
0
 /**
  * @return array
  */
 function remove_rules_with_message()
 {
     $ftp_form = null;
     $errors = array();
     $errors_short_form = array();
     if ($this->check_rules()) {
         try {
             $this->remove_rules();
         } catch (Exception $e) {
             $errors[] = sprintf('CDN/CloudFlare added rules that need to be removed. 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.', w3_get_browsercache_rules_cache_path(), W3TC_MARKER_BEGIN_CDN, W3TC_MARKER_BEGIN_CDN);
             $errors_short_form[] = sprintf('Edit file (<strong>%s</strong>) and remove all lines between and including <strong>%s</strong> and <strong>%s</strong> markers inclusive.', w3_get_browsercache_rules_cache_path(), W3TC_MARKER_BEGIN_CDN, W3TC_MARKER_BEGIN_CDN);
             if ($e instanceof FilesystemCredentialException) {
                 $ftp_form = $e->ftp_form();
             }
         }
     }
     return array('errors' => $errors, 'ftp_form' => $ftp_form, 'errors_short_form' => $errors_short_form);
 }
 /**
  * Removes cache directives
  *
  * @throws FilesystemOperationException with S/FTP form if it can't get the required filesystem credentials
  * @throws FileOperationException
  */
 private function rules_cache_remove($exs)
 {
     w3_remove_rules($exs, w3_get_browsercache_rules_cache_path(), W3TC_MARKER_BEGIN_BROWSERCACHE_CACHE, W3TC_MARKER_END_BROWSERCACHE_CACHE);
 }
Exemplo n.º 8
0
                </li>
            <?php 
    }
    ?>

        <?php 
}
?>

    </ul>

    <h4>WordPress Resources</h4>

    <ul>
        <?php 
$paths = array_unique(array(w3_get_pgcache_rules_core_path(), w3_get_browsercache_rules_cache_path(), w3_get_browsercache_rules_no404wp_path()));
?>

        <?php 
foreach ($paths as $path) {
    if ($path) {
        ?>

        <li>
            <?php 
        echo htmlspecialchars($path);
        ?>
:
            <?php 
        if (file_exists($path)) {
            ?>
Exemplo n.º 9
0
 /**
  * Send support request
  *
  * @return void
  */
 function support_request()
 {
     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');
     $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);
     foreach ($templates as $template_index => $template) {
         $template_key = sprintf('templates[%d]', $template_index);
         $params[$template_key] = $template;
     }
     if (!isset($this->_request_types[$request_type])) {
         $this->redirect(array_merge($params, array('w3tc_error' => 'support_request_type')));
     }
     $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 == '') {
         $this->redirect(array_merge($params, array('w3tc_error' => 'support_request_url')));
     }
     if (strstr($required[$request_type], 'name') !== false && $name == '') {
         $this->redirect(array_merge($params, array('w3tc_error' => 'support_request_name')));
     }
     if (strstr($required[$request_type], 'email') !== false && !preg_match('~^[a-z0-9_\\-\\.]+@[a-z0-9-\\.]+\\.[a-z]{2,5}$~', $email)) {
         $this->redirect(array_merge($params, array('w3tc_error' => 'support_request_email')));
     }
     if (strstr($required[$request_type], 'phone') !== false && !preg_match('~^[0-9\\-\\.\\ \\(\\)\\+]+$~', $phone)) {
         $this->redirect(array_merge($params, array('w3tc_error' => 'support_request_phone')));
     }
     if (strstr($required[$request_type], 'subject') !== false && $subject == '') {
         $this->redirect(array_merge($params, array('w3tc_error' => 'support_request_subject')));
     }
     if (strstr($required[$request_type], 'description') !== false && $description == '') {
         $this->redirect(array_merge($params, array('w3tc_error' => 'support_request_description')));
     }
     if (strstr($required[$request_type], 'wp_login') !== false && $wp_login == '') {
         $this->redirect(array_merge($params, array('w3tc_error' => 'support_request_wp_login')));
     }
     if (strstr($required[$request_type], 'wp_password') !== false && $wp_password == '') {
         $this->redirect(array_merge($params, array('w3tc_error' => 'support_request_wp_password')));
     }
     if (strstr($required[$request_type], 'ftp_host') !== false && $ftp_host == '') {
         $this->redirect(array_merge($params, array('w3tc_error' => 'support_request_ftp_host')));
     }
     if (strstr($required[$request_type], 'ftp_login') !== false && $ftp_login == '') {
         $this->redirect(array_merge($params, array('w3tc_error' => 'support_request_ftp_login')));
     }
     if (strstr($required[$request_type], 'ftp_password') !== false && $ftp_password == '') {
         $this->redirect(array_merge($params, array('w3tc_error' => 'support_request_ftp_password')));
     }
     /**
      * Add attachments
      */
     $attachments = array();
     $attach_files = array(w3_get_wp_config_path(), W3TC_CONFIG_PATH, W3TC_CONFIG_PREVIEW_PATH, W3TC_CONFIG_MASTER_PATH, W3TC_MINIFY_LOG_FILE, 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());
     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_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_TMP_DIR . '/php_info.html';
     if (@file_put_contents($php_info_path, $php_info)) {
         $attachments[] = $php_info_path;
     }
     /**
      * Attach self-test
      */
     ob_start();
     $this->self_test();
     $self_test = ob_get_contents();
     ob_end_clean();
     $self_test_path = W3TC_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_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 = null;
     }
     /**
      * Get body contents
      */
     ob_start();
     include W3TC_DIR . '/inc/email/support_request.phtml';
     $body = ob_get_contents();
     ob_end_clean();
     /**
      * Send email
      */
     $subject = sprintf('[W3TC %s] #%s: %s', $this->_request_types[$request_type], $request_id, $subject);
     $headers = array(sprintf('From: "%s" <%s>', addslashes($name), $email), sprintf('Reply-To: "%s" <%s>', addslashes($name), $email), 'Content-Type: text/html; charset=UTF-8');
     $this->_phpmailer_sender = $email;
     add_action('phpmailer_init', array(&$this, 'phpmailer_init'));
     @set_time_limit($this->_config->get_integer('timelimit.email_send'));
     $result = @wp_mail(W3TC_EMAIL, $subject, $body, implode("\n", $headers), $attachments);
     /**
      * Remove temporary files
      */
     foreach ($attachments as $attachment) {
         if (strstr($attachment, W3TC_TMP_DIR) !== false) {
             @unlink($attachment);
         }
     }
     if ($result) {
         $this->redirect(array('tab' => 'general', 'w3tc_note' => 'support_request'));
     } else {
         $this->redirect(array_merge($params, array('request_type' => $request_type, 'w3tc_error' => 'support_request')));
     }
 }
 /**
  * Removes Page Cache core directives
  *
  * @param SelfTestExceptions $exs
  * @throws FilesystemOperationException with S/FTP form if it can't get the required filesystem credentials
  * @throws FileOperationException
  */
 private function rules_remove($exs)
 {
     w3_remove_rules($exs, w3_get_browsercache_rules_cache_path(), W3TC_MARKER_BEGIN_CDN, W3TC_MARKER_END_CDN);
 }
Exemplo n.º 11
0
 /**
  * Save config action
  *
  * Do some actions on config keys update
  * Used in several places such as:
  *
  * 1. common config save
  * 2. import settings
  * 3. enable/disable preview mode
  *
  * @param W3_Config $old_config
  * @param W3_Config $new_config
  * @param boolean $preview
  * @return void
  */
 function config_save(&$old_config, &$new_config, $preview = null)
 {
     $browsercache_dependencies = array();
     if ($new_config->get_boolean('browsercache.enabled')) {
         $browsercache_dependencies = array_merge($browsercache_dependencies, array('browsercache.cssjs.replace', 'browsercache.html.replace', 'browsercache.other.replace'));
         if ($new_config->get_boolean('browsercache.cssjs.replace')) {
             $browsercache_dependencies = array_merge($browsercache_dependencies, array('browsercache.cssjs.compression', 'browsercache.cssjs.expires', 'browsercache.cssjs.lifetime', 'browsercache.cssjs.cache.control', 'browsercache.cssjs.cache.policy', 'browsercache.cssjs.etag', 'browsercache.cssjs.w3tc'));
         }
         if ($new_config->get_boolean('browsercache.html.replace')) {
             $browsercache_dependencies = array_merge($browsercache_dependencies, array('browsercache.html.compression', 'browsercache.html.expires', 'browsercache.html.lifetime', 'browsercache.html.cache.control', 'browsercache.html.cache.policy', 'browsercache.html.etag', 'browsercache.html.w3tc'));
         }
         if ($new_config->get_boolean('browsercache.other.replace')) {
             $browsercache_dependencies = array_merge($browsercache_dependencies, array('browsercache.other.compression', 'browsercache.other.expires', 'browsercache.other.lifetime', 'browsercache.other.cache.control', 'browsercache.other.cache.policy', 'browsercache.other.etag', 'browsercache.other.w3tc'));
         }
     }
     /**
      * Show need empty page cache notification
      */
     if ($new_config->get_boolean('pgcache.enabled')) {
         $pgcache_dependencies = array_merge($browsercache_dependencies, array('pgcache.debug', 'dbcache.enabled', 'objectcache.enabled', 'minify.enabled', 'cdn.enabled', 'mobile.enabled', 'referrer.enabled'));
         if ($new_config->get_boolean('dbcache.enabled')) {
             $pgcache_dependencies = array_merge($pgcache_dependencies, array('dbcache.debug'));
         }
         if ($new_config->get_boolean('objectcache.enabled')) {
             $pgcache_dependencies = array_merge($pgcache_dependencies, array('objectcache.debug'));
         }
         if ($new_config->get_boolean('minify.enabled')) {
             $pgcache_dependencies = array_merge($pgcache_dependencies, array('minify.auto', 'minify.debug', 'minify.rewrite', 'minify.html.enable', 'minify.html.engine', 'minify.html.inline.css', 'minify.html.inline.js', 'minify.html.strip.crlf', 'minify.html.comments.ignore', 'minify.css.enable', 'minify.css.engine', 'minify.css.groups', 'minify.js.enable', 'minify.js.engine', 'minify.js.groups', 'minify.htmltidy.options.clean', 'minify.htmltidy.options.hide-comments', 'minify.htmltidy.options.wrap', 'minify.reject.logged', 'minify.reject.ua', 'minify.reject.uri'));
         }
         if ($new_config->get_boolean('cdn.enabled')) {
             $pgcache_dependencies = array_merge($pgcache_dependencies, array('cdn.debug', 'cdn.engine', 'cdn.uploads.enable', 'cdn.includes.enable', 'cdn.includes.files', 'cdn.theme.enable', 'cdn.theme.files', 'cdn.minify.enable', 'cdn.custom.enable', 'cdn.custom.files', 'cdn.ftp.domain', 'cdn.ftp.ssl', 'cdn.s3.cname', 'cdn.s3.ssl', 'cdn.cf.cname', 'cdn.cf.ssl', 'cdn.cf2.cname', 'cdn.cf2.ssl', 'cdn.rscf.cname', 'cdn.rscf.ssl', 'cdn.azure.cname', 'cdn.azure.ssl', 'cdn.mirror.domain', 'cdn.mirror.ssl', 'cdn.netdna.domain', 'cdn.netdna.ssl', 'cdn.cotendo.domain', 'cdn.cotendo.ssl', 'cdn.edgecast.domain', 'cdn.edgecast.ssl', 'cdn.reject.admins', 'cdn.reject.ua', 'cdn.reject.uri', 'cdn.reject.files'));
         }
         if ($new_config->get_boolean('mobile.enabled')) {
             $pgcache_dependencies = array_merge($pgcache_dependencies, array('mobile.rgroups'));
         }
         if ($new_config->get_boolean('referrer.enabled')) {
             $pgcache_dependencies = array_merge($pgcache_dependencies, array('referrer.rgroups'));
         }
         $old_pgcache_dependencies_values = array();
         $new_pgcache_dependencies_values = array();
         foreach ($pgcache_dependencies as $pgcache_dependency) {
             $old_pgcache_dependencies_values[] = $old_config->get($pgcache_dependency);
             $new_pgcache_dependencies_values[] = $new_config->get($pgcache_dependency);
         }
         if (serialize($old_pgcache_dependencies_values) != serialize($new_pgcache_dependencies_values)) {
             $new_config->set('notes.need_empty_pgcache', true);
         }
     }
     /**
      * Show need empty minify notification
      */
     if ($new_config->get_boolean('minify.enabled') && ($new_config->get_boolean('minify.css.enable') && ($new_config->get_boolean('minify.auto') || count($new_config->get_array('minify.css.groups'))) || $new_config->get_boolean('minify.js.enable') && ($new_config->get_boolean('minify.auto') || count($new_config->get_array('minify.js.groups'))))) {
         $minify_dependencies = array_merge($browsercache_dependencies, array('minify.auto', 'minify.debug', 'minify.options', 'minify.symlinks', 'minify.css.enable', 'minify.js.enable', 'cdn.enabled'));
         if ($new_config->get_boolean('minify.css.enable') && ($new_config->get_boolean('minify.auto') || count($new_config->get_array('minify.css.groups')))) {
             $minify_dependencies = array_merge($minify_dependencies, array('minify.css.engine', 'minify.css.combine', 'minify.css.strip.comments', 'minify.css.strip.crlf', 'minify.css.imports', 'minify.css.groups', 'minify.yuicss.path.java', 'minify.yuicss.path.jar', 'minify.yuicss.options.line-break', 'minify.csstidy.options.remove_bslash', 'minify.csstidy.options.compress_colors', 'minify.csstidy.options.compress_font-weight', 'minify.csstidy.options.lowercase_s', 'minify.csstidy.options.optimise_shorthands', 'minify.csstidy.options.remove_last_;', 'minify.csstidy.options.case_properties', 'minify.csstidy.options.sort_properties', 'minify.csstidy.options.sort_selectors', 'minify.csstidy.options.merge_selectors', 'minify.csstidy.options.discard_invalid_properties', 'minify.csstidy.options.css_level', 'minify.csstidy.options.preserve_css', 'minify.csstidy.options.timestamp', 'minify.csstidy.options.template'));
         }
         if ($new_config->get_boolean('minify.js.enable') && ($new_config->get_boolean('minify.auto') || count($new_config->get_array('minify.js.groups')))) {
             $minify_dependencies = array_merge($minify_dependencies, array('minify.js.engine', 'minify.js.combine.header', 'minify.js.combine.body', 'minify.js.combine.footer', 'minify.js.strip.comments', 'minify.js.strip.crlf', 'minify.js.groups', 'minify.yuijs.path.java', 'minify.yuijs.path.jar', 'minify.yuijs.options.line-break', 'minify.yuijs.options.nomunge', 'minify.yuijs.options.preserve-semi', 'minify.yuijs.options.disable-optimizations', 'minify.ccjs.path.java', 'minify.ccjs.path.jar', 'minify.ccjs.options.compilation_level', 'minify.ccjs.options.formatting'));
         }
         if ($new_config->get_boolean('cdn.enabled')) {
             $minify_dependencies = array_merge($minify_dependencies, array('cdn.engine'));
         }
         $old_minify_dependencies_values = array();
         $new_minify_dependencies_values = array();
         foreach ($minify_dependencies as $minify_dependency) {
             $old_minify_dependencies_values[] = $old_config->get($minify_dependency);
             $new_minify_dependencies_values[] = $new_config->get($minify_dependency);
         }
         if (serialize($old_minify_dependencies_values) != serialize($new_minify_dependencies_values)) {
             $new_config->set('notes.need_empty_minify', true);
         }
     }
     if ($new_config->get_boolean('cdn.enabled') && !w3_is_cdn_mirror($new_config->get_string('cdn.engine'))) {
         /**
          * Show notification when CDN enabled
          */
         if (!$old_config->get_boolean('cdn.enabled')) {
             $new_config->set('notes.cdn_upload', true);
         }
         /**
          * Show notification when Browser Cache settings changes
          */
         $cdn_dependencies = array('browsercache.enabled');
         if ($new_config->get_boolean('cdn.enabled')) {
             $cdn_dependencies = array('browsercache.cssjs.compression', 'browsercache.cssjs.expires', 'browsercache.cssjs.lifetime', 'browsercache.cssjs.cache.control', 'browsercache.cssjs.cache.policy', 'browsercache.cssjs.etag', 'browsercache.cssjs.w3tc', 'browsercache.html.compression', 'browsercache.html.expires', 'browsercache.html.lifetime', 'browsercache.html.cache.control', 'browsercache.html.cache.policy', 'browsercache.html.etag', 'browsercache.html.w3tc', 'browsercache.other.compression', 'browsercache.other.expires', 'browsercache.other.lifetime', 'browsercache.other.cache.control', 'browsercache.other.cache.policy', 'browsercache.other.etag', 'browsercache.other.w3tc');
         }
         $old_cdn_dependencies_values = array();
         $new_cdn_dependencies_values = array();
         foreach ($cdn_dependencies as $cdn_dependency) {
             $old_cdn_dependencies_values[] = $old_config->get($cdn_dependency);
             $new_cdn_dependencies_values[] = $new_config->get($cdn_dependency);
         }
         if (serialize($old_cdn_dependencies_values) != serialize($new_cdn_dependencies_values)) {
             $new_config->set('notes.cdn_reupload', true);
         }
     }
     /**
      * Show need empty object cache notification
      */
     if ($this->_config->get_boolean('objectcache.enabled')) {
         $objectcache_dependencies = array('objectcache.groups.global', 'objectcache.groups.nonpersistent');
         $old_objectcache_dependencies_values = array();
         $new_objectcache_dependencies_values = array();
         foreach ($objectcache_dependencies as $objectcache_dependency) {
             $old_objectcache_dependencies_values[] = $old_config->get($objectcache_dependency);
             $new_objectcache_dependencies_values[] = $new_config->get($objectcache_dependency);
         }
         if (serialize($old_objectcache_dependencies_values) != serialize($new_objectcache_dependencies_values)) {
             $new_config->set('notes.need_empty_objectcache', true);
         }
     }
     /**
      * Save config
      */
     if ($new_config->save($preview)) {
         $w3_plugin_pgcache =& w3_instance('W3_Plugin_PgCacheAdmin');
         $w3_plugin_dbcache =& w3_instance('W3_Plugin_DbCache');
         $w3_plugin_objectcache =& w3_instance('W3_Plugin_ObjectCache');
         $w3_plugin_browsercache =& w3_instance('W3_Plugin_BrowserCacheAdmin');
         $w3_plugin_cdn =& w3_instance('W3_Plugin_CdnAdmin');
         if (W3TC_PHP5) {
             $w3_plugin_minify =& w3_instance('W3_Plugin_MinifyAdmin');
         }
         /**
          * Empty caches on engine change or cache enable/disable
          */
         if ($old_config->get_string('pgcache.engine') != $new_config->get_string('pgcache.engine') || $old_config->get_string('pgcache.enabled') != $new_config->get_string('pgcache.enabled')) {
             $this->flush_pgcache();
         }
         if ($old_config->get_string('dbcache.engine') != $new_config->get_string('dbcache.engine') || $old_config->get_string('dbcache.enabled') != $new_config->get_string('dbcache.enabled')) {
             $this->flush_dbcache();
         }
         if ($old_config->get_string('objectcache.engine') != $new_config->get_string('objectcache.engine') || $old_config->get_string('objectcache.enabled') != $new_config->get_string('objectcache.enabled')) {
             $this->flush_objectcache();
         }
         if ($old_config->get_string('minify.engine') != $new_config->get_string('minify.engine') || $old_config->get_string('minify.enabled') != $new_config->get_string('minify.enabled')) {
             $this->flush_minify();
         }
         /**
          * Unschedule events if changed file gc interval
          */
         $w3_plugin_pgcache->before_config_change($old_config, $new_config);
         if ($old_config->get_integer('dbcache.file.gc') != $new_config->get_integer('dbcache.file.gc')) {
             $w3_plugin_dbcache->unschedule();
         }
         if ($old_config->get_integer('objectcache.file.gc') != $new_config->get_integer('objectcache.file.gc')) {
             $w3_plugin_objectcache->unschedule();
         }
         if ($old_config->get_integer('cdn.autoupload.interval') != $new_config->get_integer('cdn.autoupload.interval')) {
             $w3_plugin_cdn->unschedule_upload();
         }
         if (W3TC_PHP5) {
             $w3_plugin_minify->before_config_change($old_config, $new_config);
         }
         /**
          * Create CDN queue table
          */
         if (($old_config->get_boolean('cdn.enabled') != $new_config->get_boolean('cdn.enabled') || $old_config->get_string('cdn.engine') != $new_config->get_string('cdn.engine')) && $new_config->get_boolean('cdn.enabled') && !w3_is_cdn_mirror($new_config->get_string('cdn.engine'))) {
             $w3_plugin_cdn->table_create();
         }
         /**
          * Update CloudFront CNAMEs
          */
         $update_cf_cnames = false;
         if ($new_config->get_boolean('cdn.enabled') && in_array($new_config->get_string('cdn.engine'), array('cf', 'cf2'))) {
             if ($new_config->get_string('cdn.engine') == 'cf') {
                 $old_cnames = $old_config->get_array('cdn.cf.cname');
                 $new_cnames = $new_config->get_array('cdn.cf.cname');
             } else {
                 $old_cnames = $old_config->get_array('cdn.cf2.cname');
                 $new_cnames = $new_config->get_array('cdn.cf2.cname');
             }
             if (count($old_cnames) != count($new_cnames) || count(array_diff($old_cnames, $new_cnames))) {
                 $update_cf_cnames = true;
             }
         }
         /**
          * Refresh config
          */
         $old_config->load();
         /**
          * Schedule events
          */
         $w3_plugin_pgcache->after_config_change();
         $w3_plugin_dbcache->schedule();
         $w3_plugin_objectcache->schedule();
         $w3_plugin_cdn->after_config_change();
         /**
          * Update support us option
          */
         $this->link_update();
         /**
          * Write browsercache rules
          */
         if ($new_config->get_boolean('browsercache.enabled')) {
             if (w3_can_modify_rules(w3_get_browsercache_rules_cache_path())) {
                 $w3_plugin_browsercache->write_rules_cache();
             }
             if ($new_config->get_boolean('browsercache.no404nxt')) {
                 if (w3_can_modify_rules(w3_get_browsercache_rules_no404nxt_path())) {
                     $w3_plugin_browsercache->write_rules_no404nxt();
                 }
             } else {
                 if (w3_can_modify_rules(w3_get_browsercache_rules_no404nxt_path())) {
                     $w3_plugin_browsercache->remove_rules_no404nxt();
                 }
             }
         } else {
             if (w3_can_modify_rules(w3_get_browsercache_rules_cache_path())) {
                 $w3_plugin_browsercache->remove_rules_cache();
             }
             if (w3_can_modify_rules(w3_get_browsercache_rules_no404nxt_path())) {
                 $w3_plugin_browsercache->remove_rules_no404nxt();
             }
         }
         /**
          * Write minify rewrite rules
          */
         if (W3TC_PHP5) {
             $w3_plugin_minify->after_config_change();
         }
         /**
          * Auto upload minify files to CDN
          */
         if ($new_config->get_boolean('minify.enabled') && $new_config->get_boolean('minify.upload') && $new_config->get_boolean('cdn.enabled') && !w3_is_cdn_mirror($new_config->get_string('cdn.engine'))) {
             $this->cdn_upload_minify();
         }
         /**
          * Auto upload browsercache files to CDN
          */
         if ($new_config->get_boolean('cdn.enabled') && $new_config->get_string('cdn.engine') == 'ftp') {
             $this->cdn_delete_browsercache();
             if ($new_config->get_boolean('browsercache.enabled')) {
                 $this->cdn_upload_browsercache();
             }
         }
         /**
          * Update CloudFront CNAMEs
          */
         if ($update_cf_cnames) {
             $error = null;
             $w3_plugin_cdn->update_cnames($error);
         }
         /**
          * Save blognames into file
          */
         if (w3_is_network() && !w3_is_subdomain_install()) {
             w3_save_blognames();
         }
         return true;
     }
     return false;
 }
 /**
  * Write rules
  *
  * @return void
  */
 function action_rules_autoinstall()
 {
     $commands = explode(',', W3_Request::get_string('autoinstall'));
     $errors = array();
     $notes = array();
     foreach ($commands as $command) {
         try {
             switch ($command) {
                 case 'browsercache_write_rules_cache':
                     $w3_plugin_browsercache = w3_instance('W3_Plugin_BrowserCacheAdmin');
                     $w3_plugin_browsercache->write_rules_cache();
                     if ($w3_plugin_browsercache->check_rules_cache()) {
                         $notes[] = 'Browser cache directives have been successfully written.';
                     } else {
                         $browsercache_rules_cache_path = w3_get_browsercache_rules_cache_path();
                         $errors[] = sprintf('The browser cache rules could not be modified. Please %srun <strong>chmod 777 %s</strong> to resolve this issue.', file_exists($browsercache_rules_cache_path) ? '' : sprintf('create an empty file in <strong>%s</strong> and ', $browsercache_rules_cache_path), $browsercache_rules_cache_path);
                     }
                     break;
                 case 'minify_remove_rules_legacy':
                     $w3_plugin_minify = w3_instance('W3_Plugin_MinifyAdmin');
                     if ($w3_plugin_minify->remove_rules_legacy()) {
                         $notes[] = 'Legacy minify configuration settings have been successfuly removed.';
                     } else {
                         $minify_rules_cache_path = w3_get_minify_rules_cache_path();
                         $errors[] = sprintf('The legacy minify rules could not be modified. Please run <strong>chmod 777 %s</strong> to resolve this issue.', file_exists($minify_rules_cache_path) ? $minify_rules_cache_path : dirname($minify_rules_cache_path));
                     }
                     break;
                 case 'minify_write_rules':
                     $w3_plugin_minify = w3_instance('W3_Plugin_MinifyAdmin');
                     $w3_plugin_minify->write_rules_cache();
                     // throw exceptions
                     if ($w3_plugin_minify->write_rules_core()) {
                         $notes[] = 'Minify rewrite rules have been successfully written.';
                     } else {
                         $minify_rules_core_path = w3_get_minify_rules_core_path();
                         $errors[] = sprintf('The minify rules could not be modified. Please run <strong>chmod 777 %s</strong> to resolve this issue.', file_exists($minify_rules_core_path) ? $minify_rules_core_path : dirname($minify_rules_core_path));
                     }
                     break;
                 case 'minify_write_test_rules':
                     $w3_plugin_minify = w3_instance('W3_Plugin_MinifyAdmin');
                     $w3_plugin_minify->write_multiste_subfolder_rewrite_test_rules_apache();
                     if ($w3_plugin_minify->check_multisite_subfolder_test_rules_cache_apache()) {
                         $notes[] = 'Minify test rewrite rules have been successfully written.';
                     } else {
                         $minify_test_rules_path = w3_get_document_root() . '/.htaccess';
                         $errors[] = sprintf('The minify test rules could not be modified. Please run <strong>chmod 777 %s</strong> to resolve this issue.', $minify_test_rules_path);
                     }
                     break;
                 case 'pgcache_remove_rules_legacy':
                     $w3_plugin_pgcache = w3_instance('W3_Plugin_PgCacheAdmin');
                     if ($w3_plugin_pgcache->remove_rules_legacy()) {
                         $notes[] = 'Legacy page cache configuration settings have been successfully removed.';
                     } else {
                         $pgcache_rules_cache_path = w3_get_pgcache_rules_cache_path();
                         $errors[] = sprintf('The legacy page cache rules could not be removed. Please run <strong>chmod 777 %s</strong> to resolve this issue.', file_exists($pgcache_rules_cache_path) ? $pgcache_rules_cache_path : dirname($pgcache_rules_cache_path));
                     }
                     break;
                 case 'pgcache_write_rules_cache':
                     $w3_plugin_pgcache = w3_instance('W3_Plugin_PgCacheAdmin');
                     $w3_plugin_pgcache->write_rules_cache();
                     // throw exceptions
                     $notes[] = 'Page cache rewrite rules have been successfully written.';
                     break;
                 case 'pgcache_write_rules_core':
                     $w3_plugin_pgcache = w3_instance('W3_Plugin_PgCacheAdmin');
                     $w3_plugin_pgcache->write_rules_core();
                     if ($w3_plugin_pgcache->check_rules_core()) {
                         $notes[] = 'Page cache rewrite rules have been successfully written.';
                     } else {
                         $pgcache_rules_core_path = w3_get_pgcache_rules_core_path();
                         $errors[] = sprintf('The page cache rules could not be modified. Please %srun <strong>chmod 777 %s</strong> to resolve this issue.', file_exists($pgcache_rules_core_path) ? '' : sprintf('create an empty file in <strong>%s</strong> and ', $pgcache_rules_core_path), $pgcache_rules_core_path);
                     }
                     break;
             }
         } catch (Exception $e) {
             $error = $e->getMessage();
             // avoid duplicate errors, like absense of permission for wp-content folder
             if (!in_array($error, $errors)) {
                 $errors[] = $error;
             }
         }
     }
     $this->redirect_with_custom_messages(array(), $errors, $notes);
 }