use Friendica\Protocol\Diaspora;
use Friendica\Security\Security;
use Friendica\Util\DateTimeFormat;
+use Friendica\Util\ParseUrl;
use Friendica\Worker\Delivery;
function item_post(App $a) {
$attachment_img_width = $_REQUEST['attachment_img_width'] ?? 0;
$attachment_img_height = $_REQUEST['attachment_img_height'] ?? 0;
- $attachment = [
- 'type' => $attachment_type,
- 'title' => $attachment_title,
- 'text' => $attachment_text,
- 'url' => $attachment_url,
- ];
+
+ // Fetch the basic attachment data
+ $attachment = ParseUrl::getSiteinfoCached($attachment_url);
+
+ // Overwrite the basic data with possible changes from the frontend
+ $attachment['type'] = $attachment_type;
+ $attachment['title'] = $attachment_title;
+ $attachment['text'] = $attachment_text;
+ $attachment['url'] = $attachment_url;
if (!empty($attachment_img_src)) {
$attachment['images'] = [
'height' => $attachment_img_height
]
];
+ } else {
+ unset($attachment['images']);
}
$att_bbcode = "\n" . PageInfo::getFooterFromData($attachment);
}
}
- if (!empty($data['title']) && empty($oembed->title)) {
+ if (!empty($data['title'])) {
$oembed->title = $data['title'];
}
- if (!empty($data['text']) && empty($oembed->description)) {
+ if (!empty($data['text'])) {
$oembed->description = $data['text'];
}
- if (!empty($data['publisher']) && empty($oembed->provider_name)) {
- $oembed->provider_name = $data['publisher'];
+ if (!empty($data['publisher_name'])) {
+ $oembed->provider_name = $data['publisher_name'];
}
- if (!empty($data['publisher_url']) && empty($oembed->provider_url)) {
+ if (!empty($data['publisher_url'])) {
$oembed->provider_url = $data['publisher_url'];
}
- if (!empty($data['author']) && empty($oembed->author_name)) {
- $oembed->author_name = $data['author'];
+ if (!empty($data['author_name'])) {
+ $oembed->author_name = $data['author_name'];
}
- if (!empty($data['author_url']) && empty($oembed->author_url)) {
+ if (!empty($data['author_url'])) {
$oembed->author_url = $data['author_url'];
}
- if (!empty($data['images']) && empty($oembed->thumbnail_url)) {
+ if (!empty($data['images'])) {
$oembed->thumbnail_url = $data['images'][0]['src'];
$oembed->thumbnail_width = $data['images'][0]['width'];
$oembed->thumbnail_height = $data['images'][0]['height'];
// Escape some bad characters
$text = "[attachment";
- foreach (['type', 'url', 'title', 'alternative_title', 'publisher', 'publisher_url', 'publisher_image', 'author', 'author_url', 'author_image'] as $field) {
+ foreach (['type', 'url', 'title', 'alternative_title', 'publisher_name', 'publisher_url', 'publisher_img', 'author_name', 'author_url', 'author_img'] as $field) {
if (!empty($data[$field])) {
$text .= " " . $field . "='" . str_replace(['[', ']'], ['[', ']'], htmlentities($data[$field], ENT_QUOTES, 'UTF-8', false)) . "'";
}
$siteinfo['text'] = trim($meta_tag['content']);
break;
case 'dc.creator':
- $siteinfo['publisher'] = trim($meta_tag['content']);
+ $siteinfo['publisher_name'] = trim($meta_tag['content']);
break;
case 'keywords':
$keywords = explode(',', $meta_tag['content']);
$siteinfo['text'] = trim($meta_tag['content']);
break;
case 'og:site_name':
- $siteinfo['publisher'] = trim($meta_tag['content']);
+ $siteinfo['publisher_name'] = trim($meta_tag['content']);
break;
case 'twitter:description':
$siteinfo['text'] = trim($meta_tag['content']);
{
$jsonldinfo = [];
- if (is_array($jsonld['publisher'])) {
+ if (!empty($jsonld['publisher']) && is_array($jsonld['publisher'])) {
$content = JsonLD::fetchElement($jsonld, 'publisher', 'name', '@type', 'Organization');
if (!empty($content) && is_string($content)) {
- $jsonldinfo['publisher'] = trim($content);
+ $jsonldinfo['publisher_name'] = trim($content);
}
$content = JsonLD::fetchElement($jsonld, 'publisher', 'url', '@type', 'Organization');
if (!empty($brand)) {
$content = JsonLD::fetchElement($brand, 'name', '@type', 'brand');
if (!empty($content) && is_string($content)) {
- $jsonldinfo['publisher'] = trim($content);
+ $jsonldinfo['publisher_name'] = trim($content);
}
}
}
- if (is_array($jsonld['author'])) {
+ if (!empty($jsonld['author']) && is_array($jsonld['author'])) {
$content = JsonLD::fetchElement($jsonld, 'author', 'name', '@type', 'Organization');
if (!empty($content) && is_string($content)) {
- $jsonldinfo['publisher'] = trim($content);
+ $jsonldinfo['publisher_name'] = trim($content);
}
$content = JsonLD::fetchElement($jsonld, 'author', 'url', '@type', 'Organization');
$content = JsonLD::fetchElement($jsonld, 'author', 'name', '@type', 'Person');
if (!empty($content) && is_string($content)) {
- $jsonldinfo['author'] = trim($content);
+ $jsonldinfo['author_name'] = trim($content);
}
$content = JsonLD::fetchElement($jsonld, 'author', 'url', '@type', 'Person');
$content = JsonLD::fetchElement($jsonld, 'name');
if (!empty($content)) {
- $jsonldinfo['publisher'] = trim($content);
+ $jsonldinfo['publisher_name'] = trim($content);
}
$content = JsonLD::fetchElement($jsonld, 'description');
$content = JsonLD::fetchElement($jsonld, 'name');
if (!empty($content)) {
- $jsonldinfo['publisher'] = trim($content);
+ $jsonldinfo['publisher_name'] = trim($content);
}
$content = JsonLD::fetchElement($jsonld, 'url');
$content = JsonLD::fetchElement($jsonld, 'logo', 'url', '@type', 'ImageObject');
if (!empty($content)) {
- $jsonldinfo['publisher_image'] = trim($content);
+ $jsonldinfo['publisher_img'] = trim($content);
}
Logger::info('Fetched Organization information', ['url' => $siteinfo['url'], 'fetched' => $jsonldinfo]);
$content = JsonLD::fetchElement($jsonld, 'name');
if (!empty($content)) {
- $jsonldinfo['author'] = trim($content);
+ $jsonldinfo['author_name'] = trim($content);
}
$content = JsonLD::fetchElement($jsonld, 'description');
$content = JsonLD::fetchElement($jsonld, 'image', 'url', '@type', 'ImageObject');
if (!empty($content)) {
- $jsonldinfo['author_image'] = trim($content);
+ $jsonldinfo['author_img'] = trim($content);
}
Logger::info('Fetched Person information', ['url' => $siteinfo['url'], 'fetched' => $jsonldinfo]);