public/wordpress/wp-content/plugins/backupbuddy/lib/zipbuddy/zbzipexec.php
/**
		 *	extract_generic_selected()
		 *
		 *	Extracts the contents of a zip file to the specified directory using the best unzip methods possible.
		 *
		 *	@param	string		$zip_file					Full path & filename of ZIP file to extract from.
		 *	@param	string		$destination_directory		Full directory path to extract into.
		 *	@param	array		$items						Mapping of what to extract and to what
		 *	@return	bool									true on success (all extractions successful), false otherwise
		 */
extract_generic_selected()
Extracts the contents of a zip file to the specified directory using the best unzip methods possible.

@param  string          $zip_file                                       Full path & filename of ZIP file to extract from.
@param  string          $destination_directory          Full directory path to extract into.
@param  array           $items                                          Mapping of what to extract and to what
@return bool                                                                    true on success (all extractions successful), false otherwise
extract_generic_selected () Extracts the contents of a zip file to the specified directory using the best unzip methods possible . @param string $zip_file Full path & filename of ZIP file to extract from . @param string $destination_directory Full directory path to extract into . @param array $items Mapping of what to extract and to what @return bool true on success ( all extractions successful ) false otherwise
protected function extract_generic_selected( $zip_file, $destination_directory = '', $items ) {
			$summary = '';
			$output = array();
			$exit_code = 127;
			$matches = array();
			$result = false;
			$zippath = '';
			$command = '';
			$rename_required = false;
			if ( function_exists( 'exec' ) ) {
				$zippath = $this->get_command_path( self::COMMAND_UNZIP_PATH );
				if ( !empty ( $zippath ) ) {
					pb_backupbuddy::status( 'details', __( 'Using absolute unzip path: ','it-l10n-backupbuddy' ) . $zippath );
				}
				$command = $this->slashify( $zippath ) . 'unzip';	
				foreach ( $items as $what => $where ) {
					$rename_required = false;
					$result = false;
					if ( empty( $where) ) {
						$unzip_command = $command . " -qqoj '{$zip_file}' '{$what}' -d '{$destination_directory}' ";
					} elseif ( !empty( $where ) ) {
						if ( $what === $where ) {
							$unzip_command = $command . " -qqo '{$zip_file}' '{$what}' -d '{$destination_directory}' ";
						} else {
							$unzip_command = $command . " -qqoj '{$zip_file}' '{$what}' -d '{$destination_directory}' ";
							$rename_required = true;
						}
					}
					$unzip_command = ( self::OS_TYPE_WIN === $this->get_os_type() ) ? str_replace( '\'', '"', $unzip_command ) : $unzip_command;
					@exec( $unzip_command, $output, $exit_code);
					switch ( (int) $exit_code ) {
						case 0:
							pb_backupbuddy::status( 'details', sprintf( __('exec (unzip) extracted file contents (%1$s from %2$s to %3$s%4$s)','it-l10n-backupbuddy' ), $what, $zip_file, $destination_directory, $where ) );
							$result = true;
							if ( true === $rename_required) {
								$result = $result && rename( $destination_directory . DIRECTORY_SEPARATOR . basename( $what ),
															 $destination_directory . DIRECTORY_SEPARATOR . $where );
							}
							break;
						default:
							$error_string = $exit_code;
							pb_backupbuddy::status( 'details', sprintf( __('exec (unzip) failed to open/process file to extract contents (%1$s from %2$s to %3$s%4$s) - Error Info: %5$s.','it-l10n-backupbuddy' ), $what, $zip_file, $destination_directory, $where, $error_string ) );
							$result = false;
					}
					if ( false === $result ) {
						break;
					}
				}
			} else {
				pb_backupbuddy::status( 'details', __('exec indicated as available method but exec function non-existent','it-l10n-backupbuddy' ) );
				$result = false;
			}
			return $result;
		}
protected function extract_generic_selected ( $ zip_file , $ destination_directory = '' , $ items ) { $ summary = '' ; $ output = array ( ) ; $ exit_code = 127 ; $ matches = array ( ) ; $ result = false ; $ zippath = '' ; $ command = '' ; $ rename_required = false ; if ( function_exists ( 'exec' ) ) { $ zippath = $ this -> get_command_path ( self :: COMMAND_UNZIP_PATH ) ; if ( ! empty ( $ zippath ) ) { pb_backupbuddy :: status ( 'details' , __ ( 'Using absolute unzip path: ' , 'it-l10n-backupbuddy' ) . $ zippath ) ; } $ command = $ this -> slashify ( $ zippath ) . 'unzip' ; foreach ( $ items as $ what => $ where ) { $ rename_required = false ; $ result = false ; if ( empty ( $ where ) ) { $ unzip_command = $ command . "  -qqoj ' { $ zip_file } ' ' { $ what } ' -d ' { $ destination_directory } '  " ; } elseif ( ! empty ( $ where ) ) { if ( $ what === $ where ) { $ unzip_command = $ command . "  -qqo ' { $ zip_file } ' ' { $ what } ' -d ' { $ destination_directory } '  " ; } else { $ unzip_command = $ command . "  -qqoj ' { $ zip_file } ' ' { $ what } ' -d ' { $ destination_directory } '  " ; $ rename_required = true ; } } $ unzip_command = ( self :: OS_TYPE_WIN === $ this -> get_os_type ( ) ) ? str_replace ( '\'' , '"' , $ unzip_command ) : $ unzip_command ; @ exec ( $ unzip_command , $ output , $ exit_code ) ; switch ( ( int ) $ exit_code ) { case 0 : pb_backupbuddy :: status ( 'details' , sprintf ( __ ( 'exec (unzip) extracted file contents (%1$s from %2$s to %3$s%4$s)' , 'it-l10n-backupbuddy' ) , $ what , $ zip_file , $ destination_directory , $ where ) ) ; $ result = true ; if ( true === $ rename_required ) { $ result = $ result && rename ( $ destination_directory . DIRECTORY_SEPARATOR . basename ( $ what ) , $ destination_directory . DIRECTORY_SEPARATOR . $ where ) ; } break ; default : $ error_string = $ exit_code ; pb_backupbuddy :: status ( 'details' , sprintf ( __ ( 'exec (unzip) failed to open/process file to extract contents (%1$s from %2$s to %3$s%4$s) - Error Info: %5$s.' , 'it-l10n-backupbuddy' ) , $ what , $ zip_file , $ destination_directory , $ where , $ error_string ) ) ; $ result = false ; } if ( false === $ result ) { break ; } } } else { pb_backupbuddy :: status ( 'details' , __ ( 'exec indicated as available method but exec function non-existent' , 'it-l10n-backupbuddy' ) ) ; $ result = false ; } return $ result ; }
extract_generic_selected()
      Extracts the contents of a zip file to the specified directory using the best unzip methods possible.
extract_generic_selected () Extracts the contents of a zip file to the specified directory using the best unzip methods possible .
// Get the command path for the unzip command - should return a trimmed string // Determine if we are using an absolute path // Add the trailing slash if required // Now we need to take each item and run an unzip for it - unfortunately there is no easy way of combining // arbitrary extractions into a single command if some might be to a  // Decide how to extract based on where // Extract direct to destination directory with junked path // Extract to same directory structure - don't junk path, no need to add where to destnation as automatic // Firt we'll extract and junk the path // Will need to rename if the extract is ok // Note: we don't open the file and then do stuff but it's all done in one action // so we need to interpret the return code to dedide what to do // Handled archive and apparently no extraction problems						 // Rename if we have to // Note: we junked the path on the extraction so just the filename of $what is the source but // $where could be a simple file name or a file path  // For now let's just print the error code and drop through // Return an error code and a description - this needs to be handled more generically //$result = array( 1, "Unable to get archive contents" ); // Currently as we are returning an array as a valid result we just return false on failure // If the extraction failed (or rename after extraction) then break out of the foreach and simply return false // Something fishy - the methods indicated exec but we couldn't find the function // Return an error code and a description - this needs to be handled more generically //$result = array( 1, "Class not available to match method" ); // Currently as we are returning an array as a valid result we just return false on failure