mirror of
https://github.com/Terranom674/Piwigo_Bratonien_Tools.git
synced 2026-09-19 23:24:36 +00:00
Compare commits
12 Commits
fix/09715-
...
fix/09717-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c772010137 | ||
|
|
d075d05708 | ||
|
|
a4fb7421f0 | ||
|
|
9da08b5d8e | ||
|
|
f28365b0ca | ||
|
|
fb6c1a03d2 | ||
|
|
98d0471683 | ||
|
|
63eba888f8 | ||
|
|
748b0e986d | ||
|
|
c1281ad077 | ||
|
|
bc0593642c | ||
|
|
9052076fd7 |
@@ -28,18 +28,34 @@ function bratonien_tools_nc_connector_webdav_site_id(array $connection)
|
|||||||
return (int)$row['id'];
|
return (int)$row['id'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function bratonien_tools_nc_connector_gallery_db_prefix(array $connection)
|
||||||
|
{
|
||||||
|
$config = isset($connection['config']) && is_array($connection['config']) ? $connection['config'] : array();
|
||||||
|
$gallery_root = rtrim((string)($config['parallel_gallery_root'] ?? ''), '/');
|
||||||
|
$piwigo_root = rtrim(PHPWG_ROOT_PATH, '/');
|
||||||
|
if ($gallery_root === '' || strpos($gallery_root, $piwigo_root.'/') !== 0) return '';
|
||||||
|
|
||||||
|
$relative = ltrim(substr($gallery_root, strlen($piwigo_root)), '/');
|
||||||
|
return $relative === '' ? '' : './'.rtrim($relative, '/').'/';
|
||||||
|
}
|
||||||
|
|
||||||
function bratonien_tools_nc_connector_remove_webdav_piwigo_content(array $connection)
|
function bratonien_tools_nc_connector_remove_webdav_piwigo_content(array $connection)
|
||||||
{
|
{
|
||||||
$site_id = bratonien_tools_nc_connector_webdav_site_id($connection);
|
|
||||||
if ($site_id < 1) return array('site_id'=>0, 'images'=>0);
|
|
||||||
|
|
||||||
include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
|
include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
|
||||||
|
|
||||||
|
$site_id = bratonien_tools_nc_connector_webdav_site_id($connection);
|
||||||
|
$db_prefix = bratonien_tools_nc_connector_gallery_db_prefix($connection);
|
||||||
|
if ($db_prefix === '') return array('site_id'=>$site_id, 'images'=>0);
|
||||||
|
|
||||||
|
$escaped = pwg_db_real_escape_string(addcslashes($db_prefix, '_%\\'));
|
||||||
$image_rows = array();
|
$image_rows = array();
|
||||||
$query = '\nSELECT DISTINCT i.id, i.path, i.representative_ext\n FROM '.IMAGES_TABLE.' AS i\n LEFT JOIN '.CATEGORIES_TABLE.' AS sc ON sc.id = i.storage_category_id\n LEFT JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON ic.image_id = i.id\n LEFT JOIN '.CATEGORIES_TABLE.' AS vc ON vc.id = ic.category_id\n WHERE sc.site_id = '.$site_id.' OR vc.site_id = '.$site_id.'\n;';
|
$result = pwg_query(
|
||||||
$result = pwg_query($query);
|
"SELECT id, path, representative_ext FROM ".IMAGES_TABLE.
|
||||||
|
" WHERE path LIKE '".$escaped."%' ESCAPE '\\\\'"
|
||||||
|
);
|
||||||
while ($row = pwg_db_fetch_assoc($result))
|
while ($row = pwg_db_fetch_assoc($result))
|
||||||
{
|
{
|
||||||
|
if (strpos((string)$row['path'], $db_prefix) !== 0) continue;
|
||||||
$row['id'] = (int)$row['id'];
|
$row['id'] = (int)$row['id'];
|
||||||
$image_rows[$row['id']] = $row;
|
$image_rows[$row['id']] = $row;
|
||||||
}
|
}
|
||||||
@@ -56,20 +72,14 @@ function bratonien_tools_nc_connector_remove_webdav_piwigo_content(array $connec
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
delete_site($site_id);
|
|
||||||
|
|
||||||
if ($image_rows)
|
if ($image_rows)
|
||||||
{
|
{
|
||||||
$ids = array_keys($image_rows);
|
delete_elements(array_map('intval', array_keys($image_rows)), false);
|
||||||
$remaining = query2array(
|
|
||||||
'SELECT id FROM '.IMAGES_TABLE.' WHERE id IN ('.implode(',', array_map('intval', $ids)).')',
|
|
||||||
null,
|
|
||||||
'id'
|
|
||||||
);
|
|
||||||
if ($remaining)
|
|
||||||
{
|
|
||||||
delete_elements(array_map('intval', $remaining), false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($site_id > 0)
|
||||||
|
{
|
||||||
|
delete_site($site_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
invalidate_user_cache(true);
|
invalidate_user_cache(true);
|
||||||
@@ -110,14 +120,7 @@ function bratonien_tools_nc_connector_delete_safe()
|
|||||||
@file_put_contents($status_dir.'/deleted-'.$id, date('c')."\n", LOCK_EX);
|
@file_put_contents($status_dir.'/deleted-'.$id, date('c')."\n", LOCK_EX);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((int)$cleanup['site_id'] > 0)
|
|
||||||
{
|
|
||||||
return array(
|
return array(
|
||||||
'message'=>'Verbindung wurde gelöscht. Die zugehörigen Piwigo-Alben und '.(int)$cleanup['images'].' Bilder wurden aus Piwigo entfernt. Nextcloud-Dateien blieben unverändert.',
|
'message'=>'Verbindung wurde gelöscht. '.(int)$cleanup['images'].' eindeutig zu dieser Verbindung gehörende Bilder wurden aus Piwigo entfernt. Nextcloud-Dateien blieben unverändert.',
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return array(
|
|
||||||
'message'=>'Verbindung wurde gelöscht. Verbliebene Laufzeitdaten werden automatisch bereinigt. Quelldateien blieben unverändert.',
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,98 +0,0 @@
|
|||||||
<?php
|
|
||||||
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_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)
|
|
||||||
{
|
|
||||||
if (!is_object($src_image) || empty($src_image->id) || empty($src_image->rel_path)) return $url;
|
|
||||||
|
|
||||||
$source_path = str_replace('\\', '/', (string)$src_image->rel_path);
|
|
||||||
if (!preg_match('#/nc-webdav-source/connection-[0-9]+/root-[0-9]+/.+$#', $source_path))
|
|
||||||
{
|
|
||||||
return $url;
|
|
||||||
}
|
|
||||||
|
|
||||||
$image_id = (int)$src_image->id;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
$derivative = new DerivativeImage($params, $src_image);
|
|
||||||
if (!$derivative->same_as_source())
|
|
||||||
{
|
|
||||||
$derivative_path = $derivative->get_path();
|
|
||||||
if (bratonien_tools_webdav_derivative_matches_preview($derivative_path, $params, $image_id))
|
|
||||||
{
|
|
||||||
return $url;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Throwable $e)
|
|
||||||
{
|
|
||||||
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'] ?? ''));
|
|
||||||
if ($script_name === 'picture.php')
|
|
||||||
{
|
|
||||||
$ondemand_url = bratonien_tools_webdav_ondemand_derivative_url($image_id, $params);
|
|
||||||
if ($ondemand_url) return $ondemand_url;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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;
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
/*
|
/*
|
||||||
Plugin Name: Bratonien Tools
|
Plugin Name: Bratonien Tools
|
||||||
Version: 0.9.7.15
|
Version: 0.9.7.17
|
||||||
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
|
||||||
@@ -17,7 +17,6 @@ define('BRATONIEN_TOOLS_PATH', PHPWG_PLUGINS_PATH . BRATONIEN_TOOLS_ID . '/');
|
|||||||
|
|
||||||
require_once(BRATONIEN_TOOLS_PATH . 'include/watermark_runtime.inc.php');
|
require_once(BRATONIEN_TOOLS_PATH . 'include/watermark_runtime.inc.php');
|
||||||
require_once(BRATONIEN_TOOLS_PATH . 'include/webdav_image_runtime.inc.php');
|
require_once(BRATONIEN_TOOLS_PATH . 'include/webdav_image_runtime.inc.php');
|
||||||
require_once(BRATONIEN_TOOLS_PATH . 'include/webdav_gallery_runtime.inc.php');
|
|
||||||
require_once(BRATONIEN_TOOLS_PATH . 'include/public_selection.inc.php');
|
require_once(BRATONIEN_TOOLS_PATH . 'include/public_selection.inc.php');
|
||||||
require_once(BRATONIEN_TOOLS_PATH . 'include/picture_navigation.inc.php');
|
require_once(BRATONIEN_TOOLS_PATH . 'include/picture_navigation.inc.php');
|
||||||
require_once(BRATONIEN_TOOLS_PATH . 'include/batch_titles.inc.php');
|
require_once(BRATONIEN_TOOLS_PATH . 'include/batch_titles.inc.php');
|
||||||
@@ -31,7 +30,6 @@ 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('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('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_watermark_cache_upgrade', EVENT_HANDLER_PRIORITY_NEUTRAL - 40);
|
||||||
|
|||||||
@@ -56,6 +56,15 @@ normalize_connector_cache_permissions() {
|
|||||||
# werden zumindest alle eigenen Dateien gruppenschreibbar gehalten.
|
# werden zumindest alle eigenen Dateien gruppenschreibbar gehalten.
|
||||||
normalize_connector_cache_permissions
|
normalize_connector_cache_permissions
|
||||||
|
|
||||||
|
# Dieser Medienlauf wird erst nach einem erfolgreichen WebDAV-Aufbau und einer
|
||||||
|
# erfolgreichen Piwigo-Synchronisierung gestartet. Deshalb darf erst hier aus
|
||||||
|
# "lokale Connector-Datei fehlt" auf eine in Nextcloud entfernte Freigabe/Datei
|
||||||
|
# geschlossen werden. Bei einer nicht erreichbaren Verbindung wird dieser Block
|
||||||
|
# niemals ausgeführt und der vorhandene Piwigo-Bestand bleibt unverändert.
|
||||||
|
php "$SCRIPT_DIR/cleanup-missing-webdav-images.php" \
|
||||||
|
--piwigo-root="$PIWIGO_ROOT" \
|
||||||
|
--connection-id="$CONNECTION_ID"
|
||||||
|
|
||||||
php "$SCRIPT_DIR/lib/precache-webdav-previews.php" \
|
php "$SCRIPT_DIR/lib/precache-webdav-previews.php" \
|
||||||
--mapping="$WEBDAV_MAPPING_FILE" \
|
--mapping="$WEBDAV_MAPPING_FILE" \
|
||||||
--base-url="$WEBDAV_BASE_URL" \
|
--base-url="$WEBDAV_BASE_URL" \
|
||||||
|
|||||||
124
runtime/cleanup-missing-webdav-images.php
Normal file
124
runtime/cleanup-missing-webdav-images.php
Normal file
@@ -0,0 +1,124 @@
|
|||||||
|
#!/usr/bin/env php
|
||||||
|
<?php
|
||||||
|
if (PHP_SAPI !== 'cli')
|
||||||
|
{
|
||||||
|
fwrite(STDERR, "CLI only\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
$options = getopt('', array('piwigo-root:', 'connection-id:'));
|
||||||
|
$piwigo_root = rtrim((string)($options['piwigo-root'] ?? ''), '/');
|
||||||
|
$connection_id = (int)($options['connection-id'] ?? 0);
|
||||||
|
if ($piwigo_root === '' || $connection_id < 1)
|
||||||
|
{
|
||||||
|
fwrite(STDERR, "Parameter --piwigo-root und --connection-id werden benoetigt.\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
$db_config = $piwigo_root.'/local/config/database.inc.php';
|
||||||
|
if (!is_readable($db_config))
|
||||||
|
{
|
||||||
|
fwrite(STDERR, "Piwigo-Datenbankkonfiguration ist nicht lesbar.\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
$conf = array();
|
||||||
|
$prefixeTable = 'piwigo_';
|
||||||
|
require $db_config;
|
||||||
|
foreach (array('db_host','db_user','db_password','db_base') as $key)
|
||||||
|
{
|
||||||
|
if (!isset($conf[$key]))
|
||||||
|
{
|
||||||
|
fwrite(STDERR, "Piwigo-Datenbankkonfiguration ist unvollstaendig: $key\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$db = new mysqli($conf['db_host'], $conf['db_user'], $conf['db_password'], $conf['db_base']);
|
||||||
|
if ($db->connect_errno)
|
||||||
|
{
|
||||||
|
fwrite(STDERR, "Piwigo-Datenbank ist nicht erreichbar: ".$db->connect_error."\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
$db->set_charset('utf8mb4');
|
||||||
|
|
||||||
|
$table = $prefixeTable.'bratonien_tools_nc_connections';
|
||||||
|
$result = $db->query('SELECT config_json FROM `'.$table.'` WHERE id='.$connection_id.' LIMIT 1');
|
||||||
|
if (!$result || !$result->num_rows)
|
||||||
|
{
|
||||||
|
fwrite(STDERR, "Connector-Verbindung #$connection_id wurde nicht gefunden.\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
$config = json_decode((string)$result->fetch_assoc()['config_json'], true);
|
||||||
|
if (!is_array($config) || (string)($config['source_mode'] ?? '') !== 'webdav-placeholder')
|
||||||
|
{
|
||||||
|
echo "Keine WebDAV-Bereinigung erforderlich.\n";
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
$gallery_root = rtrim((string)($config['parallel_gallery_root'] ?? ''), '/');
|
||||||
|
if ($gallery_root === '' || strpos($gallery_root, $piwigo_root.'/') !== 0)
|
||||||
|
{
|
||||||
|
fwrite(STDERR, "Verbindungseigene Gallery-Root ist ungueltig.\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
$relative = ltrim(substr($gallery_root, strlen($piwigo_root)), '/');
|
||||||
|
$db_prefix = './'.rtrim($relative, '/').'/';
|
||||||
|
$escaped_prefix = $db->real_escape_string(addcslashes($db_prefix, "_%\\"));
|
||||||
|
$images_table = $prefixeTable.'images';
|
||||||
|
$query = "SELECT id, path FROM `{$images_table}` WHERE path LIKE '{$escaped_prefix}%' ESCAPE '\\\\'";
|
||||||
|
$rows = $db->query($query);
|
||||||
|
if (!$rows)
|
||||||
|
{
|
||||||
|
fwrite(STDERR, "Connector-Bilder konnten nicht gelesen werden: ".$db->error."\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
$missing_ids = array();
|
||||||
|
while ($row = $rows->fetch_assoc())
|
||||||
|
{
|
||||||
|
$path = (string)$row['path'];
|
||||||
|
if (strpos($path, $db_prefix) !== 0)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$absolute = $piwigo_root.'/'.ltrim(preg_replace('#^\\./#', '', $path), '/');
|
||||||
|
if (!is_file($absolute))
|
||||||
|
{
|
||||||
|
$missing_ids[] = (int)$row['id'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$db->close();
|
||||||
|
|
||||||
|
if (!$missing_ids)
|
||||||
|
{
|
||||||
|
echo "WebDAV-Bereinigung: keine fehlenden Piwigo-Bilder.\n";
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Erst jetzt Piwigo bootstrappen. Dieser Prozess wird nur nach einem erfolgreich
|
||||||
|
// abgeschlossenen WebDAV-Abruf gestartet. Eine nicht erreichbare Verbindung kann
|
||||||
|
// daher niemals ueber diesen Pfad Bilder loeschen.
|
||||||
|
define('PHPWG_ROOT_PATH', $piwigo_root.'/');
|
||||||
|
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
|
||||||
|
$_SERVER['SERVER_ADDR'] = '127.0.0.1';
|
||||||
|
$_SERVER['SERVER_NAME'] = 'localhost';
|
||||||
|
$_SERVER['HTTP_HOST'] = 'localhost';
|
||||||
|
$_SERVER['SERVER_PORT'] = '80';
|
||||||
|
$_SERVER['REQUEST_METHOD'] = 'GET';
|
||||||
|
$_SERVER['REQUEST_URI'] = '/';
|
||||||
|
$_SERVER['SCRIPT_NAME'] = '/plugins/bratonien_tools/runtime/cleanup-missing-webdav-images.php';
|
||||||
|
$_SERVER['PHP_SELF'] = $_SERVER['SCRIPT_NAME'];
|
||||||
|
$_SERVER['QUERY_STRING'] = '';
|
||||||
|
$_SERVER['HTTPS'] = 'off';
|
||||||
|
|
||||||
|
require_once(PHPWG_ROOT_PATH.'include/common.inc.php');
|
||||||
|
include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
|
||||||
|
|
||||||
|
delete_elements($missing_ids, false);
|
||||||
|
update_category('all');
|
||||||
|
invalidate_user_cache(true);
|
||||||
|
|
||||||
|
echo 'WebDAV-Bereinigung: '.count($missing_ids)." nicht mehr freigegebene/ vorhandene Bilder aus Piwigo entfernt.\n";
|
||||||
@@ -34,7 +34,7 @@ function fetch_remote_blob($url, $user, $password)
|
|||||||
CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
|
CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
|
||||||
CURLOPT_USERPWD => $user.':'.$password,
|
CURLOPT_USERPWD => $user.':'.$password,
|
||||||
CURLOPT_FAILONERROR => false,
|
CURLOPT_FAILONERROR => false,
|
||||||
CURLOPT_USERAGENT => 'Bratonien-Tools-WebDAV-Precache/0.9.7.1',
|
CURLOPT_USERAGENT => 'Bratonien-Tools-WebDAV-Precache/0.9.7.16',
|
||||||
);
|
);
|
||||||
bratonien_tools_nc_transport_apply_curl($options, $url);
|
bratonien_tools_nc_transport_apply_curl($options, $url);
|
||||||
curl_setopt_array($ch, $options);
|
curl_setopt_array($ch, $options);
|
||||||
@@ -52,12 +52,11 @@ function fetch_remote_blob($url, $user, $password)
|
|||||||
|
|
||||||
function preview_extension_for_entry(array $entry)
|
function preview_extension_for_entry(array $entry)
|
||||||
{
|
{
|
||||||
$content_type = strtolower(trim((string)($entry['content_type'] ?? '')));
|
|
||||||
$path = strtolower((string)($entry['webdav_path'] ?? ''));
|
$path = strtolower((string)($entry['webdav_path'] ?? ''));
|
||||||
if ($content_type === 'image/png' || preg_match('/\.png$/', $path))
|
$extension = strtolower(pathinfo($path, PATHINFO_EXTENSION));
|
||||||
{
|
if ($extension === 'png') return 'png';
|
||||||
return 'png';
|
if ($extension === 'gif') return 'gif';
|
||||||
}
|
if ($extension === 'webp') return 'webp';
|
||||||
return 'jpg';
|
return 'jpg';
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,7 +67,7 @@ function preview_target_for_entry($cache_dir, $key, array $entry)
|
|||||||
|
|
||||||
function remove_other_preview_format($cache_dir, $key, $keep_target)
|
function remove_other_preview_format($cache_dir, $key, $keep_target)
|
||||||
{
|
{
|
||||||
foreach (array('jpg', 'png', 'webp') as $ext)
|
foreach (array('jpg', 'png', 'gif', 'webp') as $ext)
|
||||||
{
|
{
|
||||||
$candidate = $cache_dir.'/'.$key.'.'.$ext;
|
$candidate = $cache_dir.'/'.$key.'.'.$ext;
|
||||||
if ($candidate !== $keep_target && is_file($candidate)) @unlink($candidate);
|
if ($candidate !== $keep_target && is_file($candidate)) @unlink($candidate);
|
||||||
@@ -90,13 +89,19 @@ function write_preview_imagick($blob, $target, $extension)
|
|||||||
{
|
{
|
||||||
$image->setImageFormat('png');
|
$image->setImageFormat('png');
|
||||||
}
|
}
|
||||||
|
elseif ($extension === 'gif')
|
||||||
|
{
|
||||||
|
$image->setImageFormat('gif');
|
||||||
|
}
|
||||||
|
elseif ($extension === 'webp')
|
||||||
|
{
|
||||||
|
$image->setImageFormat('webp');
|
||||||
|
$image->setImageCompressionQuality(BRATONIEN_WEBDAV_PREVIEW_JPEG_QUALITY);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$image->setImageBackgroundColor('white');
|
$image->setImageBackgroundColor('white');
|
||||||
if (method_exists($image, 'mergeImageLayers'))
|
if (method_exists($image, 'mergeImageLayers')) $image = $image->mergeImageLayers(Imagick::LAYERMETHOD_FLATTEN);
|
||||||
{
|
|
||||||
$image = $image->mergeImageLayers(Imagick::LAYERMETHOD_FLATTEN);
|
|
||||||
}
|
|
||||||
$image->setImageFormat('jpeg');
|
$image->setImageFormat('jpeg');
|
||||||
$image->setImageCompression(Imagick::COMPRESSION_JPEG);
|
$image->setImageCompression(Imagick::COMPRESSION_JPEG);
|
||||||
$image->setImageCompressionQuality(BRATONIEN_WEBDAV_PREVIEW_JPEG_QUALITY);
|
$image->setImageCompressionQuality(BRATONIEN_WEBDAV_PREVIEW_JPEG_QUALITY);
|
||||||
@@ -131,7 +136,7 @@ function write_preview_gd($blob, $target, $extension)
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if ($extension === 'png')
|
if (in_array($extension, array('png', 'gif', 'webp'), true))
|
||||||
{
|
{
|
||||||
imagealphablending($preview, false);
|
imagealphablending($preview, false);
|
||||||
imagesavealpha($preview, true);
|
imagesavealpha($preview, true);
|
||||||
@@ -149,10 +154,12 @@ function write_preview_gd($blob, $target, $extension)
|
|||||||
fail_preview('GD konnte das Preview nicht skalieren.');
|
fail_preview('GD konnte das Preview nicht skalieren.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$written = $extension === 'png'
|
if ($extension === 'png') $written = imagepng($preview, $target, 6);
|
||||||
? imagepng($preview, $target, 6)
|
elseif ($extension === 'gif') $written = function_exists('imagegif') ? imagegif($preview, $target) : false;
|
||||||
: imagejpeg($preview, $target, BRATONIEN_WEBDAV_PREVIEW_JPEG_QUALITY);
|
elseif ($extension === 'webp') $written = function_exists('imagewebp') ? imagewebp($preview, $target, BRATONIEN_WEBDAV_PREVIEW_JPEG_QUALITY) : false;
|
||||||
if (!$written) fail_preview('GD konnte das Preview nicht schreiben.');
|
else $written = imagejpeg($preview, $target, BRATONIEN_WEBDAV_PREVIEW_JPEG_QUALITY);
|
||||||
|
|
||||||
|
if (!$written) fail_preview('GD konnte das Preview im Format '.$extension.' nicht schreiben.');
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
@@ -168,7 +175,7 @@ function write_preview_gd($blob, $target, $extension)
|
|||||||
function write_preview($blob, $target, $extension)
|
function write_preview($blob, $target, $extension)
|
||||||
{
|
{
|
||||||
$dir = dirname($target);
|
$dir = dirname($target);
|
||||||
if (!is_dir($dir) && !mkdir($dir, 0755, true) && !is_dir($dir)) fail_preview('Preview-Verzeichnis konnte nicht angelegt werden.');
|
if (!is_dir($dir) && !mkdir($dir, 0775, true) && !is_dir($dir)) fail_preview('Preview-Verzeichnis konnte nicht angelegt werden.');
|
||||||
|
|
||||||
if (class_exists('Imagick'))
|
if (class_exists('Imagick'))
|
||||||
{
|
{
|
||||||
@@ -190,7 +197,48 @@ function write_preview($blob, $target, $extension)
|
|||||||
@unlink($target);
|
@unlink($target);
|
||||||
fail_preview('Das erzeugte Preview ist ungültig.');
|
fail_preview('Das erzeugte Preview ist ungültig.');
|
||||||
}
|
}
|
||||||
@chmod($target, 0644);
|
@chmod($target, 0664);
|
||||||
|
}
|
||||||
|
|
||||||
|
function local_source_is_hydrated($source_path, $preview)
|
||||||
|
{
|
||||||
|
if (!is_file($source_path) || !is_readable($source_path)) return false;
|
||||||
|
$source_size = @getimagesize($source_path);
|
||||||
|
$preview_size = @getimagesize($preview);
|
||||||
|
if (!is_array($source_size) || !is_array($preview_size)) return false;
|
||||||
|
if ((int)$source_size[0] !== (int)$preview_size[0] || (int)$source_size[1] !== (int)$preview_size[1]) return false;
|
||||||
|
$source_bytes = @filesize($source_path);
|
||||||
|
$preview_bytes = @filesize($preview);
|
||||||
|
return $source_bytes !== false && $preview_bytes !== false && (int)$source_bytes === (int)$preview_bytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
function hydrate_local_source($source_path, $preview)
|
||||||
|
{
|
||||||
|
$normalized = str_replace('\\', '/', (string)$source_path);
|
||||||
|
if (!preg_match('#/nc-webdav-source/connection-[0-9]+/root-[0-9]+/#', $normalized))
|
||||||
|
{
|
||||||
|
fail_preview('Unsicherer lokaler Connector-Quellpfad: '.$source_path);
|
||||||
|
}
|
||||||
|
if (!is_file($preview) || !is_readable($preview)) fail_preview('Preview für lokale Quelle fehlt: '.$preview);
|
||||||
|
if (local_source_is_hydrated($source_path, $preview)) return false;
|
||||||
|
|
||||||
|
$dir = dirname($source_path);
|
||||||
|
if (!is_dir($dir) && !mkdir($dir, 0775, true) && !is_dir($dir)) fail_preview('Lokales Connector-Verzeichnis konnte nicht angelegt werden: '.$dir);
|
||||||
|
|
||||||
|
$tmp = $source_path.'.bratonien-next-'.getmypid();
|
||||||
|
if (!@copy($preview, $tmp)) fail_preview('Preview konnte nicht in lokale Piwigo-Quelle kopiert werden: '.$source_path);
|
||||||
|
@chmod($tmp, 0664);
|
||||||
|
$mtime = @filemtime($preview);
|
||||||
|
if ($mtime) @touch($tmp, $mtime);
|
||||||
|
if (!@rename($tmp, $source_path))
|
||||||
|
{
|
||||||
|
@unlink($tmp);
|
||||||
|
fail_preview('Lokale Piwigo-Quelle konnte nicht ersetzt werden: '.$source_path);
|
||||||
|
}
|
||||||
|
clearstatcache(true, $source_path);
|
||||||
|
$size = @getimagesize($source_path);
|
||||||
|
if (!is_array($size) || empty($size[0]) || empty($size[1])) fail_preview('Lokale Piwigo-Quelle ist nach dem Ersetzen ungültig: '.$source_path);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
@@ -212,8 +260,8 @@ try
|
|||||||
$mapping = json_decode((string)file_get_contents($mapping_file), true);
|
$mapping = json_decode((string)file_get_contents($mapping_file), true);
|
||||||
if (!is_array($mapping) || !isset($mapping['files']) || !is_array($mapping['files'])) fail_preview('WebDAV-Mapping ist ungültig.');
|
if (!is_array($mapping) || !isset($mapping['files']) || !is_array($mapping['files'])) fail_preview('WebDAV-Mapping ist ungültig.');
|
||||||
|
|
||||||
if (!is_dir($cache_dir) && !mkdir($cache_dir, 0755, true) && !is_dir($cache_dir)) fail_preview('Preview-Cache konnte nicht angelegt werden.');
|
if (!is_dir($cache_dir) && !mkdir($cache_dir, 0775, true) && !is_dir($cache_dir)) fail_preview('Preview-Cache konnte nicht angelegt werden.');
|
||||||
@chmod($cache_dir, 0755);
|
@chmod($cache_dir, 2775);
|
||||||
|
|
||||||
$state_file = $cache_dir.'/state.json';
|
$state_file = $cache_dir.'/state.json';
|
||||||
$old_state = array();
|
$old_state = array();
|
||||||
@@ -226,9 +274,10 @@ try
|
|||||||
$new_state = array();
|
$new_state = array();
|
||||||
$generated = 0;
|
$generated = 0;
|
||||||
$cached = 0;
|
$cached = 0;
|
||||||
|
$hydrated = 0;
|
||||||
$errors = 0;
|
$errors = 0;
|
||||||
|
|
||||||
foreach ($mapping['files'] as $entry)
|
foreach ($mapping['files'] as $local_path=>$entry)
|
||||||
{
|
{
|
||||||
if (!is_array($entry) || (string)($entry['kind'] ?? '') !== 'file') continue;
|
if (!is_array($entry) || (string)($entry['kind'] ?? '') !== 'file') continue;
|
||||||
$webdav_path = trim((string)($entry['webdav_path'] ?? ''), '/');
|
$webdav_path = trim((string)($entry['webdav_path'] ?? ''), '/');
|
||||||
@@ -245,20 +294,16 @@ try
|
|||||||
'version' => BRATONIEN_WEBDAV_PREVIEW_VERSION,
|
'version' => BRATONIEN_WEBDAV_PREVIEW_VERSION,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
$old = $old_state[$key] ?? null;
|
$old = $old_state[$key] ?? null;
|
||||||
if (
|
$valid_cached = is_file($target)
|
||||||
is_file($target)
|
|
||||||
&& is_array($old)
|
&& is_array($old)
|
||||||
&& (string)($old['etag'] ?? '') === $etag
|
&& (string)($old['etag'] ?? '') === $etag
|
||||||
&& (string)($old['format'] ?? '') === $extension
|
&& (string)($old['format'] ?? '') === $extension
|
||||||
&& (int)($old['version'] ?? 0) === BRATONIEN_WEBDAV_PREVIEW_VERSION
|
&& (int)($old['version'] ?? 0) === BRATONIEN_WEBDAV_PREVIEW_VERSION;
|
||||||
)
|
|
||||||
{
|
|
||||||
$cached++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
if (!$valid_cached)
|
||||||
{
|
{
|
||||||
$url = $base_url.'/remote.php/dav/files/'.rawurlencode($user).'/'.quote_webdav_path($webdav_path);
|
$url = $base_url.'/remote.php/dav/files/'.rawurlencode($user).'/'.quote_webdav_path($webdav_path);
|
||||||
$blob = fetch_remote_blob($url, $user, $password);
|
$blob = fetch_remote_blob($url, $user, $password);
|
||||||
@@ -266,6 +311,13 @@ try
|
|||||||
remove_other_preview_format($cache_dir, $key, $target);
|
remove_other_preview_format($cache_dir, $key, $target);
|
||||||
$generated++;
|
$generated++;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$cached++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hydrate_local_source((string)$local_path, $target)) $hydrated++;
|
||||||
|
}
|
||||||
catch (Throwable $e)
|
catch (Throwable $e)
|
||||||
{
|
{
|
||||||
$errors++;
|
$errors++;
|
||||||
@@ -277,14 +329,14 @@ try
|
|||||||
{
|
{
|
||||||
if (!is_file($file) || basename($file) === 'state.json') continue;
|
if (!is_file($file) || basename($file) === 'state.json') continue;
|
||||||
$name = basename($file);
|
$name = basename($file);
|
||||||
if (!preg_match('/^([a-f0-9]{40})\.(jpg|png|webp)$/', $name, $m)) continue;
|
if (!preg_match('/^([a-f0-9]{40})\.(jpg|png|gif|webp)$/', $name, $m)) continue;
|
||||||
if (!isset($new_state[$m[1]])) @unlink($file);
|
if (!isset($new_state[$m[1]])) @unlink($file);
|
||||||
}
|
}
|
||||||
|
|
||||||
file_put_contents($state_file, json_encode($new_state, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT)."\n", LOCK_EX);
|
file_put_contents($state_file, json_encode($new_state, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT)."\n", LOCK_EX);
|
||||||
@chmod($state_file, 0644);
|
@chmod($state_file, 0664);
|
||||||
|
|
||||||
echo 'WebDAV-Previews: erzeugt='.$generated.' vorhanden='.$cached.' fehler='.$errors."\n";
|
echo 'WebDAV-Previews: erzeugt='.$generated.' vorhanden='.$cached.' lokale_quellen='.$hydrated.' fehler='.$errors."\n";
|
||||||
exit($errors > 0 ? 1 : 0);
|
exit($errors > 0 ? 1 : 0);
|
||||||
}
|
}
|
||||||
catch (Throwable $e)
|
catch (Throwable $e)
|
||||||
|
|||||||
@@ -1,169 +0,0 @@
|
|||||||
<?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_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)
|
|
||||||
{
|
|
||||||
$url = bratonien_tools_webdav_image_url((int)$image_id, false);
|
|
||||||
if (!$url)
|
|
||||||
{
|
|
||||||
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('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))
|
|
||||||
{
|
|
||||||
bratonien_tools_webdav_derivative_fallback($image_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
$derivative = new DerivativeImage($params, $src);
|
|
||||||
if ($derivative->same_as_source())
|
|
||||||
{
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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);
|
|
||||||
$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);
|
|
||||||
}
|
|
||||||
@@ -19,18 +19,6 @@ 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);
|
||||||
@@ -64,17 +52,7 @@ 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.');
|
||||||
|
|
||||||
$preview_requested = !empty($_GET['preview']);
|
if (!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)
|
||||||
@@ -143,7 +121,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.15',
|
CURLOPT_USERAGENT => 'Bratonien-Tools-WebDAV-Image/0.9.7.16',
|
||||||
CURLOPT_HEADERFUNCTION => function($ch, $line)
|
CURLOPT_HEADERFUNCTION => function($ch, $line)
|
||||||
{
|
{
|
||||||
$length = strlen($line);
|
$length = strlen($line);
|
||||||
|
|||||||
Reference in New Issue
Block a user