From d784dcc0723fc77e53f5bd9a6c4e86e8ac8c4c5a Mon Sep 17 00:00:00 2001 From: Trevor Slocum Date: Fri, 23 Sep 2016 20:59:09 -0700 Subject: [PATCH] Inline WebM files, move oEmbed service URLs into settings.php --- README.md | 4 ++-- imgboard.php | 34 +++++++++++----------------------- inc/defines.php | 3 +++ inc/functions.php | 8 ++++---- inc/html.php | 36 +++++++++++++++++++++++++----------- settings.default.php | 9 +++++++-- 6 files changed, 52 insertions(+), 42 deletions(-) diff --git a/README.md b/README.md index 0730132..a59f366 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ For demos see the [TinyIB Installations](https://github.com/tslocum/TinyIB/wiki) Features ------------ - - GIF, JPG, PNG, SWF and WebA/WebM upload. + - GIF, JPG, PNG, SWF and WebM upload. - YouTube, Vimeo and SoundCloud embedding. - CAPTCHA (A simple implementation is included, reCAPTCHA is also supported) - Reference links >>### @@ -38,7 +38,7 @@ Installing - `git clone git://github.com/tslocum/TinyIB.git ./` 4. Copy **settings.default.php** to **settings.php** 5. Configure **settings.php** - - To allow WebA/WebM upload: + - To allow 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``. diff --git a/imgboard.php b/imgboard.php index a688d72..11aa87f 100644 --- a/imgboard.php +++ b/imgboard.php @@ -31,7 +31,7 @@ function fancyDie($message) { } if (!file_exists('settings.php')) { - fancyDie('Please rename the file settings.default.php to settings.php'); + fancyDie('Please copy the file settings.default.php to settings.php'); } require 'settings.php'; @@ -102,7 +102,7 @@ if (isset($_POST['message']) || isset($_POST['file'])) { if (isset($_POST['embed']) && trim($_POST['embed']) != '') { list($service, $embed) = getEmbed(trim($_POST['embed'])); if (empty($embed) || !isset($embed['html']) || !isset($embed['title']) || !isset($embed['thumbnail_url'])) { - fancyDie("Invalid embed URL. Only " . (implode("/", array_keys(TINYIB_EMBEDS))) . " URLs are supported."); + fancyDie("Invalid embed URL. Only " . (implode("/", array_keys($tinyib_embeds))) . " URLs are supported."); } $post['file_hex'] = $service; @@ -162,9 +162,6 @@ if (isset($_POST['message']) || isset($_POST['file'])) { if ($file_type == '.jpeg') { $file_type = '.jpg'; } - if ($file_type == '.weba') { - $file_type = '.webm'; - } // Thumbnail type if ($file_type == '.webm') { @@ -213,21 +210,10 @@ if (isset($_POST['message']) || isset($_POST['file'])) { } if ($file_mime == "audio/webm" || $file_mime == "video/webm") { - $post['image_width'] = intval(shell_exec('mediainfo --Inform="Video;%Width%" ' . $file_location)); - $post['image_height'] = intval(shell_exec('mediainfo --Inform="Video;%Height%" ' . $file_location)); + $post['image_width'] = max(0, intval(shell_exec('mediainfo --Inform="Video;%Width%" ' . $file_location))); + $post['image_height'] = max(0, intval(shell_exec('mediainfo --Inform="Video;%Height%" ' . $file_location))); - if ($post['image_width'] <= 0 || $post['image_height'] <= 0) { - $post['image_width'] = 0; - $post['image_height'] = 0; - - $file_location_old = $file_location; - $file_location = substr($file_location, 0, -1) . 'a'; // replace webm with weba - rename($file_location_old, $file_location); - - $post['file'] = substr($post['file'], 0, -1) . 'a'; // replace webm with weba - } - - if ($file_mime == "video/webm") { + if ($post['image_width'] > 0 && $post['image_height'] > 0) { list($thumb_maxwidth, $thumb_maxheight) = thumbnailDimensions($post); shell_exec("ffmpegthumbnailer -s " . max($thumb_maxwidth, $thumb_maxheight) . " -i $file_location -o $thumb_location"); @@ -244,11 +230,13 @@ if (isset($_POST['message']) || isset($_POST['file'])) { addVideoOverlay($thumb_location); } - $duration = intval(shell_exec('mediainfo --Inform="' . ($file_mime == 'video/webm' ? 'Video' : 'Audio') . ';%Duration%" ' . $file_location)); - $mins = floor(round($duration / 1000) / 60); - $secs = str_pad(floor(round($duration / 1000) % 60), 2, "0", STR_PAD_LEFT); + $duration = intval(shell_exec('mediainfo --Inform="General;%Duration%" ' . $file_location)); + if ($duration > 0) { + $mins = floor(round($duration / 1000) / 60); + $secs = str_pad(floor(round($duration / 1000) % 60), 2, "0", STR_PAD_LEFT); - $post['file_original'] = "$mins:$secs" . ($post['file_original'] != '' ? (', ' . $post['file_original']) : ''); + $post['file_original'] = "$mins:$secs" . ($post['file_original'] != '' ? (', ' . $post['file_original']) : ''); + } } else { $file_info = getimagesize($file_location); diff --git a/inc/defines.php b/inc/defines.php index 74efadb..dc7cd2a 100644 --- a/inc/defines.php +++ b/inc/defines.php @@ -54,3 +54,6 @@ if (!defined('TINYIB_DBDRIVER')) { if (!defined('TINYIB_DBDSN')) { define('TINYIB_DBDSN', ''); } +if (!isset($tinyib_embeds)) { + $tinyib_embeds = array('SoundCloud' => 'http://soundcloud.com/oembed?format=json&url=TINYIBEMBED', 'Vimeo' => 'http://vimeo.com/api/oembed.json?url=TINYIBEMBED', 'YouTube' => 'http://www.youtube.com/oembed?url=TINYIBEMBED&format=json'); +} diff --git a/inc/functions.php b/inc/functions.php index 27eb61f..edc7fb9 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -3,8 +3,6 @@ if (!defined('TINYIB_BOARD')) { die(''); } -define('TINYIB_EMBEDS', array('YouTube' => "http://www.youtube.com/oembed?url=TINYIBEMBED&format=json", 'Vimeo' => "http://vimeo.com/api/oembed.json?url=TINYIBEMBED", 'SoundCloud' => "http://soundcloud.com/oembed?format=json&url=TINYIBEMBED")); - $posts_sql = "CREATE TABLE `" . TINYIB_DBPOSTS . "` ( `id` mediumint(7) unsigned NOT NULL auto_increment, `parent` mediumint(7) unsigned NOT NULL, @@ -525,11 +523,13 @@ function strallpos($haystack, $needle, $offset = 0) { } function isEmbed($file_hex) { - return in_array($file_hex, array_keys(TINYIB_EMBEDS)); + global $tinyib_embeds; + return in_array($file_hex, array_keys($tinyib_embeds)); } function getEmbed($url) { - foreach (TINYIB_EMBEDS as $service => $service_url) { + global $tinyib_embeds; + foreach ($tinyib_embeds as $service => $service_url) { $service_url = str_ireplace("TINYIBEMBED", urlencode($url), $service_url); $curl = curl_init($service_url); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); diff --git a/inc/html.php b/inc/html.php index cbf0526..456c4bb 100644 --- a/inc/html.php +++ b/inc/html.php @@ -106,11 +106,7 @@ function buildPost($post, $res) { $filehtml = ''; $filesize = ''; $expandhtml = ''; - - $direct_link = '#'; - if (!isEmbed($post["file_hex"])) { - $direct_link = "src/${post["file"]}"; - } + $direct_link = isEmbed($post["file_hex"]) ? "#" : (($res == TINYIB_RESPAGE ? "../" : "") . "src/" . $post["file"]); if ($post['parent'] == TINYIB_NEWTHREAD && $post["file"] != '') { $filesize .= isEmbed($post['file_hex']) ? 'Embed: ' : 'File: '; @@ -118,6 +114,16 @@ function buildPost($post, $res) { if (isEmbed($post["file_hex"])) { $expandhtml = $post['file']; + } else if (substr($post['file'], -5) == '.webm') { + $dimensions = 'width="500" height="50"'; + if ($post['image_width'] > 0 && $post['image_height'] > 0) { + $dimensions = 'width="' . $post['image_width'] . '" height="' . $post['image_height'] . '"'; + } + $expandhtml = << + + +EOF; } else if ($post["file"] != '') { $expandhtml = ""; } @@ -128,7 +134,14 @@ function buildPost($post, $res) { if (isEmbed($post["file_hex"])) { $filesize .= "${post['file_original']}–(${post['file_hex']})"; } else if ($post["file"] != '') { - $filesize .= $thumblink . "${post["file"]}–(${post["file_size_formatted"]}, ${post["image_width"]}x${post["image_height"]}, ${post["file_original"]})"; + $filesize .= $thumblink . "${post["file"]}–(${post["file_size_formatted"]}"; + if ($post["image_width"] > 0 && $post["image_height"] > 0) { + $filesize .= ", " . $post["image_width"] . "x" . $post["image_height"]; + } + if ($post["file_original"] != "") { + $filesize .= ", " . $post["file_original"]; + } + $filesize .= ")"; } if ($filesize != '') { @@ -139,15 +152,16 @@ function buildPost($post, $res) { if ($post['parent'] != TINYIB_NEWTHREAD) { $filehtml .= '
'; } - $filehtml .= << - + $filehtml .= $filesize . '
'; + if ($post["thumb_width"] > 0 && $post["thumb_height"] > 0) { + $filehtml .= << - EOF; + } + $filehtml .= '
'; + if ($expandhtml != '') { $filehtml .= <<