Skip to content

Commit abba593

Browse files
committed
Fix resource type detection for eZ XML text
1 parent 45be98e commit abba593

File tree

4 files changed

+80
-79
lines changed

4 files changed

+80
-79
lines changed

bundle/Converter/XmlText/NgRemoteMediaPreConverter.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function convert(DOMDocument $xmlDoc)
4646
$resource = $this->remoteMediaProvider->getRemoteResource($resourceId, $resourceType);
4747
$resource->variations = json_decode($imageVariations, true);
4848

49-
switch ($resource->resourceType) {
49+
switch ($resource->mediaType) {
5050
case 'video':
5151
$videoTag = $this->remoteMediaProvider->generateVideoTag($resource, 'embedded', $variation);
5252
$src = $this->remoteMediaProvider->getVideoThumbnail($resource);
@@ -64,14 +64,15 @@ public function convert(DOMDocument $xmlDoc)
6464
break;
6565

6666
default:
67-
$filename = $resource->resourceId ?? basename($resource->resourceId);
68-
$src = $resource->secure_url;
67+
$src = $this->remoteMediaProvider->generateDownloadLink($resource);
68+
$filename = $src ? basename($src) : '';
6969
}
7070

7171
$tag->setAttributeNS(self::CUSTOMTAG_NAMESPACE, 'src', $src);
7272
$tag->setAttributeNS(self::CUSTOMTAG_NAMESPACE, 'videoTag', $videoTag);
7373
$tag->setAttributeNS(self::CUSTOMTAG_NAMESPACE, 'filename', $filename);
7474
$tag->setAttributeNS(self::CUSTOMTAG_NAMESPACE, 'alt', $resource->metaData['alt_text'] ?? '');
75+
$tag->setAttributeNS(self::CUSTOMTAG_NAMESPACE, 'mediaType', $resource->mediaType ?? '');
7576
}
7677
}
7778
}

bundle/Resources/xsl/ezxml_ngremotemedia.xsl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<xsl:stylesheet
3-
version="1.0"
4-
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
5-
xmlns:xhtml="http://ez.no/namespaces/ezpublish3/xhtml/"
6-
xmlns:custom="http://ez.no/namespaces/ezpublish3/custom/"
7-
xmlns:image="http://ez.no/namespaces/ezpublish3/image/"
8-
exclude-result-prefixes="xhtml custom image">
3+
version="1.0"
4+
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
5+
xmlns:xhtml="http://ez.no/namespaces/ezpublish3/xhtml/"
6+
xmlns:custom="http://ez.no/namespaces/ezpublish3/custom/"
7+
xmlns:image="http://ez.no/namespaces/ezpublish3/image/"
8+
exclude-result-prefixes="xhtml custom image">
99

1010
<xsl:output method="html" indent="yes" encoding="UTF-8"/>
1111

1212
<xsl:template match="custom[@name='ngremotemedia']">
1313
<div>
14-
<xsl:attribute name="class">remote-image-inline <xsl:value-of select="@custom:cssclass"/>
14+
<xsl:attribute name="class">remote-image-inline <xsl:value-of select="@custom:cssclass"/> remote-<xsl:value-of select="@custom:mediaType"/>
1515
<xsl:if test="@align!=''">
1616
<xsl:choose>
1717
<xsl:when test="@align='middle'">
@@ -26,14 +26,14 @@
2626
</xsl:attribute>
2727

2828
<xsl:choose>
29-
<xsl:when test="@custom:resourceType='image'">
29+
<xsl:when test="@custom:mediaType='image'">
3030
<img>
3131
<xsl:attribute name="src"><xsl:value-of select="@custom:src"/></xsl:attribute>
3232
<xsl:attribute name="alt"><xsl:value-of select="@custom:alt"/></xsl:attribute>
3333
</img>
3434
</xsl:when>
3535

36-
<xsl:when test="@custom:resourceType='video'">
36+
<xsl:when test="@custom:mediaType='video'">
3737
<xsl:value-of select="@custom:videoTag" disable-output-escaping="yes"/>
3838
</xsl:when>
3939

Lines changed: 65 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,84 @@
11
/* eslint-disable prefer-arrow-callback */
22
(function (tinymce) {
3-
function insertMediaCallback(data, caption, align, cssClass) {
4-
var imageUrl = '';
5-
if (data.type === 'image') {
6-
if (data.variation_url !== null) {
7-
imageUrl = data.variation_url;
8-
} else if (data.url !== null) {
9-
imageUrl = data.url;
10-
}
11-
} else if (data.type === 'video' && data.thumbnail_url !== null && data.thumbnail_url !== '') {
12-
imageUrl = data.thumbnail_url;
13-
}
3+
function insertMediaCallback(data, caption, align, cssClass) {
4+
var imageUrl = '';
5+
if (data.mediaType === 'image') {
6+
if (data.variation_url !== null) {
7+
imageUrl = data.variation_url;
8+
} else if (data.url !== null) {
9+
imageUrl = data.url;
10+
}
11+
} else if (data.mediaType === 'video' && data.thumbnail_url !== null && data.thumbnail_url !== '') {
12+
imageUrl = data.thumbnail_url;
13+
}
1414

15-
let previewUrl = imageUrl !== '' ? imageUrl : '/extension/ezoe/design/standard/images/tango/mail-attachment.png';
16-
let elementClass = "ezoeItemCustomTag ngremotemedia";
17-
let alignAttr = '';
15+
let previewUrl = imageUrl !== '' ? imageUrl : '/extension/ezoe/design/standard/images/tango/mail-attachment.png';
16+
let elementClass = "ezoeItemCustomTag ngremotemedia";
17+
let alignAttr = '';
1818

19-
if (typeof align !== 'undefined' && align !== '') {
20-
elementClass += (' ezoeAlign' + align);
21-
alignAttr = 'align="'+align+'"';
22-
}
19+
if (typeof align !== 'undefined' && align !== '') {
20+
elementClass += (' ezoeAlign' + align);
21+
alignAttr = 'align="'+align+'"';
22+
}
2323

24-
let html = '<img type="custom" src="'+previewUrl+'"'
25-
+ 'data-mce-src="'+previewUrl+'"'
26-
+ alignAttr
27-
+ 'customattributes=\'caption|'+caption+'attribute_separationcssclass|'+cssClass+'attribute_separationcoords|'+JSON.stringify(data.image_variations)
28-
+ 'attribute_separationresourceId|'+data.resourceId+'attribute_separationresourceType|'+data.type+'attribute_separationimage_url|'+imageUrl
29-
+ 'attribute_separationvariation|'+data.selected_variation+'\'"'+'class="'+elementClass+'" style="">';
24+
let html = '<img type="custom" src="'+previewUrl+'"'
25+
+ 'data-mce-src="'+previewUrl+'"'
26+
+ alignAttr
27+
+ 'customattributes=\'caption|'+caption+'attribute_separationcssclass|'+cssClass+'attribute_separationcoords|'+JSON.stringify(data.image_variations)
28+
+ 'attribute_separationresourceId|'+data.resourceId+'attribute_separationresourceType|'+data.type+'attribute_separationimage_url|'+imageUrl
29+
+ 'attribute_separationvariation|'+data.selected_variation+'\'"'+'class="'+elementClass+'" style="">';
3030

31-
tinymce.execCommand('mceInsertContent', false, html);
32-
}
31+
tinymce.execCommand('mceInsertContent', false, html);
32+
}
3333

34-
tinymce.PluginManager.add("ngremotemedia", function (editor) {
35-
const fieldId = editor.settings.ez_attribute_id;
34+
tinymce.PluginManager.add("ngremotemedia", function (editor) {
35+
const fieldId = editor.settings.ez_attribute_id;
3636

37-
window[`remoteMedia` + fieldId].setEditorInsertCallback(insertMediaCallback);
37+
window[`remoteMedia` + fieldId].setEditorInsertCallback(insertMediaCallback);
3838

39-
// Add a button that opens a modal
40-
editor.addButton("ngremotemedia", {
41-
title: "Insert remote media",
42-
image: "/bundles/netgenremotemedia/img/cloud-upload-alt.svg",
43-
onclick() {
44-
let attributeType = tinymce.activeEditor.selection.getNode().getAttribute('type');
45-
let attributeString = tinymce.activeEditor.selection.getNode().getAttribute('customattributes');
46-
let hasNgrmClass = tinymce.activeEditor.selection.getNode().classList.contains('ngremotemedia');
39+
// Add a button that opens a modal
40+
editor.addButton("ngremotemedia", {
41+
title: "Insert remote media",
42+
image: "/bundles/netgenremotemedia/img/cloud-upload-alt.svg",
43+
onclick() {
44+
let attributeType = tinymce.activeEditor.selection.getNode().getAttribute('type');
45+
let attributeString = tinymce.activeEditor.selection.getNode().getAttribute('customattributes');
46+
let hasNgrmClass = tinymce.activeEditor.selection.getNode().classList.contains('ngremotemedia');
4747

48-
var data = {};
49-
if (attributeType === 'custom' && hasNgrmClass === true && attributeString) {
50-
data.align = tinymce.activeEditor.selection.getNode().getAttribute('align');
51-
let attributes = attributeString.split('attribute_separation');
48+
var data = {};
49+
if (attributeType === 'custom' && hasNgrmClass === true && attributeString) {
50+
data.align = tinymce.activeEditor.selection.getNode().getAttribute('align');
51+
let attributes = attributeString.split('attribute_separation');
5252

53-
attributes.forEach(function (attribute) {
54-
let attributeKey = attribute.split('|')[0];
55-
let attributeValue = attribute.split('|')[1];
53+
attributes.forEach(function (attribute) {
54+
let attributeKey = attribute.split('|')[0];
55+
let attributeValue = attribute.split('|')[1];
5656

57-
if (attributeKey === 'coords' || attributeKey === 'image_variations') {
58-
try {
59-
data['image_variations'] = JSON.parse(attributeValue);
60-
} catch(e) {
61-
data['image_variations'] = {};
62-
}
57+
if (attributeKey === 'coords' || attributeKey === 'image_variations') {
58+
try {
59+
data['image_variations'] = JSON.parse(attributeValue);
60+
} catch(e) {
61+
data['image_variations'] = {};
62+
}
6363

64-
return;
65-
}
64+
return;
65+
}
6666

67-
data[attributeKey] = attributeValue;
68-
});
69-
}
67+
data[attributeKey] = attributeValue;
68+
});
69+
}
7070

71-
window[`remoteMedia` + fieldId].openEditorInsertModal(data);
72-
},
73-
});
71+
window[`remoteMedia` + fieldId].openEditorInsertModal(data);
72+
},
73+
});
7474

75+
return {
76+
getMetadata() {
7577
return {
76-
getMetadata() {
77-
return {
78-
name: "Netgen remote media",
79-
url: "https://github.com/netgen/NetgenRemoteMediaBundle",
80-
};
81-
},
78+
name: "Netgen remote media",
79+
url: "https://github.com/netgen/NetgenRemoteMediaBundle",
8280
};
83-
});
81+
},
82+
};
83+
});
8484
})(tinymce);

bundle/ezpublish_legacy/ngremotemedia/design/standard/templates/content/datatype/view/ezxmltags/ngremotemedia.tpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
{if and(resource, $resource.resourceId|is_null|not)}
1010
<div{if and(is_set($align), is_string($align), not($align|compare('')))} class="object-{if $align|compare('middle')}center{else}{$align}{/if}"{/if}>
11-
{if eq($resourceType, 'image')}
11+
{if eq($resource.mediaType, 'image')}
1212
{def $image_url = $resource.secure_url}
1313

1414
{def $image_url = ngremotemedia($resource, 'embedded', $variation).url}
@@ -17,7 +17,7 @@
1717
{if and(is_set($cssclass), is_string($cssclass), not($cssclass|compare('')))}class="{$cssclass|wash()}"{/if}
1818
{if and(is_set($style), is_string($style), not($style|compare('')))}style="{$style|wash()}"{/if}
1919
{if and(is_set($resource.metaData.alt_text), is_string($resource.metaData.alt_text))}alt="{$resource.metaData.alt_text|wash()}"{/if} />
20-
{elseif eq($resourceType, 'video')}
20+
{elseif eq($resource.mediaType, 'video')}
2121
{ngremotevideo($resource, $variation, 'embedded')}
2222
{else}
2323
<a href="{$resource.secure_url}">{$resourceId}</a>

0 commit comments

Comments
 (0)