diff --git a/README.md b/README.md index 5d90421..b316f45 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,8 @@ this is a silly little BBS page I've thrown together out of a desite to have som comment VARCHAR(2048), img VARCHAR(256), thumb_width INT, - thumb_height INT + thumb_height INT, + spoiler BOOL ); ``` ```sql diff --git a/index.php b/index.php index 517323e..e975791 100644 --- a/index.php +++ b/index.php @@ -61,7 +61,10 @@ * trip VARCHAR(10), * email VARCHAR(256), * comment VARCHAR(2048), - * img VARCHAR(256) + * img VARCHAR(256), + * thumb_width INT, + * thumb_height INT, + * spoiler BOOL * ); * * CREATE TABLE access @@ -80,7 +83,7 @@ //// Functions: //// // Adds a post to the database - function post($name, $email, $comment, $img, $save_cookie, $captcha, $captcha_answer) { + function post($name, $email, $comment, $img, $spoiler, $save_cookie, $captcha, $captcha_answer) { $extensions = [ 'image/bmp' => '.bmp', 'image/gif' => '.gif', @@ -131,14 +134,18 @@ return 'Unable to upload image, please contact the webmaster.'; } - // Create thumbnail - exec("ffmpeg -y -loglevel error -i '$target' -filter_complex 'color=#ffccdd[c];[c][0]scale2ref[cs][0s];[cs][0s]overlay=shortest=1[o];[o]scale=min(200\,iw):-1[o];[o]scale=-1:min(100\,ih)' -frames:v 1 " . THUMB_PATH . "$img_name.jpg", $output, $ret); - if($ret != 0) { - @unlink($target); - return 'Unable to create thumbnail, please contact the webmaster.'; + if(!$spoiler) { + $thumb_size = getimagesize(ASSETS_PATH . "spoiler.gif"); + } else { + // Create thumbnail + exec("ffmpeg -y -loglevel error -i '$target' -filter_complex 'color=#ffccdd[c];[c][0]scale2ref[cs][0s];[cs][0s]overlay=shortest=1[o];[o]scale=min(200\,iw):-1[o];[o]scale=-1:min(100\,ih)' -frames:v 1 " . THUMB_PATH . "$img_name.jpg", $output, $ret); + if($ret != 0) { + @unlink($target); + return 'Unable to create thumbnail, please contact the webmaster.'; + } + + $thumb_size = getimagesize(THUMB_PATH . "$img_name.jpg"); } - - $thumb_size = getimagesize(THUMB_PATH . "$img_name.jpg"); } else { // The new image file move failed, so delete the temporary file and return an error @unlink($img['tmp_name']); @@ -172,8 +179,8 @@ $trip_name = trip_name($name); // Add post to database - $query = 'INSERT INTO posts (user_id, name, trip, email, comment, img, thumb_width, thumb_height) ' . - 'VALUES ($1, $2, $3, $4, $5, $6, $7, $8)'; + $query = 'INSERT INTO posts (user_id, name, trip, email, comment, img, thumb_width, thumb_height, spoiler) ' . + 'VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)'; $params = [ empty($uid) ? NULL : $uid, empty($trip_name['name']) ? 'Anonymous' : htmlspecialchars($trip_name['name']), @@ -182,7 +189,8 @@ empty($comment) ? NULL : htmlspecialchars($comment), empty($target) ? NULL : basename($target), $thumb_size[0], - $thumb_size[1] + $thumb_size[1], + $spoiler ? 'T' : 'F' ]; pg_query_params($query, $params) or die('Query failed: ' . pg_last_error()); @@ -203,7 +211,7 @@ // Prints the post list function show_posts() { - $query = 'SELECT post_id, user_id, name, trip, email, comment, img, thumb_width, thumb_height, post_time FROM posts ORDER BY posts.post_time'; + $query = 'SELECT post_id, user_id, name, trip, email, comment, img, thumb_width, thumb_height, spoiler, post_time FROM posts ORDER BY posts.post_time'; $result = pg_query($query) or die('Query failed: ' . pg_last_error()); // Clean up old posts @@ -257,7 +265,8 @@ echo '
'; if(!empty($row['img'])){ echo ''; - echo '\"{$row['img']}\""; + $thumb_path = ($row['spoiler'] == 't') ? (ASSETS_PATH . 'spoiler.gif') : (THUMB_PATH . preg_replace('/\.(?:png|gif|bmp)$/', '.jpg', $row['img'])); + echo "\"{$row['img']}\""; echo ''; } @@ -383,11 +392,12 @@ $email = trim($_POST['email']); $comment = trim($_POST['comment']); $img = $_FILES['img']; + $spoiler = isset($_POST['spoiler']) && !empty($_FILES['img']['tmp_name']); $save_cookie = isset($_POST['save_cookie']); $captcha = trim($_POST['captcha']); $captcha_answer = trim($_POST['captcha_answer']); - $err = post($name, $email, $comment, $img, $save_cookie, $captcha, $captcha_answer); + $err = post($name, $email, $comment, $img, $spoiler, $save_cookie, $captcha, $captcha_answer); if($err == "") { # Redirect to latest post $query = 'SELECT post_id FROM posts ORDER BY posts.post_time DESC LIMIT 1'; @@ -480,6 +490,11 @@

+ + +
+
+
@@ -514,6 +529,10 @@ (Limit: > 10; ?> KiB) + + + + diff --git a/rss.php b/rss.php index 9a2b37b..a5ca63d 100644 --- a/rss.php +++ b/rss.php @@ -52,7 +52,7 @@ // Get posts $posts = []; - $query = "SELECT post_id, name, trip, email, comment, img, TO_CHAR(post_time, 'Dy, DD Mon YYYY HH24:MI:SS TZHTZM') AS ts " + $query = "SELECT post_id, name, trip, email, comment, img, spoiler, TO_CHAR(post_time, 'Dy, DD Mon YYYY HH24:MI:SS TZHTZM') AS ts " . "FROM posts ORDER BY posts.post_time DESC LIMIT 10"; $result = pg_query($query) or die('Query failed: ' . pg_last_error()); @@ -71,7 +71,7 @@ if(!empty($row['trip'])) $name .= '◆' . $row['trip']; $comment = htmlspecialchars("

$comment

"); - $img = preg_replace('/\.(?:png|gif|bmp)$/', '.jpg', $row['img']); + $img = ($row['spoiler'] == 't') ? (ASSETS_PATH . 'spoiler.gif') : (THUMB_PATH . preg_replace('/\.(?:png|gif|bmp)$/', '.jpg', $row['img'])); $posts[] = [ 'title' => "New post by $name", @@ -81,9 +81,9 @@ 'pubDate' => $row['ts'], 'guid' => 'p' . $row['post_id'], 'img' => empty($row['img']) ? NULL : [ - 'url' => $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['SERVER_NAME'] . '/' . THUMB_PATH . $img, - 'length' => filesize(THUMB_PATH . $img), - 'type' => mime_content_type(THUMB_PATH . $img) + 'url' => $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['SERVER_NAME'] . '/' . $img, + 'length' => filesize($img), + 'type' => mime_content_type($img) ] ]; }