public/wordpress/wp-content/plugins/backupbuddy/lib/xzipbuddy/zipbuddy.php
/**
		 *	add_directory_to_zip()
		 *
		 *	Adds a directory to a new or existing (TODO: not yet available) ZIP file.
		 *
		 *	@param	string	$zip_file					Full path & filename of ZIP file to create.
		 *	@param	string	$add_directory				Full directory to add to zip file.
		 *	@param	array	$excludes					Array of strings of paths/files to exclude from zipping
		 *	@param	string	$temporary_zip_directory	Full directory path to directory to temporarily place ZIP
		 *
		 *	@return						true on success, false otherwise
		 *
		 */
add_directory_to_zip()
Adds a directory to a new or existing (TODO: not yet available) ZIP file.

@param  string  $zip_file                                       Full path & filename of ZIP file to create.
@param  string  $add_directory                          Full directory to add to zip file.
@param  array   $excludes                                       Array of strings of paths/files to exclude from zipping
@param  string  $temporary_zip_directory        Full directory path to directory to temporarily place ZIP

@return                                         true on success, false otherwise
add_directory_to_zip () Adds a directory to a new or existing ( TODO : not yet available ) ZIP file . @param string $zip_file Full path & filename of ZIP file to create . @param string $add_directory Full directory to add to zip file . @param array $excludes Array of strings of paths / files to exclude from zipping @param string $temporary_zip_directory Full directory path to directory to temporarily place ZIP @return true on success false otherwise
public function add_directory_to_zip( $zip_file, $add_directory, $excludes = array(), $temporary_zip_directory = '' ) {
			if ( true === $this->_is_experimental ) {
				$this->log( 'message', __('Running alternative ZIP system (BETA) based on settings.','it-l10n-backupbuddy' ) );
			} else {
				$this->log( 'message', __('Running standard ZIP system based on settings.','it-l10n-backupbuddy' ) );
			}
			$php_size = ( pluginbuddy_stat::is_php( pluginbuddy_stat::THIRTY_TWO_BIT ) ) ? "32" : "64" ;
			$this->log( 'details', sprintf( __( 'Running under %1$s-bit PHP', 'it-l10n-backupbuddy' ), $php_size ) );
			$this->log( 'details', sprintf( __( 'Server API: %1$s', 'it-l10n-backupbuddy' ), $this->get_sapi_name() ) );			
			$zip_methods = array();
			$sanitized_excludes = array();
			$additional_excludes = array();
			if ( isset( pb_backupbuddy::$options[ 'zip_method_strategy' ] ) && 	( '0' !== pb_backupbuddy::$options[ 'zip_method_strategy' ] ) ) {
				$zip_method_strategy = pb_backupbuddy::$options[ 'zip_method_strategy' ];
				switch ( $zip_method_strategy ) {
					case "1":
						$zip_methods = $this->get_best_zip_methods( array( 'is_archiver' ) );
						$this->log( 'details', __('Using Best Available zip method based on settings.','it-l10n-backupbuddy' ) );
						break;
					case "2":
						$zip_methods = $this->_zip_methods;
						$this->log( 'details', __('Using All Available zip methods in preferred order based on settings.','it-l10n-backupbuddy' ) );
						break;
					case "3":
						$zip_methods = $this->get_compatibility_zip_methods();				
						$this->log( 'message', __('Using Forced Compatibility zip method based on settings.','it-l10n-backupbuddy' ) );
						break;
					default:
						$zip_methods = $this->get_compatibility_zip_methods();				
						$this->log( 'message', sprintf( __('Forced Compatibility Mode as Zip Method Strategy setting not recognized: %1$s','it-l10n-backupbuddy' ), $zip_method_strategy ) );
				}
			} else {
				$zip_methods = $this->get_compatibility_zip_methods();				
				$this->log( 'message', __('Forced Compatibility Mode as Zip Method Strategy not set or setting not recognized.','it-l10n-backupbuddy' ) );
			}
			if ( empty( $zip_methods ) ) {
				$this->log( 'details', __('Failed to create a Zip Archive file - no available methods.','it-l10n-backupbuddy' ) );
				if ( !empty( $temporary_zip_directory ) && file_exists( $temporary_zip_directory ) ) {
					if ( !rmdir( $temporary_zip_directory ) ) {
						$this->log( 'details', __('Temporary directory could not be deleted: ','it-l10n-backupbuddy' ) . $temporary_zip_directory );
					}
				}
				return false;
			}
			$this->log( 'details', __('Creating ZIP file','it-l10n-backupbuddy' ) . ' `' . $zip_file . '`. ' . __('Adding directory','it-l10n-backupbuddy' ) . ' `' . $add_directory . '`. ' . __('Excludes','it-l10n-backupbuddy' ) . ': ' . implode( ',', $excludes ) );
			require_once( pb_backupbuddy::plugin_path() . '/lib/' . $this->_whereami . '/zbdir.php' );
			if ( !class_exists( 'pluginbuddy_zbdir' ) ) {
				$this->log( 'details', __('Unable to load classes for backup file list builder.','it-l10n-backupbuddy' ) );
				return false;
			}
			$sanitized_excludes = $this->sanitize_excludes( $excludes, $additional_excludes );
			foreach ( $zip_methods as $method_tag ) {
				if ( $this->_zip_methods_details[ $method_tag ][ 'attr' ][ 'is_archiver' ] === true ) {
					$class_name = 'pluginbuddy_zbzip' . $method_tag;
					$zipper = new $class_name( $this );
					$zipper->set_logger( $this->_default_child_logger );
					$zipper->set_compression( $this->get_compression() );
					$zipper->set_ignore_symlinks( $this->get_ignore_symlinks() );
					$zipper->set_ignore_warnings( $this->get_ignore_warnings() );
					$zipper->set_step_period( $this->get_step_period() );
					$zipper->set_burst_gap( $this->get_burst_gap() );
					$zipper->set_min_burst_content( $this->get_min_burst_content() );
					$zipper->set_max_burst_content( $this->get_max_burst_content() );
					$zipper->set_method_details( $this->_zip_methods_details[ $method_tag ] );
					$zipper->set_sapi_name( $this->get_sapi_name() );
					$this->log( 'details', __('Trying ', 'it-l10n-backupbuddy' ) . $method_tag . __(' method for ZIP.','it-l10n-backupbuddy' ) );
					clearstatcache();
					if ( !empty( $temporary_zip_directory ) ) {
						if ( !file_exists( $temporary_zip_directory ) ) { 
							mkdir( $temporary_zip_directory );
						}
					}
					if (  true === ( $result = $zipper->create( $zip_file, $add_directory, $sanitized_excludes, $temporary_zip_directory ) ) ) {
						$this->log( 'details', __('The ', 'it-l10n-backupbuddy' ) . $method_tag . __(' method for ZIP was successful.','it-l10n-backupbuddy' ) );
						unset( $zipper );
						return true;
					} elseif ( is_array( $result ) ) {
						$this->log( 'details', __('The ', 'it-l10n-backupbuddy' ) . $method_tag . __(' method for ZIP partially completed.','it-l10n-backupbuddy' ) );
						unset( $zipper );
						return $result;
					} else {
						$this->log( 'details', __('The ', 'it-l10n-backupbuddy' ) . $method_tag . __(' method for ZIP was unsuccessful.','it-l10n-backupbuddy' ) );
						unset( $zipper );
					}
				} else {
					$this->log( 'details', __('The ','it-l10n-backupbuddy' ) . $method_tag . __(' method is not currently supported for backup.','it-l10n-backupbuddy' ) );					
				}
			}
			$this->log( 'details', __('Failed to create a Zip Archive file with any nominated method.','it-l10n-backupbuddy' ) );
			return false;
		}
public function add_directory_to_zip ( $ zip_file , $ add_directory , $ excludes = array ( ) , $ temporary_zip_directory = '' ) { if ( true === $ this -> _is_experimental ) { $ this -> log ( 'message' , __ ( 'Running alternative ZIP system (BETA) based on settings.' , 'it-l10n-backupbuddy' ) ) ; } else { $ this -> log ( 'message' , __ ( 'Running standard ZIP system based on settings.' , 'it-l10n-backupbuddy' ) ) ; } $ php_size = ( pluginbuddy_stat :: is_php ( pluginbuddy_stat :: THIRTY_TWO_BIT ) ) ? " 32 " : " 64 " ; $ this -> log ( 'details' , sprintf ( __ ( 'Running under %1$s-bit PHP' , 'it-l10n-backupbuddy' ) , $ php_size ) ) ; $ this -> log ( 'details' , sprintf ( __ ( 'Server API: %1$s' , 'it-l10n-backupbuddy' ) , $ this -> get_sapi_name ( ) ) ) ; $ zip_methods = array ( ) ; $ sanitized_excludes = array ( ) ; $ additional_excludes = array ( ) ; if ( isset ( pb_backupbuddy :: $ options [ 'zip_method_strategy' ] ) && ( '0' !== pb_backupbuddy :: $ options [ 'zip_method_strategy' ] ) ) { $ zip_method_strategy = pb_backupbuddy :: $ options [ 'zip_method_strategy' ] ; switch ( $ zip_method_strategy ) { case " 1 " : $ zip_methods = $ this -> get_best_zip_methods ( array ( 'is_archiver' ) ) ; $ this -> log ( 'details' , __ ( 'Using Best Available zip method based on settings.' , 'it-l10n-backupbuddy' ) ) ; break ; case " 2 " : $ zip_methods = $ this -> _zip_methods ; $ this -> log ( 'details' , __ ( 'Using All Available zip methods in preferred order based on settings.' , 'it-l10n-backupbuddy' ) ) ; break ; case " 3 " : $ zip_methods = $ this -> get_compatibility_zip_methods ( ) ; $ this -> log ( 'message' , __ ( 'Using Forced Compatibility zip method based on settings.' , 'it-l10n-backupbuddy' ) ) ; break ; default : $ zip_methods = $ this -> get_compatibility_zip_methods ( ) ; $ this -> log ( 'message' , sprintf ( __ ( 'Forced Compatibility Mode as Zip Method Strategy setting not recognized: %1$s' , 'it-l10n-backupbuddy' ) , $ zip_method_strategy ) ) ; } } else { $ zip_methods = $ this -> get_compatibility_zip_methods ( ) ; $ this -> log ( 'message' , __ ( 'Forced Compatibility Mode as Zip Method Strategy not set or setting not recognized.' , 'it-l10n-backupbuddy' ) ) ; } if ( empty ( $ zip_methods ) ) { $ this -> log ( 'details' , __ ( 'Failed to create a Zip Archive file - no available methods.' , 'it-l10n-backupbuddy' ) ) ; if ( ! empty ( $ temporary_zip_directory ) && file_exists ( $ temporary_zip_directory ) ) { if ( ! rmdir ( $ temporary_zip_directory ) ) { $ this -> log ( 'details' , __ ( 'Temporary directory could not be deleted: ' , 'it-l10n-backupbuddy' ) . $ temporary_zip_directory ) ; } } return false ; } $ this -> log ( 'details' , __ ( 'Creating ZIP file' , 'it-l10n-backupbuddy' ) . ' `' . $ zip_file . '`. ' . __ ( 'Adding directory' , 'it-l10n-backupbuddy' ) . ' `' . $ add_directory . '`. ' . __ ( 'Excludes' , 'it-l10n-backupbuddy' ) . ': ' . implode ( ',' , $ excludes ) ) ; require_once ( pb_backupbuddy :: plugin_path ( ) . '/lib/' . $ this -> _whereami . '/zbdir.php' ) ; if ( ! class_exists ( 'pluginbuddy_zbdir' ) ) { $ this -> log ( 'details' , __ ( 'Unable to load classes for backup file list builder.' , 'it-l10n-backupbuddy' ) ) ; return false ; } $ sanitized_excludes = $ this -> sanitize_excludes ( $ excludes , $ additional_excludes ) ; foreach ( $ zip_methods as $ method_tag ) { if ( $ this -> _zip_methods_details [ $ method_tag ] [ 'attr' ] [ 'is_archiver' ] === true ) { $ class_name = 'pluginbuddy_zbzip' . $ method_tag ; $ zipper = new $ class_name ( $ this ) ; $ zipper -> set_logger ( $ this -> _default_child_logger ) ; $ zipper -> set_compression ( $ this -> get_compression ( ) ) ; $ zipper -> set_ignore_symlinks ( $ this -> get_ignore_symlinks ( ) ) ; $ zipper -> set_ignore_warnings ( $ this -> get_ignore_warnings ( ) ) ; $ zipper -> set_step_period ( $ this -> get_step_period ( ) ) ; $ zipper -> set_burst_gap ( $ this -> get_burst_gap ( ) ) ; $ zipper -> set_min_burst_content ( $ this -> get_min_burst_content ( ) ) ; $ zipper -> set_max_burst_content ( $ this -> get_max_burst_content ( ) ) ; $ zipper -> set_method_details ( $ this -> _zip_methods_details [ $ method_tag ] ) ; $ zipper -> set_sapi_name ( $ this -> get_sapi_name ( ) ) ; $ this -> log ( 'details' , __ ( 'Trying ' , 'it-l10n-backupbuddy' ) . $ method_tag . __ ( ' method for ZIP.' , 'it-l10n-backupbuddy' ) ) ; clearstatcache ( ) ; if ( ! empty ( $ temporary_zip_directory ) ) { if ( ! file_exists ( $ temporary_zip_directory ) ) { mkdir ( $ temporary_zip_directory ) ; } } if ( true === ( $ result = $ zipper -> create ( $ zip_file , $ add_directory , $ sanitized_excludes , $ temporary_zip_directory ) ) ) { $ this -> log ( 'details' , __ ( 'The ' , 'it-l10n-backupbuddy' ) . $ method_tag . __ ( ' method for ZIP was successful.' , 'it-l10n-backupbuddy' ) ) ; unset ( $ zipper ) ; return true ; } elseif ( is_array ( $ result ) ) { $ this -> log ( 'details' , __ ( 'The ' , 'it-l10n-backupbuddy' ) . $ method_tag . __ ( ' method for ZIP partially completed.' , 'it-l10n-backupbuddy' ) ) ; unset ( $ zipper ) ; return $ result ; } else { $ this -> log ( 'details' , __ ( 'The ' , 'it-l10n-backupbuddy' ) . $ method_tag . __ ( ' method for ZIP was unsuccessful.' , 'it-l10n-backupbuddy' ) ) ; unset ( $ zipper ) ; } } else { $ this -> log ( 'details' , __ ( 'The ' , 'it-l10n-backupbuddy' ) . $ method_tag . __ ( ' method is not currently supported for backup.' , 'it-l10n-backupbuddy' ) ) ; } } $ this -> log ( 'details' , __ ( 'Failed to create a Zip Archive file with any nominated method.' , 'it-l10n-backupbuddy' ) ) ; return false ; }
add_directory_to_zip()
      Adds a directory to a new or existing (TODO: not yet available) ZIP file.
add_directory_to_zip () Adds a directory to a new or existing ( TODO : not yet available ) ZIP file .
// Let's just log if this is a 32 or 64 bit system // Make sure we tell what the sapi is // Set some additional system excludes here for now - these are all from the site install root // Make sure we have a valid zip method strategy setting to use otherwise fall back to emergency compatibility // Best Available // All Available // Force Compatibility // Hmm...unrecognized value - emergency compatibility // We got no or an invalid zip method strategy which is a bad situation - emergency compatibility is the order of the day // Better make sure we have some available methods // Hmm, we don't seem to have any available methods, oops, best go no further // We should have a temporary directory, must get rid of it, can simply rmdir it as it will (should) be empty // We need the classes for being able to build backup file list // Hmm, require_once() didn't bomb but we haven't got the class we expect - bail out // Generate our sanitized list of directories/files to exclude as relative paths // Do the same for directories/files to include //$sanitized_includes = $this->sanitize_excludes( $includes, $additional_includes ); // Iterate over the methods - once we succeed just return directly otherwise drop through // First make sure we can archive with this method // Zipper will initially inherit our logger and our // process monitor // Now override logger - will define a prefix here // Set these on specific zipper based on the values we derived at construnction or // overridden by subsequent method calls // We need to tell the method what details belong to it // Tell the method the server api in use // As we are looping make sure we have no stale file information // The temporary zip directory _must_ exist // Create temp dir if it does not exist. // Now we are ready to try and produce the backup // Got a valid zip file so we can just return - method will have cleaned up the temporary directory // We have to return here because we cannot break out of foreach // Didn't finish zip creation on that step so we need to set up for another step // Add in any addiitonal state information and simply return the state // We failed on the first step for one eason or another - may be an option // to try with another method... // Method will have cleaned up the temporary directory				 // This method is not considered suitable (reliable enough) for creating archives or lacked zip capability // If we get here then have failed in all attempts