@@ -4084,19 +4084,7 @@ public static function map_media(object $options, $dato) : ?string {
40844084 return null ;
40854085 }
40864086
4087- // process options. Expected an object as {"quality": "original"}
4088- $ process_options = $ options ->properties ->options ?? null ;
4089- // Empty options. Stop processing
4090- if (empty ($ process_options )) {
4091- return null ;
4092- }
4093-
4094- // transformations
4095- $ file_path = null ;
4096-
4097- // component. Create a component to get the correct defaults
40984087 try {
4099-
41004088 $ tipo = $ options ->component ->tipo ;
41014089 $ model = RecordObj_dd::get_modelo_name_by_tipo ($ tipo ,true );
41024090 $ component = component_common::get_instance (
@@ -4107,54 +4095,35 @@ public static function map_media(object $options, $dato) : ?string {
41074095 DEDALO_DATA_NOLAN , // string lang
41084096 $ options ->component ->section_tipo // string section_tipo
41094097 );
4110-
4111- $ default_quality = $ component ->get_default_quality ();
4112- $ default_extension = $ component ->get_extension ();
4113-
41144098 } catch (Exception $ e ) {
41154099 debug_log (__METHOD__
4116- . " Error on resolve custom path " . PHP_EOL
4100+ . " Error on load component " . PHP_EOL
41174101 . ' exception: ' . $ e ->getMessage () . PHP_EOL
41184102 . ' options : ' . json_encode ($ options , JSON_PRETTY_PRINT )
41194103 , logger::DEBUG
41204104 );
41214105 return null ;
41224106 }
41234107
4124- // 1 - Quality/extension. Filters available files by quality and extension
4125- // Sample to get '/image/original/0/rsc37_rsc176_1.jpg' from '/image/1.5MB/0/rsc37_rsc176_1.jpg'
4126- // {
4127- // "process_dato": "diffusion_sql::map_media",
4128- // "options": {
4129- // "quality": "original",
4130- // "extension": "jpg"
4131- // }
4132- // }
4133- // }
4134- // select desired quality for the list if available
4135- $ found = array_find ((array )$ files_info , function ($ el ) use ($ process_options , $ default_quality , $ default_extension ){
4136-
4137- return $ el ->quality === ($ process_options ->quality ?? $ default_quality ) &&
4138- strtolower ($ el ->extension ) === strtolower ($ process_options ->extension ?? $ default_extension );
4139- });
4140- if (empty ($ found ) || empty ($ found ->file_path )) {
4141- // quality do not exists
4142- return null ;
4108+ // process options. Expected an object as {"quality": "original"}
4109+ $ process_options = $ options ->properties ->options ?? null ;
4110+ // Empty options. Stop processing
4111+ if (empty ($ process_options )) {
4112+ return $ component ->get_diffusion_value ();
41434113 }
4144- $ file_path = $ found ->file_path ;
41454114
4146- // 2 - Replace. Replaces file path string using PHP regex replacements.
4147- // Sample to get 'rsc37_rsc176_1.jpg' from '/pdf/original/0/rsc37_rsc176_1.jpg'
4148- // {
4149- // "process_dato": "diffusion_sql::map_media",
4150- // "options": {
4151- // "replace": {
4152- // "regex": "~.*/~",
4153- // "substitution": ""
4154- // }
4155- // }
4156- // }
4157- // replace (regex). Use delimiters '~' as ~.*/~
4115+ // transformations
4116+ $ file_path = null ;
4117+
4118+ // component. Create a component to get the correct defaults
4119+ $ quality = $ process_options -> quality ?? $ component -> get_default_quality ();
4120+ $ extension = $ process_options -> extension ?? $ component -> get_extension ();
4121+
4122+ // 1 - Quality/Extension. Builds the URL based on given quality and extension when provided.
4123+ $ component -> set_extension ( $ extension );
4124+ $ file_path = $ component -> get_url ( $ quality );
4125+
4126+ // 2 - Replace (regex). Use delimiters '~' as ~.*/~
41584127 if (isset ($ process_options ->replace )) {
41594128 try {
41604129 $ file_path = preg_replace (
@@ -4172,7 +4141,7 @@ public static function map_media(object $options, $dato) : ?string {
41724141 }
41734142 }
41744143
4175- // 3 - prefix . Prepends a string to the file path
4144+ // 3 - Prefix . Prepends a string to the file path
41764145 // Sample to get 'http://dedalo.dev/media/rsc37_rsc176_1.jpg' from '/pdf/original/0/rsc37_rsc176_1.jpg'
41774146 // {
41784147 // "process_dato": "diffusion_sql::map_media",
0 commit comments