2 global $HOME_PAGE_PROVIDERS;
5 $CALL_ME_FUNCTIONS["repoview"] = "gwvpmini_RepoViewCallMe";
9 function gwvpmini_RepoViewCallMe()
11 global $repo_view_call;
13 // error_log("in admin callme");
\r
14 if(isset($_REQUEST["q"])) {
\r
15 $query = $_REQUEST["q"];
\r
16 $qspl = explode("/", $query);
\r
17 if(isset($qspl[0])) {
\r
18 if($qspl[0] == "view") {
\r
20 $repo_view_call = $qspl[1];
21 return "gwvpmini_RepoViewPage";
\r
22 } else return false;
\r
24 if($qspl[0] == "updaterepobaseperms") {
25 return "gwvpmini_UpdateRepoBasePerms";
27 if($qspl[0] == "repoaddreader") {
28 return "gwvpmini_AddRepoReader";
30 if($qspl[0] == "repoaddcontrib") {
31 return "gwvpmini_AddRepoContributor";
33 if($qspl[0] == "reporemovereaders") {
34 return "gwvpmini_RemoveRepoReader";
36 if($qspl[0] == "reporemovecontribs") {
37 return "gwvpmini_RemoveRepoContributor";
39 if($qspl[0] == "repoupdatedesc") {
40 return "gwvpmini_RepoUpdateDescription";
52 function gwvpmini_RepoViewPage()
\r
54 global $repo_view_call, $MENU_ITEMS, $BASE_URL;
\r
56 $MENU_ITEMS["40thisrepo"]["text"] = "$repo_view_call";
\r
57 $MENU_ITEMS["40thisrepo"]["link"] = "$BASE_URL/view/$repo_view_call";
\r
59 gwvpmini_goMainPage("gwvpmini_RepoViewPageBody");
\r
62 function gwvpmini_RepoViewPageBody()
64 global $repo_view_call, $MENU_ITEMS, $BASE_URL;
66 $repo_base = gwvpmini_getConfigVal("repodir");
\r
68 $bperms_f = gwvpmini_GetRepoPerms(gwvpmini_GetRepoId($repo_view_call));
69 $bperms = $bperms_f["b"];
71 $owner_view = false;
\r
73 if($_SERVER["SERVER_PORT"] == 443) $proto="https://";
74 else $proto = "http://";
75 $sname = $_SERVER["SERVER_NAME"];
77 $owner = gwvpmini_GetRepoOwnerDetailsFromName($repo_view_call);
78 $desc = gwvpmini_GetRepoDescFromName($repo_view_call);
79 $editdesc = preg_replace("/\<br\>/", "\n", $desc);
81 $rid = gwvpmini_GetRepoId($repo_view_call);
83 $owner_name = $owner["username"];
85 // TODO: fix this so that if user has no read access to repo, they cant see it
86 if(isset($_SESSION["id"])) {
87 if($owner["id"] == $_SESSION["id"]) {
89 } else if ($bperms != "r") {
90 // check user level perms
91 $perm = gwvpmini_GetRepoPerm($rid, $_SESSION["id"]);
93 header("Location: $BASE_URL");
\r
99 header("Location: $BASE_URL");
105 // error_log("STUFF:".print_r($owner,true));
106 if($bperms != "a") $login = $_SESSION["username"].":password@";
108 $cloneurl = "git clone $proto$login$sname$BASE_URL/git/$repo_view_call.git";
109 echo "<textarea rows=1 cols=".strlen($cloneurl).">$cloneurl</textarea><br>";
111 if($owner_view) $owner_extra = " (YOU)";
112 else $owner_extra = "";
\r
114 echo "<h2>".gwvpmini_HtmlGravatar($owner["email"], 30)."$repo_view_call - $owner_name$owner_extra</h2>";
115 if(!$owner_view) echo "$desc<br>";
118 echo "<form method=\"post\" action=\"$BASE_URL/repoupdatedesc/$repo_view_call\">";
\r
119 echo "<h3>Description<h3><textarea name=\"desc\" cols=\"120\" rows=\"5\">$editdesc</textarea><br><input type=\"submit\" name=\"Update\" value=\"Update\">";
\r
120 echo "</form><br>";
\r
128 if($bperms == "a") $anyo = " selected";
\r
129 if($bperms == "r") $regd = " selected";
\r
130 if($bperms == "x") $expl = " selected";
\r
132 // error_log("BPERMS: $bperms");
134 if($bperms == "x") $cspan = 3;
137 echo "<table border=\"1\"><tr valign=\"top\"><tr><th colspan=\"$cspan\">Permissions</th></tr><td>";
138 echo "<form method=\"post\" action=\"$BASE_URL/updaterepobaseperms/$repo_view_call\">";
139 echo "<select name=\"base_perms\">";
140 echo "<option value=\"a\"$anyo>Anyone can read</option>";
141 echo "<option value=\"r\"$regd>Only registered users can read</option>";
142 echo "<option value=\"x\"$expl>Explicit read permissions</option>";
144 echo "<input type=\"submit\" name=\"Set\" value=\"Set\">";
147 echo "</td><td><b>Readers</b><br>";
148 echo "<form method=\"post\" action=\"$BASE_URL/reporemovereaders/$repo_view_call\">";
150 foreach($bperms_f as $key=>$val) {
152 $dets = gwvpmini_getUser(null, null, $key);
153 echo gwvpmini_HtmlGravatar($dets["email"], 18, " ")."<input type=\"checkbox\" name=\"$key\"> ".$dets["username"]."<br>";
157 if($nl==1) echo "<input type=\"submit\" name=\"remove\" value=\"Remove Selected\">";
159 echo "<form method=\"post\" action=\"$BASE_URL/repoaddreader/$repo_view_call\">";
160 echo "<input type=\"text\" name=\"readerusername\"> <input type=\"submit\" name=\"Add\" value=\"Add\">";
164 echo "</td><td><b>Contributors</b><br>";
165 echo "<form method=\"post\" action=\"$BASE_URL/reporemovecontribs/$repo_view_call\">";
167 foreach($bperms_f as $key=>$val) {
\r
169 $dets = gwvpmini_getUser(null, null, $key);
\r
170 echo gwvpmini_HtmlGravatar($dets["email"], 18, " ")."<input type=\"checkbox\" name=\"$key\"> ".$dets["username"]."<br>";
174 if($nl==1) echo "<input type=\"submit\" name=\"remove\" value=\"Remove Selected\">";
\r
177 echo "<form method=\"post\" action=\"$BASE_URL/repoaddcontrib/$repo_view_call\">";
178 echo "<input type=\"text\" name=\"contribusername\"> <input type=\"submit\" name=\"Add\" value=\"Add\">";
180 echo "</td></tr></table>";
183 //echo "command: git log --git-dir=$repo_base/$repo_view_call.git --pretty=format:\"%H\" -10";
184 $rs = popen("git --git-dir=$repo_base/$repo_view_call.git log --pretty=format:\"%H\" -10", "r");
185 $commitids = array();
190 if($flin !== false) {
191 $commitids[$i] = trim($flin);
200 if($commitids != false) {
201 echo "<hr>Commits<br>";
202 echo "<table border=\"1\">";
203 echo "<tr><th>Committed By</th><th>Date</th><th>Commit Log Entry</th></tr>";
204 foreach($commitids as $ids) {
205 $rs = popen("git --git-dir=$repo_base/$repo_view_call.git log --pretty=format:\"%at%n%ce%n%an%n%s\" $ids -1 2> /dev/null", "r");
207 $flin1 = trim(fgets($rs));
208 $flin2 = trim(fgets($rs));
209 $flin3 = trim(fgets($rs));
211 $flin4 = fread($rs, 8192);
213 $flon = gwvpmini_emailToUserLink($flin2);
215 $flon = "$flin3 (external)";
218 $timedifftxt = gwvpmini_TimeDiffText($flin1);
219 echo "<tr><td>".gwvpmini_HtmlGravatar($flin2, 18)."$flon</td><td>$timedifftxt</td><td>$flin4</td></tr>";
223 echo "No commit information available yet<br>";
227 function gwvpmini_UpdateRepoBasePerms()
229 global $BASE_URL, $repo_view_call;
231 if(isset($_REQUEST["q"])) {
\r
232 $query = $_REQUEST["q"];
\r
233 $qspl = explode("/", $query);
234 // error_log("PLOOP:qview".print_r($qspl, true));
\r
237 if(isset($qspl[1])) $repo_view_call = $qspl[1];
239 // error_log("PLOOP: no repo name");
240 header("Location: $BASE_URL/view/$repo_view_call");
244 $newperms = $_REQUEST["base_perms"];
246 $owner = gwvpmini_GetRepoOwnerDetailsFromName($repo_view_call);
\r
247 $desc = gwvpmini_GetRepoDescFromName($repo_view_call);
\r
249 $owner_name = $owner["username"];
252 if(isset($_SESSION["id"])) {
\r
253 if($owner["id"] == $_SESSION["id"]) {
\r
254 $owner_view = true;
\r
258 $rid = gwvpmini_GetRepoId($repo_view_call);
261 gwvpmini_SendMessage("error", "failure updating permission for repo");
262 // error_log("PLOOP: attempt to update from non-owner");
264 // error_log("PLOOP: updateds: ".print_r($_REQUEST, true));
265 gwvpmini_ChangeRepoPerm($rid, "b", $_REQUEST["base_perms"]);
266 gwvpmini_SendMessage("info", "Base permissions for repo updated");
269 header("Location: $BASE_URL/view/$repo_view_call");
272 function gwvpmini_AddRepoReader()
274 global $BASE_URL, $repo_view_call;
\r
276 if(isset($_REQUEST["q"])) {
\r
277 $query = $_REQUEST["q"];
\r
278 $qspl = explode("/", $query);
\r
279 // error_log("PLOOP:qview".print_r($qspl, true));
\r
282 if(isset($qspl[1])) $repo_view_call = $qspl[1];
\r
284 // error_log("PLOOP: no repo name");
285 // TODO: btw, this makes no sense
\r
286 header("Location: $BASE_URL/view/$repo_view_call");
\r
290 $newperms = $_REQUEST["base_perms"];
\r
292 $owner = gwvpmini_GetRepoOwnerDetailsFromName($repo_view_call);
\r
293 $desc = gwvpmini_GetRepoDescFromName($repo_view_call);
\r
295 $owner_name = $owner["username"];
\r
297 $owner_view = false;
\r
298 if(isset($_SESSION["id"])) {
\r
299 if($owner["id"] == $_SESSION["id"]) {
\r
300 $owner_view = true;
\r
304 gwvpmini_SendMessage("error", "failure updating permission for repo");
\r
305 // error_log("PLOOP: attempt to update from non-owner");
306 header("Location: $BASE_URL/view/$repo_view_call");
310 $auid = gwvpmini_GetUserId($_REQUEST["readerusername"]);
312 if($auid == $_SESSION["id"]) {
313 gwvpmini_SendMessage("error", "You cannot add yourself as a reader as you already own the repo");
314 header("Location: $BASE_URL/view/$repo_view_call");
\r
319 $rid = gwvpmini_GetRepoId($repo_view_call);
321 gwvpmini_ChangeRepoPerm($rid, $auid, 1);
322 gwvpmini_SendMessage("info", "Added user ".$_REQUEST["readerusername"]." as a reader");
323 header("Location: $BASE_URL/view/$repo_view_call");
\r
326 gwvpmini_SendMessage("error", "Couldnt find user with username of ".$_REQUEST["readerusername"]);
327 header("Location: $BASE_URL/view/$repo_view_call");
334 function gwvpmini_AddRepoContributor()
336 global $BASE_URL, $repo_view_call;
\r
338 if(isset($_REQUEST["q"])) {
\r
339 $query = $_REQUEST["q"];
\r
340 $qspl = explode("/", $query);
\r
341 // error_log("PLOOP:qview".print_r($qspl, true));
\r
344 if(isset($qspl[1])) $repo_view_call = $qspl[1];
\r
346 // error_log("PLOOP: no repo name");
\r
347 // TODO: btw, this makes no sense
\r
348 header("Location: $BASE_URL/view/$repo_view_call");
\r
352 $newperms = $_REQUEST["base_perms"];
\r
354 $owner = gwvpmini_GetRepoOwnerDetailsFromName($repo_view_call);
\r
355 $desc = gwvpmini_GetRepoDescFromName($repo_view_call);
\r
357 $owner_name = $owner["username"];
\r
359 $owner_view = false;
\r
360 if(isset($_SESSION["id"])) {
\r
361 if($owner["id"] == $_SESSION["id"]) {
\r
362 $owner_view = true;
\r
366 gwvpmini_SendMessage("error", "failure updating permission for repo");
\r
367 // error_log("PLOOP: attempt to update from non-owner");
\r
368 header("Location: $BASE_URL/view/$repo_view_call");
\r
372 $auid = gwvpmini_GetUserId($_REQUEST["contribusername"]);
\r
374 if($auid == $_SESSION["id"]) {
\r
375 gwvpmini_SendMessage("error", "You cannot add yourself as a contributor as you already own the repo");
\r
376 header("Location: $BASE_URL/view/$repo_view_call");
\r
381 $rid = gwvpmini_GetRepoId($repo_view_call);
\r
383 gwvpmini_ChangeRepoPerm($rid, $auid, 2);
\r
384 gwvpmini_SendMessage("info", "Added user ".$_REQUEST["contribusername"]." as a contributor");
\r
385 header("Location: $BASE_URL/view/$repo_view_call");
\r
388 gwvpmini_SendMessage("error", "Couldnt find user with username of ".$_REQUEST["contribusername"]);
\r
389 header("Location: $BASE_URL/view/$repo_view_call");
\r
394 function gwvpmini_RemoveRepoContributor()
397 global $BASE_URL, $repo_view_call;
\r
399 if(isset($_REQUEST["q"])) {
\r
400 $query = $_REQUEST["q"];
\r
401 $qspl = explode("/", $query);
\r
402 // error_log("PLOOP:qview".print_r($qspl, true));
\r
405 if(isset($qspl[1])) $repo_view_call = $qspl[1];
\r
407 // error_log("PLOOP: no repo name");
\r
408 // TODO: btw, this makes no sense
\r
409 header("Location: $BASE_URL/view/$repo_view_call");
\r
414 $owner = gwvpmini_GetRepoOwnerDetailsFromName($repo_view_call);
\r
415 $desc = gwvpmini_GetRepoDescFromName($repo_view_call);
\r
417 $owner_name = $owner["username"];
\r
419 $owner_view = false;
\r
420 if(isset($_SESSION["id"])) {
\r
421 if($owner["id"] == $_SESSION["id"]) {
\r
422 $owner_view = true;
\r
426 gwvpmini_SendMessage("error", "failure updating permission for repo");
\r
427 // error_log("PLOOP: attempt to update from non-owner");
\r
428 header("Location: $BASE_URL/view/$repo_view_call");
\r
432 $rid = gwvpmini_GetRepoId($repo_view_call);
434 $bperms_f = gwvpmini_GetRepoPerms($rid);
436 foreach($bperms_f as $key=>$val) {
438 if(isset($_REQUEST["$key"])) {
439 gwvpmini_ChangeRepoPerm($rid, $key, 0);
444 gwvpmini_SendMessage("info", "Repo permissions updated");
445 header("Location: $BASE_URL/view/$repo_view_call");
\r
451 function gwvpmini_RemoveRepoReader()
\r
454 global $BASE_URL, $repo_view_call;
\r
456 if(isset($_REQUEST["q"])) {
\r
457 $query = $_REQUEST["q"];
\r
458 $qspl = explode("/", $query);
\r
459 // error_log("PLOOP:qview".print_r($qspl, true));
\r
462 if(isset($qspl[1])) $repo_view_call = $qspl[1];
\r
464 // error_log("PLOOP: no repo name");
\r
465 // TODO: btw, this makes no sense
\r
466 header("Location: $BASE_URL/view/$repo_view_call");
\r
471 $owner = gwvpmini_GetRepoOwnerDetailsFromName($repo_view_call);
\r
472 $desc = gwvpmini_GetRepoDescFromName($repo_view_call);
\r
474 $owner_name = $owner["username"];
\r
476 $owner_view = false;
\r
477 if(isset($_SESSION["id"])) {
\r
478 if($owner["id"] == $_SESSION["id"]) {
\r
479 $owner_view = true;
\r
483 gwvpmini_SendMessage("error", "failure updating permission for repo");
\r
484 // error_log("PLOOP: attempt to update from non-owner");
\r
485 header("Location: $BASE_URL/view/$repo_view_call");
\r
489 $rid = gwvpmini_GetRepoId($repo_view_call);
\r
491 $bperms_f = gwvpmini_GetRepoPerms($rid);
\r
493 foreach($bperms_f as $key=>$val) {
\r
495 if(isset($_REQUEST["$key"])) {
\r
496 gwvpmini_ChangeRepoPerm($rid, $key, 0);
\r
501 gwvpmini_SendMessage("info", "Repo permissions updated");
\r
502 header("Location: $BASE_URL/view/$repo_view_call");
\r
507 function gwvpmini_RepoUpdateDescription()
509 global $BASE_URL, $repo_view_call;
\r
511 if(isset($_REQUEST["q"])) {
\r
512 $query = $_REQUEST["q"];
\r
513 $qspl = explode("/", $query);
\r
514 // error_log("PLOOP:qview".print_r($qspl, true));
\r
517 if(isset($qspl[1])) $repo_view_call = $qspl[1];
\r
519 // error_log("PLOOP: no repo name");
\r
520 // TODO: btw, this makes no sense
\r
521 header("Location: $BASE_URL/view/$repo_view_call");
\r
526 $owner = gwvpmini_GetRepoOwnerDetailsFromName($repo_view_call);
\r
527 $desc = gwvpmini_GetRepoDescFromName($repo_view_call);
\r
529 $owner_name = $owner["username"];
\r
531 $owner_view = false;
\r
532 if(isset($_SESSION["id"])) {
\r
533 if($owner["id"] == $_SESSION["id"]) {
\r
534 $owner_view = true;
\r
538 gwvpmini_SendMessage("error", "failure updating description for repo");
\r
539 // error_log("PLOOP: attempt to update from non-owner");
\r
540 header("Location: $BASE_URL/view/$repo_view_call");
\r
544 $rid = gwvpmini_GetRepoId($repo_view_call);
\r
546 gwvpmini_UpdateRepoDescription($rid, $_REQUEST["desc"]);
548 gwvpmini_SendMessage("info", "Repo description updated");
\r
549 header("Location: $BASE_URL/view/$repo_view_call");
\r