Pass emojis in remote mastodon posts in mastodon api

This commit is contained in:
gudzpoz 2023-11-14 10:52:34 +08:00
parent e088bb722b
commit 2cb0027f56
3 changed files with 26 additions and 9 deletions

View file

@ -1548,7 +1548,11 @@ class BBCode
$text = preg_replace("(\[style=(.*?)\](.*?)\[\/style\])ism", '<span style="$1">$2</span>', $text);
// Mastodon Emoji (internal tag, do not document for users)
if ($simple_html == self::MASTODON_API) {
$text = preg_replace("(\[emoji=(.*?)](.*?)\[/emoji])ism", '$2', $text);
} else {
$text = preg_replace("(\[emoji=(.*?)](.*?)\[/emoji])ism", '<span class="mastodon emoji"><img src="$1" alt="$2" title="$2"/></span>', $text);
}
// Check for CSS classes
// @deprecated since 2021.12, left for backward-compatibility reasons

View file

@ -34,19 +34,28 @@ class Emoji extends BaseFactory
/**
* Creates an emoji collection from shortcode => image mappings.
*
* Only emojis with shortcodes of the form of ':shortcode:' are passed in the collection.
*
* @param array $smilies
* @param bool $extract_url
*
* @return Emojis
*/
public function createCollectionFromArray(array $smilies): Emojis
public function createCollectionFromArray(array $smilies, bool $extract_url = true): Emojis
{
$prototype = null;
$emojis = [];
foreach ($smilies as $shortcode => $icon) {
if (preg_match('/src="(.+?)"/', $icon, $matches)) {
foreach ($smilies as $shortcode => $url) {
if (substr($shortcode, 0, 1) == ':' && substr($shortcode, -1) == ':') {
if ($extract_url) {
if (preg_match('/src="(.+?)"/', $url, $matches)) {
$url = $matches[1];
} else {
continue;
}
}
$shortcode = trim($shortcode, ':');
if ($prototype === null) {

View file

@ -292,6 +292,10 @@ class Status extends BaseFactory
if (DI::baseUrl()->isLocalUrl($item['uri'])) {
$used_smilies = Smilies::extractUsedSmilies($item['body'] ?: $item['raw-body']);
$emojis = $this->mstdnEmojiFactory->createCollectionFromArray($used_smilies)->getArrayCopy(true);
} else {
if (preg_match_all("(\[emoji=(.*?)](.*?)\[/emoji])ism", $item['body'] ?: $item['raw-body'], $matches)) {
$emojis = $this->mstdnEmojiFactory->createCollectionFromArray(array_combine($matches[2], $matches[1]), false)->getArrayCopy(true);
}
}
if ($is_reshare) {