X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FModel%2FItem.php;h=33ba8ee7a4d1b849631bec1e245d17c4f91f8fc9;hb=8397ccf37c2733ae74a997dab31ac55c1762a402;hp=3b9477fc31a29d43cae7154d6e46acf5b4a50fa1;hpb=1454f3bc2a3a150ee7cdafb432ab1a7f696128e5;p=friendica.git diff --git a/src/Model/Item.php b/src/Model/Item.php index 3b9477fc31..33ba8ee7a4 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -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, '
' . $leading . '
' . BBCode::TOP_ANCHOR, $content); - $content = str_replace(BBCode::BOTTOM_ANCHOR, '
' . $trailing . '
' . BBCode::BOTTOM_ANCHOR, $content); + $content = str_replace(BBCode::TOP_ANCHOR, '
' . $leading . '
' . BBCode::TOP_ANCHOR, $content); + $content = str_replace(BBCode::BOTTOM_ANCHOR, '
' . $trailing . '
' . BBCode::BOTTOM_ANCHOR, $content); } else { if ($leading != '') { - $content = '
' . $leading . '
' . $content; + $content = '
' . $leading . '
' . $content; } if ($trailing != '') { - $content .= '
' . $trailing . '
'; + $content .= '
' . $trailing . '
'; } } @@ -3553,7 +3503,7 @@ class Item } if ($trailing != '') { - $content .= '
' . $trailing . '
'; + $content .= '
' . $trailing . '
'; } DI::profiler()->stopRecording();