function log_message($message) { if ($this->log_fp) { fwrite($this->log_fp, Snapshot_Helper_Utility::show_date_time(time(), 'Y-m-d H:i:s') . ": " . $message . "\r\n"); fflush($this->log_fp); } }
public static function render_destination_listing_panel() { if (!Snapshot_Helper_Utility::is_pro()) { self::render_premium_plugin_prompt(); return false; } if (isset($_REQUEST['snapshot-action']) && (sanitize_text_field($_REQUEST['snapshot-action']) == 'add' || sanitize_text_field($_REQUEST['snapshot-action']) == 'edit' || sanitize_text_field($_REQUEST['snapshot-action']) == 'update')) { self::render_destination_edit_panel(); } else { ?> <div id="snapshot-edit-destinations-panel" class="wrap snapshot-wrap"> <h2><?php _ex("All Snapshot Destinations", "Snapshot Destination Page Title", SNAPSHOT_I18N_DOMAIN); ?> </h2> <p><?php _ex("This page show all the destinations available for the Snapshot plugin. A destination is a remote system like Amazon S3, Dropbox or SFTP. Simply select the destination type from the drop down then will in the details. When you add or edit a Snapshot you will be able to assign it a destination. When the snapshot backup runs the archive file will be sent to the destination instead of stored locally.", 'Snapshot page description', SNAPSHOT_I18N_DOMAIN); ?> </p> <?php if (session_id() == "") { @session_start(); } $destinations = array(); foreach (WPMUDEVSnapshot::instance()->config_data['destinations'] as $key => $item) { $type = $item['type']; if (!isset($destinations[$type])) { $destinations[$type] = array(); } $destinations[$type][$key] = $item; } $destinationClasses = WPMUDEVSnapshot::instance()->get_setting('destinationClasses'); if ($destinationClasses && count($destinationClasses)) { ksort($destinationClasses); foreach ($destinationClasses as $classObject) { //echo "classObject<pre>"; print_r($classObject); echo "</pre>"; ?> <h3 style="float:left;"><?php echo $classObject->name_display; ?> <?php if (current_user_can('manage_snapshots_destinations')) { ?> <a class="add-new-h2" style="top:0;" href="<?php echo WPMUDEVSnapshot::instance()->get_setting('SNAPSHOT_MENU_URL'); ?> snapshots_destinations_panel&snapshot-action=add&type=<?php echo $classObject->name_slug; ?> "> Add New</a><?php } ?> </h3> <?php if (isset($classObject->name_logo) && strlen($classObject->name_logo)) { ?> <img style="float: right; height: 40px;" src="<?php echo $classObject->name_logo; ?> " alt="<?php $classObject->name_display; ?> " /><?php } ?> <form id="snapshot-edit-destination-<?php echo $classObject->name_slug; ?> " action="<?php echo WPMUDEVSnapshot::instance()->get_setting('SNAPSHOT_MENU_URL'); ?> snapshots_destinations_panel" method="post"> <input type="hidden" name="snapshot-action" value="delete-bulk"/> <input type="hidden" name="snapshot-destination-type" value="<?php echo $classObject->name_slug; ?> "/> <?php wp_nonce_field('snapshot-delete-destination-bulk-' . $classObject->name_slug, 'snapshot-noonce-field-' . $classObject->name_slug); ?> <?php $edit_url = WPMUDEVSnapshot::instance()->get_setting('SNAPSHOT_MENU_URL') . 'snapshots_destinations_panel&snapshot-action=edit&type=' . $classObject->name_slug . '&'; $delete_url = WPMUDEVSnapshot::instance()->get_setting('SNAPSHOT_MENU_URL') . 'snapshots_destinations_panel&snapshot-action=delete&'; if (isset($destinations[$classObject->name_slug])) { $destination_items = $destinations[$classObject->name_slug]; } else { $destination_items = array(); } $classObject->display_listing_table($destination_items, $edit_url, $delete_url); ?> </form> <?php } } ?> </div> <?php } }
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; }
function snapshot_admin_show_import_panel() { // require( WPMUDEVSnapshot::instance()->get_setting( 'SNAPSHOT_PLUGIN_BASE_DIR' ) . '/lib/snapshot_admin_metaboxes.php' ); $_snapshot_metaboxes = new Snapshot_View_Metabox_Admin(); ?> <div id="snapshot-settings-metaboxes-general" class="wrap snapshot-wrap"> <h2><?php _ex("Snapshots Scan / Import", "Snapshot Plugin Page Title", SNAPSHOT_I18N_DOMAIN); ?> </h2> <div id="poststuff" class="metabox-holder"> <div id="post-body" class=""> <div id="post-body-content" class="snapshot-metabox-holder-main"> <p><?php _e('The Snapshot import form below is used to import snapshot archives from outside of this environment into view of the snapshot plugin. If you are attempting to restore an archive from a remote server for example you first need to import the archive here. This will then show the archive in the All Snapshots listing. From that page you can then perform the needed restore.', SNAPSHOT_I18N_DOMAIN); ?> </p> <form action="<?php echo WPMUDEVSnapshot::instance()->get_setting('SNAPSHOT_MENU_URL'); ?> snapshots_import_panel" method="post"> <input type="hidden" value="archives-import" name="snapshot-action"> <?php wp_nonce_field('snapshot-import', 'snapshot-noonce-field'); ?> <?php $_snapshot_metaboxes->snapshot_metaboxes_show_import(__('Import Options', SNAPSHOT_I18N_DOMAIN)); ?> <input id="snapshot-add-button" class="button-primary" type="submit" value="<?php _e('Scan / Import Snapshots', SNAPSHOT_I18N_DOMAIN); ?> "/> </form> </div> </div> <?php //echo "_POST<pre>"; print_r($_POST); echo "</pre>"; //echo "_GET<pre>"; print_r($_GET); echo "</pre>"; if (isset($_REQUEST['snapshot-action']) && esc_attr($_REQUEST['snapshot-action']) == "archives-import") { if (wp_verify_nonce($_POST['snapshot-noonce-field'], 'snapshot-import')) { if (isset($_POST['snapshot-import-archive-remote-url']) && !empty($_POST['snapshot-import-archive-remote-url'])) { //echo "remote url[". $_POST['snapshot-import-archive-remote-url'] ."]<br />"; if (substr($_POST['snapshot-import-archive-remote-url'], 0, 4) == 'http') { if (function_exists('curl_version')) { $remoteFile = esc_url_raw($_POST['snapshot-import-archive-remote-url']); @set_time_limit(900); // 15 minutes Technically, server to server should be quick for large files. ?> <p><?php _e("PHP max_execution_time", SNAPSHOT_I18N_DOMAIN); ?> : <?php echo ini_get('max_execution_time'); ?> s</p><?php ?> <p><?php _e("Attempting to download remote file", SNAPSHOT_I18N_DOMAIN); ?> : <?php echo $remoteFile; ?> </p><?php flush(); $restoreFile = trailingslashit(WPMUDEVSnapshot::instance()->get_setting('backupBaseFolderFull')) . basename($remoteFile); //echo "remoteFile=[". $remoteFile ."]<br />"; //echo "restoreFile=[". $restoreFile ."]<br />"; Snapshot_Helper_Utility::remote_url_to_local_file($remoteFile, $restoreFile); if (file_exists($restoreFile)) { $restoreFolder = trailingslashit(WPMUDEVSnapshot::instance()->get_setting('backupRestoreFolderFull')) . "_imports"; echo "<ol>"; echo "<li><strong>" . __('Processing archive', SNAPSHOT_I18N_DOMAIN) . ": ", basename($restoreFile) . "</strong> (" . Snapshot_Helper_Utility::size_format(filesize($restoreFile)) . ")<ul><li>"; flush(); $error_status = Snapshot_Helper_Utility::archives_import_proc($restoreFile, $restoreFolder); //echo "error_status<pre>"; print_r($error_status); echo "</pre>"; if (isset($error_status['errorStatus']) && $error_status['errorStatus'] === true) { if (isset($error_status['errorText']) && strlen($error_status['errorText'])) { echo '<span class="snapshot-error">Error: ' . $error_status['errorText'] . '</span></br />'; } } else { if (isset($error_status['errorStatus']) && $error_status['errorStatus'] === false) { if (isset($error_status['responseText']) && strlen($error_status['responseText'])) { echo '<span class="snapshot-success">Success: ' . $error_status['responseText'] . '</span></br />'; } else { } } } echo "</li></ul></li>"; echo "</ol>"; } else { echo '<p>' . __('Error: Your server does not have lib_curl installed. So the import process cannot retrieve remote file.', SNAPSHOT_I18N_DOMAIN) . '</p>'; } } else { echo "<p>" . __('local import file not found. This could mean either the entered URL was not valid or the file was not publicly accessible.', SNAPSHOT_I18N_DOMAIN) . "</p>"; } } else { // Then a local directory // Are we dealing with a absolote path... if (substr($_POST['snapshot-import-archive-remote-url'], 0, 1) == "/") { $dir = trailingslashit(esc_attr($_POST['snapshot-import-archive-remote-url'])); } else { $dir = trailingslashit(trailingslashit(WPMUDEVSnapshot::instance()->get_setting('backupBaseFolderFull')) . esc_attr($_POST['snapshot-import-archive-remote-url'])); } //echo "dir[". $dir ."]<br />"; if (is_dir($dir)) { echo "<p>" . __('Importing archives from', SNAPSHOT_I18N_DOMAIN) . ": " . $dir . "</p>"; if ($dh = opendir($dir)) { $restoreFolder = trailingslashit(WPMUDEVSnapshot::instance()->get_setting('backupRestoreFolderFull')) . "_imports"; echo "<ol>"; while (($file = readdir($dh)) !== false) { if ($file == '.' || $file == '..' || $file == 'index.php' || $file[0] == '.') { continue; } if (pathinfo($file, PATHINFO_EXTENSION) != "zip") { continue; } $restoreFile = $dir . $file; if (is_dir($restoreFile)) { continue; } echo "<li><strong>" . __('Processing archive', SNAPSHOT_I18N_DOMAIN) . ": ", basename($restoreFile) . "</strong> (" . Snapshot_Helper_Utility::size_format(filesize($restoreFile)) . ")<ul><li>"; flush(); $error_status = Snapshot_Helper_Utility::archives_import_proc($restoreFile, $restoreFolder); //echo "error_status<pre>"; print_r($error_status); echo "</pre>"; if (isset($error_status['errorStatus']) && $error_status['errorStatus'] === true) { if (isset($error_status['errorText']) && strlen($error_status['errorText'])) { echo '<span class="snapshot-error">Error: ' . $error_status['errorText'] . '</span></br />'; } } else { if (isset($error_status['errorStatus']) && $error_status['errorStatus'] === false) { if (isset($error_status['responseText']) && strlen($error_status['responseText'])) { echo '<span class="snapshot-success">Success: ' . $error_status['responseText'] . '</span></br />'; } else { } } } echo "</li></ul></li>"; } echo "</ol>"; closedir($dh); } } else { echo "<p>" . sprintf(__('local import file not found %s. This could mean either the entered path was not valid or accessible.', SNAPSHOT_I18N_DOMAIN), $dir) . "</p>"; } } } else { $dir = trailingslashit(WPMUDEVSnapshot::instance()->get_setting('backupBaseFolderFull')); echo "<p>" . __('Importing archives from', SNAPSHOT_I18N_DOMAIN) . ": " . $dir . "</p>"; if ($dh = opendir($dir)) { $restoreFolder = trailingslashit(WPMUDEVSnapshot::instance()->get_setting('backupRestoreFolderFull')) . "_imports"; echo "<ol>"; while (($file = readdir($dh)) !== false) { if ($file == '.' || $file == '..' || $file == 'index.php' || $file[0] == '.') { continue; } if (pathinfo($file, PATHINFO_EXTENSION) != "zip") { continue; } $restoreFile = $dir . $file; if (is_dir($restoreFile)) { continue; } echo "<li><strong>" . __('Processing archive', SNAPSHOT_I18N_DOMAIN) . ": ", basename($restoreFile) . "</strong> (" . Snapshot_Helper_Utility::size_format(filesize($restoreFile)) . ")<ul><li>"; flush(); $error_status = Snapshot_Helper_Utility::archives_import_proc($restoreFile, $restoreFolder); //echo "error_status<pre>"; print_r($error_status); echo "</pre>"; if (isset($error_status['errorStatus']) && $error_status['errorStatus'] === true) { if (isset($error_status['errorText']) && strlen($error_status['errorText'])) { echo '<span class="snapshot-error">Error: ' . $error_status['errorText'] . '</span></br />'; } } else { if (isset($error_status['errorStatus']) && $error_status['errorStatus'] === false) { if (isset($error_status['responseText']) && strlen($error_status['responseText'])) { echo '<span class="snapshot-success">Success: ' . $error_status['responseText'] . '</span></br />'; } else { } } } echo "</li></ul></li>"; } echo "</ol>"; closedir($dh); } } } echo "<p>" . __('Snapshot import complete', SNAPSHOT_I18N_DOMAIN) . "</p>"; } ?> </div> </div> <?php }
function column_status($item) { $status = array(); $status['archives'] = array(); $status['archives']['pending'] = 0; $status['archives']['fail'] = 0; $status['archives']['complete'] = 0; $status['destination']['pending'] = 0; $status['destination']['fail'] = 0; $status['destination']['complete'] = 0; if (!isset($item['data']) || !count($item['data'])) { $status['archives']['pending'] += 1; } else { ksort($item['data']); foreach ($item['data'] as $data_item) { if (!isset($data_item['archive-status'])) { $status['archives']['pending'] += 1; } else { $status_item = Snapshot_Helper_Utility::latest_data_item($data_item['archive-status']); if (!$status_item) { $status['archives']['pending'] += 1; } else { if (isset($status_item['errorStatus'])) { if ($status_item['errorStatus'] === true) { $status['archives']['fail'] += 1; } else { if ($status_item['errorStatus'] !== true) { $status['archives']['complete'] += 1; } } } } } if (!isset($data_item['destination']) || $data_item['destination'] != $item['destination']) { $data_item['destination'] = $item['destination']; } //echo "data_item[destination-status]<pre>"; print_r($) if (isset($data_item['destination']) && $data_item['destination'] != "local" && !empty($data_item['destination'])) { if (!isset($data_item['destination-status'])) { $status['destination']['pending'] += 1; } else { $status_item = Snapshot_Helper_Utility::latest_data_item($data_item['destination-status']); //echo "status_item<pre>"; print_r($status_item); echo "</pre>"; if (!$status_item) { $status['destination']['pending'] += 1; } else { if (isset($status_item['sendFileStatus']) && $status_item['sendFileStatus'] === true) { $status['destination']['complete'] += 1; } else { if ($status_item['errorStatus'] === true) { $status['destination']['fail'] += 1; } } } } } } } //echo "status<pre>"; print_r($status); echo "</pre>"; $status_output = ''; foreach ($status['archives'] as $_key => $_count) { if ($_count == 0) { continue; } switch ($_key) { case 'pending': if (strlen($status_output)) { $status_output .= ', '; } $status_output .= $_count . " " . __('Pending', SNAPSHOT_I18N_DOMAIN); break; case 'fail': if (strlen($status_output)) { $status_output .= ', '; } $status_output .= $_count . " " . __('Fail', SNAPSHOT_I18N_DOMAIN); break; case 'complete': if (strlen($status_output)) { $status_output .= ', '; } $status_output .= $_count . " " . __('Complete', SNAPSHOT_I18N_DOMAIN); break; } } //if (strlen($status_output)) // echo __('Archives:', SNAPSHOT_I18N_DOMAIN) ." ".$status_output ."<br />"; //else // echo __('Archives:', SNAPSHOT_I18N_DOMAIN) ." ".$status_output ."<br />"; //echo "status_output=[". $status_output ."]<br />"; $status_output = ''; foreach ($status['destination'] as $_key => $_count) { if ($_count == 0) { continue; } switch ($_key) { case 'pending': if (strlen($status_output)) { $status_output .= ', '; } $status_output .= $_count . " " . __('Pending', SNAPSHOT_I18N_DOMAIN); break; case 'fail': if (strlen($status_output)) { $status_output .= ', '; } $status_output .= $_count . " " . __('Fail', SNAPSHOT_I18N_DOMAIN); break; case 'complete': if (strlen($status_output)) { $status_output .= ', '; } $status_output .= $_count . " " . __('Complete', SNAPSHOT_I18N_DOMAIN); break; } } if (strlen($status_output)) { echo "<br />" . __('Destination:', SNAPSHOT_I18N_DOMAIN) . " " . $status_output . "<br />"; } //else // echo __('Archives:', SNAPSHOT_I18N_DOMAIN) ." ".$status_output ."<br />"; //echo "status_output=[". $status_output ."]<br />"; }
/** * @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); } } }
function snapshot_metaboxes_show_memory_limit() { ?> <form action="?page=snapshots_settings_panel" method="post"> <input type="hidden" name="snapshot-action" value="settings-update"/> <input type="hidden" name="snapshot-sub-action" value="memoryLimit"/> <?php wp_nonce_field('snapshot-settings', 'snapshot-noonce-field'); ?> <?php wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false); ?> <?php wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false); ?> <p><?php _ex("The Memory Limit setting can allow Snapshot to use more or limit the amount of memory used by Snapshot during the backup or restore processing. The value set here can be higher than the value you would define for WP_MEMORY_LIMIT in you wp-config.php. This is because working with zip archives takes more memory than just serving a web page. For any moderate size site this value should be at least <strong>256M</strong>.", 'Snapshot page description', SNAPSHOT_I18N_DOMAIN); ?> </p> <p><?php _ex("<strong>If left blank, Snapshot will compare the php.ini (memory_limit), WP_MEMORY_LIMIT and WP_MAX_MEMORY_LIMIT settings and use the largest value.</strong>", 'Snapshot page description', SNAPSHOT_I18N_DOMAIN); ?> </p> <p><?php $memory_limits = array(); $memory_limit = ini_get('memory_limit'); $memory_limits[$memory_limit] = Snapshot_Helper_Utility::size_unformat($memory_limit); /* ?><br /><?php echo $memory_limit; ?>: <?php _e('php.ini (memory_limit)', SNAPSHOT_I18N_DOMAIN); */ if (defined('WP_MEMORY_LIMIT')) { $memory_limit = WP_MEMORY_LIMIT; $memory_limits[$memory_limit] = Snapshot_Helper_Utility::size_unformat($memory_limit); /* ?><br /><?php echo $memory_limit; ?>: <?php _e('WP_MEMORY_LIMIT', SNAPSHOT_I18N_DOMAIN); */ } if (defined('WP_MAX_MEMORY_LIMIT')) { $memory_limit = WP_MAX_MEMORY_LIMIT; $memory_limits[$memory_limit] = Snapshot_Helper_Utility::size_unformat($memory_limit); /* ?><br /><?php echo $memory_limit; ?>: <?php _e('WP_MAX_MEMORY_LIMIT', SNAPSHOT_I18N_DOMAIN); */ } ?> </p><?php arsort($memory_limits); //echo "memory_limits<pre>"; print_r($memory_limits); echo "</pre>"; foreach ($memory_limits as $memory_key => $memory_value) { $memoryLimit = $memory_key; break; } @ini_set('memory_limit', $memoryLimit); $memoryLimit_get = ini_get('memory_limit'); if (ini_get('memory_limit') !== $memoryLimit) { ?> <p style="color: #FF0000;"><?php _ex("Warning: Unable to update the 'memory_limit' via the PHP function init_set. This means in order in to increased the allowed memory limit for Snapshot you will need to make the change directly in your php.ini file. Contact your host provider for details.", 'Snapshot page description', SNAPSHOT_I18N_DOMAIN); ?> </p> <?php } else { if (!isset(WPMUDEVSnapshot::instance()->config_data['config']['memoryLimit']) || empty(WPMUDEVSnapshot::instance()->config_data['config']['memoryLimit'])) { WPMUDEVSnapshot::instance()->config_data['config']['memoryLimit'] = $memoryLimit; } ?> <table class="form-table snapshot-settings-server-info"> <tr class="form-field"> <th scope="row"> <label for="snapshot-settings-memory-limit"><?php _e('Memory Limit', SNAPSHOT_I18N_DOMAIN); ?> </label> </th> <td> <input type="text" name="memoryLimit" id="snapshot-settings-memory-limit" value="<?php echo WPMUDEVSnapshot::instance()->config_data['config']['memoryLimit']; ?> "/> <p class="description"><?php echo __('Important to include the size M = Megabytes, G = Gigbytes as in 256M, 1G, etc.', SNAPSHOT_I18N_DOMAIN); ?> </p> </td> </tr> <tr> <td> </td> <td> <input class="button-primary" type="submit" value="<?php _e('Save Settings', SNAPSHOT_I18N_DOMAIN); ?> "/></td> </tr> </table> <?php } ?> </form> <?php }