Inline WebM files, move oEmbed service URLs into settings.php

This commit is contained in:
Trevor Slocum 2016-09-23 20:59:09 -07:00
parent eedef06bbf
commit d784dcc072
6 changed files with 52 additions and 42 deletions

View File

@ -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``.

View File

@ -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);

View File

@ -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');
}

View File

@ -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);

View File

@ -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
<video $dimensions style="position: static; pointer-events: inherit; display: inline; max-width: 100%; max-height: 100%;" controls autoplay loop>
<source src="$direct_link"></source>
</video>
EOF;
} else if ($post["file"] != '') {
$expandhtml = "<a href=\"src/${post["file"]}\" onclick=\"return expandFile(event, '${post['id']}');\"><img src=\"" . ($res == TINYIB_RESPAGE ? "../" : "") . "src/${post["file"]}\" width=\"${post["image_width"]}\" style=\"max-width: 100%;height: auto;\"></a>";
}
@ -128,7 +134,14 @@ function buildPost($post, $res) {
if (isEmbed($post["file_hex"])) {
$filesize .= "<a href=\"$direct_link\" onclick=\"return expandFile(event, '${post['id']}');\">${post['file_original']}</a>&ndash;(${post['file_hex']})";
} else if ($post["file"] != '') {
$filesize .= $thumblink . "${post["file"]}</a>&ndash;(${post["file_size_formatted"]}, ${post["image_width"]}x${post["image_height"]}, ${post["file_original"]})";
$filesize .= $thumblink . "${post["file"]}</a>&ndash;(${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 .= '<br>';
}
$filehtml .= <<<EOF
$filesize
<br>
<span id="thumbfile${post['id']}">
$filehtml .= $filesize . '<br><div id="thumbfile' . $post['id'] . '">';
if ($post["thumb_width"] > 0 && $post["thumb_height"] > 0) {
$filehtml .= <<<EOF
$thumblink
<img src="thumb/${post["thumb"]}" alt="${post["id"]}" class="thumb" id="thumbnail${post['id']}" width="${post["thumb_width"]}" height="${post["thumb_height"]}">
</a>
</span>
EOF;
}
$filehtml .= '</div>';
if ($expandhtml != '') {
$filehtml .= <<<EOF
<div id="expand${post['id']}" style="display: none;">$expandhtml</div>

View File

@ -32,8 +32,7 @@ define('TINYIB_MAXREPLIES', 0); // Maximum replies before a thread stops b
// Upload types
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_EMBED', false); // Enable embedding (e.g. YouTube, Vimeo, SoundCloud)
define('TINYIB_WEBM', false); // Enable .webm audio/video file upload (see README for instructions)
// File control
define('TINYIB_MAXKB', 2048); // Maximum file size in kilobytes [0 to disable]
@ -49,6 +48,12 @@ define('TINYIB_MAXHOP', 250); // Height
define('TINYIB_MAXW', 250); // Width
define('TINYIB_MAXH', 250); // Height
// Embedding - oEmbed API
define('TINYIB_EMBED', true); // Enable embedding (e.g. YouTube, Vimeo, SoundCloud)
$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');
// Tripcode seed - Must not change once set!
define('TINYIB_TRIPSEED', ''); // Enter some random text (used when generating secure tripcodes)