Skip to content

Commit

Permalink
Unwrap link previews nested in paragraphs
Browse files Browse the repository at this point in the history
  • Loading branch information
dtdesign committed Aug 5, 2023
1 parent 6238b55 commit db7d228
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 6 deletions.
2 changes: 1 addition & 1 deletion com.woltlab.wcf/templates/unfurlUrl.tpl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{if $object->status == "SUCCESSFUL"}
{if $object->hasFetchedContent()}
{if $object->isPlainUrl()}
<a {anchorAttributes url=$object->url isUgc=$enableUgc}>{$object->title}</a>
{else}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,14 @@ private function getImageType(): string
return self::IMAGE_COVER;
}

/**
* @since 6.0
*/
public function hasFetchedContent(): bool
{
return $this->status === self::STATUS_SUCCESSFUL;
}

/**
* Returns the unfurl url object for a given url.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace wcf\system\html\output\node;

use wcf\data\unfurl\url\UnfurlUrl;
use wcf\system\html\AbstractHtmlProcessor;
use wcf\system\html\node\AbstractHtmlNodeProcessor;
use wcf\system\html\node\HtmlNodeUnfurlLink;
Expand Down Expand Up @@ -62,7 +63,18 @@ public function process(array $elements, AbstractHtmlNodeProcessor $htmlNodeProc
'enableUgc' => $enableUgc,
]);

$parentParagraph = null;
if ($this->getUnfurlUrl($attribute)->hasFetchedContent() && $element->parentNode->nodeName === 'p') {
$parentParagraph = $element->parentNode;
$parentParagraph->parentNode->insertBefore($element, $parentParagraph);
}

$htmlNodeProcessor->renameTag($element, $tagName);

if ($parentParagraph !== null && !$parentParagraph->hasChildNodes()) {
/** @var \DOMElement $parentParagraph */
$parentParagraph->remove();
}
}
}
}
Expand All @@ -72,9 +84,14 @@ public function process(array $elements, AbstractHtmlNodeProcessor $htmlNodeProc
*/
public function replaceTag(array $data)
{
/** @var \wcf\data\unfurl\url\UnfurlUrl $object */
$object = MessageEmbeddedObjectManager::getInstance()->getObject('com.woltlab.wcf.unfurlUrl', $data['urlId']);
return $this->getUnfurlUrl($data['urlId'])->render($data['enableUgc']);
}

return $object->render($data['enableUgc']);
/**
* @since 6.0
*/
protected function getUnfurlUrl(int $id): UnfurlUrl
{
return MessageEmbeddedObjectManager::getInstance()->getObject('com.woltlab.wcf.unfurlUrl', $id);
}
}
6 changes: 4 additions & 2 deletions wcfsetup/install/files/style/ui/unfurlUrl.scss
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
.unfurlUrlCard {
background-color: var(--wcfContentBackground);
border-radius: 3px;
box-shadow: 0 0 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.24);
box-shadow:
0 0 3px rgba(0, 0, 0, 0.12),
0 1px 2px rgba(0, 0, 0, 0.24);
color: var(--wcfContentText);
display: inline-block;
margin: 10px 0;
margin: 1em 0 0 0;
max-width: 100%;
overflow: hidden;
position: relative;
Expand Down

0 comments on commit db7d228

Please sign in to comment.