public/wordpress/wp-content/plugins/backupbuddy/lib/xzipbuddy/zipbuddy.php
/**
		 *	deduce_zip_methods()
		 *	
		 *	Returns the array of zip methods that are available (or just the best) filtered by requested methods.
		 *	Because the available methods don't really change often (rarely once stable) we use a transient
		 *	which has some defined lifetime so we don't waste time repeating the testing which involves creating
		 *	objects and processes and files which can be time consuming.
		 *	The using script can decide to have the transient refreshed by deleting it and then it will be regenerated.
		 *	Note: There is an included "signature" so that we can detect server or other moves and regenerate.
		 *	Note: filemtime() is used because this will (should) force the transient to update if the plugin is
		 *	updated because the file modification time of the file will change because the plugin is installed in a
		 *	different disk location with newly written files - the same should apply if the site is restored/migrated.
		 *	
		 *	@param		array	Array reference for the deduced zip methods
		 *	@param		array	Arry reference for the details of the deduced methods
		 *	@param		array	Flat array of requested (preferred) zip methods
		 *	@param		bool	True if only the best available method wanted
		 *	@param		string	Which zip mode being tested
		 *	@return		bool	True if methods are available, False otherwise
		 *
		 */


Returns the array of zip methods that are available (or just the best) filtered by requested methods.
Because the available methods don't really change often (rarely once stable) we use a transient
which has some defined lifetime so we don't waste time repeating the testing which involves creating
objects and processes and files which can be time consuming.
The using script can decide to have the transient refreshed by deleting it and then it will be regenerated.
Note: There is an included "signature" so that we can detect server or other moves and regenerate.
Note: filemtime() is used because this will (should) force the transient to update if the plugin is
updated because the file modification time of the file will change because the plugin is installed in a
different disk location with newly written files - the same should apply if the site is restored/migrated.


Returns the array of zip methods that are available ( or just the best ) filtered by requested methods . Because the available methods don ' t really change often ( rarely once stable ) we use a transient which has some defined lifetime so we don ' t waste time repeating the testing which involves creating objects and processes and files which can be time consuming . The using script can decide to have the transient refreshed by deleting it and then it will be regenerated . Note : There is an included " signature " so that we can detect server or other moves and regenerate . Note : filemtime () is used because this will ( should ) force the transient to update if the plugin is updated because the file modification time of the file will change because the plugin is installed in a different disk location with newly written files - the same should apply if the site is restored / migrated .
protected function deduce_zip_methods( array &$methods, array &$methods_details, array $requested, $best_only ) {
			$available_methods = array();
			$available_methods_details = array();
			$aggregate_available_methods = array();
			$server_signature_string = "";
			$server_signature = "";
			$use_cached_methods = false;
			if ( ( $use_cached_methods = $this->use_cached_methods() ) ) {
				$aggregate_available_methods = get_transient( $this->_zip_methods_transient );
				if ( false !== $aggregate_available_methods ) {
					$server_signature_string = __FILE__ . " : " . ( ( $filemodtime = filemtime( __FILE__ ) ) ? (string) $filemodtime : '1' );
					$server_signature = md5( $server_signature_string );
					if ( ( false === isset( $aggregate_available_methods[ 'control' ][ 'signature' ] ) ) ||
						 ( $server_signature !== $aggregate_available_methods[ 'control' ][ 'signature' ] ) ) {
						$aggregate_available_methods = false;
					}
				}
			} else {
				$this->log( 'details', 'Zip method caching disabled based on settings or unavailable.' );
				$aggregate_available_methods = false;
			}
			if ( false === $aggregate_available_methods ) {
				$this->get_available_zip_methods( $this->_supported_zip_methods, $available_methods, $available_methods_details );
				$aggregate_available_methods[ 'methods' ] = $available_methods;
				$aggregate_available_methods[ 'details' ] = $available_methods_details;
				if ( $use_cached_methods ) {
					$server_signature_string = __FILE__ . " : " . ( ( $filemodtime = filemtime( __FILE__ ) ) ? (string) $filemodtime : '1' );
					$server_signature = md5( $server_signature_string );
					$aggregate_available_methods[ 'control' ][ 'signature' ] = $server_signature;
					set_transient( $this->_zip_methods_transient, $aggregate_available_methods, self::ZIP_METHODS_TRANSIENT_LIFE );
				}
			} else {
				$available_methods = $aggregate_available_methods[ 'methods' ];
				$available_methods_details = $aggregate_available_methods[ 'details' ];
			}
			if ( !empty( $requested ) ) {
				$available_methods = array_values( array_intersect( $available_methods, $requested ) );
			}
			if ( ( true === $best_only ) && ( !empty( $available_methods ) ) ) {
				$methods = array_slice( $available_methods, 0, 1 );
				$methods_details = $available_methods_details;
			} else {
				$methods = $available_methods;
				$methods_details = $available_methods_details;
			}
			if ( !empty( $methods ) ) {
				return true;
			} else {
				return false;
			}
		}
protected function deduce_zip_methods ( array & $ methods , array & $ methods_details , array $ requested , $ best_only ) { $ available_methods = array ( ) ; $ available_methods_details = array ( ) ; $ aggregate_available_methods = array ( ) ; $ server_signature_string = " " ; $ server_signature = " " ; $ use_cached_methods = false ; if ( ( $ use_cached_methods = $ this -> use_cached_methods ( ) ) ) { $ aggregate_available_methods = get_transient ( $ this -> _zip_methods_transient ) ; if ( false !== $ aggregate_available_methods ) { $ server_signature_string = __FILE__ . "  :  " . ( ( $ filemodtime = filemtime ( __FILE__ ) ) ? ( string ) $ filemodtime : '1' ) ; $ server_signature = md5 ( $ server_signature_string ) ; if ( ( false === isset ( $ aggregate_available_methods [ 'control' ] [ 'signature' ] ) ) || ( $ server_signature !== $ aggregate_available_methods [ 'control' ] [ 'signature' ] ) ) { $ aggregate_available_methods = false ; } } } else { $ this -> log ( 'details' , 'Zip method caching disabled based on settings or unavailable.' ) ; $ aggregate_available_methods = false ; } if ( false === $ aggregate_available_methods ) { $ this -> get_available_zip_methods ( $ this -> _supported_zip_methods , $ available_methods , $ available_methods_details ) ; $ aggregate_available_methods [ 'methods' ] = $ available_methods ; $ aggregate_available_methods [ 'details' ] = $ available_methods_details ; if ( $ use_cached_methods ) { $ server_signature_string = __FILE__ . "  :  " . ( ( $ filemodtime = filemtime ( __FILE__ ) ) ? ( string ) $ filemodtime : '1' ) ; $ server_signature = md5 ( $ server_signature_string ) ; $ aggregate_available_methods [ 'control' ] [ 'signature' ] = $ server_signature ; set_transient ( $ this -> _zip_methods_transient , $ aggregate_available_methods , self :: ZIP_METHODS_TRANSIENT_LIFE ) ; } } else { $ available_methods = $ aggregate_available_methods [ 'methods' ] ; $ available_methods_details = $ aggregate_available_methods [ 'details' ] ; } if ( ! empty ( $ requested ) ) { $ available_methods = array_values ( array_intersect ( $ available_methods , $ requested ) ) ; } if ( ( true === $ best_only ) && ( ! empty ( $ available_methods ) ) ) { $ methods = array_slice ( $ available_methods , 0 , 1 ) ; $ methods_details = $ available_methods_details ; } else { $ methods = $ available_methods ; $ methods_details = $ available_methods_details ; } if ( ! empty ( $ methods ) ) { return true ; } else { return false ; } }
deduce_zip_methods()
deduce_zip_methods ()
// Decide if we should try for cached methods or not (save for later)			 // Drop through if we didn't get a transient otherwise we'll test it for validity // Generate server signature and check it matches the cached signature // Use current filename as component as it should be unique enough for this purpose // Either no signature previously set or it has changed - either way we need to reevaluate available methods // Create new transient if we didn't have one, it was expired or we nuked it because invalid // Get all available methods in $available_methods - must return them in order best -> worst // Also getting the method details array which is keyed by method tag // Now we have to combine the two arrays into an aggregate to save // Only save if we are using caching (determined earlier) // Add the server signature for detecting invalidated methods details on a migration or some other change // Note: See discussion above on derivation of signature // TODO: Check, probably can use the server signature calculated above // We got a valid transient value so now separate the aggregate into two // Check whether these need to be filtered by requested methods // Filter the available methods - result could be empty // Order will be retained regardless of order of requested methods // Renumber numeric keys fom 0 // If just the best available requested then slice it off