X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FModel%2FItem.php;h=039a106e7d1750a908258bb8df2228082a9d8815;hb=0ab5fed64cdd737817489434f0f008646a28a61d;hp=921d35882d62db4f6c1a681a9c3f3cbff8037638;hpb=fe2c4f7c4b592e9991034a53378952bb52f8de68;p=friendica.git diff --git a/src/Model/Item.php b/src/Model/Item.php index 921d35882d..039a106e7d 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -1,6 +1,6 @@ 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,13 @@ class Item $item['hashtags'] = $tags['hashtags']; $item['mentions'] = $tags['mentions']; - $body = $item['body'] = Post\Media::removeFromEndOfBody($item['body'] ?? ''); + $item['body'] = preg_replace("#\s*\[attachment .*?].*?\[/attachment]\s*#ism", "\n", $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']; @@ -3021,6 +3032,7 @@ class Item $shared = DI::contentItem()->getSharedPost($item, $fields); if (!empty($shared['post'])) { $shared_item = $shared['post']; + $shared_item['body'] = Post\Media::removeFromEndOfBody($shared_item['body']); $quote_uri_id = $shared['post']['uri-id']; $shared_links[] = strtolower($shared['post']['uri']); $item['body'] = BBCode::removeSharedData($item['body']); @@ -3055,8 +3067,6 @@ class Item $attachments = Post\Media::splitAttachments($item['uri-id'], $shared_links, $item['has-media'] ?? false); $item['body'] = self::replaceVisualAttachments($attachments, $item['body'] ?? ''); - $item['body'] = preg_replace("/\s*\[attachment .*?\].*?\[\/attachment\]\s*/ism", "\n", $item['body']); - self::putInCache($item); $item['body'] = $body; $s = $item["rendered-html"]; @@ -3091,7 +3101,7 @@ class Item ]; Hook::callAll('prepare_body', $hook_data); $s = $hook_data['html']; - + unset($hook_data); if (!$attach) { @@ -3139,83 +3149,25 @@ 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 +3322,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 +3336,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 . '
'; } } @@ -3498,13 +3449,15 @@ class Item } // @todo Use a template - $preview_mode = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'preview_mode', BBCode::PREVIEW_LARGE); + $preview_mode = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'preview_mode', BBCode::PREVIEW_LARGE); if ($preview_mode != BBCode::PREVIEW_NONE) { $rendered = BBCode::convertAttachment('', BBCode::INTERNAL, false, $data, $uriid, $preview_mode); + } else { + $rendered = ''; } } elseif (!self::containsLink($content, $data['url'], Post\Media::HTML)) { $rendered = Renderer::replaceMacros(Renderer::getMarkupTemplate('content/link.tpl'), [ - '$url' => $data['url'], + '$url' => $data['url'], '$title' => $data['title'], ]); } else { @@ -3553,7 +3506,7 @@ class Item } if ($trailing != '') { - $content .= '
' . $trailing . '
'; + $content .= '
' . $trailing . '
'; } DI::profiler()->stopRecording();