WP Clone by WP Academy - Version 2.1

Version Description

  • 2012-12-25 = *Added: WP Academy sidebar.
Download this release

Release Info

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

Code changes from version 2.0.9 to 2.1

Files changed (6) hide show
  1. lib/css/style.css +92 -27
  2. lib/functions.php +1 -1
  3. lib/js/backupmanager.js +5 -3
  4. lib/view.php +62 -100
  5. readme.txt +4 -1
  6. wpclone.php +1 -1
lib/css/style.css CHANGED
@@ -1,50 +1,115 @@
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
  }
1
+ #wrapper {
2
+ padding: 10px 0;
3
  }
4
 
5
+ #MainView {
6
+ padding: 10px;
7
+ width: 800px;
8
+ float: left;
9
+ border-radius: 5px;
10
  }
11
 
12
+ #sidebar {
13
+ float: left;
14
  }
15
 
16
+ #MainView h2 {
17
+ padding-bottom: 10px;
 
 
18
  }
19
 
20
+ #sidebar ul {
21
+ max-width: 300px;
22
+ padding: 10px 10px 10px 30px;
23
+ margin-left: 5px;
24
+ border: 1px solid #bbb;
25
+ border-radius: 5px;
26
+ list-style: disc;
27
+ -moz-box-shadow: 5px 5px 15px #aaa;
28
+ -webkit-box-shadow: 5px 5px 15px #aaa;
29
+ box-shadow: 5px 5px 15px #aaa;
30
  }
31
 
32
+ #sidebar ul h2 {
33
+ border-bottom: 5px solid #ccc;
34
+ padding-bottom: 10px;
35
+ text-shadow: 5px 5px 10px #888;
36
+ filter: dropshadow(color=#888, offx=5, offy=5);
37
  }
38
 
39
+ #sidebar ul h3 {
40
+ border-bottom: 2px solid #ccc;
41
+ padding: 10px 0 5px 0;
42
  }
43
 
44
+ #backupForm #create-backup-option {
45
+ margin-bottom: 5px;
46
  }
47
 
48
+ #RestoreOptions, #file_directory {
49
+ display: none;
50
  }
51
 
52
+ div.info {
53
+ padding: 15px;
54
+ margin: 30px 0;
55
+ width: 530px;
56
+ background: #fea;
57
+ border-radius: 5px;
58
+ -moz-box-shadow: 5px 5px 15px #aaa;
59
+ -webkit-box-shadow: 5px 5px 15px #aaa;
60
+ box-shadow: 5px 5px 15px #aaa;
61
  }
62
 
63
  div.try .restore-backup-options {
64
  display: block;
65
+ }
66
+
67
+ .btn-primary.active, .btn-warning.active, .btn-danger.active, .btn-success.active, .btn-info.active, .btn-inverse.active {
68
+ color: rgba(255, 255, 255, 0.75);
69
+ }
70
+
71
+ .btn {
72
+ border-color: rgba(0, 0, 0, 0.15) rgba(0, 0, 0, 0.15) rgba(0, 0, 0, 0.25);
73
+ margin: 20px 0;
74
+ padding: 15px 30px;
75
+ font-size: 1.5em;
76
+ font-weight: bold;
77
+ }
78
+
79
+ input[type="submit"].btn-primary {
80
+ background-color: #006DCC;
81
+ background-image: -moz-linear-gradient(top, #0088CC, #0044CC);
82
+ background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#0088CC), to(#0044CC));
83
+ background-image: -webkit-linear-gradient(top, #0088CC, #0044CC);
84
+ background-image: -o-linear-gradient(top, #0088CC, #0044CC);
85
+ background-image: linear-gradient(to bottom, #0088CC, #0044CC);
86
+ background-repeat: repeat-x;
87
+ border-color: rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.25);
88
+ color: #FFFFFF;
89
+ text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.25);
90
+ }
91
+
92
+ input[type="submit"].btn-primary:hover, input[type="submit"].btn-primary:active, .btn-primary.active, .btn-primary.disabled, .btn-primary[disabled] {
93
+ background-color: #0044CC;
94
+ color: #EEEEEE;
95
+ }
96
+ .btn-primary:active, .btn-primary.active {
97
+ }
98
+ input[type="submit"].btn-warning {
99
+ background-color: #FAA732;
100
+ background-image: linear-gradient(to bottom, #FBB450, #F89406);
101
+ background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#FBB450), to(#F89406));
102
+ background-image: -webkit-linear-gradient(top, #FBB450, #F89406);
103
+ background-image: -o-linear-gradient(top, #FBB450, #F89406);
104
+ background-image: linear-gradient(to bottom, #FBB450, #F89406);
105
+ background-repeat: repeat-x;
106
+ border-color: rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.25);
107
+ color: #FFFFFF;
108
+ text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.25);
109
+ }
110
+ input[type="submit"].btn-warning:hover, input[type="submit"].btn-warning:active, .btn-warning.active, .btn-warning.disabled, .btn-warning[disabled] {
111
+ background-color: #F89406;
112
+ color: #EEEEEE;
113
+ }
114
+ .btn-warning:active, .btn-warning.active {
115
  }
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');
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...
 
498
  $backupName = date('Y-m-d-H-i-s') . '_' . get_bloginfo('name', 'display');
499
  $backupName = substr(str_replace(' ', '', $backupName), 0, 40);
500
  $backupName = sanitize_file_name($backupName);
501
  return $backupName;
502
  return str_replace("\\", "/", $path);
503
  return rtrim(str_replace("//", "/", wpCloneSafePathMode($path)), '/') . '/';
504
  return str_replace(rtrim(WPCLONE_ROOT, "/\\"), site_url(), $path);
505
  return str_replace(site_url(), rtrim(WPCLONE_ROOT, "/\\"), $url);
506
  if (is_readable($source)) {
507
  if (is_dir($source)) {
508
  if (!strstr(wpCloneSafePathMode($source), rtrim(WPCLONE_DIR_BACKUP, "/\\"))) {
509
  if (!file_exists($target)) {
510
  mkdir($target, WPBACKUP_FILE_PERMISSION);
511
  }
512
  $d = dir($source);
513
  while (FALSE !== ($entry = $d->read())) {
514
  if ($entry == '.' || $entry == '..') {
515
  continue;
516
  }
517
  $Entry = "{$source}/{$entry}";
518
  if (is_dir($Entry)) {
519
  wpBackupFullCopy($Entry, $target . '/' . $entry);
520
  } else {
521
  @ copy($Entry, $target . '/' . $entry);
522
  }
523
  }
524
  $d->close();
525
  }
526
  } else {
527
  copy($source, $target);
528
  }
529
  }
530
  global $wpdb;
531
  $WPCLONE_DB_ICONV_IN = "UTF-8";
532
  $WPCLONE_DB_ICONV_OUT = "ISO-8859-1//TRANSLIT";
533
  $return = '';
534
  // Get all of the tables
535
  $tables = $wpdb->get_col('SHOW TABLES');
536
  // Cycle through each provided table
537
  foreach ($tables as $table) {
538
  // First part of the output � remove the table
539
  $result = $wpdb->get_results("SELECT * FROM {$table}", ARRAY_N);
540
  $numberOfFields = count($result[0]);
541
  $numberOfItems = count($result);
542
  // Second part of the output � create table
543
  $row2 = $wpdb->get_row("SHOW CREATE TABLE {$table}", ARRAY_N);
544
  $return .= "\n\n" . $row2[1] . ";\n\n";
545
  // Third part of the output � insert values into new table
546
  for ($currentRowNumber = 0; $currentRowNumber < $numberOfItems; $currentRowNumber++) {
547
  $row = $result[$currentRowNumber];
548
  $query = "INSERT INTO {$table} VALUES(";
549
  for ($j = 0; $j < $numberOfFields; $j++) {
550
  $row[$j] = iconv($WPCLONE_DB_ICONV_IN, $WPCLONE_DB_ICONV_OUT, $row[$j]);
551
  $query .= (empty($row[$j])) ? '"", ' : '"' . mysql_real_escape_string($row[$j]) . '", ';
552
  }
553
  $return .= substr($query, 0, -2) . ");\n";
554
  }
555
  $return .= "\n";
556
  }
557
  // Generate the filename for the sql file
558
  $File_open = fopen($destination . '/database.sql', 'w+');
559
  // Save the sql file
560
  fwrite($File_open, $return);
561
  //file close
562
  fclose($File_open);
563
  $wpdb->flush();
564
  global $wpdb;
565
  global $current_user;
566
  $wpdb->insert($wpdb->prefix . "wpclone", array(
567
  'backup_name' => $name,
568
  'data_time' => current_time('mysql', get_option('gmt_offset')),
569
  'creator' => $current_user->user_login,
570
  'backup_size' => $size)
571
  );
572
  $wpdb->flush;
573
  $folderToBeZipped = WPCLONE_DIR_BACKUP . $backupName;
574
  $destinationPath = $folderToBeZipped . '/' . basename(WPCLONE_WP_CONTENT);
575
  $zipFileName = $backupName . '.zip';
576
  DirectoryTree::createDirectory($destinationPath);
577
  wpBackupFullCopy(rtrim(WPCLONE_WP_CONTENT, "/\\"), $destinationPath);
578
  wpa_save_prefix($folderToBeZipped);
579
  dw_backup_tables(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME, $folderToBeZipped);
580
  wpa_zip("{$folderToBeZipped}.zip", $folderToBeZipped, $zipmode);
581
  $zipSize = filesize("{$folderToBeZipped}.zip");
582
  DirectoryTree::DeleteAllDirectoryFiles($folderToBeZipped, true);
583
  return array($zipFileName, $zipSize);
584
  $backupDirectory = rtrim(WPCLONE_DIR_BACKUP, "/\\");
585
  $key = array_search($backupDirectory, $directoryFiles);
586
  if ($directoryFiles[$key] === $backupDirectory) {
587
  unset($directoryFiles[$key]);
588
  }
589
  $destinationPath = WPCLONE_DIR_BACKUP . $backupName;
590
  $zipFileName = $backupName . '.zip';
591
  mkdir($destinationPath, WPBACKUP_FILE_PERMISSION);
592
  foreach($directoryFiles AS $directoryFolder) {
593
  $destinationFolder = str_replace(rtrim(WPCLONE_ROOT, "/\\"), $destinationPath, $directoryFolder);
594
  wpBackupFullCopy($directoryFolder, $destinationFolder);
595
  }
596
  CreateDb($destinationPath);
597
  wpa_zip("{$destinationPath}.zip", $destinationPath);
598
  $zipSize = filesize("{$destinationPath}.zip");
599
  DirectoryTree::DeleteAllDirectoryFiles($destinationPath, true);
600
  return array($zipFileName, $zipSize);
601
  $installerBackupFile = "{$backupName}_wpclone";
602
  $installerBackupPath = WPCLONE_DIR_BACKUP . $installerBackupFile;
603
  $installerBackupFileZip = $installerBackupFile . '.zip';
604
  wpBackupFullCopy(rtrim(WPCLONE_INSTALLER_PATH, "/\\"), $installerBackupPath);
605
  $editBackupFilePath = $installerBackupPath . "/lib/file";
606
  $backupZipPath = convertPathIntoUrl(WPCLONE_DIR_BACKUP . $zipFileName);
607
  if (file_exists($editBackupFilePath)) {
608
  $search = 'class="Url" value=""';
609
  $replace = 'class="Url" value="' . $backupZipPath . '"';
610
  chdir($editBackupFilePath);
611
  DirectoryTree::openFileSearchAndReplace($editBackupFilePath, $search, $replace);
612
  !file_exists($installerBackupPath . '/lib/view.php') || unlink($installerBackupPath . '/lib/view.php');
613
  $copyFrom = $editBackupFilePath . '/view.php';
614
  $copyTo = $installerBackupPath . '/lib/view.php';
615
  DirectoryTree::CopyDirectory($copyFrom, $copyTo);
616
  }
617
  new WPbackupZip("{$installerBackupPath}.zip", $installerBackupPath, '.svn');
618
  DirectoryTree::DeleteAllDirectoryFiles($installerBackupPath, true);
619
  return $installerBackupFileZip;
620
 
621
  $zipFileObject = new ZipArchive;
622
  $response = true;
623
 
624
 
625
  if ( $zipFileObject->open($zipFilename) === TRUE ) {
626
 
627
  $zipFileObject->extractTo($destinationFolder);
628
  /* Remove htaccess file from directory. */
629
  $folder = pathinfo($zipFilename, PATHINFO_FILENAME);
630
  $htaccess = wpCloneSafePathMode($destinationFolder . $folder) . '/.htaccess';
631
  !(file_exists($htaccess)) || unlink($htaccess);
632
 
633
  }
634
  else {
635
  $response = false;
636
  }
637
  unset($zipFileObject);
638
  return $response;
639
  global $wpdb;
640
  $wp_backup = "{$wpdb->prefix}wpclone";
641
  $deleteRow = $wpdb->get_row("SELECT * FROM {$wp_backup} WHERE id = '{$nm}'");
642
  $wpdb->query("DELETE FROM {$wp_backup} WHERE id = '{$nm}' ");
643
  if (file_exists(WPCLONE_DIR_BACKUP . $deleteRow->backup_name)) unlink(WPCLONE_DIR_BACKUP . $deleteRow->backup_name) or die ('unable to delete backup file.');
644
  if (file_exists(WPCLONE_DIR_BACKUP . $deleteRow->installer_name)) @unlink(WPCLONE_DIR_BACKUP . $deleteRow->installer_name);
645
  return $deleteRow;
646
  $kilobyte = 1024;
647
  $megabyte = $kilobyte * 1024;
648
  $gigabyte = $megabyte * 1024;
649
  $terabyte = $gigabyte * 1024;
650
  if (($bytes >= 0) && ($bytes < $kilobyte)) {
651
  return $bytes . ' B';
652
  } elseif (($bytes >= $kilobyte) && ($bytes < $megabyte)) {
653
  return round($bytes / $kilobyte, $precision) . ' KB';
654
  } elseif (($bytes >= $megabyte) && ($bytes < $gigabyte)) {
655
  return round($bytes / $megabyte, $precision) . ' MB';
656
  } elseif (($bytes >= $gigabyte) && ($bytes < $terabyte)) {
657
  return round($bytes / $gigabyte, $precision) . ' GB';
658
  } elseif ($bytes >= $terabyte) {
659
  return round($bytes / $terabyte, $precision) . ' TB';
660
  } else {
661
  return $bytes . ' B';
662
  }
663
  $ext = strrchr($name, '.');
664
  if ($ext !== false) {
665
  $name = substr($name, 0, -strlen($ext));
666
  }
667
  return $name;
668
  function file_put_contents($filename, $data)
669
  {
670
  $f = @fopen($filename, 'w');
671
  if (!$f) {
672
  return false;
673
  } else {
674
  $bytes = fwrite($f, $data);
675
  fclose($f);
676
  return $bytes;
677
  }
678
  }
679
  *
680
  * @param string $filename
681
  * @return string
682
  */
683
  if (!function_exists('file_get_contents')) {
684
  $handle = fopen($filename, "r");
685
  $contents = fread($handle, filesize($filename));
686
  fclose($handle);
687
  } else {
688
  $contents = file_get_contents($filename);
689
  }
690
  return $contents;
691
  $dbInfo = array();
692
  $dbInfo["dbhost"] = DB_HOST;
693
  $dbInfo["dbname"] = DB_NAME;
694
  $dbInfo["dbuser"] = DB_USER;
695
  $dbInfo["dbpassword"] = DB_PASSWORD;
696
  return $dbInfo;
697
  $selectQuery = "SELECT COUNT(*) AS number_of_tables
698
  FROM information_schema.tables
699
  WHERE table_schema = '{$databaseName}'";
700
  $numOfTables = mysql_query($selectQuery, $dbConn);
701
  $numOfTables = mysql_fetch_assoc($numOfTables);
702
  return $numOfTables;
703
  $backupFileVariables = getVariablesFromFile($configInZipFile);
704
  $backupPrefix = $backupFileVariables["table_prefix"];
705
  replaceTablePrefix($currentConfigFile, $backupPrefix);
706
  return $backupPrefix;
707
  ob_start();
708
  include($filename);
709
  ob_end_clean();
710
  return get_defined_vars();
711
  $fileContent = file_get_contents($filename);
712
  $pos = strpos($fileContent, '$table_prefix');
713
  $str = substr($fileContent, $pos, strpos($fileContent, PHP_EOL, $pos) - $pos);
714
  $fileContent = str_replace($str, '$table_prefix = "' . $newPrefix . '";', $fileContent);
715
  file_put_contents($filename, $fileContent);
716
  $fileContent = file_get_contents($databaseFile, true);
717
  $pos = strpos($fileContent, 'siteurl') + 8;
718
  $urlStartPos = strpos($fileContent, '"', $pos) + 1;
719
  $urlEndPos = strpos($fileContent, '"', $urlStartPos);
720
  $backupSiteUrl = substr($fileContent, $urlStartPos, $urlEndPos - $urlStartPos);
721
  return $backupSiteUrl;
722
  /* Replacing backup site url with the current one. */
723
  $backupSiteUrl = replaceSiteUrlFromDatabaseFile($databaseFileInZip);
724
  $currentSiteUrl = site_url();
725
  $backupSiteUrl = wpa_trailing_slash_check($backupSiteUrl);
726
  $currentSiteUrl = wpa_trailing_slash_check($currentSiteUrl);
727
  $dbInfo = getDbInfo();
728
  $conn = mysql_connect($dbInfo['dbhost'], $dbInfo['dbuser'], $dbInfo['dbpassword']);
729
  mysql_select_db($dbInfo['dbname'], $conn) or die(mysql_error());
730
  $query = mysql_query("SHOW TABLES", $conn);
731
  while (($fetch = mysql_fetch_array($query))) {
732
  mysql_query("Drop table `{$fetch[0]}`") or die(mysql_error() . '<br> Acess denied');
733
  }
734
  $dbFileContent = file_get_contents($databaseFileInZip);
735
  $res = explode(";\n", $dbFileContent);
736
  flush();
737
  foreach ($res AS $query) {
738
  mysql_query($query, $conn);
739
  }
740
  wpa_safe_replace_wrapper ( $dbInfo['dbhost'], $dbInfo['dbuser'], $dbInfo['dbpassword'], $dbInfo['dbname'], $backupSiteUrl, $currentSiteUrl );
741
  mysql_close($conn);
742
  return $currentSiteUrl;
743
  *
744
  * @param type $host mysql host name,already defined in wp-config.php as DB_HOST.
745
  * @param type $user mysql username, "" DB_USER.
746
  * @param type $pass mysql password, "" DB_PASSWORD.
747
  * @param type $data mysql database name, "" DB_NAME.
748
  * @param type $search URL of the previous site.
749
  * @param type $replace URL of the current site.
750
  * @return type total time it took for the operation.
751
  */
752
  $connection = @mysql_connect( $host, $user, $pass );
753
  $all_tables = array( );
754
  @mysql_select_db( $data, $connection );
755
  $all_tables_mysql = @mysql_query( 'SHOW TABLES', $connection );
756
  if ( ! $all_tables_mysql ) {
757
  $errors[] = mysql_error( );
758
  } else {
759
  while ( $table = mysql_fetch_array( $all_tables_mysql ) ) {
760
  $all_tables[] = $table[ 0 ];
761
  }
762
  }
763
  $report = icit_srdb_replacer( $connection, $search, $replace, $all_tables );
764
  return $report;
765
  * Take a serialised array and unserialise it replacing elements as needed and
766
  * unserialising any subordinate arrays and performing the replace on those too.
767
  *
768
  * @param string $from String we're looking to replace.
769
  * @param string $to What we want it to be replaced with
770
  * @param array $data Used to pass any subordinate arrays back to in.
771
  * @param bool $serialised Does the array passed via $data need serialising.
772
  *
773
  * @return array The original array with all elements replaced as needed.
774
  */
775
  * The main loop triggered in step 5. Up here to keep it out of the way of the
776
  * HTML. This walks every table in the db that was selected in step 3 and then
777
  * walks every row and column replacing all occurences of a string with another.
778
  * We split large tables into 50,000 row blocks when dealing with them to save
779
  * on memmory consumption.
780
  *
781
  * @param mysql $connection The db connection object
782
  * @param string $search What we want to replace
783
  * @param string $replace What we want to replace it with.
784
  * @param array $tables The tables we want to look at.
785
  *
786
  * @return array Collection of information gathered during the run.
787
  */
788
  if (!is_string($url) || '' == $url) die('The provided path is not valid,aborting..');
789
 
790
  $pathParts = pathinfo($url);
791
  $urlDir = WPCLONE_DIR_BACKUP . 'url/';
792
  file_exists($urlDir) || mkdir($urlDir, WPBACKUP_FILE_PERMISSION);
793
 
794
  /* Copy the file found from url to plugin root */
795
  $zipFilename = $urlDir . $pathParts['basename'];
796
  DirectoryTree::CopyDirectory($url, $zipFilename);
797
  $result = wpa_unzip($zipFilename, WPCLONE_ROOT, $zipmode);
798
  if ($result) {
799
  $unzippedFolderPath = wpCloneSafePathMode(WPCLONE_ROOT . $pathParts['filename']);
800
  $old_db_prefix = $unzippedFolderPath . '/prefix.txt';
801
  $prefix = wpa_check_prefix($old_db_prefix);
802
  $databaseFile = $unzippedFolderPath . '/database.sql';
803
  if ($prefix) {
804
  wpa_replace_prefix( ABSPATH . 'wp-config.php', $prefix );
805
  }
806
 
807
  $currentSiteUrl = processConfigAndDatabaseFile($databaseFile);
808
  !file_exists($databaseFile) || unlink($databaseFile);
809
  !file_exists($old_db_prefix) || unlink($old_db_prefix);
810
  !file_exists($unzippedFolderPath . '/wp-config.php') || unlink($unzippedFolderPath . '/wp-config.php');
811
  wpa_copy($unzippedFolderPath, WPCLONE_ROOT);
812
  DirectoryTree::DeleteAllDirectoryFiles($unzippedFolderPath, true);
813
  echo "<h1>Restore Successful!</h1>";
814
  echo "Visit your restored site [ <a href='{$currentSiteUrl}' target=blank>here</a> ]<br><br>";
815
  echo "<strong>You may need to re-save your permalink structure <a href='{$currentSiteUrl}/wp-admin/options-permalink.php' target=blank>Here</a></strong>";
816
  } else {
817
  echo "<h1>Restore unsuccessful!!!</h1>";
818
  echo "Please try again.";
819
  }
820
  !file_exists($urlDir) || DirectoryTree::DeleteAllDirectoryFiles($urlDir, true);
821
  global $wpdb;
822
  $prefix = $wpdb->prefix;
823
  $file = $path . '/prefix.txt';
824
  if ( is_dir($path) && is_writable($path) ) {
825
  file_put_contents($file, $prefix);
826
  }
827
  * 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.
828
  *
829
  * @param type $file path to the prefix.txt file.
830
  * @return type bool string
831
  */
832
  global $wpdb;
833
  $prefix = $wpdb->prefix;
834
  if (file_exists($file) && is_readable($file)) {
835
  $old_prefix = file_get_contents($file);
836
  if ( $prefix !== $old_prefix ) {
837
  return $old_prefix;
838
  }
839
  else {
840
  return false;
841
  }
842
  }
843
  return false;
844
  * checks for a trailing slash at the end of the provided URL and strips it if found.
845
  * @param type $url
846
  * @return type
847
  */
848
  if (substr($url, -1) == "/" ) {
849
  $url = rtrim($url, "/");
850
  return $url;
851
  }
852
  else {
853
  return $url;
854
  }
855
  * @link http://davidwalsh.name/backup-mysql-database-php
856
  *
857
  * @param type $host
858
  * @param type $user
859
  * @param type $pass
860
  * @param type $name
861
  * @param type $tables
862
  */
863
  * @since 2.0.6
864
  *
865
  * @param type $zipfile path to the zip file that needs to be extracted.
866
  * @param type $path the place to where the file needs to be extracted.
867
  * @return as false in the event of failure.
868
  */
869
  if ( $zipmode || (!in_array('ZipArchive', get_declared_classes()) || !class_exists('ZipArchive')) ) {
870
  define('PCLZIP_TEMPORARY_DIR', WPCLONE_DIR_BACKUP);
871
  require_once ( ABSPATH . 'wp-admin/includes/class-pclzip.php' );
872
  $z = new PclZip($zipfile);
873
  if ($z->extract(PCLZIP_OPT_PATH, $path) == 0) {
874
  return false;
875
  }
876
  echo 'PclZip';
877
  return true;
878
  }
879
  else {
880
  $r = unzipBackupFile($zipfile, $path);
881
  return $r;
882
  }
883
  * @since 2.0.6
884
  *
885
  * @param type $name name of the zip file.
886
  * @param type $file_list an array of files that needs to be archived.
887
  */
888
  if ( $zipmode || (!in_array('ZipArchive', get_declared_classes()) || !class_exists('ZipArchive')) ) {
889
  define('PCLZIP_TEMPORARY_DIR', WPCLONE_DIR_BACKUP);
890
  require_once ( ABSPATH . 'wp-admin/includes/class-pclzip.php');
891
  $z = new PclZip($name);
892
  $v_list = $z->create($file_list, PCLZIP_OPT_REMOVE_PATH, WPCLONE_DIR_BACKUP);
893
  if ($v_list == 0) {
894
  die("Error : ".$z->errorInfo(true));
895
  }
896
  }
897
  else {
898
  new WPbackupZip($name, $file_list, '.svn');
899
  }
900
  * just a simple function to increase PHP limits.
901
  * @since 2.0.6
902
  */
903
  $time = isset($time) && $time != '' ? $time : 900;
904
  $mem = isset ($mem) && $mem != '' ? $mem . 'M' : '512M';
905
  @ini_set('memory_limit', $mem);
906
  @ini_set('max_execution_time', $time); //900 seconds = 15 minutes
907
  * @since 2.0.6
908
  */
909
  if (!empty($_REQUEST['del'])) {
910
  wpa_remove_backup();
911
  return true;
912
  }
913
  if (isset($_POST['createBackup'])) {
914
  wpa_create_backup();
915
  return true;
916
  }
917
  if (empty($_POST)) return false;
918
  check_admin_referer('wpclone-submit');
919
  $form_post = wp_nonce_url('admin.php?page=wp-clone');
920
  $extra_fields = array('restore_from_url', 'maxmem', 'maxexec', 'zipmode', 'restoreBackup');
921
  $type = '';
922
  if ( false === ($creds = request_filesystem_credentials($form_post, $type, false, false, $extra_fields)) ){
923
  return true;
924
  }
925
  if (!WP_Filesystem($creds)) {
926
  request_filesystem_credentials($form_post, $type, true, false, $extra_fields);
927
  return true;
928
  }
929
  wpa_bump_limits($_POST['maxmem'], $_POST['maxexec']);
930
  $url = isset($_POST['restoreBackup']) ? $_POST['restoreBackup'] : $_POST['restore_from_url'];
931
  $zipmode = isset($_POST['zipmode']) ? true : false;
932
  processRestoringBackup($url, $zipmode);
933
  return true;
934
  * @since 2.0.6
935
  */
936
  global $wp_filesystem;
937
  if (is_readable($source)) {
938
  if (is_dir($source)) {
939
  if (!strstr(wpCloneSafePathMode($source), rtrim(WPCLONE_DIR_BACKUP, "/\\"))) {
940
  if (!file_exists($target)) {
941
  $wp_filesystem->mkdir($target);
942
  }
943
  $d = dir($source);
944
  while (FALSE !== ($entry = $d->read())) {
945
  if ($entry == '.' || $entry == '..') {
946
  continue;
947
  }
948
  $Entry = "{$source}/{$entry}";
949
  if (is_dir($Entry)) {
950
  wpa_copy($Entry, $target . '/' . $entry);
951
  } else {
952
  $wp_filesystem->copy($Entry, $target . '/' . $entry, true, FS_CHMOD_FILE);
953
  }
954
  }
955
  $d->close();
956
  }
957
  }
958
  else {
959
  $wp_filesystem->copy($source, $target, true);
960
  }
961
  }
962
  * @since 2.0.6
963
  */
964
  if (!is_writable($filename)) die ("Unable to modify wp-config.php,please change the permissions to '0600'.Aborting..");
965
  global $wp_filesystem;
966
  $fileContent = file_get_contents($filename);
967
  $pos = strpos($fileContent, '$table_prefix');
968
  $str = substr($fileContent, $pos, strpos($fileContent, PHP_EOL, $pos) - $pos);
969
  $fileContent = str_replace($str, '$table_prefix = "' . $newPrefix . '";', $fileContent);
970
  $wp_filesystem->put_contents($filename, $fileContent, 0600);
971
  * @since 2.0.6
972
  */
973
  check_admin_referer('wpclone-submit');
974
  get_currentuserinfo();
975
  wpa_bump_limits($_POST['maxmem'], $_POST['maxexec']);
976
  $backupName = getBackupFileName();
977
  $zipmode = isset($_POST['zipmode']) ? true : false;
978
  list($zipFileName, $zipSize) = CreateWPFullBackupZip($backupName, $zipmode);
979
  InsertData($zipFileName, $zipSize);
980
  $backZipPath = convertPathIntoUrl(WPCLONE_DIR_BACKUP . $zipFileName);
981
  $zipSize = bytesToSize($zipSize);
982
  echo <<<EOF
983
  <a href='{$backZipPath}'><span>{$backZipPath}</span></a> ( {$zipSize} ) &nbsp;&nbsp;|&nbsp;&nbsp;
984
  <input type='hidden' name='backupUrl' class='backupUrl' value="{$backZipPath}" />
985
  <a class='copy-button' href='#'>Copy URL</a> &nbsp;<br /><br />
986
  (Copy that link and paste it into the "Restore URL" of your new WordPress installation to clone this site)
987
  * @since 2.0.6
988
  */
989
  $deleteRow = DeleteWPBackupZip($_REQUEST['del']);
990
  echo <<<EOT
991
  <h1>Deleted Successful!</h1> <br />
992
  {$deleteRow->backup_name} <br />
993
  File deleted from backup folder and database...
 
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');
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} ) &nbsp;&nbsp;|&nbsp;&nbsp;
487
  <input type='hidden' name='backupUrl' class='backupUrl' value="{$backZipPath}" />
488
  <a class='copy-button' href='#'>Copy URL</a> &nbsp;<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
  $backupName = date('Y-m-d-H-i-s') . '_' . get_bloginfo('name', 'display');
499
  $backupName = substr(str_replace(' ', '', $backupName), 0, 40);
500
  $backupName = sanitize_file_name($backupName);
501
  return $backupName;
502
  return str_replace("\\", "/", $path);
503
  return rtrim(str_replace("//", "/", wpCloneSafePathMode($path)), '/') . '/';
504
  return str_replace(rtrim(WPCLONE_ROOT, "/\\"), site_url(), $path);
505
  return str_replace(site_url(), rtrim(WPCLONE_ROOT, "/\\"), $url);
506
  if (is_readable($source)) {
507
  if (is_dir($source)) {
508
  if (!strstr(wpCloneSafePathMode($source), rtrim(WPCLONE_DIR_BACKUP, "/\\"))) {
509
  if (!file_exists($target)) {
510
  mkdir($target, WPBACKUP_FILE_PERMISSION);
511
  }
512
  $d = dir($source);
513
  while (FALSE !== ($entry = $d->read())) {
514
  if ($entry == '.' || $entry == '..') {
515
  continue;
516
  }
517
  $Entry = "{$source}/{$entry}";
518
  if (is_dir($Entry)) {
519
  wpBackupFullCopy($Entry, $target . '/' . $entry);
520
  } else {
521
  @ copy($Entry, $target . '/' . $entry);
522
  }
523
  }
524
  $d->close();
525
  }
526
  } else {
527
  copy($source, $target);
528
  }
529
  }
530
  global $wpdb;
531
  $WPCLONE_DB_ICONV_IN = "UTF-8";
532
  $WPCLONE_DB_ICONV_OUT = "ISO-8859-1//TRANSLIT";
533
  $return = '';
534
  // Get all of the tables
535
  $tables = $wpdb->get_col('SHOW TABLES');
536
  // Cycle through each provided table
537
  foreach ($tables as $table) {
538
  // First part of the output � remove the table
539
  $result = $wpdb->get_results("SELECT * FROM {$table}", ARRAY_N);
540
  $numberOfFields = count($result[0]);
541
  $numberOfItems = count($result);
542
  // Second part of the output � create table
543
  $row2 = $wpdb->get_row("SHOW CREATE TABLE {$table}", ARRAY_N);
544
  $return .= "\n\n" . $row2[1] . ";\n\n";
545
  // Third part of the output � insert values into new table
546
  for ($currentRowNumber = 0; $currentRowNumber < $numberOfItems; $currentRowNumber++) {
547
  $row = $result[$currentRowNumber];
548
  $query = "INSERT INTO {$table} VALUES(";
549
  for ($j = 0; $j < $numberOfFields; $j++) {
550
  $row[$j] = iconv($WPCLONE_DB_ICONV_IN, $WPCLONE_DB_ICONV_OUT, $row[$j]);
551
  $query .= (empty($row[$j])) ? '"", ' : '"' . mysql_real_escape_string($row[$j]) . '", ';
552
  }
553
  $return .= substr($query, 0, -2) . ");\n";
554
  }
555
  $return .= "\n";
556
  }
557
  // Generate the filename for the sql file
558
  $File_open = fopen($destination . '/database.sql', 'w+');
559
  // Save the sql file
560
  fwrite($File_open, $return);
561
  //file close
562
  fclose($File_open);
563
  $wpdb->flush();
564
  global $wpdb;
565
  global $current_user;
566
  $wpdb->insert($wpdb->prefix . "wpclone", array(
567
  'backup_name' => $name,
568
  'data_time' => current_time('mysql', get_option('gmt_offset')),
569
  'creator' => $current_user->user_login,
570
  'backup_size' => $size)
571
  );
572
  $wpdb->flush;
573
  $folderToBeZipped = WPCLONE_DIR_BACKUP . $backupName;
574
  $destinationPath = $folderToBeZipped . '/' . basename(WPCLONE_WP_CONTENT);
575
  $zipFileName = $backupName . '.zip';
576
  DirectoryTree::createDirectory($destinationPath);
577
  wpBackupFullCopy(rtrim(WPCLONE_WP_CONTENT, "/\\"), $destinationPath);
578
  wpa_save_prefix($folderToBeZipped);
579
  dw_backup_tables(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME, $folderToBeZipped);
580
  wpa_zip("{$folderToBeZipped}.zip", $folderToBeZipped, $zipmode);
581
  $zipSize = filesize("{$folderToBeZipped}.zip");
582
  DirectoryTree::DeleteAllDirectoryFiles($folderToBeZipped, true);
583
  return array($zipFileName, $zipSize);
584
  $backupDirectory = rtrim(WPCLONE_DIR_BACKUP, "/\\");
585
  $key = array_search($backupDirectory, $directoryFiles);
586
  if ($directoryFiles[$key] === $backupDirectory) {
587
  unset($directoryFiles[$key]);
588
  }
589
  $destinationPath = WPCLONE_DIR_BACKUP . $backupName;
590
  $zipFileName = $backupName . '.zip';
591
  mkdir($destinationPath, WPBACKUP_FILE_PERMISSION);
592
  foreach($directoryFiles AS $directoryFolder) {
593
  $destinationFolder = str_replace(rtrim(WPCLONE_ROOT, "/\\"), $destinationPath, $directoryFolder);
594
  wpBackupFullCopy($directoryFolder, $destinationFolder);
595
  }
596
  CreateDb($destinationPath);
597
  wpa_zip("{$destinationPath}.zip", $destinationPath);
598
  $zipSize = filesize("{$destinationPath}.zip");
599
  DirectoryTree::DeleteAllDirectoryFiles($destinationPath, true);
600
  return array($zipFileName, $zipSize);
601
  $installerBackupFile = "{$backupName}_wpclone";
602
  $installerBackupPath = WPCLONE_DIR_BACKUP . $installerBackupFile;
603
  $installerBackupFileZip = $installerBackupFile . '.zip';
604
  wpBackupFullCopy(rtrim(WPCLONE_INSTALLER_PATH, "/\\"), $installerBackupPath);
605
  $editBackupFilePath = $installerBackupPath . "/lib/file";
606
  $backupZipPath = convertPathIntoUrl(WPCLONE_DIR_BACKUP . $zipFileName);
607
  if (file_exists($editBackupFilePath)) {
608
  $search = 'class="Url" value=""';
609
  $replace = 'class="Url" value="' . $backupZipPath . '"';
610
  chdir($editBackupFilePath);
611
  DirectoryTree::openFileSearchAndReplace($editBackupFilePath, $search, $replace);
612
  !file_exists($installerBackupPath . '/lib/view.php') || unlink($installerBackupPath . '/lib/view.php');
613
  $copyFrom = $editBackupFilePath . '/view.php';
614
  $copyTo = $installerBackupPath . '/lib/view.php';
615
  DirectoryTree::CopyDirectory($copyFrom, $copyTo);
616
  }
617
  new WPbackupZip("{$installerBackupPath}.zip", $installerBackupPath, '.svn');
618
  DirectoryTree::DeleteAllDirectoryFiles($installerBackupPath, true);
619
  return $installerBackupFileZip;
620
 
621
  $zipFileObject = new ZipArchive;
622
  $response = true;
623
 
624
 
625
  if ( $zipFileObject->open($zipFilename) === TRUE ) {
626
 
627
  $zipFileObject->extractTo($destinationFolder);
628
  /* Remove htaccess file from directory. */
629
  $folder = pathinfo($zipFilename, PATHINFO_FILENAME);
630
  $htaccess = wpCloneSafePathMode($destinationFolder . $folder) . '/.htaccess';
631
  !(file_exists($htaccess)) || unlink($htaccess);
632
 
633
  }
634
  else {
635
  $response = false;
636
  }
637
  unset($zipFileObject);
638
  return $response;
639
  global $wpdb;
640
  $wp_backup = "{$wpdb->prefix}wpclone";
641
  $deleteRow = $wpdb->get_row("SELECT * FROM {$wp_backup} WHERE id = '{$nm}'");
642
  $wpdb->query("DELETE FROM {$wp_backup} WHERE id = '{$nm}' ");
643
  if (file_exists(WPCLONE_DIR_BACKUP . $deleteRow->backup_name)) unlink(WPCLONE_DIR_BACKUP . $deleteRow->backup_name) or die ('unable to delete backup file.');
644
  if (file_exists(WPCLONE_DIR_BACKUP . $deleteRow->installer_name)) @unlink(WPCLONE_DIR_BACKUP . $deleteRow->installer_name);
645
  return $deleteRow;
646
  $kilobyte = 1024;
647
  $megabyte = $kilobyte * 1024;
648
  $gigabyte = $megabyte * 1024;
649
  $terabyte = $gigabyte * 1024;
650
  if (($bytes >= 0) && ($bytes < $kilobyte)) {
651
  return $bytes . ' B';
652
  } elseif (($bytes >= $kilobyte) && ($bytes < $megabyte)) {
653
  return round($bytes / $kilobyte, $precision) . ' KB';
654
  } elseif (($bytes >= $megabyte) && ($bytes < $gigabyte)) {
655
  return round($bytes / $megabyte, $precision) . ' MB';
656
  } elseif (($bytes >= $gigabyte) && ($bytes < $terabyte)) {
657
  return round($bytes / $gigabyte, $precision) . ' GB';
658
  } elseif ($bytes >= $terabyte) {
659
  return round($bytes / $terabyte, $precision) . ' TB';
660
  } else {
661
  return $bytes . ' B';
662
  }
663
  $ext = strrchr($name, '.');
664
  if ($ext !== false) {
665
  $name = substr($name, 0, -strlen($ext));
666
  }
667
  return $name;
668
  function file_put_contents($filename, $data)
669
  {
670
  $f = @fopen($filename, 'w');
671
  if (!$f) {
672
  return false;
673
  } else {
674
  $bytes = fwrite($f, $data);
675
  fclose($f);
676
  return $bytes;
677
  }
678
  }
679
  *
680
  * @param string $filename
681
  * @return string
682
  */
683
  if (!function_exists('file_get_contents')) {
684
  $handle = fopen($filename, "r");
685
  $contents = fread($handle, filesize($filename));
686
  fclose($handle);
687
  } else {
688
  $contents = file_get_contents($filename);
689
  }
690
  return $contents;
691
  $dbInfo = array();
692
  $dbInfo["dbhost"] = DB_HOST;
693
  $dbInfo["dbname"] = DB_NAME;
694
  $dbInfo["dbuser"] = DB_USER;
695
  $dbInfo["dbpassword"] = DB_PASSWORD;
696
  return $dbInfo;
697
  $selectQuery = "SELECT COUNT(*) AS number_of_tables
698
  FROM information_schema.tables
699
  WHERE table_schema = '{$databaseName}'";
700
  $numOfTables = mysql_query($selectQuery, $dbConn);
701
  $numOfTables = mysql_fetch_assoc($numOfTables);
702
  return $numOfTables;
703
  $backupFileVariables = getVariablesFromFile($configInZipFile);
704
  $backupPrefix = $backupFileVariables["table_prefix"];
705
  replaceTablePrefix($currentConfigFile, $backupPrefix);
706
  return $backupPrefix;
707
  ob_start();
708
  include($filename);
709
  ob_end_clean();
710
  return get_defined_vars();
711
  $fileContent = file_get_contents($filename);
712
  $pos = strpos($fileContent, '$table_prefix');
713
  $str = substr($fileContent, $pos, strpos($fileContent, PHP_EOL, $pos) - $pos);
714
  $fileContent = str_replace($str, '$table_prefix = "' . $newPrefix . '";', $fileContent);
715
  file_put_contents($filename, $fileContent);
716
  $fileContent = file_get_contents($databaseFile, true);
717
  $pos = strpos($fileContent, 'siteurl') + 8;
718
  $urlStartPos = strpos($fileContent, '"', $pos) + 1;
719
  $urlEndPos = strpos($fileContent, '"', $urlStartPos);
720
  $backupSiteUrl = substr($fileContent, $urlStartPos, $urlEndPos - $urlStartPos);
721
  return $backupSiteUrl;
722
  /* Replacing backup site url with the current one. */
723
  $backupSiteUrl = replaceSiteUrlFromDatabaseFile($databaseFileInZip);
724
  $currentSiteUrl = site_url();
725
  $backupSiteUrl = wpa_trailing_slash_check($backupSiteUrl);
726
  $currentSiteUrl = wpa_trailing_slash_check($currentSiteUrl);
727
  $dbInfo = getDbInfo();
728
  $conn = mysql_connect($dbInfo['dbhost'], $dbInfo['dbuser'], $dbInfo['dbpassword']);
729
  mysql_select_db($dbInfo['dbname'], $conn) or die(mysql_error());
730
  $query = mysql_query("SHOW TABLES", $conn);
731
  while (($fetch = mysql_fetch_array($query))) {
732
  mysql_query("Drop table `{$fetch[0]}`") or die(mysql_error() . '<br> Acess denied');
733
  }
734
  $dbFileContent = file_get_contents($databaseFileInZip);
735
  $res = explode(";\n", $dbFileContent);
736
  flush();
737
  foreach ($res AS $query) {
738
  mysql_query($query, $conn);
739
  }
740
  wpa_safe_replace_wrapper ( $dbInfo['dbhost'], $dbInfo['dbuser'], $dbInfo['dbpassword'], $dbInfo['dbname'], $backupSiteUrl, $currentSiteUrl );
741
  mysql_close($conn);
742
  return $currentSiteUrl;
743
  *
744
  * @param type $host mysql host name,already defined in wp-config.php as DB_HOST.
745
  * @param type $user mysql username, "" DB_USER.
746
  * @param type $pass mysql password, "" DB_PASSWORD.
747
  * @param type $data mysql database name, "" DB_NAME.
748
  * @param type $search URL of the previous site.
749
  * @param type $replace URL of the current site.
750
  * @return type total time it took for the operation.
751
  */
752
  $connection = @mysql_connect( $host, $user, $pass );
753
  $all_tables = array( );
754
  @mysql_select_db( $data, $connection );
755
  $all_tables_mysql = @mysql_query( 'SHOW TABLES', $connection );
756
  if ( ! $all_tables_mysql ) {
757
  $errors[] = mysql_error( );
758
  } else {
759
  while ( $table = mysql_fetch_array( $all_tables_mysql ) ) {
760
  $all_tables[] = $table[ 0 ];
761
  }
762
  }
763
  $report = icit_srdb_replacer( $connection, $search, $replace, $all_tables );
764
  return $report;
765
  * Take a serialised array and unserialise it replacing elements as needed and
766
  * unserialising any subordinate arrays and performing the replace on those too.
767
  *
768
  * @param string $from String we're looking to replace.
769
  * @param string $to What we want it to be replaced with
770
  * @param array $data Used to pass any subordinate arrays back to in.
771
  * @param bool $serialised Does the array passed via $data need serialising.
772
  *
773
  * @return array The original array with all elements replaced as needed.
774
  */
775
  * The main loop triggered in step 5. Up here to keep it out of the way of the
776
  * HTML. This walks every table in the db that was selected in step 3 and then
777
  * walks every row and column replacing all occurences of a string with another.
778
  * We split large tables into 50,000 row blocks when dealing with them to save
779
  * on memmory consumption.
780
  *
781
  * @param mysql $connection The db connection object
782
  * @param string $search What we want to replace
783
  * @param string $replace What we want to replace it with.
784
  * @param array $tables The tables we want to look at.
785
  *
786
  * @return array Collection of information gathered during the run.
787
  */
788
  if (!is_string($url) || '' == $url) die('The provided path is not valid,aborting..');
789
 
790
  $pathParts = pathinfo($url);
791
  $urlDir = WPCLONE_DIR_BACKUP . 'url/';
792
  file_exists($urlDir) || mkdir($urlDir, WPBACKUP_FILE_PERMISSION);
793
 
794
  /* Copy the file found from url to plugin root */
795
  $zipFilename = $urlDir . $pathParts['basename'];
796
  DirectoryTree::CopyDirectory($url, $zipFilename);
797
  $result = wpa_unzip($zipFilename, WPCLONE_ROOT, $zipmode);
798
  if ($result) {
799
  $unzippedFolderPath = wpCloneSafePathMode(WPCLONE_ROOT . $pathParts['filename']);
800
  $old_db_prefix = $unzippedFolderPath . '/prefix.txt';
801
  $prefix = wpa_check_prefix($old_db_prefix);
802
  $databaseFile = $unzippedFolderPath . '/database.sql';
803
  if ($prefix) {
804
  wpa_replace_prefix( ABSPATH . 'wp-config.php', $prefix );
805
  }
806
 
807
  $currentSiteUrl = processConfigAndDatabaseFile($databaseFile);
808
  !file_exists($databaseFile) || unlink($databaseFile);
809
  !file_exists($old_db_prefix) || unlink($old_db_prefix);
810
  !file_exists($unzippedFolderPath . '/wp-config.php') || unlink($unzippedFolderPath . '/wp-config.php');
811
  wpa_copy($unzippedFolderPath, WPCLONE_ROOT);
812
  DirectoryTree::DeleteAllDirectoryFiles($unzippedFolderPath, true);
813
  echo "<h1>Restore Successful!</h1>";
814
  echo "Visit your restored site [ <a href='{$currentSiteUrl}' target=blank>here</a> ]<br><br>";
815
  echo "<strong>You may need to re-save your permalink structure <a href='{$currentSiteUrl}/wp-admin/options-permalink.php' target=blank>Here</a></strong>";
816
  } else {
817
  echo "<h1>Restore unsuccessful!!!</h1>";
818
  echo "Please try again.";
819
  }
820
  !file_exists($urlDir) || DirectoryTree::DeleteAllDirectoryFiles($urlDir, true);
821
  global $wpdb;
822
  $prefix = $wpdb->prefix;
823
  $file = $path . '/prefix.txt';
824
  if ( is_dir($path) && is_writable($path) ) {
825
  file_put_contents($file, $prefix);
826
  }
827
  * 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.
828
  *
829
  * @param type $file path to the prefix.txt file.
830
  * @return type bool string
831
  */
832
  global $wpdb;
833
  $prefix = $wpdb->prefix;
834
  if (file_exists($file) && is_readable($file)) {
835
  $old_prefix = file_get_contents($file);
836
  if ( $prefix !== $old_prefix ) {
837
  return $old_prefix;
838
  }
839
  else {
840
  return false;
841
  }
842
  }
843
  return false;
844
  * checks for a trailing slash at the end of the provided URL and strips it if found.
845
  * @param type $url
846
  * @return type
847
  */
848
  if (substr($url, -1) == "/" ) {
849
  $url = rtrim($url, "/");
850
  return $url;
851
  }
852
  else {
853
  return $url;
854
  }
855
  * @link http://davidwalsh.name/backup-mysql-database-php
856
  *
857
  * @param type $host
858
  * @param type $user
859
  * @param type $pass
860
  * @param type $name
861
  * @param type $tables
862
  */
863
  * @since 2.0.6
864
  *
865
  * @param type $zipfile path to the zip file that needs to be extracted.
866
  * @param type $path the place to where the file needs to be extracted.
867
  * @return as false in the event of failure.
868
  */
869
  if ( $zipmode || (!in_array('ZipArchive', get_declared_classes()) || !class_exists('ZipArchive')) ) {
870
  define('PCLZIP_TEMPORARY_DIR', WPCLONE_DIR_BACKUP);
871
  require_once ( ABSPATH . 'wp-admin/includes/class-pclzip.php' );
872
  $z = new PclZip($zipfile);
873
  if ($z->extract(PCLZIP_OPT_PATH, $path) == 0) {
874
  return false;
875
  }
876
  echo 'PclZip';
877
  return true;
878
  }
879
  else {
880
  $r = unzipBackupFile($zipfile, $path);
881
  return $r;
882
  }
883
  * @since 2.0.6
884
  *
885
  * @param type $name name of the zip file.
886
  * @param type $file_list an array of files that needs to be archived.
887
  */
888
  if ( $zipmode || (!in_array('ZipArchive', get_declared_classes()) || !class_exists('ZipArchive')) ) {
889
  define('PCLZIP_TEMPORARY_DIR', WPCLONE_DIR_BACKUP);
890
  require_once ( ABSPATH . 'wp-admin/includes/class-pclzip.php');
891
  $z = new PclZip($name);
892
  $v_list = $z->create($file_list, PCLZIP_OPT_REMOVE_PATH, WPCLONE_DIR_BACKUP);
893
  if ($v_list == 0) {
894
  die("Error : ".$z->errorInfo(true));
895
  }
896
  }
897
  else {
898
  new WPbackupZip($name, $file_list, '.svn');
899
  }
900
  * just a simple function to increase PHP limits.
901
  * @since 2.0.6
902
  */
903
  $time = isset($time) && $time != '' ? $time : 900;
904
  $mem = isset ($mem) && $mem != '' ? $mem . 'M' : '512M';
905
  @ini_set('memory_limit', $mem);
906
  @ini_set('max_execution_time', $time); //900 seconds = 15 minutes
907
  * @since 2.0.6
908
  */
909
  if (!empty($_REQUEST['del'])) {
910
  wpa_remove_backup();
911
  return true;
912
  }
913
  if (isset($_POST['createBackup'])) {
914
  wpa_create_backup();
915
  return true;
916
  }
917
  if (empty($_POST)) return false;
918
  check_admin_referer('wpclone-submit');
919
  $form_post = wp_nonce_url('admin.php?page=wp-clone');
920
  $extra_fields = array('restore_from_url', 'maxmem', 'maxexec', 'zipmode', 'restoreBackup');
921
  $type = '';
922
  if ( false === ($creds = request_filesystem_credentials($form_post, $type, false, false, $extra_fields)) ){
923
  return true;
924
  }
925
  if (!WP_Filesystem($creds)) {
926
  request_filesystem_credentials($form_post, $type, true, false, $extra_fields);
927
  return true;
928
  }
929
  wpa_bump_limits($_POST['maxmem'], $_POST['maxexec']);
930
  $url = isset($_POST['restoreBackup']) ? $_POST['restoreBackup'] : $_POST['restore_from_url'];
931
  $zipmode = isset($_POST['zipmode']) ? true : false;
932
  processRestoringBackup($url, $zipmode);
933
  return true;
934
  * @since 2.0.6
935
  */
936
  global $wp_filesystem;
937
  if (is_readable($source)) {
938
  if (is_dir($source)) {
939
  if (!strstr(wpCloneSafePathMode($source), rtrim(WPCLONE_DIR_BACKUP, "/\\"))) {
940
  if (!file_exists($target)) {
941
  $wp_filesystem->mkdir($target);
942
  }
943
  $d = dir($source);
944
  while (FALSE !== ($entry = $d->read())) {
945
  if ($entry == '.' || $entry == '..') {
946
  continue;
947
  }
948
  $Entry = "{$source}/{$entry}";
949
  if (is_dir($Entry)) {
950
  wpa_copy($Entry, $target . '/' . $entry);
951
  } else {
952
  $wp_filesystem->copy($Entry, $target . '/' . $entry, true, FS_CHMOD_FILE);
953
  }
954
  }
955
  $d->close();
956
  }
957
  }
958
  else {
959
  $wp_filesystem->copy($source, $target, true);
960
  }
961
  }
962
  * @since 2.0.6
963
  */
964
  if (!is_writable($filename)) die ("Unable to modify wp-config.php,please change the permissions to '0600'.Aborting..");
965
  global $wp_filesystem;
966
  $fileContent = file_get_contents($filename);
967
  $pos = strpos($fileContent, '$table_prefix');
968
  $str = substr($fileContent, $pos, strpos($fileContent, PHP_EOL, $pos) - $pos);
969
  $fileContent = str_replace($str, '$table_prefix = "' . $newPrefix . '";', $fileContent);
970
  $wp_filesystem->put_contents($filename, $fileContent, 0600);
971
  * @since 2.0.6
972
  */
973
  check_admin_referer('wpclone-submit');
974
  get_currentuserinfo();
975
  wpa_bump_limits($_POST['maxmem'], $_POST['maxexec']);
976
  $backupName = getBackupFileName();
977
  $zipmode = isset($_POST['zipmode']) ? true : false;
978
  list($zipFileName, $zipSize) = CreateWPFullBackupZip($backupName, $zipmode);
979
  InsertData($zipFileName, $zipSize);
980
  $backZipPath = convertPathIntoUrl(WPCLONE_DIR_BACKUP . $zipFileName);
981
  $zipSize = bytesToSize($zipSize);
982
  echo <<<EOF
983
  <a href='{$backZipPath}'><span>{$backZipPath}</span></a> ( {$zipSize} ) &nbsp;&nbsp;|&nbsp;&nbsp;
984
  <input type='hidden' name='backupUrl' class='backupUrl' value="{$backZipPath}" />
985
  <a class='copy-button' href='#'>Copy URL</a> &nbsp;<br /><br />
986
  (Copy that link and paste it into the "Restore URL" of your new WordPress installation to clone this site)
987
  * @since 2.0.6
988
  */
989
  $deleteRow = DeleteWPBackupZip($_REQUEST['del']);
990
  echo <<<EOT
991
  <h1>Deleted Successful!</h1> <br />
992
  {$deleteRow->backup_name} <br />
993
  File deleted from backup folder and database...
lib/js/backupmanager.js CHANGED
@@ -48,16 +48,18 @@ jQuery(function($) {
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() {
@@ -67,7 +69,7 @@ jQuery(function($) {
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
  }
@@ -110,7 +112,7 @@ jQuery(function($) {
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
  }
48
  $("input[name$='backupUrl']").attr('checked', false);
49
  $(this).attr('checked', true);
50
  unCheckCreateBackupOption();
51
+ $("input#submit").val("Restore Backup").removeClass("btn-primary").addClass("btn-warning");
52
 
53
  });
54
 
55
  $("input[name$='backupUrl']").click(function() {
56
  prepareBackUrlOption();
57
+ $("input#submit").removeClass("btn-primary").addClass("btn-warning");
58
  });
59
 
60
  $("input[name$='restore_from_url']").focus(function() {
61
  prepareBackUrlOption();
62
+ $("input#submit").removeClass("btn-primary").addClass("btn-warning");
63
  });
64
 
65
  $("input#submit").click(function() {
69
  if ($("input[name$='restore_from_url']").val() == '') {
70
  alert('Please enter the url you want to restore from.');
71
  } else if (!$('#approve').is(':checked')) {
72
+ alert('Please confirm that you agree to our terms by checking the "I AGREE" checkbox.');
73
  } else {
74
  return getConfirmation('restore');
75
  }
112
  function checkCreateBackupOption() {
113
  $("input[name$='createBackup']").attr('checked', true);
114
  $("#backupChoices").show("fast");
115
+ $("input#submit").val("Create Backup").removeClass("btn-warning").addClass("btn-primary");
116
  $("input[id='fullBackup']").attr('checked',
117
  $("input[name$='createBackup']").is(':checked') && !$("input[id$='customBackup']").is(':checked'));
118
  }
lib/view.php CHANGED
@@ -1,63 +1,13 @@
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()
@@ -70,32 +20,10 @@
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;
@@ -103,10 +31,10 @@ global $wpdb;
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
 
@@ -114,10 +42,6 @@ $result = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}wpclone ORDER BY id D
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
 
@@ -126,7 +50,7 @@ $result = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}wpclone ORDER BY id D
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>
@@ -138,13 +62,6 @@ $result = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}wpclone ORDER BY id D
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
 
@@ -152,8 +69,9 @@ $result = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}wpclone ORDER BY id D
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
 
@@ -167,7 +85,7 @@ $result = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}wpclone ORDER BY id D
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 ?>
@@ -203,16 +121,41 @@ $result = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}wpclone ORDER BY id D
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>';
@@ -236,4 +179,23 @@ $result = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}wpclone ORDER BY id D
236
  echo "<p style='padding:5px;'><a href='{$link}' style='margin-top:10px'>Advanced Settings</a></p>";
237
  }
238
 
239
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  <script type="text/javascript">
2
+
3
+ jQuery(function($) {
4
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  $(".copy-button").zclip({
6
  path: "<?php echo WPCLONE_URL_PLUGIN ?>lib/js/ZeroClipboard.swf",
7
  copy: function(){
8
  return $(this).prev().val();
9
  }
10
  });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  $('a#copy-description').zclip({
12
  path:'<?php echo WPCLONE_URL_PLUGIN ?>lib/js/ZeroClipboard.swf',
13
  copy:$('p#description').text()
20
  }
21
  });
22
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
  });
24
+
25
  </script>
26
+
27
  <?php
28
  if (wpa_wpfs_init()) return;
29
  global $wpdb;
31
  $result = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}wpclone ORDER BY id DESC", ARRAY_A);
32
 
33
  ?>
34
+ <div id="wrapper">
35
+ <div id="MainView">
36
 
37
+ <h2>Welcome to WP Clone by WP Academy</h2>
 
 
38
 
39
  <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>
40
 
42
  into the "Restore" dialog of a new WordPress site, which will clone the original site to the new site. You must
43
  install the plugin on the new site and then run the WP Clone > Restore function.</p>
44
 
 
 
 
 
45
  <p><strong>Choose your selection below:</strong> either create a backup of this site, or choose which backup you
46
  would like to restore.</p>
47
 
50
  <form id="backupForm" name="backupForm" action="#" method="post">
51
  <?php
52
  if ( isset($_GET['mode']) && 'advanced' == $_GET['mode'] ) { ?>
53
+ <div class="info">
54
  <table>
55
  <tr align="left"><th><label for="zipmode">Alternate zip method</label></th><td colspan="2"><input type="checkbox" name="zipmode" value="alt" /></td></tr>
56
  <tr align="left"><th><label for="maxmem">Maximum memory limit</label></th><td colspan="2"><input type="text" name="maxmem" /></td></tr>
62
  ?>
63
  <strong>Create Backup</strong>
64
  <input id="createBackup" name="createBackup" type="radio" value="fullBackup"/><br/><br/>
 
 
 
 
 
 
 
65
 
66
  <?php if (count($result) > 0) : ?>
67
 
69
 
70
  <?php foreach ($result AS $row) :
71
 
72
+ $filename = convertPathIntoUrl(WPCLONE_DIR_BACKUP . $row['backup_name']);
73
+ $url = wp_nonce_url( get_bloginfo('wpurl') . '/wp-admin/options-general.php?page=wp-clone&del=' . $row['id'], 'wpclone-submit');
74
+ ?>
75
  <div class="restore-backup-options">
76
  <strong>Restore backup </strong>
77
 
85
  <input type="hidden" name="backup_name" value="<?php echo $filename ?>" />
86
 
87
  <a class="copy-button" href="#">Copy URL</a> &nbsp;|&nbsp;
88
+ <a href="<?php echo $url; ?>">Delete</a>
89
  </div>
90
 
91
  <?php endforeach ?>
121
 
122
  </div>
123
 
124
+ <input id="submit" name="submit" class="btn-primary btn" type="submit" value="Create Backup"/>
125
  <?php wp_nonce_field('wpclone-submit')?>
126
  </form>
 
127
  </div>
128
+ <div id="sidebar">
129
+
130
+ <ul>
131
+ <h2>WP Academy Resources</h2>
132
+ <li><a href="http://wpacademy.tv/ww3.htm" title="WP Encyclopedia">Free WP Encyclopedia</a></li>
133
+ <li><a href="http://wpacademy.com" title="WP Live">WP Live</a></li>
134
+ <li><a href="http://wpacademy.com/software#rtmp" title="RTMP Player Plugin">RTMP Player</a></li>
135
+ <li><a href="http://wpacademy.tv/host" title="Managed WordPress Hosting">Managed WordPress Hosting</a></li>
136
+ </ul>
137
+
138
+ <ul>
139
+ <h2>WP Academy News</h2>
140
+ <h3>WPAcademy.com</h3>
141
+ <?php wpa_fetch_feed ('http://wpacademy.com/feed', 3); ?>
142
+ <h3>Twitter @wpacademytv</h3>
143
+ <?php wpa_fetch_feed ('http://api.twitter.com/1/statuses/user_timeline.rss?screen_name=wpacademytv', 5); ?>
144
+ </ul>
145
+
146
+ <ul>
147
+ <h2>Help & Support</h2>
148
+ <li><a href="http://wpacademy.tv/wpclone-faq" title="WP Clone FAQ">Visit the WP Clone FAQ Page</a></li>
149
+ <li><a href="http://wordpress.org/support/plugin/wp-clone-by-wp-academy" title="Support Forum">Support forum at WordPress.org</a></li>
150
+ </ul>
151
+
152
+ </div>
153
+ </div> <!--wrapper-->
154
+ <p style="clear: both;" ></p>
155
  <?php
156
  if ( isset($_GET['mode']) && 'advanced' == $_GET['mode'] ) {
157
  global $wpdb;
158
+ echo '<div class="info">';
159
  echo '<h3>System Info:</h3>';
160
  echo 'Memory limit: ' . ini_get('memory_limit') . '</br>';
161
  echo 'Maximum execution time: ' . ini_get('max_execution_time') . ' seconds</br>';
179
  echo "<p style='padding:5px;'><a href='{$link}' style='margin-top:10px'>Advanced Settings</a></p>";
180
  }
181
 
182
+ function wpa_fetch_feed ($feed, $limit) {
183
+ include_once(ABSPATH . WPINC . '/feed.php');
184
+ $rss = fetch_feed($feed);
185
+ if (!is_wp_error( $rss ) ) :
186
+ $maxitems = $rss->get_item_quantity($limit);
187
+ $rss_items = $rss->get_items(0, $maxitems);
188
+ endif;
189
+ if ($maxitems == 0) echo '<li>No items.</li>';
190
+ else
191
+ // Loop through each feed item and display each item as a hyperlink.
192
+ foreach ( $rss_items as $item ) : ?>
193
+ <li>
194
+ <a href='<?php echo esc_url( $item->get_permalink() ); ?>'
195
+ title='<?php echo 'Posted '.$item->get_date('j F Y | g:i a'); ?>'>
196
+ <?php echo esc_html( $item->get_title() ); ?></a>
197
+ </li>
198
+ <?php endforeach;
199
+ }
200
+
201
+ // 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
9
- Stable tag: 2.0.9
10
  License: GPLv2 or later
11
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
12
 
@@ -49,6 +49,9 @@ 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.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
6
  Plugin URI: http://wpacademy.com/software
7
  Requires at least: 3.0
8
  Tested up to: 3.5
9
+ Stable tag: 2.1
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 - 2012-12-25 =
53
+ *Added: WP Academy sidebar.
54
+
55
  = 2.0.6 - 2012-08-05 =
56
  * Added: WP Filesystem integration
57
  * Added: Alternate zip method for better compatibility with hosts that haven't enabled PHP's zip extension
wpclone.php CHANGED
@@ -4,7 +4,7 @@ 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
 
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