if (IMAGE_PROXY_INSECURE_ONLY && $urlComponents['scheme'] === 'https') {
// proxy is enabled for insecure connections only
+ if (!IMAGE_ALLOW_EXTERNAL_SOURCE && !$this->isAllowedOrigin($src)) {
+ $this->replaceExternalSource($element, $src);
+ }
+
continue;
}
}
}
else if (!IMAGE_ALLOW_EXTERNAL_SOURCE && !$this->isAllowedOrigin($src)) {
- $element->parentNode->insertBefore($element->ownerDocument->createTextNode('[IMG:'), $element);
-
- $link = $element->ownerDocument->createElement('a');
- $link->setAttribute('href', $src);
- $link->textContent = $src;
- HtmlOutputNodeA::markLinkAsExternal($link);
-
- $element->parentNode->insertBefore($link, $element);
-
- $element->parentNode->insertBefore($element->ownerDocument->createTextNode(']'), $element);
-
- $element->parentNode->removeChild($element);
+ $this->replaceExternalSource($element, $src);
}
else if (MESSAGE_FORCE_SECURE_IMAGES && Url::parse($src)['scheme'] === 'http') {
// rewrite protocol to `https`
}
}
+ /**
+ * Replaces images embedded from external sources that are not handled by the image proxy.
+ *
+ * @param \DOMElement $element
+ * @param string $src
+ */
+ protected function replaceExternalSource(\DOMElement $element, $src) {
+ $element->parentNode->insertBefore($element->ownerDocument->createTextNode('[IMG:'), $element);
+
+ $link = $element->ownerDocument->createElement('a');
+ $link->setAttribute('href', $src);
+ $link->textContent = $src;
+ HtmlOutputNodeA::markLinkAsExternal($link);
+
+ $element->parentNode->insertBefore($link, $element);
+
+ $element->parentNode->insertBefore($element->ownerDocument->createTextNode(']'), $element);
+
+ $element->parentNode->removeChild($element);
+ }
+
/**
* Validates the domain name against the list of own domains
* and whitelisted ones with wildcard support.