Switched to embedding using full URL instead of code, added support for specifying the start time of the video
This commit is contained in:
parent
e89a356b1d
commit
5ff1203914
|
@ -173,6 +173,7 @@ CREATE TABLE `PREFIX_embeds` (
|
|||
`filetype` varchar(3) NOT NULL,
|
||||
`name` varchar(255) NOT NULL,
|
||||
`videourl` varchar(510) NOT NULL,
|
||||
`timeprefix` varchar(10) NULL DEFAULT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=KU_DBCHARSET COLLATE=KU_COLLATION;
|
||||
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
ALTER TABLE `embeds`
|
||||
ADD COLUMN `timeprefix` VARCHAR(10) NULL;
|
||||
|
||||
UPDATE `embeds` SET `timeprefix`='&t=' WHERE `filetype`='you';
|
||||
UPDATE `embeds` SET `timeprefix`='#t=' WHERE `filetype`='vim';
|
|
@ -2893,4 +2893,11 @@ figure .post-menu {
|
|||
}
|
||||
.spoiler-cover:hover div {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.site-indicator {
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
vertical-align: middle;
|
||||
margin-left: 4px;
|
||||
}
|
|
@ -186,7 +186,7 @@
|
|||
</figcaption>
|
||||
{else}
|
||||
<div class="embed-wrap">
|
||||
<div class="emb-iframe-wrapper" data-w="{$embed.image_w}" data-h="{$embed.image_h}" data-code="{$embed.file}" data-site="{$embed.site_name}"></div>
|
||||
<div class="emb-iframe-wrapper" data-w="{$embed.image_w}" data-h="{$embed.image_h}" data-code="{$embed.file}" data-site="{$embed.site_name}"{if $embed.start} data-start="{$embed.start}" data-startraw="{$embed.file_size}"{/if}></div>
|
||||
<div class="embed-overlay"></div>
|
||||
<img class="embed-thumbnail" src="{$file_path}/thumb/{$embed.thumbnail}" alt="">
|
||||
<div class="embed-title">
|
||||
|
|
|
@ -135,11 +135,7 @@
|
|||
<td>
|
||||
{for embcnt 1 $board.maxfiles}
|
||||
<div class="multiembedwrap" data-pos="embed-{$embcnt}">
|
||||
<input type="text" name="embed[]" placeholder="{t}Embed{/t}" size="28" maxlength="75" accesskey="e" /> <select name="embedtype[]">
|
||||
{foreach name=embed from=$board.embeds_allowed item=embed}
|
||||
<option value="{$embed.filetype}">{$embed.name}</option>
|
||||
{/foreach}
|
||||
</select>
|
||||
<input type="text" name="embed[]" placeholder="{t}Embed{/t}" size="28" maxlength="75" accesskey="e" />
|
||||
<label class="icon-checkbox-wrap" title="{t}Spoiler{/t}" for="embed-spoiler-{$embcnt-1}">
|
||||
<input type="checkbox" name="embed-spoiler-{$embcnt-1}" id="embed-spoiler-{$embcnt-1}" value="1">
|
||||
<span class="icon-with-fallback">
|
||||
|
|
|
@ -579,6 +579,16 @@ class Board {
|
|||
$embed['thumbnail'] = $embed['file_type'].'-'.$embed['file'].'-s.jpg';
|
||||
$embed['site_name'] = $embed_site['name'];
|
||||
$embed['videourl'] = $embed_site['videourl'].$embed['file'];
|
||||
if ($embed['file_size'] > 0) {
|
||||
$h = floor($embed['file_size'] / 3600);
|
||||
if ($h) $time .= $h.'h';
|
||||
$m = floor(($embed['file_size'] / 60) % 60);
|
||||
if ($m) $time .= $m.'m';
|
||||
$s = $embed['file_size'] % 60;
|
||||
if ($s) $time .= $s.'s';
|
||||
$embed['start'] = $time;
|
||||
$embed['videourl'] .= $embed_site['timeprefix'].$time;
|
||||
}
|
||||
}
|
||||
if ($embed['file_type'] == 'mp3' && $this->board['loadbalanceurl'] == '') {
|
||||
require_once(KU_ROOTDIR . 'lib/getid3/getid3.php');
|
||||
|
@ -1138,7 +1148,7 @@ class Post extends Board {
|
|||
//image_h
|
||||
intval($attachment['imgHeight']),
|
||||
//file_size
|
||||
($is_embed ? null : $attachment['file_size']),
|
||||
($is_embed ? $attachment['start'] : $attachment['file_size']),
|
||||
//file_size_formatted
|
||||
(($is_embed || $attachment['is_duplicate']) ? $attachment['file_size_formatted'] : ConvertBytes($attachment['size'])),
|
||||
//thumb_w
|
||||
|
|
|
@ -116,14 +116,14 @@ class Upload {
|
|||
// 2) Collect embeds
|
||||
$embed_hashes = array();
|
||||
if (is_array($_POST['embed']) || is_object($_POST['embed'])) {
|
||||
foreach($_POST['embed'] as $i => $code) {
|
||||
foreach($_POST['embed'] as $i => $url) {
|
||||
list($site, $code, $time) = $this->ParseEmbed($url);
|
||||
if ($code != '') {
|
||||
if (array_key_exists($_POST['embedtype'][$i], $board_class->board['embeds_allowed_assoc'])) {
|
||||
$embed_filetype = $_POST['embedtype'][$i];
|
||||
$hash = md5($embed_filetype.'/'.$code);
|
||||
if (array_key_exists($site, $board_class->board['embeds_allowed_assoc'])) {
|
||||
$hash = md5($site.'/'.$code);
|
||||
if (in_array($hash, $embed_hashes)) {
|
||||
$this->exitWithUploadErrorPage(_gettext('Duplicate embed entry detected.'),
|
||||
$atype, $i, $embed_filetype . '/' . $code);
|
||||
$atype, $i, $site . '/' . $code);
|
||||
}
|
||||
else {
|
||||
$embed_hashes []= $hash;
|
||||
|
@ -131,14 +131,16 @@ class Upload {
|
|||
$attachments []= array(
|
||||
'attachmenttype' => 'embed',
|
||||
'spoiler' => $_POST['embed-spoiler-'.$i] || '0',
|
||||
'embedtype' => $embed_filetype,
|
||||
'embedtype' => $site,
|
||||
'embedtime' => $time,
|
||||
'embed' => $code,
|
||||
'filetype_withoutdot' => $embed_filetype,
|
||||
'file_md5' => $hash
|
||||
'filetype_withoutdot' => $site,
|
||||
'file_md5' => $hash,
|
||||
'start' => $time
|
||||
);
|
||||
}
|
||||
else $this->exitWithUploadErrorPage(_gettext('Sorry, that filetype is not allowed on this board.'),
|
||||
$atype, $i, $_POST['embedtype'][$i] . '/' . $code);
|
||||
$atype, $i, $site . '/' . $code);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -155,6 +157,34 @@ class Upload {
|
|||
$this->attachments = $attachments;
|
||||
}
|
||||
|
||||
function ParseEmbed($url) {
|
||||
$sites = array(
|
||||
'you' => "/(?:youtu(?:\.be|be\.com)\/(?:.*v(?:\/|=)|(?:.*\/)?)(?P<code>[\w'-]+))(?:[?#&]t=(?:(?P<h>[0-9]{1,2})h)?(?:(?P<m>[0-9]{1,2})m)?(?:(?P<s>[0-9]{1,2})s)?)?/i",
|
||||
'vim' => "/[\w\W]*vimeo\.com\/(?:.*?)(?P<code>[0-9]+)(?:#t=(?:(?P<h>[0-9]{1,2})h)?(?:(?P<m>[0-9]{1,2})m)?(?:(?P<s>[0-9]{1,2})s)?)?/i",
|
||||
'cob' => "/[\w\W]*coub\.com\/view\/(?P<code>[\w\W]*)[\w\W]*/i"
|
||||
);
|
||||
foreach ($sites as $s => $rx) {
|
||||
preg_match($rx, $url, $matches);
|
||||
if ($matches) {
|
||||
$time = 0;
|
||||
$code = $matches['code'];
|
||||
$site = $s;
|
||||
foreach(array('h', 'm', 's') as $u) {
|
||||
$t = (int)$matches[$u];
|
||||
if ($t > 0 && $t < 60) {
|
||||
if ($u == 'h')
|
||||
$t *= 60;
|
||||
if ($u != 's')
|
||||
$t *= 60;
|
||||
$time += $t;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return array($site, $code, $time);
|
||||
}
|
||||
|
||||
function HandleUpload() {
|
||||
global $tc_db, $board_class;
|
||||
|
||||
|
|
|
@ -1844,10 +1844,11 @@ function readyset() {
|
|||
});
|
||||
|
||||
$('input[name^=embed]').on('input', function() {
|
||||
let $this = $(this)
|
||||
$this.parent().find('.site-indicator').remove()
|
||||
var match = embedLinks.process($(this).val());
|
||||
if(match) {
|
||||
$(this).val(match.code)
|
||||
.parents('.multiembedwrap').find('[name^=embedtype]').val(match.site);
|
||||
$this.after(`<img src="${ku_boardspath}/images/site-logos/${match.site}.png" class="site-indicator">`)
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -2661,16 +2662,20 @@ function unwrapEmbed($fig) {
|
|||
$fig.addClass('unwrapped')
|
||||
let $iw = $fig.find('.emb-iframe-wrapper')
|
||||
if ($iw.data('h') > $iw.data('w'))
|
||||
$iw.addClass('vertical-video');
|
||||
$iw.addClass('vertical-video')
|
||||
$iw.css({
|
||||
paddingBottom: `${($iw.data('h')/$iw.data('w'))*100}%`
|
||||
})
|
||||
let code = $iw.data('code')
|
||||
, iframeOptions = `frameborder="0" scrolling="no" webkitallowfullscreen="" mozallowfullscreen="" allowfullscreen=""`
|
||||
if ($iw.data('site') == "Youtube")
|
||||
$iw.append(`<iframe src="https://www.youtube-nocookie.com/embed/${code}?autoplay=1" ${iframeOptions}></iframe>`)
|
||||
if ($iw.data('site') == "Vimeo")
|
||||
$iw.append(`<iframe src="//player.vimeo.com/video/${code}?badge=0&autoplay=1" ${iframeOptions}></iframe>`)
|
||||
if ($iw.data('site') == "Youtube") {
|
||||
let start = $iw.data('startraw')
|
||||
$iw.append(`<iframe src="https://www.youtube-nocookie.com/embed/${code}?autoplay=1${start ? `&start=${start}` : ''}" ${iframeOptions}></iframe>`)
|
||||
}
|
||||
if ($iw.data('site') == "Vimeo") {
|
||||
let start = $iw.data('start')
|
||||
$iw.append(`<iframe src="//player.vimeo.com/video/${code}?badge=0&autoplay=1${start ? `#t=${start}` : ''}" ${iframeOptions}></iframe>`)
|
||||
}
|
||||
if ($iw.data('site') == "Coub")
|
||||
$iw.append(`<iframe src="http://coub.com/embed/${code}?muted=false&autostart=true&originalSize=false&hideTopBar=false&noSiteButtons=false&startWithHD=false" ${iframeOptions}></iframe>`)
|
||||
let $ew = $fig.find('.embed-wrap')
|
||||
|
@ -2707,6 +2712,7 @@ function wrapEmbed($fig) {
|
|||
function resetForm(form) {
|
||||
let fields = form.querySelectorAll('input[type=text]:not([name=name]), input[type=file], textarea')
|
||||
Array.prototype.forEach.call(fields, field => field.value = null)
|
||||
Array.prototype.forEach.call(form.querySelectorAll('.site-indicator'), i => i.remove())
|
||||
}
|
||||
|
||||
var injector = {
|
||||
|
@ -3263,9 +3269,9 @@ var ffdata = {
|
|||
|
||||
var embedLinks = {
|
||||
sites: [
|
||||
{id: 'you', rx: /(?:youtu(?:\.be|be\.com)\/(?:.*v(?:\/|=)|(?:.*\/)?)([\w'-]+))/ },
|
||||
{id: 'vim', rx: /[\w\W]*vimeo\.com\/(?:.*?)([0-9]+)(?:.*)?/ },
|
||||
{id: 'cob', rx: /[\w\W]*coub\.com\/view\/([\w\W]*)[\w\W]*/ }
|
||||
{id: 'youtube', rx: /(?:youtu(?:\.be|be\.com)\/(?:.*v(?:\/|=)|(?:.*\/)?)([\w'-]+))/i },
|
||||
{id: 'vimeo', rx: /[\w\W]*vimeo\.com\/(?:.*?)([0-9]+)(?:.*)?/ },
|
||||
{id: 'coub', rx: /[\w\W]*coub\.com\/view\/([\w\W]*)[\w\W]*/ }
|
||||
],
|
||||
process: function(val) {
|
||||
var result = null;
|
||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue