/** * Gets an array of relative paths of all files in site root recursively. * By default, there are all files from root folder, all files from folders wp-admin, wp-content, wp-includes recursively. * Parameter $include adds other folders from site root, and excludes any file or folder by relative path to site's root. * * @param array $exclude array of files of folders to exclude, relative to site's root * @param array $include array of folders from site root which are included to backup (wp-admin, wp-content, wp-includes are default) * * @return array array with all files in site root dir */ public function get_backup_files($exclude, $include) { $add = array(trim(WPINC), trim(basename(WP_CONTENT_DIR)), "wp-admin"); $include = array_merge($add, $include); foreach ($include as &$value) { $value = rtrim($value, '/'); } $filelist = array(); if ($handle = opendir(ABSPATH)) { while (false !== ($file = readdir($handle))) { if ($file !== '..' && is_dir($file) && file_exists(ABSPATH . $file) && !in_array($file, $include)) { $exclude[] = $file; } } closedir($handle); } $exclude[] = 'error_log'; $filelist = get_all_files_from_dir(ABSPATH, $exclude); if (!file_exists(ABSPATH . 'wp-config.php') && file_exists(dirname(ABSPATH) . '/wp-config.php') && !file_exists(dirname(ABSPATH) . '/wp-settings.php')) { $filelist[] = dirname(ABSPATH) . '/wp-config.php'; } $path = wp_upload_dir(); $path = $path['path']; if (strpos($path, WP_CONTENT_DIR) === false && strpos($path, ABSPATH) === 0) { $mediaDir = ABSPATH . ltrim(substr($path, strlen(ABSPATH)), ' /'); if (is_dir($mediaDir)) { $allMediaFiles = get_all_files_from_dir($mediaDir); $filelist = array_merge($filelist, $allMediaFiles); } } return $filelist; }
function appendSplitFiles($fileToAppend) { // function to join the split files during multicall backup $directory_tree = get_all_files_from_dir($fileToAppend); usort($directory_tree, array($this, "sortString")); $joinedFilesArray = array(); $orgHashValues = array(); $hashValue = ''; foreach ($directory_tree as $k => $v) { $contents = ''; $orgFileCount = 0; /* $subject = $v; $pattern = '/iwp_part/i'; preg_match($pattern, $subject, $matches, PREG_OFFSET_CAPTURE); print_r($matches); */ $pos = strpos($v, 'iwp_part'); if ($pos !== false) { $currentFile = explode(".", $v); $currentFileSize = count($currentFile); foreach ($currentFile as $key => $val) { if ($key == $currentFileSize - 2 || $currentFileSize == 1) { $insPos = strpos($val, '_iwp_part'); $rest = substr_replace($val, '', $insPos); $currentFile[$key] = $rest; $insPos2 = strpos($rest, '_iwp_hash'); if ($insPos2 !== false) { $hashInitialPoint = strrpos($rest, "_iwp_hash"); $hashValue = substr($rest, $hashInitialPoint + 10); //$hashValue = substr($rest, -32); $rest = substr_replace($rest, '', $insPos2); $currentFile[$key] = $rest; } } } $orgFileCount++; $orgFileName = implode(".", $currentFile); $handle = fopen($v, "r"); $contents = fread($handle, iwp_mmb_get_file_size($v)); fclose($handle); if ($orgFileCount == 1) { //clearing contents of file intially to prevent appending to already existing file //file_put_contents($orgFileName,'',FILE_APPEND); } file_put_contents($orgFileName, $contents, FILE_APPEND); $joinedFilesArray[$orgFileName] = 'hash'; $orgHashValues[$orgFileName] = $hashValue; echo " orgFileName - " . $orgFileName; $file_to_ulink = realpath($v); $resultUnlink = unlink($file_to_ulink); $resultUnlink = error_get_last(); if (!$resultUnlink) { if (is_file($v)) { unlink($file_to_ulink); } } } } $hashValues = array(); foreach ($joinedFilesArray as $key => $value) { //$hashValues[$key] = md5_file($key); $hashValues[$key] = 'hash'; } $totalHashValues = array(); $totalHashValues['orgHash'] = $orgHashValues; $totalHashValues['afterSplitHash'] = $hashValues; return $totalHashValues; }
/** * Gets an array of relative paths of all files in site root recursively. * By default, there are all files from root folder, all files from folders wp-admin, wp-content, wp-includes recursively. * Parameter $include adds other folders from site root, and excludes any file or folder by relative path to site's root. * * @param array $exclude array of files of folders to exclude, relative to site's root * @param array $include array of folders from site root which are included to backup (wp-admin, wp-content, wp-includes are default) * @return array array with all files in site root dir */ function get_backup_files($exclude, $include) { $add = array(trim(WPINC), trim(basename(WP_CONTENT_DIR)), "wp-admin"); $include = array_merge($add, $include); $filelist = array(); if ($handle = opendir(ABSPATH)) { while (false !== ($file = readdir($handle))) { if (is_dir($file) && file_exists(ABSPATH . $file) && !in_array($file, $include)) { $exclude[] = $file; } } closedir($handle); } $filelist = get_all_files_from_dir(ABSPATH, $exclude); return $filelist; }