wordpress/wp-content/plugins/sqlite-integration/utilities/patch.php
/**
	 * Method to apply patch to the plugins.
	 *
	 * It executes patch command and apply it to the target plugins.
	 * If patch file(s) is not selected, returns false.
	 * Or else returns array contains messages.
	 *
	 * @return boolean|array
	 * @access private
	 */
Method to apply patch to the plugins.
It executes patch command and apply it to the target plugins.
If patch file(s) is not selected, returns false.
Or else returns array contains messages.

@return boolean|array
@access private
Method to apply patch to the plugins . It executes patch command and apply it to the target plugins . If patch file ( s ) is not selected returns false . Or else returns array contains messages . @return boolean|array @access private
private function apply_patches() {
		global $utils;
		$domain = $utils->text_domain;
		$installed_plugins = array();
		$file_names = array();
		$output = array();
		$retval = 0;
		$patch_results = array();
		$message = '';
		if (isset($_POST['plugin_checked'])) {
			$file_names = $_POST['plugin_checked'];
		} else {
			return false;
		}
		if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
			exec('where patch 2>&1', $out, $val);
		} else {
			exec('which patch 2>&1', $out, $val);
		}
		if ($val != 0) {
			$patch_results['error'] = __('Patch command is not found', $domain);
			return $patch_results;
		} elseif (!is_executable(trim($out[0]))) {
			$patch_results['error'] = __('Patch command is not executable', $domain);
			return $patch_results;
		} else {
			$patch_command = trim($out[0]) . ' -s -N -p1';
		}
		$installed_plugins = get_plugins();
		foreach ($file_names as $file) {
			if (preg_match('/_(.*)\.patch/i', $file, $match)) {
				$plugin_version = trim($match[1]);
				$plugin_basename = preg_replace('/_.*\.patch$/i', '', $file);
				foreach (array_keys($installed_plugins) as $key) {
					if (stripos($key, $plugin_basename) !== false) {
						$installed_plugin_version = $installed_plugins[$key]['Version'];
						break;
					}
				}
			} else {
				$patch_results['error'] = __('Patch file name is invalid', $domain);
				break;
			}
			if (version_compare($installed_plugin_version, $plugin_version, '!=')) {
				$patch_results['error'] = __('Patch file version does not match with that of your plugin.', $domain);
				break;
			}
			$plugin_dir = WP_PLUGIN_DIR.'/'.$plugin_basename;
			$patch_file = SQLitePatchDir.'/'.$file;
			$command = $patch_command.' <'.$patch_file.' 2>&1';
			if (chdir($plugin_dir)) {
				exec("$command", $output, $retval);
			} else {
				$patch_results[$file] = __('Error! Plugin directory is not accessible.', $domain);
			}
			if ($retval == 0) {
				$patch_results[$file] = __('is patched successfully.', $domain);
			} else {
				foreach ($output as $val) {
					$message .= $val.'<br />';
				}
				$patch_results[$file] = sprintf(__('Error! Messages: %s', $domain), $message);
			}
		}
		return $patch_results;
	}
private function apply_patches ( ) { global $ utils ; $ domain = $ utils -> text_domain ; $ installed_plugins = array ( ) ; $ file_names = array ( ) ; $ output = array ( ) ; $ retval = 0 ; $ patch_results = array ( ) ; $ message = '' ; if ( isset ( $ _POST [ 'plugin_checked' ] ) ) { $ file_names = $ _POST [ 'plugin_checked' ] ; } else { return false ; } if ( strtoupper ( substr ( PHP_OS , 0 , 3 ) ) == 'WIN' ) { exec ( 'where patch 2>&1' , $ out , $ val ) ; } else { exec ( 'which patch 2>&1' , $ out , $ val ) ; } if ( $ val != 0 ) { $ patch_results [ 'error' ] = __ ( 'Patch command is not found' , $ domain ) ; return $ patch_results ; } elseif ( ! is_executable ( trim ( $ out [ 0 ] ) ) ) { $ patch_results [ 'error' ] = __ ( 'Patch command is not executable' , $ domain ) ; return $ patch_results ; } else { $ patch_command = trim ( $ out [ 0 ] ) . ' -s -N -p1' ; } $ installed_plugins = get_plugins ( ) ; foreach ( $ file_names as $ file ) { if ( preg_match ( '/_(.*)\.patch/i' , $ file , $ match ) ) { $ plugin_version = trim ( $ match [ 1 ] ) ; $ plugin_basename = preg_replace ( '/_.*\.patch$/i' , '' , $ file ) ; foreach ( array_keys ( $ installed_plugins ) as $ key ) { if ( stripos ( $ key , $ plugin_basename ) !== false ) { $ installed_plugin_version = $ installed_plugins [ $ key ] [ 'Version' ] ; break ; } } } else { $ patch_results [ 'error' ] = __ ( 'Patch file name is invalid' , $ domain ) ; break ; } if ( version_compare ( $ installed_plugin_version , $ plugin_version , '!=' ) ) { $ patch_results [ 'error' ] = __ ( 'Patch file version does not match with that of your plugin.' , $ domain ) ; break ; } $ plugin_dir = WP_PLUGIN_DIR . '/' . $ plugin_basename ; $ patch_file = SQLitePatchDir . '/' . $ file ; $ command = $ patch_command . ' <' . $ patch_file . ' 2>&1' ; if ( chdir ( $ plugin_dir ) ) { exec ( " $ command " , $ output , $ retval ) ; } else { $ patch_results [ $ file ] = __ ( 'Error! Plugin directory is not accessible.' , $ domain ) ; } if ( $ retval == 0 ) { $ patch_results [ $ file ] = __ ( 'is patched successfully.' , $ domain ) ; } else { foreach ( $ output as $ val ) { $ message .= $ val . '<br />' ; } $ patch_results [ $ file ] = sprintf ( __ ( 'Error! Messages: %s' , $ domain ) , $ message ) ; } } return $ patch_results ; }
Method to apply patch to the plugins.
Method to apply patch to the plugins .