<?php
/**
- * @copyright Copyright (C) 2010-2022, the Friendica project
+ * @copyright Copyright (C) 2010-2023, the Friendica project
*
* @license GNU AGPL version 3 or any later version
*
use Friendica\DI;
use Friendica\Protocol\Activity;
use Friendica\Protocol\ActivityPub;
+use Friendica\Protocol\Delivery;
use Friendica\Protocol\Diaspora;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Map;
use Friendica\Util\Proxy;
use Friendica\Util\Strings;
use Friendica\Util\Temporal;
-use Friendica\Worker\Delivery;
use GuzzleHttp\Psr7\Uri;
use LanguageDetection\Language;
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;
}
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;
}
$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'];
$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']);
$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"];
];
Hook::callAll('prepare_body', $hook_data);
$s = $hook_data['html'];
-
+
unset($hook_data);
if (!$attach) {
* @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
*
$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],
]);
}
}
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>';
}
}
}
// @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 {
}
if ($trailing != '') {
- $content .= '<div class="body-attach">' . $trailing . '<div class="clear"></div></div>';
+ $content .= '<div class="body-attach">' . $trailing . '</div>';
}
DI::profiler()->stopRecording();