]> git.mxchange.org Git - friendica.git/blobdiff - src/Content/Text/BBCode.php
Update copyright
[friendica.git] / src / Content / Text / BBCode.php
index 87db9fb063d8e776d53fcaad1d63dc36a7b64de3..6d30afbffd7d58bef90ed4f74dc93afdf1195b40 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2010-2021, the Friendica project
+ * @copyright Copyright (C) 2010-2022, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
@@ -39,13 +39,13 @@ use Friendica\Model\Event;
 use Friendica\Model\Photo;
 use Friendica\Model\Post;
 use Friendica\Model\Tag;
-use Friendica\Network\HTTPClientOptions;
+use Friendica\Network\HTTPClient\Client\HttpClientOptions;
 use Friendica\Object\Image;
 use Friendica\Protocol\Activity;
 use Friendica\Util\Images;
 use Friendica\Util\Map;
 use Friendica\Util\ParseUrl;
-use Friendica\Util\Proxy as ProxyUtils;
+use Friendica\Util\Proxy;
 use Friendica\Util\Strings;
 use Friendica\Util\XML;
 
@@ -470,7 +470,7 @@ class BBCode
                } elseif ($uriid > 0) {
                        return Post\Link::getByLink($uriid, $image, $size);
                } else {
-                       return ProxyUtils::proxifyUrl($image, $size);
+                       return Proxy::proxifyUrl($image, $size);
                }
        }
 
@@ -687,7 +687,7 @@ class BBCode
                                        } elseif (!empty($data['preview'])) {
                                                $return .= sprintf('<a href="%s" target="_blank" rel="noopener noreferrer"><img src="%s" alt="" title="%s" class="attachment-preview" /></a><br>', $data['url'], self::proxyUrl($data['preview'], $simplehtml, $uriid), $data['title']);
                                        }
-                                       $return .= sprintf('<h4><a href="%s">%s</a></h4>', $data['url'], $data['title']);
+                                       $return .= sprintf('<h4><a href="%s" target="_blank" rel="noopener noreferrer">%s</a></h4>', $data['url'], $data['title']);
                                }
                        }
 
@@ -698,9 +698,9 @@ class BBCode
 
                        if (!empty($data['provider_url']) && !empty($data['provider_name'])) {
                                if (!empty($data['author_name'])) {
-                                       $return .= sprintf('<sup><a href="%s">%s (%s)</a></sup>', $data['provider_url'], $data['author_name'], $data['provider_name']);
+                                       $return .= sprintf('<sup><a href="%s" target="_blank" rel="noopener noreferrer">%s (%s)</a></sup>', $data['provider_url'], $data['author_name'], $data['provider_name']);
                                } else {
-                                       $return .= sprintf('<sup><a href="%s">%s</a></sup>', $data['provider_url'], $data['provider_name']);
+                                       $return .= sprintf('<sup><a href="%s" target="_blank" rel="noopener noreferrer">%s</a></sup>', $data['provider_url'], $data['provider_name']);
                                }
                        }
 
@@ -1059,9 +1059,9 @@ class BBCode
                                $attributes['profile']  = ($author_contact['url']   ?? '') ?: $attributes['profile'];
 
                                if (!empty($author_contact['id'])) {
-                                       $attributes['avatar'] = Contact::getAvatarUrlForId($author_contact['id'], ProxyUtils::SIZE_THUMB);
+                                       $attributes['avatar'] = Contact::getAvatarUrlForId($author_contact['id'], Proxy::SIZE_THUMB);
                                } elseif ($attributes['avatar']) {
-                                       $attributes['avatar'] = self::proxyUrl($attributes['avatar'], self::INTERNAL, $uriid, ProxyUtils::SIZE_THUMB);
+                                       $attributes['avatar'] = self::proxyUrl($attributes['avatar'], self::INTERNAL, $uriid, Proxy::SIZE_THUMB);
                                }
 
                                $content = preg_replace(Strings::autoLinkRegEx(), '<a href="$1">$1</a>', $match[3]);
@@ -1201,7 +1201,7 @@ class BBCode
                $text = DI::cache()->get($cache_key);
 
                if (is_null($text)) {
-                       $curlResult = DI::httpClient()->head($match[1], [HTTPClientOptions::TIMEOUT => DI::config()->get('system', 'xrd_timeout')]);
+                       $curlResult = DI::httpClient()->head($match[1], [HttpClientOptions::TIMEOUT => DI::config()->get('system', 'xrd_timeout')]);
                        if ($curlResult->isSuccess()) {
                                $mimetype = $curlResult->getHeader('Content-Type')[0] ?? '';
                        } else {
@@ -1272,7 +1272,7 @@ class BBCode
                        return $text;
                }
 
-               $curlResult = DI::httpClient()->head($match[1], [HTTPClientOptions::TIMEOUT => DI::config()->get('system', 'xrd_timeout')]);
+               $curlResult = DI::httpClient()->head($match[1], [HttpClientOptions::TIMEOUT => DI::config()->get('system', 'xrd_timeout')]);
                if ($curlResult->isSuccess()) {
                        $mimetype = $curlResult->getHeader('Content-Type')[0] ?? '';
                } else {
@@ -1560,9 +1560,6 @@ class BBCode
                                        $text = self::convertAttachment($text, $simple_html, $try_oembed, [], $uriid);
                                }
 
-                               // Add HTML new lines
-                               $text = str_replace("\n", '<br>', $text);
-
                                $nosmile = strpos($text, '[nosmile]') !== false;
                                $text = str_replace('[nosmile]', '', $text);
 
@@ -1645,11 +1642,20 @@ class BBCode
                                // Check for list text
                                $text = str_replace("[*]", "<li>", $text);
 
-                               // Check for style sheet commands
+                               // Check for block-level custom CSS
+                               $text = preg_replace('#(?<=^|\n)\[style=(.*?)](.*?)\[/style](?:\n|$)#ism', '<div style="$1">$2</div>', $text);
+
+                               // Check for inline custom CSS
                                $text = preg_replace("(\[style=(.*?)\](.*?)\[\/style\])ism", '<span style="$1">$2</span>', $text);
 
+                               // Mastodon Emoji (internal tag, do not document for users)
+                               $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
                                $text = preg_replace("(\[class=(.*?)\](.*?)\[\/class\])ism", '<span class="$1">$2</span>', $text);
+                               // Add HTML new lines
+                               $text = str_replace("\n", '<br>', $text);
 
                                // handle nested lists
                                $endlessloop = 0;
@@ -2316,7 +2322,7 @@ class BBCode
                                                break;
                                        case '#':
                                        default:
-                                               return $match[1] . '[url=' . 'https://' . DI::baseUrl() . '/search?tag=' . $match[2] . ']' . $match[2] . '[/url]';
+                                               return $match[1] . '[url=' . DI::baseUrl() . '/search?tag=' . $match[2] . ']' . $match[2] . '[/url]';
                                }
                        }, $body);
        }