WP Clone by WP Academy - Version 2.0.9

Version Description

Download this release

Release Info

Developer wpacademy
Plugin Icon 128x128 WP Clone by WP Academy
Version 2.0.9
Comparing to
See all releases

Version 2.0.9

lib/DirectoryTree.php ADDED
@@ -0,0 +1,178 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .MainView p {
2
+ width: 825px;
3
+ }
4
+
5
+ #backupForm #create-backup-option {
6
+ margin-bottom: 5px;
7
+ }
8
+
9
+ #RestoreOptions, #file_directory {
10
+ display: none;
11
+ }
12
+
13
+ #file_directory {
14
+ background: url('../images/folder.png') no-repeat;
15
+ min-height: 30px;
16
+ padding: 5px 0 0 35px
17
+ }
18
+
19
+ #file_directory ul {
20
+ list-style: none;
21
+ margin: 0 0 0 20px;
22
+ padding-left: 20px;
23
+ }
24
+
25
+ #file_directory li {
26
+ min-height: 30px;
27
+ margin: 1px 0;
28
+ padding: 5px 0 0 30px;
29
+ position: relative;
30
+ }
31
+
32
+ #file_directory input[type=checkbox] {
33
+ float: left;
34
+ }
35
+
36
+ #file_directory span.parent {
37
+ cursor: pointer;
38
+ }
39
+
40
+ #file_directory .folder {
41
+ background: url('../images/folder.png') no-repeat;
42
+ }
43
+
44
+ #file_directory .file {
45
+ background: url('../images/file.png') no-repeat;
46
+ }
47
+
48
+ div.try .restore-backup-options {
49
+ display: block;
50
+ }
lib/functions.php ADDED
@@ -0,0 +1 @@
 
0
  $backupName = date('Y-m-d-H-i-s') . '_' . get_bloginfo('name', 'display');
1
  $backupName = substr(str_replace(' ', '', $backupName), 0, 40);
2
  $backupName = sanitize_file_name($backupName);
3
  return $backupName;
4
  return str_replace("\\", "/", $path);
5
  return rtrim(str_replace("//", "/", wpCloneSafePathMode($path)), '/') . '/';
6
  return str_replace(rtrim(WPCLONE_ROOT, "/\\"), site_url(), $path);
7
  return str_replace(site_url(), rtrim(WPCLONE_ROOT, "/\\"), $url);
8
  if (is_readable($source)) {
9
  if (is_dir($source)) {
10
  if (!strstr(wpCloneSafePathMode($source), rtrim(WPCLONE_DIR_BACKUP, "/\\"))) {
11
  if (!file_exists($target)) {
12
  mkdir($target, WPBACKUP_FILE_PERMISSION);
13
  }
14
  $d = dir($source);
15
  while (FALSE !== ($entry = $d->read())) {
16
  if ($entry == '.' || $entry == '..') {
17
  continue;
18
  }
19
  $Entry = "{$source}/{$entry}";
20
  if (is_dir($Entry)) {
21
  wpBackupFullCopy($Entry, $target . '/' . $entry);
22
  } else {
23
  @ copy($Entry, $target . '/' . $entry);
24
  }
25
  }
26
  $d->close();
27
  }
28
  } else {
29
  copy($source, $target);
30
  }
31
  }
32
  global $wpdb;
33
  $WPCLONE_DB_ICONV_IN = "UTF-8";
34
  $WPCLONE_DB_ICONV_OUT = "ISO-8859-1//TRANSLIT";
35
  $return = '';
36
  // Get all of the tables
37
  $tables = $wpdb->get_col('SHOW TABLES');
38
  // Cycle through each provided table
39
  foreach ($tables as $table) {
40
  // First part of the output � remove the table
41
  $result = $wpdb->get_results("SELECT * FROM {$table}", ARRAY_N);
42
  $numberOfFields = count($result[0]);
43
  $numberOfItems = count($result);
44
  // Second part of the output � create table
45
  $row2 = $wpdb->get_row("SHOW CREATE TABLE {$table}", ARRAY_N);
46
  $return .= "\n\n" . $row2[1] . ";\n\n";
47
  // Third part of the output � insert values into new table
48
  for ($currentRowNumber = 0; $currentRowNumber < $numberOfItems; $currentRowNumber++) {
49
  $row = $result[$currentRowNumber];
50
  $query = "INSERT INTO {$table} VALUES(";
51
  for ($j = 0; $j < $numberOfFields; $j++) {
52
  $row[$j] = iconv($WPCLONE_DB_ICONV_IN, $WPCLONE_DB_ICONV_OUT, $row[$j]);
53
  $query .= (empty($row[$j])) ? '"", ' : '"' . mysql_real_escape_string($row[$j]) . '", ';
54
  }
55
  $return .= substr($query, 0, -2) . ");\n";
56
  }
57
  $return .= "\n";
58
  }
59
  // Generate the filename for the sql file
60
  $File_open = fopen($destination . '/database.sql', 'w+');
61
  // Save the sql file
62
  fwrite($File_open, $return);
63
  //file close
64
  fclose($File_open);
65
  $wpdb->flush();
66
  global $wpdb;
67
  global $current_user;
68
  $wpdb->insert($wpdb->prefix . "wpclone", array(
69
  'backup_name' => $name,
70
  'data_time' => current_time('mysql', get_option('gmt_offset')),
71
  'creator' => $current_user->user_login,
72
  'backup_size' => $size)
73
  );
74
  $wpdb->flush;
75
  $folderToBeZipped = WPCLONE_DIR_BACKUP . $backupName;
76
  $destinationPath = $folderToBeZipped . '/' . basename(WPCLONE_WP_CONTENT);
77
  $zipFileName = $backupName . '.zip';
78
  DirectoryTree::createDirectory($destinationPath);
79
  wpBackupFullCopy(rtrim(WPCLONE_WP_CONTENT, "/\\"), $destinationPath);
80
  wpa_save_prefix($folderToBeZipped);
81
  dw_backup_tables(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME, $folderToBeZipped);
82
  wpa_zip("{$folderToBeZipped}.zip", $folderToBeZipped, $zipmode);
83
  $zipSize = filesize("{$folderToBeZipped}.zip");
84
  DirectoryTree::DeleteAllDirectoryFiles($folderToBeZipped, true);
85
  return array($zipFileName, $zipSize);
86
  $backupDirectory = rtrim(WPCLONE_DIR_BACKUP, "/\\");
87
  $key = array_search($backupDirectory, $directoryFiles);
88
  if ($directoryFiles[$key] === $backupDirectory) {
89
  unset($directoryFiles[$key]);
90
  }
91
  $destinationPath = WPCLONE_DIR_BACKUP . $backupName;
92
  $zipFileName = $backupName . '.zip';
93
  mkdir($destinationPath, WPBACKUP_FILE_PERMISSION);
94
  foreach($directoryFiles AS $directoryFolder) {
95
  $destinationFolder = str_replace(rtrim(WPCLONE_ROOT, "/\\"), $destinationPath, $directoryFolder);
96
  wpBackupFullCopy($directoryFolder, $destinationFolder);
97
  }
98
  CreateDb($destinationPath);
99
  wpa_zip("{$destinationPath}.zip", $destinationPath);
100
  $zipSize = filesize("{$destinationPath}.zip");
101
  DirectoryTree::DeleteAllDirectoryFiles($destinationPath, true);
102
  return array($zipFileName, $zipSize);
103
  $installerBackupFile = "{$backupName}_wpclone";
104
  $installerBackupPath = WPCLONE_DIR_BACKUP . $installerBackupFile;
105
  $installerBackupFileZip = $installerBackupFile . '.zip';
106
  wpBackupFullCopy(rtrim(WPCLONE_INSTALLER_PATH, "/\\"), $installerBackupPath);
107
  $editBackupFilePath = $installerBackupPath . "/lib/file";
108
  $backupZipPath = convertPathIntoUrl(WPCLONE_DIR_BACKUP . $zipFileName);
109
  if (file_exists($editBackupFilePath)) {
110
  $search = 'class="Url" value=""';
111
  $replace = 'class="Url" value="' . $backupZipPath . '"';
112
  chdir($editBackupFilePath);
113
  DirectoryTree::openFileSearchAndReplace($editBackupFilePath, $search, $replace);
114
  !file_exists($installerBackupPath . '/lib/view.php') || unlink($installerBackupPath . '/lib/view.php');
115
  $copyFrom = $editBackupFilePath . '/view.php';
116
  $copyTo = $installerBackupPath . '/lib/view.php';
117
  DirectoryTree::CopyDirectory($copyFrom, $copyTo);
118
  }
119
  new WPbackupZip("{$installerBackupPath}.zip", $installerBackupPath, '.svn');
120
  DirectoryTree::DeleteAllDirectoryFiles($installerBackupPath, true);
121
  return $installerBackupFileZip;
122
 
123
  $zipFileObject = new ZipArchive;
124
  $response = true;
125
 
126
 
127
  if ( $zipFileObject->open($zipFilename) === TRUE ) {
128
 
129
  $zipFileObject->extractTo($destinationFolder);
130
  /* Remove htaccess file from directory. */
131
  $folder = pathinfo($zipFilename, PATHINFO_FILENAME);
132
  $htaccess = wpCloneSafePathMode($destinationFolder . $folder) . '/.htaccess';
133
  !(file_exists($htaccess)) || unlink($htaccess);
134
 
135
  }
136
  else {
137
  $response = false;
138
  }
139
  unset($zipFileObject);
140
  return $response;
141
  global $wpdb;
142
  $wp_backup = "{$wpdb->prefix}wpclone";
143
  $deleteRow = $wpdb->get_row("SELECT * FROM {$wp_backup} WHERE id = '{$nm}'");
144
  $wpdb->query("DELETE FROM {$wp_backup} WHERE id = '{$nm}' ");
145
  if (file_exists(WPCLONE_DIR_BACKUP . $deleteRow->backup_name)) unlink(WPCLONE_DIR_BACKUP . $deleteRow->backup_name) or die ('unable to delete backup file.');
146
  if (file_exists(WPCLONE_DIR_BACKUP . $deleteRow->installer_name)) @unlink(WPCLONE_DIR_BACKUP . $deleteRow->installer_name);
147
  return $deleteRow;
148
  $kilobyte = 1024;
149
  $megabyte = $kilobyte * 1024;
150
  $gigabyte = $megabyte * 1024;
151
  $terabyte = $gigabyte * 1024;
152
  if (($bytes >= 0) && ($bytes < $kilobyte)) {
153
  return $bytes . ' B';
154
  } elseif (($bytes >= $kilobyte) && ($bytes < $megabyte)) {
155
  return round($bytes / $kilobyte, $precision) . ' KB';
156
  } elseif (($bytes >= $megabyte) && ($bytes < $gigabyte)) {
157
  return round($bytes / $megabyte, $precision) . ' MB';
158
  } elseif (($bytes >= $gigabyte) && ($bytes < $terabyte)) {
159
  return round($bytes / $gigabyte, $precision) . ' GB';
160
  } elseif ($bytes >= $terabyte) {
161
  return round($bytes / $terabyte, $precision) . ' TB';
162
  } else {
163
  return $bytes . ' B';
164
  }
165
  $ext = strrchr($name, '.');
166
  if ($ext !== false) {
167
  $name = substr($name, 0, -strlen($ext));
168
  }
169
  return $name;
170
  function file_put_contents($filename, $data)
171
  {
172
  $f = @fopen($filename, 'w');
173
  if (!$f) {
174
  return false;
175
  } else {
176
  $bytes = fwrite($f, $data);
177
  fclose($f);
178
  return $bytes;
179
  }
180
  }
181
  *
182
  * @param string $filename
183
  * @return string
184
  */
185
  if (!function_exists('file_get_contents')) {
186
  $handle = fopen($filename, "r");
187
  $contents = fread($handle, filesize($filename));
188
  fclose($handle);
189
  } else {
190
  $contents = file_get_contents($filename);
191
  }
192
  return $contents;
193
  $dbInfo = array();
194
  $dbInfo["dbhost"] = DB_HOST;
195
  $dbInfo["dbname"] = DB_NAME;
196
  $dbInfo["dbuser"] = DB_USER;
197
  $dbInfo["dbpassword"] = DB_PASSWORD;
198
  return $dbInfo;
199
  $selectQuery = "SELECT COUNT(*) AS number_of_tables
200
  FROM information_schema.tables
201
  WHERE table_schema = '{$databaseName}'";
202
  $numOfTables = mysql_query($selectQuery, $dbConn);
203
  $numOfTables = mysql_fetch_assoc($numOfTables);
204
  return $numOfTables;
205
  $backupFileVariables = getVariablesFromFile($configInZipFile);
206
  $backupPrefix = $backupFileVariables["table_prefix"];
207
  replaceTablePrefix($currentConfigFile, $backupPrefix);
208
  return $backupPrefix;
209
  ob_start();
210
  include($filename);
211
  ob_end_clean();
212
  return get_defined_vars();
213
  $fileContent = file_get_contents($filename);
214
  $pos = strpos($fileContent, '$table_prefix');
215
  $str = substr($fileContent, $pos, strpos($fileContent, PHP_EOL, $pos) - $pos);
216
  $fileContent = str_replace($str, '$table_prefix = "' . $newPrefix . '";', $fileContent);
217
  file_put_contents($filename, $fileContent);
218
  $fileContent = file_get_contents($databaseFile, true);
219
  $pos = strpos($fileContent, 'siteurl') + 8;
220
  $urlStartPos = strpos($fileContent, '"', $pos) + 1;
221
  $urlEndPos = strpos($fileContent, '"', $urlStartPos);
222
  $backupSiteUrl = substr($fileContent, $urlStartPos, $urlEndPos - $urlStartPos);
223
  return $backupSiteUrl;
224
  /* Replacing backup site url with the current one. */
225
  $backupSiteUrl = replaceSiteUrlFromDatabaseFile($databaseFileInZip);
226
  $currentSiteUrl = site_url();
227
  $backupSiteUrl = wpa_trailing_slash_check($backupSiteUrl);
228
  $currentSiteUrl = wpa_trailing_slash_check($currentSiteUrl);
229
  $dbInfo = getDbInfo();
230
  $conn = mysql_connect($dbInfo['dbhost'], $dbInfo['dbuser'], $dbInfo['dbpassword']);
231
  mysql_select_db($dbInfo['dbname'], $conn) or die(mysql_error());
232
  $query = mysql_query("SHOW TABLES", $conn);
233
  while (($fetch = mysql_fetch_array($query))) {
234
  mysql_query("Drop table `{$fetch[0]}`") or die(mysql_error() . '<br> Acess denied');
235
  }
236
  $dbFileContent = file_get_contents($databaseFileInZip);
237
  $res = explode(";\n", $dbFileContent);
238
  flush();
239
  foreach ($res AS $query) {
240
  mysql_query($query, $conn);
241
  }
242
  wpa_safe_replace_wrapper ( $dbInfo['dbhost'], $dbInfo['dbuser'], $dbInfo['dbpassword'], $dbInfo['dbname'], $backupSiteUrl, $currentSiteUrl );
243
  mysql_close($conn);
244
  return $currentSiteUrl;
245
  *
246
  * @param type $host mysql host name,already defined in wp-config.php as DB_HOST.
247
  * @param type $user mysql username, "" DB_USER.
248
  * @param type $pass mysql password, "" DB_PASSWORD.
249
  * @param type $data mysql database name, "" DB_NAME.
250
  * @param type $search URL of the previous site.
251
  * @param type $replace URL of the current site.
252
  * @return type total time it took for the operation.
253
  */
254
  $connection = @mysql_connect( $host, $user, $pass );
255
  $all_tables = array( );
256
  @mysql_select_db( $data, $connection );
257
  $all_tables_mysql = @mysql_query( 'SHOW TABLES', $connection );
258
  if ( ! $all_tables_mysql ) {
259
  $errors[] = mysql_error( );
260
  } else {
261
  while ( $table = mysql_fetch_array( $all_tables_mysql ) ) {
262
  $all_tables[] = $table[ 0 ];
263
  }
264
  }
265
  $report = icit_srdb_replacer( $connection, $search, $replace, $all_tables );
266
  return $report;
267
  * Take a serialised array and unserialise it replacing elements as needed and
268
  * unserialising any subordinate arrays and performing the replace on those too.
269
  *
270
  * @param string $from String we're looking to replace.
271
  * @param string $to What we want it to be replaced with
272
  * @param array $data Used to pass any subordinate arrays back to in.
273
  * @param bool $serialised Does the array passed via $data need serialising.
274
  *
275
  * @return array The original array with all elements replaced as needed.
276
  */
277
  * The main loop triggered in step 5. Up here to keep it out of the way of the
278
  * HTML. This walks every table in the db that was selected in step 3 and then
279
  * walks every row and column replacing all occurences of a string with another.
280
  * We split large tables into 50,000 row blocks when dealing with them to save
281
  * on memmory consumption.
282
  *
283
  * @param mysql $connection The db connection object
284
  * @param string $search What we want to replace
285
  * @param string $replace What we want to replace it with.
286
  * @param array $tables The tables we want to look at.
287
  *
288
  * @return array Collection of information gathered during the run.
289
  */
290
  if (!is_string($url) || '' == $url) die('The provided path is not valid,aborting..');
291
 
292
  $pathParts = pathinfo($url);
293
  $urlDir = WPCLONE_DIR_BACKUP . 'url/';
294
  file_exists($urlDir) || mkdir($urlDir, WPBACKUP_FILE_PERMISSION);
295
 
296
  /* Copy the file found from url to plugin root */
297
  $zipFilename = $urlDir . $pathParts['basename'];
298
  DirectoryTree::CopyDirectory($url, $zipFilename);
299
  $result = wpa_unzip($zipFilename, WPCLONE_ROOT, $zipmode);
300
  if ($result) {
301
  $unzippedFolderPath = wpCloneSafePathMode(WPCLONE_ROOT . $pathParts['filename']);
302
  $old_db_prefix = $unzippedFolderPath . '/prefix.txt';
303
  $prefix = wpa_check_prefix($old_db_prefix);
304
  $databaseFile = $unzippedFolderPath . '/database.sql';
305
  if ($prefix) {
306
  wpa_replace_prefix( ABSPATH . 'wp-config.php', $prefix );
307
  }
308
 
309
  $currentSiteUrl = processConfigAndDatabaseFile($databaseFile);
310
  !file_exists($databaseFile) || unlink($databaseFile);
311
  !file_exists($old_db_prefix) || unlink($old_db_prefix);
312
  !file_exists($unzippedFolderPath . '/wp-config.php') || unlink($unzippedFolderPath . '/wp-config.php');
313
  wpa_copy($unzippedFolderPath, WPCLONE_ROOT);
314
  DirectoryTree::DeleteAllDirectoryFiles($unzippedFolderPath, true);
315
  echo "<h1>Restore Successful!</h1>";
316
  echo "Visit your restored site [ <a href='{$currentSiteUrl}' target=blank>here</a> ]<br><br>";
317
  echo "<strong>You may need to re-save your permalink structure <a href='{$currentSiteUrl}/wp-admin/options-permalink.php' target=blank>Here</a></strong>";
318
  } else {
319
  echo "<h1>Restore unsuccessful!!!</h1>";
320
  echo "Please try again.";
321
  }
322
  !file_exists($urlDir) || DirectoryTree::DeleteAllDirectoryFiles($urlDir, true);
323
  global $wpdb;
324
  $prefix = $wpdb->prefix;
325
  $file = $path . '/prefix.txt';
326
  if ( is_dir($path) && is_writable($path) ) {
327
  file_put_contents($file, $prefix);
328
  }
329
  * 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.
330
  *
331
  * @param type $file path to the prefix.txt file.
332
  * @return type bool string
333
  */
334
  global $wpdb;
335
  $prefix = $wpdb->prefix;
336
  if (file_exists($file) && is_readable($file)) {
337
  $old_prefix = file_get_contents($file);
338
  if ( $prefix !== $old_prefix ) {
339
  return $old_prefix;
340
  }
341
  else {
342
  return false;
343
  }
344
  }
345
  return false;
346
  * checks for a trailing slash at the end of the provided URL and strips it if found.
347
  * @param type $url
348
  * @return type
349
  */
350
  if (substr($url, -1) == "/" ) {
351
  $url = rtrim($url, "/");
352
  return $url;
353
  }
354
  else {
355
  return $url;
356
  }
357
  * @link http://davidwalsh.name/backup-mysql-database-php
358
  *
359
  * @param type $host
360
  * @param type $user
361
  * @param type $pass
362
  * @param type $name
363
  * @param type $tables
364
  */
365
  * @since 2.0.6
366
  *
367
  * @param type $zipfile path to the zip file that needs to be extracted.
368
  * @param type $path the place to where the file needs to be extracted.
369
  * @return as false in the event of failure.
370
  */
371
  if ( $zipmode || (!in_array('ZipArchive', get_declared_classes()) || !class_exists('ZipArchive')) ) {
372
  define('PCLZIP_TEMPORARY_DIR', WPCLONE_DIR_BACKUP);
373
  require_once ( ABSPATH . 'wp-admin/includes/class-pclzip.php' );
374
  $z = new PclZip($zipfile);
375
  if ($z->extract(PCLZIP_OPT_PATH, $path) == 0) {
376
  return false;
377
  }
378
  echo 'PclZip';
379
  return true;
380
  }
381
  else {
382
  $r = unzipBackupFile($zipfile, $path);
383
  return $r;
384
  }
385
  * @since 2.0.6
386
  *
387
  * @param type $name name of the zip file.
388
  * @param type $file_list an array of files that needs to be archived.
389
  */
390
  if ( $zipmode || (!in_array('ZipArchive', get_declared_classes()) || !class_exists('ZipArchive')) ) {
391
  define('PCLZIP_TEMPORARY_DIR', WPCLONE_DIR_BACKUP);
392
  require_once ( ABSPATH . 'wp-admin/includes/class-pclzip.php');
393
  $z = new PclZip($name);
394
  $v_list = $z->create($file_list, PCLZIP_OPT_REMOVE_PATH, WPCLONE_DIR_BACKUP);
395
  if ($v_list == 0) {
396
  die("Error : ".$z->errorInfo(true));
397
  }
398
  }
399
  else {
400
  new WPbackupZip($name, $file_list, '.svn');
401
  }
402
  * just a simple function to increase PHP limits.
403
  * @since 2.0.6
404
  */
405
  $time = isset($time) && $time != '' ? $time : 900;
406
  $mem = isset ($mem) && $mem != '' ? $mem . 'M' : '512M';
407
  @ini_set('memory_limit', $mem);
408
  @ini_set('max_execution_time', $time); //900 seconds = 15 minutes
409
  * @since 2.0.6
410
  */
411
  if (!empty($_REQUEST['del'])) {
412
  wpa_remove_backup();
413
  return true;
414
  }
415
  if (isset($_POST['createBackup'])) {
416
  wpa_create_backup();
417
  return true;
418
  }
419
  if (empty($_POST)) return false;
420
  check_admin_referer('wpclone-submit');
421
  $form_post = wp_nonce_url('admin.php?page=wp-clone');
422
  $extra_fields = array('restore_from_url', 'maxmem', 'maxexec', 'zipmode', 'restoreBackup');
423
  $type = '';
424
  if ( false === ($creds = request_filesystem_credentials($form_post, $type, false, false, $extra_fields)) ){
425
  return true;
426
  }
427
  if (!WP_Filesystem($creds)) {
428
  request_filesystem_credentials($form_post, $type, true, false, $extra_fields);
429
  return true;
430
  }
431
  wpa_bump_limits($_POST['maxmem'], $_POST['maxexec']);
432
  $url = isset($_POST['restoreBackup']) ? $_POST['restoreBackup'] : $_POST['restore_from_url'];
433
  $zipmode = isset($_POST['zipmode']) ? true : false;
434
  processRestoringBackup($url, $zipmode);
435
  return true;
436
  * @since 2.0.6
437
  */
438
  global $wp_filesystem;
439
  if (is_readable($source)) {
440
  if (is_dir($source)) {
441
  if (!strstr(wpCloneSafePathMode($source), rtrim(WPCLONE_DIR_BACKUP, "/\\"))) {
442
  if (!file_exists($target)) {
443
  $wp_filesystem->mkdir($target);
444
  }
445
  $d = dir($source);
446
  while (FALSE !== ($entry = $d->read())) {
447
  if ($entry == '.' || $entry == '..') {
448
  continue;
449
  }
450
  $Entry = "{$source}/{$entry}";
451
  if (is_dir($Entry)) {
452
  wpa_copy($Entry, $target . '/' . $entry);
453
  } else {
454
  $wp_filesystem->copy($Entry, $target . '/' . $entry, true, FS_CHMOD_FILE);
455
  }
456
  }
457
  $d->close();
458
  }
459
  }
460
  else {
461
  $wp_filesystem->copy($source, $target, true);
462
  }
463
  }
464
  * @since 2.0.6
465
  */
466
  if (!is_writable($filename)) die ("Unable to modify wp-config.php,please change the permissions to '0600'.Aborting..");
467
  global $wp_filesystem;
468
  $fileContent = file_get_contents($filename);
469
  $pos = strpos($fileContent, '$table_prefix');
470
  $str = substr($fileContent, $pos, strpos($fileContent, PHP_EOL, $pos) - $pos);
471
  $fileContent = str_replace($str, '$table_prefix = "' . $newPrefix . '";', $fileContent);
472
  $wp_filesystem->put_contents($filename, $fileContent, 0600);
473
  * @since 2.0.6
474
  */
475
  check_admin_referer('wpclone-submit');
476
  get_currentuserinfo();
477
  wpa_bump_limits($_POST['maxmem'], $_POST['maxexec']);
478
  $backupName = getBackupFileName();
479
  $zipmode = isset($_POST['zipmode']) ? true : false;
480
  list($zipFileName, $zipSize) = CreateWPFullBackupZip($backupName, $zipmode);
481
  InsertData($zipFileName, $zipSize);
482
  $backZipPath = convertPathIntoUrl(WPCLONE_DIR_BACKUP . $zipFileName);
483
  $zipSize = bytesToSize($zipSize);
484
  echo <<<EOF
485
  <a href='{$backZipPath}'><span>{$backZipPath}</span></a> ( {$zipSize} ) &nbsp;&nbsp;|&nbsp;&nbsp;
486
  <input type='hidden' name='backupUrl' class='backupUrl' value="{$backZipPath}" />
487
  <a class='copy-button' href='#'>Copy URL</a> &nbsp;<br /><br />
488
  (Copy that link and paste it into the "Restore URL" of your new WordPress installation to clone this site)
489
  * @since 2.0.6
490
  */
491
  $deleteRow = DeleteWPBackupZip($_REQUEST['del']);
492
  echo <<<EOT
493
  <h1>Deleted Successful!</h1> <br />
494
  {$deleteRow->backup_name} <br />
495
  File deleted from backup folder and database...
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');
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} ) &nbsp;&nbsp;|&nbsp;&nbsp;
488
  <input type='hidden' name='backupUrl' class='backupUrl' value="{$backZipPath}" />
489
  <a class='copy-button' href='#'>Copy URL</a> &nbsp;<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...
lib/js/ZeroClipboard.swf ADDED
Binary file
lib/js/backupmanager.js ADDED
@@ -0,0 +1,118 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ jQuery(function($) {
3
+
4
+ initialize();
5
+ bindActions();
6
+
7
+ function initialize() {
8
+ $("input[name$='backupChoice']").removeAttr('checked');
9
+ checkCreateBackupOption();
10
+ }
11
+
12
+ function bindActions() {
13
+
14
+ $("input[id='fullBackup']").click(function() {
15
+
16
+ $("#RestoreOptions").hide("fast");
17
+ $("#file_directory").hide("fast");
18
+ $("input[name$='createBackup']").attr('checked', true);
19
+ $("input[name$='backupUrl']").removeAttr('checked');
20
+ $("#backupChoices").show("fast");
21
+ $("input#submit").val("Create Backup");
22
+
23
+ });
24
+
25
+ $("input[id='customBackup']").click(function() {
26
+
27
+ $("#RestoreOptions").hide("fast");
28
+ $("#file_directory").show("fast");
29
+ $("input[name$='createBackup']").attr('checked', true);
30
+ $("input[name$='backupUrl']").removeAttr('checked');
31
+ $("#backupChoices").show("fast");
32
+ $("input#submit").val("Create Backup");
33
+
34
+ });
35
+
36
+ $("input[name$='createBackup']").click(function() {
37
+
38
+ $("#RestoreOptions").hide("fast");
39
+ $("input[name$='backupUrl']").attr('checked', false);
40
+ $("input[class$='restoreBackup']").each(function(){ $(this).attr('checked', false) });
41
+ checkCreateBackupOption();
42
+
43
+ });
44
+
45
+ $("input[class$='restoreBackup']").click(function() {
46
+
47
+ $("#RestoreOptions").show("fast");
48
+ $("input[name$='backupUrl']").attr('checked', false);
49
+ $(this).attr('checked', true);
50
+ unCheckCreateBackupOption();
51
+ $("input#submit").val("Restore backup");
52
+
53
+ });
54
+
55
+ $("input[name$='backupUrl']").click(function() {
56
+ prepareBackUrlOption();
57
+ });
58
+
59
+ $("input[name$='restore_from_url']").focus(function() {
60
+ prepareBackUrlOption();
61
+ });
62
+
63
+ $("input#submit").click(function() {
64
+
65
+ if ($('#backupUrl').is(':checked')) {
66
+
67
+ if ($("input[name$='restore_from_url']").val() == '') {
68
+ alert('Please enter the url you want to restore from.');
69
+ } else if (!$('#approve').is(':checked')) {
70
+ alert('Please confirm that you agree to our terms by checking "I AGREE (Required for "Restore" function):" checkbox.');
71
+ } else {
72
+ return getConfirmation('restore');
73
+ }
74
+
75
+ return false;
76
+
77
+ } else if ($('input[class$="restoreBackup"]').is(':checked')) {
78
+
79
+ if ($('#approve').is(':checked')) {
80
+ return getConfirmation('restore');
81
+ }
82
+
83
+ alert('Please confirm that you agree to our terms by checking "I AGREE (Required for "Restore" function):" checkbox.');
84
+ return false;
85
+
86
+ } else {
87
+ return getConfirmation('create backup');
88
+ }
89
+
90
+ function getConfirmation(toDo) {
91
+ return confirm('This may take a few minutes. Proceed to ' + toDo + ' now?');
92
+ }
93
+ });
94
+
95
+ function unCheckCreateBackupOption() {
96
+ $("input[name$='createBackup']").attr('checked', false);
97
+ $("#backupChoices").hide("fast");
98
+ }
99
+
100
+ function prepareBackUrlOption() {
101
+ $("#RestoreOptions").show("fast");
102
+ $("input[name$='backupUrl']").attr('checked', true);
103
+ $("input[class$='restoreBackup']").attr('checked', false);
104
+ unCheckCreateBackupOption();
105
+ $("input#submit").val('Restore from URL');
106
+ }
107
+
108
+ }
109
+
110
+ function checkCreateBackupOption() {
111
+ $("input[name$='createBackup']").attr('checked', true);
112
+ $("#backupChoices").show("fast");
113
+ $("input#submit").val("Create Backup");
114
+ $("input[id='fullBackup']").attr('checked',
115
+ $("input[name$='createBackup']").is(':checked') && !$("input[id$='customBackup']").is(':checked'));
116
+ }
117
+
118
+ });
lib/js/jquery.zclip.min.js ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * zClip :: jQuery ZeroClipboard v1.1.1
3
+ * http://steamdev.com/zclip
4
+ *
5
+ * Copyright 2011, SteamDev
6
+ * Released under the MIT license.
7
+ * http://www.opensource.org/licenses/mit-license.php
8
+ *
9
+ * Date: Wed Jun 01, 2011
10
+ */
11
+
12
+ (function(a){a.fn.zclip=function(c){if(typeof c=="object"&&!c.length){var b=a.extend({path:"ZeroClipboard.swf",copy:null,beforeCopy:null,afterCopy:null,clickAfter:true,setHandCursor:true,setCSSEffects:true},c);return this.each(function(){var e=a(this);if(e.is(":visible")&&(typeof b.copy=="string"||a.isFunction(b.copy))){ZeroClipboard.setMoviePath(b.path);var d=new ZeroClipboard.Client();if(a.isFunction(b.copy)){e.bind("zClip_copy",b.copy)}if(a.isFunction(b.beforeCopy)){e.bind("zClip_beforeCopy",b.beforeCopy)}if(a.isFunction(b.afterCopy)){e.bind("zClip_afterCopy",b.afterCopy)}d.setHandCursor(b.setHandCursor);d.setCSSEffects(b.setCSSEffects);d.addEventListener("mouseOver",function(f){e.trigger("mouseenter")});d.addEventListener("mouseOut",function(f){e.trigger("mouseleave")});d.addEventListener("mouseDown",function(f){e.trigger("mousedown");if(!a.isFunction(b.copy)){d.setText(b.copy)}else{d.setText(e.triggerHandler("zClip_copy"))}if(a.isFunction(b.beforeCopy)){e.trigger("zClip_beforeCopy")}});d.addEventListener("complete",function(f,g){if(a.isFunction(b.afterCopy)){e.trigger("zClip_afterCopy")}else{if(g.length>500){g=g.substr(0,500)+"...\n\n("+(g.length-500)+" characters not shown)"}e.removeClass("hover");alert("Copied text to clipboard:\n\n "+g)}if(b.clickAfter){e.trigger("click")}});d.glue(e[0],e.parent()[0]);a(window).bind("load resize",function(){d.reposition()})}})}else{if(typeof c=="string"){return this.each(function(){var f=a(this);c=c.toLowerCase();var e=f.data("zclipId");var d=a("#"+e+".zclip");if(c=="remove"){d.remove();f.removeClass("active hover")}else{if(c=="hide"){d.hide();f.removeClass("active hover")}else{if(c=="show"){d.show()}}}})}}}})(jQuery);var ZeroClipboard={version:"1.0.7",clients:{},moviePath:"ZeroClipboard.swf",nextId:1,jQuery:function(a){if(typeof(a)=="string"){a=document.getElementById(a)}if(!a.addClass){a.hide=function(){this.style.display="none"};a.show=function(){this.style.display=""};a.addClass=function(b){this.removeClass(b);this.className+=" "+b};a.removeClass=function(d){var e=this.className.split(/\s+/);var b=-1;for(var c=0;c<e.length;c++){if(e[c]==d){b=c;c=e.length}}if(b>-1){e.splice(b,1);this.className=e.join(" ")}return this};a.hasClass=function(b){return !!this.className.match(new RegExp("\\s*"+b+"\\s*"))}}return a},setMoviePath:function(a){this.moviePath=a},dispatch:function(d,b,c){var a=this.clients[d];if(a){a.receiveEvent(b,c)}},register:function(b,a){this.clients[b]=a},getDOMObjectPosition:function(c,a){var b={left:0,top:0,width:c.width?c.width:c.offsetWidth,height:c.height?c.height:c.offsetHeight};if(c&&(c!=a)){b.left+=c.offsetLeft;b.top+=c.offsetTop}return b},Client:function(a){this.handlers={};this.id=ZeroClipboard.nextId++;this.movieId="ZeroClipboardMovie_"+this.id;ZeroClipboard.register(this.id,this);if(a){this.glue(a)}}};ZeroClipboard.Client.prototype={id:0,ready:false,movie:null,clipText:"",handCursorEnabled:true,cssEffects:true,handlers:null,glue:function(d,b,e){this.domElement=ZeroClipboard.jQuery(d);var f=99;if(this.domElement.style.zIndex){f=parseInt(this.domElement.style.zIndex,10)+1}if(typeof(b)=="string"){b=ZeroClipboard.jQuery(b)}else{if(typeof(b)=="undefined"){b=document.getElementsByTagName("body")[0]}}var c=ZeroClipboard.getDOMObjectPosition(this.domElement,b);this.div=document.createElement("div");this.div.className="zclip";this.div.id="zclip-"+this.movieId;jQuery(this.domElement).data("zclipId","zclip-"+this.movieId);var a=this.div.style;a.position="absolute";a.left=""+c.left+"px";a.top=""+c.top+"px";a.width=""+c.width+"px";a.height=""+c.height+"px";a.zIndex=f;if(typeof(e)=="object"){for(addedStyle in e){a[addedStyle]=e[addedStyle]}}b.appendChild(this.div);this.div.innerHTML=this.getHTML(c.width,c.height)},getHTML:function(d,a){var c="";var b="id="+this.id+"&width="+d+"&height="+a;if(navigator.userAgent.match(/MSIE/)){var e=location.href.match(/^https/i)?"https://":"http://";c+='<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="'+e+'download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="'+d+'" height="'+a+'" id="'+this.movieId+'" align="middle"><param name="allowScriptAccess" value="always" /><param name="allowFullScreen" value="false" /><param name="movie" value="'+ZeroClipboard.moviePath+'" /><param name="loop" value="false" /><param name="menu" value="false" /><param name="quality" value="best" /><param name="bgcolor" value="#ffffff" /><param name="flashvars" value="'+b+'"/><param name="wmode" value="transparent"/></object>'}else{c+='<embed id="'+this.movieId+'" src="'+ZeroClipboard.moviePath+'" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="'+d+'" height="'+a+'" name="'+this.movieId+'" align="middle" allowScriptAccess="always" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="'+b+'" wmode="transparent" />'}return c},hide:function(){if(this.div){this.div.style.left="-2000px"}},show:function(){this.reposition()},destroy:function(){if(this.domElement&&this.div){this.hide();this.div.innerHTML="";var a=document.getElementsByTagName("body")[0];try{a.removeChild(this.div)}catch(b){}this.domElement=null;this.div=null}},reposition:function(c){if(c){this.domElement=ZeroClipboard.jQuery(c);if(!this.domElement){this.hide()}}if(this.domElement&&this.div){var b=ZeroClipboard.getDOMObjectPosition(this.domElement);var a=this.div.style;a.left=""+b.left+"px";a.top=""+b.top+"px"}},setText:function(a){this.clipText=a;if(this.ready){this.movie.setText(a)}},addEventListener:function(a,b){a=a.toString().toLowerCase().replace(/^on/,"");if(!this.handlers[a]){this.handlers[a]=[]}this.handlers[a].push(b)},setHandCursor:function(a){this.handCursorEnabled=a;if(this.ready){this.movie.setHandCursor(a)}},setCSSEffects:function(a){this.cssEffects=!!a},receiveEvent:function(d,f){d=d.toString().toLowerCase().replace(/^on/,"");switch(d){case"load":this.movie=document.getElementById(this.movieId);if(!this.movie){var c=this;setTimeout(function(){c.receiveEvent("load",null)},1);return}if(!this.ready&&navigator.userAgent.match(/Firefox/)&&navigator.userAgent.match(/Windows/)){var c=this;setTimeout(function(){c.receiveEvent("load",null)},100);this.ready=true;return}this.ready=true;try{this.movie.setText(this.clipText)}catch(h){}try{this.movie.setHandCursor(this.handCursorEnabled)}catch(h){}break;case"mouseover":if(this.domElement&&this.cssEffects){this.domElement.addClass("hover");if(this.recoverActive){this.domElement.addClass("active")}}break;case"mouseout":if(this.domElement&&this.cssEffects){this.recoverActive=false;if(this.domElement.hasClass("active")){this.domElement.removeClass("active");this.recoverActive=true}this.domElement.removeClass("hover")}break;case"mousedown":if(this.domElement&&this.cssEffects){this.domElement.addClass("active")}break;case"mouseup":if(this.domElement&&this.cssEffects){this.domElement.removeClass("active");this.recoverActive=false}break}if(this.handlers[d]){for(var b=0,a=this.handlers[d].length;b<a;b++){var g=this.handlers[d][b];if(typeof(g)=="function"){g(this,f)}else{if((typeof(g)=="object")&&(g.length==2)){g[0][g[1]](this,f)}else{if(typeof(g)=="string"){window[g](this,f)}}}}}}};
lib/view.php ADDED
@@ -0,0 +1,239 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script type="text/javascript">
2
+
3
+ var folders = <?php echo json_encode(DirectoryTree::getDirectoryFolders(rtrim(WPCLONE_ROOT, "/\\"), 2)); ?>;
4
+ var rootPath = '<?php echo dirname(rtrim(WPCLONE_ROOT, "/\\")) ?>';
5
+ var root = '<?php echo basename(rtrim(WPCLONE_ROOT, "/\\")) ?>';
6
+
7
+ jQuery(function($) {
8
+
9
+ var fileTree = buildDirectoryFolderTreeWithCheckBox(folders, root, rootPath);
10
+
11
+ fileTree.appendTo('#file_directory');
12
+
13
+ $('.directory-component').click(function() {
14
+ $(this).next().next().find('input[type="checkbox"]').attr('checked', $(this).is(':checked'));
15
+ if ($(this).parent().attr('id') == 'file_directory') {
16
+ return;
17
+ }
18
+
19
+ unCheckParent($(this));
20
+ function unCheckParent(element) {
21
+ if ($(element).parent().attr('id') == 'file_directory') {
22
+ return;
23
+ }
24
+
25
+ var parent = $(element).parent().parent().prev().prev().attr('checked', $(element).is(':checked')
26
+ && ! ($(element).parent().siblings("li").children("li > input[type='checkbox']").not(':checked').length));
27
+
28
+ if (parent.length) {
29
+ unCheckParent(parent);
30
+ }
31
+ }
32
+ });
33
+
34
+ $(".copy-button").zclip({
35
+ path: "<?php echo WPCLONE_URL_PLUGIN ?>lib/js/ZeroClipboard.swf",
36
+ copy: function(){
37
+ return $(this).prev().val();
38
+ }
39
+ });
40
+
41
+ $(".try pre.js").snippet("javascript",{
42
+ style:'print',
43
+ clipboard:'<?php echo WPCLONE_URL_PLUGIN ?>lib/js/ZeroClipboard.swf',
44
+ collapse:'true',
45
+ showMsg:'View Source Code',
46
+ hideMsg:'Hide Source Code'
47
+ });
48
+ $("pre.js").snippet("javascript",{
49
+ style:'print',
50
+ clipboard:'<?php echo WPCLONE_URL_PLUGIN ?>lib/js/ZeroClipboard.swf'
51
+ });
52
+ $("pre.html").snippet("html",{
53
+ style:'print',
54
+ clipboard:'<?php echo WPCLONE_URL_PLUGIN ?>lib/js/ZeroClipboard.swf'
55
+ });
56
+ $("pre.css").snippet("css",{
57
+ style:'print',
58
+ clipboard:'<?php echo WPCLONE_URL_PLUGIN ?>lib/js/ZeroClipboard.swf'
59
+ });
60
+
61
+ $('a#copy-description').zclip({
62
+ path:'<?php echo WPCLONE_URL_PLUGIN ?>lib/js/ZeroClipboard.swf',
63
+ copy:$('p#description').text()
64
+ });
65
+
66
+ $('a#copy-dynamic').zclip({
67
+ path:'<?php echo WPCLONE_URL_PLUGIN ?>lib/js/ZeroClipboard.swf',
68
+ copy:function(){
69
+ return $('input#dynamic').val();
70
+ }
71
+ });
72
+
73
+ function buildDirectoryFolderTreeWithCheckBox(files, folderName, path) {
74
+
75
+ var tree = $("<ul></ul>"), file, li;
76
+ for (file in files) {
77
+
78
+ if (typeof files[file] == "object") {
79
+
80
+ li = $('<li></li>').addClass('folder')
81
+ .append(buildDirectoryFolderTreeWithCheckBox(files[file], file, path+'/'+folderName));
82
+
83
+ }
84
+
85
+ tree.append(li);
86
+ }
87
+
88
+ return $('<input />').attr({'type': 'checkbox', 'class': 'directory-component',
89
+ 'name': 'directory_folders[]', 'value': path+'/'+folderName})
90
+ .after($('<span></span>').attr({'class': 'parent'}).html(folderName).click(function() {
91
+ $(this).parent().find('ul:first').toggle();
92
+ }))
93
+ .after(tree.hide());
94
+ }
95
+
96
+ });
97
+
98
+ </script>
99
+ <?php
100
+ if (wpa_wpfs_init()) return;
101
+ global $wpdb;
102
+
103
+ $result = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}wpclone ORDER BY id DESC", ARRAY_A);
104
+
105
+ ?>
106
+
107
+ <div class="MainView">
108
+
109
+ <h2>Welcome to WP Clone </h2>
110
+
111
+ <p>You can use this tool to create a backup of this site and (optionally) restore it to another server, or another WordPress installation on the same server.</p>
112
+
113
+ <p><strong>Here is how it works:</strong> the "Backup" function will give you a URL that you can then copy and paste
114
+ into the "Restore" dialog of a new WordPress site, which will clone the original site to the new site. You must
115
+ install the plugin on the new site and then run the WP Clone > Restore function.</p>
116
+
117
+ <p><a href="http://wpacademy.tv/wpclone-faq" target="_blank">Click here</a> for help. Commercial
118
+ license holders may also access support <a href="http://wpacademy.tv/wpclone-download" target="_blank">click
119
+ here</a>.</p>
120
+
121
+ <p><strong>Choose your selection below:</strong> either create a backup of this site, or choose which backup you
122
+ would like to restore.</p>
123
+
124
+ <p>&nbsp;</p>
125
+
126
+ <form id="backupForm" name="backupForm" action="#" method="post">
127
+ <?php
128
+ if ( isset($_GET['mode']) && 'advanced' == $_GET['mode'] ) { ?>
129
+ <div style="padding: 5px; margin: 5px; width: 530px; background: #fea;">
130
+ <table>
131
+ <tr align="left"><th><label for="zipmode">Alternate zip method</label></th><td colspan="2"><input type="checkbox" name="zipmode" value="alt" /></td></tr>
132
+ <tr align="left"><th><label for="maxmem">Maximum memory limit</label></th><td colspan="2"><input type="text" name="maxmem" /></td></tr>
133
+ <tr align="left"><th><label for="maxexec">Script execution time</label></th><td><input type="text" name="maxexec" /></td></tr>
134
+ </table>
135
+ </div>
136
+ <?php
137
+ }
138
+ ?>
139
+ <strong>Create Backup</strong>
140
+ <input id="createBackup" name="createBackup" type="radio" value="fullBackup"/><br/><br/>
141
+ <!-- <div style="padding-left: 50px" id="backupChoices">-->
142
+ <!-- <strong>Full Backup</strong>-->
143
+ <!-- <input id="fullBackup" name="backupChoice" type="radio" value="fullBackup"/><br/>-->
144
+ <!---->
145
+ <!--<!--<!-- <strong>Custom Backup</strong> <input id="customBackup" name="backupChoice" type="radio" value="customBackup"/><br/>-->
146
+ <!--<!--<!-- <div id="file_directory"></div>-->
147
+ <!-- </div>-->
148
+
149
+ <?php if (count($result) > 0) : ?>
150
+
151
+ <div class="try">
152
+
153
+ <?php foreach ($result AS $row) :
154
+
155
+ $filename = convertPathIntoUrl(WPCLONE_DIR_BACKUP . $row['backup_name']) ?>
156
+
157
+ <div class="restore-backup-options">
158
+ <strong>Restore backup </strong>
159
+
160
+ <input class="restoreBackup" name="restoreBackup" type="radio"
161
+ value="<?php echo $filename ?>" />&nbsp;
162
+
163
+ <a href="<?php echo $filename ?>">
164
+ (&nbsp;<?php echo bytesToSize($row['backup_size']);?>&nbsp;)&nbsp; <?php echo $row['backup_name'] ?>
165
+ </a>&nbsp;|&nbsp;
166
+
167
+ <input type="hidden" name="backup_name" value="<?php echo $filename ?>" />
168
+
169
+ <a class="copy-button" href="#">Copy URL</a> &nbsp;|&nbsp;
170
+ <a href="<?php echo site_url()?>/wp-admin/options-general.php?page=wp-clone&del=<?php echo $row['id'];?>">Delete</a>
171
+ </div>
172
+
173
+ <?php endforeach ?>
174
+
175
+ </div>
176
+
177
+ <?php endif ?>
178
+
179
+ <strong>Restore from URl:</strong><input id="backupUrl" name="backupUrl" type="radio" value="backupUrl"/>
180
+
181
+ <input type="text" name="restore_from_url" class="Url" value="" size="80px"/><br/><br/>
182
+
183
+ <div class="RestoreOptions" id="RestoreOptions">
184
+
185
+ <input type="checkbox" name="approve" id="approve" /> I AGREE (Required for "Restore" function):<br/>
186
+
187
+ 1. You have nothing of value in your current site <strong>[<?php echo site_url() ?>]</strong><br/>
188
+
189
+ 2. Your current site at <strong>[<?php echo site_url() ?>]</strong> may become unusable in case of failure,
190
+ and you will need to re-install WordPress<br/>
191
+
192
+ <?php
193
+
194
+ require_once(WPCLONE_ROOT . "wp-config.php");
195
+
196
+ $dbInfo = getDbInfo(get_defined_vars());
197
+
198
+ ?>
199
+
200
+ 3. Your WordPress database <strong>[<?php if (isset($dbInfo['dbname'])) {
201
+ echo $dbInfo['dbname'];
202
+ }?>]</strong> will be overwritten from the database in the backup file. <br/>
203
+
204
+ </div>
205
+
206
+ <input id="submit" name="submit" class="button-primary" type="submit" value="Create Backup"/>
207
+ <?php wp_nonce_field('wpclone-submit')?>
208
+ </form>
209
+
210
+ </div>
211
+
212
+ <?php
213
+ if ( isset($_GET['mode']) && 'advanced' == $_GET['mode'] ) {
214
+ global $wpdb;
215
+ echo '<div style="padding: 5px; margin: 5px; width: 530px; background: #fea;">';
216
+ echo '<h3>System Info:</h3>';
217
+ echo 'Memory limit: ' . ini_get('memory_limit') . '</br>';
218
+ echo 'Maximum execution time: ' . ini_get('max_execution_time') . ' seconds</br>';
219
+ echo 'PHP version : ' . phpversion() . '</br>';
220
+ echo 'MySQL version : ' . $wpdb->db_version() . '</br>';
221
+ if (ini_get('safe_mode')) { echo '<span style="color:#f11">PHP is running in safemode!</span></br>'; }
222
+ echo '<h4>Directory list:</h4>';
223
+ echo 'Uploads path : <pre>' . WPCLONE_DIR_UPLOADS . '</pre></br>';
224
+ echo 'Plugin path : <pre>' . WPCLONE_DIR_PLUGIN . '</pre></br>';
225
+ echo 'Plugin URL : <pre>' . WPCLONE_URL_PLUGIN . '</pre></br>';
226
+ echo 'Backup path : <pre>' . WPCLONE_DIR_BACKUP . '</pre></br>';
227
+ echo 'wp-content path : <pre>' . WPCLONE_WP_CONTENT . '</pre></br>';
228
+ echo 'Site Root : <pre>' . WPCLONE_ROOT . '</pre></br>';
229
+ if (!is_writable(WPCLONE_DIR_BACKUP)) { echo '<span style="color:#f11">Cannot write to the backup directory!</span></br>'; }
230
+ if (!is_writable(WPCLONE_ROOT)) { echo '<span style="color:#f11">Cannot write to the root directory!</span></br>'; }
231
+ echo '</div>';
232
+ }
233
+
234
+ if(!isset($_GET['mode'])){
235
+ $link = get_bloginfo('wpurl') . '/wp-admin/admin.php?page=wp-clone&mode=advanced';
236
+ echo "<p style='padding:5px;'><a href='{$link}' style='margin-top:10px'>Advanced Settings</a></p>";
237
+ }
238
+
239
+
readme.txt ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === WP Clone by WP Academy ===
2
+ Contributors: wpacademy
3
+ Donate link: http://wpacademy.com/software
4
+ Tags: wp academy, wpacademy, move wordpress, copy wordpress, clone wordpress, install wordpress, wordpress hosting, backup, restore
5
+ Author URI: http://wpacademy.com
6
+ Plugin URI: http://wpacademy.com/software
7
+ Requires at least: 3.0
8
+ Tested up to: 3.5
9
+ Stable tag: 2.0.9
10
+ License: GPLv2 or later
11
+ License URI: http://www.gnu.org/licenses/gpl-2.0.html
12
+
13
+ Move or copy a WordPress site to another server or to another domain name, move to/from local server hosting, and backup sites.
14
+
15
+ == Description ==
16
+
17
+ WP Clone is the easiest, fastest and most secure way to move or copy a WordPress site to another domain or hosting server. You can also use it to move your site to/from local server hosting, to create copies of your site for development or testing purposes, to backup your site, and to install pre-configured versions of WordPress.
18
+
19
+ WP Clone is a superior solution to even commercial WordPress cloning plugins for the following reasons:
20
+
21
+ * Does not require FTP access to either the source or destination site &ndash; just install a new WordPress on the destination site, upload and activate WP Clone plugin, and follow the prompts
22
+ * It does not backup or restore the WordPress system files (just the user content and database) &ndash; reducing upload time and improving security of your site
23
+ * It fetches the site backup via your host&apos;s direct http connection, which saves you from needing to upload large files through your internet connection
24
+ * It uses the WordPress internal zip archive function, which makes it compatible with virtually 100% of hosts that support WordPress (no special PHP libraries are required)
25
+
26
+ = Help Video =
27
+ [youtube http://www.youtube.com/watch?feature=player_embedded&v=dqpv2VjLCSY]
28
+
29
+ = Please donate to support plugin development & ongoing support =
30
+ WP Clone is provided free of charge to the community and supported through the plugin forums on WordPress.org. Please help defray our development expenses and help with support costs through the [Donations Page](http://wpacademy.com/software "Donations page")
31
+ Donation page.
32
+
33
+ = Additional documentation =
34
+ Additional documentation, including supported hosts, at the [WP Clone FAQ Page](http://wpacademy.tv/wpclone-faq "WP Clone FAQ")
35
+
36
+ = Other contributors =
37
+ WP Clone uses functions from the "Safe Search and Replace on Database with Serialized Data" script first written by David Coveney of Interconnect IT Ltd (UK) http://www.davidcoveney.com or http://www.interconnectit.com and
38
+ released under the WTFPL http://sam.zoy.org/wtfpl/. Partial script with full changelog is placed inside 'lib/files' directory.
39
+
40
+
41
+ == Installation ==
42
+
43
+ 1. Navigate to Plugins > Add New
44
+ 2. Search for "WP Clone"
45
+ 3. Install and activate the plugin
46
+ 4. Follow remaining instructions in the help video
47
+
48
+ == Frequently Asked Questions ==
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.0.6 - 2012-08-05 =
53
+ * Added: WP Filesystem integration
54
+ * Added: Alternate zip method for better compatibility with hosts that haven't enabled PHP's zip extension
55
+
56
+ = 2.0.5 - 2012-06-25 =
57
+ * Fixed: A secondary search and replace that was corrupting serialized entries
58
+
59
+ = 2.0.3 - 2012-05-16 =
60
+ * Fixed: ignoring trailing slashes in the site URLs
61
+
62
+ = 2.0.2 - 2012-04-12 =
63
+ * Initial release
wpclone.php ADDED
@@ -0,0 +1,118 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ 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.0.9
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
+
17
+ define('WPBACKUP_VERSION', '1.0.0');
18
+ define('WPBACKUP_DB_VERSION', '1.0.0');
19
+ define('WPBACKUP_REQUIRED_WP_VERSION', '3.0');
20
+ define('WPBACKUP_FILE_PERMISSION', 0755);
21
+ define('WPCLONE_ROOT', rtrim(str_replace("\\", "/", ABSPATH), "/\\") . '/');
22
+ define('WPCLONE_BACKUP_FOLDER', 'wp-clone');
23
+ define('WPCLONE_DIR_UPLOADS', str_replace('\\', '/', $upload_dir['basedir']));
24
+ define('WPCLONE_DIR_PLUGIN', str_replace('\\', '/', plugin_dir_path(__FILE__)));
25
+ define('WPCLONE_URL_PLUGIN', plugin_dir_url(__FILE__));
26
+ define('WPCLONE_DIR_CONFIG', WPCLONE_ROOT.'wp-content/uploads/conf/');
27
+ define('WPCLONE_DIR_BACKUP', WPCLONE_DIR_UPLOADS . '/' .WPCLONE_BACKUP_FOLDER . '/');
28
+ define('WPCLONE_INSTALLER_PATH', WPCLONE_DIR_PLUGIN);
29
+ define('WPCLONE_WP_CONTENT' , str_replace('\\', '/', WP_CONTENT_DIR));
30
+
31
+
32
+ // Init options & tables during activation & deregister init option
33
+
34
+ register_activation_hook((__FILE__), 'wpa_wpclone_activate');
35
+ register_deactivation_hook(__FILE__ , 'wpa_wpclone_deactivate');
36
+ add_action('admin_menu', 'wpclone_plugin_menu');
37
+
38
+ function wpclone_plugin_menu() {
39
+ add_menu_page (
40
+ 'WP Clone Plugin Options',
41
+ 'WP Clone',
42
+ 'manage_options',
43
+ 'wp-clone',
44
+ 'wpclone_plugin_options'
45
+ );
46
+ }
47
+
48
+ function wpclone_plugin_options() {
49
+ include_once 'lib/view.php';
50
+ }
51
+
52
+ function wpa_enqueue_scripts(){
53
+ wp_register_script('jquery-zclip', plugin_dir_url(__FILE__) . '/lib/js/jquery.zclip.min.js', array('jquery'));
54
+ wp_register_script('wpclone', plugin_dir_url(__FILE__) . '/lib/js/backupmanager.js', array('jquery'));
55
+ wp_register_style('wpclone', plugin_dir_url(__FILE__) . '/lib/css/style.css');
56
+ wp_enqueue_script('jquery-zclip');
57
+ wp_enqueue_script('wpclone');
58
+ wp_enqueue_style('wpclone');
59
+ }
60
+ if( isset($_GET['page']) && 'wp-clone' == $_GET['page'] ) add_action('admin_enqueue_scripts', 'wpa_enqueue_scripts');
61
+
62
+ function wpa_wpclone_activate() {
63
+ global $wpdb;
64
+ wpa_create_directory();
65
+ wpa_install_database();
66
+ if (file_exists(WPCLONE_DIR_BACKUP . '.htaccess')) { unlink (WPCLONE_DIR_BACKUP . '.htaccess'); }
67
+ }
68
+
69
+ function wpa_wpclone_deactivate() {
70
+ //removing the table
71
+ global $wpdb;
72
+ $wp_backup = $wpdb->prefix . 'wpclone';
73
+ $wpdb->query ("DROP TABLE IF EXISTS $wp_backup");
74
+ $data = "<Files>\r\n\tOrder allow,deny\r\n\tDeny from all\r\n\tSatisfy all\r\n</Files>";
75
+ $file = WPCLONE_DIR_BACKUP . '.htaccess';
76
+ file_put_contents($file, $data);
77
+ }
78
+
79
+
80
+ function wpa_create_directory() {
81
+ $upload_dir = wp_upload_dir();
82
+ $indexFile = (WPCLONE_DIR_BACKUP.'index.html');
83
+ $directoryPath = "wp-clone";
84
+ if (!file_exists($indexFile)) {
85
+ if(!file_exists(WPCLONE_DIR_BACKUP)) {
86
+ if(!mkdir(WPCLONE_DIR_BACKUP, WPBACKUP_FILE_PERMISSION)) {
87
+ die("Unable to create directory '" . rtrim(WPCLONE_DIR_BACKUP, "/\\"). "'. Please set 0755 permission to wp-content.");
88
+ }
89
+ }
90
+ mkdir(WPCLONE_DIR_CONFIG, WPBACKUP_FILE_PERMISSION);
91
+ $handle = fopen($indexFile, "w");
92
+ fclose($handle);
93
+ }
94
+ }
95
+
96
+ function wpa_install_database() {
97
+ global $wpdb , $wp_roles, $wp_version;
98
+ require_once(WPCLONE_ROOT . 'wp-admin/upgrade-functions.php');
99
+ // add charset & collate like wp core
100
+ $charset_collate = '';
101
+ if ( version_compare(mysql_get_server_info(), '4.1.0', '>=') ) {
102
+ if ( ! empty($wpdb->charset) )
103
+ $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
104
+ if ( ! empty($wpdb->collate) )
105
+ $charset_collate .= " COLLATE $wpdb->collate";
106
+ }
107
+ $wp_backup = $wpdb->prefix . 'wpclone';
108
+ // could be case senstive : http://dev.mysql.com/doc/refman/5.1/en/identifier-case-sensitivity.html
109
+ if( !$wpdb->get_var( "SHOW TABLES LIKE '{$wp_backup}'" ) ) {
110
+ $sql = "CREATE TABLE {$wp_backup} (
111
+ id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
112
+ backup_name VARCHAR(250) NOT NULL,
113
+ backup_size INT (11),
114
+ data_time DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
115
+ creator VARCHAR(60) NOT NULL) $charset_collate;";
116
+ dbDelta($sql);
117
+ }
118
+ }