Allow clicking through to full quality images
[pics.git] / index.php
index 88310ff..b5b343e 100644 (file)
--- a/index.php
+++ b/index.php
@@ -1,40 +1,33 @@
-<html>
-<head>
-<link rel="stylesheet" href="style.css">
-</head>
-
-<body>
-<main>
-<a href='upload.php'>Upload</a>
 <?php
 
-require_once __DIR__ . '/db.php';
+// May contain query params
+$request_uri = explode('?', $_SERVER['REQUEST_URI'], 2);
+$pieces = array_values(array_filter(
+    explode('/', $request_uri[0]),
+    function($exploded) { return $exploded; }
+));
 
-$db = get_db();
-$posts = $db->query('SELECT
-  p.ID, p.TIMESTAMP, pi.MIME_TYPE, pi.PIC_B64, c.BODY
-  FROM posts p
-  JOIN pics pi on p.id = pi.post_id
-  JOIN comments c on p.id = c.post_id
-  ORDER BY p.TIMESTAMP DESC');
-while ($post = $posts->fetchArray()) {
-  $mime_type = $post['MIME_TYPE'];
-  $file_b64 = $post['PIC_B64'];
-  $post_id = $post['ID'];
-  $comment_text = $post['BODY'];
-  $img = new Imagick();
-  $img->readImageBlob(base64_decode($file_b64));
-  $img->setImageCompressionQuality(85);
-  $img->adaptiveResizeImage(480, 0);
-  $compressed_b64 = base64_encode($img->getImageBlob());
+if (empty($pieces)) {
+  require './app.php';
+  die;
+}
 
-  echo "<div id='post-{$post_id}'>";
+$path = array_shift($pieces);
 
-  echo "<img src='data:{$mime_type};base64,{$compressed_b64}' alt='$'/>";
-  echo "<p>{$comment_text}</p>";
-  echo '</div>';
+switch ($path) {
+    case '':
+        require './app.php';
+        break;
+    case 'pic':
+        require './pic.php';
+        break;
+    case 'upload':
+        require './upload.php';
+        break;
+    case 'unauthorized':
+        require './unauthorized.php';
+        break;
+    default:
+        header('HTTP/1.0 404 Not Found');
+        die('404 Not Found');
 }
-?>
-</main>
-</body>
-</html>