From dd475f29c790bba54b912803d4faaa2b4993b608 Mon Sep 17 00:00:00 2001 From: Justin Georgi Date: Thu, 14 Nov 2024 08:41:59 -0700 Subject: [PATCH] Add annotation set transform framework Signed-off-by: Justin Georgi --- GlModelHandler.i18n.magic.php | 3 ++- includes/GlModelHandler.php | 25 +++++++++++++++++-------- includes/GlModelTransformOutput.php | 10 ++++++++++ 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/GlModelHandler.i18n.magic.php b/GlModelHandler.i18n.magic.php index 16c6330..f23c0d7 100644 --- a/GlModelHandler.i18n.magic.php +++ b/GlModelHandler.i18n.magic.php @@ -3,5 +3,6 @@ $magicWords = []; $magicWords['en'] = [ 'glmv_view' => [ 1, "view=$1" ], - 'glmv_hsset' => [1, "set=$1"] + 'glmv_hsset' => [1, "set=$1"], + 'glmv_settrans' => [1, "transform=$1"] ]; \ No newline at end of file diff --git a/includes/GlModelHandler.php b/includes/GlModelHandler.php index fcff3bb..cbf9d07 100644 --- a/includes/GlModelHandler.php +++ b/includes/GlModelHandler.php @@ -62,9 +62,9 @@ class GlModelHandler extends ImageHandler { * @return bool */ public function validateParam( $name, $value ) { - if (in_array($name, ['width', 'height'])) { + if (in_array($name, ['width', 'height'])) { return $value > 0; - } else if (in_array($name, ['view', 'hsset'])) { + } else if (in_array($name, ['view', 'hsset', 'settrans'])) { return true; } else { return false; @@ -80,10 +80,13 @@ class GlModelHandler extends ImageHandler { public function makeParamString( $params ) { $res = parent::makeParamString( $params ); if ( $res && isset( $params['hsset'] ) ) { - $res = "hs{$params['hsset']}-$res"; + $res = "glhs{$params['hsset']}-$res"; } if ( $res && isset( $params['view'] ) ) { - $res = "v{$params['view']}-$res"; + $res = "glv{$params['view']}-$res"; + } + if ( $res && isset( $params['settrans'] ) ) { + $res = "gltr{$params['settrans']}-$res"; } return $res; } @@ -95,12 +98,14 @@ class GlModelHandler extends ImageHandler { * @return array|false Array of parameters or false on failure */ public function parseParamString( $str ) { - preg_match( '/v([^-]*?)-/', $str, $view ); - preg_match( '/hs([^-]*?)-/', $str, $hsset ); - $otherParams = preg_replace('/(?:(?:hs[^-]*?-)|(?:v[^-]*?-))*(.*)$/', '/$1/', $str); + preg_match( '/glv([^-]*?)-/', $str, $view ); + preg_match( '/glhs([^-]*?)-/', $str, $hsset ); + preg_match( '/gltr([^-]*?)-/', $str, $settrans ); + $otherParams = preg_replace('/(?:gl(?:hs[^-]*?-)|(?:v[^-]*?-)|(?:tr[^-]*?-))*(.*)$/', '/$1/', $str); $parsedParams = parent::parseParamString( $otherParams ); $parsedParams['view'] = $view; $parsedParams['hsset'] = $hsset; + $parsedParams['settrans'] = $settrans; return $res; } @@ -118,6 +123,9 @@ class GlModelHandler extends ImageHandler { if ( isset( $params['hsset'] ) ) { $res['hsset'] = $params['hsset']; } + if ( isset( $params['settrans'] ) ) { + $res['settrans'] = $params['settrans']; + } return $res; } @@ -130,7 +138,8 @@ class GlModelHandler extends ImageHandler { return [ 'img_width' => 'width', 'glmv_view' => 'view', - 'glmv_hsset' => 'hsset' + 'glmv_hsset' => 'hsset', + 'glmv_settrans' => 'settrans' ]; } diff --git a/includes/GlModelTransformOutput.php b/includes/GlModelTransformOutput.php index 2ca56c4..e91dd42 100644 --- a/includes/GlModelTransformOutput.php +++ b/includes/GlModelTransformOutput.php @@ -23,6 +23,7 @@ class GlModelTransformOutput extends MediaTransformOutput { $this->height = $parameters['height']; $this->view = (isset($parameters['view'])) ? $parameters['view'] : 'default'; $this->hsset = (isset($parameters['hsset'])) ? $parameters['hsset'] : 'all'; + $this->transform = (isset($parameters['settrans'])) ? preg_split("/[\s,]+/", $parameters['settrans']) : []; $this->url = $file->getFullUrl(); $this->thumb = isset($parameters['isFilePageThumb']) && $parameters['isFilePageThumb']; } @@ -112,6 +113,15 @@ class GlModelTransformOutput extends MediaTransformOutput { } else { $annotations = $metadata['annotations']; } + + //Apply any request transformations + if ($this->transform) { + if (in_array('alpha',$this->transform)) { + ksort($annotations); + } + } + + //Create hotspot elements foreach($annotations as $label => $an) { $elAnnot = Html::rawElement('div',['class' => 'HotspotAnnotation HiddenAnnotation'],$label); $hsDefault = array(