Fixed image viewer for embedded images
authorAlexander Ebert <ebert@woltlab.com>
Fri, 13 Jan 2017 11:41:22 +0000 (12:41 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Fri, 13 Jan 2017 11:41:22 +0000 (12:41 +0100)
wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodeImg.class.php
wcfsetup/install/files/style/ui/attachment.scss

index 3186ae936df67862619fd8a93a6ceac063b9384d..bf2392410dd3930a508cab703bcf6eb78e00d6a2 100644 (file)
@@ -52,51 +52,58 @@ class HtmlOutputNodeImg extends AbstractHtmlOutputNode {
                                        else $element->removeAttribute('srcset');
                                }
                        }
-                       else if (MODULE_IMAGE_PROXY) {
+                       else {
                                $src = $element->getAttribute('src');
                                if (!$src) {
                                        DOMUtil::removeNode($element);
                                        continue;
                                }
                                
-                               $urlComponents = parse_url($src);
-                               if ($urlComponents === false) {
-                                       // not a valid URL, discard it
-                                       DOMUtil::removeNode($element);
-                                       continue;
-                               }
-                               
-                               if (empty($urlComponents['host'])) {
-                                       // relative URL, ignore it
-                                       continue;
-                               }
-                               
-                               $element->setAttribute('data-valid', 'true');
-                               
-                               if (!empty($urlComponents['path']) && preg_match('~\.svg~', basename($urlComponents['path']))) {
-                                       // we can't proxy SVG, ignore it
-                                       continue;
-                               }
-                               
-                               $element->setAttribute('src', $this->getProxyLink($src));
+                               $class = $element->getAttribute('class');
+                               if ($class) $class .= ' ';
+                               $class .= 'jsResizeImage';
+                               $element->setAttribute('class', $class);
                                
-                               $srcset = $element->getAttribute('srcset');
-                               if ($srcset) {
-                                       // simplified regex to check if it appears to be a valid list of sources
-                                       if (!preg_match('~^[^\s]+\s+[0-9\.]+[wx](,\s*[^\s]+\s+[0-9\.]+[wx])*~', $srcset)) {
-                                               $element->removeAttribute('srcset');
+                               if (MODULE_IMAGE_PROXY) {
+                                       $urlComponents = parse_url($src);
+                                       if ($urlComponents === false) {
+                                               // not a valid URL, discard it
+                                               DOMUtil::removeNode($element);
                                                continue;
                                        }
                                        
-                                       $sources = explode(',', $srcset);
-                                       $srcset = '';
-                                       foreach ($sources as $source) {
-                                               $tmp = preg_split('~\s+~', StringUtil::trim($source));
-                                               if (!empty($srcset)) $srcset .= ', ';
-                                               $srcset .= $this->getProxyLink($tmp[0]) . ' ' . $tmp[1];
+                                       if (empty($urlComponents['host'])) {
+                                               // relative URL, ignore it
+                                               continue;
                                        }
                                        
-                                       $element->setAttribute('srcset', $srcset);
+                                       $element->setAttribute('data-valid', 'true');
+                                       
+                                       if (!empty($urlComponents['path']) && preg_match('~\.svg~', basename($urlComponents['path']))) {
+                                               // we can't proxy SVG, ignore it
+                                               continue;
+                                       }
+                                       
+                                       $element->setAttribute('src', $this->getProxyLink($src));
+                                       
+                                       $srcset = $element->getAttribute('srcset');
+                                       if ($srcset) {
+                                               // simplified regex to check if it appears to be a valid list of sources
+                                               if (!preg_match('~^[^\s]+\s+[0-9\.]+[wx](,\s*[^\s]+\s+[0-9\.]+[wx])*~', $srcset)) {
+                                                       $element->removeAttribute('srcset');
+                                                       continue;
+                                               }
+                                               
+                                               $sources = explode(',', $srcset);
+                                               $srcset = '';
+                                               foreach ($sources as $source) {
+                                                       $tmp = preg_split('~\s+~', StringUtil::trim($source));
+                                                       if (!empty($srcset)) $srcset .= ', ';
+                                                       $srcset .= $this->getProxyLink($tmp[0]) . ' ' . $tmp[1];
+                                               }
+                                               
+                                               $element->setAttribute('srcset', $srcset);
+                                       }
                                }
                        }
                }
index ec0d7afdc3bfd34e427feaac809b8a9ec72bb535..3d8bee9482d4e3d1d24f3fa681d9537aa6be511e 100644 (file)
 }
 
 /* embedded images */
-.embeddedAttachmentLink {
+.embeddedAttachmentLink,
+.embeddedImageLink {
        border: 1px solid $wcfContentBorderInner;
        display: inline-block;
        max-width: 100%;