From 588f1fc10072d99b412a4d69362a3ef58f5aa187 Mon Sep 17 00:00:00 2001 From: Terranom674 Date: Wed, 19 Aug 2026 21:35:06 +0200 Subject: [PATCH 1/5] 0.9.7.6: WebDAV-Hotpath pro Request cachen --- include/webdav_image_runtime.inc.php | 96 ++++++++++++++++++---------- 1 file changed, 61 insertions(+), 35 deletions(-) diff --git a/include/webdav_image_runtime.inc.php b/include/webdav_image_runtime.inc.php index 8acc6b9..8afad73 100644 --- a/include/webdav_image_runtime.inc.php +++ b/include/webdav_image_runtime.inc.php @@ -7,6 +7,9 @@ if (!defined('PHPWG_ROOT_PATH')) function bratonien_tools_webdav_image_source_info($image_id) { static $cache = array(); + static $connection_cache = array(); + static $mapping_cache = array(); + $image_id = (int)$image_id; if ($image_id < 1) return null; if (array_key_exists($image_id, $cache)) return $cache[$image_id]; @@ -20,12 +23,12 @@ function bratonien_tools_webdav_image_source_info($image_id) $absolute = $path; if (strpos($absolute, '/') !== 0) { - $absolute = PHPWG_ROOT_PATH.ltrim(preg_replace('#^\./#', '', $absolute), '/'); + $absolute = PHPWG_ROOT_PATH.ltrim(preg_replace('#^\\./#', '', $absolute), '/'); } $resolved = realpath($absolute); if ($resolved === false) return $cache[$image_id] = null; - $normalized = str_replace('\\', '/', $resolved); + $normalized = str_replace('\\\\', '/', $resolved); if (!preg_match('#/nc-webdav-source/connection-([0-9]+)/root-([0-9]+)/(.*)$#', $normalized, $match)) { return $cache[$image_id] = null; @@ -36,13 +39,25 @@ function bratonien_tools_webdav_image_source_info($image_id) $relative_path = trim((string)$match[3], '/'); if ($relative_path === '') return $cache[$image_id] = null; - $table = defined('BRATONIEN_TOOLS_NC_CONNECTIONS_TABLE') - ? BRATONIEN_TOOLS_NC_CONNECTIONS_TABLE - : $GLOBALS['prefixeTable'].'bratonien_tools_nc_connections'; - $connection_result = pwg_query('SELECT config_json FROM `'.$table.'` WHERE id='.$connection_id.' LIMIT 1'); - if (!pwg_db_num_rows($connection_result)) return $cache[$image_id] = null; - $connection_row = pwg_db_fetch_assoc($connection_result); - $config = json_decode((string)$connection_row['config_json'], true); + if (!array_key_exists($connection_id, $connection_cache)) + { + $table = defined('BRATONIEN_TOOLS_NC_CONNECTIONS_TABLE') + ? BRATONIEN_TOOLS_NC_CONNECTIONS_TABLE + : $GLOBALS['prefixeTable'].'bratonien_tools_nc_connections'; + $connection_result = pwg_query('SELECT config_json FROM `'.$table.'` WHERE id='.$connection_id.' LIMIT 1'); + if (!pwg_db_num_rows($connection_result)) + { + $connection_cache[$connection_id] = null; + } + else + { + $connection_row = pwg_db_fetch_assoc($connection_result); + $decoded = json_decode((string)$connection_row['config_json'], true); + $connection_cache[$connection_id] = is_array($decoded) ? $decoded : null; + } + } + + $config = $connection_cache[$connection_id]; if (!is_array($config) || (string)($config['source_mode'] ?? '') !== 'webdav-placeholder') { return $cache[$image_id] = null; @@ -68,27 +83,33 @@ function bratonien_tools_webdav_image_source_info($image_id) $size = 0; $etag = ''; - $state_dir = rtrim((string)($config['state_dir'] ?? ''), '/'); - if ($state_dir !== '') + if (!array_key_exists($connection_id, $mapping_cache)) { - $mapping_file = $state_dir.'/webdav-map.json'; - if (is_readable($mapping_file)) + $mapping_cache[$connection_id] = array(); + $state_dir = rtrim((string)($config['state_dir'] ?? ''), '/'); + if ($state_dir !== '') { - $mapping = json_decode((string)file_get_contents($mapping_file), true); - if (is_array($mapping) && isset($mapping['files']) && is_array($mapping['files'])) + $mapping_file = $state_dir.'/webdav-map.json'; + if (is_readable($mapping_file)) { - $entry = $mapping['files'][$resolved] ?? $mapping['files'][$normalized] ?? null; - if (is_array($entry) && (string)($entry['kind'] ?? '') === 'file') + $mapping = json_decode((string)file_get_contents($mapping_file), true); + if (is_array($mapping) && isset($mapping['files']) && is_array($mapping['files'])) { - $webdav_path = trim((string)($entry['webdav_path'] ?? $webdav_path), '/'); - $content_type = (string)($entry['content_type'] ?? ''); - $size = (int)($entry['size'] ?? 0); - $etag = (string)($entry['etag'] ?? ''); + $mapping_cache[$connection_id] = $mapping['files']; } } } } + $entry = $mapping_cache[$connection_id][$resolved] ?? $mapping_cache[$connection_id][$normalized] ?? null; + if (is_array($entry) && (string)($entry['kind'] ?? '') === 'file') + { + $webdav_path = trim((string)($entry['webdav_path'] ?? $webdav_path), '/'); + $content_type = (string)($entry['content_type'] ?? ''); + $size = (int)($entry['size'] ?? 0); + $etag = (string)($entry['etag'] ?? ''); + } + return $cache[$image_id] = array( 'image_id'=>$image_id, 'connection_id'=>$connection_id, @@ -416,25 +437,30 @@ function bratonien_tools_filter_webdav_src_url($url, $src_image) function bratonien_tools_filter_webdav_derivative_url($url, $params, $src_image, $rel_url) { if (!is_object($src_image) || empty($src_image->id)) return $url; - $info = bratonien_tools_webdav_image_source_info((int)$src_image->id); - if (!$info) return $url; - if (empty($info['root_is_base'])) + // Hotpath: Bei einem bereits vorbereiteten WebDAV-Derivat keinerlei + // Connection-DB oder Mapping-Datei mehr anfassen. Der reale Quellpfad + // reicht aus, um Connector-Bilder sicher zu erkennen. + $source_path = $src_image->get_path(); + $resolved_source = $source_path !== '' ? realpath($source_path) : false; + if ($resolved_source === false || !preg_match('#/nc-webdav-source/connection-[0-9]+/root-[0-9]+/#', str_replace('\\\\', '/', $resolved_source))) { - try + return $url; + } + + try + { + $derivative = new DerivativeImage($params, $src_image); + if (!$derivative->same_as_source()) { - $derivative = new DerivativeImage($params, $src_image); - if (!$derivative->same_as_source()) - { - $path = $derivative->get_path(); - if ($path !== '' && is_file($path) && is_readable($path)) return $url; - } - } - catch (Throwable $e) - { - error_log('Bratonien WebDAV derivative lookup #'.(int)$src_image->id.': '.$e->getMessage()); + $path = $derivative->get_path(); + if ($path !== '' && is_file($path) && is_readable($path)) return $url; } } + catch (Throwable $e) + { + error_log('Bratonien WebDAV derivative lookup #'.(int)$src_image->id.': '.$e->getMessage()); + } $preview_url = bratonien_tools_webdav_image_url((int)$src_image->id, true); return $preview_url ?: $url; From 9e07cd804244e5a756e350a1bc649eccd52d6925 Mon Sep 17 00:00:00 2001 From: Terranom674 Date: Wed, 19 Aug 2026 21:35:50 +0200 Subject: [PATCH 2/5] 0.9.7.6: Request-Scheduler aus Galeriepfad entfernen --- main.inc.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/main.inc.php b/main.inc.php index d5772d0..1507d99 100644 --- a/main.inc.php +++ b/main.inc.php @@ -1,7 +1,7 @@ Date: Wed, 19 Aug 2026 21:36:37 +0200 Subject: [PATCH 3/5] 0.9.7.6: Wasserzeichen-Engine pro Request nur einmal initialisieren --- include/watermark_engine.inc.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/include/watermark_engine.inc.php b/include/watermark_engine.inc.php index 3826954..5f5f5a6 100644 --- a/include/watermark_engine.inc.php +++ b/include/watermark_engine.inc.php @@ -8,12 +8,22 @@ require_once(BRATONIEN_TOOLS_PATH . 'include/watermark_base.inc.php'); function bratonien_tools_watermark_engine_enabled() { + static $initialized = false; + static $enabled = false; + + if ($initialized) + { + return $enabled; + } + $config = bratonien_tools_get_watermark_engine_config(); $enabled = !empty($config['enabled']); + $initialized = true; // Piwigo recalculates use_watermark for custom derivatives from the native // watermark file itself. Therefore an active Bratonien engine must keep the // native watermark file empty, not only the stored use_watermark flags false. + // This initialization is required only once per PHP request. if ($enabled) { bratonien_tools_disable_piwigo_watermarks(); From 5a5669d976685189b46fcb8f941e7a403c7d0bc3 Mon Sep 17 00:00:00 2001 From: Terranom674 Date: Wed, 19 Aug 2026 21:36:46 +0200 Subject: [PATCH 4/5] ci: trigger 0.9.7.6 --- .ci-trigger-0976 | 1 + 1 file changed, 1 insertion(+) create mode 100644 .ci-trigger-0976 diff --git a/.ci-trigger-0976 b/.ci-trigger-0976 new file mode 100644 index 0000000..6d8a404 --- /dev/null +++ b/.ci-trigger-0976 @@ -0,0 +1 @@ +0.9.7.6 From 32f2ceaaecebf585b252ade9534d6bd7abc63455 Mon Sep 17 00:00:00 2001 From: Terranom674 Date: Wed, 19 Aug 2026 21:37:19 +0200 Subject: [PATCH 5/5] cleanup: temporaeren CI-Trigger entfernen --- .ci-trigger-0976 | 1 - 1 file changed, 1 deletion(-) delete mode 100644 .ci-trigger-0976 diff --git a/.ci-trigger-0976 b/.ci-trigger-0976 deleted file mode 100644 index 6d8a404..0000000 --- a/.ci-trigger-0976 +++ /dev/null @@ -1 +0,0 @@ -0.9.7.6