diff --git a/app/Library/VK/Mapper/PostMapper.php b/app/Library/VK/Mapper/PostMapper.php index e801dfe..2052f20 100644 --- a/app/Library/VK/Mapper/PostMapper.php +++ b/app/Library/VK/Mapper/PostMapper.php @@ -23,6 +23,23 @@ class PostMapper /** @var MappingStrategyInterface $strategy */ $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 "{$label}"; + }, $text); + + $vkPost->setText($newText); + + return $vkPost; } }