diff --git a/README.md b/README.md index 79f184e..c298b4f 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ For demos see the [TinyIB Installations](https://github.com/tslocum/TinyIB/wiki) Features ------------ - - GIF, JPG, PNG and WebA/WebM upload. + - GIF, JPG, PNG, SWF and WebA/WebM upload. - Reference links >>### - Delete post via password. - Management panel: @@ -33,11 +33,11 @@ Installing - `git clone git://github.com/tslocum/TinyIB.git ./` 4. Copy **settings.default.php** to **settings.php** 5. Configure **settings.php** + - To remove the play icon from .SWF/.WebM thumbnails, delete or rename **video_overlay.png**. - To allow WebA/WebM upload: - Ensure your web host is running Linux. - Install [mediainfo](http://mediaarea.net/en/MediaInfo) and [ffmpegthumbnailer](https://code.google.com/p/ffmpegthumbnailer/). On Ubuntu, run ``sudo apt-get install mediainfo ffmpegthumbnailer``. - Set ``TINYIB_WEBM`` to ``true``. - - To remove the play icon from thumbnails, delete or rename **video_overlay.png**. 6. [CHMOD](http://en.wikipedia.org/wiki/Chmod) write permissions to these directories: - ./ (the directory containing TinyIB) - ./src/ diff --git a/imgboard.php b/imgboard.php index 4ce6fdc..882da8f 100644 --- a/imgboard.php +++ b/imgboard.php @@ -102,6 +102,7 @@ if (isset($_POST['message']) || isset($_POST['file'])) { $post['file_size'] = $_FILES['file']['size']; $post['file_size_formatted'] = convertBytes($post['file_size']); + // Uploaded file type $file_type = strtolower(preg_replace('/.*(\..+)/', '\1', $_FILES['file']['name'])); if ($file_type == '.jpeg') { $file_type = '.jpg'; @@ -110,9 +111,19 @@ if (isset($_POST['message']) || isset($_POST['file'])) { $file_type = '.webm'; } + // Thumbnail type + if ($file_type == '.webm') { + $thumb_type = '.jpg'; + } else if ($file_type == '.swf') { + $thumb_type = '.png'; + } else { + $thumb_type = $file_type; + } + $file_name = time() . substr(microtime(), 2, 3); $post['file'] = $file_name . $file_type; - $post['thumb'] = $file_name . "s" . ($file_type == '.webm' ? '.jpg' : $file_type); + $post['thumb'] = $file_name . "s" . $thumb_type; + $file_location = "src/" . $post['file']; $thumb_location = "thumb/" . $post['thumb']; @@ -136,9 +147,9 @@ if (isset($_POST['message']) || isset($_POST['file'])) { $file_mime = $file_info['mime']; } - if (!($file_mime == "image/jpeg" || $file_mime == "image/gif" || $file_mime == "image/png" || (TINYIB_WEBM && ($file_mime == "video/webm" || $file_mime == "audio/webm")))) { + if (!($file_mime == "image/jpeg" || $file_mime == "image/gif" || $file_mime == "image/png" || (TINYIB_WEBM && ($file_mime == "video/webm" || $file_mime == "audio/webm")) || (TINYIB_SWF && ($file_mime == "application/x-shockwave-flash")))) { @unlink($file_location); - fancyDie("Only " . (TINYIB_WEBM ? "GIF, JPG, PNG, and WEBM" : "GIF, JPG, and PNG") . " files are allowed."); + fancyDie(supportedFileTypes()); } if ($_FILES['file']['size'] != filesize($file_location)) { @@ -175,24 +186,7 @@ if (isset($_POST['message']) || isset($_POST['file'])) { fancyDie("Sorry, your video appears to be corrupt."); } - if (file_exists('video_overlay.png')) { - $thumbnail = imagecreatefromjpeg($thumb_location); - list($width, $height, $type, $attr) = getimagesize($thumb_location); - - $overlay_play = imagecreatefrompng('video_overlay.png'); - imagealphablending($overlay_play, false); - imagesavealpha($overlay_play, true); - list($overlay_width, $overlay_height, $overlay_type, $overlay_attr) = getimagesize('video_overlay.png'); - - $new_thumbnail = imagecreatetruecolor($width, $height); - imagecopyresampled($new_thumbnail, $thumbnail, 0, 0, 0, 0, $width, $height, $width, $height); - imagecopyresampled($new_thumbnail, $overlay_play, ($width / 2) - ($overlay_width / 2), ($height / 2) - ($overlay_height / 2), 0, 0, $overlay_width, $overlay_width, $overlay_width, $overlay_height); - imagejpeg($new_thumbnail, $thumb_location); - - $thumb_info = getimagesize($thumb_location); - $post['thumb_width'] = $thumb_info[0]; - $post['thumb_height'] = $thumb_info[1]; - } + addVideoOverlay($thumb_location); } $duration = intval(shell_exec('mediainfo --Inform="' . ($file_mime == 'video/webm' ? 'Video' : 'Audio') . ';%Duration%" ' . $file_location)); @@ -206,25 +200,35 @@ if (isset($_POST['message']) || isset($_POST['file'])) { $post['image_width'] = $file_info[0]; $post['image_height'] = $file_info[1]; - list($thumb_maxwidth, $thumb_maxheight) = thumbnailDimensions($post); + if ($file_mime == "application/x-shockwave-flash") { + if (!copy('swf_thumbnail.png', $thumb_location)) { + @unlink($file_location); + fancyDie("Could not create thumbnail."); + } - if (!createThumbnail($file_location, $thumb_location, $thumb_maxwidth, $thumb_maxheight)) { - fancyDie("Could not create thumbnail."); + addVideoOverlay($thumb_location); + } else { + list($thumb_maxwidth, $thumb_maxheight) = thumbnailDimensions($post); + + if (!createThumbnail($file_location, $thumb_location, $thumb_maxwidth, $thumb_maxheight)) { + @unlink($file_location); + fancyDie("Could not create thumbnail."); + } } - - $thumb_info = getimagesize($thumb_location); - $post['thumb_width'] = $thumb_info[0]; - $post['thumb_height'] = $thumb_info[1]; } + + $thumb_info = getimagesize($thumb_location); + $post['thumb_width'] = $thumb_info[0]; + $post['thumb_height'] = $thumb_info[1]; } } if ($post['file'] == '') { // No file uploaded - if ($post['parent'] == TINYIB_NEWTHREAD) { - fancyDie("An image is required to start a thread."); + if ($post['parent'] == TINYIB_NEWTHREAD && (TINYIB_PIC || TINYIB_SWF || TINYIB_WEBM)) { + fancyDie("A file is required to start a thread."); } if (str_replace('
', '', $post['message']) == "") { - fancyDie("Please enter a message and/or upload an image to make a reply."); + fancyDie("Please enter a message" . ((TINYIB_PIC || TINYIB_SWF || TINYIB_WEBM) ? " and/or upload a file" : "") . "."); } } else { echo $post['file_original'] . ' uploaded.
'; diff --git a/inc/defines.php b/inc/defines.php index 13959d2..098d8b7 100644 --- a/inc/defines.php +++ b/inc/defines.php @@ -18,6 +18,12 @@ if (!defined('TINYIB_MAXWOP')) { if (!defined('TINYIB_MAXHOP')) { define('TINYIB_MAXHOP', TINYIB_MAXH); } +if (!defined('TINYIB_PIC')) { + define('TINYIB_PIC', true); +} +if (!defined('TINYIB_SWF')) { + define('TINYIB_SWF', false); +} if (!defined('TINYIB_WEBM')) { define('TINYIB_WEBM', false); } diff --git a/inc/functions.php b/inc/functions.php index 984dc8b..b1ea56a 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -374,6 +374,36 @@ function fastImageCopyResampled(&$dst_image, &$src_image, $dst_x, $dst_y, $src_x return true; } +function addVideoOverlay($thumb_location) { + if (file_exists('video_overlay.png')) { + if (substr($thumb_location, -4) == ".jpg") { + $thumbnail = imagecreatefromjpeg($thumb_location); + } else { + $thumbnail = imagecreatefrompng($thumb_location); + } + list($width, $height, $type, $attr) = getimagesize($thumb_location); + + $overlay_play = imagecreatefrompng('video_overlay.png'); + imagealphablending($overlay_play, false); + imagesavealpha($overlay_play, true); + list($overlay_width, $overlay_height, $overlay_type, $overlay_attr) = getimagesize('video_overlay.png'); + + if (substr($thumb_location, -4) == ".png") { + imagecolortransparent($thumbnail, imagecolorallocatealpha($thumbnail, 0, 0, 0, 127)); + imagealphablending($thumbnail, true); + imagesavealpha($thumbnail, true); + } + + imagecopy($thumbnail, $overlay_play, ($width / 2) - ($overlay_width / 2), ($height / 2) - ($overlay_height / 2), 0, 0, $overlay_width, $overlay_height); + + if (substr($thumb_location, -4) == ".jpg") { + imagejpeg($thumbnail, $thumb_location); + } else { + imagepng($thumbnail, $thumb_location); + } + } +} + function strallpos($haystack, $needle, $offset = 0) { $result = array(); for ($i = $offset; $i < strlen($haystack); $i++) { diff --git a/inc/html.php b/inc/html.php index 815cd27..020cc77 100644 --- a/inc/html.php +++ b/inc/html.php @@ -35,6 +35,36 @@ function pageFooter() { EOF; } +function supportedFileTypes() { + $types_allowed = array(); + if (TINYIB_PIC) { + array_push($types_allowed, "GIF", "JPG", "PNG"); + } + if (TINYIB_SWF) { + array_push($types_allowed, "SWF"); + } + if (TINYIB_WEBM) { + array_push($types_allowed, "WebM"); + } + + $i = 0; + $types_count = count($types_allowed); + $types_formatted = ""; + foreach ($types_allowed as $type) { + if (++$i >= $types_count - 1) { + $types_formatted .= $type . ($i == $types_count - 1 && $types_count > 1 ? " and " : ""); + } else { + $types_formatted .= $type . ", "; + } + } + + if ($types_formatted != "") { + return "Supported file type" . ($types_count != 1 ? "s are " : " is ") . $types_formatted . "."; + } + + return $types_formatted; +} + function buildPost($post, $res) { $return = ""; $threadid = ($post['parent'] == TINYIB_NEWTHREAD) ? $post['id'] : $post['parent']; @@ -165,21 +195,42 @@ EOF; $postingmode = '[Return]
Posting mode: Reply
'; } - $filetypes = (TINYIB_WEBM ? "GIF, JPG, PNG, and WEBM" : "GIF, JPG, and PNG"); - + $max_file_size_input_html = ''; + $max_file_size_rules_html = ''; + $filetypes_html = ''; + $file_input_html = ''; $unique_posts_html = ''; + + if (TINYIB_PIC || TINYIB_WEBM || TINYIB_SWF) { + if (TINYIB_MAXKB > 0) { + $max_file_size_input_html = ''; + $max_file_size_rules_html = '
  • Maximum file size allowed is ' . TINYIB_MAXKBDESC . '.
  • '; + } + + $filetypes_html = '
  • ' . supportedFileTypes() . '
  • '; + + $file_input_html = << + + File + + + + + +EOF; + } + + $thumbnails_html = ''; + if (TINYIB_PIC) { + $thumbnails_html = "
  • Images greater than $maxdimensions will be thumbnailed.
  • "; + } + $unique_posts = uniquePosts(); if ($unique_posts > 0) { $unique_posts_html = "
  • Currently $unique_posts unique user posts.
  • \n"; } - $max_file_size_input = ''; - $max_file_size_html = ''; - if (TINYIB_MAXKB > 0) { - $max_file_size_input_html = ''; - $max_file_size_rules_html = '
  • Maximum file size allowed is ' . TINYIB_MAXKBDESC . '.
  • '; - } - $body = <<
    @@ -193,7 +244,7 @@ EOF; $postingmode
    - $max_file_size_input + $max_file_size_input_html @@ -230,14 +281,7 @@ EOF; - - - - + $file_input_html diff --git a/settings.default.php b/settings.default.php index 658e7eb..b8fe2e8 100644 --- a/settings.default.php +++ b/settings.default.php @@ -8,6 +8,8 @@ define('TINYIB_PREVIEWREPLIES', 3); // Amount of replies previewed on index page define('TINYIB_MAXREPLIES', 0); // Maximum replies before a thread stops bumping [0 to disable] define('TINYIB_MAXKB', 2048); // Maximum file size in kilobytes [0 to disable] define('TINYIB_MAXKBDESC', "2 MB"); // Human-readable representation of the maximum file size +define('TINYIB_PIC', true); // Enable .jpg, .png and .gif image file upload +define('TINYIB_SWF', false); // Enable .swf Flash file upload define('TINYIB_WEBM', false); // Enable .weba and .webm audio/video file upload (see README for instructions) define('TINYIB_MAXW', 250); // Maximum image width (reply) - Images exceeding these sizes will be thumbnailed define('TINYIB_MAXH', 250); // Maximum image height (reply) diff --git a/swf_thumbnail.png b/swf_thumbnail.png new file mode 100644 index 0000000..d56c208 Binary files /dev/null and b/swf_thumbnail.png differ
    - File - - -
    Password @@ -249,9 +293,9 @@ EOF;
      -
    • Supported file types are $filetypes.
    • + $filetypes_html $max_file_size_rules_html -
    • Images greater than $maxdimensions will be thumbnailed.
    • + $thumbnails_html $unique_posts_html