mirror of
https://github.com/Terranom674/Piwigo_Bratonien_Tools.git
synced 2026-09-19 19:54:31 +00:00
Compare commits
10 Commits
fix/0974-g
...
fix/09710-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
28e34d6c73 | ||
|
|
b8852310bd | ||
|
|
ae96fc2e3e | ||
|
|
ebf4fc7e74 | ||
|
|
d798b82ec7 | ||
|
|
9e282af1b4 | ||
|
|
d7628d1dac | ||
|
|
7e9c3ae05f | ||
|
|
b64e46a549 | ||
|
|
6607c4aefe |
@@ -4,6 +4,42 @@ if (!defined('PHPWG_ROOT_PATH'))
|
||||
die('Hacking attempt!');
|
||||
}
|
||||
|
||||
function bratonien_tools_webdav_derivative_matches_preview($derivative_path, $params, $image_id)
|
||||
{
|
||||
$derivative_path = (string)$derivative_path;
|
||||
$image_id = (int)$image_id;
|
||||
if ($derivative_path === '' || $image_id < 1 || !is_file($derivative_path) || !is_readable($derivative_path)) return false;
|
||||
|
||||
$info = bratonien_tools_webdav_image_source_info($image_id);
|
||||
if (!$info) return false;
|
||||
|
||||
$preview = bratonien_tools_webdav_preview_path($info);
|
||||
if (!$preview || !is_file($preview) || !is_readable($preview)) return false;
|
||||
|
||||
$preview_size = @getimagesize($preview);
|
||||
$derivative_size = @getimagesize($derivative_path);
|
||||
if (!is_array($preview_size) || empty($preview_size[0]) || empty($preview_size[1])) return false;
|
||||
if (!is_array($derivative_size) || empty($derivative_size[0]) || empty($derivative_size[1])) return false;
|
||||
|
||||
try
|
||||
{
|
||||
$expected_size = $params->compute_final_size(array((int)$preview_size[0], (int)$preview_size[1]));
|
||||
}
|
||||
catch (Throwable $e)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!is_array($expected_size) || !isset($expected_size[0], $expected_size[1])) return false;
|
||||
if ((int)$derivative_size[0] !== (int)$expected_size[0] || (int)$derivative_size[1] !== (int)$expected_size[1]) return false;
|
||||
|
||||
$preview_mtime = @filemtime($preview) ?: 0;
|
||||
$derivative_mtime = @filemtime($derivative_path) ?: 0;
|
||||
if ($preview_mtime > 0 && $derivative_mtime < $preview_mtime) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function bratonien_tools_filter_webdav_gallery_derivative_url($url, $params, $src_image, $rel_url)
|
||||
{
|
||||
if (!is_object($src_image) || empty($src_image->id) || empty($src_image->rel_path)) return $url;
|
||||
@@ -14,13 +50,15 @@ function bratonien_tools_filter_webdav_gallery_derivative_url($url, $params, $sr
|
||||
return $url;
|
||||
}
|
||||
|
||||
$image_id = (int)$src_image->id;
|
||||
$derivative_path = '';
|
||||
try
|
||||
{
|
||||
$derivative = new DerivativeImage($params, $src_image);
|
||||
if (!$derivative->same_as_source())
|
||||
{
|
||||
$path = $derivative->get_path();
|
||||
if ($path !== '' && is_file($path) && is_readable($path))
|
||||
$derivative_path = $derivative->get_path();
|
||||
if (bratonien_tools_webdav_derivative_matches_preview($derivative_path, $params, $image_id))
|
||||
{
|
||||
return $url;
|
||||
}
|
||||
@@ -28,9 +66,48 @@ function bratonien_tools_filter_webdav_gallery_derivative_url($url, $params, $sr
|
||||
}
|
||||
catch (Throwable $e)
|
||||
{
|
||||
error_log('Bratonien WebDAV gallery derivative lookup #'.(int)$src_image->id.': '.$e->getMessage());
|
||||
error_log('Bratonien WebDAV derivative lookup #'.$image_id.': '.$e->getMessage());
|
||||
}
|
||||
|
||||
$preview_url = bratonien_tools_webdav_image_url((int)$src_image->id, true);
|
||||
$script_name = basename((string)($_SERVER['SCRIPT_NAME'] ?? ''));
|
||||
if ($script_name === 'picture.php' && function_exists('bratonien_tools_webdav_generate_derivative'))
|
||||
{
|
||||
if ($derivative_path !== '' && is_file($derivative_path) && !bratonien_tools_webdav_derivative_matches_preview($derivative_path, $params, $image_id))
|
||||
{
|
||||
@unlink($derivative_path);
|
||||
clearstatcache(true, $derivative_path);
|
||||
}
|
||||
|
||||
$detail = '';
|
||||
try
|
||||
{
|
||||
if (bratonien_tools_webdav_generate_derivative($params, $src_image, $detail))
|
||||
{
|
||||
if ($derivative_path === '')
|
||||
{
|
||||
$probe = new DerivativeImage($params, $src_image);
|
||||
if (!$probe->same_as_source()) $derivative_path = $probe->get_path();
|
||||
}
|
||||
if (bratonien_tools_webdav_derivative_matches_preview($derivative_path, $params, $image_id))
|
||||
{
|
||||
return $url;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Throwable $e)
|
||||
{
|
||||
$detail = get_class($e).': '.$e->getMessage();
|
||||
}
|
||||
|
||||
if ($detail !== '')
|
||||
{
|
||||
error_log('Bratonien WebDAV picture derivative #'.$image_id.': '.$detail);
|
||||
}
|
||||
}
|
||||
|
||||
// Connector-Platzhalter oder daraus entstandene Derivate werden nie ausgeliefert.
|
||||
// Wenn noch kein echtes lokales Derivat bereitsteht, geht der Request immer auf
|
||||
// die echte WebDAV-Bildquelle bzw. deren vorbereitetes Preview.
|
||||
$preview_url = bratonien_tools_webdav_image_url($image_id, true);
|
||||
return $preview_url ?: $url;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
/*
|
||||
Plugin Name: Bratonien Tools
|
||||
Version: 0.9.7.7
|
||||
Version: 0.9.7.10
|
||||
Description: Erweiterbare Administrationswerkzeuge fuer die Bratonien-Piwigo-Installation.
|
||||
Plugin URI: https://github.com/Terranom674/Piwigo_Bratonien_Tools
|
||||
Author: Bratonien
|
||||
|
||||
@@ -6,7 +6,7 @@ if (PHP_SAPI !== 'cli')
|
||||
exit(1);
|
||||
}
|
||||
|
||||
const BRATONIEN_WEBDAV_DERIVATIVE_BUILDER_VERSION = '0.9.7.5';
|
||||
const BRATONIEN_WEBDAV_DERIVATIVE_BUILDER_VERSION = '0.9.7.8';
|
||||
|
||||
$options = getopt('', array('piwigo-root:', 'connection-id:'));
|
||||
$piwigo_root = rtrim((string)($options['piwigo-root'] ?? ''), '/');
|
||||
@@ -46,25 +46,75 @@ if (!function_exists('bratonien_tools_webdav_image_source_info') || !function_ex
|
||||
exit(1);
|
||||
}
|
||||
|
||||
try
|
||||
function bratonien_tools_webdav_modus_config()
|
||||
{
|
||||
$standard_gallery = ImageStdParams::get_by_type(IMG_THUMB);
|
||||
if (!$standard_gallery || !isset($standard_gallery->sizing->ideal_size))
|
||||
global $conf;
|
||||
|
||||
$modus = $conf['modus_theme'] ?? array();
|
||||
if (is_string($modus) && $modus !== '')
|
||||
{
|
||||
$decoded = @unserialize($modus);
|
||||
if (is_array($decoded)) $modus = $decoded;
|
||||
}
|
||||
if (!is_array($modus)) $modus = array();
|
||||
|
||||
return array_merge(
|
||||
array(
|
||||
'index_photo_deriv'=>'2small',
|
||||
'index_photo_deriv_hdpi'=>'xsmall',
|
||||
),
|
||||
$modus
|
||||
);
|
||||
}
|
||||
|
||||
function bratonien_tools_webdav_gallery_base_params()
|
||||
{
|
||||
$modus = bratonien_tools_webdav_modus_config();
|
||||
$type = trim((string)($modus['index_photo_deriv'] ?? '2small'));
|
||||
$params = $type !== '' ? @ImageStdParams::get_by_type($type) : null;
|
||||
if ($params) return $params;
|
||||
|
||||
$params = ImageStdParams::get_by_type(IMG_THUMB);
|
||||
if (!$params)
|
||||
{
|
||||
throw new RuntimeException('Piwigo-Galeriederivat ist nicht konfiguriert.');
|
||||
}
|
||||
return $params;
|
||||
}
|
||||
|
||||
$gallery_params = clone $standard_gallery;
|
||||
$gallery_params->sizing = new SizingParams(
|
||||
array(
|
||||
(int)$standard_gallery->sizing->ideal_size[0],
|
||||
(int)$standard_gallery->sizing->ideal_size[1],
|
||||
),
|
||||
0,
|
||||
null
|
||||
);
|
||||
$gallery_params->type = IMG_THUMB;
|
||||
$gallery_params->use_watermark = false;
|
||||
function bratonien_tools_webdav_modus_gallery_params(SrcImage $src, $base_params)
|
||||
{
|
||||
$row_height = (int)$base_params->max_height();
|
||||
$candidates = array($base_params);
|
||||
|
||||
foreach (ImageStdParams::get_defined_type_map() as $params)
|
||||
{
|
||||
if (
|
||||
$params->max_height() > $row_height
|
||||
&& $params->sizing->max_crop == $base_params->sizing->max_crop
|
||||
)
|
||||
{
|
||||
$candidates[] = $params;
|
||||
if (count($candidates) === 3) break;
|
||||
}
|
||||
}
|
||||
|
||||
$selected = $base_params;
|
||||
foreach ($candidates as $params)
|
||||
{
|
||||
$selected = $params;
|
||||
$probe = new DerivativeImage($params, $src);
|
||||
$size = $probe->get_size();
|
||||
if ((int)$size[1] >= $row_height - 2) break;
|
||||
}
|
||||
|
||||
return $selected;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$gallery_base_params = bratonien_tools_webdav_gallery_base_params();
|
||||
$gallery_base_type = (string)$gallery_base_params->type;
|
||||
|
||||
$images = 0;
|
||||
$generated_or_ready = 0;
|
||||
@@ -73,6 +123,7 @@ try
|
||||
$legacy_derivatives_rebuilt = 0;
|
||||
$errors = 0;
|
||||
$error_lines = array();
|
||||
$variant_counts = array();
|
||||
|
||||
$result = pwg_query('SELECT * FROM '.IMAGES_TABLE.' ORDER BY id');
|
||||
while ($row = pwg_db_fetch_assoc($result))
|
||||
@@ -124,6 +175,11 @@ try
|
||||
$src = new SrcImage($row);
|
||||
try
|
||||
{
|
||||
$gallery_params = bratonien_tools_webdav_modus_gallery_params($src, $gallery_base_params);
|
||||
$variant = (string)$gallery_params->type;
|
||||
if ($variant === '') $variant = 'custom';
|
||||
$variant_counts[$variant] = ($variant_counts[$variant] ?? 0) + 1;
|
||||
|
||||
$probe = new DerivativeImage($gallery_params, $src);
|
||||
if ($probe->same_as_source())
|
||||
{
|
||||
@@ -190,9 +246,18 @@ try
|
||||
}
|
||||
}
|
||||
|
||||
ksort($variant_counts);
|
||||
$variant_parts = array();
|
||||
foreach ($variant_counts as $type=>$count)
|
||||
{
|
||||
$variant_parts[] = $type.':'.$count;
|
||||
}
|
||||
|
||||
echo 'WebDAV-Derivative-Builder: version='.BRATONIEN_WEBDAV_DERIVATIVE_BUILDER_VERSION.
|
||||
' bilder='.$images.
|
||||
' varianten=1'.
|
||||
' varianten_pro_bild=1'.
|
||||
' modus_basis='.$gallery_base_type.
|
||||
' modus_varianten='.implode(',', $variant_parts).
|
||||
' bereit='.$generated_or_ready.
|
||||
' identisch='.$identity.
|
||||
' metadaten_repariert='.$metadata_repaired.
|
||||
|
||||
Reference in New Issue
Block a user