]> git.mxchange.org Git - friendica.git/blobdiff - src/Protocol/Diaspora.php
Merge pull request #11079 from annando/attachments
[friendica.git] / src / Protocol / Diaspora.php
index 84f0c6de8218b31d66bf874efbf822dbea60a44e..5caa6c7a151147d53b296042af66c5872db6f3c3 100644 (file)
@@ -24,7 +24,7 @@ namespace Friendica\Protocol;
 use Friendica\Content\Feature;
 use Friendica\Content\Text\BBCode;
 use Friendica\Content\Text\Markdown;
-use Friendica\Core\Cache\Duration;
+use Friendica\Core\Cache\Enum\Duration;
 use Friendica\Core\Logger;
 use Friendica\Core\Protocol;
 use Friendica\Core\System;
@@ -3411,7 +3411,7 @@ class Diaspora
 
                        $attachments = Post\Media::getByURIId($item['uri-id'], [Post\Media::DOCUMENT, Post\Media::TORRENT, Post\Media::UNKNOWN]);
                        if (!empty($attachments)) {
-                               $body .= "\n".DI::l10n()->t("Attachments:")."\n";
+                               $body .= "\n[hr]\n";
                                foreach ($attachments as $attachment) {
                                        $body .= "[" . $attachment['description'] . "](" . $attachment['url'] . ")\n";
                                }
@@ -4053,4 +4053,53 @@ class Diaspora
 
                return $message;
        }
+
+       public static function performReshare(int $UriId, int $uid)
+       {
+               $fields = ['uri-id', 'body', 'title', 'author-name', 'author-link', 'author-avatar', 'guid', 'created', 'plink'];
+               $item = Post::selectFirst($fields, ['uri-id' => $UriId, 'uid' => [$uid, 0], 'private' => [Item::PUBLIC, Item::UNLISTED]]);
+               if (!DBA::isResult($item)) {
+                       return 0;
+               }
+
+               if (strpos($item['body'], '[/share]') !== false) {
+                       $pos = strpos($item['body'], '[share');
+                       $post = substr($item['body'], $pos);
+               } else {
+                       $post = BBCode::getShareOpeningTag($item['author-name'], $item['author-link'], $item['author-avatar'], $item['plink'], $item['created'], $item['guid']);
+
+                       if (!empty($item['title'])) {
+                               $post .= '[h3]' . $item['title'] . "[/h3]\n";
+                       }
+
+                       $post .= $item['body'];
+                       $post .= '[/share]';
+               }
+
+               $owner  = User::getOwnerDataById($uid);
+               $author = Contact::getPublicIdByUserId($uid);
+
+               $item = [
+                       'uid'        => $uid,
+                       'verb'       => Activity::POST,
+                       'contact-id' => $owner['id'],
+                       'author-id'  => $author,
+                       'owner-id'   => $author,
+                       'body'       => $post,
+                       'allow_cid'  => $owner['allow_cid'],
+                       'allow_gid'  => $owner['allow_gid'],
+                       'deny_cid'   => $owner['deny_cid'],
+                       'deny_gid'   => $owner['deny_gid'],
+               ];
+
+               if (!empty($item['allow_cid'] . $item['allow_gid'] . $item['deny_cid'] . $item['deny_gid'])) {
+                       $item['private'] = Item::PRIVATE;
+               } elseif (DI::pConfig()->get($uid, 'system', 'unlisted')) {
+                       $item['private'] = Item::UNLISTED;
+               } else {
+                       $item['private'] = Item::PUBLIC;
+               }
+
+               return Item::insert($item, true);
+       }
 }