Version watermark URLs with profile settings

This commit is contained in:
Terranom674
2026-08-15 15:37:10 +02:00
parent ec450713f8
commit 46b9ee94dc

View File

@@ -52,11 +52,11 @@ function bratonien_tools_runtime_effective_rule($category_id)
return bratonien_tools_resolve_album_rule((int)$category_id, $categories, $rules, $defaults); return bratonien_tools_resolve_album_rule((int)$category_id, $categories, $rules, $defaults);
} }
function bratonien_tools_runtime_sign($rel_url, $profile_id) function bratonien_tools_runtime_sign($rel_url, $profile_id, $profile_version='')
{ {
global $conf; global $conf;
$key = !empty($conf['secret_key']) ? $conf['secret_key'] : ($conf['db_password'] ?? 'bratonien-tools'); $key = !empty($conf['secret_key']) ? $conf['secret_key'] : ($conf['db_password'] ?? 'bratonien-tools');
return hash_hmac('sha256', $profile_id.'|'.$rel_url, $key); return hash_hmac('sha256', $profile_id.'|'.$profile_version.'|'.$rel_url, $key);
} }
function bratonien_tools_runtime_b64url_encode($value) function bratonien_tools_runtime_b64url_encode($value)
@@ -88,6 +88,27 @@ function bratonien_tools_profile_watermark_path(array $profile)
return $path; return $path;
} }
function bratonien_tools_runtime_profile_version(array $profile)
{
$watermark_path = bratonien_tools_profile_watermark_path($profile);
$parts = array(
$profile['id'] ?? 0,
$profile['watermark_file'] ?? '',
$profile['scale_percent'] ?? 100,
$profile['xpos'] ?? 90,
$profile['ypos'] ?? 90,
$profile['xrepeat'] ?? 0,
$profile['yrepeat'] ?? 0,
$profile['opacity'] ?? 35,
$profile['min_width'] ?? 10,
$profile['min_height'] ?? 10,
$profile['active'] ?? 1,
$watermark_path ? @filemtime($watermark_path) : 0,
);
return substr(sha1(implode('|', $parts)), 0, 16);
}
function bratonien_tools_filter_derivative_url($url, $params, $src_image, $rel_url) function bratonien_tools_filter_derivative_url($url, $params, $src_image, $rel_url)
{ {
if (!bratonien_tools_watermark_engine_enabled()) if (!bratonien_tools_watermark_engine_enabled())
@@ -122,8 +143,9 @@ function bratonien_tools_filter_derivative_url($url, $params, $src_image, $rel_u
} }
$profile_id = (int)$profile['id']; $profile_id = (int)$profile['id'];
$signature = bratonien_tools_runtime_sign($rel_url, $profile_id); $profile_version = bratonien_tools_runtime_profile_version($profile);
$signature = bratonien_tools_runtime_sign($rel_url, $profile_id, $profile_version);
return get_root_url().'plugins/'.BRATONIEN_TOOLS_ID.'/watermark.php?p='.$profile_id.'&u='. return get_root_url().'plugins/'.BRATONIEN_TOOLS_ID.'/watermark.php?p='.$profile_id.'&v='.
rawurlencode(bratonien_tools_runtime_b64url_encode($rel_url)).'&s='.$signature; rawurlencode($profile_version).'&u='.rawurlencode(bratonien_tools_runtime_b64url_encode($rel_url)).'&s='.$signature;
} }