Commit 21771e45 authored by Sven Franck's avatar Sven Franck

erp5_corporate_identity: handle non-confirming img src

parent 99e67338
...@@ -18,42 +18,69 @@ if img_string is None or img_string == "": ...@@ -18,42 +18,69 @@ if img_string is None or img_string == "":
return img_string return img_string
img_src = re.findall("src=['\"](.*?)['\"]", img_string)[0] img_src = re.findall("src=['\"](.*?)['\"]", img_string)[0]
img_obj = context.restrictedTraverse(img_src.split("?")[0], None) img_type = None
# flag broken link until further notice # START user ignoring guidelines:
if img_obj is None: validation_freebie = None
raise NotFound('The following image could not be found in erp5: %s' % (img_src.split("?")[0])) new_src = None
img_type = img_obj.getContentType() # Guideline: no relative links. we cover
if img_src.startswith("./"):
new_src = img_src.replace("./", "")
# ensure alt attributes are set img_string = img_string.replace(img_src, new_src)
if img_string.find('alt=') == -1:
img_string.replace ("src=", 'alt="%s" src=' % img_caption or img_obj.getTitle()) # Guideline: include format. we cover
img_src = new_src or img_src
# force svg display as svg or png if img_src.find("format=") == -1:
if img_type == "image/svg+xml": if img_src.find("?") == -1:
if img_svg_format == "png" or img_svg_format is None: new_src = img_src + "?format="
img_string = img_string.replace('type="image/svg+xml"', '') else:
img_string = img_string.replace("type='image/svg+xml'", '') new_src = img_src + "&format="
img_string = img_string.replace('format=svg', 'format=png') img_string = img_string.replace(img_src, new_src)
if img_svg_format == "svg":
img_string = img_string.replace('src=', 'type="image/svg+xml" src=') # Guideline: images must be stored locally, don't complain if your pdf breaks
img_string = img_string.replace('src=', "type='image/svg+xml' src=") img_src = new_src or img_src
img_string = img_string.replace('format=png', 'format=svg') if img_src.startswith("http"):
validation_freebie = True
# wrap image in fullscreen link
if img_fullscreen_link: if validation_freebie is None:
img_string = ''.join([ #END user ignoring guidelines
'<a target="_blank" rel="noopener noreferrer" href="%s" title="%s">%s<a>' % (
img_src, img_obj = context.restrictedTraverse(img_src.split("?")[0], None)
img_obj.getTitle(),
img_string # flag broken link until further notice
) if img_obj is None:
]) raise NotFound('The following image could not be found in erp5: %s' % (img_src.split("?")[0]))
# wrap image in <p> tag img_type = img_obj.getContentType()
if img_wrap:
img_string = '<p class="ci-book-img" style="text-align:center">' + img_string + '</p>' # ensure alt attributes are set
if img_string.find('alt=') == -1:
img_string.replace ("src=", 'alt="%s" src=' % img_caption or img_obj.getTitle())
# force svg display as svg or png
if img_type == "image/svg+xml":
if img_svg_format == "png" or img_svg_format is None:
img_string = img_string.replace('type="image/svg+xml"', '')
img_string = img_string.replace("type='image/svg+xml'", '')
img_string = img_string.replace('format=svg', 'format=png')
if img_svg_format == "svg":
img_string = img_string.replace('src=', 'type="image/svg+xml" src=')
img_string = img_string.replace('src=', "type='image/svg+xml' src=")
img_string = img_string.replace('format=png', 'format=svg')
# wrap image in fullscreen link
if img_fullscreen_link:
img_string = ''.join([
'<a target="_blank" rel="noopener noreferrer" href="%s" title="%s">%s<a>' % (
img_src,
img_obj.getTitle(),
img_string
)
])
# wrap image in <p> tag
if img_wrap:
img_string = '<p class="ci-book-img" style="text-align:center">' + img_string + '</p>'
return img_string return img_string
...@@ -39,7 +39,7 @@ ...@@ -39,7 +39,7 @@
</item> </item>
<item> <item>
<key> <string>_EtagSupport__etag</string> </key> <key> <string>_EtagSupport__etag</string> </key>
<value> <string>ts36830746.23</string> </value> <value> <string>ts37191622.9</string> </value>
</item> </item>
<item> <item>
<key> <string>_Modify_portal_content_Permission</string> </key> <key> <string>_Modify_portal_content_Permission</string> </key>
...@@ -83,7 +83,7 @@ ...@@ -83,7 +83,7 @@
</item> </item>
<item> <item>
<key> <string>content_md5</string> </key> <key> <string>content_md5</string> </key>
<value> <string>1347a0ac51a4ccba25cdc2ac1b9ec10e</string> </value> <value> <string>a6a557994b04da251f3e4294b0b8ff0a</string> </value>
</item> </item>
<item> <item>
<key> <string>content_type</string> </key> <key> <string>content_type</string> </key>
......
...@@ -39,7 +39,7 @@ ...@@ -39,7 +39,7 @@
</item> </item>
<item> <item>
<key> <string>_EtagSupport__etag</string> </key> <key> <string>_EtagSupport__etag</string> </key>
<value> <string>ts36830811.1</string> </value> <value> <string>ts37191680.59</string> </value>
</item> </item>
<item> <item>
<key> <string>_Modify_portal_content_Permission</string> </key> <key> <string>_Modify_portal_content_Permission</string> </key>
...@@ -83,7 +83,7 @@ ...@@ -83,7 +83,7 @@
</item> </item>
<item> <item>
<key> <string>content_md5</string> </key> <key> <string>content_md5</string> </key>
<value> <string>0f812c098ecdab01bfc987059e4004c8</string> </value> <value> <string>adc07dd7793551bd8ceba5027eab1738</string> </value>
</item> </item>
<item> <item>
<key> <string>content_type</string> </key> <key> <string>content_type</string> </key>
......
...@@ -39,7 +39,7 @@ ...@@ -39,7 +39,7 @@
</item> </item>
<item> <item>
<key> <string>_EtagSupport__etag</string> </key> <key> <string>_EtagSupport__etag</string> </key>
<value> <string>ts36830842.07</string> </value> <value> <string>ts37191710.15</string> </value>
</item> </item>
<item> <item>
<key> <string>_Modify_portal_content_Permission</string> </key> <key> <string>_Modify_portal_content_Permission</string> </key>
...@@ -83,7 +83,7 @@ ...@@ -83,7 +83,7 @@
</item> </item>
<item> <item>
<key> <string>content_md5</string> </key> <key> <string>content_md5</string> </key>
<value> <string>760600ccb9366e7f4a4b35d10fcb09e9</string> </value> <value> <string>a9253b04c66ca1ea28fbe89da4ab2dfe</string> </value>
</item> </item>
<item> <item>
<key> <string>content_type</string> </key> <key> <string>content_type</string> </key>
......
...@@ -39,7 +39,7 @@ ...@@ -39,7 +39,7 @@
</item> </item>
<item> <item>
<key> <string>_EtagSupport__etag</string> </key> <key> <string>_EtagSupport__etag</string> </key>
<value> <string>ts36830779.5</string> </value> <value> <string>ts37191651.96</string> </value>
</item> </item>
<item> <item>
<key> <string>_Modify_portal_content_Permission</string> </key> <key> <string>_Modify_portal_content_Permission</string> </key>
...@@ -83,7 +83,7 @@ ...@@ -83,7 +83,7 @@
</item> </item>
<item> <item>
<key> <string>content_md5</string> </key> <key> <string>content_md5</string> </key>
<value> <string>99655de2a23499c325e02c5e1f139f83</string> </value> <value> <string>bcab083b6997eab679dc5ea9182eb5a8</string> </value>
</item> </item>
<item> <item>
<key> <string>content_type</string> </key> <key> <string>content_type</string> </key>
......
...@@ -39,7 +39,7 @@ ...@@ -39,7 +39,7 @@
</item> </item>
<item> <item>
<key> <string>_EtagSupport__etag</string> </key> <key> <string>_EtagSupport__etag</string> </key>
<value> <string>ts36830873.95</string> </value> <value> <string>ts37191739.69</string> </value>
</item> </item>
<item> <item>
<key> <string>_Modify_portal_content_Permission</string> </key> <key> <string>_Modify_portal_content_Permission</string> </key>
...@@ -83,7 +83,7 @@ ...@@ -83,7 +83,7 @@
</item> </item>
<item> <item>
<key> <string>content_md5</string> </key> <key> <string>content_md5</string> </key>
<value> <string>78b18dfe4630d1460833c1ba7678f8e3</string> </value> <value> <string>564b35d8806e721a4b44a7644eeccec5</string> </value>
</item> </item>
<item> <item>
<key> <string>content_type</string> </key> <key> <string>content_type</string> </key>
...@@ -125,7 +125,7 @@ ...@@ -125,7 +125,7 @@
</item> </item>
<item> <item>
<key> <string>size</string> </key> <key> <string>size</string> </key>
<value> <int>381275</int> </value> <value> <int>680293</int> </value>
</item> </item>
<item> <item>
<key> <string>title</string> </key> <key> <string>title</string> </key>
......
...@@ -79,7 +79,7 @@ ...@@ -79,7 +79,7 @@
</item> </item>
<item> <item>
<key> <string>content_md5</string> </key> <key> <string>content_md5</string> </key>
<value> <string>125dda705d2c7c8942345bf6f5dd3eaa</string> </value> <value> <string>dfd18344132347b4f1b95bba2f72b781</string> </value>
</item> </item>
<item> <item>
<key> <string>content_type</string> </key> <key> <string>content_type</string> </key>
......
...@@ -34,6 +34,22 @@ ...@@ -34,6 +34,22 @@
</details> </details>
</section> </section>
<section>
<h1>Test ./Illustration Plain Reference</h1>
<img src="./Template.Test.Illustration.Stack" title="" type="image/svg+xml" alt="" />
<details open="open">
<p>svg image with weird reference</p>
</details>
</section>
<section>
<h1>Test Retrieving PDF page as PNG Image</h1>
<img alt="" src="https://www.nexedi.com/NXD-Gramfort.X.2018.May/index_html?format=png&amp;frame=17" title="" type="image/svg+xml" />
<details open="open">
<p>svg image with weird reference</p>
</details>
</section>
<section> <section>
<h1>Test SVG as PNG</h1> <h1>Test SVG as PNG</h1>
<img src="Template.Test.Illustration.Stack?format=png" alt="" /> <img src="Template.Test.Illustration.Stack?format=png" alt="" />
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment