]> git.mxchange.org Git - friendica.git/commitdiff
Use plaintext for names and titles
authorMichael <heluecht@pirati.ca>
Sun, 16 Jul 2023 07:26:20 +0000 (07:26 +0000)
committerMichael <heluecht@pirati.ca>
Sun, 16 Jul 2023 07:26:20 +0000 (07:26 +0000)
src/Content/Text/BBCode.php
src/Model/Event.php
src/Model/Profile.php
src/Module/Notifications/Introductions.php
src/Navigation/Notifications/Entity/Notify.php
src/Navigation/Notifications/Factory/FormattedNotify.php
src/Navigation/Notifications/Factory/Notify.php

index 503adbd57cafacfc83f9ddb6b65efa7f09ba25a3..875674544cb174d299422039eca29107b28b40ee 100644 (file)
@@ -142,7 +142,7 @@ class BBCode
                                                break;
 
                                        case 'title':
-                                               $value = self::convertForUriId(0, html_entity_decode($value, ENT_QUOTES, 'UTF-8'), BBCode::EXTERNAL);
+                                               $value = self::toPlaintext(html_entity_decode($value, ENT_QUOTES, 'UTF-8'));
                                                $value = html_entity_decode($value, ENT_QUOTES, 'UTF-8');
                                                $value = str_replace(['[', ']'], ['&#91;', '&#93;'], $value);
                                                $data['title'] = $value;
@@ -226,7 +226,7 @@ class BBCode
         * @param bool $keep_urls Whether to keep URLs in the resulting plaintext
         * @return string
         */
-       public static function toPlaintext(string $text, bool $keep_urls = true): string
+       public static function toPlaintext(string $text, bool $keep_urls = true, bool $strip_tags = false): string
        {
                DI::profiler()->startRecording('rendering');
                // Remove pictures in advance to avoid unneeded proxy calls
@@ -238,6 +238,9 @@ class BBCode
 
                $naked_text = HTML::toPlaintext(self::convert($text, false, BBCode::EXTERNAL, true), 0, !$keep_urls);
 
+               if ($strip_tags) {
+                       $naked_text = strip_tags($naked_text);
+               }
                DI::profiler()->stopRecording();
                return $naked_text;
        }
index 6ac1e2774e9c9d59d675773c23cd6d2a659f865f..5aa2f2488f4660756d426f23a7b1e396b5606bd6 100644 (file)
@@ -928,7 +928,7 @@ class Event
                }
 
                // Format the event location.
-               $location = self::locationToArray($item['event-location'], $item['uri-id']);
+               $location = self::locationToArray($item['event-location']);
 
                // Construct the profile link (magic-auth).
                $author       = [
@@ -979,7 +979,6 @@ class Event
         * handled as location name.
         *
         * @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>
@@ -987,7 +986,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, int $uri_id): array
+       private static function locationToArray(string $s): array
        {
                if ($s == '') {
                        return [];
@@ -1013,7 +1012,7 @@ class Event
                        }
                }
 
-               $location['name'] = BBCode::convertForUriId($uri_id, $location['name']);
+               $location['name'] = BBCode::toPlaintext($location['name'], false, true);
 
                // Construct the map HTML.
                if (isset($location['address'])) {
index e6c8e4822d17d3df1d47f75579b0d98fabd70849..0a6881853dd594cf93a71e6d5bed10252a1d4444 100644 (file)
@@ -640,13 +640,13 @@ class Profile
                                        $istoday = true;
                                }
 
-                               $title = strip_tags(html_entity_decode(BBCode::convertForUriId($rr['uri-id'], $rr['summary']), ENT_QUOTES, 'UTF-8'));
+                               $title = BBCode::toPlaintext($rr['summary'], false, true);
 
                                if (strlen($title) > 35) {
                                        $title = substr($title, 0, 32) . '... ';
                                }
 
-                               $description = substr(strip_tags(BBCode::convertForUriId($rr['uri-id'], $rr['desc'])), 0, 32) . '... ';
+                               $description = BBCode::toPlaintext($rr['desc'], false, true) . '... ';
                                if (!$description) {
                                        $description = DI::l10n()->t('[No description]');
                                }
index 1c4a98b47b258a41c96d832d11746a912196cde1..48c0d4dfe57f3b6342c1e426c91d2e7c95e6410b 100644 (file)
@@ -147,7 +147,7 @@ class Introductions extends BaseNotifications
                                                $knowyou = '';
                                        }
 
-                                       $convertedName = BBCode::convertForUriId($owner['uri-id'], $Introduction->getName());
+                                       $convertedName = BBCode::toPlaintext($Introduction->getName(), false, true);
 
                                        $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 56db3dc5c8b5ea52f243aa3f13583e54f664f78d..d45976c17414c9c943dc7ca41d6437150bf654d0 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::convertForUriId(0, $this->msg, BBCode::EXTERNAL)));
+               $this->msg_cache = self::formatMessage($this->name_cache, BBCode::toPlaintext($this->msg, false, true));
        }
 
        /**
@@ -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::convertForUriId(0, $name, BBCode::EXTERNAL)) . '</span>', htmlspecialchars($message));
+               return str_replace('{0}', '<span class="contactname">' . BBCode::toPlaintext($name, false, true) . '</span>', htmlspecialchars($message));
        }
 }
index 33abf63e4896e3a6411fa5ca8f232adb8ea7b3b7..75f6e767695b7ce9a18ecad538d69fb600ac1a63 100644 (file)
@@ -222,7 +222,7 @@ class FormattedNotify extends BaseFactory
                                        $this->baseUrl . '/notify/' . $Notify->id,
                                        Contact::getAvatarUrlForUrl($Notify->url, $Notify->uid, Proxy::SIZE_MICRO),
                                        $Notify->url,
-                                       strip_tags(BBCode::toPlaintext($Notify->msg ?? '')),
+                                       BBCode::toPlaintext($Notify->msg ?? '', false, true),
                                        DateTimeFormat::local($Notify->date->format(DateTimeFormat::MYSQL), 'r'),
                                        Temporal::getRelativeDate($Notify->date->format(DateTimeFormat::MYSQL)),
                                        $Notify->seen
index c180d4121af7bcbc57eb62d0260f810c8a87318c..dd59b3323c98d34929bc489e17cf612b92ae2e32 100644 (file)
@@ -68,7 +68,7 @@ class Notify extends BaseFactory implements ICanCreateFromTableRow
                        false,
                        $params['verb'] ?? '',
                        $params['otype'] ?? '',
-                       substr(strip_tags(BBCode::convertForUriId($uri_id, $params['source_name'])), 0, 255),
+                       substr(BBCode::toPlaintext($params['source_name'], false, true), 0, 255),
                        null,
                        null,
                        $item_id,