/** * Checks if addins in wp-content is available and correct version. * @throws SelfTestExceptions */ private function create_required_files($config, $exs) { $src = W3TC_INSTALL_FILE_ADVANCED_CACHE; $dst = W3TC_ADDIN_FILE_ADVANCED_CACHE; if (file_exists($dst)) { $script_data = @file_get_contents($dst); if ($script_data == @file_get_contents($src)) { return; } } try { w3_wp_copy_file($src, $dst); } catch (FilesystemOperationException $ex) { $exs->push($ex); } }
/** * */ function action_default_remove_add_in() { w3_require_once(W3TC_INC_FUNCTIONS_DIR . '/activation.php'); $module = W3_Request::get_string('w3tc_default_remove_add_in'); switch ($module) { case 'pgcache': w3_wp_delete_file(W3TC_ADDIN_FILE_ADVANCED_CACHE); $src = W3TC_INSTALL_FILE_ADVANCED_CACHE; $dst = W3TC_ADDIN_FILE_ADVANCED_CACHE; try { w3_wp_copy_file($src, $dst); } catch (FilesystemOperationException $ex) { } break; case 'dbcache': w3_wp_delete_file(W3TC_ADDIN_FILE_DB); break; case 'objectcache': w3_wp_delete_file(W3TC_ADDIN_FILE_OBJECT_CACHE); break; } w3_admin_redirect(array('w3tc_note' => 'add_in_removed'), true); }
/** * Creates add-in * @throws FilesystemOperationException */ private function create_addin() { $src = W3TC_INSTALL_FILE_DB; $dst = W3TC_ADDIN_FILE_DB; if ($this->db_installed()) { if ($this->is_dbcache_add_in()) { $script_data = @file_get_contents($dst); if ($script_data == @file_get_contents($src)) { return; } } elseif (!$this->db_check_old_add_in()) { w3_require_once(W3TC_INC_FUNCTIONS_DIR . '/other.php'); w3_require_once(W3TC_INC_FUNCTIONS_DIR . '/ui.php'); if (isset($_GET['page'])) { $url = 'admin.php?page=' . $_GET['page'] . '&'; } else { $url = basename(w3_remove_query($_SERVER['REQUEST_URI'])) . '?page=w3tc_dashboard&'; } $remove_url = w3_admin_url($url . 'w3tc_default_remove_add_in=dbcache'); throw new FilesystemOperationException(sprintf(__('The Database add-in file db.php is not a W3 Total Cache drop-in. Remove it or disable Database Caching. %s', 'w3-total-cache'), w3tc_button_link(__('Remove it for me', 'w3-total-cache'), wp_nonce_url($remove_url, 'w3tc')))); } } w3_wp_copy_file($src, $dst); }
/** * Creates add-in * @throws FilesystemOperationException */ private function create_addin() { $src = W3TC_INSTALL_FILE_OBJECT_CACHE; $dst = W3TC_ADDIN_FILE_OBJECT_CACHE; if (file_exists($dst)) { $script_data = @file_get_contents($dst); if ($script_data == @file_get_contents($src)) { return; } } w3_wp_copy_file($src, $dst); }
/** * Checks if addins in wp-content is available and correct version. * @throws SelfTestExceptions */ private function create_required_files($config, $exs) { w3_require_once(W3TC_INC_FUNCTIONS_DIR . '/other.php'); w3_require_once(W3TC_INC_FUNCTIONS_DIR . '/ui.php'); $src = W3TC_INSTALL_FILE_ADVANCED_CACHE; $dst = W3TC_ADDIN_FILE_ADVANCED_CACHE; if ($this->advanced_cache_installed()) { if ($this->is_advanced_cache_add_in()) { $script_data = @file_get_contents($dst); if ($script_data == @file_get_contents($src)) { return; } } else { w3_require_once(W3TC_INC_FUNCTIONS_DIR . '/other.php'); w3_require_once(W3TC_INC_FUNCTIONS_DIR . '/ui.php'); $remove_url = w3_admin_url('admin.php?page=w3tc_dashboard&w3tc_default_remove_add_in=pgcache'); $exs->push(new FilesystemOperationException(sprintf(__('The Page Cache add-in file advanced-cache.php is not a W3 Total Cache drop-in. It should be removed. %s', 'w3-total-cache'), w3tc_button_link(__('Yes, remove it for me', 'w3-total-cache'), wp_nonce_url($remove_url, 'w3tc'))))); return; } } try { w3_wp_copy_file($src, $dst); } catch (FilesystemOperationException $ex) { $exs->push($ex); } }
/** * Creates add-in * @throws FilesystemOperationException */ private function create_addin() { $src = W3TC_INSTALL_FILE_OBJECT_CACHE; $dst = W3TC_ADDIN_FILE_OBJECT_CACHE; if ($this->objectcache_installed()) { if ($this->is_objectcache_add_in()) { $script_data = @file_get_contents($dst); if ($script_data == @file_get_contents($src)) { return; } } elseif (!$this->objectcache_check_old_add_in()) { $remove_url = is_network_admin() ? network_admin_url('admin.php?page=' . $_GET['page'] . '&w3tc_default_remove_add_in=objectcache') : admin_url('admin.php?page=' . $_GET['page'] . '&w3tc_default_remove_add_in=objectcache'); throw new FilesystemOperationException(sprintf(__('The Object Cache add-in file object-cache.php is not a W3 Total Cache drop-in. Remove it or disable Object Caching. %s', 'w3-total-cache'), w3tc_button_link(__('Yes, remove it for me', 'w3-total-cache'), wp_nonce_url($remove_url, 'w3tc')))); } } w3_wp_copy_file($src, $dst); }
/** * Copy file if destination does not exists or not equal * * @param string $source_filename * @param string $destination_filename * @param string $method Which method to use when creating * @throws FilesystemCredentialException with S/FTP form if it can't get the required filesystem credentials * @throws FileOperationException */ function w3_copy_if_not_equal($source_filename, $destination_filename, $method = 'direct') { if (@file_exists($destination_filename)) { $s = fopen($source_filename, 'rb'); if ($s) { $v1 = fread($s, filesize($source_filename)); fclose($s); $d = fopen($destination_filename, 'rb'); if ($d) { if (filesize($destination_filename) <= 0) { $v2 = ''; } else { $v2 = fread($d, filesize($destination_filename)); } fclose($d); if ($v1 && $v2 && $v1 == $v2) { return; } } } } w3_wp_copy_file($source_filename, $destination_filename, $method); }