]> git.mxchange.org Git - friendica.git/commitdiff
Unified BBCode conversion, improved proxy functionality
authorMichael <heluecht@pirati.ca>
Sat, 15 Jul 2023 20:12:08 +0000 (20:12 +0000)
committerMichael <heluecht@pirati.ca>
Sat, 15 Jul 2023 20:12:08 +0000 (20:12 +0000)
22 files changed:
src/Content/OEmbed.php
src/Content/Text/BBCode.php
src/Content/Text/NPF.php
src/Core/System.php
src/Factory/Api/Mastodon/Field.php
src/Model/Event.php
src/Model/User.php
src/Module/Api/Friendica/Profile/Show.php
src/Module/Debug/Babel.php
src/Module/Moderation/Report/Create.php
src/Module/Notifications/Introductions.php
src/Module/Register.php
src/Module/Tos.php
src/Navigation/Notifications/Entity/Notify.php
src/Navigation/Notifications/Factory/Introduction.php
src/Object/Api/Friendica/Notification.php
src/Object/Api/Mastodon/ScheduledStatus.php
src/Profile/ProfileField/Entity/ProfileField.php
src/Profile/ProfileField/Factory/ProfileField.php
src/Util/EMailer/NotifyMailBuilder.php
src/Util/EMailer/SystemMailBuilder.php
static/settings.config.php

index 7afdfac35c35361e230fcb3b235a0c54eb21a300..df2cafea45059b878fa05cd41e7fc84fc2697c82 100644 (file)
@@ -312,8 +312,7 @@ class OEmbed
         */
        public static function BBCode2HTML(string $text): string
        {
-               $stopoembed = DI::config()->get('system', 'no_oembed');
-               if ($stopoembed == true) {
+               if (DI::config()->get('system', 'no_oembed')) {
                        return preg_replace("/\[embed\](.+?)\[\/embed\]/is", "<!-- oembed $1 --><i>" . DI::l10n()->t('Embedding disabled') . " : $1</i><!-- /oembed $1 -->", $text);
                }
                return preg_replace_callback("/\[embed\](.+?)\[\/embed\]/is", [self::class, 'replaceCallback'], $text);
index 3635ba874cf7ee5253a68db4e2147182e0998dee..503adbd57cafacfc83f9ddb6b65efa7f09ba25a3 100644 (file)
@@ -142,7 +142,7 @@ class BBCode
                                                break;
 
                                        case 'title':
-                                               $value = self::convert(html_entity_decode($value, ENT_QUOTES, 'UTF-8'), false, true);
+                                               $value = self::convertForUriId(0, html_entity_decode($value, ENT_QUOTES, 'UTF-8'), BBCode::EXTERNAL);
                                                $value = html_entity_decode($value, ENT_QUOTES, 'UTF-8');
                                                $value = str_replace(['[', ']'], ['&#91;', '&#93;'], $value);
                                                $data['title'] = $value;
@@ -236,7 +236,7 @@ class BBCode
                // Remove attachment
                $text = self::replaceAttachment($text);
 
-               $naked_text = HTML::toPlaintext(self::convert($text, false, 0, true), 0, !$keep_urls);
+               $naked_text = HTML::toPlaintext(self::convert($text, false, BBCode::EXTERNAL, true), 0, !$keep_urls);
 
                DI::profiler()->stopRecording();
                return $naked_text;
@@ -2065,7 +2065,7 @@ class BBCode
 
                // Convert it to HTML - don't try oembed
                if ($for_diaspora) {
-                       $text = self::convert($text, false, self::DIASPORA);
+                       $text = self::convertForUriId(0, $text, self::DIASPORA);
 
                        // Add all tags that maybe were removed
                        if (preg_match_all("/#\[url\=([$url_search_string]*)\](.*?)\[\/url\]/ism", $original_text, $tags)) {
@@ -2079,7 +2079,7 @@ class BBCode
                                $text = $text . ' ' . $tagline;
                        }
                } else {
-                       $text = self::convert($text, false, self::CONNECTORS);
+                       $text = self::convertForUriId(0, $text, self::CONNECTORS);
                }
 
                // If a link is followed by a quote then there should be a newline before it
index 2f0b36083741a7c9fa0048717d430176ad63e3e2..f5a6e2dc188baf09a24f95accfdb71895a918b1a 100644 (file)
@@ -45,7 +45,7 @@ class NPF
        {
                $bbcode = self::prepareBody($bbcode);
 
-               $html = BBCode::convert($bbcode, false, BBCode::NPF);
+               $html = BBCode::convertForUriId($uri_id, $bbcode, BBCode::NPF);
                if (empty($html)) {
                        return [];
                }
index 00bdcd455c50e495d5c78587b567e8f664becc76..602d85c83c7636134b91777c58ae868ef50ecae2 100644 (file)
@@ -25,6 +25,7 @@ use Friendica\Content\Text\BBCode;
 use Friendica\Content\Text\HTML;
 use Friendica\Core\Config\Capability\IManageConfigValues;
 use Friendica\DI;
+use Friendica\Model\User;
 use Friendica\Module\Response;
 use Friendica\Network\HTTPException\FoundException;
 use Friendica\Network\HTTPException\MovedPermanentlyException;
@@ -226,9 +227,10 @@ class System
         * @param integer $depth  How many calls to include in the stacks after filtering
         * @param int     $offset How many calls to shave off the top of the stack, for example if
         *                        this is called from a centralized method that isn't relevant to the callstack
+        * @param bool    $full   If enabled, the callstack is not compacted
         * @return string
         */
-       public static function callstack(int $depth = 4, int $offset = 0): string
+       public static function callstack(int $depth = 4, int $offset = 0, bool $full = false): string
        {
                $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
 
@@ -243,7 +245,7 @@ class System
 
                while ($func = array_pop($trace)) {
                        if (!empty($func['class'])) {
-                               if (in_array($previous['function'], ['insert', 'fetch', 'toArray', 'exists', 'count', 'selectFirst', 'selectToArray',
+                               if (!$full && in_array($previous['function'], ['insert', 'fetch', 'toArray', 'exists', 'count', 'selectFirst', 'selectToArray',
                                        'select', 'update', 'delete', 'selectFirstForUser', 'selectForUser'])
                                        && (substr($previous['class'], 0, 15) === 'Friendica\Model')) {
                                        continue;
@@ -251,7 +253,7 @@ class System
 
                                // Don't show multiple calls from the Database classes to show the essential parts of the callstack
                                $func['database'] = in_array($func['class'], ['Friendica\Database\DBA', 'Friendica\Database\Database']);
-                               if (!$previous['database'] || !$func['database']) {
+                               if ($full || !$previous['database'] || !$func['database']) {
                                        $classparts = explode("\\", $func['class']);
                                        $callstack[] = array_pop($classparts).'::'.$func['function'] . (isset($func['line']) ? ' (' . $func['line'] . ')' : '');
                                        $previous = $func;
@@ -669,7 +671,7 @@ class System
 
                if (DI::config()->get('system', 'tosdisplay')) {
                        $rulelist = DI::config()->get('system', 'tosrules') ?: DI::config()->get('system', 'tostext');
-                       $html = BBCode::convert($rulelist, false, BBCode::EXTERNAL);
+                       $html = BBCode::convertForUriId(User::getSystemUriId(), $rulelist, BBCode::EXTERNAL);
 
                        $msg = HTML::toPlaintext($html, 0, true);
                        foreach (explode("\n", trim($msg)) as $line) {
index 8b24eb486153d6259609aba39ccac7ae2718219a..e4fe203057605a36b8945b9107f3397ef54e06d8 100644 (file)
@@ -38,7 +38,7 @@ class Field extends BaseFactory
         */
        public function createFromProfileField(ProfileField $profileField): \Friendica\Object\Api\Mastodon\Field
        {
-               return new \Friendica\Object\Api\Mastodon\Field($profileField->label, BBCode::convert($profileField->value, false, BBCode::ACTIVITYPUB));
+               return new \Friendica\Object\Api\Mastodon\Field($profileField->label, BBCode::convertForUriId($profileField->uriId, $profileField->value, BBCode::ACTIVITYPUB));
        }
 
        /**
index bc03370647169830d26c135f1a30068b95021ec4..6ac1e2774e9c9d59d675773c23cd6d2a659f865f 100644 (file)
@@ -928,7 +928,7 @@ class Event
                }
 
                // Format the event location.
-               $location = self::locationToArray($item['event-location']);
+               $location = self::locationToArray($item['event-location'], $item['uri-id']);
 
                // Construct the profile link (magic-auth).
                $author       = [
@@ -978,7 +978,8 @@ class Event
         * Note: The string must only contain location data. A string with no bbcode will be
         * handled as location name.
         *
-        * @param string $s The string with the bbcode formatted location data.
+        * @param string $s      The string with the bbcode formatted location data.
+        * @param int    $uri_id The uri-id of the related post
         *
         * @return array The array with the location data.
         *  'name' => The name of the location,<br>
@@ -986,7 +987,7 @@ class Event
         * 'coordinates' => Latitude and longitude (e.g. '48.864716,2.349014').<br>
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
-       private static function locationToArray(string $s = ''): array
+       private static function locationToArray(string $s, int $uri_id): array
        {
                if ($s == '') {
                        return [];
@@ -1012,7 +1013,7 @@ class Event
                        }
                }
 
-               $location['name'] = BBCode::convert($location['name']);
+               $location['name'] = BBCode::convertForUriId($uri_id, $location['name']);
 
                // Construct the map HTML.
                if (isset($location['address'])) {
index 854961154b5dfe56772dc11c70c7d4314a1eaae0..89d75849fe9430057a65a34953c718e7b68d516f 100644 (file)
@@ -132,6 +132,17 @@ class User
                return null;
        }
 
+       /**
+        * Get the Uri-Id of the system account
+        *
+        * @return integer
+        */
+       public static function getSystemUriId(): int
+       {
+               $system = self::getSystemAccount();
+               return $system['uri-id'] ?? 0;
+       }
+
        /**
         * Fetch the system account
         *
index 28909f0e39af01af0d6bbbe5ea323f3d6915783e..b97fcdcab9e9effe17d330522570205e6890bd57 100644 (file)
@@ -78,7 +78,7 @@ class Show extends BaseApi
                foreach ($profileFields as $profileField) {
                        $custom_fields[] = [
                                'label' => $profileField->label,
-                               'value' => BBCode::convert($profileField->value, false, BBCode::TWITTER_API),
+                               'value' => BBCode::convertForUriId($profileField->uriId, $profileField->value, BBCode::TWITTER_API),
                        ];
                }
 
index 560d002a1b85c93791b64f0599315a5a6e5a977e..a914f4fe908705e5abe7dec8c1aeafb84bee6550 100644 (file)
@@ -58,7 +58,7 @@ class Babel extends BaseModule
                                                'content' => visible_whitespace($plain)
                                        ];
 
-                                       $html = Text\BBCode::convert($bbcode);
+                                       $html = Text\BBCode::convertForUriId(0, $bbcode);
                                        $results[] = [
                                                'title'   => DI::l10n()->t('BBCode::convert (raw HTML)'),
                                                'content' => visible_whitespace($html)
@@ -125,7 +125,7 @@ class Babel extends BaseModule
                                                'title'   => DI::l10n()->t('PageInfo::appendToBody'),
                                                'content' => visible_whitespace($body2)
                                        ];
-                                       $html3 = Text\BBCode::convert($body2);
+                                       $html3 = Text\BBCode::convertForUriId(0, $body2);
                                        $results[] = [
                                                'title'   => DI::l10n()->t('PageInfo::appendToBody => BBCode::convert (raw HTML)'),
                                                'content' => visible_whitespace($html3)
@@ -203,7 +203,7 @@ class Babel extends BaseModule
                                                'content' => visible_whitespace($bbcode)
                                        ];
 
-                                       $html2 = Text\BBCode::convert($bbcode);
+                                       $html2 = Text\BBCode::convertForUriId(0, $bbcode);
                                        $results[] = [
                                                'title'   => DI::l10n()->t('HTML::toBBCode => BBCode::convert'),
                                                'content' => $html2
index 0e0e4c925e8a0d28861dc2045cbf9c370cc57aa0..1185730abafbd08783024ea601bf68a05d85e43c 100644 (file)
@@ -337,7 +337,7 @@ class Create extends BaseModule
                        '$contact'  => $contact,
                        '$category' => $category,
                        '$rules'    => $rules ?? [],
-                       '$comment'  => BBCode::convert($this->session->get('report_comment') ?? '', false, ),
+                       '$comment'  => BBCode::convertForUriId($contact['uri-id'] ?? 0, $this->session->get('report_comment') ?? '', BBCode::EXTERNAL),
                        '$posts'    => count($request['uri-ids']),
                ]);
        }
index 246bed54029d54f616e633de48d1ecc721a18aca..1c4a98b47b258a41c96d832d11746a912196cde1 100644 (file)
@@ -147,7 +147,7 @@ class Introductions extends BaseNotifications
                                                $knowyou = '';
                                        }
 
-                                       $convertedName = BBCode::convert($Introduction->getName());
+                                       $convertedName = BBCode::convertForUriId($owner['uri-id'], $Introduction->getName());
 
                                        $helptext  = $this->t('Shall your connection be bidirectional or not?');
                                        $helptext2 = $this->t('Accepting %s as a friend allows %s to subscribe to your posts, and you will also receive updates from them in your news feed.', $convertedName, $convertedName);
index d26fb0a3d321bfc34096ea852ef7015a4ab6bba3..a62525a986a5cbef067ed135c490eca6a7c8f9b7 100644 (file)
@@ -150,7 +150,7 @@ class Register extends BaseModule
                        '$invite_label' => DI::l10n()->t('Your invitation code: '),
                        '$invite_id'    => $invite_id,
                        '$regtitle'     => DI::l10n()->t('Registration'),
-                       '$registertext' => BBCode::convert(DI::config()->get('config', 'register_text', '')),
+                       '$registertext' => BBCode::convertForUriId(User::getSystemUriId(), DI::config()->get('config', 'register_text', '')),
                        '$fillwith'     => $fillwith,
                        '$fillext'      => $fillext,
                        '$oidlabel'     => $oidlabel,
index af64810086b77cbc4016ba2601f7222b00f73b09..3b151c31f5a7865bd793cb3c5fb460d31f4765b8 100644 (file)
@@ -27,6 +27,7 @@ use Friendica\Core\Config\Capability\IManageConfigValues;
 use Friendica\Core\L10n;
 use Friendica\Core\Renderer;
 use Friendica\Content\Text\BBCode;
+use Friendica\Model\User;
 use Friendica\Util\Profiler;
 use Psr\Log\LoggerInterface;
 
@@ -98,9 +99,9 @@ class Tos extends BaseModule
 
                        return Renderer::replaceMacros($tpl, [
                                '$title'                => $this->t('Terms of Service'),
-                               '$tostext'              => BBCode::convert($this->config->get('system', 'tostext')),
+                               '$tostext'              => BBCode::convertForUriId(User::getSystemUriId(), $this->config->get('system', 'tostext')),
                                '$rulestitle'           => $this->t('Rules'),
-                               '$rules'                => BBCode::convert($rules),
+                               '$rules'                => BBCode::convertForUriId(User::getSystemUriId(), $rules),
                                '$displayprivstatement' => $this->config->get('system', 'tosprivstatement'),
                                '$privstatementtitle'   => $this->t('Privacy Statement'),
                                '$privacy_operate'      => $this->t('At the time of registration, and for providing communications between the user account and their contacts, the user has to provide a display name (pen name), an username (nickname) and a working email address. The names will be accessible on the profile page of the account by any visitor of the page, even if other profile details are not displayed. The email address will only be used to send the user notifications about interactions, but wont be visibly displayed. The listing of an account in the node\'s user directory or the global user directory is optional and can be controlled in the user settings, it is not necessary for communication.'),
index 45f450b1d1aee9d3a7cac337e0a8c4fe3d565858..56db3dc5c8b5ea52f243aa3f13583e54f664f78d 100644 (file)
@@ -118,7 +118,7 @@ class Notify extends BaseEntity
        public function updateMsgFromPreamble($epreamble)
        {
                $this->msg       = Renderer::replaceMacros($epreamble, ['$itemlink' => $this->link->__toString()]);
-               $this->msg_cache = self::formatMessage($this->name_cache, strip_tags(BBCode::convert($this->msg)));
+               $this->msg_cache = self::formatMessage($this->name_cache, strip_tags(BBCode::convertForUriId(0, $this->msg, BBCode::EXTERNAL)));
        }
 
        /**
@@ -134,6 +134,6 @@ class Notify extends BaseEntity
         */
        public static function formatMessage(string $name, string $message): string
        {
-               return str_replace('{0}', '<span class="contactname">' . strip_tags(BBCode::convert($name)) . '</span>', htmlspecialchars($message));
+               return str_replace('{0}', '<span class="contactname">' . strip_tags(BBCode::convertForUriId(0, $name, BBCode::EXTERNAL)) . '</span>', htmlspecialchars($message));
        }
 }
index 3d176743c09b1b4a0a9507a37e7fabd677d82f4a..5078cac3cabe0349f19699632503e0f348e7310c 100644 (file)
@@ -163,8 +163,8 @@ class Introduction extends BaseFactory
                                                'contact_id'     => $intro['contact-id'],
                                                'photo'          => Contact::getPhoto($intro),
                                                'name'           => $intro['name'],
-                                               'location'       => BBCode::convert($intro['location'], false),
-                                               'about'          => BBCode::convert($intro['about'], false),
+                                               'location'       => BBCode::convertForUriId($intro['uri-id'], $intro['location'], BBCode::EXTERNAL),
+                                               'about'          => BBCode::convertForUriId ($intro['uri-id'], $intro['about'], BBCode::EXTERNAL),
                                                'keywords'       => $intro['keywords'],
                                                'hidden'         => $intro['hidden'] == 1,
                                                'post_newfriend' => (intval($this->pConfig->get($this->session->getLocalUserId(), 'system', 'post_newfriend')) ? '1' : 0),
index 92e6ff0445dc0fcf978916f1f15ee7127405a162..df59bb6b8ca8796fdee13e770ca0419e47bd1fb3 100644 (file)
@@ -98,7 +98,7 @@ class Notification extends BaseDataTransferObject
                $this->date_rel   = Temporal::getRelativeDate($this->date);
 
                try {
-                       $this->msg_html  = BBCode::convert($this->msg, false);
+                       $this->msg_html  = BBCode::convertForUriId($Notify->uriId, $this->msg, BBCode::EXTERNAL);
                } catch (\Exception $e) {
                        $this->msg_html  = '';
                }
index de28b048a119a92689668ab88b5a60521adb5c32..65506a21d5f612d21f9e1db75dc5ee669a7a4075 100644 (file)
@@ -67,7 +67,7 @@ class ScheduledStatus extends BaseDataTransferObject
                $this->scheduled_at = DateTimeFormat::utc($delayed_post['delayed'], DateTimeFormat::JSON);
 
                $this->params = [
-                       'text'           => BBCode::convert(BBCode::setMentionsToNicknames($parameters['item']['body'] ?? ''), false, BBCode::MASTODON_API),
+                       'text'           => BBCode::convertForUriId($parameters['item']['uri-id'] ?? 0, BBCode::setMentionsToNicknames($parameters['item']['body'] ?? ''), BBCode::MASTODON_API),
                        'media_ids'      => $media_ids,
                        'sensitive'      => null,
                        'spoiler_text'   => $parameters['item']['title'] ?? '',
index a2a7c43ce04fd87a58537874f99ac870b4cd2086..2461e02bd71edbb5ae259baeff1c904aab01992e 100644 (file)
@@ -34,6 +34,7 @@ use Friendica\Security\PermissionSet\Entity\PermissionSet;
  *
  * @property-read int|null  $id
  * @property-read int       $uid
+ * @property-read int       $uriId
  * @property-read int       $order
  * @property-read string    $label
  * @property-read string    $value
@@ -50,6 +51,8 @@ class ProfileField extends BaseEntity
        /** @var int */
        protected $uid;
        /** @var int */
+       protected $uriId;
+       /** @var int */
        protected $order;
        /** @var string */
        protected $label;
@@ -60,7 +63,7 @@ class ProfileField extends BaseEntity
        /** @var \DateTime */
        protected $edited;
 
-       public function __construct(int $uid, int $order, string $label, string $value, \DateTime $created, \DateTime $edited, PermissionSet $permissionSet, int $id = null)
+       public function __construct(int $uid, int $order, string $label, string $value, \DateTime $created, \DateTime $edited, PermissionSet $permissionSet, int $id = null, int $uriId = null)
        {
                $this->permissionSet = $permissionSet;
                $this->uid           = $uid;
@@ -70,6 +73,7 @@ class ProfileField extends BaseEntity
                $this->created       = $created;
                $this->edited        = $edited;
                $this->id            = $id;
+               $this->uriId         = $uriId;
        }
 
        /**
index cad542bc7db7e1d6f269e6d13c3d8b6658dfe6f7..3c8e4673ea15992522c2c037180ffce7147b7222 100644 (file)
@@ -26,6 +26,7 @@ use Friendica\Profile\ProfileField\Exception\UnexpectedPermissionSetException;
 use Friendica\Security\PermissionSet\Factory\PermissionSet as PermissionSetFactory;
 use Friendica\Profile\ProfileField\Entity;
 use Friendica\Capabilities\ICanCreateFromTableRow;
+use Friendica\Model\User;
 use Friendica\Security\PermissionSet\Entity\PermissionSet;
 use Psr\Log\LoggerInterface;
 
@@ -54,6 +55,8 @@ class ProfileField extends BaseFactory implements ICanCreateFromTableRow
                        throw new UnexpectedPermissionSetException('Either set the PermissionSet fields (join) or the PermissionSet itself');
                }
 
+               $owner = User::getOwnerDataById($row['uid']);
+
                return new Entity\ProfileField(
                        $row['uid'],
                        $row['order'],
@@ -69,7 +72,8 @@ class ProfileField extends BaseFactory implements ICanCreateFromTableRow
                                $row['deny_gid'],
                                $row['psid']
                        ),
-                       $row['id'] ?? null
+                       $row['id'] ?? null,
+                       $owner['uri-id'] ?? null
                );
        }
 
index b7e9c51d42d8a8c1322cf82cdcb45ae3467ff8a9..4191dbba2401a1e3ba09c72ba5c1f2f0fd0e6fb0 100644 (file)
@@ -179,7 +179,7 @@ class NotifyMailBuilder extends MailBuilder
         */
        protected function getHtmlMessage()
        {
-               $htmlVersion = BBCode::convert($this->body);
+               $htmlVersion = BBCode::convertForUriId(0, $this->body, BBCode::EXTERNAL);
 
                // load the template for private message notifications
                $tpl = Renderer::getMarkupTemplate('email/notify/html.tpl');
index 3c50ba9165d3ef5bd519a548c33088843895ef50..68e19ae83d92f6f5ff55df18b1e7e9f8e16acbf5 100644 (file)
@@ -100,7 +100,7 @@ class SystemMailBuilder extends MailBuilder
                        '$preamble'    => str_replace("\n", "<br>\n", $this->preamble),
                        '$thanks'      => $this->l10n->t('thanks'),
                        '$site_admin'  => $this->siteAdmin,
-                       '$htmlversion' => BBCode::convert($this->body),
+                       '$htmlversion' => BBCode::convertForUriId(0, $this->body, BBCode::EXTERNAL),
                ]);
        }
 
index 47d1a515000374c01cec2c74defdcbca5a718afa..335b702561726896fe5d434c619e8b88f1d05690 100644 (file)
@@ -164,6 +164,10 @@ return [
                // Allow pseudonyms (true) or enforce a space between first name and last name in Full name, as an anti spam measure (false).
                'no_regfullname' => true,
 
+               // no_oembed_rich_content (Boolean)
+               // If enabled, allow OEmbed for all URLs. Disabled by default.
+               'no_oembed_rich_content' => true,
+
                // optimize_tables (Boolean)
                // Periodically (once an hour) run an "optimize table" command for cache tables
                'optimize_tables' => false,