]> git.mxchange.org Git - friendica.git/commitdiff
Support for non HTML content for feed imports
authorMichael <heluecht@pirati.ca>
Sat, 11 May 2024 20:03:19 +0000 (20:03 +0000)
committerMichael <heluecht@pirati.ca>
Sat, 11 May 2024 20:03:19 +0000 (20:03 +0000)
src/Content/Text/HTML.php
src/Protocol/Feed.php

index 209b12eec49857b7d117185b2a6013973c400cb6..f3be678f9d49979ad794dea2a98fb1672cd02487 100644 (file)
@@ -253,8 +253,10 @@ class HTML
                        self::tagToBBCode($doc, 'span', ['class' => 'type-link'], '[class=type-link]', '[/class]');
                        self::tagToBBCode($doc, 'span', ['class' => 'type-video'], '[class=type-video]', '[/class]');
 
-                       $elements = ['b', 'del', 'em', 'i', 'ins', 'kbd', 'mark',
-                               's', 'samp', 'strong', 'sub', 'sup', 'u', 'var'];
+                       $elements = [
+                               'b', 'del', 'em', 'i', 'ins', 'kbd', 'mark',
+                               's', 'samp', 'strong', 'sub', 'sup', 'u', 'var'
+                       ];
                        foreach ($elements as $element) {
                                self::tagToBBCode($doc, $element, [], '[' . $element . ']', '[/' . $element . ']');
                        }
@@ -1059,4 +1061,15 @@ class HTML
 
                return null;
        }
+
+       /**
+        * Check if a document contains HTML or entities
+        *
+        * @param string $text
+        * @return boolean
+        */
+       public static function isHTML(string $text): bool
+       {
+               return ($text != html_entity_decode($text)) || ($text != strip_tags($text));
+       }
 }
index 4b5342d0a1577a2f2cd9a56353658f11ce6a124f..f1b8d26ca6f35c4e97f09a3b83dfe2b06e4023cb 100644 (file)
@@ -29,7 +29,6 @@ use Friendica\Contact\LocalRelationship\Entity\LocalRelationship;
 use Friendica\Content\PageInfo;
 use Friendica\Content\Text\BBCode;
 use Friendica\Content\Text\HTML;
-use Friendica\Core\Cache\Enum\Duration;
 use Friendica\Core\Logger;
 use Friendica\Core\Protocol;
 use Friendica\Core\Worker;
@@ -546,6 +545,13 @@ class Feed
                        if (self::titleIsBody($item['title'], $body)) {
                                $item['title'] = '';
                        }
+
+                       if (!HTML::isHTML($body)) {
+                               $original = $body;
+                               $body = BBCode::convert($body, false, BBCode::EXTERNAL);
+                               Logger::debug('Body contained no HTML', ['original' => $original, 'converted' => $body]);
+                       }
+
                        $item['body'] = HTML::toBBCode($body, $basepath);
 
                        // Remove tracking pixels