mirror of
https://github.com/Terranom674/Piwigo_Bratonien_Tools.git
synced 2026-11-14 15:58:23 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6ecbf26bfd | ||
|
|
7c8c7ab98a | ||
|
|
ade38ff2d1 | ||
|
|
6a013fe875 | ||
|
|
c71112d94e | ||
|
|
7d97e1b515 | ||
|
|
47afbc7f43 | ||
|
|
706639a57e | ||
|
|
c7b14add33 | ||
|
|
f9e87df305 | ||
|
|
6ba5eb4d7f | ||
|
|
85369fa15e | ||
|
|
981ba6c18b | ||
|
|
77e20af977 | ||
|
|
e187c517da | ||
|
|
28e34d6c73 | ||
|
|
b8852310bd | ||
|
|
ae96fc2e3e |
No files matched your search
@@ -27,6 +27,72 @@ function bratonien_tools_runtime_category_id()
|
|||||||
return 0;
|
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)
|
function bratonien_tools_runtime_effective_rule($category_id)
|
||||||
{
|
{
|
||||||
static $categories = null;
|
static $categories = null;
|
||||||
@@ -230,7 +296,7 @@ function bratonien_tools_filter_derivative_url($url, $params, $src_image, $rel_u
|
|||||||
return $url;
|
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']))
|
if ($rule['mode'] !== 'profile' || empty($rule['profile_id']))
|
||||||
{
|
{
|
||||||
return $url;
|
return $url;
|
||||||
|
|||||||
@@ -4,6 +4,53 @@ if (!defined('PHPWG_ROOT_PATH'))
|
|||||||
die('Hacking attempt!');
|
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_webdav_ondemand_derivative_url($image_id, $params)
|
||||||
|
{
|
||||||
|
$image_id = (int)$image_id;
|
||||||
|
if ($image_id < 1 || !is_object($params)) return null;
|
||||||
|
|
||||||
|
$type = trim((string)($params->type ?? ''));
|
||||||
|
if ($type === '') return null;
|
||||||
|
|
||||||
|
return get_root_url().'plugins/'.BRATONIEN_TOOLS_ID.'/webdav-derivative.php?id='.$image_id.'&type='.rawurlencode($type);
|
||||||
|
}
|
||||||
|
|
||||||
function bratonien_tools_filter_webdav_gallery_derivative_url($url, $params, $src_image, $rel_url)
|
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;
|
if (!is_object($src_image) || empty($src_image->id) || empty($src_image->rel_path)) return $url;
|
||||||
@@ -14,14 +61,14 @@ function bratonien_tools_filter_webdav_gallery_derivative_url($url, $params, $sr
|
|||||||
return $url;
|
return $url;
|
||||||
}
|
}
|
||||||
|
|
||||||
$derivative_path = '';
|
$image_id = (int)$src_image->id;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$derivative = new DerivativeImage($params, $src_image);
|
$derivative = new DerivativeImage($params, $src_image);
|
||||||
if (!$derivative->same_as_source())
|
if (!$derivative->same_as_source())
|
||||||
{
|
{
|
||||||
$derivative_path = $derivative->get_path();
|
$derivative_path = $derivative->get_path();
|
||||||
if ($derivative_path !== '' && is_file($derivative_path) && is_readable($derivative_path))
|
if (bratonien_tools_webdav_derivative_matches_preview($derivative_path, $params, $image_id))
|
||||||
{
|
{
|
||||||
return $url;
|
return $url;
|
||||||
}
|
}
|
||||||
@@ -29,39 +76,23 @@ function bratonien_tools_filter_webdav_gallery_derivative_url($url, $params, $sr
|
|||||||
}
|
}
|
||||||
catch (Throwable $e)
|
catch (Throwable $e)
|
||||||
{
|
{
|
||||||
error_log('Bratonien WebDAV derivative lookup #'.(int)$src_image->id.': '.$e->getMessage());
|
error_log('Bratonien WebDAV derivative lookup #'.$image_id.': '.$e->getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Auf der Picture-/Fotorama-Seite wird nicht mehr waehrend des HTML-Aufbaus
|
||||||
|
// synchron erzeugt. Fotorama arbeitet lazy: Erst wenn das konkrete Bild in
|
||||||
|
// den Fokus kommt und seine URL abruft, erzeugt dieser Endpoint genau dieses
|
||||||
|
// angeforderte Standard-Derivat aus dem bereits gecachten NC-Preview.
|
||||||
$script_name = basename((string)($_SERVER['SCRIPT_NAME'] ?? ''));
|
$script_name = basename((string)($_SERVER['SCRIPT_NAME'] ?? ''));
|
||||||
if ($script_name === 'picture.php' && function_exists('bratonien_tools_webdav_generate_derivative'))
|
if ($script_name === 'picture.php')
|
||||||
{
|
{
|
||||||
$detail = '';
|
$ondemand_url = bratonien_tools_webdav_ondemand_derivative_url($image_id, $params);
|
||||||
try
|
if ($ondemand_url) return $ondemand_url;
|
||||||
{
|
|
||||||
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 ($derivative_path !== '' && is_file($derivative_path) && is_readable($derivative_path))
|
|
||||||
{
|
|
||||||
return $url;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Throwable $e)
|
|
||||||
{
|
|
||||||
$detail = get_class($e).': '.$e->getMessage();
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($detail !== '')
|
|
||||||
{
|
|
||||||
error_log('Bratonien WebDAV picture derivative #'.(int)$src_image->id.': '.$detail);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$preview_url = bratonien_tools_webdav_image_url((int)$src_image->id, true);
|
// Galerie-Fallback: niemals Connector-Platzhalter ausliefern. Solange kein
|
||||||
|
// lokales korrektes Derivat vorliegt, wird das echte vorbereitete NC-Preview
|
||||||
|
// verwendet. Der eigentliche Galerie-Derivattyp wird beim Sync vorgebaut.
|
||||||
|
$preview_url = bratonien_tools_webdav_image_url($image_id, true);
|
||||||
return $preview_url ?: $url;
|
return $preview_url ?: $url;
|
||||||
}
|
}
|
||||||
+3
-1
@@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
/*
|
/*
|
||||||
Plugin Name: Bratonien Tools
|
Plugin Name: Bratonien Tools
|
||||||
Version: 0.9.7.9
|
Version: 0.9.7.13
|
||||||
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
|
||||||
@@ -28,11 +28,13 @@ require_once(BRATONIEN_TOOLS_PATH . 'include/nc_productive_ws.inc.php');
|
|||||||
require_once(BRATONIEN_TOOLS_PATH . 'include/nc_connector_scheduler.inc.php');
|
require_once(BRATONIEN_TOOLS_PATH . 'include/nc_connector_scheduler.inc.php');
|
||||||
|
|
||||||
add_event_handler('get_admin_plugin_menu_links', 'bratonien_tools_admin_menu');
|
add_event_handler('get_admin_plugin_menu_links', 'bratonien_tools_admin_menu');
|
||||||
|
add_event_handler('loc_end_index_category_thumbnails', 'bratonien_tools_watermark_prepare_album_overview');
|
||||||
add_event_handler('get_derivative_url', 'bratonien_tools_filter_derivative_url', EVENT_HANDLER_PRIORITY_NEUTRAL, 4);
|
add_event_handler('get_derivative_url', 'bratonien_tools_filter_derivative_url', EVENT_HANDLER_PRIORITY_NEUTRAL, 4);
|
||||||
add_event_handler('get_src_image_url', 'bratonien_tools_filter_webdav_src_url', EVENT_HANDLER_PRIORITY_NEUTRAL + 50, 2);
|
add_event_handler('get_src_image_url', 'bratonien_tools_filter_webdav_src_url', EVENT_HANDLER_PRIORITY_NEUTRAL + 50, 2);
|
||||||
add_event_handler('get_derivative_url', 'bratonien_tools_filter_webdav_gallery_derivative_url', EVENT_HANDLER_PRIORITY_NEUTRAL + 50, 4);
|
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('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('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_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_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);
|
||||||
|
|||||||
@@ -61,6 +61,7 @@ function bratonien_tools_save_album_rule()
|
|||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bratonien_tools_clear_watermark_cache();
|
||||||
return array('message'=>'Albumregel gespeichert.');
|
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;
|
$root = $by_id[$category_id] ?? null;
|
||||||
$is_private = $root && isset($root['status']) && $root['status'] === 'private';
|
$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 ($is_private)
|
||||||
{
|
{
|
||||||
if (isset($rules[$category_id]))
|
if (isset($rules[$category_id]))
|
||||||
|
|||||||
@@ -128,6 +128,7 @@ function bratonien_tools_save_watermark_profile()
|
|||||||
mass_inserts($table, array_keys($data), array($data));
|
mass_inserts($table, array_keys($data), array($data));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bratonien_tools_clear_watermark_cache();
|
||||||
return array('message'=>'Wasserzeichenprofil gespeichert.');
|
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);
|
pwg_query('DELETE FROM '.bratonien_tools_table('watermark_profiles').' WHERE id='.$id);
|
||||||
|
bratonien_tools_clear_watermark_cache();
|
||||||
return array('message'=>'Wasserzeichenprofil geloescht.');
|
return array('message'=>'Wasserzeichenprofil geloescht.');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -174,6 +176,7 @@ function bratonien_tools_duplicate_watermark_profile()
|
|||||||
$profile['name'] .= ' (Kopie)';
|
$profile['name'] .= ' (Kopie)';
|
||||||
$profile['created'] = date('Y-m-d H:i:s');
|
$profile['created'] = date('Y-m-d H:i:s');
|
||||||
mass_inserts(bratonien_tools_table('watermark_profiles'), array_keys($profile), array($profile));
|
mass_inserts(bratonien_tools_table('watermark_profiles'), array_keys($profile), array($profile));
|
||||||
|
bratonien_tools_clear_watermark_cache();
|
||||||
|
|
||||||
return array('message'=>'Wasserzeichenprofil dupliziert.');
|
return array('message'=>'Wasserzeichenprofil dupliziert.');
|
||||||
}
|
}
|
||||||
@@ -4,6 +4,59 @@ if (!defined('PHPWG_ROOT_PATH'))
|
|||||||
die('Hacking attempt!');
|
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()
|
function bratonien_tools_get_watermark_defaults()
|
||||||
{
|
{
|
||||||
$defaults = conf_get_param('bratonien_watermark_defaults', null);
|
$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));
|
conf_update_param('bratonien_watermark_defaults', json_encode($config));
|
||||||
|
bratonien_tools_clear_watermark_cache();
|
||||||
|
|
||||||
return array('message'=>'Globale Wasserzeichenregeln gespeichert.');
|
return array('message'=>'Globale Wasserzeichenregeln gespeichert.');
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,144 @@
|
|||||||
|
<?php
|
||||||
|
define('PHPWG_ROOT_PATH', '../../');
|
||||||
|
include_once(PHPWG_ROOT_PATH.'include/common.inc.php');
|
||||||
|
|
||||||
|
if (!defined('BRATONIEN_TOOLS_PATH'))
|
||||||
|
{
|
||||||
|
define('BRATONIEN_TOOLS_ID', basename(__DIR__));
|
||||||
|
define('BRATONIEN_TOOLS_PATH', PHPWG_ROOT_PATH.'plugins/'.BRATONIEN_TOOLS_ID.'/');
|
||||||
|
}
|
||||||
|
|
||||||
|
require_once(BRATONIEN_TOOLS_PATH.'include/webdav_image_runtime.inc.php');
|
||||||
|
require_once(BRATONIEN_TOOLS_PATH.'include/webdav_gallery_runtime.inc.php');
|
||||||
|
|
||||||
|
function bratonien_tools_webdav_derivative_abort($status, $message)
|
||||||
|
{
|
||||||
|
http_response_code((int)$status);
|
||||||
|
header('Content-Type: text/plain; charset=utf-8');
|
||||||
|
header('Cache-Control: no-store');
|
||||||
|
echo $message;
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
function bratonien_tools_webdav_derivative_fallback($image_id)
|
||||||
|
{
|
||||||
|
$url = bratonien_tools_webdav_image_url((int)$image_id, false);
|
||||||
|
if (!$url)
|
||||||
|
{
|
||||||
|
bratonien_tools_webdav_derivative_abort(404, 'WebDAV-Bildquelle ist nicht verfuegbar.');
|
||||||
|
}
|
||||||
|
|
||||||
|
header('Cache-Control: no-store');
|
||||||
|
header('Location: '.$url, true, 302);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$image_id = (int)($_GET['id'] ?? 0);
|
||||||
|
$type = trim((string)($_GET['type'] ?? ''));
|
||||||
|
if ($image_id < 1 || $type === '')
|
||||||
|
{
|
||||||
|
bratonien_tools_webdav_derivative_abort(400, 'Bild-ID oder Derivattyp fehlt.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$permission_condition = get_sql_condition_FandF(array('forbidden_categories'=>'category_id'), null, true);
|
||||||
|
$access_result = pwg_query('SELECT 1 FROM '.IMAGE_CATEGORY_TABLE.' WHERE image_id='.$image_id.' AND '.$permission_condition.' LIMIT 1');
|
||||||
|
if (!pwg_db_num_rows($access_result))
|
||||||
|
{
|
||||||
|
bratonien_tools_webdav_derivative_abort(403, 'Kein Zugriff auf dieses Bild.');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!class_exists('ImageStdParams') || !class_exists('DerivativeImage') || !class_exists('SrcImage'))
|
||||||
|
{
|
||||||
|
require_once(PHPWG_ROOT_PATH.'include/derivative.inc.php');
|
||||||
|
}
|
||||||
|
|
||||||
|
$params = @ImageStdParams::get_by_type($type);
|
||||||
|
if (!$params)
|
||||||
|
{
|
||||||
|
bratonien_tools_webdav_derivative_abort(404, 'Unbekannter Piwigo-Derivattyp.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = pwg_query('SELECT * FROM '.IMAGES_TABLE.' WHERE id='.$image_id.' LIMIT 1');
|
||||||
|
if (!pwg_db_num_rows($result))
|
||||||
|
{
|
||||||
|
bratonien_tools_webdav_derivative_abort(404, 'Bild wurde nicht gefunden.');
|
||||||
|
}
|
||||||
|
$row = pwg_db_fetch_assoc($result);
|
||||||
|
$src = new SrcImage($row);
|
||||||
|
$info = bratonien_tools_webdav_image_source_info($image_id);
|
||||||
|
if (!$info)
|
||||||
|
{
|
||||||
|
bratonien_tools_webdav_derivative_abort(404, 'Keine WebDAV-Quelle fuer dieses Bild gefunden.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$preview = bratonien_tools_webdav_preview_path($info);
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
$derivative = new DerivativeImage($params, $src);
|
||||||
|
if ($derivative->same_as_source())
|
||||||
|
{
|
||||||
|
// Niemals die lokale Connector-Platzhalterquelle ausliefern.
|
||||||
|
bratonien_tools_webdav_derivative_fallback($image_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
$target = $derivative->get_path();
|
||||||
|
if ($target === '')
|
||||||
|
{
|
||||||
|
bratonien_tools_webdav_derivative_fallback($image_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!bratonien_tools_webdav_derivative_matches_preview($target, $params, $image_id))
|
||||||
|
{
|
||||||
|
if (is_file($target))
|
||||||
|
{
|
||||||
|
@unlink($target);
|
||||||
|
clearstatcache(true, $target);
|
||||||
|
}
|
||||||
|
|
||||||
|
$detail = '';
|
||||||
|
if (!bratonien_tools_webdav_generate_derivative($params, $src, $detail))
|
||||||
|
{
|
||||||
|
error_log('Bratonien WebDAV on-demand derivative #'.$image_id.' type='.$type.': '.$detail);
|
||||||
|
bratonien_tools_webdav_derivative_fallback($image_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!bratonien_tools_webdav_derivative_matches_preview($target, $params, $image_id))
|
||||||
|
{
|
||||||
|
bratonien_tools_webdav_derivative_fallback($image_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
$size = @filesize($target);
|
||||||
|
$mtime = @filemtime($target) ?: time();
|
||||||
|
$etag = sha1($target.'|'.$mtime.'|'.($size ?: 0));
|
||||||
|
$extension = strtolower(pathinfo($target, PATHINFO_EXTENSION));
|
||||||
|
$content_type = 'image/jpeg';
|
||||||
|
if ($extension === 'png') $content_type = 'image/png';
|
||||||
|
elseif ($extension === 'gif') $content_type = 'image/gif';
|
||||||
|
elseif ($extension === 'webp') $content_type = 'image/webp';
|
||||||
|
|
||||||
|
header('Content-Type: '.$content_type);
|
||||||
|
if ($size !== false) header('Content-Length: '.(string)$size);
|
||||||
|
header('ETag: "'.$etag.'"');
|
||||||
|
header('Last-Modified: '.gmdate('D, d M Y H:i:s', $mtime).' GMT');
|
||||||
|
header('Cache-Control: private, max-age=86400, must-revalidate');
|
||||||
|
header('X-Content-Type-Options: nosniff');
|
||||||
|
|
||||||
|
$client_etag = trim((string)($_SERVER['HTTP_IF_NONE_MATCH'] ?? ''), " \t\r\n\"");
|
||||||
|
if ($client_etag !== '' && hash_equals($etag, $client_etag))
|
||||||
|
{
|
||||||
|
http_response_code(304);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (($_SERVER['REQUEST_METHOD'] ?? 'GET') !== 'HEAD')
|
||||||
|
{
|
||||||
|
readfile($target);
|
||||||
|
}
|
||||||
Reference in new issue
Block a user