fixed PostMapper.php
This commit is contained in:
@@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user