diff --git a/inc/config.php b/inc/config.php index 0566741d..e2cc2ebd 100644 --- a/inc/config.php +++ b/inc/config.php @@ -755,6 +755,13 @@ // Display the file's original filename. $config['show_filename'] = true; + // WebM Settings + $config['webm']['use_ffmpeg'] = false; + $config['webm']['allow_audio'] = false; + $config['webm']['max_length'] = 120; + $config['webm']['ffmpeg_path'] = 'ffmpeg'; + $config['webm']['ffprobe_path'] = 'ffprobe'; + // Display image identification links for ImgOps, regex.info/exif, Google Images and iqdb. $config['image_identification'] = false; // Which of the identification links to display. Only works if $config['image_identification'] is true. @@ -764,6 +771,9 @@ // Anime/manga search engine. $config['image_identification_iqdb'] = false; + // Set this to true if you're using a BSD + $config['bsd_md5'] = false; + // Number of posts in a "View Last X Posts" page $config['noko50_count'] = 50; // Number of posts a thread needs before it gets a "View Last X Posts" page. @@ -1036,6 +1046,10 @@ $config['error']['unknownext'] = _('Unknown file extension.'); $config['error']['filesize'] = _('Maximum file size: %maxsz% bytes
Your file\'s size: %filesz% bytes'); $config['error']['maxsize'] = _('The file was too big.'); + $config['error']['webmerror'] = _('There was a problem processing your webm.'); + $config['error']['invalidwebm'] = _('Invalid webm uploaded.'); + $config['error']['webmhasaudio'] = _('The uploaded webm contains an audio or another type of additional stream.'); + $config['error']['webmtoolong'] = _('The uploaded webm is longer than ' . $config['webm']['max_length'] . ' seconds.'); $config['error']['fileexists'] = _('That file already exists!'); $config['error']['fileexistsinthread'] = _('That file already exists in this thread!'); $config['error']['delete_too_soon'] = _('You\'ll have to wait another %s before deleting that.'); @@ -1043,6 +1057,7 @@ $config['error']['invalid_embed'] = _('Couldn\'t make sense of the URL of the video you tried to embed.'); $config['error']['captcha'] = _('You seem to have mistyped the verification.'); + // Moderator errors $config['error']['toomanyunban'] = _('You are only allowed to unban %s users at a time. You tried to unban %u users.'); $config['error']['invalid'] = _('Invalid username and/or password.'); diff --git a/inc/lib/webm/README.md b/inc/lib/webm/README.md index baa7a641..dc3394c9 100644 --- a/inc/lib/webm/README.md +++ b/inc/lib/webm/README.md @@ -20,6 +20,16 @@ Add these lines to inc/instance-config.php: $config['additional_javascript'][] = 'js/webm-settings.js'; $config['additional_javascript'][] = 'js/expand-video.js'; +If you have an [FFmpeg](https://www.ffmpeg.org/) binary on your server and you wish to generate real thumbnails (the webm thumbnails created with the original implementation reportedly cause users' browsers to crash), add the following to inc/instance-config.php as well: + + $config['webm']['use_ffmpeg'] = true; + + // If your ffmpeg binary isn't in your path you need to set these options + // as well. + + $config['webm']['ffmpeg_path'] = '/path/to/ffmeg'; + $config['webm']['ffprobe_path'] = '/path/to/ffprobe'; + License ------- diff --git a/inc/lib/webm/ffmpeg.php b/inc/lib/webm/ffmpeg.php new file mode 100644 index 00000000..edd2c73a --- /dev/null +++ b/inc/lib/webm/ffmpeg.php @@ -0,0 +1,62 @@ + 1, 'msg' => $config['error']['genwebmerror']); + + if ($ffprobe_out['format']['format_name'] != 'matroska,webm') + return array('code' => 2, 'msg' => $config['error']['invalidwebm']); + + if ((count($ffprobe_out['streams']) > 1) && (!$config['webm']['allow_audio'])) + return array('code' => 3, 'msg' => $config['error']['webmhasaudio']); + + if ($ffprobe_out['streams'][0]['codec_name'] != 'vp8') + return array('code' => 2, 'msg' => $config['error']['invalidwebm']); + + if (empty($ffprobe_out['streams'][0]['width']) || (empty($ffprobe_out['streams'][0]['height']))) + return array('code' => 2, 'msg' => $config['error']['invalidwebm']); + + if ($ffprobe_out['format']['duration'] > $config['webm']['max_length']) + return array('code' => 4, 'msg' => $config['error']['webmtoolong']); +} + +function make_webm_thumbnail($filename, $thumbnail, $width, $height) { + global $board, $config; + + $filename = escapeshellarg($filename); + $thumbnail = escapeshellarg($thumbnail); // Should be safe by default but you + // can never be too safe. + + $ffmpeg = $config['webm']['ffmpeg_path']; + $ffmpeg_out = array(); + + exec("$ffmpeg -i $filename -v quiet -ss 00:00:00 -an -vframes 1 -f mjpeg -vf scale=$width:$height $thumbnail 2>&1"); + + return count($ffmpeg_out); +} diff --git a/inc/lib/webm/posthandler.php b/inc/lib/webm/posthandler.php index 1f831f5a..308c7507 100644 --- a/inc/lib/webm/posthandler.php +++ b/inc/lib/webm/posthandler.php @@ -6,6 +6,34 @@ function postHandler($post) { global $board, $config; if ($post->has_file) foreach ($post->files as &$file) if ($file->extension == 'webm') { + 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'; + + if(empty(make_webm_thumbnail($file->file_path, $tn_path, $file->thumbwidth, $file->thumbheight))) { + $file->thumb = $file->file_id . '.jpg'; + } + else { + $file->thumb = 'file'; + } + } + } + else { + return $webminfo['error']['msg']; + } + } + else { require_once dirname(__FILE__) . '/videodata.php'; $videoDetails = videoData($file->file_path); if (!isset($videoDetails['container']) || $videoDetails['container'] != 'webm') return "not a WebM file"; @@ -14,10 +42,7 @@ function postHandler($post) { $thumbName = $board['dir'] . $config['dir']['thumb'] . $file->file_id . '.webm'; if ($config['spoiler_images'] && isset($_POST['spoiler'])) { // Use spoiler thumbnail - $file->thumb = 'spoiler'; - $size = @getimagesize($config['spoiler_image']); - $file->thumbwidth = $size[0]; - $file->thumbheight = $size[1]; + $file = webm_set_spoiler($file); } elseif (isset($videoDetails['frame']) && $thumbFile = fopen($thumbName, 'wb')) { // Use single frame from video as pseudo-thumbnail fwrite($thumbFile, $videoDetails['frame']); @@ -33,17 +58,40 @@ function postHandler($post) { if (isset($videoDetails['width']) && isset($videoDetails['height'])) { $file->width = $videoDetails['width']; $file->height = $videoDetails['height']; + if ($file->thumb != 'file' && $file->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) { - $file->thumbwidth = min($thumbMaxWidth, intval(round($videoDetails['width'] * $thumbMaxHeight / $videoDetails['height']))); - $file->thumbheight = min($thumbMaxHeight, intval(round($videoDetails['height'] * $thumbMaxWidth / $videoDetails['width']))); - } else { - $file->thumbwidth = $videoDetails['width']; - $file->thumbheight = $videoDetails['height']; + $file = set_thumbnail_dimensions($post, $file); } } } } } + +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; +} diff --git a/js/catalog.js b/js/catalog.js index 4a4eae37..768845f6 100644 --- a/js/catalog.js +++ b/js/catalog.js @@ -7,12 +7,9 @@ if (active_page == 'catalog') $(function(){ $("#image_size").change(function(){ var value = this.value, old; - if (value == "small") { - old = "large"; - } else { - old = "small"; - } - $(".grid-li").removeClass("grid-size-"+old); + $(".grid-li").removeClass("grid-size-vsmall"); + $(".grid-li").removeClass("grid-size-small"); + $(".grid-li").removeClass("grid-size-large"); $(".grid-li").addClass("grid-size-"+value); }); diff --git a/js/expand-video.js b/js/expand-video.js index 76a2018e..79872510 100644 --- a/js/expand-video.js +++ b/js/expand-video.js @@ -218,7 +218,8 @@ function setupVideosIn(element) { onready(function(){ // Insert menu from settings.js - if (typeof settingsMenu != "undefined") document.body.insertBefore(settingsMenu, document.getElementsByTagName("hr")[0]); + if (typeof settingsMenu != "undefined" && typeof Options == "undefined") + document.body.insertBefore(settingsMenu, document.getElementsByTagName("hr")[0]); // Setup Javascript events for videos in document now setupVideosIn(document); diff --git a/js/options.js b/js/options.js new file mode 100644 index 00000000..4a7f3ce9 --- /dev/null +++ b/js/options.js @@ -0,0 +1,126 @@ +/* + * options.js - allow users choose board options as they wish + * + * Copyright (c) 2014 Marcin Łabanowski + * + * Usage: + * $config['additional_javascript'][] = 'js/jquery.min.js'; + * $config['additional_javascript'][] = 'js/options.js'; + */ + ++function(){ + +var options_button, options_handler, options_background, options_div + , options_close, options_tablist, options_tabs, options_current_tab; + +var Options = {}; +window.Options = Options; + +var first_tab = function() { + for (var i in options_tabs) { + return i; + } + return false; +}; + +Options.show = function() { + if (!options_current_tab) { + Options.select_tab(first_tab(), true); + } + options_handler.fadeIn(); +}; +Options.hide = function() { + options_handler.fadeOut(); +}; + +options_tabs = {}; + +Options.add_tab = function(id, icon, name, content) { + var tab = {}; + + if (typeof content == "string") { + content = $("
"+content+"
"); + } + + tab.id = id; + tab.name = name; + tab.icon = $("
"+name+"
"); + tab.content = $("
").css("display", "none"); + + tab.content.appendTo(options_div); + + tab.icon.on("click", function() { + Options.select_tab(id); + }).appendTo(options_tablist); + + $("

"+name+"

").appendTo(tab.content); + + if (content) { + content.appendTo(tab.content); + } + + options_tabs[id] = tab; + + return tab; +}; + +Options.get_tab = function(id) { + return options_tabs[id]; +}; + +Options.extend_tab = function(id, content) { + if (typeof content == "string") { + content = $("
"+content+"
"); + } + + content.appendTo(options_tabs[id].content); + + return options_tabs[id]; +}; + +Options.select_tab = function(id, quick) { + if (options_current_tab) { + if (options_current_tab.id == id) { + return false; + } + options_current_tab.content.fadeOut(); + options_current_tab.icon.removeClass("active"); + } + var tab = options_tabs[id]; + options_current_tab = tab; + options_current_tab.icon.addClass("active"); + tab.content[quick? "show" : "fadeIn"](); + + return tab; +}; + +options_handler = $("
").css("display", "none"); +options_background = $("
").on("click", Options.hide).appendTo(options_handler); +options_div = $("
").appendTo(options_handler); +options_close = $("") + .on("click", Options.hide).appendTo(options_div); +options_tablist = $("
").appendTo(options_div); + + +$(function(){ + options_button = $("
["+_("Options")+"]").css("float", "right"); + + if ($(".boardlist.compact-boardlist").length) { + options_button.addClass("cb-item cb-fa").html(""); + } + + if ($(".boardlist:first").length) { + options_button.appendTo($(".boardlist:first")); + } + else { + options_button.prependTo($(document.body)); + } + + options_button.on("click", Options.show); + + options_handler.appendTo($(document.body)); +}); + + + +}(); diff --git a/js/options/general.js b/js/options/general.js new file mode 100644 index 00000000..f95ba04f --- /dev/null +++ b/js/options/general.js @@ -0,0 +1,44 @@ +/* + * options/general.js - general settings tab for options panel + * + * Copyright (c) 2014 Marcin Łabanowski + * + * Usage: + * $config['additional_javascript'][] = 'js/jquery.min.js'; + * $config['additional_javascript'][] = 'js/options.js'; + * $config['additional_javascript'][] = 'js/style-select.js'; + * $config['additional_javascript'][] = 'js/options/general.js'; + */ + ++function(){ + +var tab = Options.add_tab("general", "home", _("General")); + +$(function(){ + var stor = $("
"+_("Storage: ")+"
"); + stor.appendTo(tab.content); + + $("").appendTo(stor).on("click", function() { + var str = JSON.stringify(localStorage); + + $(".output").remove(); + $("").appendTo(stor).val(str); + }); + $("").appendTo(stor).on("click", function() { + var str = prompt(_("Paste your storage data")); + if (!str) return false; + var obj = JSON.parse(str); + if (!obj) return false; + + localStorage.clear(); + for (var i in obj) { + localStorage[i] = obj[i]; + } + + document.location.reload(); + }); + + $("#style-select").detach().css({float:"none","margin-bottom":0}).appendTo(tab.content); +}); + +}(); diff --git a/js/watch.js b/js/watch.js index 4c36dbc4..a202130f 100644 --- a/js/watch.js +++ b/js/watch.js @@ -107,6 +107,7 @@ $(function(){ var list = $("
"); list.attr("data-board", board); + if (storage()[board] && storage()[board].threads) for (var tid in storage()[board].threads) { var newposts = "(0)"; if (status && status[board] && status[board].threads && status[board].threads[tid]) { diff --git a/js/webm-settings.js b/js/webm-settings.js index 3e792741..bd3c6f0f 100644 --- a/js/webm-settings.js +++ b/js/webm-settings.js @@ -36,15 +36,25 @@ function changeSetting(name, value) { // Create settings menu var settingsMenu = document.createElement("div"); -settingsMenu.style.textAlign = "right"; -settingsMenu.style.background = "inherit"; +var prefix = "", suffix = "", style = ""; +if (window.Options) { + var tab = Options.add_tab("webm", "video-camera", _("WebM")); + $(settingsMenu).appendTo(tab.content); +} +else { + prefix = ''+_('WebM Settings')+''; + settingsMenu.style.textAlign = "right"; + settingsMenu.style.background = "inherit"; + suffix = ''; + style = 'display: none; text-align: left; position: absolute; right: 1em; margin-left: -999em; margin-top: -1px; padding-top: 1px; background: inherit;'; +} -settingsMenu.innerHTML = ''+_('WebM Settings')+'' - + '
' +settingsMenu.innerHTML = prefix + + '
' + '
' + '
' + '
' - + '
'; + + suffix; function refreshSettings() { var settingsItems = settingsMenu.getElementsByTagName("input"); @@ -74,7 +84,7 @@ for (var i = 0; i < settingsItems.length; i++) { setupControl(settingsItems[i]); } -if (settingsMenu.addEventListener) { +if (settingsMenu.addEventListener && !window.Options) { settingsMenu.addEventListener("mouseover", function(e) { refreshSettings(); settingsMenu.getElementsByTagName("a")[0].style.fontWeight = "bold"; diff --git a/post.php b/post.php index dac28ea5..88189572 100644 --- a/post.php +++ b/post.php @@ -571,7 +571,9 @@ if (isset($_POST['delete'])) { error($config['error']['nomove']); } - if ($output = shell_exec_error("cat $filenames | md5sum")) { + $md5cmd = $config['bsd_md5'] ? 'md5 -r' : 'md5sum'; + + if ($output = shell_exec_error("cat $filenames | $md5cmd")) { $explodedvar = explode(' ', $output); $hash = $explodedvar[0]; $post['filehash'] = $hash; @@ -930,4 +932,3 @@ if (isset($_POST['delete'])) { error($config['error']['nopost']); } } - diff --git a/stylesheets/style.css b/stylesheets/style.css index 4e1c5f86..ffd26e7d 100644 --- a/stylesheets/style.css +++ b/stylesheets/style.css @@ -539,6 +539,17 @@ pre { margin-left: -20px; } +.theme-catalog div.grid-size-vsmall img { + max-width: 100%; + max-height: 100px; +} + +.theme-catalog div.grid-size-vsmall { + width: 100px; + max-width: 100px; + max-height: 150px; +} + .theme-catalog div.grid-size-small { width: 200px; max-width: 200px; @@ -628,12 +639,6 @@ pre { vertical-align: middle; } -/* Containerchan */ - div.post video.post-image { - padding: 0; - margin: 5px 25px 5px 5px; - } - /* live-index.js */ .new-posts { opacity: 0.6; @@ -642,3 +647,76 @@ pre { .new-threads { text-align: center; } + +/* options.js */ +#options_handler { + position: fixed; + top: 0px; left: 0px; right: 0px; bottom: 0px; + width: 100%; height: 100%; + text-align: center; + z-index: 9900; +} +#options_background { + background: black; + opacity: 0.5; + position: absolute; + top: 0px; left: 0px; right: 0px; bottom: 0px; + width: 100%; height: 100%; + z-index: -1; +} +#options_div { + background-color: #d6daf0; + border: 1px solid black; + display: inline-block; + position: relative; + margin-top: 20px; + width: 600px; + height: 300px; +} +#options_close { + top: 0px; right: 0px; + position: absolute; + margin-right: 3px; + font-size: 20px; z-index: 100; +} +#options_tablist { + padding: 0px 5px; + left: 0px; + width: 70px; + top: 0px; + bottom: 0px; + height: 100%; + border-right: 1px solid black; +} +.options_tab_icon { + padding: 5px; + color: black; +} +.options_tab_icon.active { + color: red; +} +.options_tab_icon i { + font-size: 20px; +} +.options_tab_icon div { + font-size: 11px; +} +.options_tab { + padding: 10px; + position: absolute; + top: 0px; bottom: 0px; + left: 81px; right: 0px; + text-align: left; + font-size: 12px; +} +.options_tab h2 { + text-align: center; + margin-bottom: 5px; +} + +.mobile-style #options_div { + display: block; + width: 100%; + height: 100%; + margin-top: 0px; +} diff --git a/templates/themes/catalog/catalog.html b/templates/themes/catalog/catalog.html index 6dd683cf..db94e2a4 100644 --- a/templates/themes/catalog/catalog.html +++ b/templates/themes/catalog/catalog.html @@ -33,6 +33,7 @@ {% trans 'Image size' %}: diff --git a/templates/themes/catalog/theme.php b/templates/themes/catalog/theme.php index a9ad8ec1..9bb501c3 100644 --- a/templates/themes/catalog/theme.php +++ b/templates/themes/catalog/theme.php @@ -55,10 +55,29 @@ if (isset($post['files'])) { $files = json_decode($post['files']); - if ($files[0]->file == 'deleted') continue; + + if ($files[0]->file == 'deleted') { + if (count($files) > 1) { + foreach ($files as $file) { + if (($file == $files[0]) || ($file->file == 'deleted')) continue; + $post['file'] = $config['uri_thumb'] . $file->thumb; + } + + if (empty($post['file'])) $post['file'] = $config['image_deleted']; + } + else { + $post['file'] = $config['image_deleted']; + } + } + else if($files[0]->thumb == 'spoiler') { + $post['file'] = '/' . $config['spoiler_image']; + } + else { $post['file'] = $config['uri_thumb'] . $files[0]->thumb; } + } + if (empty($post['image_count'])) $post['image_count'] = 0; $recent_posts[] = $post; } diff --git a/templates/themes/recent/theme.php b/templates/themes/recent/theme.php index 842ab9ac..a25ff6a9 100644 --- a/templates/themes/recent/theme.php +++ b/templates/themes/recent/theme.php @@ -54,14 +54,27 @@ while ($post = $query->fetch(PDO::FETCH_ASSOC)) { openBoard($post['board']); + if (isset($post['files'])) $files = json_decode($post['files']); if ($files[0]->file == 'deleted') continue; // board settings won't be available in the template file, so generate links now - $post['link'] = $config['root'] . $board['dir'] . $config['dir']['res'] . sprintf($config['file_page'], ($post['thread'] ? $post['thread'] : $post['id'])) . '#' . $post['id']; - if ($files) $post['src'] = $config['uri_thumb'] . $files[0]->thumb; + $post['link'] = $config['root'] . $board['dir'] . $config['dir']['res'] + . sprintf($config['file_page'], ($post['thread'] ? $post['thread'] : $post['id'])) . '#' . $post['id']; + + if ($files) { + if ($files[0]->thumb == 'spoiler') { + $tn_size = @getimagesize($config['spoiler_image']); + $post['src'] = $config['spoiler_image']; + $post['thumbwidth'] = $tn_size[0]; + $post['thumbheight'] = $tn_size[1]; + } + else { + $post['src'] = $config['uri_thumb'] . $files[0]->thumb; + } + } $recent_images[] = $post; }