Version Description
- 2013-03-17 =
- Fixed: The 'copy' link in the 'backup successful' screen which stopped working after the 2.1.2 update.
- Added: An option to backup the database using WordPress' WPDB class.
- Removed: The need to keep the original backup names intact.
- Removed: 'lib/DirectoryTree.php' and 'lib/class.php'.
- Changed: The backup name structure.
- Changed: Backup file downloads are now handled using WP core functions.
Download this release
Release Info
Developer | wpacademy |
Plugin | WP Clone by WP Academy |
Version | 2.1.3 |
Comparing to | |
See all releases |
Code changes from version 2.1.2 to 2.1.3
- lib/DirectoryTree.php +0 -178
- lib/class.php +0 -56
- lib/css/style.css +7 -0
- lib/functions.php +1 -1
- lib/icit_srdb_replacer.php +154 -0
- lib/view.php +37 -27
- readme.txt +9 -1
- wpclone.php +6 -9
lib/DirectoryTree.php
DELETED
@@ -1,178 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
class DirectoryTree
|
3 |
-
{
|
4 |
-
/**
|
5 |
-
* Create a Directory Map
|
6 |
-
*
|
7 |
-
* Reads the specified directory and builds an array
|
8 |
-
* representation of it. Sub-folders contained with the
|
9 |
-
* directory will be mapped as well.
|
10 |
-
*
|
11 |
-
* @access public
|
12 |
-
* @param string path to source
|
13 |
-
* @param int depth of directories to traverse (0 = fully recursive, 1 = current dir, etc)
|
14 |
-
* @param bool
|
15 |
-
* @return array
|
16 |
-
*/
|
17 |
-
public static function getDirectoryFiles($source_dir, $directory_depth = 0, $hidden = FALSE)
|
18 |
-
{
|
19 |
-
if ($fp = @opendir($source_dir)) {
|
20 |
-
$fileData = array();
|
21 |
-
$new_depth = $directory_depth - 1;
|
22 |
-
$source_dir = rtrim($source_dir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
|
23 |
-
|
24 |
-
while (FALSE !== ($file = readdir($fp))) {
|
25 |
-
// Remove '.', '..', and hidden files [optional]
|
26 |
-
if (!trim($file, '.') OR ($hidden == FALSE && $file[0] == '.')) {
|
27 |
-
continue;
|
28 |
-
}
|
29 |
-
|
30 |
-
if (($directory_depth < 1 OR $new_depth > 0) && @is_dir($source_dir . $file)) {
|
31 |
-
$fileData[$file] = self::getDirectoryFiles($source_dir . $file . DIRECTORY_SEPARATOR, $new_depth, $hidden);
|
32 |
-
} else {
|
33 |
-
$fileData[] = $file;
|
34 |
-
}
|
35 |
-
}
|
36 |
-
|
37 |
-
closedir($fp);
|
38 |
-
return $fileData;
|
39 |
-
}
|
40 |
-
|
41 |
-
return FALSE;
|
42 |
-
}
|
43 |
-
|
44 |
-
/**
|
45 |
-
* Create a Directory Folder Map
|
46 |
-
*
|
47 |
-
* Reads the specified directory and builds an array of sub-folders.
|
48 |
-
* Sub-folders contained with the directory will be mapped as well.
|
49 |
-
*
|
50 |
-
* @access public
|
51 |
-
* @param string path to source
|
52 |
-
* @param int depth of directories to traverse (0 = fully recursive, 1 = current dir, etc)
|
53 |
-
* @param bool
|
54 |
-
* @return array
|
55 |
-
*/
|
56 |
-
public static function getDirectoryFolders($source_dir, $directory_depth = 0, $hidden = FALSE)
|
57 |
-
{
|
58 |
-
if ($fp = @opendir($source_dir)) {
|
59 |
-
$fileData = array();
|
60 |
-
$new_depth = $directory_depth - 1;
|
61 |
-
$source_dir = rtrim($source_dir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
|
62 |
-
|
63 |
-
while (FALSE !== ($file = readdir($fp))) {
|
64 |
-
// Remove '.', '..', and hidden files [optional]
|
65 |
-
if (!trim($file, '.') OR ($hidden == FALSE && $file[0] == '.')) {
|
66 |
-
continue;
|
67 |
-
}
|
68 |
-
|
69 |
-
if (($directory_depth < 1 OR $new_depth > 0) && @is_dir($source_dir . $file)) {
|
70 |
-
$fileData[$file] = self::getDirectoryFolders($source_dir . $file . DIRECTORY_SEPARATOR, $new_depth, $hidden);
|
71 |
-
}
|
72 |
-
}
|
73 |
-
|
74 |
-
closedir($fp);
|
75 |
-
return $fileData;
|
76 |
-
}
|
77 |
-
|
78 |
-
return FALSE;
|
79 |
-
}
|
80 |
-
|
81 |
-
public static function CopyDirectory($source, $destination)
|
82 |
-
{
|
83 |
-
if (is_dir($source)) {
|
84 |
-
|
85 |
-
mkdir($destination, WPBACKUP_FILE_PERMISSION);
|
86 |
-
$directory = dir($source);
|
87 |
-
|
88 |
-
while (FALSE !== ($readDirectory = $directory->read())) {
|
89 |
-
if ($readDirectory == '.' || $readDirectory == '..') {
|
90 |
-
continue;
|
91 |
-
}
|
92 |
-
|
93 |
-
$PathDir = $source . '/' . $readDirectory;
|
94 |
-
|
95 |
-
if (is_dir($PathDir)) {
|
96 |
-
self::CopyDirectory($PathDir, $destination . '/' . $readDirectory);
|
97 |
-
} else {
|
98 |
-
copy($PathDir, $destination . '/' . $readDirectory);
|
99 |
-
}
|
100 |
-
}
|
101 |
-
|
102 |
-
$directory->close();
|
103 |
-
|
104 |
-
} else {
|
105 |
-
|
106 |
-
@ copy($source, $destination);
|
107 |
-
|
108 |
-
}
|
109 |
-
}
|
110 |
-
|
111 |
-
public static function DeleteAllDirectoryFiles($directory, $empty = false)
|
112 |
-
{
|
113 |
-
try {
|
114 |
-
$iterator = new RecursiveIteratorIterator(
|
115 |
-
new RecursiveDirectoryIterator($directory),
|
116 |
-
RecursiveIteratorIterator::CHILD_FIRST);
|
117 |
-
|
118 |
-
foreach ($iterator as $path) {
|
119 |
-
if ($path->isDir()) {
|
120 |
-
@rmdir($path->__toString());
|
121 |
-
} else {
|
122 |
-
@unlink($path->__toString());
|
123 |
-
}
|
124 |
-
}
|
125 |
-
|
126 |
-
unset($iterator);
|
127 |
-
|
128 |
-
if ($empty == true) {
|
129 |
-
if (!rmdir($directory)) {
|
130 |
-
return false;
|
131 |
-
}
|
132 |
-
}
|
133 |
-
return true;
|
134 |
-
} catch (Exception $e) {
|
135 |
-
echo "Not Copied..." . $e->getMessage();
|
136 |
-
}
|
137 |
-
}
|
138 |
-
|
139 |
-
public static function openFileSearchAndReplace($parentDirectory, $searchFor, $replaceWith)
|
140 |
-
{
|
141 |
-
if (($handle = opendir($parentDirectory))) {
|
142 |
-
while (false !== ($file = readdir($handle))) {
|
143 |
-
if ($file != "." && $file != "..") {
|
144 |
-
if (is_dir($file)) {
|
145 |
-
self::openFileSearchAndReplace(wpCloneDirectory("{$parentDirectory}/{$file}"), $searchFor, $replaceWith);
|
146 |
-
} else {
|
147 |
-
|
148 |
-
// chdir("$parentDirectory"); //to make sure you are always in right directory
|
149 |
-
// strpos($searchFor);
|
150 |
-
$holdContent = file_get_contents($file);
|
151 |
-
$holdContent = str_replace($searchFor, $replaceWith, $holdContent);
|
152 |
-
file_put_contents($file, $holdContent);
|
153 |
-
}
|
154 |
-
}
|
155 |
-
}
|
156 |
-
|
157 |
-
closedir($handle);
|
158 |
-
}
|
159 |
-
}
|
160 |
-
|
161 |
-
public static function createDirectory($path)
|
162 |
-
{
|
163 |
-
if (file_exists($path)) {
|
164 |
-
return;
|
165 |
-
}
|
166 |
-
|
167 |
-
$serverRoot = rtrim(WPCLONE_ROOT, '/') . '/';
|
168 |
-
$directoryPath = str_replace($serverRoot, '', $path);
|
169 |
-
|
170 |
-
$directories = explode('/', $directoryPath);
|
171 |
-
|
172 |
-
$path = $serverRoot;
|
173 |
-
foreach($directories AS $folder) {
|
174 |
-
$path .= "{$folder}/";
|
175 |
-
file_exists($path) || mkdir($path, WPBACKUP_FILE_PERMISSION);
|
176 |
-
}
|
177 |
-
}
|
178 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lib/class.php
DELETED
@@ -1,56 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
class WPBackupZip
|
4 |
-
{
|
5 |
-
/**
|
6 |
-
* @var ZipArchive
|
7 |
-
*/
|
8 |
-
protected $zip;
|
9 |
-
protected $root = '';
|
10 |
-
protected $ignored_names;
|
11 |
-
|
12 |
-
function __construct($file, $folder, $ignored=null)
|
13 |
-
{
|
14 |
-
$this->zip = new ZipArchive();
|
15 |
-
$this->ignored_names = is_array($ignored) ? $ignored : $ignored ? array($ignored) : array();
|
16 |
-
|
17 |
-
if ($this->zip->open($file, ZIPARCHIVE::CREATE) !== TRUE) {
|
18 |
-
throw new Exception("cannot open <$file>\n");
|
19 |
-
}
|
20 |
-
|
21 |
-
$folder = $this->getFolder($folder);
|
22 |
-
$this->zip($folder);
|
23 |
-
$this->zip->close();
|
24 |
-
}
|
25 |
-
|
26 |
-
protected function zip($folder, $parent=null)
|
27 |
-
{
|
28 |
-
$full_path = $this->root . $parent . $folder;
|
29 |
-
$zip_path = $parent . $folder;
|
30 |
-
$this->zip->addEmptyDir($zip_path);
|
31 |
-
$dir = new DirectoryIterator($full_path);
|
32 |
-
foreach ($dir as $file) {
|
33 |
-
if (!$file->isDot()) {
|
34 |
-
$filename = $file->getFilename();
|
35 |
-
if (!in_array($filename, $this->ignored_names)) {
|
36 |
-
if ($file->isDir()) {
|
37 |
-
$this->zip($filename, $zip_path . '/');
|
38 |
-
} else {
|
39 |
-
$this->zip->addFile($full_path . '/' . $filename, $zip_path . '/' . $filename);
|
40 |
-
}
|
41 |
-
}
|
42 |
-
}
|
43 |
-
}
|
44 |
-
}
|
45 |
-
|
46 |
-
protected function getFolder($folder)
|
47 |
-
{
|
48 |
-
$folder = rtrim($folder, "\\/");
|
49 |
-
if (strstr($folder, '/')) {
|
50 |
-
$this->root = substr($folder, 0, strrpos($folder, '/') + 1);
|
51 |
-
$folder = substr($folder, strrpos($folder, '/') + 1);
|
52 |
-
}
|
53 |
-
|
54 |
-
return $folder;
|
55 |
-
}
|
56 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lib/css/style.css
CHANGED
@@ -111,4 +111,11 @@ input[type="submit"].btn-warning:hover, input[type="submit"].btn-warning:active,
|
|
111 |
color: #EEEEEE;
|
112 |
}
|
113 |
.btn-warning:active, .btn-warning.active {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
114 |
}
|
111 |
color: #EEEEEE;
|
112 |
}
|
113 |
.btn-warning:active, .btn-warning.active {
|
114 |
+
}
|
115 |
+
|
116 |
+
.wpclone_notice {
|
117 |
+
width: 500px;
|
118 |
+
padding: 5px;
|
119 |
+
margin: 25px 0 0 0;
|
120 |
+
border-radius: 5px;
|
121 |
}
|
lib/functions.php
CHANGED
@@ -1 +1 @@
|
|
1 |
-
<?php
|
2 |
$backupName = date('Y-m-d-H-i-s') . '_' . get_bloginfo('name', 'display');
|
3 |
$backupName = substr(str_replace(' ', '', $backupName), 0, 40);
|
4 |
$backupName = sanitize_file_name($backupName);
|
5 |
return $backupName;
|
6 |
return str_replace("\\", "/", $path);
|
7 |
return rtrim(str_replace("//", "/", wpCloneSafePathMode($path)), '/') . '/';
|
8 |
return str_replace(rtrim(WPCLONE_ROOT, "/\\"), site_url(), $path);
|
9 |
return str_replace(site_url(), rtrim(WPCLONE_ROOT, "/\\"), $url);
|
10 |
if (is_readable($source)) {
|
11 |
if (is_dir($source)) {
|
12 |
if (!strstr(wpCloneSafePathMode($source), rtrim(WPCLONE_DIR_BACKUP, "/\\"))) {
|
13 |
if (!file_exists($target)) {
|
14 |
mkdir($target, WPBACKUP_FILE_PERMISSION);
|
15 |
}
|
16 |
$d = dir($source);
|
17 |
while (FALSE !== ($entry = $d->read())) {
|
18 |
if ($entry == '.' || $entry == '..') {
|
19 |
continue;
|
20 |
}
|
21 |
$Entry = "{$source}/{$entry}";
|
22 |
if (is_dir($Entry)) {
|
23 |
wpBackupFullCopy($Entry, $target . '/' . $entry);
|
24 |
} else {
|
25 |
@ copy($Entry, $target . '/' . $entry);
|
26 |
}
|
27 |
}
|
28 |
$d->close();
|
29 |
}
|
30 |
} else {
|
31 |
copy($source, $target);
|
32 |
}
|
33 |
}
|
34 |
global $wpdb;
|
35 |
$WPCLONE_DB_ICONV_IN = "UTF-8";
|
36 |
$WPCLONE_DB_ICONV_OUT = "ISO-8859-1//TRANSLIT";
|
37 |
$return = '';
|
38 |
// Get all of the tables
|
39 |
$tables = $wpdb->get_col('SHOW TABLES');
|
40 |
// Cycle through each provided table
|
41 |
foreach ($tables as $table) {
|
42 |
// First part of the output � remove the table
|
43 |
$result = $wpdb->get_results("SELECT * FROM {$table}", ARRAY_N);
|
44 |
$numberOfFields = count($result[0]);
|
45 |
$numberOfItems = count($result);
|
46 |
// Second part of the output � create table
|
47 |
$row2 = $wpdb->get_row("SHOW CREATE TABLE {$table}", ARRAY_N);
|
48 |
$return .= "\n\n" . $row2[1] . ";\n\n";
|
49 |
// Third part of the output � insert values into new table
|
50 |
for ($currentRowNumber = 0; $currentRowNumber < $numberOfItems; $currentRowNumber++) {
|
51 |
$row = $result[$currentRowNumber];
|
52 |
$query = "INSERT INTO {$table} VALUES(";
|
53 |
for ($j = 0; $j < $numberOfFields; $j++) {
|
54 |
$row[$j] = iconv($WPCLONE_DB_ICONV_IN, $WPCLONE_DB_ICONV_OUT, $row[$j]);
|
55 |
$query .= (empty($row[$j])) ? '"", ' : '"' . mysql_real_escape_string($row[$j]) . '", ';
|
56 |
}
|
57 |
$return .= substr($query, 0, -2) . ");\n";
|
58 |
}
|
59 |
$return .= "\n";
|
60 |
}
|
61 |
// Generate the filename for the sql file
|
62 |
$File_open = fopen($destination . '/database.sql', 'w+');
|
63 |
// Save the sql file
|
64 |
fwrite($File_open, $return);
|
65 |
//file close
|
66 |
fclose($File_open);
|
67 |
$wpdb->flush();
|
68 |
global $wpdb;
|
69 |
global $current_user;
|
70 |
$wpdb->insert($wpdb->prefix . "wpclone", array(
|
71 |
'backup_name' => $name,
|
72 |
'data_time' => current_time('mysql', get_option('gmt_offset')),
|
73 |
'creator' => $current_user->user_login,
|
74 |
'backup_size' => $size)
|
75 |
);
|
76 |
$wpdb->flush;
|
77 |
$folderToBeZipped = WPCLONE_DIR_BACKUP . $backupName;
|
78 |
$destinationPath = $folderToBeZipped . '/' . basename(WPCLONE_WP_CONTENT);
|
79 |
$zipFileName = $backupName . '.zip';
|
80 |
DirectoryTree::createDirectory($destinationPath);
|
81 |
wpBackupFullCopy(rtrim(WPCLONE_WP_CONTENT, "/\\"), $destinationPath);
|
82 |
wpa_save_prefix($folderToBeZipped);
|
83 |
dw_backup_tables(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME, $folderToBeZipped);
|
84 |
wpa_zip("{$folderToBeZipped}.zip", $folderToBeZipped, $zipmode);
|
85 |
$zipSize = filesize("{$folderToBeZipped}.zip");
|
86 |
DirectoryTree::DeleteAllDirectoryFiles($folderToBeZipped, true);
|
87 |
return array($zipFileName, $zipSize);
|
88 |
$backupDirectory = rtrim(WPCLONE_DIR_BACKUP, "/\\");
|
89 |
$key = array_search($backupDirectory, $directoryFiles);
|
90 |
if ($directoryFiles[$key] === $backupDirectory) {
|
91 |
unset($directoryFiles[$key]);
|
92 |
}
|
93 |
$destinationPath = WPCLONE_DIR_BACKUP . $backupName;
|
94 |
$zipFileName = $backupName . '.zip';
|
95 |
mkdir($destinationPath, WPBACKUP_FILE_PERMISSION);
|
96 |
foreach($directoryFiles AS $directoryFolder) {
|
97 |
$destinationFolder = str_replace(rtrim(WPCLONE_ROOT, "/\\"), $destinationPath, $directoryFolder);
|
98 |
wpBackupFullCopy($directoryFolder, $destinationFolder);
|
99 |
}
|
100 |
CreateDb($destinationPath);
|
101 |
wpa_zip("{$destinationPath}.zip", $destinationPath);
|
102 |
$zipSize = filesize("{$destinationPath}.zip");
|
103 |
DirectoryTree::DeleteAllDirectoryFiles($destinationPath, true);
|
104 |
return array($zipFileName, $zipSize);
|
105 |
$installerBackupFile = "{$backupName}_wpclone";
|
106 |
$installerBackupPath = WPCLONE_DIR_BACKUP . $installerBackupFile;
|
107 |
$installerBackupFileZip = $installerBackupFile . '.zip';
|
108 |
wpBackupFullCopy(rtrim(WPCLONE_INSTALLER_PATH, "/\\"), $installerBackupPath);
|
109 |
$editBackupFilePath = $installerBackupPath . "/lib/file";
|
110 |
$backupZipPath = convertPathIntoUrl(WPCLONE_DIR_BACKUP . $zipFileName);
|
111 |
if (file_exists($editBackupFilePath)) {
|
112 |
$search = 'class="Url" value=""';
|
113 |
$replace = 'class="Url" value="' . $backupZipPath . '"';
|
114 |
chdir($editBackupFilePath);
|
115 |
DirectoryTree::openFileSearchAndReplace($editBackupFilePath, $search, $replace);
|
116 |
!file_exists($installerBackupPath . '/lib/view.php') || unlink($installerBackupPath . '/lib/view.php');
|
117 |
$copyFrom = $editBackupFilePath . '/view.php';
|
118 |
$copyTo = $installerBackupPath . '/lib/view.php';
|
119 |
DirectoryTree::CopyDirectory($copyFrom, $copyTo);
|
120 |
}
|
121 |
new WPbackupZip("{$installerBackupPath}.zip", $installerBackupPath, '.svn');
|
122 |
DirectoryTree::DeleteAllDirectoryFiles($installerBackupPath, true);
|
123 |
return $installerBackupFileZip;
|
124 |
|
125 |
$zipFileObject = new ZipArchive;
|
126 |
$response = true;
|
127 |
|
128 |
|
129 |
if ( $zipFileObject->open($zipFilename) === TRUE ) {
|
130 |
|
131 |
$zipFileObject->extractTo($destinationFolder);
|
132 |
/* Remove htaccess file from directory. */
|
133 |
$folder = pathinfo($zipFilename, PATHINFO_FILENAME);
|
134 |
$htaccess = wpCloneSafePathMode($destinationFolder . $folder) . '/.htaccess';
|
135 |
!(file_exists($htaccess)) || unlink($htaccess);
|
136 |
|
137 |
}
|
138 |
else {
|
139 |
$response = false;
|
140 |
}
|
141 |
unset($zipFileObject);
|
142 |
return $response;
|
143 |
global $wpdb;
|
144 |
$wp_backup = "{$wpdb->prefix}wpclone";
|
145 |
$deleteRow = $wpdb->get_row("SELECT * FROM {$wp_backup} WHERE id = '{$nm}'");
|
146 |
$wpdb->query("DELETE FROM {$wp_backup} WHERE id = '{$nm}' ");
|
147 |
if (file_exists(WPCLONE_DIR_BACKUP . $deleteRow->backup_name)) unlink(WPCLONE_DIR_BACKUP . $deleteRow->backup_name) or die ('unable to delete backup file.');
|
148 |
if (file_exists(WPCLONE_DIR_BACKUP . $deleteRow->installer_name)) @unlink(WPCLONE_DIR_BACKUP . $deleteRow->installer_name);
|
149 |
return $deleteRow;
|
150 |
$kilobyte = 1024;
|
151 |
$megabyte = $kilobyte * 1024;
|
152 |
$gigabyte = $megabyte * 1024;
|
153 |
$terabyte = $gigabyte * 1024;
|
154 |
if (($bytes >= 0) && ($bytes < $kilobyte)) {
|
155 |
return $bytes . ' B';
|
156 |
} elseif (($bytes >= $kilobyte) && ($bytes < $megabyte)) {
|
157 |
return round($bytes / $kilobyte, $precision) . ' KB';
|
158 |
} elseif (($bytes >= $megabyte) && ($bytes < $gigabyte)) {
|
159 |
return round($bytes / $megabyte, $precision) . ' MB';
|
160 |
} elseif (($bytes >= $gigabyte) && ($bytes < $terabyte)) {
|
161 |
return round($bytes / $gigabyte, $precision) . ' GB';
|
162 |
} elseif ($bytes >= $terabyte) {
|
163 |
return round($bytes / $terabyte, $precision) . ' TB';
|
164 |
} else {
|
165 |
return $bytes . ' B';
|
166 |
}
|
167 |
$ext = strrchr($name, '.');
|
168 |
if ($ext !== false) {
|
169 |
$name = substr($name, 0, -strlen($ext));
|
170 |
}
|
171 |
return $name;
|
172 |
function file_put_contents($filename, $data)
|
173 |
{
|
174 |
$f = @fopen($filename, 'w');
|
175 |
if (!$f) {
|
176 |
return false;
|
177 |
} else {
|
178 |
$bytes = fwrite($f, $data);
|
179 |
fclose($f);
|
180 |
return $bytes;
|
181 |
}
|
182 |
}
|
183 |
*
|
184 |
* @param string $filename
|
185 |
* @return string
|
186 |
*/
|
187 |
if (!function_exists('file_get_contents')) {
|
188 |
$handle = fopen($filename, "r");
|
189 |
$contents = fread($handle, filesize($filename));
|
190 |
fclose($handle);
|
191 |
} else {
|
192 |
$contents = file_get_contents($filename);
|
193 |
}
|
194 |
return $contents;
|
195 |
$dbInfo = array();
|
196 |
$dbInfo["dbhost"] = DB_HOST;
|
197 |
$dbInfo["dbname"] = DB_NAME;
|
198 |
$dbInfo["dbuser"] = DB_USER;
|
199 |
$dbInfo["dbpassword"] = DB_PASSWORD;
|
200 |
return $dbInfo;
|
201 |
$selectQuery = "SELECT COUNT(*) AS number_of_tables
|
202 |
FROM information_schema.tables
|
203 |
WHERE table_schema = '{$databaseName}'";
|
204 |
$numOfTables = mysql_query($selectQuery, $dbConn);
|
205 |
$numOfTables = mysql_fetch_assoc($numOfTables);
|
206 |
return $numOfTables;
|
207 |
$backupFileVariables = getVariablesFromFile($configInZipFile);
|
208 |
$backupPrefix = $backupFileVariables["table_prefix"];
|
209 |
replaceTablePrefix($currentConfigFile, $backupPrefix);
|
210 |
return $backupPrefix;
|
211 |
ob_start();
|
212 |
include($filename);
|
213 |
ob_end_clean();
|
214 |
return get_defined_vars();
|
215 |
$fileContent = file_get_contents($filename);
|
216 |
$pos = strpos($fileContent, '$table_prefix');
|
217 |
$str = substr($fileContent, $pos, strpos($fileContent, PHP_EOL, $pos) - $pos);
|
218 |
$fileContent = str_replace($str, '$table_prefix = "' . $newPrefix . '";', $fileContent);
|
219 |
file_put_contents($filename, $fileContent);
|
220 |
$fileContent = file_get_contents($databaseFile, true);
|
221 |
$pos = strpos($fileContent, 'siteurl') + 8;
|
222 |
$urlStartPos = strpos($fileContent, '"', $pos) + 1;
|
223 |
$urlEndPos = strpos($fileContent, '"', $urlStartPos);
|
224 |
$backupSiteUrl = substr($fileContent, $urlStartPos, $urlEndPos - $urlStartPos);
|
225 |
return $backupSiteUrl;
|
226 |
/* Replacing backup site url with the current one. */
|
227 |
$backupSiteUrl = replaceSiteUrlFromDatabaseFile($databaseFileInZip);
|
228 |
$currentSiteUrl = site_url();
|
229 |
$backupSiteUrl = wpa_trailing_slash_check($backupSiteUrl);
|
230 |
$currentSiteUrl = wpa_trailing_slash_check($currentSiteUrl);
|
231 |
$dbInfo = getDbInfo();
|
232 |
$conn = mysql_connect($dbInfo['dbhost'], $dbInfo['dbuser'], $dbInfo['dbpassword']);
|
233 |
mysql_select_db($dbInfo['dbname'], $conn) or die(mysql_error());
|
234 |
$query = mysql_query("SHOW TABLES", $conn);
|
235 |
while (($fetch = mysql_fetch_array($query))) {
|
236 |
mysql_query("Drop table `{$fetch[0]}`") or die(mysql_error() . '<br> Acess denied');
|
237 |
}
|
238 |
$dbFileContent = file_get_contents($databaseFileInZip);
|
239 |
$res = explode(";\n", $dbFileContent);
|
240 |
flush();
|
241 |
foreach ($res AS $query) {
|
242 |
mysql_query($query, $conn);
|
243 |
}
|
244 |
wpa_safe_replace_wrapper ( $dbInfo['dbhost'], $dbInfo['dbuser'], $dbInfo['dbpassword'], $dbInfo['dbname'], $backupSiteUrl, $currentSiteUrl );
|
245 |
mysql_close($conn);
|
246 |
return $currentSiteUrl;
|
247 |
*
|
248 |
* @param type $host mysql host name,already defined in wp-config.php as DB_HOST.
|
249 |
* @param type $user mysql username, "" DB_USER.
|
250 |
* @param type $pass mysql password, "" DB_PASSWORD.
|
251 |
* @param type $data mysql database name, "" DB_NAME.
|
252 |
* @param type $search URL of the previous site.
|
253 |
* @param type $replace URL of the current site.
|
254 |
* @return type total time it took for the operation.
|
255 |
*/
|
256 |
$connection = @mysql_connect( $host, $user, $pass );
|
257 |
$all_tables = array( );
|
258 |
@mysql_select_db( $data, $connection );
|
259 |
$all_tables_mysql = @mysql_query( 'SHOW TABLES', $connection );
|
260 |
if ( ! $all_tables_mysql ) {
|
261 |
$errors[] = mysql_error( );
|
262 |
} else {
|
263 |
while ( $table = mysql_fetch_array( $all_tables_mysql ) ) {
|
264 |
$all_tables[] = $table[ 0 ];
|
265 |
}
|
266 |
}
|
267 |
$report = icit_srdb_replacer( $connection, $search, $replace, $all_tables );
|
268 |
return $report;
|
269 |
* Take a serialised array and unserialise it replacing elements as needed and
|
270 |
* unserialising any subordinate arrays and performing the replace on those too.
|
271 |
*
|
272 |
* @param string $from String we're looking to replace.
|
273 |
* @param string $to What we want it to be replaced with
|
274 |
* @param array $data Used to pass any subordinate arrays back to in.
|
275 |
* @param bool $serialised Does the array passed via $data need serialising.
|
276 |
*
|
277 |
* @return array The original array with all elements replaced as needed.
|
278 |
*/
|
279 |
* The main loop triggered in step 5. Up here to keep it out of the way of the
|
280 |
* HTML. This walks every table in the db that was selected in step 3 and then
|
281 |
* walks every row and column replacing all occurences of a string with another.
|
282 |
* We split large tables into 50,000 row blocks when dealing with them to save
|
283 |
* on memmory consumption.
|
284 |
*
|
285 |
* @param mysql $connection The db connection object
|
286 |
* @param string $search What we want to replace
|
287 |
* @param string $replace What we want to replace it with.
|
288 |
* @param array $tables The tables we want to look at.
|
289 |
*
|
290 |
* @return array Collection of information gathered during the run.
|
291 |
*/
|
292 |
if (!is_string($url) || '' == $url) die('The provided path is not valid,aborting..');
|
293 |
|
294 |
$pathParts = pathinfo($url);
|
295 |
$urlDir = WPCLONE_DIR_BACKUP . 'url/';
|
296 |
file_exists($urlDir) || mkdir($urlDir, WPBACKUP_FILE_PERMISSION);
|
297 |
|
298 |
/* Copy the file found from url to plugin root */
|
299 |
$zipFilename = $urlDir . $pathParts['basename'];
|
300 |
DirectoryTree::CopyDirectory($url, $zipFilename);
|
301 |
$result = wpa_unzip($zipFilename, WPCLONE_ROOT, $zipmode);
|
302 |
if ($result) {
|
303 |
$unzippedFolderPath = wpCloneSafePathMode(WPCLONE_ROOT . $pathParts['filename']);
|
304 |
$old_db_prefix = $unzippedFolderPath . '/prefix.txt';
|
305 |
$prefix = wpa_check_prefix($old_db_prefix);
|
306 |
$databaseFile = $unzippedFolderPath . '/database.sql';
|
307 |
if ($prefix) {
|
308 |
wpa_replace_prefix( ABSPATH . 'wp-config.php', $prefix );
|
309 |
}
|
310 |
|
311 |
$currentSiteUrl = processConfigAndDatabaseFile($databaseFile);
|
312 |
!file_exists($databaseFile) || unlink($databaseFile);
|
313 |
!file_exists($old_db_prefix) || unlink($old_db_prefix);
|
314 |
!file_exists($unzippedFolderPath . '/wp-config.php') || unlink($unzippedFolderPath . '/wp-config.php');
|
315 |
wpa_copy($unzippedFolderPath, WPCLONE_ROOT);
|
316 |
DirectoryTree::DeleteAllDirectoryFiles($unzippedFolderPath, true);
|
317 |
echo "<h1>Restore Successful!</h1>";
|
318 |
echo "Visit your restored site [ <a href='{$currentSiteUrl}' target=blank>here</a> ]<br><br>";
|
319 |
echo "<strong>You may need to re-save your permalink structure <a href='{$currentSiteUrl}/wp-admin/options-permalink.php' target=blank>Here</a></strong>";
|
320 |
} else {
|
321 |
echo "<h1>Restore unsuccessful!!!</h1>";
|
322 |
echo "Please try again.";
|
323 |
}
|
324 |
!file_exists($urlDir) || DirectoryTree::DeleteAllDirectoryFiles($urlDir, true);
|
325 |
global $wpdb;
|
326 |
$prefix = $wpdb->prefix;
|
327 |
$file = $path . '/prefix.txt';
|
328 |
if ( is_dir($path) && is_writable($path) ) {
|
329 |
file_put_contents($file, $prefix);
|
330 |
}
|
331 |
* Checks to see whether the current destination site's table prefix matches that of the origin site.old prefix is returned in case of a mismatch.
|
332 |
*
|
333 |
* @param type $file path to the prefix.txt file.
|
334 |
* @return type bool string
|
335 |
*/
|
336 |
global $wpdb;
|
337 |
$prefix = $wpdb->prefix;
|
338 |
if (file_exists($file) && is_readable($file)) {
|
339 |
$old_prefix = file_get_contents($file);
|
340 |
if ( $prefix !== $old_prefix ) {
|
341 |
return $old_prefix;
|
342 |
}
|
343 |
else {
|
344 |
return false;
|
345 |
}
|
346 |
}
|
347 |
return false;
|
348 |
* checks for a trailing slash at the end of the provided URL and strips it if found.
|
349 |
* @param type $url
|
350 |
* @return type
|
351 |
*/
|
352 |
if (substr($url, -1) == "/" ) {
|
353 |
$url = rtrim($url, "/");
|
354 |
return $url;
|
355 |
}
|
356 |
else {
|
357 |
return $url;
|
358 |
}
|
359 |
* @link http://davidwalsh.name/backup-mysql-database-php
|
360 |
*
|
361 |
* @param type $host
|
362 |
* @param type $user
|
363 |
* @param type $pass
|
364 |
* @param type $name
|
365 |
* @param type $tables
|
366 |
*/
|
367 |
* @since 2.0.6
|
368 |
*
|
369 |
* @param type $zipfile path to the zip file that needs to be extracted.
|
370 |
* @param type $path the place to where the file needs to be extracted.
|
371 |
* @return as false in the event of failure.
|
372 |
*/
|
373 |
if ( $zipmode || (!in_array('ZipArchive', get_declared_classes()) || !class_exists('ZipArchive')) ) {
|
374 |
define('PCLZIP_TEMPORARY_DIR', WPCLONE_DIR_BACKUP);
|
375 |
require_once ( ABSPATH . 'wp-admin/includes/class-pclzip.php' );
|
376 |
$z = new PclZip($zipfile);
|
377 |
if ($z->extract(PCLZIP_OPT_PATH, $path) == 0) {
|
378 |
return false;
|
379 |
}
|
380 |
echo 'PclZip';
|
381 |
return true;
|
382 |
}
|
383 |
else {
|
384 |
$r = unzipBackupFile($zipfile, $path);
|
385 |
return $r;
|
386 |
}
|
387 |
* @since 2.0.6
|
388 |
*
|
389 |
* @param type $name name of the zip file.
|
390 |
* @param type $file_list an array of files that needs to be archived.
|
391 |
*/
|
392 |
if ( $zipmode || (!in_array('ZipArchive', get_declared_classes()) || !class_exists('ZipArchive')) ) {
|
393 |
define('PCLZIP_TEMPORARY_DIR', WPCLONE_DIR_BACKUP);
|
394 |
require_once ( ABSPATH . 'wp-admin/includes/class-pclzip.php');
|
395 |
$z = new PclZip($name);
|
396 |
$v_list = $z->create($file_list, PCLZIP_OPT_REMOVE_PATH, WPCLONE_DIR_BACKUP);
|
397 |
if ($v_list == 0) {
|
398 |
die("Error : ".$z->errorInfo(true));
|
399 |
}
|
400 |
}
|
401 |
else {
|
402 |
new WPbackupZip($name, $file_list, '.svn');
|
403 |
}
|
404 |
* just a simple function to increase PHP limits.
|
405 |
* @since 2.0.6
|
406 |
*/
|
407 |
$time = isset($time) && $time != '' ? $time : 900;
|
408 |
$mem = isset ($mem) && $mem != '' ? $mem . 'M' : '512M';
|
409 |
@ini_set('memory_limit', $mem);
|
410 |
@ini_set('max_execution_time', $time); //900 seconds = 15 minutes
|
411 |
* @since 2.0.6
|
412 |
*/
|
413 |
if (!empty($_REQUEST['del'])) {
|
414 |
wpa_remove_backup();
|
415 |
return true;
|
416 |
}
|
417 |
if (isset($_POST['createBackup'])) {
|
418 |
wpa_create_backup();
|
419 |
return true;
|
420 |
}
|
421 |
if (empty($_POST)) return false;
|
422 |
check_admin_referer('wpclone-submit');
|
423 |
$form_post = wp_nonce_url('admin.php?page=wp-clone', 'wpclone-submit');
|
424 |
$extra_fields = array('restore_from_url', 'maxmem', 'maxexec', 'zipmode', 'restoreBackup');
|
425 |
$type = '';
|
426 |
if ( false === ($creds = request_filesystem_credentials($form_post, $type, false, false, $extra_fields)) ){
|
427 |
return true;
|
428 |
}
|
429 |
if (!WP_Filesystem($creds)) {
|
430 |
request_filesystem_credentials($form_post, $type, true, false, $extra_fields);
|
431 |
return true;
|
432 |
}
|
433 |
wpa_bump_limits($_POST['maxmem'], $_POST['maxexec']);
|
434 |
$url = isset($_POST['restoreBackup']) ? $_POST['restoreBackup'] : $_POST['restore_from_url'];
|
435 |
$zipmode = isset($_POST['zipmode']) ? true : false;
|
436 |
processRestoringBackup($url, $zipmode);
|
437 |
return true;
|
438 |
* @since 2.0.6
|
439 |
*/
|
440 |
global $wp_filesystem;
|
441 |
if (is_readable($source)) {
|
442 |
if (is_dir($source)) {
|
443 |
if (!strstr(wpCloneSafePathMode($source), rtrim(WPCLONE_DIR_BACKUP, "/\\"))) {
|
444 |
if (!file_exists($target)) {
|
445 |
$wp_filesystem->mkdir($target);
|
446 |
}
|
447 |
$d = dir($source);
|
448 |
while (FALSE !== ($entry = $d->read())) {
|
449 |
if ($entry == '.' || $entry == '..') {
|
450 |
continue;
|
451 |
}
|
452 |
$Entry = "{$source}/{$entry}";
|
453 |
if (is_dir($Entry)) {
|
454 |
wpa_copy($Entry, $target . '/' . $entry);
|
455 |
} else {
|
456 |
$wp_filesystem->copy($Entry, $target . '/' . $entry, true, FS_CHMOD_FILE);
|
457 |
}
|
458 |
}
|
459 |
$d->close();
|
460 |
}
|
461 |
}
|
462 |
else {
|
463 |
$wp_filesystem->copy($source, $target, true);
|
464 |
}
|
465 |
}
|
466 |
* @since 2.0.6
|
467 |
*/
|
468 |
if (!is_writable($filename)) die ("Unable to modify wp-config.php,please change the permissions to '0600'.Aborting..");
|
469 |
global $wp_filesystem;
|
470 |
$fileContent = file_get_contents($filename);
|
471 |
$pos = strpos($fileContent, '$table_prefix');
|
472 |
$str = substr($fileContent, $pos, strpos($fileContent, PHP_EOL, $pos) - $pos);
|
473 |
$fileContent = str_replace($str, '$table_prefix = "' . $newPrefix . '";', $fileContent);
|
474 |
$wp_filesystem->put_contents($filename, $fileContent, 0600);
|
475 |
* @since 2.0.6
|
476 |
*/
|
477 |
check_admin_referer('wpclone-submit');
|
478 |
get_currentuserinfo();
|
479 |
wpa_bump_limits($_POST['maxmem'], $_POST['maxexec']);
|
480 |
$backupName = getBackupFileName();
|
481 |
$zipmode = isset($_POST['zipmode']) ? true : false;
|
482 |
list($zipFileName, $zipSize) = CreateWPFullBackupZip($backupName, $zipmode);
|
483 |
InsertData($zipFileName, $zipSize);
|
484 |
$backZipPath = convertPathIntoUrl(WPCLONE_DIR_BACKUP . $zipFileName);
|
485 |
$zipSize = bytesToSize($zipSize);
|
486 |
echo <<<EOF
|
487 |
<a href='{$backZipPath}'><span>{$backZipPath}</span></a> ( {$zipSize} ) |
|
488 |
<input type='hidden' name='backupUrl' class='backupUrl' value="{$backZipPath}" />
|
489 |
<a class='copy-button' href='#'>Copy URL</a> <br /><br />
|
490 |
(Copy that link and paste it into the "Restore URL" of your new WordPress installation to clone this site)
|
491 |
* @since 2.0.6
|
492 |
*/
|
493 |
$deleteRow = DeleteWPBackupZip($_REQUEST['del']);
|
494 |
echo <<<EOT
|
495 |
<h1>Deleted Successful!</h1> <br />
|
496 |
{$deleteRow->backup_name} <br />
|
497 |
File deleted from backup folder and database...
|
|
|
498 |
return str_replace("\\", "/", $path);
|
499 |
return rtrim(str_replace("//", "/", wpCloneSafePathMode($path)), '/') . '/';
|
500 |
return str_replace(rtrim(WPCLONE_ROOT, "/\\"), site_url(), $path);
|
501 |
return str_replace(site_url(), rtrim(WPCLONE_ROOT, "/\\"), $url);
|
502 |
global $wpdb;
|
503 |
$WPCLONE_DB_ICONV_IN = "UTF-8";
|
504 |
$WPCLONE_DB_ICONV_OUT = "ISO-8859-1//TRANSLIT";
|
505 |
$return = '';
|
506 |
// Get all of the tables
|
507 |
$tables = $wpdb->get_col('SHOW TABLES');
|
508 |
// Cycle through each provided table
|
509 |
foreach ($tables as $table) {
|
510 |
// First part of the output � remove the table
|
511 |
$result = $wpdb->get_results("SELECT * FROM {$table}", ARRAY_N);
|
512 |
$numberOfFields = count($result[0]);
|
513 |
$numberOfItems = count($result);
|
514 |
// Second part of the output � create table
|
515 |
$row2 = $wpdb->get_row("SHOW CREATE TABLE {$table}", ARRAY_N);
|
516 |
$return .= "\n\n" . $row2[1] . ";\n\n";
|
517 |
// Third part of the output � insert values into new table
|
518 |
for ($currentRowNumber = 0; $currentRowNumber < $numberOfItems; $currentRowNumber++) {
|
519 |
$row = $result[$currentRowNumber];
|
520 |
$query = "INSERT INTO {$table} VALUES(";
|
521 |
for ($j = 0; $j < $numberOfFields; $j++) {
|
522 |
$row[$j] = iconv($WPCLONE_DB_ICONV_IN, $WPCLONE_DB_ICONV_OUT, $row[$j]);
|
523 |
$query .= (empty($row[$j])) ? '"", ' : '"' . mysql_real_escape_string($row[$j]) . '", ';
|
524 |
}
|
525 |
$return .= substr($query, 0, -2) . ");\n";
|
526 |
}
|
527 |
$return .= "\n";
|
528 |
}
|
529 |
// Generate the filename for the sql file
|
530 |
$File_open = fopen($destination . '/database.sql', 'w+');
|
531 |
// Save the sql file
|
532 |
fwrite($File_open, $return);
|
533 |
//file close
|
534 |
fclose($File_open);
|
535 |
$wpdb->flush();
|
536 |
* @link http://davidwalsh.name/backup-mysql-database-php
|
537 |
*/
|
538 |
if ( false === $link ) {
|
539 |
wpa_backup_error('db', mysql_error() );
|
540 |
}
|
541 |
if ( false === $result ) {
|
542 |
wpa_backup_error('db', mysql_error() );
|
543 |
}
|
544 |
if ( false === $result ) {
|
545 |
wpa_backup_error('db', mysql_error() );
|
546 |
}
|
547 |
global $wpdb;
|
548 |
global $current_user;
|
549 |
$wpdb->insert($wpdb->prefix . "wpclone", array(
|
550 |
'backup_name' => $name,
|
551 |
'data_time' => current_time('mysql', get_option('gmt_offset')),
|
552 |
'creator' => $current_user->user_login,
|
553 |
'backup_size' => $size)
|
554 |
);
|
555 |
$wpdb->flush();
|
556 |
$folderToBeZipped = WPCLONE_DIR_BACKUP . 'wpclone_backup';
|
557 |
$destinationPath = $folderToBeZipped . '/' . basename(WPCLONE_WP_CONTENT);
|
558 |
$zipFileName = WPCLONE_DIR_BACKUP . $backupName . '.zip';
|
559 |
global $wp_filesystem;
|
560 |
|
561 |
/* create the backup directory and call the cleanup function if it failed to do so */
|
562 |
$dir = $wp_filesystem->mkdir( $folderToBeZipped );
|
563 |
if( is_wp_error($dir) ) {
|
564 |
wpa_backup_error ( 'file', $dir->get_error_message() . $folderToBeZipped );
|
565 |
}
|
566 |
/* copy wp-content directory into the newly created backup directory. call the cleanup function if it fails.
|
567 |
* (wpa_copy doesn't return anything at the moment)*/
|
568 |
$files = wpa_copy(WPCLONE_WP_CONTENT, $destinationPath);
|
569 |
if( is_wp_error($files) ) {
|
570 |
wpa_backup_error ( 'file', $files->get_error_message() );
|
571 |
}
|
572 |
wpa_save_prefix($folderToBeZipped);
|
573 |
/* error handler is called from within the db backup functions */
|
574 |
if ( $use_wpdb ) {
|
575 |
wpa_db_backup_wpdb( $folderToBeZipped );
|
576 |
} else {
|
577 |
wpa_db_backup_direct( $folderToBeZipped );
|
578 |
}
|
579 |
|
580 |
/* error haldler is called from within the wpa_zip function */
|
581 |
wpa_zip($zipFileName, $folderToBeZipped, $zipmode);
|
582 |
$zipSize = filesize($zipFileName);
|
583 |
$wp_filesystem->delete( $folderToBeZipped, true );
|
584 |
return array($backupName . '.zip', $zipSize);
|
585 |
global $wpdb;
|
586 |
$wp_backup = "{$wpdb->prefix}wpclone";
|
587 |
$deleteRow = $wpdb->get_row("SELECT * FROM {$wp_backup} WHERE id = '{$nm}'");
|
588 |
$wpdb->query("DELETE FROM {$wp_backup} WHERE id = '{$nm}' ");
|
589 |
if (file_exists(WPCLONE_DIR_BACKUP . $deleteRow->backup_name)) unlink(WPCLONE_DIR_BACKUP . $deleteRow->backup_name) or die ('unable to delete backup file.');
|
590 |
return $deleteRow;
|
591 |
$kilobyte = 1024;
|
592 |
$megabyte = $kilobyte * 1024;
|
593 |
$gigabyte = $megabyte * 1024;
|
594 |
$terabyte = $gigabyte * 1024;
|
595 |
if (($bytes >= 0) && ($bytes < $kilobyte)) {
|
596 |
return $bytes . ' B';
|
597 |
} elseif (($bytes >= $kilobyte) && ($bytes < $megabyte)) {
|
598 |
return round($bytes / $kilobyte, $precision) . ' KB';
|
599 |
} elseif (($bytes >= $megabyte) && ($bytes < $gigabyte)) {
|
600 |
return round($bytes / $megabyte, $precision) . ' MB';
|
601 |
} elseif (($bytes >= $gigabyte) && ($bytes < $terabyte)) {
|
602 |
return round($bytes / $gigabyte, $precision) . ' GB';
|
603 |
} elseif ($bytes >= $terabyte) {
|
604 |
return round($bytes / $terabyte, $precision) . ' TB';
|
605 |
} else {
|
606 |
return $bytes . ' B';
|
607 |
}
|
608 |
$fileContent = file_get_contents($databaseFile, true);
|
609 |
$pos = strpos($fileContent, 'siteurl') + 8;
|
610 |
$urlStartPos = strpos($fileContent, '"', $pos) + 1;
|
611 |
$urlEndPos = strpos($fileContent, '"', $urlStartPos);
|
612 |
$backupSiteUrl = substr($fileContent, $urlStartPos, $urlEndPos - $urlStartPos);
|
613 |
return $backupSiteUrl;
|
614 |
|
615 |
$dbFileContent = file_get_contents($databaseFileInZip);
|
616 |
/* we don't want to nuke the curret database if if something went wrong with the above operation */
|
617 |
if ( false === $dbFileContent ) {
|
618 |
wpa_backup_error( 'dbrest', sprintf ( __( 'Cannot read <code>%s</code>' ), $databaseFileInZip ) , true );
|
619 |
}
|
620 |
|
621 |
|
622 |
$conn = mysql_connect( DB_HOST, DB_USER, DB_PASSWORD );
|
623 |
/* and we cannot nuke the db if the connection failed now can we */
|
624 |
if ( false === $conn ) {
|
625 |
wpa_backup_error('dbrest', __( 'database connection failed' ), true );
|
626 |
}
|
627 |
|
628 |
mysql_select_db( DB_NAME, $conn);
|
629 |
|
630 |
$query = mysql_query("SHOW TABLES", $conn);
|
631 |
/* point of no return,if it fails after this you're royally boned ;) */
|
632 |
while (($fetch = mysql_fetch_array($query))) {
|
633 |
mysql_query("Drop table `{$fetch[0]}`");
|
634 |
}
|
635 |
flush();
|
636 |
|
637 |
$res = explode(";\n", $dbFileContent);
|
638 |
foreach ($res AS $query) {
|
639 |
mysql_query($query, $conn);
|
640 |
}
|
641 |
mysql_close($conn);
|
642 |
$backupSiteUrl = replaceSiteUrlFromDatabaseFile($databaseFileInZip); /* don't let the name fool you,it just returns the old site's url */
|
643 |
$currentSiteUrl = site_url();
|
644 |
$backupSiteUrl = untrailingslashit($backupSiteUrl);
|
645 |
$currentSiteUrl = untrailingslashit($currentSiteUrl);
|
646 |
wpa_safe_replace_wrapper ( $backupSiteUrl, $currentSiteUrl );
|
647 |
|
648 |
return $currentSiteUrl;
|
649 |
* @param type $search URL of the previous site.
|
650 |
* @param type $replace URL of the current site.
|
651 |
* @return type total time it took for the operation.
|
652 |
*/
|
653 |
if ( !function_exists( 'icit_srdb_replacer' ) && !function_exists( 'recursive_unserialize_replace' ) ) {
|
654 |
require_once 'icit_srdb_replacer.php';
|
655 |
}
|
656 |
$connection = @mysql_connect( DB_HOST, DB_USER, DB_PASSWORD );
|
657 |
$all_tables = array( );
|
658 |
@mysql_select_db( DB_NAME, $connection );
|
659 |
$all_tables_mysql = @mysql_query( 'SHOW TABLES', $connection );
|
660 |
if ( ! $all_tables_mysql ) {
|
661 |
wpa_backup_error( 'dbrest', mysql_error(), true );
|
662 |
} else {
|
663 |
while ( $table = mysql_fetch_array( $all_tables_mysql ) ) {
|
664 |
$all_tables[] = $table[ 0 ];
|
665 |
}
|
666 |
}
|
667 |
$report = icit_srdb_replacer( $connection, $search, $replace, $all_tables );
|
668 |
return $report;
|
669 |
wpa_cleanup( true );
|
670 |
if (!is_string($url) || '' == $url) {
|
671 |
wpa_backup_error( 'restore', sprintf( __( 'The provided URL (<code>%s<code>) is either not valid or empty' ), $url ), true );
|
672 |
}
|
673 |
|
674 |
$pathParts = pathinfo($url);
|
675 |
$zipFilename = wpa_fetch_file($url);
|
676 |
$result = wpa_unzip($zipFilename, WPCLONE_WP_CONTENT, $zipmode);
|
677 |
if ($result) {
|
678 |
$unzippedFolderPath = wpCloneSafePathMode( trailingslashit( WPCLONE_WP_CONTENT ) . 'wpclone_backup' );
|
679 |
if ( !file_exists( $unzippedFolderPath ) ) {
|
680 |
$unzippedFolderPath = wpCloneSafePathMode( trailingslashit( WPCLONE_WP_CONTENT ) . $pathParts['filename'] );
|
681 |
}
|
682 |
|
683 |
/* if we're here then the file extraction worked,but let's make doubly sure */
|
684 |
if( !is_dir( $unzippedFolderPath ) ) {
|
685 |
wpa_backup_error( 'restore', sprintf( __( 'Cannot find <code>%s<code>' ), $unzippedFolderPath ), true );
|
686 |
}
|
687 |
/* check the table prefixes */
|
688 |
$old_db_prefix = $unzippedFolderPath . '/prefix.txt';
|
689 |
$prefix = wpa_check_prefix($old_db_prefix);
|
690 |
if ($prefix) {
|
691 |
wpa_replace_prefix( $prefix );
|
692 |
}
|
693 |
/* import db */
|
694 |
$databaseFile = $unzippedFolderPath . '/database.sql';
|
695 |
$currentSiteUrl = processConfigAndDatabaseFile($databaseFile);
|
696 |
/* */
|
697 |
wpa_copy( $unzippedFolderPath, WPCLONE_ROOT );
|
698 |
global $wp_filesystem;
|
699 |
$wp_filesystem->delete( $unzippedFolderPath, true );
|
700 |
/* remove the zip file only if it was downloaded from an external location. */
|
701 |
$wptmp = explode('.', $zipFilename);
|
702 |
if ( in_array( 'tmp', $wptmp ) ) {
|
703 |
$wp_filesystem->delete( $zipFilename );
|
704 |
}
|
705 |
echo "<h1>Restore Successful!</h1>";
|
706 |
echo "Visit your restored site [ <a href='{$currentSiteUrl}' target=blank>here</a> ]<br><br>";
|
707 |
echo "<strong>You may need to re-save your permalink structure <a href='{$currentSiteUrl}/wp-admin/options-permalink.php' target=blank>Here</a></strong>";
|
708 |
} else {
|
709 |
echo "<h1>Restore unsuccessful!!!</h1>";
|
710 |
echo "Please try again.";
|
711 |
}
|
712 |
global $wpdb;
|
713 |
$prefix = $wpdb->prefix;
|
714 |
$file = $path . '/prefix.txt';
|
715 |
if ( is_dir($path) && is_writable($path) ) {
|
716 |
file_put_contents($file, $prefix);
|
717 |
}
|
718 |
* Checks to see whether the destination site's table prefix matches that of the origin site.old prefix is returned in case of a mismatch.
|
719 |
*
|
720 |
* @param type $file path to the prefix.txt file.
|
721 |
* @return type bool string
|
722 |
*/
|
723 |
global $wpdb;
|
724 |
$prefix = $wpdb->prefix;
|
725 |
if (file_exists($file) && is_readable($file)) {
|
726 |
$old_prefix = file_get_contents($file);
|
727 |
if ( $prefix !== $old_prefix ) {
|
728 |
return $old_prefix;
|
729 |
}
|
730 |
else {
|
731 |
return false;
|
732 |
}
|
733 |
}
|
734 |
return false;
|
735 |
* @since 2.0.6
|
736 |
*
|
737 |
* @param type $zipfile path to the zip file that needs to be extracted.
|
738 |
* @param type $path the place to where the file needs to be extracted.
|
739 |
* @return as false in the event of failure.
|
740 |
*/
|
741 |
if ( $zipmode ) {
|
742 |
if ( ini_get('mbstring.func_overload') && function_exists('mb_internal_encoding') ) {
|
743 |
$previous_encoding = mb_internal_encoding();
|
744 |
mb_internal_encoding('ISO-8859-1');
|
745 |
}
|
746 |
define('PCLZIP_TEMPORARY_DIR', WPCLONE_DIR_BACKUP);
|
747 |
require_once ( ABSPATH . 'wp-admin/includes/class-pclzip.php' );
|
748 |
$z = new PclZip($zipfile);
|
749 |
$files = $z->extract(PCLZIP_OPT_PATH, $path);
|
750 |
if ( isset($previous_encoding) ) mb_internal_encoding($previous_encoding);
|
751 |
if ( $files == 0 ) {
|
752 |
wpa_backup_error( 'pclunzip', $z->errorInfo(true), true );
|
753 |
}
|
754 |
return true;
|
755 |
}
|
756 |
else {
|
757 |
$z= unzip_file($zipfile, $path);
|
758 |
if (is_wp_error($z)) {
|
759 |
wpa_backup_error( 'unzip', $z->get_error_message(), true );
|
760 |
}
|
761 |
return true;
|
762 |
}
|
763 |
* @since 2.0.6
|
764 |
*
|
765 |
* @param type $name name of the zip file.
|
766 |
* @param type $file_list an array of files that needs to be archived.
|
767 |
*/
|
768 |
if ( $zipmode || (!in_array('ZipArchive', get_declared_classes()) || !class_exists('ZipArchive')) ) {
|
769 |
define('PCLZIP_TEMPORARY_DIR', WPCLONE_DIR_BACKUP);
|
770 |
require_once ( ABSPATH . 'wp-admin/includes/class-pclzip.php');
|
771 |
$z = new PclZip($zip_name);
|
772 |
$v_list = $z->create($folder, PCLZIP_OPT_REMOVE_PATH, WPCLONE_DIR_BACKUP);
|
773 |
if ($v_list == 0) {
|
774 |
wpa_backup_error( 'pclzip', $z->errorInfo(true) );
|
775 |
}
|
776 |
} else {
|
777 |
$z = new ZipArchive();
|
778 |
if ( true !== $z->open( $zip_name, ZIPARCHIVE::CREATE ) ) {
|
779 |
wpa_backup_error( 'zip', $z );
|
780 |
}
|
781 |
wpa_ziparc($z, $folder, WPCLONE_DIR_BACKUP);
|
782 |
$z->close();
|
783 |
}
|
784 |
$new_folder = str_replace($base, '', $dir);
|
785 |
$zip->addEmptyDir($new_folder);
|
786 |
foreach( glob( $dir . '/*' ) as $file ){
|
787 |
if( is_dir($file) ) {
|
788 |
wpa_ziparc($zip, $file, $base);
|
789 |
} else {
|
790 |
$new_file = str_replace( $base, '', $file );
|
791 |
$zip->addFile($file, $new_file);
|
792 |
}
|
793 |
}
|
794 |
* just a simple function to increase PHP limits.
|
795 |
* @since 2.0.6
|
796 |
*/
|
797 |
$time = isset( $_POST['maxexec'] ) && '' != $_POST['maxexec'] ? $_POST['maxexec'] : 900;
|
798 |
$mem = isset ( $_POST['maxmem'] ) && '' != $_POST['maxmem'] ? $_POST['maxmem'] . 'M' : '512M';
|
799 |
@ini_set('memory_limit', $mem);
|
800 |
@ini_set('max_execution_time', $time); //900 seconds = 15 minutes
|
801 |
* @since 2.0.6
|
802 |
*/
|
803 |
if (!empty($_REQUEST['del'])) {
|
804 |
wpa_remove_backup();
|
805 |
return true;
|
806 |
}
|
807 |
if (empty($_POST)) return false;
|
808 |
check_admin_referer('wpclone-submit');
|
809 |
$form_post = wp_nonce_url('admin.php?page=wp-clone', 'wpclone-submit');
|
810 |
$extra_fields = array('restore_from_url', 'maxmem', 'maxexec', 'zipmode', 'restoreBackup');
|
811 |
$type = '';
|
812 |
if ( false === ($creds = request_filesystem_credentials($form_post, $type, false, false, $extra_fields)) ){
|
813 |
return true;
|
814 |
}
|
815 |
if (!WP_Filesystem($creds)) {
|
816 |
request_filesystem_credentials($form_post, $type, true, false, $extra_fields);
|
817 |
return true;
|
818 |
}
|
819 |
wpa_bump_limits();
|
820 |
|
821 |
if (isset($_POST['createBackup'])) {
|
822 |
wpa_create_backup();
|
823 |
return true;
|
824 |
}
|
825 |
|
826 |
$zipmode = isset($_POST['zipmode']) ? true : false;
|
827 |
$url = isset($_POST['restoreBackup']) ? $_POST['restoreBackup'] : $_POST['restore_from_url'];
|
828 |
processRestoringBackup($url, $zipmode);
|
829 |
return true;
|
830 |
* @since 2.0.6
|
831 |
*/
|
832 |
global $wp_filesystem;
|
833 |
if (is_readable($source)) {
|
834 |
if (is_dir($source)) {
|
835 |
if (!strstr(wpCloneSafePathMode($source), rtrim(WPCLONE_DIR_BACKUP, "/\\"))) {
|
836 |
if (!file_exists($target)) {
|
837 |
$wp_filesystem->mkdir($target);
|
838 |
}
|
839 |
$d = dir($source);
|
840 |
while (FALSE !== ($entry = $d->read())) {
|
841 |
if ($entry == '.' || $entry == '..') {
|
842 |
continue;
|
843 |
}
|
844 |
$Entry = "{$source}/{$entry}";
|
845 |
if (is_dir($Entry)) {
|
846 |
wpa_copy($Entry, $target . '/' . $entry);
|
847 |
} else {
|
848 |
$wp_filesystem->copy($Entry, $target . '/' . $entry, true, FS_CHMOD_FILE);
|
849 |
}
|
850 |
}
|
851 |
$d->close();
|
852 |
}
|
853 |
}
|
854 |
else {
|
855 |
$wp_filesystem->copy($source, $target, true);
|
856 |
}
|
857 |
}
|
858 |
* @since 2.0.6
|
859 |
*/
|
860 |
$wpconfig = wpa_wpconfig_path();
|
861 |
if ( ! is_writable($wpconfig) ) {
|
862 |
wpa_backup_error('wpconfig', sprintf( __( "<code>%s</code> is not writable." ), $wpconfig ), true );
|
863 |
}
|
864 |
|
865 |
global $wp_filesystem;
|
866 |
$fileContent = file_get_contents($wpconfig);
|
867 |
$pos = strpos($fileContent, '$table_prefix');
|
868 |
$str = substr($fileContent, $pos, strpos($fileContent, PHP_EOL, $pos) - $pos);
|
869 |
$fileContent = str_replace($str, '$table_prefix = "' . $newPrefix . '";', $fileContent);
|
870 |
$wp_filesystem->put_contents($wpconfig, $fileContent, 0600);
|
871 |
* @since 2.0.6
|
872 |
*/
|
873 |
wpa_cleanup();
|
874 |
$use_wpdb = isset( $_POST['use_wpdb'] ) && 'true' == $_POST['use_wpdb'] ? true : false;
|
875 |
$backupName = wpa_backup_name();
|
876 |
$zipmode = isset($_POST['zipmode']) ? true : false;
|
877 |
list($zipFileName, $zipSize) = CreateWPFullBackupZip($backupName, $zipmode, $use_wpdb);
|
878 |
wpa_insert_data($zipFileName, $zipSize);
|
879 |
$backZipPath = convertPathIntoUrl(WPCLONE_DIR_BACKUP . $zipFileName);
|
880 |
$zipSize = bytesToSize($zipSize);
|
881 |
echo <<<EOF
|
882 |
<a href='{$backZipPath}'><span>{$backZipPath}</span></a> ( {$zipSize} ) |
|
883 |
<input type='hidden' name='backupUrl' class='backupUrl' value="{$backZipPath}" />
|
884 |
<a class='copy-button' href='#' data-clipboard-text='{$backZipPath}'>Copy URL</a> <br /><br />
|
885 |
(Copy that link and paste it into the "Restore URL" of your new WordPress installation to clone this site)
|
886 |
* @since 2.0.6
|
887 |
*/
|
888 |
$deleteRow = DeleteWPBackupZip($_REQUEST['del']);
|
889 |
echo <<<EOT
|
890 |
<h1>Deleted Successful!</h1> <br />
|
891 |
{$deleteRow->backup_name} <br />
|
892 |
File deleted from backup folder and database...
|
893 |
* @since 2.1.2
|
894 |
* copypasta from wp-load.php
|
895 |
* @return the path to wp-config.php
|
896 |
*/
|
897 |
$z = pathinfo($path);
|
898 |
if (file_exists(WPCLONE_DIR_BACKUP . $z['basename'])) {
|
899 |
return WPCLONE_DIR_BACKUP . $z['basename'];
|
900 |
}
|
901 |
else {
|
902 |
$url = download_url($path, 750);
|
903 |
if ( is_wp_error($url) ) wpa_backup_error( 'url', $url->get_error_message(), true );
|
904 |
return $url;
|
905 |
}
|
906 |
$backup_name = 'wpclone_backup_' . date( 'dS_M_Y_h-iA' ) . '_' . get_option( 'blogname' );
|
907 |
$backup_name = substr( str_replace( ' ', '', $backup_name ), 0, 40 );
|
908 |
$rand_str = substr( str_shuffle( "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" ), 0, 10 );
|
909 |
$backup_name = sanitize_file_name( $backup_name ) . '_' . $rand_str;
|
910 |
return $backup_name;
|
911 |
|
912 |
$backup_dir = $restore ? trailingslashit( WPCLONE_WP_CONTENT ) . 'wpclone_backup' : trailingslashit( WPCLONE_DIR_BACKUP ) . 'wpclone_backup';
|
913 |
if( $restore ) {
|
914 |
$url = isset($_POST['restoreBackup']) ? $_POST['restoreBackup'] : $_POST['restore_from_url'];
|
915 |
if ( !file_exists( $backup_dir ) ) {
|
916 |
$path = pathinfo( $url );
|
917 |
$backup_dir = trailingslashit( WPCLONE_WP_CONTENT ) . $path['filename'];
|
918 |
}
|
919 |
if( !file_exists( $backup_dir ) ) {
|
920 |
unset( $backup_dir );
|
921 |
}
|
922 |
}
|
923 |
switch ( $error ) :
|
924 |
/* during backup */
|
925 |
case 'file' :
|
926 |
$error = __( 'while copying files into the temp directory' );
|
927 |
break;
|
928 |
case 'db' :
|
929 |
$error = __( 'during the database backup' );
|
930 |
break;
|
931 |
case 'zip' :
|
932 |
$error = __( 'while creating the zip file using PHP\'s ZipArchive library' );
|
933 |
break;
|
934 |
case 'pclzip' :
|
935 |
$error = __( 'while creating the zip file using the PclZip library' );
|
936 |
break;
|
937 |
/* during restore */
|
938 |
case 'filerest' :
|
939 |
$error = __( 'while copying files from the temp directory into the wp-content directory' );
|
940 |
break;
|
941 |
case 'dbrest' :
|
942 |
$error = __( 'while cloning the database' );
|
943 |
break;
|
944 |
case 'unzip' :
|
945 |
$error = __( 'while extracting the zip file using WP\'s zip file extractor' );
|
946 |
break;
|
947 |
case 'pclunzip' :
|
948 |
$error = __( 'while extracting the zip file using the PclZip library' );
|
949 |
break;
|
950 |
case 'url' :
|
951 |
$error = __( 'while downloading the zip file' );
|
952 |
break;
|
953 |
case 'wpconfig' :
|
954 |
$error = __( 'while trying to modify the table prefix in the wp-config.php file' );
|
955 |
break;
|
956 |
/* and a catch all for the things that aren't covered above */
|
957 |
default :
|
958 |
$error = sprintf( __( 'during the %s process' ), $error );
|
959 |
endswitch;
|
960 |
|
961 |
echo '<div class="wpclone_notice updated">';
|
962 |
printf( __( 'The plugin encountered an error %s,the following error message was returned:</br>' ), $error );
|
963 |
echo '<div class="error">' . __( 'Error Message : ' ) . $data . '</div></br>';
|
964 |
if( isset( $backup_dir) ) {
|
965 |
printf( __( 'Temporary files created in <code>%s</code> will be deleted.' ), $backup_dir );
|
966 |
echo '</div>';
|
967 |
global $wp_filesystem;
|
968 |
$wp_filesystem->delete($backup_dir, true);
|
969 |
} else {
|
970 |
echo '</div>';
|
971 |
}
|
972 |
die;
|
973 |
$backup_dir = $restore ? trailingslashit( WPCLONE_WP_CONTENT ) . 'wpclone_backup' : trailingslashit( WPCLONE_DIR_BACKUP ) . 'wpclone_backup';
|
974 |
if ( file_exists( $backup_dir ) && is_dir( $backup_dir ) ) {
|
975 |
global $wp_filesystem;
|
976 |
$wp_filesystem->delete($backup_dir, true);
|
977 |
}
|
|
|
1 |
$backupName = date('Y-m-d-H-i-s') . '_' . get_bloginfo('name', 'display');
|
2 |
$backupName = substr(str_replace(' ', '', $backupName), 0, 40);
|
3 |
$backupName = sanitize_file_name($backupName);
|
4 |
return $backupName;
|
5 |
return str_replace("\\", "/", $path);
|
6 |
return rtrim(str_replace("//", "/", wpCloneSafePathMode($path)), '/') . '/';
|
7 |
return str_replace(rtrim(WPCLONE_ROOT, "/\\"), site_url(), $path);
|
8 |
return str_replace(site_url(), rtrim(WPCLONE_ROOT, "/\\"), $url);
|
9 |
if (is_readable($source)) {
|
10 |
if (is_dir($source)) {
|
11 |
if (!strstr(wpCloneSafePathMode($source), rtrim(WPCLONE_DIR_BACKUP, "/\\"))) {
|
12 |
if (!file_exists($target)) {
|
13 |
mkdir($target, WPBACKUP_FILE_PERMISSION);
|
14 |
}
|
15 |
$d = dir($source);
|
16 |
while (FALSE !== ($entry = $d->read())) {
|
17 |
if ($entry == '.' || $entry == '..') {
|
18 |
continue;
|
19 |
}
|
20 |
$Entry = "{$source}/{$entry}";
|
21 |
if (is_dir($Entry)) {
|
22 |
wpBackupFullCopy($Entry, $target . '/' . $entry);
|
23 |
} else {
|
24 |
@ copy($Entry, $target . '/' . $entry);
|
25 |
}
|
26 |
}
|
27 |
$d->close();
|
28 |
}
|
29 |
} else {
|
30 |
copy($source, $target);
|
31 |
}
|
32 |
}
|
33 |
global $wpdb;
|
34 |
$WPCLONE_DB_ICONV_IN = "UTF-8";
|
35 |
$WPCLONE_DB_ICONV_OUT = "ISO-8859-1//TRANSLIT";
|
36 |
$return = '';
|
37 |
// Get all of the tables
|
38 |
$tables = $wpdb->get_col('SHOW TABLES');
|
39 |
// Cycle through each provided table
|
40 |
foreach ($tables as $table) {
|
41 |
// First part of the output � remove the table
|
42 |
$result = $wpdb->get_results("SELECT * FROM {$table}", ARRAY_N);
|
43 |
$numberOfFields = count($result[0]);
|
44 |
$numberOfItems = count($result);
|
45 |
// Second part of the output � create table
|
46 |
$row2 = $wpdb->get_row("SHOW CREATE TABLE {$table}", ARRAY_N);
|
47 |
$return .= "\n\n" . $row2[1] . ";\n\n";
|
48 |
// Third part of the output � insert values into new table
|
49 |
for ($currentRowNumber = 0; $currentRowNumber < $numberOfItems; $currentRowNumber++) {
|
50 |
$row = $result[$currentRowNumber];
|
51 |
$query = "INSERT INTO {$table} VALUES(";
|
52 |
for ($j = 0; $j < $numberOfFields; $j++) {
|
53 |
$row[$j] = iconv($WPCLONE_DB_ICONV_IN, $WPCLONE_DB_ICONV_OUT, $row[$j]);
|
54 |
$query .= (empty($row[$j])) ? '"", ' : '"' . mysql_real_escape_string($row[$j]) . '", ';
|
55 |
}
|
56 |
$return .= substr($query, 0, -2) . ");\n";
|
57 |
}
|
58 |
$return .= "\n";
|
59 |
}
|
60 |
// Generate the filename for the sql file
|
61 |
$File_open = fopen($destination . '/database.sql', 'w+');
|
62 |
// Save the sql file
|
63 |
fwrite($File_open, $return);
|
64 |
//file close
|
65 |
fclose($File_open);
|
66 |
$wpdb->flush();
|
67 |
global $wpdb;
|
68 |
global $current_user;
|
69 |
$wpdb->insert($wpdb->prefix . "wpclone", array(
|
70 |
'backup_name' => $name,
|
71 |
'data_time' => current_time('mysql', get_option('gmt_offset')),
|
72 |
'creator' => $current_user->user_login,
|
73 |
'backup_size' => $size)
|
74 |
);
|
75 |
$wpdb->flush;
|
76 |
$folderToBeZipped = WPCLONE_DIR_BACKUP . $backupName;
|
77 |
$destinationPath = $folderToBeZipped . '/' . basename(WPCLONE_WP_CONTENT);
|
78 |
$zipFileName = $backupName . '.zip';
|
79 |
DirectoryTree::createDirectory($destinationPath);
|
80 |
wpBackupFullCopy(rtrim(WPCLONE_WP_CONTENT, "/\\"), $destinationPath);
|
81 |
wpa_save_prefix($folderToBeZipped);
|
82 |
dw_backup_tables(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME, $folderToBeZipped);
|
83 |
wpa_zip("{$folderToBeZipped}.zip", $folderToBeZipped, $zipmode);
|
84 |
$zipSize = filesize("{$folderToBeZipped}.zip");
|
85 |
DirectoryTree::DeleteAllDirectoryFiles($folderToBeZipped, true);
|
86 |
return array($zipFileName, $zipSize);
|
87 |
$backupDirectory = rtrim(WPCLONE_DIR_BACKUP, "/\\");
|
88 |
$key = array_search($backupDirectory, $directoryFiles);
|
89 |
if ($directoryFiles[$key] === $backupDirectory) {
|
90 |
unset($directoryFiles[$key]);
|
91 |
}
|
92 |
$destinationPath = WPCLONE_DIR_BACKUP . $backupName;
|
93 |
$zipFileName = $backupName . '.zip';
|
94 |
mkdir($destinationPath, WPBACKUP_FILE_PERMISSION);
|
95 |
foreach($directoryFiles AS $directoryFolder) {
|
96 |
$destinationFolder = str_replace(rtrim(WPCLONE_ROOT, "/\\"), $destinationPath, $directoryFolder);
|
97 |
wpBackupFullCopy($directoryFolder, $destinationFolder);
|
98 |
}
|
99 |
CreateDb($destinationPath);
|
100 |
wpa_zip("{$destinationPath}.zip", $destinationPath);
|
101 |
$zipSize = filesize("{$destinationPath}.zip");
|
102 |
DirectoryTree::DeleteAllDirectoryFiles($destinationPath, true);
|
103 |
return array($zipFileName, $zipSize);
|
104 |
$installerBackupFile = "{$backupName}_wpclone";
|
105 |
$installerBackupPath = WPCLONE_DIR_BACKUP . $installerBackupFile;
|
106 |
$installerBackupFileZip = $installerBackupFile . '.zip';
|
107 |
wpBackupFullCopy(rtrim(WPCLONE_INSTALLER_PATH, "/\\"), $installerBackupPath);
|
108 |
$editBackupFilePath = $installerBackupPath . "/lib/file";
|
109 |
$backupZipPath = convertPathIntoUrl(WPCLONE_DIR_BACKUP . $zipFileName);
|
110 |
if (file_exists($editBackupFilePath)) {
|
111 |
$search = 'class="Url" value=""';
|
112 |
$replace = 'class="Url" value="' . $backupZipPath . '"';
|
113 |
chdir($editBackupFilePath);
|
114 |
DirectoryTree::openFileSearchAndReplace($editBackupFilePath, $search, $replace);
|
115 |
!file_exists($installerBackupPath . '/lib/view.php') || unlink($installerBackupPath . '/lib/view.php');
|
116 |
$copyFrom = $editBackupFilePath . '/view.php';
|
117 |
$copyTo = $installerBackupPath . '/lib/view.php';
|
118 |
DirectoryTree::CopyDirectory($copyFrom, $copyTo);
|
119 |
}
|
120 |
new WPbackupZip("{$installerBackupPath}.zip", $installerBackupPath, '.svn');
|
121 |
DirectoryTree::DeleteAllDirectoryFiles($installerBackupPath, true);
|
122 |
return $installerBackupFileZip;
|
123 |
|
124 |
$zipFileObject = new ZipArchive;
|
125 |
$response = true;
|
126 |
|
127 |
|
128 |
if ( $zipFileObject->open($zipFilename) === TRUE ) {
|
129 |
|
130 |
$zipFileObject->extractTo($destinationFolder);
|
131 |
/* Remove htaccess file from directory. */
|
132 |
$folder = pathinfo($zipFilename, PATHINFO_FILENAME);
|
133 |
$htaccess = wpCloneSafePathMode($destinationFolder . $folder) . '/.htaccess';
|
134 |
!(file_exists($htaccess)) || unlink($htaccess);
|
135 |
|
136 |
}
|
137 |
else {
|
138 |
$response = false;
|
139 |
}
|
140 |
unset($zipFileObject);
|
141 |
return $response;
|
142 |
global $wpdb;
|
143 |
$wp_backup = "{$wpdb->prefix}wpclone";
|
144 |
$deleteRow = $wpdb->get_row("SELECT * FROM {$wp_backup} WHERE id = '{$nm}'");
|
145 |
$wpdb->query("DELETE FROM {$wp_backup} WHERE id = '{$nm}' ");
|
146 |
if (file_exists(WPCLONE_DIR_BACKUP . $deleteRow->backup_name)) unlink(WPCLONE_DIR_BACKUP . $deleteRow->backup_name) or die ('unable to delete backup file.');
|
147 |
if (file_exists(WPCLONE_DIR_BACKUP . $deleteRow->installer_name)) @unlink(WPCLONE_DIR_BACKUP . $deleteRow->installer_name);
|
148 |
return $deleteRow;
|
149 |
$kilobyte = 1024;
|
150 |
$megabyte = $kilobyte * 1024;
|
151 |
$gigabyte = $megabyte * 1024;
|
152 |
$terabyte = $gigabyte * 1024;
|
153 |
if (($bytes >= 0) && ($bytes < $kilobyte)) {
|
154 |
return $bytes . ' B';
|
155 |
} elseif (($bytes >= $kilobyte) && ($bytes < $megabyte)) {
|
156 |
return round($bytes / $kilobyte, $precision) . ' KB';
|
157 |
} elseif (($bytes >= $megabyte) && ($bytes < $gigabyte)) {
|
158 |
return round($bytes / $megabyte, $precision) . ' MB';
|
159 |
} elseif (($bytes >= $gigabyte) && ($bytes < $terabyte)) {
|
160 |
return round($bytes / $gigabyte, $precision) . ' GB';
|
161 |
} elseif ($bytes >= $terabyte) {
|
162 |
return round($bytes / $terabyte, $precision) . ' TB';
|
163 |
} else {
|
164 |
return $bytes . ' B';
|
165 |
}
|
166 |
$ext = strrchr($name, '.');
|
167 |
if ($ext !== false) {
|
168 |
$name = substr($name, 0, -strlen($ext));
|
169 |
}
|
170 |
return $name;
|
171 |
function file_put_contents($filename, $data)
|
172 |
{
|
173 |
$f = @fopen($filename, 'w');
|
174 |
if (!$f) {
|
175 |
return false;
|
176 |
} else {
|
177 |
$bytes = fwrite($f, $data);
|
178 |
fclose($f);
|
179 |
return $bytes;
|
180 |
}
|
181 |
}
|
182 |
*
|
183 |
* @param string $filename
|
184 |
* @return string
|
185 |
*/
|
186 |
if (!function_exists('file_get_contents')) {
|
187 |
$handle = fopen($filename, "r");
|
188 |
$contents = fread($handle, filesize($filename));
|
189 |
fclose($handle);
|
190 |
} else {
|
191 |
$contents = file_get_contents($filename);
|
192 |
}
|
193 |
return $contents;
|
194 |
$dbInfo = array();
|
195 |
$dbInfo["dbhost"] = DB_HOST;
|
196 |
$dbInfo["dbname"] = DB_NAME;
|
197 |
$dbInfo["dbuser"] = DB_USER;
|
198 |
$dbInfo["dbpassword"] = DB_PASSWORD;
|
199 |
return $dbInfo;
|
200 |
$selectQuery = "SELECT COUNT(*) AS number_of_tables
|
201 |
FROM information_schema.tables
|
202 |
WHERE table_schema = '{$databaseName}'";
|
203 |
$numOfTables = mysql_query($selectQuery, $dbConn);
|
204 |
$numOfTables = mysql_fetch_assoc($numOfTables);
|
205 |
return $numOfTables;
|
206 |
$backupFileVariables = getVariablesFromFile($configInZipFile);
|
207 |
$backupPrefix = $backupFileVariables["table_prefix"];
|
208 |
replaceTablePrefix($currentConfigFile, $backupPrefix);
|
209 |
return $backupPrefix;
|
210 |
ob_start();
|
211 |
include($filename);
|
212 |
ob_end_clean();
|
213 |
return get_defined_vars();
|
214 |
$fileContent = file_get_contents($filename);
|
215 |
$pos = strpos($fileContent, '$table_prefix');
|
216 |
$str = substr($fileContent, $pos, strpos($fileContent, PHP_EOL, $pos) - $pos);
|
217 |
$fileContent = str_replace($str, '$table_prefix = "' . $newPrefix . '";', $fileContent);
|
218 |
file_put_contents($filename, $fileContent);
|
219 |
$fileContent = file_get_contents($databaseFile, true);
|
220 |
$pos = strpos($fileContent, 'siteurl') + 8;
|
221 |
$urlStartPos = strpos($fileContent, '"', $pos) + 1;
|
222 |
$urlEndPos = strpos($fileContent, '"', $urlStartPos);
|
223 |
$backupSiteUrl = substr($fileContent, $urlStartPos, $urlEndPos - $urlStartPos);
|
224 |
return $backupSiteUrl;
|
225 |
/* Replacing backup site url with the current one. */
|
226 |
$backupSiteUrl = replaceSiteUrlFromDatabaseFile($databaseFileInZip);
|
227 |
$currentSiteUrl = site_url();
|
228 |
$backupSiteUrl = wpa_trailing_slash_check($backupSiteUrl);
|
229 |
$currentSiteUrl = wpa_trailing_slash_check($currentSiteUrl);
|
230 |
$dbInfo = getDbInfo();
|
231 |
$conn = mysql_connect($dbInfo['dbhost'], $dbInfo['dbuser'], $dbInfo['dbpassword']);
|
232 |
mysql_select_db($dbInfo['dbname'], $conn) or die(mysql_error());
|
233 |
$query = mysql_query("SHOW TABLES", $conn);
|
234 |
while (($fetch = mysql_fetch_array($query))) {
|
235 |
mysql_query("Drop table `{$fetch[0]}`") or die(mysql_error() . '<br> Acess denied');
|
236 |
}
|
237 |
$dbFileContent = file_get_contents($databaseFileInZip);
|
238 |
$res = explode(";\n", $dbFileContent);
|
239 |
flush();
|
240 |
foreach ($res AS $query) {
|
241 |
mysql_query($query, $conn);
|
242 |
}
|
243 |
wpa_safe_replace_wrapper ( $dbInfo['dbhost'], $dbInfo['dbuser'], $dbInfo['dbpassword'], $dbInfo['dbname'], $backupSiteUrl, $currentSiteUrl );
|
244 |
mysql_close($conn);
|
245 |
return $currentSiteUrl;
|
246 |
*
|
247 |
* @param type $host mysql host name,already defined in wp-config.php as DB_HOST.
|
248 |
* @param type $user mysql username, "" DB_USER.
|
249 |
* @param type $pass mysql password, "" DB_PASSWORD.
|
250 |
* @param type $data mysql database name, "" DB_NAME.
|
251 |
* @param type $search URL of the previous site.
|
252 |
* @param type $replace URL of the current site.
|
253 |
* @return type total time it took for the operation.
|
254 |
*/
|
255 |
$connection = @mysql_connect( $host, $user, $pass );
|
256 |
$all_tables = array( );
|
257 |
@mysql_select_db( $data, $connection );
|
258 |
$all_tables_mysql = @mysql_query( 'SHOW TABLES', $connection );
|
259 |
if ( ! $all_tables_mysql ) {
|
260 |
$errors[] = mysql_error( );
|
261 |
} else {
|
262 |
while ( $table = mysql_fetch_array( $all_tables_mysql ) ) {
|
263 |
$all_tables[] = $table[ 0 ];
|
264 |
}
|
265 |
}
|
266 |
$report = icit_srdb_replacer( $connection, $search, $replace, $all_tables );
|
267 |
return $report;
|
268 |
* Take a serialised array and unserialise it replacing elements as needed and
|
269 |
* unserialising any subordinate arrays and performing the replace on those too.
|
270 |
*
|
271 |
* @param string $from String we're looking to replace.
|
272 |
* @param string $to What we want it to be replaced with
|
273 |
* @param array $data Used to pass any subordinate arrays back to in.
|
274 |
* @param bool $serialised Does the array passed via $data need serialising.
|
275 |
*
|
276 |
* @return array The original array with all elements replaced as needed.
|
277 |
*/
|
278 |
* The main loop triggered in step 5. Up here to keep it out of the way of the
|
279 |
* HTML. This walks every table in the db that was selected in step 3 and then
|
280 |
* walks every row and column replacing all occurences of a string with another.
|
281 |
* We split large tables into 50,000 row blocks when dealing with them to save
|
282 |
* on memmory consumption.
|
283 |
*
|
284 |
* @param mysql $connection The db connection object
|
285 |
* @param string $search What we want to replace
|
286 |
* @param string $replace What we want to replace it with.
|
287 |
* @param array $tables The tables we want to look at.
|
288 |
*
|
289 |
* @return array Collection of information gathered during the run.
|
290 |
*/
|
291 |
if (!is_string($url) || '' == $url) die('The provided path is not valid,aborting..');
|
292 |
|
293 |
$pathParts = pathinfo($url);
|
294 |
$urlDir = WPCLONE_DIR_BACKUP . 'url/';
|
295 |
file_exists($urlDir) || mkdir($urlDir, WPBACKUP_FILE_PERMISSION);
|
296 |
|
297 |
/* Copy the file found from url to plugin root */
|
298 |
$zipFilename = $urlDir . $pathParts['basename'];
|
299 |
DirectoryTree::CopyDirectory($url, $zipFilename);
|
300 |
$result = wpa_unzip($zipFilename, WPCLONE_ROOT, $zipmode);
|
301 |
if ($result) {
|
302 |
$unzippedFolderPath = wpCloneSafePathMode(WPCLONE_ROOT . $pathParts['filename']);
|
303 |
$old_db_prefix = $unzippedFolderPath . '/prefix.txt';
|
304 |
$prefix = wpa_check_prefix($old_db_prefix);
|
305 |
$databaseFile = $unzippedFolderPath . '/database.sql';
|
306 |
if ($prefix) {
|
307 |
wpa_replace_prefix( ABSPATH . 'wp-config.php', $prefix );
|
308 |
}
|
309 |
|
310 |
$currentSiteUrl = processConfigAndDatabaseFile($databaseFile);
|
311 |
!file_exists($databaseFile) || unlink($databaseFile);
|
312 |
!file_exists($old_db_prefix) || unlink($old_db_prefix);
|
313 |
!file_exists($unzippedFolderPath . '/wp-config.php') || unlink($unzippedFolderPath . '/wp-config.php');
|
314 |
wpa_copy($unzippedFolderPath, WPCLONE_ROOT);
|
315 |
DirectoryTree::DeleteAllDirectoryFiles($unzippedFolderPath, true);
|
316 |
echo "<h1>Restore Successful!</h1>";
|
317 |
echo "Visit your restored site [ <a href='{$currentSiteUrl}' target=blank>here</a> ]<br><br>";
|
318 |
echo "<strong>You may need to re-save your permalink structure <a href='{$currentSiteUrl}/wp-admin/options-permalink.php' target=blank>Here</a></strong>";
|
319 |
} else {
|
320 |
echo "<h1>Restore unsuccessful!!!</h1>";
|
321 |
echo "Please try again.";
|
322 |
}
|
323 |
!file_exists($urlDir) || DirectoryTree::DeleteAllDirectoryFiles($urlDir, true);
|
324 |
global $wpdb;
|
325 |
$prefix = $wpdb->prefix;
|
326 |
$file = $path . '/prefix.txt';
|
327 |
if ( is_dir($path) && is_writable($path) ) {
|
328 |
file_put_contents($file, $prefix);
|
329 |
}
|
330 |
* Checks to see whether the current destination site's table prefix matches that of the origin site.old prefix is returned in case of a mismatch.
|
331 |
*
|
332 |
* @param type $file path to the prefix.txt file.
|
333 |
* @return type bool string
|
334 |
*/
|
335 |
global $wpdb;
|
336 |
$prefix = $wpdb->prefix;
|
337 |
if (file_exists($file) && is_readable($file)) {
|
338 |
$old_prefix = file_get_contents($file);
|
339 |
if ( $prefix !== $old_prefix ) {
|
340 |
return $old_prefix;
|
341 |
}
|
342 |
else {
|
343 |
return false;
|
344 |
}
|
345 |
}
|
346 |
return false;
|
347 |
* checks for a trailing slash at the end of the provided URL and strips it if found.
|
348 |
* @param type $url
|
349 |
* @return type
|
350 |
*/
|
351 |
if (substr($url, -1) == "/" ) {
|
352 |
$url = rtrim($url, "/");
|
353 |
return $url;
|
354 |
}
|
355 |
else {
|
356 |
return $url;
|
357 |
}
|
358 |
* @link http://davidwalsh.name/backup-mysql-database-php
|
359 |
*
|
360 |
* @param type $host
|
361 |
* @param type $user
|
362 |
* @param type $pass
|
363 |
* @param type $name
|
364 |
* @param type $tables
|
365 |
*/
|
366 |
* @since 2.0.6
|
367 |
*
|
368 |
* @param type $zipfile path to the zip file that needs to be extracted.
|
369 |
* @param type $path the place to where the file needs to be extracted.
|
370 |
* @return as false in the event of failure.
|
371 |
*/
|
372 |
if ( $zipmode || (!in_array('ZipArchive', get_declared_classes()) || !class_exists('ZipArchive')) ) {
|
373 |
define('PCLZIP_TEMPORARY_DIR', WPCLONE_DIR_BACKUP);
|
374 |
require_once ( ABSPATH . 'wp-admin/includes/class-pclzip.php' );
|
375 |
$z = new PclZip($zipfile);
|
376 |
if ($z->extract(PCLZIP_OPT_PATH, $path) == 0) {
|
377 |
return false;
|
378 |
}
|
379 |
echo 'PclZip';
|
380 |
return true;
|
381 |
}
|
382 |
else {
|
383 |
$r = unzipBackupFile($zipfile, $path);
|
384 |
return $r;
|
385 |
}
|
386 |
* @since 2.0.6
|
387 |
*
|
388 |
* @param type $name name of the zip file.
|
389 |
* @param type $file_list an array of files that needs to be archived.
|
390 |
*/
|
391 |
if ( $zipmode || (!in_array('ZipArchive', get_declared_classes()) || !class_exists('ZipArchive')) ) {
|
392 |
define('PCLZIP_TEMPORARY_DIR', WPCLONE_DIR_BACKUP);
|
393 |
require_once ( ABSPATH . 'wp-admin/includes/class-pclzip.php');
|
394 |
$z = new PclZip($name);
|
395 |
$v_list = $z->create($file_list, PCLZIP_OPT_REMOVE_PATH, WPCLONE_DIR_BACKUP);
|
396 |
if ($v_list == 0) {
|
397 |
die("Error : ".$z->errorInfo(true));
|
398 |
}
|
399 |
}
|
400 |
else {
|
401 |
new WPbackupZip($name, $file_list, '.svn');
|
402 |
}
|
403 |
* just a simple function to increase PHP limits.
|
404 |
* @since 2.0.6
|
405 |
*/
|
406 |
$time = isset($time) && $time != '' ? $time : 900;
|
407 |
$mem = isset ($mem) && $mem != '' ? $mem . 'M' : '512M';
|
408 |
@ini_set('memory_limit', $mem);
|
409 |
@ini_set('max_execution_time', $time); //900 seconds = 15 minutes
|
410 |
* @since 2.0.6
|
411 |
*/
|
412 |
if (!empty($_REQUEST['del'])) {
|
413 |
wpa_remove_backup();
|
414 |
return true;
|
415 |
}
|
416 |
if (isset($_POST['createBackup'])) {
|
417 |
wpa_create_backup();
|
418 |
return true;
|
419 |
}
|
420 |
if (empty($_POST)) return false;
|
421 |
check_admin_referer('wpclone-submit');
|
422 |
$form_post = wp_nonce_url('admin.php?page=wp-clone', 'wpclone-submit');
|
423 |
$extra_fields = array('restore_from_url', 'maxmem', 'maxexec', 'zipmode', 'restoreBackup');
|
424 |
$type = '';
|
425 |
if ( false === ($creds = request_filesystem_credentials($form_post, $type, false, false, $extra_fields)) ){
|
426 |
return true;
|
427 |
}
|
428 |
if (!WP_Filesystem($creds)) {
|
429 |
request_filesystem_credentials($form_post, $type, true, false, $extra_fields);
|
430 |
return true;
|
431 |
}
|
432 |
wpa_bump_limits($_POST['maxmem'], $_POST['maxexec']);
|
433 |
$url = isset($_POST['restoreBackup']) ? $_POST['restoreBackup'] : $_POST['restore_from_url'];
|
434 |
$zipmode = isset($_POST['zipmode']) ? true : false;
|
435 |
processRestoringBackup($url, $zipmode);
|
436 |
return true;
|
437 |
* @since 2.0.6
|
438 |
*/
|
439 |
global $wp_filesystem;
|
440 |
if (is_readable($source)) {
|
441 |
if (is_dir($source)) {
|
442 |
if (!strstr(wpCloneSafePathMode($source), rtrim(WPCLONE_DIR_BACKUP, "/\\"))) {
|
443 |
if (!file_exists($target)) {
|
444 |
$wp_filesystem->mkdir($target);
|
445 |
}
|
446 |
$d = dir($source);
|
447 |
while (FALSE !== ($entry = $d->read())) {
|
448 |
if ($entry == '.' || $entry == '..') {
|
449 |
continue;
|
450 |
}
|
451 |
$Entry = "{$source}/{$entry}";
|
452 |
if (is_dir($Entry)) {
|
453 |
wpa_copy($Entry, $target . '/' . $entry);
|
454 |
} else {
|
455 |
$wp_filesystem->copy($Entry, $target . '/' . $entry, true, FS_CHMOD_FILE);
|
456 |
}
|
457 |
}
|
458 |
$d->close();
|
459 |
}
|
460 |
}
|
461 |
else {
|
462 |
$wp_filesystem->copy($source, $target, true);
|
463 |
}
|
464 |
}
|
465 |
* @since 2.0.6
|
466 |
*/
|
467 |
if (!is_writable($filename)) die ("Unable to modify wp-config.php,please change the permissions to '0600'.Aborting..");
|
468 |
global $wp_filesystem;
|
469 |
$fileContent = file_get_contents($filename);
|
470 |
$pos = strpos($fileContent, '$table_prefix');
|
471 |
$str = substr($fileContent, $pos, strpos($fileContent, PHP_EOL, $pos) - $pos);
|
472 |
$fileContent = str_replace($str, '$table_prefix = "' . $newPrefix . '";', $fileContent);
|
473 |
$wp_filesystem->put_contents($filename, $fileContent, 0600);
|
474 |
* @since 2.0.6
|
475 |
*/
|
476 |
check_admin_referer('wpclone-submit');
|
477 |
get_currentuserinfo();
|
478 |
wpa_bump_limits($_POST['maxmem'], $_POST['maxexec']);
|
479 |
$backupName = getBackupFileName();
|
480 |
$zipmode = isset($_POST['zipmode']) ? true : false;
|
481 |
list($zipFileName, $zipSize) = CreateWPFullBackupZip($backupName, $zipmode);
|
482 |
InsertData($zipFileName, $zipSize);
|
483 |
$backZipPath = convertPathIntoUrl(WPCLONE_DIR_BACKUP . $zipFileName);
|
484 |
$zipSize = bytesToSize($zipSize);
|
485 |
echo <<<EOF
|
486 |
<a href='{$backZipPath}'><span>{$backZipPath}</span></a> ( {$zipSize} ) |
|
487 |
<input type='hidden' name='backupUrl' class='backupUrl' value="{$backZipPath}" />
|
488 |
<a class='copy-button' href='#'>Copy URL</a> <br /><br />
|
489 |
(Copy that link and paste it into the "Restore URL" of your new WordPress installation to clone this site)
|
490 |
* @since 2.0.6
|
491 |
*/
|
492 |
$deleteRow = DeleteWPBackupZip($_REQUEST['del']);
|
493 |
echo <<<EOT
|
494 |
<h1>Deleted Successful!</h1> <br />
|
495 |
{$deleteRow->backup_name} <br />
|
496 |
File deleted from backup folder and database...
|
497 |
+
<?php
|
498 |
return str_replace("\\", "/", $path);
|
499 |
return rtrim(str_replace("//", "/", wpCloneSafePathMode($path)), '/') . '/';
|
500 |
return str_replace(rtrim(WPCLONE_ROOT, "/\\"), site_url(), $path);
|
501 |
return str_replace(site_url(), rtrim(WPCLONE_ROOT, "/\\"), $url);
|
502 |
global $wpdb;
|
503 |
$WPCLONE_DB_ICONV_IN = "UTF-8";
|
504 |
$WPCLONE_DB_ICONV_OUT = "ISO-8859-1//TRANSLIT";
|
505 |
$return = '';
|
506 |
// Get all of the tables
|
507 |
$tables = $wpdb->get_col('SHOW TABLES');
|
508 |
// Cycle through each provided table
|
509 |
foreach ($tables as $table) {
|
510 |
// First part of the output � remove the table
|
511 |
$result = $wpdb->get_results("SELECT * FROM {$table}", ARRAY_N);
|
512 |
$numberOfFields = count($result[0]);
|
513 |
$numberOfItems = count($result);
|
514 |
// Second part of the output � create table
|
515 |
$row2 = $wpdb->get_row("SHOW CREATE TABLE {$table}", ARRAY_N);
|
516 |
$return .= "\n\n" . $row2[1] . ";\n\n";
|
517 |
// Third part of the output � insert values into new table
|
518 |
for ($currentRowNumber = 0; $currentRowNumber < $numberOfItems; $currentRowNumber++) {
|
519 |
$row = $result[$currentRowNumber];
|
520 |
$query = "INSERT INTO {$table} VALUES(";
|
521 |
for ($j = 0; $j < $numberOfFields; $j++) {
|
522 |
$row[$j] = iconv($WPCLONE_DB_ICONV_IN, $WPCLONE_DB_ICONV_OUT, $row[$j]);
|
523 |
$query .= (empty($row[$j])) ? '"", ' : '"' . mysql_real_escape_string($row[$j]) . '", ';
|
524 |
}
|
525 |
$return .= substr($query, 0, -2) . ");\n";
|
526 |
}
|
527 |
$return .= "\n";
|
528 |
}
|
529 |
// Generate the filename for the sql file
|
530 |
$File_open = fopen($destination . '/database.sql', 'w+');
|
531 |
// Save the sql file
|
532 |
fwrite($File_open, $return);
|
533 |
//file close
|
534 |
fclose($File_open);
|
535 |
$wpdb->flush();
|
536 |
* @link http://davidwalsh.name/backup-mysql-database-php
|
537 |
*/
|
538 |
if ( false === $link ) {
|
539 |
wpa_backup_error('db', mysql_error() );
|
540 |
}
|
541 |
if ( false === $result ) {
|
542 |
wpa_backup_error('db', mysql_error() );
|
543 |
}
|
544 |
if ( false === $result ) {
|
545 |
wpa_backup_error('db', mysql_error() );
|
546 |
}
|
547 |
global $wpdb;
|
548 |
global $current_user;
|
549 |
$wpdb->insert($wpdb->prefix . "wpclone", array(
|
550 |
'backup_name' => $name,
|
551 |
'data_time' => current_time('mysql', get_option('gmt_offset')),
|
552 |
'creator' => $current_user->user_login,
|
553 |
'backup_size' => $size)
|
554 |
);
|
555 |
$wpdb->flush();
|
556 |
$folderToBeZipped = WPCLONE_DIR_BACKUP . 'wpclone_backup';
|
557 |
$destinationPath = $folderToBeZipped . '/' . basename(WPCLONE_WP_CONTENT);
|
558 |
$zipFileName = WPCLONE_DIR_BACKUP . $backupName . '.zip';
|
559 |
global $wp_filesystem;
|
560 |
|
561 |
/* create the backup directory and call the cleanup function if it failed to do so */
|
562 |
$dir = $wp_filesystem->mkdir( $folderToBeZipped );
|
563 |
if( is_wp_error($dir) ) {
|
564 |
wpa_backup_error ( 'file', $dir->get_error_message() . $folderToBeZipped );
|
565 |
}
|
566 |
/* copy wp-content directory into the newly created backup directory. call the cleanup function if it fails.
|
567 |
* (wpa_copy doesn't return anything at the moment)*/
|
568 |
$files = wpa_copy(WPCLONE_WP_CONTENT, $destinationPath);
|
569 |
if( is_wp_error($files) ) {
|
570 |
wpa_backup_error ( 'file', $files->get_error_message() );
|
571 |
}
|
572 |
wpa_save_prefix($folderToBeZipped);
|
573 |
/* error handler is called from within the db backup functions */
|
574 |
if ( $use_wpdb ) {
|
575 |
wpa_db_backup_wpdb( $folderToBeZipped );
|
576 |
} else {
|
577 |
wpa_db_backup_direct( $folderToBeZipped );
|
578 |
}
|
579 |
|
580 |
/* error haldler is called from within the wpa_zip function */
|
581 |
wpa_zip($zipFileName, $folderToBeZipped, $zipmode);
|
582 |
$zipSize = filesize($zipFileName);
|
583 |
$wp_filesystem->delete( $folderToBeZipped, true );
|
584 |
return array($backupName . '.zip', $zipSize);
|
585 |
global $wpdb;
|
586 |
$wp_backup = "{$wpdb->prefix}wpclone";
|
587 |
$deleteRow = $wpdb->get_row("SELECT * FROM {$wp_backup} WHERE id = '{$nm}'");
|
588 |
$wpdb->query("DELETE FROM {$wp_backup} WHERE id = '{$nm}' ");
|
589 |
if (file_exists(WPCLONE_DIR_BACKUP . $deleteRow->backup_name)) unlink(WPCLONE_DIR_BACKUP . $deleteRow->backup_name) or die ('unable to delete backup file.');
|
590 |
return $deleteRow;
|
591 |
$kilobyte = 1024;
|
592 |
$megabyte = $kilobyte * 1024;
|
593 |
$gigabyte = $megabyte * 1024;
|
594 |
$terabyte = $gigabyte * 1024;
|
595 |
if (($bytes >= 0) && ($bytes < $kilobyte)) {
|
596 |
return $bytes . ' B';
|
597 |
} elseif (($bytes >= $kilobyte) && ($bytes < $megabyte)) {
|
598 |
return round($bytes / $kilobyte, $precision) . ' KB';
|
599 |
} elseif (($bytes >= $megabyte) && ($bytes < $gigabyte)) {
|
600 |
return round($bytes / $megabyte, $precision) . ' MB';
|
601 |
} elseif (($bytes >= $gigabyte) && ($bytes < $terabyte)) {
|
602 |
return round($bytes / $gigabyte, $precision) . ' GB';
|
603 |
} elseif ($bytes >= $terabyte) {
|
604 |
return round($bytes / $terabyte, $precision) . ' TB';
|
605 |
} else {
|
606 |
return $bytes . ' B';
|
607 |
}
|
608 |
$fileContent = file_get_contents($databaseFile, true);
|
609 |
$pos = strpos($fileContent, 'siteurl') + 8;
|
610 |
$urlStartPos = strpos($fileContent, '"', $pos) + 1;
|
611 |
$urlEndPos = strpos($fileContent, '"', $urlStartPos);
|
612 |
$backupSiteUrl = substr($fileContent, $urlStartPos, $urlEndPos - $urlStartPos);
|
613 |
return $backupSiteUrl;
|
614 |
|
615 |
$dbFileContent = file_get_contents($databaseFileInZip);
|
616 |
/* we don't want to nuke the curret database if if something went wrong with the above operation */
|
617 |
if ( false === $dbFileContent ) {
|
618 |
wpa_backup_error( 'dbrest', sprintf ( __( 'Cannot read <code>%s</code>' ), $databaseFileInZip ) , true );
|
619 |
}
|
620 |
|
621 |
|
622 |
$conn = mysql_connect( DB_HOST, DB_USER, DB_PASSWORD );
|
623 |
/* and we cannot nuke the db if the connection failed now can we */
|
624 |
if ( false === $conn ) {
|
625 |
wpa_backup_error('dbrest', __( 'database connection failed' ), true );
|
626 |
}
|
627 |
|
628 |
mysql_select_db( DB_NAME, $conn);
|
629 |
|
630 |
$query = mysql_query("SHOW TABLES", $conn);
|
631 |
/* point of no return,if it fails after this you're royally boned ;) */
|
632 |
while (($fetch = mysql_fetch_array($query))) {
|
633 |
mysql_query("Drop table `{$fetch[0]}`");
|
634 |
}
|
635 |
flush();
|
636 |
|
637 |
$res = explode(";\n", $dbFileContent);
|
638 |
foreach ($res AS $query) {
|
639 |
mysql_query($query, $conn);
|
640 |
}
|
641 |
mysql_close($conn);
|
642 |
$backupSiteUrl = replaceSiteUrlFromDatabaseFile($databaseFileInZip); /* don't let the name fool you,it just returns the old site's url */
|
643 |
$currentSiteUrl = site_url();
|
644 |
$backupSiteUrl = untrailingslashit($backupSiteUrl);
|
645 |
$currentSiteUrl = untrailingslashit($currentSiteUrl);
|
646 |
wpa_safe_replace_wrapper ( $backupSiteUrl, $currentSiteUrl );
|
647 |
|
648 |
return $currentSiteUrl;
|
649 |
* @param type $search URL of the previous site.
|
650 |
* @param type $replace URL of the current site.
|
651 |
* @return type total time it took for the operation.
|
652 |
*/
|
653 |
if ( !function_exists( 'icit_srdb_replacer' ) && !function_exists( 'recursive_unserialize_replace' ) ) {
|
654 |
require_once 'icit_srdb_replacer.php';
|
655 |
}
|
656 |
$connection = @mysql_connect( DB_HOST, DB_USER, DB_PASSWORD );
|
657 |
$all_tables = array( );
|
658 |
@mysql_select_db( DB_NAME, $connection );
|
659 |
$all_tables_mysql = @mysql_query( 'SHOW TABLES', $connection );
|
660 |
if ( ! $all_tables_mysql ) {
|
661 |
wpa_backup_error( 'dbrest', mysql_error(), true );
|
662 |
} else {
|
663 |
while ( $table = mysql_fetch_array( $all_tables_mysql ) ) {
|
664 |
$all_tables[] = $table[ 0 ];
|
665 |
}
|
666 |
}
|
667 |
$report = icit_srdb_replacer( $connection, $search, $replace, $all_tables );
|
668 |
return $report;
|
669 |
wpa_cleanup( true );
|
670 |
if (!is_string($url) || '' == $url) {
|
671 |
wpa_backup_error( 'restore', sprintf( __( 'The provided URL (<code>%s<code>) is either not valid or empty' ), $url ), true );
|
672 |
}
|
673 |
|
674 |
$pathParts = pathinfo($url);
|
675 |
$zipFilename = wpa_fetch_file($url);
|
676 |
$result = wpa_unzip($zipFilename, WPCLONE_WP_CONTENT, $zipmode);
|
677 |
if ($result) {
|
678 |
$unzippedFolderPath = wpCloneSafePathMode( trailingslashit( WPCLONE_WP_CONTENT ) . 'wpclone_backup' );
|
679 |
if ( !file_exists( $unzippedFolderPath ) ) {
|
680 |
$unzippedFolderPath = wpCloneSafePathMode( trailingslashit( WPCLONE_WP_CONTENT ) . $pathParts['filename'] );
|
681 |
}
|
682 |
|
683 |
/* if we're here then the file extraction worked,but let's make doubly sure */
|
684 |
if( !is_dir( $unzippedFolderPath ) ) {
|
685 |
wpa_backup_error( 'restore', sprintf( __( 'Cannot find <code>%s<code>' ), $unzippedFolderPath ), true );
|
686 |
}
|
687 |
/* check the table prefixes */
|
688 |
$old_db_prefix = $unzippedFolderPath . '/prefix.txt';
|
689 |
$prefix = wpa_check_prefix($old_db_prefix);
|
690 |
if ($prefix) {
|
691 |
wpa_replace_prefix( $prefix );
|
692 |
}
|
693 |
/* import db */
|
694 |
$databaseFile = $unzippedFolderPath . '/database.sql';
|
695 |
$currentSiteUrl = processConfigAndDatabaseFile($databaseFile);
|
696 |
/* */
|
697 |
wpa_copy( $unzippedFolderPath, WPCLONE_ROOT );
|
698 |
global $wp_filesystem;
|
699 |
$wp_filesystem->delete( $unzippedFolderPath, true );
|
700 |
/* remove the zip file only if it was downloaded from an external location. */
|
701 |
$wptmp = explode('.', $zipFilename);
|
702 |
if ( in_array( 'tmp', $wptmp ) ) {
|
703 |
$wp_filesystem->delete( $zipFilename );
|
704 |
}
|
705 |
echo "<h1>Restore Successful!</h1>";
|
706 |
echo "Visit your restored site [ <a href='{$currentSiteUrl}' target=blank>here</a> ]<br><br>";
|
707 |
echo "<strong>You may need to re-save your permalink structure <a href='{$currentSiteUrl}/wp-admin/options-permalink.php' target=blank>Here</a></strong>";
|
708 |
} else {
|
709 |
echo "<h1>Restore unsuccessful!!!</h1>";
|
710 |
echo "Please try again.";
|
711 |
}
|
712 |
global $wpdb;
|
713 |
$prefix = $wpdb->prefix;
|
714 |
$file = $path . '/prefix.txt';
|
715 |
if ( is_dir($path) && is_writable($path) ) {
|
716 |
file_put_contents($file, $prefix);
|
717 |
}
|
718 |
* Checks to see whether the destination site's table prefix matches that of the origin site.old prefix is returned in case of a mismatch.
|
719 |
*
|
720 |
* @param type $file path to the prefix.txt file.
|
721 |
* @return type bool string
|
722 |
*/
|
723 |
global $wpdb;
|
724 |
$prefix = $wpdb->prefix;
|
725 |
if (file_exists($file) && is_readable($file)) {
|
726 |
$old_prefix = file_get_contents($file);
|
727 |
if ( $prefix !== $old_prefix ) {
|
728 |
return $old_prefix;
|
729 |
}
|
730 |
else {
|
731 |
return false;
|
732 |
}
|
733 |
}
|
734 |
return false;
|
735 |
* @since 2.0.6
|
736 |
*
|
737 |
* @param type $zipfile path to the zip file that needs to be extracted.
|
738 |
* @param type $path the place to where the file needs to be extracted.
|
739 |
* @return as false in the event of failure.
|
740 |
*/
|
741 |
if ( $zipmode ) {
|
742 |
if ( ini_get('mbstring.func_overload') && function_exists('mb_internal_encoding') ) {
|
743 |
$previous_encoding = mb_internal_encoding();
|
744 |
mb_internal_encoding('ISO-8859-1');
|
745 |
}
|
746 |
define('PCLZIP_TEMPORARY_DIR', WPCLONE_DIR_BACKUP);
|
747 |
require_once ( ABSPATH . 'wp-admin/includes/class-pclzip.php' );
|
748 |
$z = new PclZip($zipfile);
|
749 |
$files = $z->extract(PCLZIP_OPT_PATH, $path);
|
750 |
if ( isset($previous_encoding) ) mb_internal_encoding($previous_encoding);
|
751 |
if ( $files == 0 ) {
|
752 |
wpa_backup_error( 'pclunzip', $z->errorInfo(true), true );
|
753 |
}
|
754 |
return true;
|
755 |
}
|
756 |
else {
|
757 |
$z= unzip_file($zipfile, $path);
|
758 |
if (is_wp_error($z)) {
|
759 |
wpa_backup_error( 'unzip', $z->get_error_message(), true );
|
760 |
}
|
761 |
return true;
|
762 |
}
|
763 |
* @since 2.0.6
|
764 |
*
|
765 |
* @param type $name name of the zip file.
|
766 |
* @param type $file_list an array of files that needs to be archived.
|
767 |
*/
|
768 |
if ( $zipmode || (!in_array('ZipArchive', get_declared_classes()) || !class_exists('ZipArchive')) ) {
|
769 |
define('PCLZIP_TEMPORARY_DIR', WPCLONE_DIR_BACKUP);
|
770 |
require_once ( ABSPATH . 'wp-admin/includes/class-pclzip.php');
|
771 |
$z = new PclZip($zip_name);
|
772 |
$v_list = $z->create($folder, PCLZIP_OPT_REMOVE_PATH, WPCLONE_DIR_BACKUP);
|
773 |
if ($v_list == 0) {
|
774 |
wpa_backup_error( 'pclzip', $z->errorInfo(true) );
|
775 |
}
|
776 |
} else {
|
777 |
$z = new ZipArchive();
|
778 |
if ( true !== $z->open( $zip_name, ZIPARCHIVE::CREATE ) ) {
|
779 |
wpa_backup_error( 'zip', $z );
|
780 |
}
|
781 |
wpa_ziparc($z, $folder, WPCLONE_DIR_BACKUP);
|
782 |
$z->close();
|
783 |
}
|
784 |
$new_folder = str_replace($base, '', $dir);
|
785 |
$zip->addEmptyDir($new_folder);
|
786 |
foreach( glob( $dir . '/*' ) as $file ){
|
787 |
if( is_dir($file) ) {
|
788 |
wpa_ziparc($zip, $file, $base);
|
789 |
} else {
|
790 |
$new_file = str_replace( $base, '', $file );
|
791 |
$zip->addFile($file, $new_file);
|
792 |
}
|
793 |
}
|
794 |
* just a simple function to increase PHP limits.
|
795 |
* @since 2.0.6
|
796 |
*/
|
797 |
$time = isset( $_POST['maxexec'] ) && '' != $_POST['maxexec'] ? $_POST['maxexec'] : 900;
|
798 |
$mem = isset ( $_POST['maxmem'] ) && '' != $_POST['maxmem'] ? $_POST['maxmem'] . 'M' : '512M';
|
799 |
@ini_set('memory_limit', $mem);
|
800 |
@ini_set('max_execution_time', $time); //900 seconds = 15 minutes
|
801 |
* @since 2.0.6
|
802 |
*/
|
803 |
if (!empty($_REQUEST['del'])) {
|
804 |
wpa_remove_backup();
|
805 |
return true;
|
806 |
}
|
807 |
if (empty($_POST)) return false;
|
808 |
check_admin_referer('wpclone-submit');
|
809 |
$form_post = wp_nonce_url('admin.php?page=wp-clone', 'wpclone-submit');
|
810 |
$extra_fields = array('restore_from_url', 'maxmem', 'maxexec', 'zipmode', 'restoreBackup');
|
811 |
$type = '';
|
812 |
if ( false === ($creds = request_filesystem_credentials($form_post, $type, false, false, $extra_fields)) ){
|
813 |
return true;
|
814 |
}
|
815 |
if (!WP_Filesystem($creds)) {
|
816 |
request_filesystem_credentials($form_post, $type, true, false, $extra_fields);
|
817 |
return true;
|
818 |
}
|
819 |
wpa_bump_limits();
|
820 |
|
821 |
if (isset($_POST['createBackup'])) {
|
822 |
wpa_create_backup();
|
823 |
return true;
|
824 |
}
|
825 |
|
826 |
$zipmode = isset($_POST['zipmode']) ? true : false;
|
827 |
$url = isset($_POST['restoreBackup']) ? $_POST['restoreBackup'] : $_POST['restore_from_url'];
|
828 |
processRestoringBackup($url, $zipmode);
|
829 |
return true;
|
830 |
* @since 2.0.6
|
831 |
*/
|
832 |
global $wp_filesystem;
|
833 |
if (is_readable($source)) {
|
834 |
if (is_dir($source)) {
|
835 |
if (!strstr(wpCloneSafePathMode($source), rtrim(WPCLONE_DIR_BACKUP, "/\\"))) {
|
836 |
if (!file_exists($target)) {
|
837 |
$wp_filesystem->mkdir($target);
|
838 |
}
|
839 |
$d = dir($source);
|
840 |
while (FALSE !== ($entry = $d->read())) {
|
841 |
if ($entry == '.' || $entry == '..') {
|
842 |
continue;
|
843 |
}
|
844 |
$Entry = "{$source}/{$entry}";
|
845 |
if (is_dir($Entry)) {
|
846 |
wpa_copy($Entry, $target . '/' . $entry);
|
847 |
} else {
|
848 |
$wp_filesystem->copy($Entry, $target . '/' . $entry, true, FS_CHMOD_FILE);
|
849 |
}
|
850 |
}
|
851 |
$d->close();
|
852 |
}
|
853 |
}
|
854 |
else {
|
855 |
$wp_filesystem->copy($source, $target, true);
|
856 |
}
|
857 |
}
|
858 |
* @since 2.0.6
|
859 |
*/
|
860 |
$wpconfig = wpa_wpconfig_path();
|
861 |
if ( ! is_writable($wpconfig) ) {
|
862 |
wpa_backup_error('wpconfig', sprintf( __( "<code>%s</code> is not writable." ), $wpconfig ), true );
|
863 |
}
|
864 |
|
865 |
global $wp_filesystem;
|
866 |
$fileContent = file_get_contents($wpconfig);
|
867 |
$pos = strpos($fileContent, '$table_prefix');
|
868 |
$str = substr($fileContent, $pos, strpos($fileContent, PHP_EOL, $pos) - $pos);
|
869 |
$fileContent = str_replace($str, '$table_prefix = "' . $newPrefix . '";', $fileContent);
|
870 |
$wp_filesystem->put_contents($wpconfig, $fileContent, 0600);
|
871 |
* @since 2.0.6
|
872 |
*/
|
873 |
wpa_cleanup();
|
874 |
$use_wpdb = isset( $_POST['use_wpdb'] ) && 'true' == $_POST['use_wpdb'] ? true : false;
|
875 |
$backupName = wpa_backup_name();
|
876 |
$zipmode = isset($_POST['zipmode']) ? true : false;
|
877 |
list($zipFileName, $zipSize) = CreateWPFullBackupZip($backupName, $zipmode, $use_wpdb);
|
878 |
wpa_insert_data($zipFileName, $zipSize);
|
879 |
$backZipPath = convertPathIntoUrl(WPCLONE_DIR_BACKUP . $zipFileName);
|
880 |
$zipSize = bytesToSize($zipSize);
|
881 |
echo <<<EOF
|
882 |
<a href='{$backZipPath}'><span>{$backZipPath}</span></a> ( {$zipSize} ) |
|
883 |
<input type='hidden' name='backupUrl' class='backupUrl' value="{$backZipPath}" />
|
884 |
<a class='copy-button' href='#' data-clipboard-text='{$backZipPath}'>Copy URL</a> <br /><br />
|
885 |
(Copy that link and paste it into the "Restore URL" of your new WordPress installation to clone this site)
|
886 |
* @since 2.0.6
|
887 |
*/
|
888 |
$deleteRow = DeleteWPBackupZip($_REQUEST['del']);
|
889 |
echo <<<EOT
|
890 |
<h1>Deleted Successful!</h1> <br />
|
891 |
{$deleteRow->backup_name} <br />
|
892 |
File deleted from backup folder and database...
|
893 |
* @since 2.1.2
|
894 |
* copypasta from wp-load.php
|
895 |
* @return the path to wp-config.php
|
896 |
*/
|
897 |
$z = pathinfo($path);
|
898 |
if (file_exists(WPCLONE_DIR_BACKUP . $z['basename'])) {
|
899 |
return WPCLONE_DIR_BACKUP . $z['basename'];
|
900 |
}
|
901 |
else {
|
902 |
$url = download_url($path, 750);
|
903 |
if ( is_wp_error($url) ) wpa_backup_error( 'url', $url->get_error_message(), true );
|
904 |
return $url;
|
905 |
}
|
906 |
$backup_name = 'wpclone_backup_' . date( 'dS_M_Y_h-iA' ) . '_' . get_option( 'blogname' );
|
907 |
$backup_name = substr( str_replace( ' ', '', $backup_name ), 0, 40 );
|
908 |
$rand_str = substr( str_shuffle( "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" ), 0, 10 );
|
909 |
$backup_name = sanitize_file_name( $backup_name ) . '_' . $rand_str;
|
910 |
return $backup_name;
|
911 |
|
912 |
$backup_dir = $restore ? trailingslashit( WPCLONE_WP_CONTENT ) . 'wpclone_backup' : trailingslashit( WPCLONE_DIR_BACKUP ) . 'wpclone_backup';
|
913 |
if( $restore ) {
|
914 |
$url = isset($_POST['restoreBackup']) ? $_POST['restoreBackup'] : $_POST['restore_from_url'];
|
915 |
if ( !file_exists( $backup_dir ) ) {
|
916 |
$path = pathinfo( $url );
|
917 |
$backup_dir = trailingslashit( WPCLONE_WP_CONTENT ) . $path['filename'];
|
918 |
}
|
919 |
if( !file_exists( $backup_dir ) ) {
|
920 |
unset( $backup_dir );
|
921 |
}
|
922 |
}
|
923 |
switch ( $error ) :
|
924 |
/* during backup */
|
925 |
case 'file' :
|
926 |
$error = __( 'while copying files into the temp directory' );
|
927 |
break;
|
928 |
case 'db' :
|
929 |
$error = __( 'during the database backup' );
|
930 |
break;
|
931 |
case 'zip' :
|
932 |
$error = __( 'while creating the zip file using PHP\'s ZipArchive library' );
|
933 |
break;
|
934 |
case 'pclzip' :
|
935 |
$error = __( 'while creating the zip file using the PclZip library' );
|
936 |
break;
|
937 |
/* during restore */
|
938 |
case 'filerest' :
|
939 |
$error = __( 'while copying files from the temp directory into the wp-content directory' );
|
940 |
break;
|
941 |
case 'dbrest' :
|
942 |
$error = __( 'while cloning the database' );
|
943 |
break;
|
944 |
case 'unzip' :
|
945 |
$error = __( 'while extracting the zip file using WP\'s zip file extractor' );
|
946 |
break;
|
947 |
case 'pclunzip' :
|
948 |
$error = __( 'while extracting the zip file using the PclZip library' );
|
949 |
break;
|
950 |
case 'url' :
|
951 |
$error = __( 'while downloading the zip file' );
|
952 |
break;
|
953 |
case 'wpconfig' :
|
954 |
$error = __( 'while trying to modify the table prefix in the wp-config.php file' );
|
955 |
break;
|
956 |
/* and a catch all for the things that aren't covered above */
|
957 |
default :
|
958 |
$error = sprintf( __( 'during the %s process' ), $error );
|
959 |
endswitch;
|
960 |
|
961 |
echo '<div class="wpclone_notice updated">';
|
962 |
printf( __( 'The plugin encountered an error %s,the following error message was returned:</br>' ), $error );
|
963 |
echo '<div class="error">' . __( 'Error Message : ' ) . $data . '</div></br>';
|
964 |
if( isset( $backup_dir) ) {
|
965 |
printf( __( 'Temporary files created in <code>%s</code> will be deleted.' ), $backup_dir );
|
966 |
echo '</div>';
|
967 |
global $wp_filesystem;
|
968 |
$wp_filesystem->delete($backup_dir, true);
|
969 |
} else {
|
970 |
echo '</div>';
|
971 |
}
|
972 |
die;
|
973 |
$backup_dir = $restore ? trailingslashit( WPCLONE_WP_CONTENT ) . 'wpclone_backup' : trailingslashit( WPCLONE_DIR_BACKUP ) . 'wpclone_backup';
|
974 |
if ( file_exists( $backup_dir ) && is_dir( $backup_dir ) ) {
|
975 |
global $wp_filesystem;
|
976 |
$wp_filesystem->delete($backup_dir, true);
|
977 |
}
|
lib/icit_srdb_replacer.php
ADDED
@@ -0,0 +1,154 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Take a serialised array and unserialise it replacing elements as needed and
|
4 |
+
* unserialising any subordinate arrays and performing the replace on those too.
|
5 |
+
*
|
6 |
+
* @param string $from String we're looking to replace.
|
7 |
+
* @param string $to What we want it to be replaced with
|
8 |
+
* @param array $data Used to pass any subordinate arrays back to in.
|
9 |
+
* @param bool $serialised Does the array passed via $data need serialising.
|
10 |
+
*
|
11 |
+
* @return array The original array with all elements replaced as needed.
|
12 |
+
*/
|
13 |
+
function recursive_unserialize_replace( $from = '', $to = '', $data = '', $serialised = false ) {
|
14 |
+
|
15 |
+
// some unseriliased data cannot be re-serialised eg. SimpleXMLElements
|
16 |
+
try {
|
17 |
+
|
18 |
+
if ( is_string( $data ) && ( $unserialized = @unserialize( $data ) ) !== false ) {
|
19 |
+
$data = recursive_unserialize_replace( $from, $to, $unserialized, true );
|
20 |
+
}
|
21 |
+
|
22 |
+
elseif ( is_array( $data ) ) {
|
23 |
+
$_tmp = array( );
|
24 |
+
foreach ( $data as $key => $value ) {
|
25 |
+
$_tmp[ $key ] = recursive_unserialize_replace( $from, $to, $value, false );
|
26 |
+
}
|
27 |
+
|
28 |
+
$data = $_tmp;
|
29 |
+
unset( $_tmp );
|
30 |
+
}
|
31 |
+
|
32 |
+
else {
|
33 |
+
if ( is_string( $data ) )
|
34 |
+
$data = str_replace( $from, $to, $data );
|
35 |
+
}
|
36 |
+
|
37 |
+
if ( $serialised )
|
38 |
+
return serialize( $data );
|
39 |
+
|
40 |
+
} catch( Exception $error ) {
|
41 |
+
|
42 |
+
}
|
43 |
+
|
44 |
+
return $data;
|
45 |
+
}
|
46 |
+
|
47 |
+
/**
|
48 |
+
* The main loop triggered in step 5. Up here to keep it out of the way of the
|
49 |
+
* HTML. This walks every table in the db that was selected in step 3 and then
|
50 |
+
* walks every row and column replacing all occurences of a string with another.
|
51 |
+
* We split large tables into 50,000 row blocks when dealing with them to save
|
52 |
+
* on memmory consumption.
|
53 |
+
*
|
54 |
+
* @param mysql $connection The db connection object
|
55 |
+
* @param string $search What we want to replace
|
56 |
+
* @param string $replace What we want to replace it with.
|
57 |
+
* @param array $tables The tables we want to look at.
|
58 |
+
*
|
59 |
+
* @return array Collection of information gathered during the run.
|
60 |
+
*/
|
61 |
+
function icit_srdb_replacer( $connection, $search = '', $replace = '', $tables = array( ) ) {
|
62 |
+
global $guid, $exclude_cols;
|
63 |
+
|
64 |
+
$report = array( 'tables' => 0,
|
65 |
+
'rows' => 0,
|
66 |
+
'change' => 0,
|
67 |
+
'updates' => 0,
|
68 |
+
'start' => microtime( ),
|
69 |
+
'end' => microtime( ),
|
70 |
+
'errors' => array( ),
|
71 |
+
);
|
72 |
+
|
73 |
+
if ( is_array( $tables ) && ! empty( $tables ) ) {
|
74 |
+
foreach( $tables as $table ) {
|
75 |
+
$report[ 'tables' ]++;
|
76 |
+
|
77 |
+
$columns = array( );
|
78 |
+
|
79 |
+
// Get a list of columns in this table
|
80 |
+
$fields = mysql_query( 'DESCRIBE ' . $table, $connection );
|
81 |
+
while( $column = mysql_fetch_array( $fields ) )
|
82 |
+
$columns[ $column[ 'Field' ] ] = $column[ 'Key' ] == 'PRI' ? true : false;
|
83 |
+
|
84 |
+
// Count the number of rows we have in the table if large we'll split into blocks, This is a mod from Simon Wheatley
|
85 |
+
$row_count = mysql_query( 'SELECT COUNT(*) FROM ' . $table, $connection );
|
86 |
+
$rows_result = mysql_fetch_array( $row_count );
|
87 |
+
$row_count = $rows_result[ 0 ];
|
88 |
+
if ( $row_count == 0 )
|
89 |
+
continue;
|
90 |
+
|
91 |
+
$page_size = 50000;
|
92 |
+
$pages = ceil( $row_count / $page_size );
|
93 |
+
|
94 |
+
for( $page = 0; $page < $pages; $page++ ) {
|
95 |
+
|
96 |
+
$current_row = 0;
|
97 |
+
$start = $page * $page_size;
|
98 |
+
$end = $start + $page_size;
|
99 |
+
// Grab the content of the table
|
100 |
+
$data = mysql_query( sprintf( 'SELECT * FROM %s LIMIT %d, %d', $table, $start, $end ), $connection );
|
101 |
+
|
102 |
+
if ( ! $data )
|
103 |
+
$report[ 'errors' ][] = mysql_error( );
|
104 |
+
|
105 |
+
while ( $row = mysql_fetch_array( $data ) ) {
|
106 |
+
|
107 |
+
$report[ 'rows' ]++; // Increment the row counter
|
108 |
+
$current_row++;
|
109 |
+
|
110 |
+
$update_sql = array( );
|
111 |
+
$where_sql = array( );
|
112 |
+
$upd = false;
|
113 |
+
|
114 |
+
foreach( $columns as $column => $primary_key ) {
|
115 |
+
if ( $guid == 1 && in_array( $column, $exclude_cols ) )
|
116 |
+
continue;
|
117 |
+
|
118 |
+
$edited_data = $data_to_fix = $row[ $column ];
|
119 |
+
|
120 |
+
// Run a search replace on the data that'll respect the serialisation.
|
121 |
+
$edited_data = recursive_unserialize_replace( $search, $replace, $data_to_fix );
|
122 |
+
|
123 |
+
// Something was changed
|
124 |
+
if ( $edited_data != $data_to_fix ) {
|
125 |
+
$report[ 'change' ]++;
|
126 |
+
$update_sql[] = $column . ' = "' . mysql_real_escape_string( $edited_data ) . '"';
|
127 |
+
$upd = true;
|
128 |
+
}
|
129 |
+
|
130 |
+
if ( $primary_key )
|
131 |
+
$where_sql[] = $column . ' = "' . mysql_real_escape_string( $data_to_fix ) . '"';
|
132 |
+
}
|
133 |
+
|
134 |
+
if ( $upd && ! empty( $where_sql ) ) {
|
135 |
+
$sql = 'UPDATE ' . $table . ' SET ' . implode( ', ', $update_sql ) . ' WHERE ' . implode( ' AND ', array_filter( $where_sql ) );
|
136 |
+
$result = mysql_query( $sql, $connection );
|
137 |
+
if ( ! $result )
|
138 |
+
$report[ 'errors' ][] = mysql_error( );
|
139 |
+
else
|
140 |
+
$report[ 'updates' ]++;
|
141 |
+
|
142 |
+
} elseif ( $upd ) {
|
143 |
+
$report[ 'errors' ][] = sprintf( '"%s" has no primary key, manual change needed on row %s.', $table, $current_row );
|
144 |
+
}
|
145 |
+
|
146 |
+
}
|
147 |
+
}
|
148 |
+
}
|
149 |
+
|
150 |
+
}
|
151 |
+
$report[ 'end' ] = microtime( );
|
152 |
+
|
153 |
+
return $report;
|
154 |
+
}
|
lib/view.php
CHANGED
@@ -1,28 +1,37 @@
|
|
1 |
<script type="text/javascript">
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
|
27 |
</script>
|
28 |
|
@@ -57,6 +66,7 @@ $result = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}wpclone ORDER BY id D
|
|
57 |
<div class="info">
|
58 |
<table>
|
59 |
<tr align="left"><th><label for="zipmode">Alternate zip method</label></th><td colspan="2"><input type="checkbox" name="zipmode" value="alt" /></td></tr>
|
|
|
60 |
<tr align="left"><th><label for="maxmem">Maximum memory limit</label></th><td colspan="2"><input type="text" name="maxmem" /></td></tr>
|
61 |
<tr align="left"><th><label for="maxexec">Script execution time</label></th><td><input type="text" name="maxexec" /></td></tr>
|
62 |
</table>
|
@@ -165,7 +175,7 @@ $result = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}wpclone ORDER BY id D
|
|
165 |
echo 'Site Root : <pre>' . WPCLONE_ROOT . '</pre></br>';
|
166 |
echo 'ABSPATH : <pre>' . ABSPATH . '</pre></br>';
|
167 |
if (!is_writable(WPCLONE_DIR_BACKUP)) { echo '<span style="color:#f11">Cannot write to the backup directory!</span></br>'; }
|
168 |
-
if (!is_writable(
|
169 |
echo '</div>';
|
170 |
}
|
171 |
|
@@ -181,7 +191,7 @@ $result = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}wpclone ORDER BY id D
|
|
181 |
$maxitems = $rss->get_item_quantity($limit);
|
182 |
$rss_items = $rss->get_items(0, $maxitems);
|
183 |
endif;
|
184 |
-
if ($maxitems == 0) echo '<li>No items.</li>';
|
185 |
else
|
186 |
// Loop through each feed item and display each item as a hyperlink.
|
187 |
foreach ( $rss_items as $item ) : ?>
|
@@ -193,4 +203,4 @@ $result = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}wpclone ORDER BY id D
|
|
193 |
<?php endforeach;
|
194 |
}
|
195 |
|
196 |
-
/** it all ends here folks. */
|
1 |
<script type="text/javascript">
|
2 |
+
jQuery ( function($) {
|
3 |
+
|
4 |
+
ZeroClipboard.setDefaults( { moviePath: '<?php echo WPCLONE_URL_PLUGIN ?>lib/js/ZeroClipboard.swf' } );
|
5 |
+
|
6 |
+
/**workaround for firefox versions 18 and 19.
|
7 |
+
https://bugzilla.mozilla.org/show_bug.cgi?id=829557
|
8 |
+
https://github.com/jonrohan/ZeroClipboard/issues/73
|
9 |
+
*/
|
10 |
+
var enableZC = true;
|
11 |
+
var is_firefox18 = navigator.userAgent.toLowerCase().indexOf('firefox/18') > -1;
|
12 |
+
var is_firefox19 = navigator.userAgent.toLowerCase().indexOf('firefox/19') > -1;
|
13 |
+
if (is_firefox18 || is_firefox19) enableZC = false;
|
14 |
+
|
15 |
+
if ( $( ".restore-backup-options" ).length ) {
|
16 |
+
$( ".restore-backup-options" ).each( function() {
|
17 |
+
var clip = new ZeroClipboard( $( "a.copy-button",this ) );
|
18 |
+
/** FF 18/19 users won't see an alert box. */
|
19 |
+
if (enableZC) {
|
20 |
+
clip.on( 'complete', function (client, args) {
|
21 |
+
alert( "Copied to clipboard:\n" + args.text );
|
22 |
+
});
|
23 |
+
}
|
24 |
+
});
|
25 |
+
} else {
|
26 |
+
var clip = new ZeroClipboard( $( "a.copy-button" ) );
|
27 |
+
/** FF 18/19 users won't see an alert box. */
|
28 |
+
if (enableZC) {
|
29 |
+
clip.on( 'complete', function (client, args) {
|
30 |
+
alert( "Copied to clipboard:\n" + args.text );
|
31 |
+
});
|
32 |
+
}
|
33 |
+
}
|
34 |
+
});
|
35 |
|
36 |
</script>
|
37 |
|
66 |
<div class="info">
|
67 |
<table>
|
68 |
<tr align="left"><th><label for="zipmode">Alternate zip method</label></th><td colspan="2"><input type="checkbox" name="zipmode" value="alt" /></td></tr>
|
69 |
+
<tr align="left"><th><label for="use_wpdb">Use wpdb to backup the database</label></th><td colspan="2"><input type="checkbox" name="use_wpdb" value="true" /></td></tr>
|
70 |
<tr align="left"><th><label for="maxmem">Maximum memory limit</label></th><td colspan="2"><input type="text" name="maxmem" /></td></tr>
|
71 |
<tr align="left"><th><label for="maxexec">Script execution time</label></th><td><input type="text" name="maxexec" /></td></tr>
|
72 |
</table>
|
175 |
echo 'Site Root : <pre>' . WPCLONE_ROOT . '</pre></br>';
|
176 |
echo 'ABSPATH : <pre>' . ABSPATH . '</pre></br>';
|
177 |
if (!is_writable(WPCLONE_DIR_BACKUP)) { echo '<span style="color:#f11">Cannot write to the backup directory!</span></br>'; }
|
178 |
+
if (!is_writable(WPCLONE_WP_CONTENT)) { echo '<span style="color:#f11">Cannot write to the root directory!</span></br>'; }
|
179 |
echo '</div>';
|
180 |
}
|
181 |
|
191 |
$maxitems = $rss->get_item_quantity($limit);
|
192 |
$rss_items = $rss->get_items(0, $maxitems);
|
193 |
endif;
|
194 |
+
if ( isset($maxitems) && $maxitems == 0 ) echo '<li>No items.</li>';
|
195 |
else
|
196 |
// Loop through each feed item and display each item as a hyperlink.
|
197 |
foreach ( $rss_items as $item ) : ?>
|
203 |
<?php endforeach;
|
204 |
}
|
205 |
|
206 |
+
/** it all ends here folks. */
|
readme.txt
CHANGED
@@ -6,7 +6,7 @@ Author URI: http://wpacademy.com
|
|
6 |
Plugin URI: http://wpacademy.com/software
|
7 |
Requires at least: 3.0
|
8 |
Tested up to: 3.5.1
|
9 |
-
Stable tag: 2.1.
|
10 |
License: GPLv2 or later
|
11 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
12 |
|
@@ -49,6 +49,14 @@ released under the WTFPL http://sam.zoy.org/wtfpl/. Partial script with full cha
|
|
49 |
Review FAQ's and Help Video at the [WP Clone FAQ Page](http://wpacademy.tv/wpclone-faq "WP Clone FAQ")
|
50 |
|
51 |
== Changelog ==
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
= 2.1.2 - 2013-03-07 =
|
53 |
* Fixed: An XSS vulnerability caused by an older version of the ZeroClipboard library.
|
54 |
|
6 |
Plugin URI: http://wpacademy.com/software
|
7 |
Requires at least: 3.0
|
8 |
Tested up to: 3.5.1
|
9 |
+
Stable tag: 2.1.3
|
10 |
License: GPLv2 or later
|
11 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
12 |
|
49 |
Review FAQ's and Help Video at the [WP Clone FAQ Page](http://wpacademy.tv/wpclone-faq "WP Clone FAQ")
|
50 |
|
51 |
== Changelog ==
|
52 |
+
= 2.1.3 - 2013-03-17 =
|
53 |
+
* Fixed: The 'copy' link in the 'backup successful' screen which stopped working after the 2.1.2 update.
|
54 |
+
* Added: An option to backup the database using WordPress' WPDB class.
|
55 |
+
* Removed: The need to keep the original backup names intact.
|
56 |
+
* Removed: 'lib/DirectoryTree.php' and 'lib/class.php'.
|
57 |
+
* Changed: The backup name structure.
|
58 |
+
* Changed: Backup file downloads are now handled using WP core functions.
|
59 |
+
|
60 |
= 2.1.2 - 2013-03-07 =
|
61 |
* Fixed: An XSS vulnerability caused by an older version of the ZeroClipboard library.
|
62 |
|
wpclone.php
CHANGED
@@ -4,13 +4,11 @@ Plugin name: WP Clone by WP Academy
|
|
4 |
Plugin URI: http://wpacademy.com/software/
|
5 |
Description: Move or copy a WordPress site to another server or to another domain name, move to/from local server hosting, and backup sites.
|
6 |
Author: WP Academy
|
7 |
-
Version: 2.1.
|
8 |
Author URI: http://wpacademy.com/
|
9 |
*/
|
10 |
|
11 |
-
include_once 'lib/class.php';
|
12 |
include_once 'lib/functions.php';
|
13 |
-
include_once 'lib/DirectoryTree.php';
|
14 |
|
15 |
$upload_dir = wp_upload_dir();
|
16 |
|
@@ -25,7 +23,7 @@ define('WPCLONE_INSTALLER_PATH', WPCLONE_DIR_PLUGIN);
|
|
25 |
define('WPCLONE_WP_CONTENT' , str_replace('\\', '/', WP_CONTENT_DIR));
|
26 |
|
27 |
|
28 |
-
|
29 |
|
30 |
register_activation_hook((__FILE__), 'wpa_wpclone_activate');
|
31 |
register_deactivation_hook(__FILE__ , 'wpa_wpclone_deactivate');
|
@@ -56,10 +54,8 @@ function wpa_enqueue_scripts(){
|
|
56 |
if( isset($_GET['page']) && 'wp-clone' == $_GET['page'] ) add_action('admin_enqueue_scripts', 'wpa_enqueue_scripts');
|
57 |
|
58 |
function wpa_wpclone_activate() {
|
59 |
-
global $wpdb;
|
60 |
wpa_create_directory();
|
61 |
wpa_install_database();
|
62 |
-
if (file_exists(WPCLONE_DIR_BACKUP . '.htaccess')) { unlink (WPCLONE_DIR_BACKUP . '.htaccess'); }
|
63 |
}
|
64 |
|
65 |
function wpa_wpclone_deactivate() {
|
@@ -74,9 +70,9 @@ function wpa_wpclone_deactivate() {
|
|
74 |
|
75 |
|
76 |
function wpa_create_directory() {
|
77 |
-
$upload_dir = wp_upload_dir();
|
78 |
$indexFile = (WPCLONE_DIR_BACKUP.'index.html');
|
79 |
-
$
|
|
|
80 |
if (!file_exists($indexFile)) {
|
81 |
if(!file_exists(WPCLONE_DIR_BACKUP)) {
|
82 |
if(!mkdir(WPCLONE_DIR_BACKUP, WPBACKUP_FILE_PERMISSION)) {
|
@@ -86,6 +82,7 @@ function wpa_create_directory() {
|
|
86 |
$handle = fopen($indexFile, "w");
|
87 |
fclose($handle);
|
88 |
}
|
|
|
89 |
}
|
90 |
|
91 |
function wpa_install_database() {
|
@@ -100,7 +97,7 @@ function wpa_install_database() {
|
|
100 |
$charset_collate .= " COLLATE $wpdb->collate";
|
101 |
}
|
102 |
$wp_backup = $wpdb->prefix . 'wpclone';
|
103 |
-
|
104 |
if( !$wpdb->get_var( "SHOW TABLES LIKE '{$wp_backup}'" ) ) {
|
105 |
$sql = "CREATE TABLE {$wp_backup} (
|
106 |
id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
4 |
Plugin URI: http://wpacademy.com/software/
|
5 |
Description: Move or copy a WordPress site to another server or to another domain name, move to/from local server hosting, and backup sites.
|
6 |
Author: WP Academy
|
7 |
+
Version: 2.1.3
|
8 |
Author URI: http://wpacademy.com/
|
9 |
*/
|
10 |
|
|
|
11 |
include_once 'lib/functions.php';
|
|
|
12 |
|
13 |
$upload_dir = wp_upload_dir();
|
14 |
|
23 |
define('WPCLONE_WP_CONTENT' , str_replace('\\', '/', WP_CONTENT_DIR));
|
24 |
|
25 |
|
26 |
+
/* Init options & tables during activation & deregister init option */
|
27 |
|
28 |
register_activation_hook((__FILE__), 'wpa_wpclone_activate');
|
29 |
register_deactivation_hook(__FILE__ , 'wpa_wpclone_deactivate');
|
54 |
if( isset($_GET['page']) && 'wp-clone' == $_GET['page'] ) add_action('admin_enqueue_scripts', 'wpa_enqueue_scripts');
|
55 |
|
56 |
function wpa_wpclone_activate() {
|
|
|
57 |
wpa_create_directory();
|
58 |
wpa_install_database();
|
|
|
59 |
}
|
60 |
|
61 |
function wpa_wpclone_deactivate() {
|
70 |
|
71 |
|
72 |
function wpa_create_directory() {
|
|
|
73 |
$indexFile = (WPCLONE_DIR_BACKUP.'index.html');
|
74 |
+
$htacc = WPCLONE_DIR_BACKUP . '.htaccess';
|
75 |
+
$htacc_data = "Options All -Indexes";
|
76 |
if (!file_exists($indexFile)) {
|
77 |
if(!file_exists(WPCLONE_DIR_BACKUP)) {
|
78 |
if(!mkdir(WPCLONE_DIR_BACKUP, WPBACKUP_FILE_PERMISSION)) {
|
82 |
$handle = fopen($indexFile, "w");
|
83 |
fclose($handle);
|
84 |
}
|
85 |
+
file_put_contents($htacc, $htacc_data);
|
86 |
}
|
87 |
|
88 |
function wpa_install_database() {
|
97 |
$charset_collate .= " COLLATE $wpdb->collate";
|
98 |
}
|
99 |
$wp_backup = $wpdb->prefix . 'wpclone';
|
100 |
+
/* could be case senstive : http://dev.mysql.com/doc/refman/5.1/en/identifier-case-sensitivity.html */
|
101 |
if( !$wpdb->get_var( "SHOW TABLES LIKE '{$wp_backup}'" ) ) {
|
102 |
$sql = "CREATE TABLE {$wp_backup} (
|
103 |
id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|