From 7f45f31aa82b87384fa09d8a7e8d074c78f703e0 Mon Sep 17 00:00:00 2001 From: fowr <89118232+perdedora@users.noreply.github.com> Date: Tue, 6 Aug 2024 11:49:51 -0300 Subject: [PATCH 1/5] fix: proper delete posts in a cyclical thread --- post.php | 41 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/post.php b/post.php index 0a0dd94a..98eb0a06 100644 --- a/post.php +++ b/post.php @@ -185,6 +185,41 @@ function strip_image_metadata(string $img_path): int { return $ret; } +/** + * Delete posts in a cyclical thread. + * + * @param string $boardUri The URI of the board. + * @param int $threadId The ID of the thread. + * @param int $cycleLimit The number of most recent posts to retain. + */ +function delete_cyclical_posts(string $boardUri, int $threadId, int $cycleLimit): void +{ + $query = prepare(sprintf(' + SELECT p.`id` + FROM ``posts_%s`` p + LEFT JOIN ( + SELECT `id` + FROM ``posts_%s`` + WHERE `thread` = :thread + ORDER BY `id` DESC + LIMIT :limit + ) recent_posts ON p.id = recent_posts.id + WHERE p.thread = :thread + AND recent_posts.id IS NULL', + $boardUri, $boardUri + )); + + $query->bindValue(':thread', $threadId, PDO::PARAM_INT); + $query->bindValue(':limit', $cycleLimit, PDO::PARAM_INT); + + $query->execute() or error(db_error($query)); + $ids = $query->fetchAll(PDO::FETCH_COLUMN); + + foreach ($ids as $id) { + deletePost($id, false); + } +} + /** * Method handling functions */ @@ -1282,11 +1317,7 @@ if (isset($_POST['delete'])) { // Handle cyclical threads if (!$post['op'] && isset($thread['cycle']) && $thread['cycle']) { - // Query is a bit weird due to "This version of MariaDB doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'" (MariaDB Ver 15.1 Distrib 10.0.17-MariaDB, for Linux (x86_64)) - $query = prepare(sprintf('DELETE FROM ``posts_%s`` WHERE `thread` = :thread AND `id` NOT IN (SELECT `id` FROM (SELECT `id` FROM ``posts_%s`` WHERE `thread` = :thread ORDER BY `id` DESC LIMIT :limit) i)', $board['uri'], $board['uri'])); - $query->bindValue(':thread', $post['thread']); - $query->bindValue(':limit', $config['cycle_limit'], PDO::PARAM_INT); - $query->execute() or error(db_error($query)); + delete_cyclical_posts($board['uri'], $post['thread'], $config['cycle_limit']); } if (isset($post['antispam_hash'])) { From d8391eb34ab19dd23211d53e751a753b0a6da9bc Mon Sep 17 00:00:00 2001 From: fowr <89118232+perdedora@users.noreply.github.com> Date: Mon, 12 Aug 2024 15:23:19 -0300 Subject: [PATCH 2/5] fixes #747 and also fix when loading next page on ukko wrong value. e.g >>thread_ --- js/show-backlinks.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/js/show-backlinks.js b/js/show-backlinks.js index fc3125db..4c12e572 100644 --- a/js/show-backlinks.js +++ b/js/show-backlinks.js @@ -53,9 +53,10 @@ onready(function(){ $('div.post.op').each(showBackLinks); $(document).on('new_post', function(e, post) { - showBackLinks.call(post); if ($(post).hasClass("op")) { $(post).find('div.post.reply').each(showBackLinks); + } else { + $(post).parent().find('div.post.reply').each(showBackLinks); } }); }); From 3e72171889e80c78c20c1e72e66ac253ce7af443 Mon Sep 17 00:00:00 2001 From: fowr <89118232+perdedora@users.noreply.github.com> Date: Mon, 12 Aug 2024 15:34:48 -0300 Subject: [PATCH 3/5] download original filename without javascript. --- templates/post/fileinfo.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/post/fileinfo.html b/templates/post/fileinfo.html index 80ddd2a6..ec490129 100644 --- a/templates/post/fileinfo.html +++ b/templates/post/fileinfo.html @@ -22,9 +22,9 @@ {% if config.show_filename and file.filename %} , {% if file.filename|length > config.max_filename_display %} - {{ file.filename|truncate_filename(config.max_filename_display)|e|bidi_cleanup }} + {{ file.filename|truncate_filename(config.max_filename_display)|e|bidi_cleanup }} {% else %} - {{ file.filename|e|bidi_cleanup }} + {{ file.filename|e|bidi_cleanup }} {% endif %} {% endif %} ) From d4b4cf5825ff120605f1450a5fb5cc69d6d9f56f Mon Sep 17 00:00:00 2001 From: fowr <89118232+perdedora@users.noreply.github.com> Date: Mon, 12 Aug 2024 15:35:16 -0300 Subject: [PATCH 4/5] script to expand original filename if truncated --- js/expand-filename.js | 53 +++++++++++++++++++++++++++++++++++++++++++ js/expand-too-long.js | 39 ------------------------------- 2 files changed, 53 insertions(+), 39 deletions(-) create mode 100644 js/expand-filename.js delete mode 100644 js/expand-too-long.js diff --git a/js/expand-filename.js b/js/expand-filename.js new file mode 100644 index 00000000..2f3ac0fd --- /dev/null +++ b/js/expand-filename.js @@ -0,0 +1,53 @@ +/* + * expand-filename.js + * https://github.com/vichan-devel/vichan/blob/master/js/expand-filename.js + * + * Released under the MIT license + * Copyright (c) 2024 Perdedora + * + * Usage: + * $config['additional_javascript'][] = 'js/expand-filename.js'; + * + */ + +function doFilename(element) { + const filenames = element.querySelectorAll('[data-truncate="true"]'); + filenames.forEach(filename => { + filename.addEventListener('mouseover', event => addHover(event.target)); + filename.addEventListener('mouseout', event => removeHover(event.target)); + }); +} + +function addHover(element) { + element.dataset.truncatedFilename = element.textContent; + element.textContent = element.download; +} + +function removeHover(element) { + element.textContent = element.dataset.truncatedFilename; + delete element.dataset.truncatedFilename; +} + +document.addEventListener('DOMContentLoaded', () => { + doFilename(document); + + // Create a MutationObserver to watch for new elements + const observer = new MutationObserver(mutationsList => { + mutationsList.forEach(mutation => { + if (mutation.type === 'childList') { + mutation.addedNodes.forEach(addedNode => { + if (addedNode.nodeType === Node.ELEMENT_NODE) { + // Apply `doFilename` to newly added elements + doFilename(addedNode); + } + }); + } + }); + }); + + // Start observing the document body for changes + observer.observe(document.body, { + childList: true, + subtree: true + }); +}); diff --git a/js/expand-too-long.js b/js/expand-too-long.js deleted file mode 100644 index bbadb5f1..00000000 --- a/js/expand-too-long.js +++ /dev/null @@ -1,39 +0,0 @@ -/* - * expand-too-long.js - * https://github.com/vichan-devel/vichan/blob/master/js/expand-too-long.js - * - * Released under the MIT license - * Copyright (c) 2013-2014 Marcin Ɓabanowski - * - * Usage: - * $config['additional_javascript'][] = 'js/jquery.min.js'; - * $config['additional_javascript'][] = 'js/expand-too-long.js'; - * - */ - -$(function() { - var do_expand = function() { - $(this).find('a').click(function(e) { - e.preventDefault(); - - var url = $(this).attr('href'); - var body = $(this).parents('.body'); - - $.ajax({ - url: url, - context: document.body, - success: function(data) { - var content = $(data).find('#'+url.split('#')[1]).parent().parent().find(".body").first().html(); - - body.html(content); - } - }); - }); - }; - - $('.toolong').each(do_expand); - - $(document).on("new_post", function(e, post) { - $(post).find('.toolong').each(do_expand) - }); -}); From b5a9dc4d1a1ce3173745e2e8e14ce37a25f689a3 Mon Sep 17 00:00:00 2001 From: Zankaria Date: Thu, 31 Oct 2024 14:47:11 +0100 Subject: [PATCH 5/5] bans.php: remove multiple return types for PHP 7.4 support --- inc/bans.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inc/bans.php b/inc/bans.php index 8ea3b921..931777a4 100644 --- a/inc/bans.php +++ b/inc/bans.php @@ -142,7 +142,7 @@ class Bans { return array($ipstart, $ipend); } - static public function findSingle(string $ip, int $ban_id, bool $require_ban_view): array|null { + static public function findSingle(string $ip, int $ban_id, bool $require_ban_view): ?array { /** * Use OR in the query to also garbage collect bans. Ideally we should move the whole GC procedure to a separate * script, but it will require a more important restructuring.