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;
 }
示例#2
0
        /**
         * Metabox Restore Blog options. Allows admin to select alternate restore blog within Multisite.
         *
         * @since 1.0.0
         * @uses metaboxes setup in $this->admin_menu_proc()
         * @uses $this->config_data['items']
         *
         * @param none
         *
         * @return none
         */
        function snapshot_metabox_restore_blog_options($title = '', $item)
        {
            global $wpdb, $blog_id;
            //echo "wpdb->blogid[". $wpdb->blogid ."]<br />";
            //echo "blog_id[". $blog_id ."]<br />";
            //echo "item<pre>"; print_r($item); echo "</pre>";
            //echo "MANIFEST<pre>"; print_r($item['MANIFEST']); echo "</pre>";
            $siteurl = '';
            $domain = '';
            if (isset($item['blog-id'])) {
                if (is_multisite()) {
                    $blog_details = get_blog_details($item['blog-id']);
                } else {
                    $blog_details = new stdClass();
                    $blog_details->blog_id = $blog_id;
                    $blog_details->siteurl = get_option('siteurl');
                    if ($blog_details->siteurl) {
                        $blog_details->domain = parse_url($blog_details->siteurl, PHP_URL_HOST);
                        $blog_details->path = parse_url($blog_details->siteurl, PHP_URL_PATH);
                        if (empty($blog_details->path)) {
                            $blog_details->path = '/';
                        }
                    }
                }
                //echo "blog_details<pre>"; print_r($blog_details); echo "</pre>";
            }
            ?>
			<div class="postbox">
				<h3 class="hndle"><span><?php 
            echo $title;
            ?>
</span></h3>

				<div class="inside">
					<?php 
            if (is_multisite()) {
                ?>
						<p class="snapshot-error"><?php 
                _e('You can restore the backup to a different blog within your Multisite environment. Note: The destination blog MUST already exist. This migration logic is considered still in beta.', SNAPSHOT_I18N_DOMAIN);
                ?>
</p>
					<?php 
            }
            ?>

					<table class="form-table snapshot-restore-blog-options">
						<tr>
							<td colspan="2"><?php 
            if (is_multisite() && $blog_details->siteurl != $item['MANIFEST']['WP_SITEURL']) {
                ?>
							<tr>
							<td colspan="2"><p
									class="snapshot-error"><?php 
                _e('Restore Note: URL mismatch!. The Snapshot archive does not appear made from the current WordPress system. Every attempt will be made to replace the source URL with the URL from the destination.', SNAPSHOT_I18N_DOMAIN);
                ?>
</p>
							</td></tr><?php 
                $restore_blog_id = '';
            } else {
                $restore_blog_id = $item['blog-id'];
            }
            ?>
<input type="hidden" name="snapshot-blog-id" id="snapshot-blog-id"
						           value="<?php 
            echo $restore_blog_id;
            ?>
"/>
						</td>
						</tr>
						<tr>
							<td style="width: 50%">
								<label><?php 
            _e('Information from Archive', SNAPSHOT_I18N_DOMAIN);
            ?>
</label>
								<ul>
									<?php 
            if (is_multisite()) {
                ?>
										<?php 
                if (!$item['blog-id'] && isset($item['IMPORT'])) {
                    $item_blog_id = $item['IMPORT']['WP_BLOG_ID'];
                } else {
                    $item_blog_id = $item['MANIFEST']['WP_BLOG_ID'];
                }
                ?>
										<li><span
												class="snapshot-field-label"><?php 
                _e('Blog ID:', SNAPSHOT_I18N_DOMAIN);
                ?>
</span>
											<span style="font-weight: bold" id="snapshot-org-blog-id"
											      class="snapshot-field-value"><?php 
                echo $item_blog_id;
                ?>
</span></li>
									<?php 
            }
            ?>
									<?php 
            if (!$item['blog-id'] && isset($item['IMPORT'])) {
                $item_siteurl = $item['IMPORT']['WP_SITEURL'];
            } else {
                $item_siteurl = $item['MANIFEST']['WP_SITEURL'];
            }
            ?>
									<li><span
											class="snapshot-field-label"><?php 
            _e('Site URL:', SNAPSHOT_I18N_DOMAIN);
            ?>
</span>
										<span style="font-weight: bold" id="snapshot-org-site-url"
										      class="snapshot-field-value"><?php 
            echo $item_siteurl;
            ?>
</span></li>
									<?php 
            /* ?>
            			<li><span class="snapshot-field-label"><?php _e('Home URL:', SNAPSHOT_I18N_DOMAIN); ?></span> <span style="font-weight: bold" id="snapshot-org-site-url" class="snapshot-field-value"><?php echo $item['MANIFEST']['WP_HOME']; ?></span></li>
            			<?php */
            ?>

									<?php 
            if (!$item['blog-id'] && isset($item['IMPORT'])) {
                $item_db_name = $item['IMPORT']['WP_DB_NAME'];
            } else {
                $item_db_name = $item['MANIFEST']['WP_DB_NAME'];
            }
            ?>
									<li><span
											class="snapshot-field-label"><?php 
            _e('Database Name:', SNAPSHOT_I18N_DOMAIN);
            ?>
</span>
										<span style="font-weight: bold" id="snapshot-org-db-name"
										      class="snapshot-field-value"><?php 
            echo $item_db_name;
            ?>
</span></li>


									<?php 
            if (!$item['blog-id'] && isset($item['IMPORT'])) {
                $item_db_base_prefix = $item['IMPORT']['WP_DB_BASE_PREFIX'];
            } else {
                $item_db_base_prefix = $item['MANIFEST']['WP_DB_BASE_PREFIX'];
            }
            ?>
									<li><span
											class="snapshot-field-label"><?php 
            _e('Database Base Prefix:', SNAPSHOT_I18N_DOMAIN);
            ?>
</span>
										<span style="font-weight: bold" id="snapshot-org-db-prefix"
										      class="snapshot-field-value"><?php 
            echo $item_db_base_prefix;
            ?>
</span>
									</li>


									<?php 
            if (!$item['blog-id'] && isset($item['IMPORT'])) {
                $item_db_prefix = $item['IMPORT']['WP_DB_PREFIX'];
            } else {
                $item_db_prefix = $item['MANIFEST']['WP_DB_PREFIX'];
            }
            ?>
									<li><span
											class="snapshot-field-label"><?php 
            _e('Database Prefix:', SNAPSHOT_I18N_DOMAIN);
            ?>
</span>
										<span style="font-weight: bold" id="snapshot-org-db-prefix"
										      class="snapshot-field-value"><?php 
            echo $item['MANIFEST']['WP_DB_PREFIX'];
            ?>
</span>
									</li>

									<?php 
            if (!$item['blog-id'] && isset($item['IMPORT'])) {
                $item_upload_path = $item['IMPORT']['WP_UPLOAD_PATH'];
            } else {
                $item_upload_path = $item['MANIFEST']['WP_UPLOAD_PATH'];
            }
            ?>
									<li><span
											class="snapshot-field-label"><?php 
            _e('Upload Path:', SNAPSHOT_I18N_DOMAIN);
            ?>
</span>
										<span style="font-weight: bold" id="snapshot-org-upload-path"
										      class="snapshot-field-value"><?php 
            echo $item_upload_path;
            ?>
</span></li>
								</ul>
							</td>
							<td style="width: 50%">
								<label><?php 
            _e('Will be restored to', SNAPSHOT_I18N_DOMAIN);
            ?>
</label>
								<ul>
									<?php 
            if (is_multisite()) {
                ?>
										<?php 
                if (!$item['blog-id'] && isset($item['IMPORT'])) {
                    $item_blog_id = '';
                } else {
                    $item_blog_id = $item['MANIFEST']['WP_BLOG_ID'];
                }
                ?>
										<li><span
												class="snapshot-field-label"><?php 
                _e('Blog ID:', SNAPSHOT_I18N_DOMAIN);
                ?>
</span>
											<span style="font-weight: bold" id="snapshot-new-blog-id"
											      class="snapshot-field-value"><?php 
                echo $item_blog_id;
                ?>
</span></li>
									<?php 
            }
            ?>

									<?php 
            if (is_multisite()) {
                if (!$item['blog-id'] && isset($item['IMPORT'])) {
                    $item_siteurl = '';
                } else {
                    $item_siteurl = $blog_details->siteurl;
                }
            } else {
                $item_siteurl = get_option('siteurl');
            }
            ?>
									<li><span
											class="snapshot-field-label"><?php 
            _e('Site URL:', SNAPSHOT_I18N_DOMAIN);
            ?>
</span> <span
											id="snapshot-blog-search-success" style="display:inline"><span
												style="font-weight: bold"
												id="snapshot-blog-name"><?php 
            echo $item_siteurl;
            ?>
</span><?php 
            if (is_multisite()) {
                ?>
												<button
													id="snapshot-blog-id-change"><?php 
                _e('Change', SNAPSHOT_I18N_DOMAIN);
                ?>
</button>
											<?php 
            }
            ?>
								</span>
										<?php 
            if (is_multisite()) {
                ?>
											<span id="snapshot-blog-search" style="display:none">
										<span id="snapshot-blog-search-error" style="color: #FF0000; display:none;"><?php 
                _e('Error on blog lookup. Try again', SNAPSHOT_I18N_DOMAIN);
                ?>
											<br/></span>
												<?php 
                if (is_subdomain_install()) {
                    $current_sub_domain = str_replace("." . network_site_url(), '', parse_url($item_siteurl, PHP_URL_HOST));
                    $site_domain = untrailingslashit(preg_replace('/^(http|https):\\/\\//', '', network_site_url()));
                    $current_sub_domain = str_replace('.' . $site_domain, '', $current_sub_domain);
                    ?>
<input name="snapshot-blog-id-search" id="snapshot-blog-id-search"
													         value="<?php 
                    echo $current_sub_domain;
                    ?>
"
													         style="width: 20%" />.<?php 
                    echo $site_domain;
                    ?>
 <span
														class="spinner"></span>
													<button
														id="snapshot-blog-id-lookup"><?php 
                    _e('Lookup', SNAPSHOT_I18N_DOMAIN);
                    ?>
</button>
													<button
														id="snapshot-blog-id-cancel"><?php 
                    _e('Cancel', SNAPSHOT_I18N_DOMAIN);
                    ?>
</button>
													<p class="description"><?php 
                    _e('Enter the blog sub-domain prefix "site1" or blog ID "22" or mapped domain or leave blank for primary site.', SNAPSHOT_I18N_DOMAIN);
                    ?>
</p><?php 
                } else {
                    $current_domain_path = parse_url($item_siteurl, PHP_URL_PATH);
                    if ($current_domain_path[0] == "/") {
                        $current_domain_path = substr($current_domain_path, 1);
                    }
                    $current_path = apply_filters('snapshot_current_path', PATH_CURRENT_SITE);
                    echo untrailingslashit(network_site_url()) . $current_path;
                    ?>
<input
													name="snapshot-blog-id-search" id="snapshot-blog-id-search"
													value="<?php 
                    echo $current_domain_path;
                    ?>
" style="width: 20%"/>
													<span class="spinner"></span>
													<button
														id="snapshot-blog-id-lookup"><?php 
                    _e('Lookup', SNAPSHOT_I18N_DOMAIN);
                    ?>
</button>
													<button
														id="snapshot-blog-id-cancel"><?php 
                    _e('Cancel', SNAPSHOT_I18N_DOMAIN);
                    ?>
</button>
													<p class="description"><?php 
                    _e('Enter the blog path "site1" or blog ID "22".', SNAPSHOT_I18N_DOMAIN);
                    ?>
</p><?php 
                }
                ?>
									</span>
										<?php 
            }
            ?>
</li>
									<?php 
            /* ?>
            			<li><span class="snapshot-field-label"><?php _e('Home URL:', SNAPSHOT_I18N_DOMAIN); ?></span> <span style="font-weight: bold" id="snapshot-new-blogurl"><?php echo get_option('home'); ?></span></li>
            			<?php */
            ?>
									<?php 
            if (is_multisite()) {
                if (!$item['blog-id'] && isset($item['IMPORT'])) {
                    $item_db_name = '';
                } else {
                    $item_db_name = DB_NAME;
                }
            } else {
                $item_db_name = DB_NAME;
            }
            ?>
									<li><span
											class="snapshot-field-label"><?php 
            _e('Database Name:', SNAPSHOT_I18N_DOMAIN);
            ?>
</span>
										<span style="font-weight: bold" id="snapshot-new-db-name"
										      class="snapshot-field-value"><?php 
            echo $item_db_name;
            ?>
</span></li>

									<?php 
            if (is_multisite()) {
                if (!$item['blog-id'] && isset($item['IMPORT'])) {
                    $item_db_base_prefix = '';
                } else {
                    $item_db_base_prefix = $wpdb->base_prefix;
                    //$wpdb->get_blog_prefix($item['blog-id']);
                }
            } else {
                $item_db_base_prefix = $wpdb->base_prefix;
            }
            ?>
									<li><span
											class="snapshot-field-label"><?php 
            _e('Database Base Prefix:', SNAPSHOT_I18N_DOMAIN);
            ?>
</span>
										<span style="font-weight: bold" id="snapshot-new-db-base-prefix"
										      class="snapshot-field-value"><?php 
            echo $item_db_base_prefix;
            ?>
</span>
									</li>

									<?php 
            if (is_multisite()) {
                if (!$item['blog-id'] && isset($item['IMPORT'])) {
                    $item_db_prefix = '';
                } else {
                    $item_db_prefix = $wpdb->get_blog_prefix($item['MANIFEST']['WP_BLOG_ID']);
                }
            } else {
                $item_db_prefix = $wpdb->prefix;
            }
            ?>
									<li><span
											class="snapshot-field-label"><?php 
            _e('Database Prefix:', SNAPSHOT_I18N_DOMAIN);
            ?>
</span>
										<span style="font-weight: bold" id="snapshot-new-db-prefix"
										      class="snapshot-field-value"><?php 
            echo $item_db_prefix;
            ?>
</span></li>


									<?php 
            if (is_multisite()) {
                if (!$item['blog-id'] && isset($item['IMPORT'])) {
                    $item_upload_path = '';
                } else {
                    $item_upload_path = Snapshot_Helper_Utility::get_blog_upload_path($item['blog-id']);
                }
            } else {
                $item_upload_path = Snapshot_Helper_Utility::get_blog_upload_path($blog_id);
            }
            ?>
									<li><span
											class="snapshot-field-label"><?php 
            _e('Upload Path:', SNAPSHOT_I18N_DOMAIN);
            ?>
</span>
										<span style="font-weight: bold" id="snapshot-new-upload-path"
										      class="snapshot-field-value"><?php 
            echo $item_upload_path;
            ?>
</span></li>
								</ul>
							</td>
						</tr>
					</table>
				</div>
			</div>
		<?php 
        }