mirror of
https://github.com/Terranom674/Piwigo_Bratonien_Tools.git
synced 2026-09-19 17:34:31 +00:00
Merge pull request #28 from Terranom674/fix/0974-gallery-derivative-only
0.9.7.6: Galerie-Hotpath entlasten
This commit is contained in:
@@ -8,12 +8,22 @@ require_once(BRATONIEN_TOOLS_PATH . 'include/watermark_base.inc.php');
|
|||||||
|
|
||||||
function bratonien_tools_watermark_engine_enabled()
|
function bratonien_tools_watermark_engine_enabled()
|
||||||
{
|
{
|
||||||
|
static $initialized = false;
|
||||||
|
static $enabled = false;
|
||||||
|
|
||||||
|
if ($initialized)
|
||||||
|
{
|
||||||
|
return $enabled;
|
||||||
|
}
|
||||||
|
|
||||||
$config = bratonien_tools_get_watermark_engine_config();
|
$config = bratonien_tools_get_watermark_engine_config();
|
||||||
$enabled = !empty($config['enabled']);
|
$enabled = !empty($config['enabled']);
|
||||||
|
$initialized = true;
|
||||||
|
|
||||||
// Piwigo recalculates use_watermark for custom derivatives from the native
|
// Piwigo recalculates use_watermark for custom derivatives from the native
|
||||||
// watermark file itself. Therefore an active Bratonien engine must keep the
|
// watermark file itself. Therefore an active Bratonien engine must keep the
|
||||||
// native watermark file empty, not only the stored use_watermark flags false.
|
// native watermark file empty, not only the stored use_watermark flags false.
|
||||||
|
// This initialization is required only once per PHP request.
|
||||||
if ($enabled)
|
if ($enabled)
|
||||||
{
|
{
|
||||||
bratonien_tools_disable_piwigo_watermarks();
|
bratonien_tools_disable_piwigo_watermarks();
|
||||||
|
|||||||
@@ -7,6 +7,9 @@ if (!defined('PHPWG_ROOT_PATH'))
|
|||||||
function bratonien_tools_webdav_image_source_info($image_id)
|
function bratonien_tools_webdav_image_source_info($image_id)
|
||||||
{
|
{
|
||||||
static $cache = array();
|
static $cache = array();
|
||||||
|
static $connection_cache = array();
|
||||||
|
static $mapping_cache = array();
|
||||||
|
|
||||||
$image_id = (int)$image_id;
|
$image_id = (int)$image_id;
|
||||||
if ($image_id < 1) return null;
|
if ($image_id < 1) return null;
|
||||||
if (array_key_exists($image_id, $cache)) return $cache[$image_id];
|
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;
|
$absolute = $path;
|
||||||
if (strpos($absolute, '/') !== 0)
|
if (strpos($absolute, '/') !== 0)
|
||||||
{
|
{
|
||||||
$absolute = PHPWG_ROOT_PATH.ltrim(preg_replace('#^\./#', '', $absolute), '/');
|
$absolute = PHPWG_ROOT_PATH.ltrim(preg_replace('#^\\./#', '', $absolute), '/');
|
||||||
}
|
}
|
||||||
$resolved = realpath($absolute);
|
$resolved = realpath($absolute);
|
||||||
if ($resolved === false) return $cache[$image_id] = null;
|
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))
|
if (!preg_match('#/nc-webdav-source/connection-([0-9]+)/root-([0-9]+)/(.*)$#', $normalized, $match))
|
||||||
{
|
{
|
||||||
return $cache[$image_id] = null;
|
return $cache[$image_id] = null;
|
||||||
@@ -36,13 +39,25 @@ function bratonien_tools_webdav_image_source_info($image_id)
|
|||||||
$relative_path = trim((string)$match[3], '/');
|
$relative_path = trim((string)$match[3], '/');
|
||||||
if ($relative_path === '') return $cache[$image_id] = null;
|
if ($relative_path === '') return $cache[$image_id] = null;
|
||||||
|
|
||||||
$table = defined('BRATONIEN_TOOLS_NC_CONNECTIONS_TABLE')
|
if (!array_key_exists($connection_id, $connection_cache))
|
||||||
? BRATONIEN_TOOLS_NC_CONNECTIONS_TABLE
|
{
|
||||||
: $GLOBALS['prefixeTable'].'bratonien_tools_nc_connections';
|
$table = defined('BRATONIEN_TOOLS_NC_CONNECTIONS_TABLE')
|
||||||
$connection_result = pwg_query('SELECT config_json FROM `'.$table.'` WHERE id='.$connection_id.' LIMIT 1');
|
? BRATONIEN_TOOLS_NC_CONNECTIONS_TABLE
|
||||||
if (!pwg_db_num_rows($connection_result)) return $cache[$image_id] = null;
|
: $GLOBALS['prefixeTable'].'bratonien_tools_nc_connections';
|
||||||
$connection_row = pwg_db_fetch_assoc($connection_result);
|
$connection_result = pwg_query('SELECT config_json FROM `'.$table.'` WHERE id='.$connection_id.' LIMIT 1');
|
||||||
$config = json_decode((string)$connection_row['config_json'], true);
|
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')
|
if (!is_array($config) || (string)($config['source_mode'] ?? '') !== 'webdav-placeholder')
|
||||||
{
|
{
|
||||||
return $cache[$image_id] = null;
|
return $cache[$image_id] = null;
|
||||||
@@ -68,27 +83,33 @@ function bratonien_tools_webdav_image_source_info($image_id)
|
|||||||
$size = 0;
|
$size = 0;
|
||||||
$etag = '';
|
$etag = '';
|
||||||
|
|
||||||
$state_dir = rtrim((string)($config['state_dir'] ?? ''), '/');
|
if (!array_key_exists($connection_id, $mapping_cache))
|
||||||
if ($state_dir !== '')
|
|
||||||
{
|
{
|
||||||
$mapping_file = $state_dir.'/webdav-map.json';
|
$mapping_cache[$connection_id] = array();
|
||||||
if (is_readable($mapping_file))
|
$state_dir = rtrim((string)($config['state_dir'] ?? ''), '/');
|
||||||
|
if ($state_dir !== '')
|
||||||
{
|
{
|
||||||
$mapping = json_decode((string)file_get_contents($mapping_file), true);
|
$mapping_file = $state_dir.'/webdav-map.json';
|
||||||
if (is_array($mapping) && isset($mapping['files']) && is_array($mapping['files']))
|
if (is_readable($mapping_file))
|
||||||
{
|
{
|
||||||
$entry = $mapping['files'][$resolved] ?? $mapping['files'][$normalized] ?? null;
|
$mapping = json_decode((string)file_get_contents($mapping_file), true);
|
||||||
if (is_array($entry) && (string)($entry['kind'] ?? '') === 'file')
|
if (is_array($mapping) && isset($mapping['files']) && is_array($mapping['files']))
|
||||||
{
|
{
|
||||||
$webdav_path = trim((string)($entry['webdav_path'] ?? $webdav_path), '/');
|
$mapping_cache[$connection_id] = $mapping['files'];
|
||||||
$content_type = (string)($entry['content_type'] ?? '');
|
|
||||||
$size = (int)($entry['size'] ?? 0);
|
|
||||||
$etag = (string)($entry['etag'] ?? '');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$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(
|
return $cache[$image_id] = array(
|
||||||
'image_id'=>$image_id,
|
'image_id'=>$image_id,
|
||||||
'connection_id'=>$connection_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)
|
function bratonien_tools_filter_webdav_derivative_url($url, $params, $src_image, $rel_url)
|
||||||
{
|
{
|
||||||
if (!is_object($src_image) || empty($src_image->id)) return $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);
|
$path = $derivative->get_path();
|
||||||
if (!$derivative->same_as_source())
|
if ($path !== '' && is_file($path) && is_readable($path)) return $url;
|
||||||
{
|
|
||||||
$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());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
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);
|
$preview_url = bratonien_tools_webdav_image_url((int)$src_image->id, true);
|
||||||
return $preview_url ?: $url;
|
return $preview_url ?: $url;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
/*
|
/*
|
||||||
Plugin Name: Bratonien Tools
|
Plugin Name: Bratonien Tools
|
||||||
Version: 0.9.7.5
|
Version: 0.9.7.6
|
||||||
Description: Erweiterbare Administrationswerkzeuge fuer die Bratonien-Piwigo-Installation.
|
Description: Erweiterbare Administrationswerkzeuge fuer die Bratonien-Piwigo-Installation.
|
||||||
Plugin URI: https://github.com/Terranom674/Piwigo_Bratonien_Tools
|
Plugin URI: https://github.com/Terranom674/Piwigo_Bratonien_Tools
|
||||||
Author: Bratonien
|
Author: Bratonien
|
||||||
@@ -37,7 +37,6 @@ add_event_handler('init', 'bratonien_tools_prepare_connector_private_import', EV
|
|||||||
add_event_handler('init', 'bratonien_tools_prepare_private_album_permissions', EVENT_HANDLER_PRIORITY_NEUTRAL - 20);
|
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);
|
add_event_handler('init', 'bratonien_tools_preserve_private_album_access', EVENT_HANDLER_PRIORITY_NEUTRAL - 10);
|
||||||
add_event_handler('init', 'bratonien_tools_album_shares_init');
|
add_event_handler('init', 'bratonien_tools_album_shares_init');
|
||||||
add_event_handler('init', 'bratonien_tools_nc_scheduler_tick', EVENT_HANDLER_PRIORITY_NEUTRAL + 100);
|
|
||||||
add_event_handler('delete_categories', 'bratonien_tools_album_shares_on_delete_categories');
|
add_event_handler('delete_categories', 'bratonien_tools_album_shares_on_delete_categories');
|
||||||
add_event_handler('ws_add_methods', 'bratonien_tools_register_ws_methods');
|
add_event_handler('ws_add_methods', 'bratonien_tools_register_ws_methods');
|
||||||
add_event_handler('ws_add_methods', 'bratonien_tools_register_nc_orphan_ws_methods');
|
add_event_handler('ws_add_methods', 'bratonien_tools_register_nc_orphan_ws_methods');
|
||||||
|
|||||||
Reference in New Issue
Block a user