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.'
'; } $patch_results[$file] = sprintf(__('Error! Messages: %s', $domain), $message); } } return $patch_results; } /** * Method to remove patch file(s) from the server. * * It deletes uploaded patch file(s). * If patch file(s) is not selected, returns false. * Or else returns array contains messages. * * @return boolean|array * @access private */ 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; } /** * Method to upload patch file(s) to the server. * * It uploads a patch file to the server. You must have the permission to write to the * temporary directory. If there isn't SQLitePatchDir, this method will create it and * set the permission to 0707. * * No return values. * * @return boolean * @access private */ private function upload_file() { global $utils; $domain = $utils->text_domain; if (!file_exists(SQLitePatchDir) || !is_dir(SQLitePatchDir)) { if (!mkdir(SQLitePatchDir, 0707, true)) { $message = __('Unable to create a patch directory.', $domain); echo '
'.$message.'
'; return false; } } if (!is_file(SQLitePatchDir . '/.htaccess')) { $fp = fopen(SQLitePatchDir . '/.htaccess', 'w'); if (!$fp) { $message = __('Unable to create a .htaccess file.', $domain); echo '
'.$message.'
'; return false; } fwrite($fp, 'DENY FROM ALL'); fclose($fp); } if (!isset($_FILES['upfile']['error']) || !is_int($_FILES['upfile']['error'])) { $message = __('Invalid operation.', $domain); echo '
'.$message.'
'; return false; } elseif ($_FILES['upfile']['error'] != UPLOAD_ERR_OK) { switch ($_FILES['upfile']['error']) { case UPLOAD_ERR_FORM_SIZE: $message = __('File is too large to upload.', $domain); echo '
'.$message.'
'; break; case UPLOAD_ERR_PARTIAL: $message = __('File upload is not complete.', $domain); echo '
'.$message.'
'; break; case UPLOAD_ERR_NO_FILE: $message = __('File is not uploaded.', $domain); echo '
'.$message.'
'; break; case UPLOAD_ERR_NO_TMP_DIR: $message = __('Temporary directory is not writable.', $domain); echo '
'.$message.'
'; break; case UPLOAD_ERR_CANT_WRITE: $message = __('File cannot be written on the disk.', $domain); echo '
'.$message.'
'; break; default: $message = __('Unknown error.', $domain); break; } return false; } if (is_uploaded_file($_FILES['upfile']['tmp_name'])) { $file_full_path = SQLitePatchDir . '/' . $_FILES['upfile']['name']; if (move_uploaded_file($_FILES['upfile']['tmp_name'], $file_full_path)) { $message = __('File is successfully uploaded.', $domain); echo '
'.$message.'
'; chmod(SQLitePatchDir.'/'.$_FILES['upfile']['name'], 0606); } else { $message = __('File upload failed. Possible file upload attack.', $domain); echo '
'.$message.'
'; return false; } } else { $message = __('File is not selected', $domain); echo '
'.$message.'
'; return false; } return true; } /** * Method to display the patch utility page on the admin panel. * */ 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', $domain); 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)) : ?>