diff --git a/config/apache/app.sixfold.org.conf b/config/apache/app.sixfold.org.conf index 0cdd30f..f6bdbd6 100644 --- a/config/apache/app.sixfold.org.conf +++ b/config/apache/app.sixfold.org.conf @@ -93,8 +93,9 @@ RewriteRule ^/games/([0-9]+)/submit$ /games/submit.php?game=$1 RewriteRule ^/games/([0-9]+)/update$ /games/update.php?game=$1 - RewriteRule ^/doc/([a-z0-9]+)$ /docs/$1 [L,R=301] - RewriteRule ^/docs/([a-z0-9]+)$ /docs/index.php?hash=$1 [L,QSA] + RewriteRule ^/doc/([a-z0-9]+)$ /docs/$1 [L,R=301] # Old site URL + RewriteRule ^/docs/([a-z0-9]+)$ /docs/submission.php?hash=$1 [L,QSA] + RewriteRule ^/members/([^\.]+?)$ /members/member.php?handle=$1 [L] # PayPal order processing rewrites diff --git a/www/docs/index.php b/www/docs/index.php index cd1e288..2580ca6 100644 --- a/www/docs/index.php +++ b/www/docs/index.php @@ -1,69 +1,13 @@ prepare($sql); - $stmt->execute([ - "hash" => $_GET["hash"], - ]); - - $doc = $stmt->fetch(PDO::FETCH_OBJ); - - $sql = "SELECT -member_id -FROM assignments -WHERE submission_id = :submission_id -"; - - $stmt = $db["data"]->prepare($sql); - $stmt->execute([ - "submission_id" => $doc->id, - ]); - - $doc->readers = $stmt->fetchAll(PDO::FETCH_COLUMN); - - $IS_OWNER = LOGGED_IN ? $_SESSION["account"]->id === $doc->owner : false; - $IS_READER = LOGGED_IN ? in_array($_SESSION["account"]->id, $doc->readers, true) : false; - - if ($IS_OWNER || $IS_READER || IS_ADMIN || $doc->is_public) : - header('Content-Type: application/pdf'); - header('Content-Disposition: inline; filename="' . slugify($doc->title) . '.pdf"'); - - echo file_get_contents(sprintf('%s/assets/docs/%s/%s', ABS_PATH, $doc->game_id, $doc->basename)); - die; - endif; - -else: - include "partials/head.php"; ?> - - -
-
-

-
- is_public): ?> -

You must log in to access this page.

- - -

Read a random document

- -
- - +?> + + + +
+
+

+
+

Read a random document

+
+prepare($sql); +$stmt->execute([ + "hash" => $_GET["hash"], +]); + +$submission = $stmt->fetch(PDO::FETCH_OBJ); + +if (!$submission): + + $title = "Submission Not Found"; + $description = + "We couldn't find a submission with that hash."; + http_response_code(404); + include "partials/head.php"; + ?> + + +
+
+

+
+

We couldn't find a submission with that hash.

+
+ + + + prepare($sql); +$stmt->execute([ + "submission_id" => $submission->id, +]); + +$submission->readers = $stmt->fetchAll(PDO::FETCH_COLUMN); + +$IS_OWNER = LOGGED_IN ? $_SESSION["account"]->id === $submission->owner : false; +$IS_READER = LOGGED_IN + ? in_array($_SESSION["account"]->id, $submission->readers, true) + : false; + +if ($IS_OWNER || $IS_READER || IS_ADMIN || $submission->is_public): + $file = file_get_contents( + sprintf( + "%s/assets/docs/%s/%s", + ABS_PATH, + $submission->game_id, + $submission->basename + ) + ); + + if ($file) { + header("Content-Type: application/pdf"); + header( + 'Content-Disposition: inline; filename="' . + slugify($submission->title) . + '.pdf"' + ); + echo $file; + } else { + + $title = "Internal Server Error"; + $description = + "The server encountered an error when attempting to open the requested file."; + http_response_code(500); + include "partials/head.php"; + ?> + + +
+
+

+
+

The server encountered an error when attempting to open the requested file. Please try again later.

+
+ + + + + + +
+
+

+
+

You must log in to view this submission.

+ +
+ + + +