const VERSION = '2021-05-01';
const INTERNAL = 0;
+ const EXTERNAL = 1;
const API = 2;
const DIASPORA = 3;
const CONNECTORS = 4;
'$avatar' => $attributes['avatar'],
'$author' => $attributes['author'],
'$link' => $attributes['link'],
- '$link_title' => DI::l10n()->t('link to source'),
+ '$link_title' => DI::l10n()->t('Link to source'),
'$posted' => $attributes['posted'],
'$guid' => $attributes['guid'],
'$network_name' => ContactSelector::networkToName($network, $attributes['profile']),
// Handle attached links or videos
if ($simple_html == self::ACTIVITYPUB) {
$text = self::removeAttachment($text);
- } elseif (!in_array($simple_html, [self::INTERNAL, self::CONNECTORS])) {
+ } elseif (!in_array($simple_html, [self::INTERNAL, self::EXTERNAL, self::CONNECTORS])) {
$text = self::removeAttachment($text, true);
} else {
$text = self::convertAttachment($text, $simple_html, $try_oembed);
$text = str_replace('[nosmile]', '', $text);
// Replace non graphical smilies for external posts
- if (!$nosmile && !$for_plaintext) {
- $text = self::performWithEscapedTags($text, ['img'], function ($text) {
- return Smilies::replace($text);
+ if (!$nosmile) {
+ $text = self::performWithEscapedTags($text, ['img'], function ($text) use ($simple_html, $for_plaintext) {
+ return Smilies::replace($text, ($simple_html != self::INTERNAL) || $for_plaintext);
});
}
$text = HTML::purify($text, $allowedIframeDomains);
- return $text;
+ return trim($text);
}
/**
return array_unique($ret);
}
+ /**
+ * Expand tags to URLs
+ *
+ * @param string $body
+ * @return string body with expanded tags
+ */
+ public static function expandTags(string $body)
+ {
+ return preg_replace_callback("/([!#@])([^\^ \x0D\x0A,;:?\']*[^\^ \x0D\x0A,;:?!\'.])/",
+ function ($match) {
+ switch ($match[1]) {
+ case '!':
+ case '@':
+ $contact = Contact::getByURL($match[2]);
+ if (!empty($contact)) {
+ return $match[1] . '[url=' . $contact['url'] . ']' . $contact['name'] . '[/url]';
+ } else {
+ return $match[1] . $match[2];
+ }
+ break;
+ case '#':
+ return $match[1] . '[url=' . 'https://' . DI::baseUrl() . '/search?tag=' . $match[2] . ']' . $match[2] . '[/url]';
+ }
+ }, $body);
+ }
+
/**
* Perform a custom function on a text after having escaped blocks enclosed in the provided tag list.
*