mirror of
https://code.rocketnine.space/tslocum/tinyib.git
synced 2025-01-18 03:38:19 +01:00
Add inline thumbnail expansion (requires rebuild)
This commit is contained in:
parent
7de09467cc
commit
eedef06bbf
@ -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;
|
||||
|
@ -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());
|
||||
}
|
||||
|
114
inc/html.php
114
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 = "<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>";
|
||||
}
|
||||
|
||||
$thumblink = "<a href=\"$direct_link\" target=\"_blank\"" . ((substr($post["file"], -4) != '.swf') ? " onclick=\"return expandFile(event, '${post['id']}');\"" : "") . ">";
|
||||
$expandhtml = rawurlencode($expandhtml);
|
||||
|
||||
if (isEmbed($post["file_hex"])) {
|
||||
$filesize .= "<a href=\"$direct_link\" onclick=\"return expandFile(event, '${post['id']}');\">${post['file_original']}</a>–(${post['file_hex']})";
|
||||
} else if ($post["file"] != '') {
|
||||
$filesize .= $thumblink . "${post["file"]}</a>–(${post["file_size_formatted"]}, ${post["image_width"]}x${post["image_height"]}, ${post["file_original"]})";
|
||||
}
|
||||
|
||||
if ($filesize != '') {
|
||||
$filesize = '<span class="filesize">' . $filesize . '</span>';
|
||||
}
|
||||
|
||||
if ($filesize != '') {
|
||||
if ($post['parent'] != TINYIB_NEWTHREAD) {
|
||||
$filehtml .= '<br>';
|
||||
}
|
||||
$filehtml .= <<<EOF
|
||||
$filesize
|
||||
<br>
|
||||
<span id="thumbfile${post['id']}">
|
||||
$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;
|
||||
if ($expandhtml != '') {
|
||||
$filehtml .= <<<EOF
|
||||
<div id="expand${post['id']}" style="display: none;">$expandhtml</div>
|
||||
<div id="file${post['id']}" class="thumb" style="display: none;"></div>
|
||||
EOF;
|
||||
}
|
||||
}
|
||||
if ($post["parent"] == TINYIB_NEWTHREAD) {
|
||||
$return .= $filehtml;
|
||||
} else {
|
||||
$return .= <<<EOF
|
||||
<table>
|
||||
<tbody>
|
||||
@ -117,32 +166,6 @@ function buildPost($post, $res) {
|
||||
¨
|
||||
</td>
|
||||
<td class="reply" id="reply${post["id"]}">
|
||||
EOF;
|
||||
} elseif ($embed != "") {
|
||||
$return .= <<<EOF
|
||||
<span class="filesize">Embed: <a href="#" id="tiembed${post['id']}">${post["file_original"]}</a>–(${post["file_hex"]})</span>
|
||||
<br>
|
||||
<span id="thumbembed${post['id']}">
|
||||
<a href="#" id="exembed${post['id']}">
|
||||
<img src="thumb/${post["thumb"]}" alt="${post["id"]}" class="thumb opthumb" id="thumbnail${post['id']}" width="${post["thumb_width"]}" height="${post["thumb_height"]}">
|
||||
</a>
|
||||
</span>
|
||||
<div id="embed${post['id']}" class="thumb" style="display: none;"></div>
|
||||
<script type="text/javascript">
|
||||
$("#tiembed${post['id']}, #exembed${post['id']}").click(function(){
|
||||
showEmbed('${post['id']}', '$embed');
|
||||
return false;
|
||||
});
|
||||
</script>
|
||||
EOF;
|
||||
|
||||
} elseif ($post["file"] != "") {
|
||||
$return .= <<<EOF
|
||||
<span class="filesize">File: <a href="src/${post["file"]}">${post["file"]}</a>–(${post["file_size_formatted"]}, ${post["image_width"]}x${post["image_height"]}, ${post["file_original"]})</span>
|
||||
<br>
|
||||
<a target="_blank" href="src/${post["file"]}">
|
||||
<span id="thumb${post['id']}"><img src="thumb/${post["thumb"]}" alt="${post["id"]}" class="thumb" width="${post["thumb_width"]}" height="${post["thumb_height"]}"></span>
|
||||
</a>
|
||||
EOF;
|
||||
}
|
||||
|
||||
@ -153,7 +176,7 @@ EOF;
|
||||
EOF;
|
||||
|
||||
if ($post['subject'] != '') {
|
||||
$return .= ' <span class="filetitle">' . $post['subject'] . '</span> ';
|
||||
$return .= ' <span class="filetitle">' . $post['subject'] . '</span> ';
|
||||
}
|
||||
|
||||
$return .= <<<EOF
|
||||
@ -165,34 +188,7 @@ ${post["nameblock"]}
|
||||
EOF;
|
||||
|
||||
if ($post['parent'] != TINYIB_NEWTHREAD) {
|
||||
if ($embed != "") {
|
||||
$return .= <<<EOF
|
||||
<br>
|
||||
<span class="filesize"><a href="#" id="tiembed${post['id']}">${post['file_original']}</a>–(${post['file_hex']})</span>
|
||||
<br>
|
||||
<span id="thumbembed${post['id']}">
|
||||
<a href="#" id="exembed${post['id']}">
|
||||
<img src="thumb/${post["thumb"]}" alt="${post["id"]}" class="thumb" id="thumbnail${post['id']}" width="${post["thumb_width"]}" height="${post["thumb_height"]}">
|
||||
</a>
|
||||
</span>
|
||||
<div id="embed${post['id']}" class="thumb" style="display: none;"></div>
|
||||
<script type="text/javascript">
|
||||
$("#tiembed${post['id']}, #exembed${post['id']}").click(function(){
|
||||
showEmbed('${post['id']}', '$embed');
|
||||
return false;
|
||||
});
|
||||
</script>
|
||||
EOF;
|
||||
} else if ($post["file"] != "") {
|
||||
$return .= <<<EOF
|
||||
<br>
|
||||
<span class="filesize"><a href="src/${post["file"]}">${post["file"]}</a>–(${post["file_size_formatted"]}, ${post["image_width"]}x${post["image_height"]}, ${post["file_original"]})</span>
|
||||
<br>
|
||||
<a target="_blank" href="src/${post["file"]}">
|
||||
<span id="thumb${post["id"]}"><img src="thumb/${post["thumb"]}" alt="${post["id"]}" class="thumb" width="${post["thumb_width"]}" height="${post["thumb_height"]}"></span>
|
||||
</a>
|
||||
EOF;
|
||||
}
|
||||
$return .= $filehtml;
|
||||
}
|
||||
|
||||
if ($post['parent'] == TINYIB_NEWTHREAD && $res == TINYIB_INDEXPAGE) {
|
||||
|
8
js/jquery.js
vendored
8
js/jquery.js
vendored
File diff suppressed because one or more lines are too long
44
js/tinyib.js
44
js/tinyib.js
@ -5,7 +5,7 @@ function getCookie(name) {
|
||||
}
|
||||
|
||||
function quotePost(postID) {
|
||||
$("#message").val('>>' + postID + "\n").focus();
|
||||
$("#message").val($("#message").val() + '>>' + postID + "\n").focus();
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -17,18 +17,26 @@ function reloadCAPTCHA() {
|
||||
return false;
|
||||
}
|
||||
|
||||
function showEmbed(id, embedhtml){
|
||||
if($("#thumbembed"+ id).attr('expanded') != 'true') {
|
||||
$("#thumbembed"+ id).hide();
|
||||
$("#embed"+ id).show();
|
||||
$("#embed"+ id).html(embedhtml);
|
||||
$("#thumbembed"+ id).attr('expanded', 'true');
|
||||
}else{
|
||||
$("#embed"+ id).hide();
|
||||
$("#embed"+ id).html('');
|
||||
$("#thumbembed"+ id).show();
|
||||
$("#thumbembed"+ id).attr('expanded', 'false');
|
||||
function expandFile(e, id){
|
||||
if (e == undefined || e.which == undefined || e.which == 1) {
|
||||
if ($("#thumbfile" + id).attr('expanded') != 'true') {
|
||||
$("#thumbfile" + id).attr('expanded', 'true');
|
||||
$("#file" + id).html(decodeURIComponent($("#expand" + id).text())).css("visibility", "hidden");
|
||||
setTimeout(function (id) {
|
||||
return function () {
|
||||
$("#thumbfile" + id).hide();
|
||||
$("#file" + id).css("visibility", "visible").show();
|
||||
}
|
||||
}(id), 100);
|
||||
} else {
|
||||
$("#file" + id).hide().html('');
|
||||
$("#thumbfile" + id).show().attr('expanded', 'false').scrollintoview();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
$(function() {
|
||||
@ -65,3 +73,15 @@ $(function() {
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* jQuery scrollintoview() plugin and :scrollable selector filter
|
||||
*
|
||||
* Version 1.8 (14 Jul 2011)
|
||||
* Requires jQuery 1.4 or newer
|
||||
*
|
||||
* Copyright (c) 2011 Robert Koritnik
|
||||
* Licensed under the terms of the MIT license
|
||||
* http://www.opensource.org/licenses/mit-license.php
|
||||
*/
|
||||
(function(f){var c={vertical:{x:false,y:true},horizontal:{x:true,y:false},both:{x:true,y:true},x:{x:true,y:false},y:{x:false,y:true}};var b={duration:"fast",direction:"both"};var e=/^(?:html)$/i;var g=function(k,j){j=j||(document.defaultView&&document.defaultView.getComputedStyle?document.defaultView.getComputedStyle(k,null):k.currentStyle);var i=document.defaultView&&document.defaultView.getComputedStyle?true:false;var h={top:(parseFloat(i?j.borderTopWidth:f.css(k,"borderTopWidth"))||0),left:(parseFloat(i?j.borderLeftWidth:f.css(k,"borderLeftWidth"))||0),bottom:(parseFloat(i?j.borderBottomWidth:f.css(k,"borderBottomWidth"))||0),right:(parseFloat(i?j.borderRightWidth:f.css(k,"borderRightWidth"))||0)};return{top:h.top,left:h.left,bottom:h.bottom,right:h.right,vertical:h.top+h.bottom,horizontal:h.left+h.right}};var d=function(h){var j=f(window);var i=e.test(h[0].nodeName);return{border:i?{top:0,left:0,bottom:0,right:0}:g(h[0]),scroll:{top:(i?j:h).scrollTop(),left:(i?j:h).scrollLeft()},scrollbar:{right:i?0:h.innerWidth()-h[0].clientWidth,bottom:i?0:h.innerHeight()-h[0].clientHeight},rect:(function(){var k=h[0].getBoundingClientRect();return{top:i?0:k.top,left:i?0:k.left,bottom:i?h[0].clientHeight:k.bottom,right:i?h[0].clientWidth:k.right}})()}};f.fn.extend({scrollintoview:function(j){j=f.extend({},b,j);j.direction=c[typeof(j.direction)==="string"&&j.direction.toLowerCase()]||c.both;var n="";if(j.direction.x===true){n="horizontal"}if(j.direction.y===true){n=n?"both":"vertical"}var l=this.eq(0);var i=l.closest(":scrollable("+n+")");if(i.length>0){i=i.eq(0);var m={e:d(l),s:d(i)};var h={top:m.e.rect.top-(m.s.rect.top+m.s.border.top),bottom:m.s.rect.bottom-m.s.border.bottom-m.s.scrollbar.bottom-m.e.rect.bottom,left:m.e.rect.left-(m.s.rect.left+m.s.border.left),right:m.s.rect.right-m.s.border.right-m.s.scrollbar.right-m.e.rect.right};var k={};if(j.direction.y===true){if(h.top<0){k.scrollTop=m.s.scroll.top+h.top}else{if(h.top>0&&h.bottom<0){k.scrollTop=m.s.scroll.top+Math.min(h.top,-h.bottom)}}}if(j.direction.x===true){if(h.left<0){k.scrollLeft=m.s.scroll.left+h.left}else{if(h.left>0&&h.right<0){k.scrollLeft=m.s.scroll.left+Math.min(h.left,-h.right)}}}if(!f.isEmptyObject(k)){if(e.test(i[0].nodeName)){i=f("html,body")}i.animate(k,j.duration).eq(0).queue(function(o){f.isFunction(j.complete)&&j.complete.call(i[0]);o()})}else{f.isFunction(j.complete)&&j.complete.call(i[0])}}return this}});var a={auto:true,scroll:true,visible:false,hidden:false};f.extend(f.expr[":"],{scrollable:function(k,i,n,h){var m=c[typeof(n[3])==="string"&&n[3].toLowerCase()]||c.both;var l=(document.defaultView&&document.defaultView.getComputedStyle?document.defaultView.getComputedStyle(k,null):k.currentStyle);var o={x:a[l.overflowX.toLowerCase()]||false,y:a[l.overflowY.toLowerCase()]||false,isRoot:e.test(k.nodeName)};if(!o.x&&!o.y&&!o.isRoot){return false}var j={height:{scroll:k.scrollHeight,client:k.clientHeight},width:{scroll:k.scrollWidth,client:k.clientWidth},scrollableX:function(){return(o.x||o.isRoot)&&this.width.scroll>this.width.client},scrollableY:function(){return(o.y||o.isRoot)&&this.height.scroll>this.height.client}};return m.y&&j.scrollableY()||m.x&&j.scrollableX()}})})(jQuery);
|
||||
|
Loading…
x
Reference in New Issue
Block a user