function snapshot_metaboxes_show_memory_limit() {
			global $wpmudev_snapshot;
			?>
			<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_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_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_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($wpmudev_snapshot->config_data['config']['memoryLimit'])) || (empty($wpmudev_snapshot->config_data['config']['memoryLimit']))) {
							$wpmudev_snapshot->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 $wpmudev_snapshot->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>&nbsp;</td>
							<td>
								<input class="button-primary" type="submit" value="<?php _e('Save Settings', SNAPSHOT_I18N_DOMAIN); ?>" /></td>
						</tr>
						</table>
						<?php
					}
				?>
				</form>
			<?php
		}
Example #2
0
 /**
  * Utility function to read our config array from the WordPress options table. This
  * function also will initialize needed instances of the array if needed.
  *
  * @since 1.0.0
  * @uses $this->_settings
  * @uses $this->config_data
  *
  * @return none
  */
 function load_config()
 {
     global $wpdb;
     if (is_multisite()) {
         //$this->config_data = get_blog_option($wpdb->blogid, $this->_settings['options_key']);
         $blog_prefix = $wpdb->get_blog_prefix($wpdb->blogid);
         $row = $wpdb->get_col($wpdb->prepare("SELECT option_value FROM {$blog_prefix}options\n\t\t\t\t\t\tWHERE option_name = %s", $this->_settings['options_key']));
         if ($row) {
             $this->config_data = unserialize($row[0]);
         }
     } else {
         //$this->config_data = get_option($this->_settings['options_key']);
         $row = $wpdb->get_col($wpdb->prepare("SELECT option_value FROM {$wpdb->options}\n\t\t\t\t\tWHERE option_name = %s LIMIT 1", $this->_settings['options_key']));
         if ($row) {
             $this->config_data = unserialize($row[0]);
         }
     }
     if (empty($this->config_data)) {
         $snapshot_legacy_versions = array('2.0.3', '2.0.2', '2.0.1', '2.0', '1.0.2');
         foreach ($snapshot_legacy_versions as $snapshot_legacy_version) {
             $snapshot_options_key = "snapshot_" . $snapshot_legacy_version;
             if (is_multisite()) {
                 $this->config_data = get_blog_option($wpdb->blogid, $snapshot_options_key);
             } else {
                 $this->config_data = get_option($snapshot_options_key);
             }
             if (!empty($this->config_data)) {
                 $this->config_data['version'] = $snapshot_legacy_version;
                 break;
             }
         }
     }
     if (!isset($this->config_data['items'])) {
         $this->config_data['items'] = array();
     } else {
         krsort($this->config_data['items']);
     }
     /* If we do have items sort them here instead of later. */
     if (!isset($this->config_data['config'])) {
         $this->config_data['config'] = array();
     }
     if (!isset($this->config_data['config']['segmentSize'])) {
         $this->config_data['config']['segmentSize'] = 1000;
     }
     if ($this->config_data['config']['segmentSize'] < 1) {
         $this->config_data['config']['segmentSize'] = 1000;
     }
     if (!isset($this->config_data['config']['memoryLimit']) || empty($this->config_data['config']['memoryLimit'])) {
         $memory_limits = array();
         $memory_limit = ini_get('memory_limit');
         $memory_limits[$memory_limit] = snapshot_utility_size_unformat($memory_limit);
         $memory_limit = WP_MEMORY_LIMIT;
         $memory_limits[$memory_limit] = snapshot_utility_size_unformat($memory_limit);
         $memory_limit = WP_MAX_MEMORY_LIMIT;
         $memory_limits[$memory_limit] = snapshot_utility_size_unformat($memory_limit);
         arsort($memory_limits);
         foreach ($memory_limits as $memory_key => $memory_value) {
             $this->config_data['config']['memoryLimit'] = $memory_key;
             break;
         }
     }
     if (!isset($this->config_data['config']['errorReporting'])) {
         $this->config_data['config']['errorReporting'] = array();
         $this->config_data['config']['errorReporting'][E_ERROR] = array();
         $this->config_data['config']['errorReporting'][E_ERROR]['stop'] = true;
         $this->config_data['config']['errorReporting'][E_ERROR]['log'] = true;
         $this->config_data['config']['errorReporting'][E_WARNING] = array();
         $this->config_data['config']['errorReporting'][E_WARNING]['log'] = true;
         $this->config_data['config']['errorReporting'][E_NOTICE] = array();
         $this->config_data['config']['errorReporting'][E_NOTICE]['log'] = true;
     }
     if (!isset($this->config_data['config']['zipLibrary'])) {
         $this->config_data['config']['zipLibrary'] = 'PclZip';
     }
     if ($this->config_data['config']['zipLibrary'] == 'ZipArchive' && !class_exists('ZipArchive')) {
         $this->config_data['config']['zipLibrary'] = 'PclZip';
     }
     if (!isset($this->config_data['config']['absoluteFolder'])) {
         $this->config_data['config']['absoluteFolder'] = false;
     }
     if (!isset($this->config_data['config']['backupFolder']) || !strlen($this->config_data['config']['backupFolder'])) {
         $this->config_data['config']['backupFolder'] = "snapshots";
     }
     // Container for Destinations S3, FTP, etc.
     if (!isset($this->config_data['destinations'])) {
         $this->config_data['destinations'] = array();
     }
     if (!isset($this->config_data['destinations']['local'])) {
         $this->config_data['destinations']['local'] = array('name' => __('Local Server', SNAPSHOT_I18N_DOMAIN), 'type' => 'local');
     }
     /* Set the default table to be part of the snapshot */
     if (!isset($this->config_data['config']['tables_last'])) {
         $this->config_data['config']['tables_last'] = array();
     }
     // Remove the activity section. No longer used.
     if (isset($this->config_data['activity'])) {
         unset($this->config_data['activity']);
     }
     // The tables needs to be converted. In earlier versions of this plugin the table array was not aware of the blog_id.
     // We need to keep a set for each blog_id. So assume the current version is for the current blog.
     if (isset($this->config_data['config']['tables_last'][0])) {
         $tables_last = $this->config_data['config']['tables_last'];
         unset($this->config_data['config']['tables_last']);
         $this->config_data['config']['tables_last'] = array();
         $this->config_data['config']['tables_last'][$wpdb->blogid] = $tables_last;
     }
     // If we don't have the 'version' config then assume it is the previous version.
     if (!isset($this->config_data['version'])) {
         $this->config_data['version'] = "1.0.2";
     }
     if (version_compare($this->config_data['version'], $this->_settings['SNAPSHOT_VERSION'], '<')) {
         //echo "config version<pre>"; print_r($this->config_data['version']); echo "</pre>";
         //echo "plugin version<pre>"; print_r($this->_settings['SNAPSHOT_VERSION']); echo "</pre>";
         //die();
         $this->set_backup_folder();
         $this->set_log_folders();
         // During the conversion we needs to update the manifest.txt file within the archive. Tricky!
         $restoreFolder = trailingslashit($this->_settings['backupRestoreFolderFull']) . "_imports";
         wp_mkdir_p($restoreFolder);
         /*
         if ($this->config_data['version'] == "1.0.2") {
         	foreach($this->config_data['items'] as $item_idx => $item) {
         
         		// We change blog_id to blog-id
         		if (!isset($item['blog-id'])) {
         			if (isset($item['blog_id'])) {
         				$item['blog-id'] = $item['blog_id'];
         				unset($item['blog_id']);
         			}
         		}
         
         		$all_tables_sections = snapshot_utility_get_database_tables($item['blog-id']);
         
         		if (!isset($item['tables-option'])) {
         			$item['tables-count'] = '';
         
         			if ($all_tables_sections) {
         				$all_tables_option = true;
         				foreach($all_tables_sections as $section => $section_tables) {
         					if (count($section_tables)) {
         						$item['tables-sections'][$section] = array_intersect_key($section_tables, $item['tables']);
         						$item['tables-count'] += count($item['tables-sections'][$section]);
         
         						if (count($item['tables-sections'][$section]) != count($section_tables))
         							$all_tables_option = false;
         					}
         					else
         						$item['tables_sections'][$section] = array();
         				}
         
         				if ($all_tables_option == true) {
         					$item['tables-option'] = 'all';
         				} else {
         					$item['tables-option'] = 'selected';
         				}
         			}
         		}
         
         		$item['files-option'] 	= "none";
         		$item['files-sections'] = array();
         		$item['files-count']	= 0;
         
         		if (!isset($item['destination']))
         			$item['destination'] = 'local';
         		if (!isset($item['destination-directory']))
         			$item['destination-directory'] = '';
         
         		unset($item['tables']);
         
         		if (!isset($item['interval']))
         			$item['interval'] = '';
         
         
         		if (isset($item['data'])) {
         			foreach($item['data'] as $item_data_idx => $item_data) {
         
         				if (!isset($item_data['blog-id'])) {
         					if (isset($item_data['blog_id'])) {
         						$item_data['blog-id'] = $item_data['blog_id'];
         						unset($item_data['blog_id']);
         					}
         				}
         
         				if (!isset($item_data['destination']))
         					$item_data['destination'] = 'local';
         				if (!isset($item_data['destination-directory']))
         					$item_data['destination-directory'] = '';
         
         				if (!isset($item_data['tables-option'])) {
         					$item_data['tables-count'] = '';
         
         					if ($all_tables_sections) {
         						$all_tables_option = true;
         
         						foreach($all_tables_sections as $section => $section_tables) {
         							if (count($section_tables)) {
         								$item_data['tables-sections'][$section] = array_intersect_key($section_tables, $item_data['tables']);
         								$item_data['tables-count'] += count($item['tables-sections'][$section]);
         
         								if (count($item_data['tables-sections'][$section]) != count($section_tables))
         									$all_tables_option = false;
         							}
         							else
         								$item_data['tables-sections'][$section] = array();
         						}
         
         						if ($all_tables_option == true) {
         							$item_data['tables-option'] = 'all';
         						} else {
         							$item_data['tables-option'] = 'selected';
         						}
         					}
         				}
         				unset($item_data['tables']);
         
         				$item_data['files-option'] 	= "none";
         				$item_data['files-sections'] = array();
         				$item_data['files-count']	= 0;
         
         				if ((isset($item_data['filename'])) && (strlen($item_data['filename']))) {
         					$backupZipFile = trailingslashit($this->_settings['backupBaseFolderFull']) . $item_data['filename'];
         					if (file_exists($backupZipFile)) {
         
         						// Get the file size
         						$item_data['file_size'] = filesize($backupZipFile);
         
         						// Now we do a hard task and extract the minifest.txt file then convert it to the new format. Tricky X 2!
         						if (!defined('PCLZIP_TEMPORARY_DIR'))
         							define('PCLZIP_TEMPORARY_DIR', trailingslashit($this->_settings['backupBackupFolderFull']) . $item_key."/");
         						if (!class_exists('class PclZip'))
         							require_once(ABSPATH . '/wp-admin/includes/class-pclzip.php');
         
         						$zipArchive = new PclZip($backupZipFile);
         						$zip_contents = $zipArchive->listContent();
         						if (($zip_contents) && (!empty($zip_contents))) {
         
         							foreach($zip_contents as $zip_index => $zip_file_info) {
         								if ($zip_file_info['stored_filename'] == "snapshot_manifest.txt") {
         
         									snapshot_utility_recursive_rmdir($restoreFolder);
         									$extract_files = $zipArchive->extractByIndex($zip_index, $restoreFolder);
         									if ($extract_files) {
         
         										$snapshot_manifest_file = trailingslashit($restoreFolder) . 'snapshot_manifest.txt';
         										if (file_exists($snapshot_manifest_file)) {
         
         											$manifest_data = snapshot_utility_consume_archive_manifest($snapshot_manifest_file);
         
         											$manifest_data['SNAPSHOT_VERSION'] = $this->_settings['SNAPSHOT_VERSION'];
         
         											$manifest_data['WP_UPLOAD_PATH'] = snapshot_utility_get_blog_upload_path(intval($item['blog-id']));
         
         											$item_tmp = $item;
         											unset($item_tmp['data']);
         											$item_tmp['data'] = array();
         											$item_tmp['data'][$item_data_idx] = $item_data;
         											$manifest_data['ITEM'] = $item_tmp;
         
         											$manifest_data['TABLES'] = $item_data['tables-sections'];
         											//echo "manifest_data<pre>"; print_r($manifest_data); echo "</pre>";
         
         											if (snapshot_utility_create_archive_manifest($manifest_data, $snapshot_manifest_file)) {
         												$zipArchive->deleteByIndex($zip_index);
         
         												$archiveFiles = array($snapshot_manifest_file);
         												$zipArchive->add($archiveFiles,
         													PCLZIP_OPT_REMOVE_PATH, $restoreFolder,
         													PCLZIP_OPT_TEMP_FILE_THRESHOLD, 10);
         
         												foreach($archiveFiles as $archiveFile) {
         													@unlink($archiveFile);
         												}
         											}
         										}
         									}
         									break;
         								}
         							}
         						}
         					}
         				}
         
         				$item['data'][$item_data_idx] = $item_data;
         			}
         			krsort($item['data']);
         		}
         
         		// Convert the logs...
         
         		$backupLogFileFull = trailingslashit($this->_settings['backupLogFolderFull']) . $item['timestamp'] ."_backup.log";
         		if (file_exists($backupLogFileFull)) {
         			$log_entries = snapshot_utility_get_archive_log_entries($backupLogFileFull);
         			if (($log_entries) && (count($log_entries))) {
         				foreach($log_entries as $log_key => $log_data) {
         					foreach($item['data'] as $item_data_idx => $item_data) {
         						if ($log_key == $item_data['filename']) {
         							$new_backupLogFileFull = trailingslashit($this->_settings['backupLogFolderFull']) .
         								$item['timestamp'] ."_". $item_data_idx .".log";
         							file_put_contents($new_backupLogFileFull, implode("\r\n", $log_data));
         						}
         					}
         				}
         			}
         			@unlink($backupLogFileFull);
         		}
         
         		$this->config_data['items'][$item_idx] = $item;
         	}
         
         	// Now convert the Last Tables config section
         	if (isset($this->config_data['config']['tables_last'])) {
         		foreach ($this->config_data['config']['tables_last'] as $blog_id => $item_tables) {
         
         			$all_tables_sections = snapshot_utility_get_database_tables($blog_id);
         			if ($all_tables_sections) {
         				$item_section_tables = array();
         				foreach($all_tables_sections as $section => $section_tables) {
         					if (count($section_tables))
         						$item_section_tables[$section] = array_intersect_key($section_tables, $item_tables);
         					else
         						$item_section_tables[$section] = array();
         				}
         			}
         			$this->config_data['config']['tables_last'][$blog_id] = $item_section_tables;
         		}
         	}
         }
         */
         /*
         				foreach($this->config_data['items'] as $item_idx => $item) {
         					if (!isset($item['data'])) continue;
         
         					foreach($item['data'] as $item_data_idx => $item_data) {
         						if (!isset($item_data['destination-status'])) continue;
         
         						foreach($item_data['destination-status'] as $destination_idx => $destination_status) {
         							if (isset($destination_status['sendFileStatus'])) continue;
         
         							if ( (isset($destination_status['responseArray'])) && (count($destination_status['responseArray']))
         							  && (isset($destination_status['errorStatus'])) && ($destination_status['errorStatus'] != true) ) {
         
         								// Assumed! Since we have responseArray items and the errorStatus is NOT set. Assume success
         								$this->config_data['items'][$item_idx]['data'][$item_data_idx]['destination-status'][$destination_idx]['sendFileStatus'] = true;
         							}
         						}
         					}
         				}
         */
         //echo "config_data<pre>"; print_r($this->config_data['items']); echo "</pre>";
         //die();
         $this->config_data['version'] = $this->_settings['SNAPSHOT_VERSION'];
         $this->save_config();
     }
 }