From: Jacob Casper Date: Sat, 9 Apr 2022 21:17:08 +0000 (-0500) Subject: Display posts, not pics X-Git-Url: https://git.jacobcasper.com/?a=commitdiff_plain;h=80f2f42a0e748c2e724dd27a6cd9ab4013a3ee3a;p=pics.git Display posts, not pics Now that we have posts, pics, and comments, rework content display to be focused on whole posts. --- diff --git a/index.php b/index.php index a33a56c..804a15e 100644 --- a/index.php +++ b/index.php @@ -5,15 +5,29 @@ require_once __DIR__ . '/db.php'; $db = get_db(); -$pics = $db->query('SELECT * from pics'); -while ($pic = $pics->fetchArray()) { - $mime_type = $pic['MIME_TYPE']; - $file_b64 = $pic['PIC_B64']; - $name = $pic['ID']; +$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()); - echo "$name"; + echo "
"; + + echo "$"; + echo "

{$comment_text}

"; + echo '
'; } -echo '

done with pics

'; ?>
footer