$attachmentID = $openingTag['attributes'][0];
}
+ $hasParentLink = false;
+ if (!empty($closingTag['__parents'])) {
+ /** @var \DOMElement $parent */
+ foreach ($closingTag['__parents'] as $parent) {
+ if ($parent->nodeName === 'a') {
+ $hasParentLink = true;
+ break;
+ }
+ }
+ }
+
// get embedded object
$attachment = MessageEmbeddedObjectManager::getInstance()->getObject('com.woltlab.wcf.attachment', $attachmentID);
if ($attachment === null) {
$title = StringUtil::encodeHTML($attachment->filename);
$result = '<img src="' . $source . '" alt="">';
- if ($attachment->width > ATTACHMENT_THUMBNAIL_WIDTH || $attachment->height > ATTACHMENT_THUMBNAIL_HEIGHT) {
+ if (!$hasParentLink && ($attachment->width > ATTACHMENT_THUMBNAIL_WIDTH || $attachment->height > ATTACHMENT_THUMBNAIL_HEIGHT)) {
$result = '<a href="' . $source . '" title="' . $title . '" class="embeddedAttachmentLink jsImageViewer' . ($class ? ' '.$class : '') . '">' . $result . '</a>';
}
else {
}
$result = '<img src="'.StringUtil::encodeHTML(LinkHandler::getInstance()->getLink('Attachment', $linkParameters)).'"'.($imageClasses ? ' class="'.$imageClasses.'"' : '').' style="width: '.($attachment->hasThumbnail() ? $attachment->thumbnailWidth : $attachment->width).'px; height: '.($attachment->hasThumbnail() ? $attachment->thumbnailHeight : $attachment->height).'px;" alt="">';
- if ($attachment->hasThumbnail() && $attachment->canDownload()) {
+ if (!$hasParentLink && $attachment->hasThumbnail() && $attachment->canDownload()) {
$result = '<a href="'.StringUtil::encodeHTML(LinkHandler::getInstance()->getLink('Attachment', ['object' => $attachment])).'" title="'.StringUtil::encodeHTML($attachment->filename).'" class="embeddedAttachmentLink jsImageViewer' . ($class ? ' '.$class : '') . '">'.$result.'</a>';
}
}
<?php
namespace wcf\system\bbcode;
use wcf\system\exception\SystemException;
+use wcf\util\DOMUtil;
use wcf\util\JSON;
use wcf\util\StringUtil;
}
$openingTag = ['attributes' => $attributes, 'name' => $name];
- $closingTag = ['name' => $name];
+ $closingTag = ['name' => $name, '__parents' => DOMUtil::getReadonlyParentTree($element)];
if ($bbcode->getProcessor()) {
/** @var IBBCode $processor */
return $reverseOrder ? array_reverse($parents) : $parents;
}
+ /**
+ * Returns a cloned parent tree that is virtually readonly. In fact it can be
+ * modified, but all changes are non permanent and do not affect the source
+ * document at all.
+ *
+ * @param \DOMNode $node node
+ * @return \DOMElement[] list of parent elements
+ */
+ public static function getReadonlyParentTree(\DOMNode $node) {
+ $tree = [];
+ /** @var \DOMElement $parent */
+ foreach (self::getParents($node) as $parent) {
+ // do not include <body>, <html> and the document itself
+ if ($parent->nodeName === 'body') break;
+
+ $tree[] = $parent->cloneNode(false);
+ }
+
+ return $tree;
+ }
+
/**
* Determines the relative position of two nodes to each other.
*