text_domain; $installed_plugins = array(); $file_names = array(); $output = array(); $retval = 0; $patch_results = array(); 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.'
'; } $patch_results[$file] = sprintf(__('Error! Messages: %s', $domain), $message); } } return $patch_results; } /** * Delete uploaded patch file(s). * If patch file(s) is not selected, returns false. * Or else returns array contains messages. * @return boolean|array */ private function delete_patch_files() { global $utils; $domain = $utils->text_domain; $file_names = array(); $rm_results = array(); if (isset($_POST['plugin_checked'])) { $file_names = $_POST['plugin_checked']; } else { return false; } if (chdir(SQLitePatchDir)) { foreach ($file_names as $file) { if (unlink($file)) { $rm_results[$file] = sprintf(__('File %s is deleted.', $domain), $file); } else { $rm_results[$file] = sprintf(__('Error! File %s is not deleted.', $domain), $file); } } } else { $rm_results[$file] = __('Error!: patches directory is not accessible.', $domain); } return $rm_results; } /** * Uploads a patch file. * No return values. */ private function upload_file() { global $utils; $domain = $utils->text_domain; if (!file_exists(SQLitePatchDir) || !is_dir(SQLitePatchDir)) { mkdir(SQLitePatchDir, 0705, true); } if (is_uploaded_file($_FILES['upfile']['tmp_name'])) { if (move_uploaded_file($_FILES['upfile']['tmp_name'], SQLitePatchDir.'/'.$_FILES['upfile']['name'])) { $message = __('File is uploaded', $domain); echo '
'.$message.'
'; chmod(SQLitePatchDir.'/'.$_FILES['upfile']['name'], 0644); } else { $message = __('File is not uploaded', $domain); echo '
'.$message.'
'; } } else { $message = __('File is not selected', $domain); echo '
'.$message.'
'; } } /** * Displays patch util page */ function show_patch_page() { global $utils; $domain = $utils->text_domain; if (is_multisite() && !current_user_can('manage_network_options')) { die(__('You are not allowed to access this page!', $domain)); } elseif (!current_user_can('manage_options')) { die(__('You are not allowed to access this page!', $domain)); } if (isset($_POST['apply_patch'])) { check_admin_referer('sqlitewordpress-plugin-manip-stats'); if (is_multisite() && !current_user_can('manage_network_options')) { die(__('You are not allowed to do this operation!', $domain)); } elseif (!current_user_can('manage_options')) { die(__('You are not allowed to do this operation!', $domain)); } $result = $this->apply_patches(); if ($result === false) { $message = __('Please select patch file(s)', $domain); echo '
'.$message.'
'; } elseif (is_array($result) && count($result) > 0) { echo '
'; foreach ($result as $key => $val) { echo $key.' => '.$val.'
'; } echo '
'; } else { $message = __('None of the patches is applied!'); echo '
'.$message.'
'; } } if (isset($_POST['patch_file_delete'])) { check_admin_referer('sqlitewordpress-plugin-manip-stats'); if (is_multisite() && !current_user_can('manage_network_options')) { die(__('You are not allowed to do this operation!', $domain)); } elseif (!current_user_can('manage_options')) { die(__('You are not allowed to do this operation!', $domain)); } $result = $this->delete_patch_files(); if ($result === false) { $message = __('Please select patch file(s)', $domain); echo '
'.$message.'
'; } elseif (is_array($result) && count($result) > 0) { echo '
'; foreach ($result as $key => $val) { echo $key.' => '.$val.'
'; } echo '
'; } else { $message = __('Error! Please remove files manually'); echo '
'.$message.'
'; } } if (isset($_POST['upload'])) { check_admin_referer('sqlitewordpress-plugin-patch-file-stats'); if (is_multisite() && !current_user_can('manage_network_options')) { die(__('You are not allowed to do this operation!', $domain)); } elseif (!current_user_can('manage_options')) { die(__('You are not allowed to do this operation!', $domain)); } $result = $this->upload_file(); } if (isset($_GET['page']) && $_GET['page'] == 'patch') : ?>

Plugin Page about how to apply a patch file to the plugin. But the command line interface sometimes embarrasses some people, especially newbies.', $domain);?>

  1. Plugin Directory for the substitutes?', $domain)?>


get_patch_files(); if (!empty($files)) : ?>