function snapshot_gather_item_files($item) { global $wpdb, $site_id; $item_files = array(); $home_path = apply_filters('snapshot_home_path', get_home_path()); if (!isset($item['files-option']) || !count($item['files-option'])) { return $item_files; } if ($item['files-option'] == "none") { if (isset($item['files-sections']) && count($item['files-sections'])) { unset($item['files-sections']); $item['files-sections'] = array(); } } else { if ($item['files-option'] == "all") { if (is_main_site($item['blog-id'])) { $files_sections = array('themes', 'plugins', 'media'); if (is_multisite()) { $files_sections[] = 'mu-plugins'; } } else { $files_sections = array('media'); } } else { if ($item['files-option'] == "selected") { $files_sections = $item['files-sections']; } } } if (!isset($files_sections) || !count($files_sections)) { return $item_files; } //global $is_IIS; //echo "is_IIS[". $is_IIS ."]<br />"; //echo "iis7_supports_permalinks[". iis7_supports_permalinks() ."]<br />"; //echo "files_sections<pre>"; print_r($files_sections); echo "</pre>"; foreach ($files_sections as $file_section) { switch ($file_section) { case 'media': $_path = $home_path . Snapshot_Helper_Utility::get_blog_upload_path($item['blog-id']); $_path = str_replace('\\', '/', $_path); //echo "_path[". $_path ."]<br />"; $item_files['media'] = Snapshot_Helper_Utility::scandir($_path); //echo "media files<pre>"; print_r($item_files['media']); echo "</pre>"; //die(); break; case 'plugins': $_path = trailingslashit($this->plugins_dir); $_path = str_replace('\\', '/', $_path); $item_files['plugins'] = Snapshot_Helper_Utility::scandir($_path); break; case 'mu-plugins': $_path = trailingslashit(WP_CONTENT_DIR) . 'mu-plugins'; $_path = str_replace('\\', '/', $_path); $item_files['mu-plugins'] = Snapshot_Helper_Utility::scandir($_path); break; case 'themes': $_path = trailingslashit(WP_CONTENT_DIR) . 'themes'; $_path = str_replace('\\', '/', $_path); $item_files['themes'] = Snapshot_Helper_Utility::scandir($_path); break; case 'config': $wp_config_file = trailingslashit($home_path) . "wp-config.php"; //$wp_config_file = str_replace('\\', '/', $wp_config_file); if (file_exists($wp_config_file)) { if (!isset($item_files['files'])) { $item_files['files'] = array(); } $item_files['files'][] = $wp_config_file; } break; case 'htaccess': $wp_htaccess_file = trailingslashit($home_path) . ".htaccess"; //$wp_htaccess_file = str_replace('\\', '/', $wp_htaccess_file); if (file_exists($wp_htaccess_file)) { if (!isset($item_files['files'])) { $item_files['files'] = array(); } $item_files['files'][] = $wp_htaccess_file; } $web_config_file = trailingslashit($home_path) . "web.config"; //$web_config_file = str_replace('\\', '/', $web_config_file); if (file_exists($web_config_file)) { if (!isset($item_files['files'])) { $item_files['files'] = array(); } $item_files['files'][] = $web_config_file; } break; default: break; } } //echo "item_files<pre>"; print_r($item_files); echo "</pre>"; //die(); if (!count($item_files)) { return $item_files; } // Exclude files. $item_ignore_files = array(); // With WP 3.5 fresh installs we have a slight issue. In prior versions of WP the main site upload folder and // related sub-site were seperate. Main site was typically /wp-content/uploads/ while sub-sites were // /wp-content/blogs.dir/X/files/ // But in 3.5 when doing a fresh install, not upgrade, the sub-site upload path is beneath the main site. // main site /wp-content/uploads/ and sub-site wp-content/uploads/sites/X // So we have this added fun to try and exclude the sub-site from the main site's media. ug. $blog_id = intval($item['blog-id']); if (is_multisite() && is_main_site($blog_id)) { $main_site_upload_path = Snapshot_Helper_Utility::get_blog_upload_path($blog_id); $sql_str = $wpdb->prepare("SELECT blog_id FROM " . $wpdb->base_prefix . "blogs WHERE blog_id != %d AND site_id=%d LIMIT 5", $blog_id, $site_id); $blog_ids = $wpdb->get_col($sql_str); if (!empty($blog_ids)) { foreach ($blog_ids as $blog_id_tmp) { $sub_site_upload_path = Snapshot_Helper_Utility::get_blog_upload_path($blog_id_tmp); if (!empty($sub_site_upload_path)) { if ($sub_site_upload_path !== $main_site_upload_path && substr($sub_site_upload_path, 0, strlen($main_site_upload_path)) == $main_site_upload_path) { $item_ignore_files[] = dirname($sub_site_upload_path); } break; } } } } //We auto exclude the snapshot tree. Plus any entered exclude entries from the form. $item_ignore_files[] = trailingslashit($this->_settings['backupBaseFolderFull']); $item_ignore_files[] = trailingslashit($this->_settings['SNAPSHOT_PLUGIN_BASE_DIR']); // Then we add any global excludes if (isset($this->config_data['config']['filesIgnore']) && count($this->config_data['config']['filesIgnore'])) { $item_ignore_files = array_merge($item_ignore_files, $this->config_data['config']['filesIgnore']); } // Then item excludes if (isset($item['files-ignore']) && count($item['files-ignore'])) { $item_ignore_files = array_merge($item_ignore_files, $item['files-ignore']); } $item_section_files = array(); // Need to exclude the user ignore patterns as well as our Snapshot base folder. No backup of the backups foreach ($item_files as $item_set_key => $item_set_files) { if (!is_array($item_set_files) || !count($item_set_files)) { continue; } foreach ($item_set_files as $item_set_files_key => $item_set_files_file) { // We spin through all the files. They will fall into one of three sections... // If the file is not readable we ignore if (!is_readable($item_set_files_file)) { if (!isset($item_section_files['error'][$item_set_key])) { $item_section_files['error'][$item_set_key] = array(); } $item_section_files['error'][$item_set_key][] = $item_set_files_file; } else { $EXCLUDE_THIS_FILE = false; foreach ($item_ignore_files as $item_ignore_file) { // Make sure we don't have any blank entries. $item_ignore_file = trim($item_ignore_file); if (empty($item_ignore_file)) { continue; } //echo "item_set_files_file<pre>"; print_r($item_set_files_file); echo "</pre>"; //echo "item_ignore_file[". $item_ignore_file ."]<br />"; $stristr_ret = stristr($item_set_files_file, $item_ignore_file); if ($stristr_ret !== false) { $EXCLUDE_THIS_FILE = true; break; } } if ($EXCLUDE_THIS_FILE == false) { // If file is valid we keep it if (!isset($item_section_files['included'][$item_set_key])) { $item_section_files['included'][$item_set_key] = array(); } $item_section_files['included'][$item_set_key][] = $item_set_files_file; } else { if (!isset($item_section_files['excluded']['pattern'])) { $item_section_files['excluded']['pattern'] = array(); } $item_section_files['excluded']['pattern'][] = $item_set_files_file; } } } } //echo "item_section_files<pre>"; print_r($item_section_files); echo "</pre>"; //die(); return $item_section_files; }
/** * @param $from_dir - Source Directory * @param $dest_dir Destination Directory * @param bool $move_files (true) will move each file individually. (false) will remove destination sub-directories and move entire source sub-directory */ public static function move_tree($from_dir, $dest_dir, $move_files = false) { if (!is_dir($from_dir)) { echo "Source Directory does not exists [" . $from_dir . "]<br />"; die; } if (!is_dir($dest_dir)) { echo "Destination Directory does not exists [" . $dest_dir . "]<br />"; die; } if ($move_files == true) { $from_files = Snapshot_Helper_Utility::scandir($from_dir); if (is_array($from_files) && count($from_files)) { foreach ($from_files as $from_file_full) { $from_file = str_replace(trailingslashit_snapshot($from_dir), '', $from_file_full); $dest_file_full = self::trailingslashit_snapshot($dest_dir) . $from_file; if (!file_exists(dirname($dest_file_full))) { mkdir(dirname($dest_file_full), 0777, true); } if (file_exists($dest_file_full)) { unlink($dest_file_full); } $rename_ret = rename($from_file_full, $dest_file_full); if ($rename_ret === false) { die; } } } } else { if ($from_dh = opendir($from_dir)) { while (($from_file = readdir($from_dh)) !== false) { if ($from_file == '.' || $from_file == '..') { continue; } $from_file_full = self::trailingslashit_snapshot($from_dir) . $from_file; $dest_file_full = self::trailingslashit_snapshot($dest_dir) . $from_file; if (file_exists($dest_file_full)) { if (is_dir($dest_file_full)) { Snapshot_Helper_Utility::recursive_rmdir($dest_file_full); } else { unlink($dest_file_full); } } rename($from_file_full, $dest_file_full); } closedir($from_dh); } } }