diff options
author | Marcel Korpel <marcel.korpel@gmail.com> | 2015-07-21 22:53:56 +0200 |
---|---|---|
committer | Lukas Fleischer <lfleischer@archlinux.org> | 2015-08-08 12:59:24 +0200 |
commit | 8328223a5e4670fbeb62c13ef89aa345f3ccc4c8 (patch) | |
tree | 7224ab2ec62c39b4a19270ed386a19a396b8f022 | |
parent | c7025054c686f1f1a877e2d2938c39c79fb62580 (diff) | |
download | aurweb-8328223a5e4670fbeb62c13ef89aa345f3ccc4c8.tar.xz |
aurjson.class.php: Add method get_comment_form()
This method will be used by the JavaScript comment editing and produces
a form containing the comment.
Signed-off-by: Marcel Korpel <marcel.korpel@gmail.com>
Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
-rw-r--r-- | web/lib/aurjson.class.php | 49 |
1 files changed, 48 insertions, 1 deletions
diff --git a/web/lib/aurjson.class.php b/web/lib/aurjson.class.php index 8ead253..4e4d5dc 100644 --- a/web/lib/aurjson.class.php +++ b/web/lib/aurjson.class.php @@ -14,7 +14,7 @@ class AurJSON { private $version = 1; private static $exposed_methods = array( 'search', 'info', 'multiinfo', 'msearch', 'suggest', - 'suggest-pkgbase' + 'suggest-pkgbase', 'get-comment-form' ); private static $exposed_fields = array( 'name', 'name-desc' @@ -477,5 +477,52 @@ class AurJSON { return json_encode($result_array); } + + /** + * Get the HTML markup of the comment form. + * + * @param array $http_data Query parameters. + * + * @return string The JSON formatted response data. + */ + private function get_comment_form($http_data) { + if (!isset($http_data['base_id']) || !isset($http_data['pkgbase_name'])) { + $output = array( + 'success' => 0, + 'error' => __('Package base ID or package base name missing.') + ); + return json_encode($output); + } + + $comment_id = intval($http_data['arg']); + $base_id = intval($http_data['base_id']); + $pkgbase_name = $http_data['pkgbase_name']; + + list($user_id, $comment) = comment_by_id($comment_id); + + if (!has_credential(CRED_COMMENT_EDIT, array($user_id))) { + $output = array( + 'success' => 0, + 'error' => __('You do not have the right to edit this comment.') + ); + return json_encode($output); + } elseif (is_null($comment)) { + $output = array( + 'success' => 0, + 'error' => __('Comment does not exist.') + ); + return json_encode($output); + } + + ob_start(); + include('pkg_comment_form.php'); + $html = ob_get_clean(); + $output = array( + 'success' => 1, + 'form' => $html + ); + + return json_encode($output); + } } |