public/wordpress/wp-content/plugins/backupbuddy/lib/textreplacebuddy/textreplacebuddy.php
/*	_stringreplace_commandline()
	 *	
	 *	Performs actual command line string replacement. VIA sed (command line replace).
	 *	Case sensitive.
	 *	Resulting file stored in $file . 'tmp'. Original file is NOT replaced.
	 *	
	 *	@param		string		$file				Full file path to file to replace in. a .tmp version is temporarily made.
	 *	@param		string		$search				String to search for.
	 *	@param		string		$replacement		String to replace with.
	 *	@param		string		$regex_condition	Condition when replacements may happen. Optional.
	 *	@param		string		$regex_replace		NOT used in commandline mode.
	 *	@param		boolean		$global				Whether or not to globally replace in regex. Default: false (only replace first instance per line).
	 *	@return		boolean							True on success; else false.
	 */


Performs actual command line string replacement. VIA sed (command line replace).
Case sensitive.
Resulting file stored in $file . 'tmp'. Original file is NOT replaced.

@param          string          $file                           Full file path to file to replace in. a .tmp version is temporarily made.
@param          string          $search                         String to search for.
@param          string          $replacement            String to replace with.
@param          string          $regex_condition        Condition when replacements may happen. Optional.
@param          string          $regex_replace          NOT used in commandline mode.
@param          boolean         $global                         Whether or not to globally replace in regex. Default: false (only replace first instance per line).
@return         boolean                                                 True on success; else false.
Performs actual command line string replacement . VIA sed ( command line replace ) . Case sensitive . Resulting file stored in $file . ' tmp ' . Original file is NOT replaced . @param string $file Full file path to file to replace in . a . tmp version is temporarily made . @param string $search String to search for . @param string $replacement String to replace with . @param string $regex_condition Condition when replacements may happen . Optional . @param string $regex_replace NOT used in commandline mode . @param boolean $global Whether or not to globally replace in regex . Default : false ( only replace first instance per line ) . @return boolean True on success ; else false .
private function _stringreplace_commandline( $file, $search, $replacement, $regex_condition = '', $regex_replace = '', $global = false ) {
		pb_backupbuddy::status( 'details', 'textreplacebuddy: Preparing to run command line sed (replacement comment) via exec().' );
		if ( $global === true ) {
			$global_flag = 'g';
			pb_backupbuddy::status( 'details', 'textreplacebuddy: Using global replace per line.' );
		} else {
			$global_flag = '';
			pb_backupbuddy::status( 'details', 'textreplacebuddy: Using first instance replace per line.' );
		}
		if ( stristr( PHP_OS, 'WIN' ) && !stristr( PHP_OS, 'DARWIN' ) ) { 
			return false;
		} else {
			if ( $regex_condition == '' ) { 
				$command = "sed s/{$search}/{$replacement}/{$global_flag} {$file} > {$file}.tmp";
			} else { 
				$command = "sed -E '/{$regex_condition}/s/{$search}/{$replacement}/{$global_flag}' {$file} > {$file}.tmp";
			}
		}
		$command .= '  2>&1';
		pb_backupbuddy::status( 'details', 'textreplacebuddy: Running replace command via exec next.' );
		list( $exec_output, $exec_exit_code ) = $this->_commandbuddy->execute( $command );
		if ( $exec_exit_code == '0' ) {
			pb_backupbuddy::status( 'details', 'textreplacebuddy: Command appears to succeeded and returned proper response.' );
			if ( file_exists( $file . '.tmp' ) ) { 
				pb_backupbuddy::status( 'message', 'textreplacebuddy: Temporary text replacement file creation verified.' );
				return true;
			} else { 
				pb_backupbuddy::status( 'error', 'textreplacebuddy: Though command reported success temporary replacement file is missing: `' . $output_file . '`.' );
				return false;
			}
		} else {
			pb_backupbuddy::status( 'error', 'textreplacebuddy: Command did not exit normally. Falling back to text replacement compatibility modes.' );
			return false;
		}
		pb_backupbuddy::status( 'error', 'textreplacebuddy: Uncaught exception #45323890.' );
		return false;
	}
private function _stringreplace_commandline ( $ file , $ search , $ replacement , $ regex_condition = '' , $ regex_replace = '' , $ global = false ) { pb_backupbuddy :: status ( 'details' , 'textreplacebuddy: Preparing to run command line sed (replacement comment) via exec().' ) ; if ( $ global === true ) { $ global_flag = 'g' ; pb_backupbuddy :: status ( 'details' , 'textreplacebuddy: Using global replace per line.' ) ; } else { $ global_flag = '' ; pb_backupbuddy :: status ( 'details' , 'textreplacebuddy: Using first instance replace per line.' ) ; } if ( stristr ( PHP_OS , 'WIN' ) && ! stristr ( PHP_OS , 'DARWIN' ) ) { return false ; } else { if ( $ regex_condition == '' ) { $ command = " sed s/ { $ search } / { $ replacement } / { $ global_flag } { $ file }  >  { $ file } .tmp " ; } else { $ command = " sed -E '/ { $ regex_condition } /s/ { $ search } / { $ replacement } / { $ global_flag } '  { $ file }  >  { $ file } .tmp " ; } } $ command .= '  2>&1' ; pb_backupbuddy :: status ( 'details' , 'textreplacebuddy: Running replace command via exec next.' ) ; list ( $ exec_output , $ exec_exit_code ) = $ this -> _commandbuddy -> execute ( $ command ) ; if ( $ exec_exit_code == '0' ) { pb_backupbuddy :: status ( 'details' , 'textreplacebuddy: Command appears to succeeded and returned proper response.' ) ; if ( file_exists ( $ file . '.tmp' ) ) { pb_backupbuddy :: status ( 'message' , 'textreplacebuddy: Temporary text replacement file creation verified.' ) ; return true ; } else { pb_backupbuddy :: status ( 'error' , 'textreplacebuddy: Though command reported success temporary replacement file is missing: `' . $ output_file . '`.' ) ; return false ; } } else { pb_backupbuddy :: status ( 'error' , 'textreplacebuddy: Command did not exit normally. Falling back to text replacement compatibility modes.' ) ; return false ; } pb_backupbuddy :: status ( 'error' , 'textreplacebuddy: Uncaught exception #45323890.' ) ; return false ; }
_stringreplace_commandline()
_stringreplace_commandline ()
// Handle optional global replacement. /********** Begin preparing command **********/ // Handle Windows wanting .exe. // Running Windows. (not darwin) // Normal string replace. // Custom regex conditions. // Redirect STDERR to STDOUT. /********** End preparing command **********/ // Run command. // Check the result. // Temp replacement file found. SUCCESS! /*
				if ( true === rename( $file . '.tmp', $file ) ) {
					pb_backupbuddy::status( 'message', 'textreplacebuddy: Temporary moved back to original file. Success.' );
					return true;
				} else {
					pb_backupbuddy::status( 'error', 'textreplacebuddy: Temporary could not be moved back to original file. Failure. Verify permissions.' );
					return false;
				}
				*/ // SQL file MISSING. FAILURE! // Should never get to here.