Version Description
- 2013-02-16 =
- Fixed: a missing nonce action which was causing a wp_nonce_ays loop on some hosts.
- Fixed: a couple of UI issues.
Download this release
Release Info
Developer | wpacademy |
Plugin | WP Clone by WP Academy |
Version | 2.1.1 |
Comparing to | |
See all releases |
Code changes from version 2.1 to 2.1.1
- lib/css/style.css +0 -1
- lib/functions.php +1 -1
- lib/view.php +1 -1
- readme.txt +6 -2
- wpclone.php +1 -1
lib/css/style.css
CHANGED
@@ -33,7 +33,6 @@
|
|
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 {
|
33 |
border-bottom: 5px solid #ccc;
|
34 |
padding-bottom: 10px;
|
35 |
text-shadow: 5px 5px 10px #888;
|
|
|
36 |
}
|
37 |
|
38 |
#sidebar ul h3 {
|
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} ) |
|
488 |
<input type='hidden' name='backupUrl' class='backupUrl' value="{$backZipPath}" />
|
489 |
<a class='copy-button' href='#'>Copy URL</a> <br /><br />
|
490 |
(Copy that link and paste it into the "Restore URL" of your new WordPress installation to clone this site)
|
491 |
* @since 2.0.6
|
492 |
*/
|
493 |
$deleteRow = DeleteWPBackupZip($_REQUEST['del']);
|
494 |
echo <<<EOT
|
495 |
<h1>Deleted Successful!</h1> <br />
|
496 |
{$deleteRow->backup_name} <br />
|
497 |
File deleted from backup folder and database...
|
|
|
498 |
$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', 'wpclone-submit');
|
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} ) |
|
984 |
<input type='hidden' name='backupUrl' class='backupUrl' value="{$backZipPath}" />
|
985 |
<a class='copy-button' href='#'>Copy URL</a> <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} ) |
|
487 |
<input type='hidden' name='backupUrl' class='backupUrl' value="{$backZipPath}" />
|
488 |
<a class='copy-button' href='#'>Copy URL</a> <br /><br />
|
489 |
(Copy that link and paste it into the "Restore URL" of your new WordPress installation to clone this site)
|
490 |
* @since 2.0.6
|
491 |
*/
|
492 |
$deleteRow = DeleteWPBackupZip($_REQUEST['del']);
|
493 |
echo <<<EOT
|
494 |
<h1>Deleted Successful!</h1> <br />
|
495 |
{$deleteRow->backup_name} <br />
|
496 |
File deleted from backup folder and database...
|
497 |
+
<?php
|
498 |
$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', 'wpclone-submit');
|
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} ) |
|
984 |
<input type='hidden' name='backupUrl' class='backupUrl' value="{$backZipPath}" />
|
985 |
<a class='copy-button' href='#'>Copy URL</a> <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/view.php
CHANGED
@@ -94,7 +94,7 @@ $result = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}wpclone ORDER BY id D
|
|
94 |
|
95 |
<?php endif ?>
|
96 |
|
97 |
-
<strong>Restore from
|
98 |
|
99 |
<input type="text" name="restore_from_url" class="Url" value="" size="80px"/><br/><br/>
|
100 |
|
94 |
|
95 |
<?php endif ?>
|
96 |
|
97 |
+
<strong>Restore from URL:</strong><input id="backupUrl" name="backupUrl" type="radio" value="backupUrl"/>
|
98 |
|
99 |
<input type="text" name="restore_from_url" class="Url" value="" size="80px"/><br/><br/>
|
100 |
|
readme.txt
CHANGED
@@ -5,7 +5,7 @@ Tags: wp academy, wpacademy, move wordpress, copy wordpress, clone wordpress, in
|
|
5 |
Author URI: http://wpacademy.com
|
6 |
Plugin URI: http://wpacademy.com/software
|
7 |
Requires at least: 3.0
|
8 |
-
Tested up to: 3.5
|
9 |
Stable tag: 2.1
|
10 |
License: GPLv2 or later
|
11 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
@@ -49,8 +49,12 @@ released under the WTFPL http://sam.zoy.org/wtfpl/. Partial script with full cha
|
|
49 |
Review FAQ's and Help Video at the [WP Clone FAQ Page](http://wpacademy.tv/wpclone-faq "WP Clone FAQ")
|
50 |
|
51 |
== Changelog ==
|
|
|
|
|
|
|
|
|
52 |
= 2.1 - 2012-12-25 =
|
53 |
-
*Added: WP Academy sidebar.
|
54 |
|
55 |
= 2.0.6 - 2012-08-05 =
|
56 |
* Added: WP Filesystem integration
|
5 |
Author URI: http://wpacademy.com
|
6 |
Plugin URI: http://wpacademy.com/software
|
7 |
Requires at least: 3.0
|
8 |
+
Tested up to: 3.5.1
|
9 |
Stable tag: 2.1
|
10 |
License: GPLv2 or later
|
11 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
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.1 - 2013-02-16 =
|
53 |
+
* Fixed: a missing nonce action which was causing a wp_nonce_ays loop on some hosts.
|
54 |
+
* Fixed: a couple of UI issues.
|
55 |
+
|
56 |
= 2.1 - 2012-12-25 =
|
57 |
+
* Added: WP Academy sidebar.
|
58 |
|
59 |
= 2.0.6 - 2012-08-05 =
|
60 |
* Added: WP Filesystem integration
|
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.1
|
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.1
|
8 |
Author URI: http://wpacademy.com/
|
9 |
*/
|
10 |
|