diff options
| author | czaks <marcin@6irc.net> | 2014-04-06 21:16:42 +0200 |
|---|---|---|
| committer | czaks <marcin@6irc.net> | 2014-04-06 21:16:42 +0200 |
| commit | 71a4a9296c6895b4d81e8046924c041047a5a4bd (patch) | |
| tree | 7a1fe57f1c6d752233be14945c7fa91e96ca17f8 /containerchan/posthandler.php | |
| parent | 5bdccc29c9ce08fbb1e8cd720ec96964c63a1d92 (diff) | |
| parent | 9e0a09566687ce83e79a2cd0c5a446b405e3c663 (diff) | |
Merge ../containerchan into containerchan-integration
Diffstat (limited to 'containerchan/posthandler.php')
| -rw-r--r-- | containerchan/posthandler.php | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/containerchan/posthandler.php b/containerchan/posthandler.php new file mode 100644 index 00000000..50adbe80 --- /dev/null +++ b/containerchan/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']; + } + } + } + } +} |
