diff --git a/bbs.php b/bbs.php index 0d2101e..8f5ea3a 100644 --- a/bbs.php +++ b/bbs.php @@ -38,6 +38,7 @@ * // Application constants * define('UPLOAD_PATH', 'image/'); // Folder to save images to * define('THUMB_PATH', 'thumb/'); // Folder to save thumbnails to + * define('ASSETS_PATH', 'assets/'); // Folder to store assets (header images, etc) in * define('MAX_FILE_SIZE', 8 << 20); // Maximum image size, 8 MiB * define('ADMIN_ID', ''); // uid that is able to delete anything * define('UID_SALT', ''); @@ -61,6 +62,9 @@ * comment VARCHAR(2048), * img VARCHAR(256) * ); + * + * Finally, you will also need ffmpeg and exiftool installed for + * metadata stripping and thumbnail conversion. */ require_once('vars.php'); @@ -85,24 +89,26 @@ // Move the file to the target upload folder $img_name = time(); $ext = $extensions[$img['type']]; - $temp = UPLOAD_PATH . "__temp$ext"; $target = UPLOAD_PATH . $img_name . $ext; - if(move_uploaded_file($img['tmp_name'], $temp)) { + if(move_uploaded_file($img['tmp_name'], $target)) { $output = null; $ret = null; - // Strip EXIF data - exec("ffmpeg -y -loglevel error -i $temp '$target'", $output, $ret); - @unlink($temp); - if($ret != 0) - return 'Unable to upload image, please contact the webmaster.'; + if($img['type'] != 'image/bmp') { + // Strip EXIF data + exec("exiftool -overwrite_original -all:all= '$target'", $output, $ret); + if($ret != 0) + 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)' " . THUMB_PATH . "$img_name.jpg", $output, $ret); + 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"); } else { // The new image file move failed, so delete the temporary file and return an error @unlink($img['tmp_name']); @@ -145,14 +151,17 @@ $trip_name = trip_name($name); // Add post to database - $query = "INSERT INTO posts (user_id, name, trip, email, comment, img) VALUES ($1, $2, $3, $4, $5, $6)"; + $query = 'INSERT INTO posts (user_id, name, trip, email, comment, img, thumb_width, thumb_height) ' . + 'VALUES ($1, $2, $3, $4, $5, $6, $7, $8)'; $params = [ empty($uid) ? NULL : $uid, empty($trip_name['name']) ? 'Anonymous' : htmlspecialchars($trip_name['name']), empty($trip_name['trip']) ? NULL : htmlspecialchars($trip_name['trip']), empty($email) ? NULL : $email, empty($comment) ? NULL : htmlspecialchars($comment), - empty($target) ? NULL : basename($target) + empty($target) ? NULL : basename($target), + $thumb_size[0], + $thumb_size[1] ]; pg_query_params($query, $params) or die('Query failed: ' . pg_last_error()); @@ -173,7 +182,7 @@ // Prints the post list function show_posts() { - $query = 'SELECT post_id, user_id, name, trip, email, comment, img, post_time FROM posts ORDER BY posts.post_time'; + $query = 'SELECT post_id, user_id, name, trip, email, comment, img, thumb_width, thumb_height, post_time FROM posts ORDER BY posts.post_time'; $result = pg_query($query) or die('Query failed: ' . pg_last_error()); // Clean up old posts @@ -189,7 +198,7 @@ $show_delete = FALSE; echo '
'; while($row = pg_fetch_array($result)) { - echo "
"; + echo "
"; $time_rel = time_ago_en($row['post_time']); $time_abs = date('Y-m-d H:m (T)', strtotime($row['post_time'])); @@ -219,10 +228,10 @@ echo ">>{$ref['post_id']} "; echo '

'; - echo '
'; + echo '
'; if(!empty($row['img'])){ echo ''; - echo '' . $row['img'] . ''; + echo '\"{$row['img']}\""; echo ''; } @@ -235,9 +244,7 @@ $comment = str_replace("\n", "
", $comment); echo "
$comment
"; } - echo '
'; - - echo '
'; + echo '
'; } pg_free_result($result); @@ -306,6 +313,14 @@ ]; } + function header_image($mobile) { + $path = ASSETS_PATH . 'header'; + if($mobile) + $path .= '/mobile'; + $files = glob("$path/*.gif"); + return $files[array_rand($files)]; + } + //// code start //// // Connect to the database @@ -340,11 +355,6 @@ } $mobile = preg_match('/Mobile|Nintendo DSi/', $_SERVER['HTTP_USER_AGENT']); - if($mobile) { - $header_image = 'header-mobile.gif'; - } else { - $header_image = 'header.gif'; - } ?> - BBS.ピケ.コム +
+ BBS.ピケ.コム +

[bottom] @@ -570,7 +596,7 @@

Formatting is very simple, just >quote - by starting a line with > and link to other posts with two > + by starting a line with > and link to other posts with two > and the post number, >>1. No other formatting is supported besides the automatic conversion of hyperlinks. You may provide a name and/or email address when posting if you wish