mirror of
https://github.com/Terranom674/Piwigo_Bratonien_Tools.git
synced 2026-09-19 11:44:31 +00:00
Version watermark URLs with profile settings
This commit is contained in:
@@ -52,11 +52,11 @@ function bratonien_tools_runtime_effective_rule($category_id)
|
||||
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;
|
||||
$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)
|
||||
@@ -88,6 +88,27 @@ function bratonien_tools_profile_watermark_path(array $profile)
|
||||
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)
|
||||
{
|
||||
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'];
|
||||
$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='.
|
||||
rawurlencode(bratonien_tools_runtime_b64url_encode($rel_url)).'&s='.$signature;
|
||||
return get_root_url().'plugins/'.BRATONIEN_TOOLS_ID.'/watermark.php?p='.$profile_id.'&v='.
|
||||
rawurlencode($profile_version).'&u='.rawurlencode(bratonien_tools_runtime_b64url_encode($rel_url)).'&s='.$signature;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user