From abba5935249becf6ec29f943132d7234ee835ec9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Randy=20=C4=8Cupi=C4=87?= Date: Tue, 14 Dec 2021 16:24:31 +0100 Subject: [PATCH 1/3] Fix resource type detection for eZ XML text --- .../XmlText/NgRemoteMediaPreConverter.php | 7 +- bundle/Resources/xsl/ezxml_ngremotemedia.xsl | 18 +-- .../plugins/ngremotemedia/editor_plugin.js | 130 +++++++++--------- .../datatype/view/ezxmltags/ngremotemedia.tpl | 4 +- 4 files changed, 80 insertions(+), 79 deletions(-) diff --git a/bundle/Converter/XmlText/NgRemoteMediaPreConverter.php b/bundle/Converter/XmlText/NgRemoteMediaPreConverter.php index 27fc678d..1eb2d2e0 100644 --- a/bundle/Converter/XmlText/NgRemoteMediaPreConverter.php +++ b/bundle/Converter/XmlText/NgRemoteMediaPreConverter.php @@ -46,7 +46,7 @@ public function convert(DOMDocument $xmlDoc) $resource = $this->remoteMediaProvider->getRemoteResource($resourceId, $resourceType); $resource->variations = json_decode($imageVariations, true); - switch ($resource->resourceType) { + switch ($resource->mediaType) { case 'video': $videoTag = $this->remoteMediaProvider->generateVideoTag($resource, 'embedded', $variation); $src = $this->remoteMediaProvider->getVideoThumbnail($resource); @@ -64,14 +64,15 @@ public function convert(DOMDocument $xmlDoc) break; default: - $filename = $resource->resourceId ?? basename($resource->resourceId); - $src = $resource->secure_url; + $src = $this->remoteMediaProvider->generateDownloadLink($resource); + $filename = $src ? basename($src) : ''; } $tag->setAttributeNS(self::CUSTOMTAG_NAMESPACE, 'src', $src); $tag->setAttributeNS(self::CUSTOMTAG_NAMESPACE, 'videoTag', $videoTag); $tag->setAttributeNS(self::CUSTOMTAG_NAMESPACE, 'filename', $filename); $tag->setAttributeNS(self::CUSTOMTAG_NAMESPACE, 'alt', $resource->metaData['alt_text'] ?? ''); + $tag->setAttributeNS(self::CUSTOMTAG_NAMESPACE, 'mediaType', $resource->mediaType ?? ''); } } } diff --git a/bundle/Resources/xsl/ezxml_ngremotemedia.xsl b/bundle/Resources/xsl/ezxml_ngremotemedia.xsl index c61a974e..73857d32 100644 --- a/bundle/Resources/xsl/ezxml_ngremotemedia.xsl +++ b/bundle/Resources/xsl/ezxml_ngremotemedia.xsl @@ -1,17 +1,17 @@ + version="1.0" + xmlns:xsl="http://www.w3.org/1999/XSL/Transform" + xmlns:xhtml="http://ez.no/namespaces/ezpublish3/xhtml/" + xmlns:custom="http://ez.no/namespaces/ezpublish3/custom/" + xmlns:image="http://ez.no/namespaces/ezpublish3/image/" + exclude-result-prefixes="xhtml custom image">
- remote-image-inline + remote-image-inline remote- @@ -26,14 +26,14 @@ - + - + diff --git a/bundle/ezpublish_legacy/ngremotemedia/design/standard/javascript/plugins/ngremotemedia/editor_plugin.js b/bundle/ezpublish_legacy/ngremotemedia/design/standard/javascript/plugins/ngremotemedia/editor_plugin.js index 333f0b6a..715d9105 100644 --- a/bundle/ezpublish_legacy/ngremotemedia/design/standard/javascript/plugins/ngremotemedia/editor_plugin.js +++ b/bundle/ezpublish_legacy/ngremotemedia/design/standard/javascript/plugins/ngremotemedia/editor_plugin.js @@ -1,84 +1,84 @@ /* eslint-disable prefer-arrow-callback */ (function (tinymce) { - function insertMediaCallback(data, caption, align, cssClass) { - var imageUrl = ''; - if (data.type === 'image') { - if (data.variation_url !== null) { - imageUrl = data.variation_url; - } else if (data.url !== null) { - imageUrl = data.url; - } - } else if (data.type === 'video' && data.thumbnail_url !== null && data.thumbnail_url !== '') { - imageUrl = data.thumbnail_url; - } + function insertMediaCallback(data, caption, align, cssClass) { + var imageUrl = ''; + if (data.mediaType === 'image') { + if (data.variation_url !== null) { + imageUrl = data.variation_url; + } else if (data.url !== null) { + imageUrl = data.url; + } + } else if (data.mediaType === 'video' && data.thumbnail_url !== null && data.thumbnail_url !== '') { + imageUrl = data.thumbnail_url; + } - let previewUrl = imageUrl !== '' ? imageUrl : '/extension/ezoe/design/standard/images/tango/mail-attachment.png'; - let elementClass = "ezoeItemCustomTag ngremotemedia"; - let alignAttr = ''; + let previewUrl = imageUrl !== '' ? imageUrl : '/extension/ezoe/design/standard/images/tango/mail-attachment.png'; + let elementClass = "ezoeItemCustomTag ngremotemedia"; + let alignAttr = ''; - if (typeof align !== 'undefined' && align !== '') { - elementClass += (' ezoeAlign' + align); - alignAttr = 'align="'+align+'"'; - } + if (typeof align !== 'undefined' && align !== '') { + elementClass += (' ezoeAlign' + align); + alignAttr = 'align="'+align+'"'; + } - let html = ''; + let html = ''; - tinymce.execCommand('mceInsertContent', false, html); - } + tinymce.execCommand('mceInsertContent', false, html); + } - tinymce.PluginManager.add("ngremotemedia", function (editor) { - const fieldId = editor.settings.ez_attribute_id; + tinymce.PluginManager.add("ngremotemedia", function (editor) { + const fieldId = editor.settings.ez_attribute_id; - window[`remoteMedia` + fieldId].setEditorInsertCallback(insertMediaCallback); + window[`remoteMedia` + fieldId].setEditorInsertCallback(insertMediaCallback); - // Add a button that opens a modal - editor.addButton("ngremotemedia", { - title: "Insert remote media", - image: "/bundles/netgenremotemedia/img/cloud-upload-alt.svg", - onclick() { - let attributeType = tinymce.activeEditor.selection.getNode().getAttribute('type'); - let attributeString = tinymce.activeEditor.selection.getNode().getAttribute('customattributes'); - let hasNgrmClass = tinymce.activeEditor.selection.getNode().classList.contains('ngremotemedia'); + // Add a button that opens a modal + editor.addButton("ngremotemedia", { + title: "Insert remote media", + image: "/bundles/netgenremotemedia/img/cloud-upload-alt.svg", + onclick() { + let attributeType = tinymce.activeEditor.selection.getNode().getAttribute('type'); + let attributeString = tinymce.activeEditor.selection.getNode().getAttribute('customattributes'); + let hasNgrmClass = tinymce.activeEditor.selection.getNode().classList.contains('ngremotemedia'); - var data = {}; - if (attributeType === 'custom' && hasNgrmClass === true && attributeString) { - data.align = tinymce.activeEditor.selection.getNode().getAttribute('align'); - let attributes = attributeString.split('attribute_separation'); + var data = {}; + if (attributeType === 'custom' && hasNgrmClass === true && attributeString) { + data.align = tinymce.activeEditor.selection.getNode().getAttribute('align'); + let attributes = attributeString.split('attribute_separation'); - attributes.forEach(function (attribute) { - let attributeKey = attribute.split('|')[0]; - let attributeValue = attribute.split('|')[1]; + attributes.forEach(function (attribute) { + let attributeKey = attribute.split('|')[0]; + let attributeValue = attribute.split('|')[1]; - if (attributeKey === 'coords' || attributeKey === 'image_variations') { - try { - data['image_variations'] = JSON.parse(attributeValue); - } catch(e) { - data['image_variations'] = {}; - } + if (attributeKey === 'coords' || attributeKey === 'image_variations') { + try { + data['image_variations'] = JSON.parse(attributeValue); + } catch(e) { + data['image_variations'] = {}; + } - return; - } + return; + } - data[attributeKey] = attributeValue; - }); - } + data[attributeKey] = attributeValue; + }); + } - window[`remoteMedia` + fieldId].openEditorInsertModal(data); - }, - }); + window[`remoteMedia` + fieldId].openEditorInsertModal(data); + }, + }); + return { + getMetadata() { return { - getMetadata() { - return { - name: "Netgen remote media", - url: "https://github.com/netgen/NetgenRemoteMediaBundle", - }; - }, + name: "Netgen remote media", + url: "https://github.com/netgen/NetgenRemoteMediaBundle", }; - }); + }, + }; + }); })(tinymce); diff --git a/bundle/ezpublish_legacy/ngremotemedia/design/standard/templates/content/datatype/view/ezxmltags/ngremotemedia.tpl b/bundle/ezpublish_legacy/ngremotemedia/design/standard/templates/content/datatype/view/ezxmltags/ngremotemedia.tpl index 8165713b..31fcaacd 100644 --- a/bundle/ezpublish_legacy/ngremotemedia/design/standard/templates/content/datatype/view/ezxmltags/ngremotemedia.tpl +++ b/bundle/ezpublish_legacy/ngremotemedia/design/standard/templates/content/datatype/view/ezxmltags/ngremotemedia.tpl @@ -8,7 +8,7 @@ {if and(resource, $resource.resourceId|is_null|not)} - {if eq($resourceType, 'image')} + {if eq($resource.mediaType, 'image')} {def $image_url = $resource.secure_url} {def $image_url = ngremotemedia($resource, 'embedded', $variation).url} @@ -17,7 +17,7 @@ {if and(is_set($cssclass), is_string($cssclass), not($cssclass|compare('')))}class="{$cssclass|wash()}"{/if} {if and(is_set($style), is_string($style), not($style|compare('')))}style="{$style|wash()}"{/if} {if and(is_set($resource.metaData.alt_text), is_string($resource.metaData.alt_text))}alt="{$resource.metaData.alt_text|wash()}"{/if} /> - {elseif eq($resourceType, 'video')} + {elseif eq($resource.mediaType, 'video')} {ngremotevideo($resource, $variation, 'embedded')} {else} {$resourceId} From d5d7e9ef365e833030aedbeb5381b03726c6f3ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Randy=20=C4=8Cupi=C4=87?= Date: Tue, 14 Dec 2021 16:25:03 +0100 Subject: [PATCH 2/3] Fix resource type detection for Richtext --- .../ezrichtext/custom_tag/ngremotemedia.html.twig | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bundle/Resources/views/ezadminui/field_type/ezrichtext/custom_tag/ngremotemedia.html.twig b/bundle/Resources/views/ezadminui/field_type/ezrichtext/custom_tag/ngremotemedia.html.twig index 85e0e4d4..52119078 100644 --- a/bundle/Resources/views/ezadminui/field_type/ezrichtext/custom_tag/ngremotemedia.html.twig +++ b/bundle/Resources/views/ezadminui/field_type/ezrichtext/custom_tag/ngremotemedia.html.twig @@ -8,10 +8,10 @@ {% set css_class = params.cssclass|default(null) %} {% if resource_id and resource_type %} -
- {% set resource = netgen_remote_media_embed(resource_id, resource_type, coords) %} + {% set resource = netgen_remote_media_embed(resource_id, resource_type, coords) %} - {% if resource.resourceType == 'image' %} +
+ {% if resource.mediaType == 'image' %} {% set image_url = resource.secure_url %} {% if variation %} {% set variation = netgen_remote_variation_embed(resource, variation) %} @@ -19,7 +19,7 @@ {% endif %} {{ resource.metaData.alt_text }} - {% elseif resource_type == 'video' %} + {% elseif resource.mediaType == 'video' %} {{ netgen_remote_video_embed(resource, variation)|raw }} {% else %} {{ resource.resourceId }} From 269f01edf4be85c32c5378549ae6181f0f78e11c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Randy=20=C4=8Cupi=C4=87?= Date: Tue, 14 Dec 2021 16:27:30 +0100 Subject: [PATCH 3/3] Don't use filename --- bundle/Converter/XmlText/NgRemoteMediaPreConverter.php | 2 -- bundle/Resources/xsl/ezxml_ngremotemedia.xsl | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/bundle/Converter/XmlText/NgRemoteMediaPreConverter.php b/bundle/Converter/XmlText/NgRemoteMediaPreConverter.php index 1eb2d2e0..6272d2a1 100644 --- a/bundle/Converter/XmlText/NgRemoteMediaPreConverter.php +++ b/bundle/Converter/XmlText/NgRemoteMediaPreConverter.php @@ -65,12 +65,10 @@ public function convert(DOMDocument $xmlDoc) default: $src = $this->remoteMediaProvider->generateDownloadLink($resource); - $filename = $src ? basename($src) : ''; } $tag->setAttributeNS(self::CUSTOMTAG_NAMESPACE, 'src', $src); $tag->setAttributeNS(self::CUSTOMTAG_NAMESPACE, 'videoTag', $videoTag); - $tag->setAttributeNS(self::CUSTOMTAG_NAMESPACE, 'filename', $filename); $tag->setAttributeNS(self::CUSTOMTAG_NAMESPACE, 'alt', $resource->metaData['alt_text'] ?? ''); $tag->setAttributeNS(self::CUSTOMTAG_NAMESPACE, 'mediaType', $resource->mediaType ?? ''); } diff --git a/bundle/Resources/xsl/ezxml_ngremotemedia.xsl b/bundle/Resources/xsl/ezxml_ngremotemedia.xsl index 73857d32..d706ee9a 100644 --- a/bundle/Resources/xsl/ezxml_ngremotemedia.xsl +++ b/bundle/Resources/xsl/ezxml_ngremotemedia.xsl @@ -40,7 +40,7 @@ - +