From eedef06bbfc965581e4891078272b9cf12c481cc Mon Sep 17 00:00:00 2001 From: Trevor Slocum Date: Wed, 21 Sep 2016 17:47:58 -0700 Subject: [PATCH] Add inline thumbnail expansion (requires rebuild) --- imgboard.php | 2 +- inc/functions.php | 17 +++++-- inc/html.php | 114 ++++++++++++++++++++++------------------------ js/jquery.js | 8 ++-- js/tinyib.js | 44 +++++++++++++----- 5 files changed, 104 insertions(+), 81 deletions(-) diff --git a/imgboard.php b/imgboard.php index f121197..a688d72 100644 --- a/imgboard.php +++ b/imgboard.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 YouTube, Vimeo, and SoundCloud URLs are supported."); + fancyDie("Invalid embed URL. Only " . (implode("/", array_keys(TINYIB_EMBEDS))) . " URLs are supported."); } $post['file_hex'] = $service; diff --git a/inc/functions.php b/inc/functions.php index 87da860..27eb61f 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -3,6 +3,8 @@ 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, @@ -213,7 +215,7 @@ function colorQuote($message) { } function deletePostImages($post) { - if ($post['file_hex'] != 'YouTube' && $post['file_hex'] != 'Vimeo' && $post['file_hex'] != 'SoundCloud' && $post['file'] != '') { + if (!isEmbed($post['file_hex']) && $post['file'] != '') { @unlink('src/' . $post['file']); } if ($post['thumb'] != '') { @@ -522,9 +524,13 @@ function strallpos($haystack, $needle, $offset = 0) { return $result; } +function isEmbed($file_hex) { + return in_array($file_hex, array_keys(TINYIB_EMBEDS)); +} + function getEmbed($url) { - $services = array('YouTube' => "http://www.youtube.com/oembed?url=" . urlencode($url) . "&format=json", 'Vimeo' => "http://vimeo.com/api/oembed.json?url=" . urlencode($url), 'SoundCloud' => "http://soundcloud.com/oembed?format=json&url=" . $url); - foreach ($services as $service => $service_url) { + 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); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); @@ -532,8 +538,9 @@ function getEmbed($url) { curl_close($curl); $result = json_decode($return, true); if (!empty($result)) { - break; + return array($service, $result); } } - return array($service, $result); + + return array('', array()); } diff --git a/inc/html.php b/inc/html.php index e64ca7f..cbf0526 100644 --- a/inc/html.php +++ b/inc/html.php @@ -103,12 +103,61 @@ function buildPost($post, $res) { $post["omitted"] = 0; } - $embed = ''; - if ($post["file_hex"] == "YouTube" || $post["file_hex"] == "Vimeo" || $post["file_hex"] == "SoundCloud") { - $embed = str_replace("'", "\'", $post['file']); + $filehtml = ''; + $filesize = ''; + $expandhtml = ''; + + $direct_link = '#'; + if (!isEmbed($post["file_hex"])) { + $direct_link = "src/${post["file"]}"; } - if ($post["parent"] != TINYIB_NEWTHREAD) { + if ($post['parent'] == TINYIB_NEWTHREAD && $post["file"] != '') { + $filesize .= isEmbed($post['file_hex']) ? 'Embed: ' : 'File: '; + } + + if (isEmbed($post["file_hex"])) { + $expandhtml = $post['file']; + } else if ($post["file"] != '') { + $expandhtml = ""; + } + + $thumblink = ""; + $expandhtml = rawurlencode($expandhtml); + + 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"]})"; + } + + if ($filesize != '') { + $filesize = '' . $filesize . ''; + } + + if ($filesize != '') { + if ($post['parent'] != TINYIB_NEWTHREAD) { + $filehtml .= '
'; + } + $filehtml .= << + +$thumblink + ${post[ + + +EOF; + if ($expandhtml != '') { + $filehtml .= <<