summaryrefslogtreecommitdiff
path: root/inc/lib/webm/posthandler.php
diff options
context:
space:
mode:
authorczaks <marcin@6irc.net>2014-04-06 21:21:17 +0200
committerczaks <marcin@6irc.net>2014-04-06 21:21:17 +0200
commit781fde7789e27bf35033bfbea740d56426b4d251 (patch)
tree6bfd86bd6d5681a001c3f3b8803c0698c8244a6f /inc/lib/webm/posthandler.php
parent0ac459d0767ffff58aa05b656ac9e0949ef32432 (diff)
move php files to a more sane directory
Diffstat (limited to 'inc/lib/webm/posthandler.php')
-rw-r--r--inc/lib/webm/posthandler.php49
1 files changed, 49 insertions, 0 deletions
diff --git a/inc/lib/webm/posthandler.php b/inc/lib/webm/posthandler.php
new file mode 100644
index 00000000..50adbe80
--- /dev/null
+++ b/inc/lib/webm/posthandler.php
@@ -0,0 +1,49 @@
+<?php
+// Glue code for handling a Tinyboard post.
+// Portions of this file are derived from Tinyboard code.
+
+function postHandler($post) {
+ global $board, $config;
+
+ if ($post->has_file && $post->extension == 'webm') {
+ require_once dirname(__FILE__) . '/videodata.php';
+ $videoDetails = videoData($post->file_path);
+ if (!isset($videoDetails['container']) || $videoDetails['container'] != 'webm') return "not a WebM file";
+
+ // Set thumbnail
+ $thumbName = $board['dir'] . $config['dir']['thumb'] . $post->file_id . '.webm';
+ if ($config['spoiler_images'] && isset($_POST['spoiler'])) {
+ // Use spoiler thumbnail
+ $post->thumb = 'spoiler';
+ $size = @getimagesize($config['spoiler_image']);
+ $post->thumbwidth = $size[0];
+ $post->thumbheight = $size[1];
+ } elseif (isset($videoDetails['frame']) && $thumbFile = fopen($thumbName, 'wb')) {
+ // Use single frame from video as pseudo-thumbnail
+ fwrite($thumbFile, $videoDetails['frame']);
+ fclose($thumbFile);
+ $post->thumb = $post->file_id . '.webm';
+ } else {
+ // Fall back to file thumbnail
+ $post->thumb = 'file';
+ }
+ unset($videoDetails['frame']);
+
+ // Set width and height
+ if (isset($videoDetails['width']) && isset($videoDetails['height'])) {
+ $post->width = $videoDetails['width'];
+ $post->height = $videoDetails['height'];
+ if ($post->thumb != 'file' && $post->thumb != 'spoiler') {
+ $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) {
+ $post->thumbwidth = min($thumbMaxWidth, intval(round($videoDetails['width'] * $thumbMaxHeight / $videoDetails['height'])));
+ $post->thumbheight = min($thumbMaxHeight, intval(round($videoDetails['height'] * $thumbMaxWidth / $videoDetails['width'])));
+ } else {
+ $post->thumbwidth = $videoDetails['width'];
+ $post->thumbheight = $videoDetails['height'];
+ }
+ }
+ }
+ }
+}