use Friendica\Model\Photo;
use Friendica\Network\Probe;
use Friendica\Object\Image;
use Friendica\Model\Photo;
use Friendica\Network\Probe;
use Friendica\Object\Image;
* 'text' -> Text before the shared message
* 'after' -> Text after the shared message
* 'image' -> Preview image of the message
* 'text' -> Text before the shared message
* 'after' -> Text after the shared message
* 'image' -> Preview image of the message
if (preg_match_all("(\[class=(.*?)\](.*?)\[\/class\])ism", $body, $attached, PREG_SET_ORDER)) {
foreach ($attached as $data) {
if (preg_match_all("(\[class=(.*?)\](.*?)\[\/class\])ism", $body, $attached, PREG_SET_ORDER)) {
foreach ($attached as $data) {
- if (!in_array($data[1], ["type-link", "type-video", "type-photo"])) {
+ if (!in_array($data[1], ['type-link', 'type-video', 'type-photo'])) {
- $post["text"] = trim(substr($body, 0, $pos));
- $post["after"] = trim(substr($body, $pos + strlen($data[0])));
+ $post['text'] = trim(substr($body, 0, $pos));
+ $post['after'] = trim(substr($body, $pos + strlen($data[0])));
}
// Search for description
if (preg_match("/\[quote\](.*?)\[\/quote\]/ism", $attacheddata, $matches)) {
}
// Search for description
if (preg_match("/\[quote\](.*?)\[\/quote\]/ism", $attacheddata, $matches)) {
* 'text' -> Text before the shared message
* 'after' -> Text after the shared message
* 'image' -> Preview image of the message
* 'text' -> Text before the shared message
* 'after' -> Text after the shared message
* 'image' -> Preview image of the message
if (!preg_match("/(.*)\[attachment(.*?)\](.*?)\[\/attachment\](.*)/ism", $body, $match)) {
return self::getOldAttachmentData($body);
if (!preg_match("/(.*)\[attachment(.*?)\](.*?)\[\/attachment\](.*)/ism", $body, $match)) {
return self::getOldAttachmentData($body);
preg_match("/type='(.*?)'/ism", $attributes, $matches);
if (!empty($matches[1])) {
$type = strtolower($matches[1]);
preg_match("/type='(.*?)'/ism", $attributes, $matches);
if (!empty($matches[1])) {
$type = strtolower($matches[1]);
- if (!in_array($type, ["link", "audio", "photo", "video"])) {
+ if (!in_array($type, ['link', 'audio', 'photo', 'video'])) {
preg_match("/url='(.*?)'/ism", $attributes, $matches);
if (!empty($matches[1])) {
$url = $matches[1];
preg_match("/url='(.*?)'/ism", $attributes, $matches);
if (!empty($matches[1])) {
$url = $matches[1];
preg_match("/title='(.*?)'/ism", $attributes, $matches);
if (!empty($matches[1])) {
$title = $matches[1];
preg_match("/title='(.*?)'/ism", $attributes, $matches);
if (!empty($matches[1])) {
$title = $matches[1];
$title = self::convert(html_entity_decode($title, ENT_QUOTES, 'UTF-8'), false, true);
$title = html_entity_decode($title, ENT_QUOTES, 'UTF-8');
$title = self::convert(html_entity_decode($title, ENT_QUOTES, 'UTF-8'), false, true);
$title = html_entity_decode($title, ENT_QUOTES, 'UTF-8');
- $title = str_replace(["[", "]"], ["[", "]"], $title);
- $data["title"] = $title;
+ $title = str_replace(['[', ']'], ['[', ']'], $title);
+ $data['title'] = $title;
preg_match("/image='(.*?)'/ism", $attributes, $matches);
if (!empty($matches[1])) {
$image = $matches[1];
preg_match("/image='(.*?)'/ism", $attributes, $matches);
if (!empty($matches[1])) {
$image = $matches[1];
preg_match("/preview='(.*?)'/ism", $attributes, $matches);
if (!empty($matches[1])) {
$preview = $matches[1];
preg_match("/preview='(.*?)'/ism", $attributes, $matches);
if (!empty($matches[1])) {
$preview = $matches[1];
// Simplify image codes
$body = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", '[img]$3[/img]', $body);
$body = preg_replace("/\[img\=(.*?)\](.*?)\[\/img\]/ism", '[img]$1[/img]', $body);
// Simplify image codes
$body = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", '[img]$3[/img]', $body);
$body = preg_replace("/\[img\=(.*?)\](.*?)\[\/img\]/ism", '[img]$1[/img]', $body);
if (preg_match_all("(\[url=(.*?)\]\s*\[img\](.*?)\[\/img\]\s*\[\/url\])ism", $body, $pictures, PREG_SET_ORDER)) {
if ((count($pictures) == 1) && !$has_title) {
if (preg_match_all("(\[url=(.*?)\]\s*\[img\](.*?)\[\/img\]\s*\[\/url\])ism", $body, $pictures, PREG_SET_ORDER)) {
if ((count($pictures) == 1) && !$has_title) {
// Replace the preview picture with the real picture
$url = str_replace('-1.', '-0.', $pictures[0][2]);
$data = ['url' => $url, 'type' => 'photo'];
// Replace the preview picture with the real picture
$url = str_replace('-1.', '-0.', $pictures[0][2]);
$data = ['url' => $url, 'type' => 'photo'];
// Workaround:
// Sometimes photo posts to the own album are not detected at the start.
// So we seem to cannot use the cache for these cases. That's strange.
// Workaround:
// Sometimes photo posts to the own album are not detected at the start.
// So we seem to cannot use the cache for these cases. That's strange.
- if ($data["type"] == "photo") {
- $post["type"] = "photo";
- if (isset($data["images"][0])) {
- $post["image"] = $data["images"][0]["src"];
- $post["url"] = $data["url"];
+ if ($data['type'] == 'photo') {
+ $post['type'] = 'photo';
+ if (isset($data['images'][0])) {
+ $post['image'] = $data['images'][0]['src'];
+ $post['url'] = $data['url'];
- $post["preview"] = $pictures[0][2];
- $post["text"] = trim(str_replace($pictures[0][0], "", $body));
+ $post['preview'] = $pictures[0][2];
+ $post['text'] = trim(str_replace($pictures[0][0], '', $body));
- if ($imgdata && substr($imgdata["mime"], 0, 6) == "image/") {
- $post["type"] = "photo";
- $post["image"] = $pictures[0][1];
- $post["preview"] = $pictures[0][2];
- $post["text"] = trim(str_replace($pictures[0][0], "", $body));
+ if ($imgdata && substr($imgdata['mime'], 0, 6) == 'image/') {
+ $post['type'] = 'photo';
+ $post['image'] = $pictures[0][1];
+ $post['preview'] = $pictures[0][2];
+ $post['text'] = trim(str_replace($pictures[0][0], '', $body));
}
}
} elseif (preg_match_all("(\[img\](.*?)\[\/img\])ism", $body, $pictures, PREG_SET_ORDER)) {
if ((count($pictures) == 1) && !$has_title) {
}
}
} elseif (preg_match_all("(\[img\](.*?)\[\/img\])ism", $body, $pictures, PREG_SET_ORDER)) {
if ((count($pictures) == 1) && !$has_title) {
- $post["type"] = "photo";
- $post["image"] = $pictures[0][1];
- $post["text"] = str_replace($pictures[0][0], "", $body);
+ $post['type'] = 'photo';
+ $post['image'] = $pictures[0][1];
+ $post['text'] = str_replace($pictures[0][0], '', $body);
- preg_match_all("(\[url\](.*?)\[\/url\])ism", $post["text"], $links1, PREG_SET_ORDER);
- preg_match_all("(\[url\=(.*?)\].*?\[\/url\])ism", $post["text"], $links2, PREG_SET_ORDER);
+ preg_match_all("(\[url\](.*?)\[\/url\])ism", $post['text'], $links1, PREG_SET_ORDER);
+ preg_match_all("(\[url\=(.*?)\].*?\[\/url\])ism", $post['text'], $links2, PREG_SET_ORDER);
$links = array_merge($links1, $links2);
// If there is only a single one, then use it.
// This should cover link posts via API.
$links = array_merge($links1, $links2);
// If there is only a single one, then use it.
// This should cover link posts via API.
- if ((count($links) == 1) && !isset($post["preview"]) && !$has_title) {
- $post["type"] = "link";
- $post["url"] = $links[0][1];
+ if ((count($links) == 1) && !isset($post['preview']) && !$has_title) {
+ $post['type'] = 'link';
+ $post['url'] = $links[0][1];
- preg_match_all("(\[vimeo\](.*?)\[\/vimeo\])ism", $post["text"], $links1, PREG_SET_ORDER);
- preg_match_all("(\[youtube\\](.*?)\[\/youtube\\])ism", $post["text"], $links2, PREG_SET_ORDER);
- preg_match_all("(\[video\\](.*?)\[\/video\\])ism", $post["text"], $links3, PREG_SET_ORDER);
- preg_match_all("(\[audio\\](.*?)\[\/audio\\])ism", $post["text"], $links4, PREG_SET_ORDER);
+ preg_match_all("(\[vimeo\](.*?)\[\/vimeo\])ism", $post['text'], $links1, PREG_SET_ORDER);
+ preg_match_all("(\[youtube\\](.*?)\[\/youtube\\])ism", $post['text'], $links2, PREG_SET_ORDER);
+ preg_match_all("(\[video\\](.*?)\[\/video\\])ism", $post['text'], $links3, PREG_SET_ORDER);
+ preg_match_all("(\[audio\\](.*?)\[\/audio\\])ism", $post['text'], $links4, PREG_SET_ORDER);
// Add them to the other external links
$links = array_merge($links, $links1, $links2, $links3, $links4);
// Add them to the other external links
$links = array_merge($links, $links1, $links2, $links3, $links4);
// Are there more than one?
if (count($links) > 1) {
// The post will be the type "text", which means a blog post
// Are there more than one?
if (count($links) > 1) {
// The post will be the type "text", which means a blog post
- if (!isset($post["type"])) {
- $post["type"] = "text";
- $post["text"] = trim($body);
+ if (!isset($post['type'])) {
+ $post['type'] = "text";
+ $post['text'] = trim($body);
- } elseif (isset($post["url"]) && ($post["type"] == "video")) {
- $data = ParseUrl::getSiteinfoCached($post["url"], true);
+ } elseif (isset($post['url']) && ($post['type'] == 'video')) {
+ $data = ParseUrl::getSiteinfoCached($post['url'], true);
private static function convertAttachment($return, $simplehtml = false, $tryoembed = true)
{
$data = self::getAttachmentData($return);
private static function convertAttachment($return, $simplehtml = false, $tryoembed = true)
{
$data = self::getAttachmentData($return);
- if (isset($data["title"])) {
- $data["title"] = strip_tags($data["title"]);
- $data["title"] = str_replace(["http://", "https://"], "", $data["title"]);
+ if (isset($data['title'])) {
+ $data['title'] = strip_tags($data['title']);
+ $data['title'] = str_replace(['http://', 'https://'], '', $data['title']);
- if (((strpos($data["text"], "[img=") !== false) || (strpos($data["text"], "[img]") !== false) || Config::get('system', 'always_show_preview')) && !empty($data["image"])) {
- $data["preview"] = $data["image"];
- $data["image"] = "";
+ if (((strpos($data['text'], "[img=") !== false) || (strpos($data['text'], "[img]") !== false) || Config::get('system', 'always_show_preview')) && !empty($data['image'])) {
+ $data['preview'] = $data['image'];
+ $data['image'] = '';
- if (!empty($data["image"]) && empty($data["text"]) && ($data["type"] == "photo")) {
- $return .= sprintf('<a href="%s" target="_blank"><img src="%s" alt="" title="%s" class="attachment-image" /></a>', $data["url"], self::proxyUrl($data["image"], $simplehtml), $data["title"]);
+ if (!empty($data['image']) && empty($data['text']) && ($data['type'] == 'photo')) {
+ $return .= sprintf('<a href="%s" target="_blank"><img src="%s" alt="" title="%s" class="attachment-image" /></a>', $data['url'], self::proxyUrl($data['image'], $simplehtml), $data['title']);
- if (!empty($data["image"])) {
- $return .= sprintf('<a href="%s" target="_blank"><img src="%s" alt="" title="%s" class="attachment-image" /></a><br />', $data["url"], self::proxyUrl($data["image"], $simplehtml), $data["title"]);
- } elseif (!empty($data["preview"])) {
- $return .= sprintf('<a href="%s" target="_blank"><img src="%s" alt="" title="%s" class="attachment-preview" /></a><br />', $data["url"], self::proxyUrl($data["preview"], $simplehtml), $data["title"]);
+ if (!empty($data['image'])) {
+ $return .= sprintf('<a href="%s" target="_blank"><img src="%s" alt="" title="%s" class="attachment-image" /></a><br />', $data['url'], self::proxyUrl($data['image'], $simplehtml), $data['title']);
+ } elseif (!empty($data['preview'])) {
+ $return .= sprintf('<a href="%s" target="_blank"><img src="%s" alt="" title="%s" class="attachment-preview" /></a><br />', $data['url'], self::proxyUrl($data['preview'], $simplehtml), $data['title']);
- $title = htmlentities(defaults($data, 'title', ''), ENT_QUOTES, 'UTF-8', false);
- $text = htmlentities($data["text"], ENT_QUOTES, 'UTF-8', false);
- if ($plaintext || (($title != "") && strstr($text, $title))) {
- $data["title"] = $data["url"];
- } elseif (($text != "") && strstr($title, $text)) {
- $data["text"] = $data["title"];
- $data["title"] = $data["url"];
+ $title = htmlentities($data['title'] ?? '', ENT_QUOTES, 'UTF-8', false);
+ $text = htmlentities($data['text'], ENT_QUOTES, 'UTF-8', false);
+ if ($plaintext || (($title != '') && strstr($text, $title))) {
+ $data['title'] = $data['url'];
+ } elseif (($text != '') && strstr($title, $text)) {
+ $data['text'] = $data['title'];
+ $data['title'] = $data['url'];
- if (empty($data["text"]) && !empty($data["title"]) && empty($data["url"])) {
- return $data["title"] . $data["after"];
+ if (empty($data['text']) && !empty($data['title']) && empty($data['url'])) {
+ return $data['title'] . $data['after'];
- if (!empty($data["url"]) && strpos($data["text"], $data["url"])) {
- return $data["text"] . $data["after"];
+ if (!empty($data['url']) && strpos($data['text'], $data['url'])) {
+ return $data['text'] . $data['after'];
- if (!empty($data["url"]) && !empty($data["title"])) {
- $text .= "\n[url=" . $data["url"] . "]" . $data["title"] . "[/url]";
- } elseif (!empty($data["url"])) {
- $text .= "\n[url]" . $data["url"] . "[/url]";
+ if (!empty($data['url']) && !empty($data['title'])) {
+ $text .= "\n[url=" . $data['url'] . ']' . $data['title'] . '[/url]';
+ } elseif (!empty($data['url'])) {
+ $text .= "\n[url]" . $data['url'] . '[/url]';
* @param array $match Array with the matching values
* @return string reformatted link including HTML codes
*/
* @param array $match Array with the matching values
* @return string reformatted link including HTML codes
*/
* @param string $url URL that is about to be reformatted
* @return string reformatted link including HTML codes
*/
* @param string $url URL that is about to be reformatted
* @return string reformatted link including HTML codes
*/
- private static function convertUrlForOStatus($url)
+ private static function convertUrlForActivityPub($url)
+ {
+ $html = '<a href="%s" target="_blank">%s</a>';
+ return sprintf($html, $url, self::getStyledURL($url));
+ }
+
+ /**
+ * Converts an URL in a nicer format (without the scheme and possibly shortened)
+ * @param string $url URL that is about to be reformatted
+ * @return string reformatted link
+ */
+ private static function getStyledURL($url)
$attributes = [];
foreach(['author', 'profile', 'avatar', 'link', 'posted'] as $field) {
preg_match("/$field=(['\"])(.+?)\\1/ism", $attribute_string, $matches);
$attributes = [];
foreach(['author', 'profile', 'avatar', 'link', 'posted'] as $field) {
preg_match("/$field=(['\"])(.+?)\\1/ism", $attribute_string, $matches);
- $attributes[$field] = html_entity_decode(defaults($matches, 2, ''), ENT_QUOTES, 'UTF-8');
+ $attributes[$field] = html_entity_decode($matches[2] ?? '', ENT_QUOTES, 'UTF-8');
Contact::getIdForURL($attributes['profile'], 0, true, $default);
$author_contact = Contact::getDetailsByURL($attributes['profile']);
Contact::getIdForURL($attributes['profile'], 0, true, $default);
$author_contact = Contact::getDetailsByURL($attributes['profile']);
- $attributes['author'] = defaults($author_contact, 'name' , $attributes['author']);
- $attributes['avatar'] = defaults($author_contact, 'micro', $attributes['avatar']);
- $attributes['profile'] = defaults($author_contact, 'url' , $attributes['profile']);
+ $attributes['author'] = ($author_contact['name'] ?? '') ?: $attributes['author'];
+ $attributes['avatar'] = ($author_contact['micro'] ?? '') ?: $attributes['avatar'];
+ $attributes['profile'] = ($author_contact['url'] ?? '') ?: $attributes['profile'];
if ($attributes['avatar']) {
$attributes['avatar'] = ProxyUtils::proxifyUrl($attributes['avatar'], false, ProxyUtils::SIZE_THUMB);
if ($attributes['avatar']) {
$attributes['avatar'] = ProxyUtils::proxifyUrl($attributes['avatar'], false, ProxyUtils::SIZE_THUMB);
- if (substr($curl_info["content_type"], 0, 6) == "image/") {
- $text = "[url=" . $match[1] . "]" . $match[1] . "[/url]";
+ if (substr($curl_info['content_type'], 0, 6) == 'image/') {
+ $text = "[url=" . $match[1] . ']' . $match[1] . "[/url]";
// if its not a picture then look if its a page that contains a picture link
$body = Network::fetchUrl($match[1]);
// if its not a picture then look if its a page that contains a picture link
$body = Network::fetchUrl($match[1]);
- if (strtolower($attr["name"]) == "twitter:image") {
- $text = "[url=" . $attr["content"] . "]" . $attr["content"] . "[/url]";
+ if (strtolower($attr['name']) == 'twitter:image') {
+ $text = '[url=' . $attr['content'] . ']' . $attr['content'] . '[/url]';
return ($match[1] . "[url]" . $match[2] . "[/url]");
} else {
return ($match[1] . $match[3] . " [url]" . $match[2] . "[/url]");
return ($match[1] . "[url]" . $match[2] . "[/url]");
} else {
return ($match[1] . $match[3] . " [url]" . $match[2] . "[/url]");
- if (is_null($text)) {
- $a = self::getApp();
+ // When the picture link is the own photo path then we can avoid fetching the link
+ $own_photo_url = preg_quote(Strings::normaliseLink($a->getBaseURL()) . '/photos/');
+ if (preg_match('|' . $own_photo_url . '.*?/image/|', Strings::normaliseLink($match[1]))) {
+ if (!empty($match[3])) {
+ $text = '[img=' . str_replace('-1.', '-0.', $match[2]) . ']' . $match[3] . '[/img]';
+ } else {
+ $text = '[img]' . str_replace('-1.', '-0.', $match[2]) . '[/img]';
+ }
+ return $text;
+ }
- $ch = @curl_init($match[1]);
- @curl_setopt($ch, CURLOPT_NOBODY, true);
- @curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- @curl_setopt($ch, CURLOPT_USERAGENT, $a->getUserAgent());
- @curl_exec($ch);
- $curl_info = @curl_getinfo($ch);
+ // Only fetch the header, not the content
+ $stamp1 = microtime(true);
- $a->getProfiler()->saveTimestamp($stamp1, "network", System::callstack());
+ $ch = @curl_init($match[1]);
+ @curl_setopt($ch, CURLOPT_NOBODY, true);
+ @curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+ @curl_setopt($ch, CURLOPT_USERAGENT, $a->getUserAgent());
+ @curl_exec($ch);
+ $curl_info = @curl_getinfo($ch);
- // if its a link to a picture then embed this picture
- if (substr($curl_info["content_type"], 0, 6) == "image/") {
- $text = "[img]" . $match[1] . "[/img]";
+ $a->getProfiler()->saveTimestamp($stamp1, "network", System::callstack());
+
+ // if its a link to a picture then embed this picture
+ if (substr($curl_info['content_type'], 0, 6) == 'image/') {
+ $text = '[img]' . $match[1] . '[/img]';
+ } else {
+ if (!empty($match[3])) {
+ $text = '[img=' . $match[2] . ']' . $match[3] . '[/img]';
- // if its not a picture then look if its a page that contains a picture link
- $body = Network::fetchUrl($match[1]);
+ // if its not a picture then look if its a page that contains a picture link
+ $body = Network::fetchUrl($match[1]);
- $doc = new DOMDocument();
- @$doc->loadHTML($body);
- $xpath = new DOMXPath($doc);
- $list = $xpath->query("//meta[@name]");
- foreach ($list as $node) {
- $attr = [];
- if ($node->attributes->length) {
- foreach ($node->attributes as $attribute) {
- $attr[$attribute->name] = $attribute->value;
- }
+ $doc = new DOMDocument();
+ @$doc->loadHTML($body);
+ $xpath = new DOMXPath($doc);
+ $list = $xpath->query("//meta[@name]");
+ foreach ($list as $node) {
+ $attr = [];
+ if ($node->attributes->length) {
+ foreach ($node->attributes as $attribute) {
+ $attr[$attribute->name] = $attribute->value;
- if (strtolower($attr["name"]) == "twitter:image") {
- if (!empty($match[3])) {
- $text = "[img=" . $attr["content"] . "]" . $match[3] . "[/img]";
- } else {
- $text = "[img]" . $attr["content"] . "[/img]";
- }
+ if (strtolower($attr['name']) == "twitter:image") {
+ if (!empty($match[3])) {
+ $text = "[img=" . $attr['content'] . "]" . $match[3] . "[/img]";
+ } else {
+ $text = "[img]" . $attr['content'] . "[/img]";
$text = str_replace($search, $replace, $text);
// removing multiplicated newlines
$text = str_replace($search, $replace, $text);
// removing multiplicated newlines
$search = ["\n\n\n", "\n ", " \n", "[/quote]\n\n", "\n[/quote]", "[/li]\n", "\n[li]", "\n[ul]", "[/ul]\n", "\n\n[share ", "[/attachment]\n",
"\n[h1]", "[/h1]\n", "\n[h2]", "[/h2]\n", "\n[h3]", "[/h3]\n", "\n[h4]", "[/h4]\n", "\n[h5]", "[/h5]\n", "\n[h6]", "[/h6]\n"];
$replace = ["\n\n", "\n", "\n", "[/quote]\n", "[/quote]", "[/li]", "[li]", "[ul]", "[/ul]", "\n[share ", "[/attachment]",
$search = ["\n\n\n", "\n ", " \n", "[/quote]\n\n", "\n[/quote]", "[/li]\n", "\n[li]", "\n[ul]", "[/ul]\n", "\n\n[share ", "[/attachment]\n",
"\n[h1]", "[/h1]\n", "\n[h2]", "[/h2]\n", "\n[h3]", "[/h3]\n", "\n[h4]", "[/h4]\n", "\n[h5]", "[/h5]\n", "\n[h6]", "[/h6]\n"];
$replace = ["\n\n", "\n", "\n", "[/quote]\n", "[/quote]", "[/li]", "[li]", "[ul]", "[/ul]", "\n[share ", "[/attachment]",
- $text = preg_replace("(\[size=(\d*?)\](.*?)\[\/size\])ism", "<span style=\"font-size: $1px; line-height: initial;\">$2</span>", $text);
- $text = preg_replace("(\[size=(.*?)\](.*?)\[\/size\])ism", "<span style=\"font-size: $1; line-height: initial;\">$2</span>", $text);
+ if ($simple_html != 3) {
+ $text = preg_replace("(\[size=(\d*?)\](.*?)\[\/size\])ism", "<span style=\"font-size: $1px; line-height: initial;\">$2</span>", $text);
+ $text = preg_replace("(\[size=(.*?)\](.*?)\[\/size\])ism", "<span style=\"font-size: $1; line-height: initial;\">$2</span>", $text);
+ } else {
+ // Issue 2199: Diaspora doesn't interpret the construct above, nor the <small> or <big> element
+ $text = preg_replace("(\[size=(.*?)\](.*?)\[\/size\])ism", "$2", $text);
+ }
+
// Check for centered text
$text = preg_replace("(\[center\](.*?)\[\/center\])ism", "<div style=\"text-align:center;\">$1</div>", $text);
// Check for centered text
$text = preg_replace("(\[center\](.*?)\[\/center\])ism", "<div style=\"text-align:center;\">$1</div>", $text);
// This is actually executed in Item::prepareBody()
$nosmile = strpos($text, '[nosmile]') !== false;
// This is actually executed in Item::prepareBody()
$nosmile = strpos($text, '[nosmile]') !== false;
$text = preg_replace("/\[font=(.*?)\](.*?)\[\/font\]/sm", "<span style=\"font-family: $1;\">$2</span>", $text);
// Declare the format for [spoiler] layout
$text = preg_replace("/\[font=(.*?)\](.*?)\[\/font\]/sm", "<span style=\"font-family: $1;\">$2</span>", $text);
// Declare the format for [spoiler] layout
// Check for [spoiler] text
// handle nested quotes
$endlessloop = 0;
while ((strpos($text, "[/spoiler]") !== false) && (strpos($text, "[spoiler]") !== false) && (++$endlessloop < 20)) {
// Check for [spoiler] text
// handle nested quotes
$endlessloop = 0;
while ((strpos($text, "[/spoiler]") !== false) && (strpos($text, "[spoiler]") !== false) && (++$endlessloop < 20)) {
// handle nested quotes
$endlessloop = 0;
while ((strpos($text, "[/spoiler]")!== false) && (strpos($text, "[spoiler=") !== false) && (++$endlessloop < 20)) {
$text = preg_replace("/\[spoiler=[\"\']*(.*?)[\"\']*\](.*?)\[\/spoiler\]/ism",
// handle nested quotes
$endlessloop = 0;
while ((strpos($text, "[/spoiler]")!== false) && (strpos($text, "[spoiler=") !== false) && (++$endlessloop < 20)) {
$text = preg_replace("/\[spoiler=[\"\']*(.*?)[\"\']*\](.*?)\[\/spoiler\]/ism",
- $text = preg_replace_callback("/\[url\](.*?)\[\/url\]/ism", 'self::convertUrlForOStatusCallback', $text);
- $text = preg_replace_callback("/\[url\=(.*?)\](.*?)\[\/url\]/ism", 'self::convertUrlForOStatusCallback', $text);
+ $text = preg_replace_callback("/\[url\](.*?)\[\/url\]/ism", 'self::convertUrlForActivityPubCallback', $text);
+ $text = preg_replace_callback("/\[url\=(.*?)\](.*?)\[\/url\]/ism", 'self::convertUrlForActivityPubCallback', $text);
// Clean up the HTML by loading and saving the HTML with the DOM.
// Bad structured html can break a whole page.
// For performance reasons do it only with activated item cache or at export.
// Clean up the HTML by loading and saving the HTML with the DOM.
// Bad structured html can break a whole page.
// For performance reasons do it only with activated item cache or at export.
$doctype = '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">';
$encoding = '<?xml encoding="UTF-8">';
$doctype = '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">';
$encoding = '<?xml encoding="UTF-8">';
- $text = str_replace(["<html><body>", "</body></html>", $doctype, $encoding], ["", "", "", ""], $text);
+ $text = str_replace(['<html><body>', '</body></html>', $doctype, $encoding], ['', '', '', ''], $text);
// Add all tags that maybe were removed
if (preg_match_all("/#\[url\=([$url_search_string]*)\](.*?)\[\/url\]/ism", $original_text, $tags)) {
// Add all tags that maybe were removed
if (preg_match_all("/#\[url\=([$url_search_string]*)\](.*?)\[\/url\]/ism", $original_text, $tags)) {
foreach ($tags[2] as $tag) {
$tag = html_entity_decode($tag, ENT_QUOTES, 'UTF-8');
if (!strpos(html_entity_decode($text, ENT_QUOTES, 'UTF-8'), '#' . $tag)) {
foreach ($tags[2] as $tag) {
$tag = html_entity_decode($tag, ENT_QUOTES, 'UTF-8');
if (!strpos(html_entity_decode($text, ENT_QUOTES, 'UTF-8'), '#' . $tag)) {
// If a link is followed by a quote then there should be a newline before it
// Maybe we should make this newline at every time before a quote.
// If a link is followed by a quote then there should be a newline before it
// Maybe we should make this newline at every time before a quote.