Do not allow empty comments
[aur.git] / web / html / pkgbase.php
blobbc32e43cc1df99a9c9a345e116b87da36b596ee7
1 <?php
3 set_include_path(get_include_path() . PATH_SEPARATOR . '../lib');
5 include_once("aur.inc.php");
6 set_lang();
7 include_once('pkgfuncs.inc.php');
8 check_sid();
11 * Retrieve package base ID and name, unless initialized by the routing
12 * framework.
14 if (!isset($base_id) || !isset($pkgbase_name)) {
15 if (isset($_GET['ID'])) {
16 $base_id = intval($_GET['ID']);
17 $pkgbase_name = pkgbase_name_from_id($_GET['ID']);
18 } else if (isset($_GET['N'])) {
19 $base_id = pkgbase_from_name($_GET['N']);
20 $pkgbase_name = $_GET['N'];
21 } else {
22 unset($base_id, $pkgbase_name);
25 if (isset($base_id) && ($base_id == 0 || $base_id == NULL || $pkgbase_name == NULL)) {
26 header("HTTP/1.0 404 Not Found");
27 include "./404.php";
28 return;
32 /* Set the title to package base name. */
33 $title = $pkgbase_name;
35 /* Grab the list of package base IDs to be operated on. */
36 $ids = array();
37 if (isset($_POST['IDs'])) {
38 foreach ($_POST['IDs'] as $id => $i) {
39 $id = intval($id);
40 if ($id > 0) {
41 $ids[] = $id;
46 /* Perform package base actions. */
47 $ret = false;
48 $output = "";
49 $fragment = "";
50 if (check_token()) {
51 if (current_action("do_Flag")) {
52 list($ret, $output) = pkgbase_flag($ids);
53 } elseif (current_action("do_UnFlag")) {
54 list($ret, $output) = pkgbase_unflag($ids);
55 } elseif (current_action("do_Adopt")) {
56 list($ret, $output) = pkgbase_adopt($ids, true, NULL);
57 } elseif (current_action("do_Disown")) {
58 if (isset($_POST['confirm'])) {
59 $via = isset($_POST['via']) ? $_POST['via'] : NULL;
60 list($ret, $output) = pkgbase_adopt($ids, false, $via);
61 } else {
62 $output = __("The selected packages have not been disowned, check the confirmation checkbox.");
63 $ret = false;
65 } elseif (current_action("do_Vote")) {
66 list($ret, $output) = pkgbase_vote($ids, true);
67 } elseif (current_action("do_UnVote")) {
68 list($ret, $output) = pkgbase_vote($ids, false);
69 } elseif (current_action("do_Delete")) {
70 if (isset($_POST['confirm'])) {
71 $via = isset($_POST['via']) ? $_POST['via'] : NULL;
72 if (!isset($_POST['merge_Into']) || empty($_POST['merge_Into'])) {
73 list($ret, $output) = pkgbase_delete($ids, NULL, $via);
74 unset($_GET['ID']);
76 else {
77 $merge_base_id = pkgbase_from_name($_POST['merge_Into']);
78 if (!$merge_base_id) {
79 $output = __("Cannot find package to merge votes and comments into.");
80 $ret = false;
81 } elseif (in_array($merge_base_id, $ids)) {
82 $output = __("Cannot merge a package base with itself.");
83 $ret = false;
84 } else {
85 list($ret, $output) = pkgbase_delete($ids, $merge_base_id, $via);
86 unset($_GET['ID']);
90 else {
91 $output = __("The selected packages have not been deleted, check the confirmation checkbox.");
92 $ret = false;
94 } elseif (current_action("do_Notify")) {
95 list($ret, $output) = pkgbase_notify($ids);
96 } elseif (current_action("do_UnNotify")) {
97 list($ret, $output) = pkgbase_notify($ids, false);
98 } elseif (current_action("do_DeleteComment")) {
99 list($ret, $output) = pkgbase_delete_comment();
100 } elseif (current_action("do_SetKeywords")) {
101 list($ret, $output) = pkgbase_set_keywords($base_id, preg_split("/[\s,;]+/", $_POST['keywords'], -1, PREG_SPLIT_NO_EMPTY));
102 } elseif (current_action("do_FileRequest")) {
103 list($ret, $output) = pkgreq_file($ids, $_POST['type'], $_POST['merge_into'], $_POST['comments']);
104 } elseif (current_action("do_CloseRequest")) {
105 list($ret, $output) = pkgreq_close($_POST['reqid'], $_POST['reason'], $_POST['comments']);
106 } elseif (current_action("do_EditComaintainers")) {
107 list($ret, $output) = pkgbase_set_comaintainers($base_id, explode("\n", $_POST['users']));
108 } elseif (current_action("do_AddComment")) {
109 $uid = uid_from_sid($_COOKIE["AURSID"]);
110 list($ret, $output) = pkgbase_add_comment($base_id, $uid, $_REQUEST['comment']);
111 $fragment = '#news';
112 } elseif (current_action("do_EditComment")) {
113 list($ret, $output) = pkgbase_edit_comment($_REQUEST['comment']);
114 if ($ret && isset($_POST["comment_id"])) {
115 $fragment = '#comment-' . intval($_POST["comment_id"]);
119 if ($ret) {
120 if (current_action("do_CloseRequest") ||
121 (current_action("do_Delete") && $_POST['via'])) {
122 /* Redirect back to package request page on success. */
123 header('Location: ' . get_pkgreq_route());
124 exit();
125 } if (isset($base_id)) {
126 /* Redirect back to package base page on success. */
127 header('Location: ' . get_pkgbase_uri($pkgbase_name) . $fragment);
128 exit();
129 } else {
130 /* Redirect back to package search page. */
131 header('Location: ' . get_pkg_route());
132 exit();
137 $pkgs = pkgbase_get_pkgnames($base_id);
138 if (!$output && count($pkgs) == 1) {
139 /* Not a split package. Redirect to the package page. */
140 if (empty($_SERVER['QUERY_STRING'])) {
141 header('Location: ' . get_pkg_uri($pkgs[0]) . $fragment);
142 } else {
143 header('Location: ' . get_pkg_uri($pkgs[0]) . '?' . $_SERVER['QUERY_STRING'] . $fragment);
147 $details = pkgbase_get_details($base_id);
148 html_header($title, $details);
151 <?php if ($output): ?>
152 <?php if ($ret): ?>
153 <p class="pkgoutput"><?= htmlspecialchars($output) ?></p>
154 <?php else: ?>
155 <ul class="errorlist"><li><?= htmlspecialchars($output) ?></li></ul>
156 <?php endif; ?>
157 <?php endif; ?>
159 <?php
160 include('pkg_search_form.php');
161 if (isset($_COOKIE["AURSID"])) {
162 pkgbase_display_details($base_id, $details, $_COOKIE["AURSID"]);
163 } else {
164 pkgbase_display_details($base_id, $details, null);
167 html_footer(AURWEB_VERSION);