]> git.mxchange.org Git - friendica.git/commitdiff
Improved code structure
authorMichael <heluecht@pirati.ca>
Fri, 7 May 2021 11:41:10 +0000 (11:41 +0000)
committerMichael <heluecht@pirati.ca>
Fri, 7 May 2021 11:41:10 +0000 (11:41 +0000)
src/Model/Item.php

index 2d481f423f8e0aab2157097d2170a1b8bcf740f9..64bd266c83fd970351b1d19811a489384c4d49b1 100644 (file)
@@ -3275,23 +3275,31 @@ class Item
        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";
-                               }
+               if (empty($shared['link'])) {
+                       return $item['body'];   
+               }
+               
+               $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) {
+                       return $item['body'];   
+               }
+
+               $shared_item = Post::selectFirst(['author-name', 'author-link', 'author-avatar', 'plink', 'created', 'guid', 'title', 'body'], ['id' => $id]);
+               if (!DBA::isResult($shared_item)) {
+                       return $item['body'];   
+               }
 
-                               $shared_content .= $shared_item['body'];
+               $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']);
 
-                               $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]);
-                       }
+               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'];
        }
 }