leftypol/inc/lib/webm/posthandler.php

50 lines
2.4 KiB
PHP
Raw Normal View History

2013-11-09 09:11:22 +00:00
<?php
2014-03-19 23:04:23 +00:00
// Glue code for handling a Tinyboard post.
// Portions of this file are derived from Tinyboard code.
2013-11-09 09:11:22 +00:00
function postHandler($post) {
global $board, $config;
2014-04-29 19:18:37 +00:00
if ($post->has_file) foreach ($post->files as &$file) if ($file->extension == 'webm') {
2013-11-09 09:11:22 +00:00
require_once dirname(__FILE__) . '/videodata.php';
2014-04-29 19:18:37 +00:00
$videoDetails = videoData($file->file_path);
2013-12-09 13:36:26 +00:00
if (!isset($videoDetails['container']) || $videoDetails['container'] != 'webm') return "not a WebM file";
2013-11-09 09:11:22 +00:00
// Set thumbnail
2014-04-29 19:18:37 +00:00
$thumbName = $board['dir'] . $config['dir']['thumb'] . $file->file_id . '.webm';
2013-11-09 09:11:22 +00:00
if ($config['spoiler_images'] && isset($_POST['spoiler'])) {
// Use spoiler thumbnail
2014-04-29 19:18:37 +00:00
$file->thumb = 'spoiler';
2013-11-09 09:11:22 +00:00
$size = @getimagesize($config['spoiler_image']);
2014-04-29 19:18:37 +00:00
$file->thumbwidth = $size[0];
$file->thumbheight = $size[1];
2013-11-09 09:11:22 +00: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 19:18:37 +00:00
$file->thumb = $file->file_id . '.webm';
2013-11-09 09:11:22 +00:00
} else {
// Fall back to file thumbnail
2014-04-29 19:18:37 +00:00
$file->thumb = 'file';
2013-11-09 09:11:22 +00:00
}
unset($videoDetails['frame']);
// Set width and height
if (isset($videoDetails['width']) && isset($videoDetails['height'])) {
2014-04-29 19:18:37 +00:00
$file->width = $videoDetails['width'];
$file->height = $videoDetails['height'];
if ($file->thumb != 'file' && $file->thumb != 'spoiler') {
2013-11-09 09:11:22 +00:00
$thumbMaxWidth = $post->op ? $config['thumb_op_width'] : $config['thumb_width'];
$thumbMaxHeight = $post->op ? $config['thumb_op_height'] : $config['thumb_height'];
if ($videoDetails['width'] > $thumbMaxWidth || $videoDetails['height'] > $thumbMaxHeight) {
2014-04-29 19:18:37 +00:00
$file->thumbwidth = min($thumbMaxWidth, intval(round($videoDetails['width'] * $thumbMaxHeight / $videoDetails['height'])));
$file->thumbheight = min($thumbMaxHeight, intval(round($videoDetails['height'] * $thumbMaxWidth / $videoDetails['width'])));
2013-11-09 09:11:22 +00:00
} else {
2014-04-29 19:18:37 +00:00
$file->thumbwidth = $videoDetails['width'];
$file->thumbheight = $videoDetails['height'];
2013-11-09 09:11:22 +00:00
}
}
}
}
}