]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/Item.php
Merge remote-tracking branch 'upstream/2022.12-rc' into diaspora-reshare
[friendica.git] / src / Model / Item.php
index 921d35882d62db4f6c1a681a9c3f3cbff8037638..33ba8ee7a4d1b849631bec1e245d17c4f91f8fc9 100644 (file)
@@ -1628,7 +1628,7 @@ class Item
 
                if (($uid != 0) && (($item['gravity'] == self::GRAVITY_PARENT) || $is_reshare) &&
                        DI::pConfig()->get($uid, 'system', 'accept_only_sharer') == self::COMPLETION_NONE &&
-                       !in_array($item['post-reason'], [self::PR_FOLLOWER, self::PR_TAG, self::PR_TO, self::PR_CC])) {
+                       !in_array($item['post-reason'], [self::PR_FOLLOWER, self::PR_TAG, self::PR_TO, self::PR_CC, self::PR_ACTIVITY])) {
                        Logger::info('Contact is not a follower, thread will not be stored', ['author' => $item['author-link'], 'uid' => $uid, 'uri-id' => $uri_id, 'post-reason' => $item['post-reason']]);
                        return 0;
                }
@@ -2282,7 +2282,12 @@ class Item
                        return;
                }
 
-               if (!DBA::exists('contact', ['id' => $item['contact-id'], 'remote_self' => Contact::MIRROR_NATIVE_RESHARE])) {
+               $cdata = Contact::getPublicAndUserContactID($item['author-id'], $item['uid']);
+               if (empty($cdata['user']) || ($cdata['user'] != $item['contact-id'])) {
+                       return;
+               }
+
+               if (!DBA::exists('contact', ['id' => $cdata['user'], 'remote_self' => Contact::MIRROR_NATIVE_RESHARE])) {
                        return;
                }
 
@@ -3011,7 +3016,11 @@ class Item
                $item['hashtags'] = $tags['hashtags'];
                $item['mentions'] = $tags['mentions'];
 
-               $body = $item['body'] = Post\Media::removeFromEndOfBody($item['body'] ?? '');
+               if (!$is_preview) {
+                       $item['body'] = Post\Media::removeFromEndOfBody($item['body'] ?? '');
+               }
+
+               $body = $item['body'];
 
                $fields = ['uri-id', 'uri', 'body', 'title', 'author-name', 'author-link', 'author-avatar', 'guid', 'created', 'plink', 'network', 'has-media', 'quote-uri-id', 'post-type'];
 
@@ -3091,7 +3100,7 @@ class Item
                ];
                Hook::callAll('prepare_body', $hook_data);
                $s = $hook_data['html'];
-               
+
                unset($hook_data);
 
                if (!$attach) {
@@ -3139,82 +3148,24 @@ class Item
         * @return string
         * @throws \Friendica\Network\HTTPException\ServiceUnavailableException
         */
-       public static function makeImageGrid(array $images): string
-       {
-               $img_tags_landscape = array();
-               $img_tags_portrait = array();
-               foreach ($images as $image) {
-                       ($image['attachment']['width'] > $image['attachment']['height']) ? ($img_tags_landscape[] = $image) : ($img_tags_portrait[] = $image);
-               }
-
-               // @todo add some fany ai to divide images equally on both columns
-               $img_tags_fc = array();
-               $img_tags_sc = array();
-               if (count($img_tags_landscape) == 0 || count($img_tags_portrait) == 0) {
-                       if (count($img_tags_landscape) == 0) {
-                               // only portrait
-                               for ($i = 0; $i < count($img_tags_portrait); $i++) {
-                                       ($i % 2 == 0) ? ($img_tags_fc[] = $img_tags_portrait[$i]) : ($img_tags_sc[] = $img_tags_portrait[$i]);
-                               }
-                       }
-                       if (count($img_tags_portrait) == 0) {
-                               // ony landscapes
-                               for ($i = 0; $i < count($img_tags_landscape); $i++) {
-                                       ($i % 2 == 0) ? ($img_tags_fc[] = $img_tags_landscape[$i]) : ($img_tags_sc[] = $img_tags_landscape[$i]);
-                               }
-                       }
-               } else {
-                       // Mix of landscape and portrait images
-                       $domformat = (count($img_tags_landscape) > count($img_tags_portrait)) ? 'landscape' : 'portrait';
-                       if ($domformat == 'landscape') {
-                               // More landscapes than portraits
-                               for ($l = 0; $l < count($img_tags_landscape); $l++) {
-                                       // use two landscapes for on portrait
-                                       if ((count($img_tags_landscape) > $l + 1) && (count($img_tags_portrait) > $l)) {
-                                               // we have one more landscape that can be used for the l-th portrait
-                                               $img_tags_fc[] = $img_tags_landscape[$l];
-                                               $img_tags_fc[] = $img_tags_landscape[$l + 1];
-                                               $img_tags_sc[] = $img_tags_portrait[$l];
-                                               $l++;
-                                       } elseif (count($img_tags_portrait) <= $l) {
-                                               // no more portraits available but landscapes
-                                               $img_tags_fc[] = $img_tags_landscape[$l];
-                                       }
-                               }
-                       }
-                       if ($domformat == 'portrait') {
-                               // More  portraits than landscapes
-                               $l = 0;
-                               for ($p = 0; $p < count($img_tags_portrait); $p++) {
-                                       // use two landscapes for on portrait
-                                       if ((count($img_tags_landscape) > $l + 1)) {
-                                               // we have one more landscape that can be used for the p-th portrait
-                                               $img_tags_sc[] = $img_tags_landscape[$l];
-                                               $img_tags_sc[] = $img_tags_landscape[$l + 1];
-                                               $img_tags_fc[] = $img_tags_portrait[$p];
-                                               // used to landscapes:
-                                               $l += 2;
-                                       } else {
-                                               // no more landscapes available
-                                               if ($p % 2 == 0 ) {
-                                                       $img_tags_fc[] = $img_tags_landscape[$l];
-                                               } else {
-                                                       $img_tags_sc[] = $img_tags_landscape[$l];
-                                               }
-
-                                       }
-                               }
-                       }
+       private static function makeImageGrid(array $images): string
+       {
+               // Image for first column (fc) and second column (sc)
+               $images_fc = [];
+               $images_sc = [];
 
+               for ($i = 0; $i < count($images); $i++) {
+                       ($i % 2 == 0) ? ($images_fc[] = $images[$i]) : ($images_sc[] = $images[$i]);
                }
 
                return Renderer::replaceMacros(Renderer::getMarkupTemplate('content/image_grid.tpl'), [
                        'columns' => [
-                               'fc' => $img_tags_fc,
-                               'sc' => $img_tags_sc,
+                               'fc' => $images_fc,
+                               'sc' => $images_sc,
                        ],
                ]);
        }
+       
 
        /**
         * Check if the body contains a link
@@ -3370,9 +3321,8 @@ class Item
                $media = '';
                if (count($images) > 1) {
                        $media = self::makeImageGrid($images);
-               }
-               elseif (count($images) == 1) {
-                       $media = $media = Renderer::replaceMacros(Renderer::getMarkupTemplate('content/image.tpl'), [
+               } elseif (count($images) == 1) {
+                       $media = Renderer::replaceMacros(Renderer::getMarkupTemplate('content/image.tpl'), [
                                '$image' => $images[0],
                        ]);
                }
@@ -3385,15 +3335,15 @@ class Item
                }
 
                if ($shared) {
-                       $content = str_replace(BBCode::TOP_ANCHOR, '<div class="body-attach">' . $leading . '<div class="clear"></div></div>' . BBCode::TOP_ANCHOR, $content);
-                       $content = str_replace(BBCode::BOTTOM_ANCHOR, '<div class="body-attach">' . $trailing . '<div class="clear"></div></div>' . BBCode::BOTTOM_ANCHOR, $content);
+                       $content = str_replace(BBCode::TOP_ANCHOR, '<div class="body-attach">' . $leading . '</div>' . BBCode::TOP_ANCHOR, $content);
+                       $content = str_replace(BBCode::BOTTOM_ANCHOR, '<div class="body-attach">' . $trailing . '</div>' . BBCode::BOTTOM_ANCHOR, $content);
                } else {
                        if ($leading != '') {
-                               $content = '<div class="body-attach">' . $leading . '<div class="clear"></div></div>' . $content;
+                               $content = '<div class="body-attach">' . $leading . '</div>' . $content;
                        }
 
                        if ($trailing != '') {
-                               $content .= '<div class="body-attach">' . $trailing . '<div class="clear"></div></div>';
+                               $content .= '<div class="body-attach">' . $trailing . '</div>';
                        }
                }
 
@@ -3553,7 +3503,7 @@ class Item
                }
 
                if ($trailing != '') {
-                       $content .= '<div class="body-attach">' . $trailing . '<div class="clear"></div></div>';
+                       $content .= '<div class="body-attach">' . $trailing . '</div>';
                }
 
                DI::profiler()->stopRecording();