Merge pull request #37 from Terranom674/fix/09715-piwigo-ajax-loader

0.9.7.15: Piwigo-AJAX-Lader für WebDAV-Bilder reparieren
This commit is contained in:
Terranom674
2026-08-19 22:59:33 +02:00
committed by GitHub
3 changed files with 55 additions and 8 deletions

View File

@@ -1,7 +1,7 @@
<?php <?php
/* /*
Plugin Name: Bratonien Tools Plugin Name: Bratonien Tools
Version: 0.9.7.14 Version: 0.9.7.15
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

View File

@@ -20,6 +20,20 @@ function bratonien_tools_webdav_derivative_abort($status, $message)
exit; exit;
} }
function bratonien_tools_webdav_derivative_ajax_response($url)
{
http_response_code(200);
header('Content-Type: application/json; charset=utf-8');
header('Cache-Control: no-store, max-age=0');
echo json_encode(array('url'=>(string)$url), JSON_UNESCAPED_SLASHES);
exit;
}
function bratonien_tools_webdav_derivative_binary_url($image_id, $type)
{
return get_root_url().'plugins/'.BRATONIEN_TOOLS_ID.'/webdav-derivative.php?id='.(int)$image_id.'&type='.rawurlencode((string)$type);
}
function bratonien_tools_webdav_derivative_fallback($image_id) function bratonien_tools_webdav_derivative_fallback($image_id)
{ {
$url = bratonien_tools_webdav_image_url((int)$image_id, false); $url = bratonien_tools_webdav_image_url((int)$image_id, false);
@@ -28,6 +42,11 @@ function bratonien_tools_webdav_derivative_fallback($image_id)
bratonien_tools_webdav_derivative_abort(404, 'WebDAV-Bildquelle ist nicht verfuegbar.'); bratonien_tools_webdav_derivative_abort(404, 'WebDAV-Bildquelle ist nicht verfuegbar.');
} }
if (isset($_GET['ajaxload']) && (string)$_GET['ajaxload'] === 'true')
{
bratonien_tools_webdav_derivative_ajax_response($url);
}
header('Cache-Control: no-store'); header('Cache-Control: no-store');
header('Location: '.$url, true, 302); header('Location: '.$url, true, 302);
exit; exit;
@@ -74,17 +93,12 @@ if (!$info)
$preview = bratonien_tools_webdav_preview_path($info); $preview = bratonien_tools_webdav_preview_path($info);
if (!$preview || !is_file($preview) || !is_readable($preview)) if (!$preview || !is_file($preview) || !is_readable($preview))
{ {
// Altbestand kann noch keinen vorbereiteten Preview-Cache besitzen. Der
// fokussierte Fotorama-Request darf dann nicht mit 404 enden, weil Fotorama
// den fehlgeschlagenen Frame sonst nicht erneut laedt. Stattdessen wird nur
// fuer dieses angeforderte Bild auf die echte WebDAV-Quelle ausgewichen.
bratonien_tools_webdav_derivative_fallback($image_id); bratonien_tools_webdav_derivative_fallback($image_id);
} }
$derivative = new DerivativeImage($params, $src); $derivative = new DerivativeImage($params, $src);
if ($derivative->same_as_source()) if ($derivative->same_as_source())
{ {
// Niemals die lokale Connector-Platzhalterquelle ausliefern.
bratonien_tools_webdav_derivative_fallback($image_id); bratonien_tools_webdav_derivative_fallback($image_id);
} }
@@ -115,6 +129,17 @@ if (!bratonien_tools_webdav_derivative_matches_preview($target, $params, $image_
bratonien_tools_webdav_derivative_fallback($image_id); bratonien_tools_webdav_derivative_fallback($image_id);
} }
// Piwigos thumbnails.loader.js fordert nicht gecachte Derivate mit
// ?ajaxload=true an und erwartet JSON {"url":"..."}. Erst diese URL wird
// danach als echtes Bild geladen. Binärdaten an dieser Stelle führen direkt
// zum Piwigo-Fehlersymbol.
if (isset($_GET['ajaxload']) && (string)$_GET['ajaxload'] === 'true')
{
bratonien_tools_webdav_derivative_ajax_response(
bratonien_tools_webdav_derivative_binary_url($image_id, $type)
);
}
$size = @filesize($target); $size = @filesize($target);
$mtime = @filemtime($target) ?: time(); $mtime = @filemtime($target) ?: time();
$etag = sha1($target.'|'.$mtime.'|'.($size ?: 0)); $etag = sha1($target.'|'.$mtime.'|'.($size ?: 0));

View File

@@ -19,6 +19,18 @@ function bratonien_tools_webdav_image_abort($status, $message)
exit; exit;
} }
function bratonien_tools_webdav_image_ajax_response($image_id, $preview)
{
$url = get_root_url().'plugins/'.BRATONIEN_TOOLS_ID.'/webdav-image.php?id='.(int)$image_id;
if ($preview) $url .= '&preview=1';
http_response_code(200);
header('Content-Type: application/json; charset=utf-8');
header('Cache-Control: no-store, max-age=0');
echo json_encode(array('url'=>$url), JSON_UNESCAPED_SLASHES);
exit;
}
function bratonien_tools_webdav_image_decrypt_secret($blob, $hex_key) function bratonien_tools_webdav_image_decrypt_secret($blob, $hex_key)
{ {
$hex_key = trim((string)$hex_key); $hex_key = trim((string)$hex_key);
@@ -52,7 +64,17 @@ if (!pwg_db_num_rows($access_result)) bratonien_tools_webdav_image_abort(403, 'K
$source = bratonien_tools_webdav_image_source_info($image_id); $source = bratonien_tools_webdav_image_source_info($image_id);
if (!$source) bratonien_tools_webdav_image_abort(404, 'Keine WebDAV-Quelle für dieses Bild gefunden.'); if (!$source) bratonien_tools_webdav_image_abort(404, 'Keine WebDAV-Quelle für dieses Bild gefunden.');
if (!empty($_GET['preview'])) $preview_requested = !empty($_GET['preview']);
// Piwigos Standard-Lader erwartet bei ?ajaxload=true JSON und lädt erst die
// darin enthaltene URL als Bild. Binärdaten in diesem Request werden als
// Ladefehler behandelt und durch errors_small.png ersetzt.
if (isset($_GET['ajaxload']) && (string)$_GET['ajaxload'] === 'true')
{
bratonien_tools_webdav_image_ajax_response($image_id, $preview_requested);
}
if ($preview_requested)
{ {
$preview = bratonien_tools_webdav_preview_path($source); $preview = bratonien_tools_webdav_preview_path($source);
if ($preview) if ($preview)
@@ -121,7 +143,7 @@ $options = array(
CURLOPT_USERPWD => $user.':'.$password, CURLOPT_USERPWD => $user.':'.$password,
CURLOPT_RETURNTRANSFER => false, CURLOPT_RETURNTRANSFER => false,
CURLOPT_FAILONERROR => false, CURLOPT_FAILONERROR => false,
CURLOPT_USERAGENT => 'Bratonien-Tools-WebDAV-Image/0.9.7.1', CURLOPT_USERAGENT => 'Bratonien-Tools-WebDAV-Image/0.9.7.15',
CURLOPT_HEADERFUNCTION => function($ch, $line) CURLOPT_HEADERFUNCTION => function($ch, $line)
{ {
$length = strlen($line); $length = strlen($line);