Implement capability to pin comments above others
[aur.git] / web / html / pkgbase.php
blob45b8084b0f7791d1f733148cb6c45e608299512a
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, $_POST['comments']);
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']);
75 unset($base_id);
77 else {
78 $merge_base_id = pkgbase_from_name($_POST['merge_Into']);
79 if (!$merge_base_id) {
80 $output = __("Cannot find package to merge votes and comments into.");
81 $ret = false;
82 } elseif (in_array($merge_base_id, $ids)) {
83 $output = __("Cannot merge a package base with itself.");
84 $ret = false;
85 } else {
86 list($ret, $output) = pkgbase_delete($ids, $merge_base_id, $via);
87 unset($_GET['ID']);
88 unset($base_id);
92 else {
93 $output = __("The selected packages have not been deleted, check the confirmation checkbox.");
94 $ret = false;
96 } elseif (current_action("do_Notify")) {
97 list($ret, $output) = pkgbase_notify($ids);
98 } elseif (current_action("do_UnNotify")) {
99 list($ret, $output) = pkgbase_notify($ids, false);
100 } elseif (current_action("do_DeleteComment")) {
101 list($ret, $output) = pkgbase_delete_comment();
102 } elseif (current_action("do_PinComment")) {
103 list($ret, $output) = pkgbase_pin_comment();
104 } elseif (current_action("do_UnpinComment")) {
105 list($ret, $output) = pkgbase_pin_comment(true);
106 } elseif (current_action("do_SetKeywords")) {
107 list($ret, $output) = pkgbase_set_keywords($base_id, preg_split("/[\s,;]+/", $_POST['keywords'], -1, PREG_SPLIT_NO_EMPTY));
108 } elseif (current_action("do_FileRequest")) {
109 list($ret, $output) = pkgreq_file($ids, $_POST['type'], $_POST['merge_into'], $_POST['comments']);
110 } elseif (current_action("do_CloseRequest")) {
111 list($ret, $output) = pkgreq_close($_POST['reqid'], $_POST['reason'], $_POST['comments']);
112 } elseif (current_action("do_EditComaintainers")) {
113 list($ret, $output) = pkgbase_set_comaintainers($base_id, explode("\n", $_POST['users']));
114 } elseif (current_action("do_AddComment")) {
115 $uid = uid_from_sid($_COOKIE["AURSID"]);
116 list($ret, $output) = pkgbase_add_comment($base_id, $uid, $_REQUEST['comment']);
117 $fragment = '#news';
118 } elseif (current_action("do_EditComment")) {
119 list($ret, $output) = pkgbase_edit_comment($_REQUEST['comment']);
120 if ($ret && isset($_POST["comment_id"])) {
121 $fragment = '#comment-' . intval($_POST["comment_id"]);
125 if ($ret) {
126 if (current_action("do_CloseRequest") ||
127 (current_action("do_Delete") && $_POST['via'])) {
128 /* Redirect back to package request page on success. */
129 header('Location: ' . get_pkgreq_route());
130 exit();
131 } if (isset($base_id)) {
132 /* Redirect back to package base page on success. */
133 header('Location: ' . get_pkgbase_uri($pkgbase_name) . $fragment);
134 exit();
135 } else {
136 /* Redirect back to package search page. */
137 header('Location: ' . get_pkg_route());
138 exit();
143 $pkgs = pkgbase_get_pkgnames($base_id);
144 if (!$output && count($pkgs) == 1) {
145 /* Not a split package. Redirect to the package page. */
146 if (empty($_SERVER['QUERY_STRING'])) {
147 header('Location: ' . get_pkg_uri($pkgs[0]) . $fragment);
148 } else {
149 header('Location: ' . get_pkg_uri($pkgs[0]) . '?' . $_SERVER['QUERY_STRING'] . $fragment);
153 $details = pkgbase_get_details($base_id);
154 html_header($title, $details);
157 <?php if ($output): ?>
158 <?php if ($ret): ?>
159 <p class="pkgoutput"><?= htmlspecialchars($output) ?></p>
160 <?php else: ?>
161 <ul class="errorlist"><li><?= htmlspecialchars($output) ?></li></ul>
162 <?php endif; ?>
163 <?php endif; ?>
165 <?php
166 include('pkg_search_form.php');
167 if (isset($_COOKIE["AURSID"])) {
168 pkgbase_display_details($base_id, $details, $_COOKIE["AURSID"]);
169 } else {
170 pkgbase_display_details($base_id, $details, null);
173 html_footer(AURWEB_VERSION);