From 47afbc7f4335e9f0b76d3361e8afa3d6dd5063f6 Mon Sep 17 00:00:00 2001 From: Terranom674 Date: Wed, 19 Aug 2026 22:38:54 +0200 Subject: [PATCH 1/6] Fix watermark context for album overview covers --- include/watermark_runtime.inc.php | 68 ++++++++++++++++++++++++++++++- 1 file changed, 67 insertions(+), 1 deletion(-) diff --git a/include/watermark_runtime.inc.php b/include/watermark_runtime.inc.php index 97adee4..4e78c07 100644 --- a/include/watermark_runtime.inc.php +++ b/include/watermark_runtime.inc.php @@ -27,6 +27,72 @@ function bratonien_tools_runtime_category_id() return 0; } +function bratonien_tools_watermark_album_cover_category($src_image, $category_id=null) +{ + static $map = null; + + if ($map === null) + { + $map = new SplObjectStorage(); + } + + if (!is_object($src_image)) + { + return 0; + } + + if ($category_id !== null) + { + $category_id = (int)$category_id; + if ($category_id > 0) + { + $map[$src_image] = $category_id; + } + return $category_id; + } + + return $map->contains($src_image) ? (int)$map[$src_image] : 0; +} + +function bratonien_tools_watermark_prepare_album_overview($thumbnails) +{ + if (!is_array($thumbnails)) + { + return $thumbnails; + } + + foreach ($thumbnails as &$thumbnail) + { + $category_id = (int)($thumbnail['id'] ?? $thumbnail['ID'] ?? 0); + if ($category_id < 1 || empty($thumbnail['representative']['src_image']) || !is_object($thumbnail['representative']['src_image'])) + { + continue; + } + + // Ein Repraesentantenbild kann fuer mehrere Alben verwendet werden. Piwigo + // reicht in der Albumuebersicht aber nur das SrcImage an get_derivative_url + // weiter. Deshalb bekommt jedes Album-Cover eine eigene SrcImage-Instanz, + // damit seine konkrete Albumregel erhalten bleibt. + $src_image = clone $thumbnail['representative']['src_image']; + $thumbnail['representative']['src_image'] = $src_image; + bratonien_tools_watermark_album_cover_category($src_image, $category_id); + } + unset($thumbnail); + + return $thumbnails; +} + +function bratonien_tools_runtime_derivative_category_id($src_image) +{ + $category_id = bratonien_tools_runtime_category_id(); + if ($category_id > 0) + { + return $category_id; + } + + return bratonien_tools_watermark_album_cover_category($src_image); +} + function bratonien_tools_runtime_effective_rule($category_id) { static $categories = null; @@ -230,7 +296,7 @@ function bratonien_tools_filter_derivative_url($url, $params, $src_image, $rel_u return $url; } - $rule = bratonien_tools_runtime_effective_rule(bratonien_tools_runtime_category_id()); + $rule = bratonien_tools_runtime_effective_rule(bratonien_tools_runtime_derivative_category_id($src_image)); if ($rule['mode'] !== 'profile' || empty($rule['profile_id'])) { return $url; From 7d97e1b51545f407efaf37b9902be712429f2bb3 Mon Sep 17 00:00:00 2001 From: Terranom674 Date: Wed, 19 Aug 2026 22:39:08 +0200 Subject: [PATCH 2/6] Register album overview watermark context --- main.inc.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/main.inc.php b/main.inc.php index 5594c49..629c2bf 100644 --- a/main.inc.php +++ b/main.inc.php @@ -1,7 +1,7 @@ Date: Wed, 19 Aug 2026 22:41:20 +0200 Subject: [PATCH 3/6] Invalidate watermark cache on rule changes --- tools/watermark_settings.inc.php | 54 ++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/tools/watermark_settings.inc.php b/tools/watermark_settings.inc.php index cfa2948..4e29868 100644 --- a/tools/watermark_settings.inc.php +++ b/tools/watermark_settings.inc.php @@ -4,6 +4,59 @@ if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); } +function bratonien_tools_watermark_cache_dir() +{ + return PHPWG_ROOT_PATH.PWG_DERIVATIVE_DIR.'bratonien-watermark'; +} + +function bratonien_tools_remove_tree($path) +{ + $path = rtrim((string)$path, DIRECTORY_SEPARATOR); + if ($path === '' || !file_exists($path)) return; + + if (is_file($path) || is_link($path)) + { + @unlink($path); + return; + } + + foreach (scandir($path) ?: array() as $entry) + { + if ($entry === '.' || $entry === '..') continue; + bratonien_tools_remove_tree($path.DIRECTORY_SEPARATOR.$entry); + } + @rmdir($path); +} + +function bratonien_tools_clear_watermark_cache() +{ + $dir = bratonien_tools_watermark_cache_dir(); + $derivative_root = realpath(PHPWG_ROOT_PATH.PWG_DERIVATIVE_DIR); + $parent = realpath(dirname($dir)); + + if ($derivative_root === false || $parent === false || $parent !== $derivative_root) + { + throw new RuntimeException('Wasserzeichen-Cachepfad ist ungueltig.'); + } + + if (is_dir($dir)) + { + bratonien_tools_remove_tree($dir); + } +} + +function bratonien_tools_watermark_cache_upgrade() +{ + $version = '0.9.7.13'; + if ((string)conf_get_param('bratonien_watermark_cache_version', '') === $version) + { + return; + } + + bratonien_tools_clear_watermark_cache(); + conf_update_param('bratonien_watermark_cache_version', $version); +} + function bratonien_tools_get_watermark_defaults() { $defaults = conf_get_param('bratonien_watermark_defaults', null); @@ -40,6 +93,7 @@ function bratonien_tools_save_watermark_defaults() ); conf_update_param('bratonien_watermark_defaults', json_encode($config)); + bratonien_tools_clear_watermark_cache(); return array('message'=>'Globale Wasserzeichenregeln gespeichert.'); } From 6a013fe8751f5e597959ad801aa9f30636324b09 Mon Sep 17 00:00:00 2001 From: Terranom674 Date: Wed, 19 Aug 2026 22:41:36 +0200 Subject: [PATCH 4/6] Clear watermark cache after album rule changes --- tools/album_rules.inc.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tools/album_rules.inc.php b/tools/album_rules.inc.php index 101767a..4046c24 100644 --- a/tools/album_rules.inc.php +++ b/tools/album_rules.inc.php @@ -61,6 +61,7 @@ function bratonien_tools_save_album_rule() ))); } + bratonien_tools_clear_watermark_cache(); return array('message'=>'Albumregel gespeichert.'); } @@ -97,9 +98,6 @@ function bratonien_tools_resolve_album_rule($category_id, array $categories, arr $root = $by_id[$category_id] ?? null; $is_private = $root && isset($root['status']) && $root['status'] === 'private'; - // Privat ist eine Vererbungsgrenze. Eine direkt auf diesem privaten Album - // gesetzte Regel bleibt moeglich, aber Regeln oeffentlicher Eltern duerfen - // nicht in ein privates Album hineinvererbt werden. if ($is_private) { if (isset($rules[$category_id])) From ade38ff2d176dc5a91de73b08ff5f2333e8dc603 Mon Sep 17 00:00:00 2001 From: Terranom674 Date: Wed, 19 Aug 2026 22:42:01 +0200 Subject: [PATCH 5/6] Clear watermark cache after profile changes --- tools/watermark_profiles.inc.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/watermark_profiles.inc.php b/tools/watermark_profiles.inc.php index 7ee37bd..cd45e25 100644 --- a/tools/watermark_profiles.inc.php +++ b/tools/watermark_profiles.inc.php @@ -128,6 +128,7 @@ function bratonien_tools_save_watermark_profile() mass_inserts($table, array_keys($data), array($data)); } + bratonien_tools_clear_watermark_cache(); return array('message'=>'Wasserzeichenprofil gespeichert.'); } @@ -158,6 +159,7 @@ function bratonien_tools_delete_watermark_profile() } pwg_query('DELETE FROM '.bratonien_tools_table('watermark_profiles').' WHERE id='.$id); + bratonien_tools_clear_watermark_cache(); return array('message'=>'Wasserzeichenprofil geloescht.'); } @@ -174,6 +176,7 @@ function bratonien_tools_duplicate_watermark_profile() $profile['name'] .= ' (Kopie)'; $profile['created'] = date('Y-m-d H:i:s'); mass_inserts(bratonien_tools_table('watermark_profiles'), array_keys($profile), array($profile)); + bratonien_tools_clear_watermark_cache(); return array('message'=>'Wasserzeichenprofil dupliziert.'); } From 7c8c7ab98a17fc8df25793d02bbedbe15652c311 Mon Sep 17 00:00:00 2001 From: Terranom674 Date: Wed, 19 Aug 2026 22:42:24 +0200 Subject: [PATCH 6/6] Purge stale watermark cache once on 0.9.7.13 --- main.inc.php | 1 + 1 file changed, 1 insertion(+) diff --git a/main.inc.php b/main.inc.php index 629c2bf..a6d7950 100644 --- a/main.inc.php +++ b/main.inc.php @@ -34,6 +34,7 @@ add_event_handler('get_src_image_url', 'bratonien_tools_filter_webdav_src_url', add_event_handler('get_derivative_url', 'bratonien_tools_filter_webdav_gallery_derivative_url', EVENT_HANDLER_PRIORITY_NEUTRAL + 50, 4); add_event_handler('loc_end_element_set_global', 'bratonien_tools_batch_titles_register_action'); add_event_handler('element_set_global_action', 'bratonien_tools_batch_titles_apply', EVENT_HANDLER_PRIORITY_NEUTRAL, 2); +add_event_handler('init', 'bratonien_tools_watermark_cache_upgrade', EVENT_HANDLER_PRIORITY_NEUTRAL - 40); add_event_handler('init', 'bratonien_tools_prepare_connector_private_import', EVENT_HANDLER_PRIORITY_NEUTRAL - 30); add_event_handler('init', 'bratonien_tools_prepare_private_album_permissions', EVENT_HANDLER_PRIORITY_NEUTRAL - 20); add_event_handler('init', 'bratonien_tools_preserve_private_album_access', EVENT_HANDLER_PRIORITY_NEUTRAL - 10);