fixed PostMapper.php

This commit is contained in:
amikhaylov
2026-05-28 03:05:06 +03:00
parent b3098730fc
commit 9f39390d6c
+18 -1
View File
@@ -23,6 +23,23 @@ class PostMapper
/** @var MappingStrategyInterface $strategy */ /** @var MappingStrategyInterface $strategy */
$strategy = $this->mappingStrategyFactory->getStrategy($isRepost); $strategy = $this->mappingStrategyFactory->getStrategy($isRepost);
return $strategy->map($item); return $this->fixLinks($strategy->map($item));
}
private function fixLinks(VkPost $vkPost): VkPost
{
$text = $vkPost->getText();
if (empty($text)) return $vkPost;
$newText = preg_replace_callback("#\[([^|]+)\|([^\]]+)\]#u", function ($matches) {
$alias = $matches[1]; // то, что после vk.com/
$label = $matches[2]; // текст ссылки
return "<a href=\"https://vk.com/{$alias}\" target=\"_blank\">{$label}</a>";
}, $text);
$vkPost->setText($newText);
return $vkPost;
} }
} }