diff --git a/include/watermark_runtime.inc.php b/include/watermark_runtime.inc.php new file mode 100644 index 0000000..eba8966 --- /dev/null +++ b/include/watermark_runtime.inc.php @@ -0,0 +1,97 @@ +'disabled','profile_id'=>null,'source'=>'global'); + } + return array('mode'=>'profile','profile_id'=>(int)$defaults['public_profile'],'source'=>'global'); + } + + return bratonien_tools_resolve_album_rule((int)$category_id, $categories, $rules, $defaults); +} + +function bratonien_tools_runtime_sign($rel_url, $profile_id) +{ + global $conf; + $key = !empty($conf['secret_key']) ? $conf['secret_key'] : $conf['db_password']; + return hash_hmac('sha256', $profile_id.'|'.$rel_url, $key); +} + +function bratonien_tools_runtime_b64url_encode($value) +{ + return rtrim(strtr(base64_encode($value), '+/', '-_'), '='); +} + +function bratonien_tools_filter_derivative_url($url, $params, $src_image, $rel_url) +{ + if (!bratonien_tools_watermark_engine_enabled()) + { + return $url; + } + + $rule = bratonien_tools_runtime_effective_rule(bratonien_tools_runtime_category_id()); + if ($rule['mode'] !== 'profile' || empty($rule['profile_id'])) + { + return $url; + } + + $profile = bratonien_tools_get_watermark_profile((int)$rule['profile_id']); + if (!$profile || empty($profile['watermark_file'])) + { + return $url; + } + + $watermark_path = PHPWG_ROOT_PATH.PWG_LOCAL_DIR.'watermarks/'.$profile['watermark_file']; + if (!is_file($watermark_path)) + { + return $url; + } + + $profile_id = (int)$profile['id']; + $signature = bratonien_tools_runtime_sign($rel_url, $profile_id); + + return get_root_url().'plugins/'.BRATONIEN_TOOLS_ID.'/watermark.php?p='.$profile_id.'&u='. + rawurlencode(bratonien_tools_runtime_b64url_encode($rel_url)).'&s='.$signature; +}