]> git.mxchange.org Git - friendica.git/commitdiff
Improve data of shared posts
authorMichael <heluecht@pirati.ca>
Fri, 7 May 2021 06:26:41 +0000 (06:26 +0000)
committerMichael <heluecht@pirati.ca>
Fri, 7 May 2021 06:26:41 +0000 (06:26 +0000)
src/Model/Item.php
src/Module/Search/Index.php
src/Protocol/ActivityPub/Processor.php
src/Protocol/DFRN.php

index 2544ed7813dc589200841bb97a0a8d83260faa1e..2d481f423f8e0aab2157097d2170a1b8bcf740f9 100644 (file)
@@ -2872,7 +2872,10 @@ class Item
                                        }
                                }
                                // @todo Judge between the links to use the one with most information
-                               if (!$found && (empty($attachment) || empty($attachment['name']) || empty($attachment['description']))) {
+                               if (!$found && (empty($attachment) || !empty($link['author-name']) ||
+                                       (empty($attachment['name']) && !empty($link['name'])) ||
+                                       (empty($attachment['description']) && !empty($link['description'])) ||
+                                       (empty($attachment['preview']) && !empty($link['preview'])))) {
                                        $attachment = $link;
                                }
                        }
@@ -3262,4 +3265,33 @@ class Item
 
                return true;
        }
+
+       /**
+        * Improve the data in shared posts
+        *
+        * @param array $item
+        * @return string body
+        */
+       public static function improveSharedDataInBody(array $item)
+       {
+               $shared = BBCode::fetchShareAttributes($item['body']);
+               if (!empty($shared['link'])) {
+                       $id = self::fetchByLink($shared['link']);
+                       Logger::info('Fetched shared post', ['uri-id' => $item['uri-id'], 'id' => $id, 'author' => $shared['profile'], 'url' => $shared['link'], 'guid' => $shared['guid'], 'callstack' => System::callstack()]);
+                       if ($id) {
+                               $shared_item = Post::selectFirst(['author-name', 'author-link', 'author-avatar', 'plink', 'created', 'guid', 'title', 'body'], ['id' => $id]);
+                               $shared_content = BBCode::getShareOpeningTag($shared_item['author-name'], $shared_item['author-link'], $shared_item['author-avatar'], $shared_item['plink'], $shared_item['created'], $shared_item['guid']);
+
+                               if (!empty($shared_item['title'])) {
+                                       $shared_content .= '[h3]'.$shared_item['title'].'[/h3]'."\n";
+                               }
+
+                               $shared_content .= $shared_item['body'];
+
+                               $item['body'] = preg_replace("/\[share.*?\](.*)\[\/share\]/ism", $shared_content . '[/share]', $item['body']);
+                               Logger::info('New shared data', ['uri-id' => $item['uri-id'], 'id' => $id, 'shared_item' => $shared_item]);
+                       }
+               }
+               return $item['body'];
+       }
 }
index d342892e1a4f8ad76f5644584eedfc80dfac3955..2fda994caae2f426b28e294de21aeb86132bb3a1 100644 (file)
@@ -34,7 +34,6 @@ use Friendica\Database\DBA;
 use Friendica\DI;
 use Friendica\Model\Contact;
 use Friendica\Model\Item;
-use Friendica\Model\ItemContent;
 use Friendica\Model\Post;
 use Friendica\Model\Tag;
 use Friendica\Module\BaseSearch;
index e36e2e7038778602adab9543cf7d013a60d67b61..ecbecb9551b5b8f5ad1ece9cb95f0caa6b5ba1ad 100644 (file)
@@ -21,7 +21,6 @@
 
 namespace Friendica\Protocol\ActivityPub;
 
-use Friendica\Content\PageInfo;
 use Friendica\Content\Text\BBCode;
 use Friendica\Content\Text\HTML;
 use Friendica\Content\Text\Markdown;
@@ -464,6 +463,7 @@ class Processor
                if (!empty($activity['source'])) {
                        $item['body'] = $activity['source'];
                        $item['raw-body'] = $content;
+                       $item['body'] = Item::improveSharedDataInBody($item);
                } else {
                        if (empty($activity['directmessage']) && ($item['thr-parent'] != $item['uri']) && ($item['gravity'] == GRAVITY_COMMENT)) {
                                $item_private = !in_array(0, $activity['item_receiver']);
index c02b02090d34f49d01760021fa9a47ca2697d79d..df974729bab07261d01cfe7b8645d167727391cc 100644 (file)
@@ -2245,6 +2245,8 @@ class DFRN
 
                $item['uri-id'] = ItemURI::insert(['uri' => $item['uri'], 'guid' => $item['guid']]);
 
+               $item["body"] = Item::improveSharedDataInBody($item);
+
                Tag::storeFromBody($item['uri-id'], $item["body"]);
 
                // We store the data from "dfrn:diaspora_signature" in a different table, this is done in "Item::insert"
@@ -2340,7 +2342,7 @@ class DFRN
                                return 403;
                        }
                }
-                               
+
                // Get the type of the item (Top level post, reply or remote reply)
                $entrytype = self::getEntryType($importer, $item);