The version of vichan running on lainchan.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

98 line
3.3KB

  1. <?php
  2. // Glue code for handling a Tinyboard post.
  3. // Portions of this file are derived from Tinyboard code.
  4. function postHandler($post) {
  5. global $board, $config;
  6. if ($post->has_file) foreach ($post->files as &$file) if ($file->extension == 'webm') {
  7. if ($config['webm']['use_ffmpeg']) {
  8. require_once dirname(__FILE__) . '/ffmpeg.php';
  9. $webminfo = get_webm_info($file->file_path);
  10. if (empty($webminfo['error'])) {
  11. $file->width = $webminfo['width'];
  12. $file->height = $webminfo['height'];
  13. if ($config['spoiler_images'] && isset($_POST['spoiler'])) {
  14. $file = webm_set_spoiler($file);
  15. }
  16. else {
  17. $file = set_thumbnail_dimensions($post, $file);
  18. $tn_path = $board['dir'] . $config['dir']['thumb'] . $file->file_id . '.jpg';
  19. if(false == make_webm_thumbnail($file->file_path, $tn_path, $file->thumbwidth, $file->thumbheight)) {
  20. $file->thumb = $file->file_id . '.jpg';
  21. }
  22. else {
  23. $file->thumb = 'file';
  24. }
  25. }
  26. }
  27. else {
  28. return $webminfo['error']['msg'];
  29. }
  30. }
  31. else {
  32. require_once dirname(__FILE__) . '/videodata.php';
  33. $videoDetails = videoData($file->file_path);
  34. if (!isset($videoDetails['container']) || $videoDetails['container'] != 'webm') return "not a WebM file";
  35. // Set thumbnail
  36. $thumbName = $board['dir'] . $config['dir']['thumb'] . $file->file_id . '.webm';
  37. if ($config['spoiler_images'] && isset($_POST['spoiler'])) {
  38. // Use spoiler thumbnail
  39. $file = webm_set_spoiler($file);
  40. } elseif (isset($videoDetails['frame']) && $thumbFile = fopen($thumbName, 'wb')) {
  41. // Use single frame from video as pseudo-thumbnail
  42. fwrite($thumbFile, $videoDetails['frame']);
  43. fclose($thumbFile);
  44. $file->thumb = $file->file_id . '.webm';
  45. } else {
  46. // Fall back to file thumbnail
  47. $file->thumb = 'file';
  48. }
  49. unset($videoDetails['frame']);
  50. // Set width and height
  51. if (isset($videoDetails['width']) && isset($videoDetails['height'])) {
  52. $file->width = $videoDetails['width'];
  53. $file->height = $videoDetails['height'];
  54. if ($file->thumb != 'file' && $file->thumb != 'spoiler') {
  55. $file = set_thumbnail_dimensions($post, $file);
  56. }
  57. }
  58. }
  59. }
  60. }
  61. function set_thumbnail_dimensions($post,$file) {
  62. global $board, $config;
  63. $tn_dimensions = array();
  64. $tn_maxw = $post->op ? $config['thumb_op_width'] : $config['thumb_width'];
  65. $tn_maxh = $post->op ? $config['thumb_op_height'] : $config['thumb_height'];
  66. if ($file->width > $tn_maxw || $file->height > $tn_maxh) {
  67. $file->thumbwidth = min($tn_maxw, intval(round($file->width * $tn_maxh / $file->height)));
  68. $file->thumbheight = min($tn_maxh, intval(round($file->height * $tn_maxw / $file->width)));
  69. } else {
  70. $file->thumbwidth = $file->width;
  71. $file->thumbheight = $file->height;
  72. }
  73. return $file;
  74. }
  75. function webm_set_spoiler($file) {
  76. global $board, $config;
  77. $file->thumb = 'spoiler';
  78. $size = @getimagesize($config['spoiler_image']);
  79. $file->thumbwidth = $size[0];
  80. $file->thumbheight = $size[1];
  81. return $file;
  82. }