2013-11-09 04:11:22 -05:00
|
|
|
<?php
|
2014-03-19 19:04:23 -04:00
|
|
|
// Glue code for handling a Tinyboard post.
|
|
|
|
// Portions of this file are derived from Tinyboard code.
|
2013-11-09 04:11:22 -05:00
|
|
|
function postHandler($post) {
|
|
|
|
global $board, $config;
|
2015-08-10 21:15:21 -04:00
|
|
|
if ($post->has_file) foreach ($post->files as &$file) if ($file->extension == 'webm' || $file->extension == 'mp4') {
|
2014-09-15 19:34:36 -04:00
|
|
|
if ($config['webm']['use_ffmpeg']) {
|
|
|
|
require_once dirname(__FILE__) . '/ffmpeg.php';
|
|
|
|
$webminfo = get_webm_info($file->file_path);
|
|
|
|
if (empty($webminfo['error'])) {
|
|
|
|
$file->width = $webminfo['width'];
|
|
|
|
$file->height = $webminfo['height'];
|
|
|
|
if ($config['spoiler_images'] && isset($_POST['spoiler'])) {
|
|
|
|
$file = webm_set_spoiler($file);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$file = set_thumbnail_dimensions($post, $file);
|
|
|
|
$tn_path = $board['dir'] . $config['dir']['thumb'] . $file->file_id . '.jpg';
|
2015-08-10 21:15:21 -04:00
|
|
|
if(0 == make_webm_thumbnail($file->file_path, $tn_path, $file->thumbwidth, $file->thumbheight, $webminfo['duration'])) {
|
2014-09-15 19:34:36 -04:00
|
|
|
$file->thumb = $file->file_id . '.jpg';
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$file->thumb = 'file';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return $webminfo['error']['msg'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2013-11-09 04:11:22 -05:00
|
|
|
require_once dirname(__FILE__) . '/videodata.php';
|
2014-04-29 15:18:37 -04:00
|
|
|
$videoDetails = videoData($file->file_path);
|
2013-12-09 08:36:26 -05:00
|
|
|
if (!isset($videoDetails['container']) || $videoDetails['container'] != 'webm') return "not a WebM file";
|
2013-11-09 04:11:22 -05:00
|
|
|
// Set thumbnail
|
2014-04-29 15:18:37 -04:00
|
|
|
$thumbName = $board['dir'] . $config['dir']['thumb'] . $file->file_id . '.webm';
|
2013-11-09 04:11:22 -05:00
|
|
|
if ($config['spoiler_images'] && isset($_POST['spoiler'])) {
|
|
|
|
// Use spoiler thumbnail
|
2014-09-15 19:34:36 -04:00
|
|
|
$file = webm_set_spoiler($file);
|
2013-11-09 04:11:22 -05:00
|
|
|
} elseif (isset($videoDetails['frame']) && $thumbFile = fopen($thumbName, 'wb')) {
|
|
|
|
// Use single frame from video as pseudo-thumbnail
|
|
|
|
fwrite($thumbFile, $videoDetails['frame']);
|
|
|
|
fclose($thumbFile);
|
2014-04-29 15:18:37 -04:00
|
|
|
$file->thumb = $file->file_id . '.webm';
|
2013-11-09 04:11:22 -05:00
|
|
|
} else {
|
|
|
|
// Fall back to file thumbnail
|
2014-04-29 15:18:37 -04:00
|
|
|
$file->thumb = 'file';
|
2013-11-09 04:11:22 -05:00
|
|
|
}
|
|
|
|
unset($videoDetails['frame']);
|
|
|
|
// Set width and height
|
|
|
|
if (isset($videoDetails['width']) && isset($videoDetails['height'])) {
|
2014-04-29 15:18:37 -04:00
|
|
|
$file->width = $videoDetails['width'];
|
|
|
|
$file->height = $videoDetails['height'];
|
|
|
|
if ($file->thumb != 'file' && $file->thumb != 'spoiler') {
|
2014-09-15 19:34:36 -04:00
|
|
|
$file = set_thumbnail_dimensions($post, $file);
|
2013-11-09 04:11:22 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-09-15 19:34:36 -04:00
|
|
|
function set_thumbnail_dimensions($post,$file) {
|
|
|
|
global $board, $config;
|
|
|
|
$tn_dimensions = array();
|
|
|
|
$tn_maxw = $post->op ? $config['thumb_op_width'] : $config['thumb_width'];
|
|
|
|
$tn_maxh = $post->op ? $config['thumb_op_height'] : $config['thumb_height'];
|
|
|
|
if ($file->width > $tn_maxw || $file->height > $tn_maxh) {
|
|
|
|
$file->thumbwidth = min($tn_maxw, intval(round($file->width * $tn_maxh / $file->height)));
|
|
|
|
$file->thumbheight = min($tn_maxh, intval(round($file->height * $tn_maxw / $file->width)));
|
|
|
|
} else {
|
|
|
|
$file->thumbwidth = $file->width;
|
|
|
|
$file->thumbheight = $file->height;
|
|
|
|
}
|
|
|
|
return $file;
|
|
|
|
}
|
|
|
|
function webm_set_spoiler($file) {
|
|
|
|
global $board, $config;
|
|
|
|
$file->thumb = 'spoiler';
|
|
|
|
$size = @getimagesize($config['spoiler_image']);
|
|
|
|
$file->thumbwidth = $size[0];
|
|
|
|
$file->thumbheight = $size[1];
|
|
|
|
return $file;
|
|
|
|
}
|