Adjusted field names

This commit is contained in:
Michael 2021-03-16 06:37:43 +00:00
parent 70bf75c342
commit 0a3d50a270
4 changed files with 35 additions and 29 deletions

View file

@ -56,6 +56,7 @@ use Friendica\Protocol\Activity;
use Friendica\Protocol\Diaspora; use Friendica\Protocol\Diaspora;
use Friendica\Security\Security; use Friendica\Security\Security;
use Friendica\Util\DateTimeFormat; use Friendica\Util\DateTimeFormat;
use Friendica\Util\ParseUrl;
use Friendica\Worker\Delivery; use Friendica\Worker\Delivery;
function item_post(App $a) { function item_post(App $a) {
@ -217,12 +218,15 @@ function item_post(App $a) {
$attachment_img_width = $_REQUEST['attachment_img_width'] ?? 0; $attachment_img_width = $_REQUEST['attachment_img_width'] ?? 0;
$attachment_img_height = $_REQUEST['attachment_img_height'] ?? 0; $attachment_img_height = $_REQUEST['attachment_img_height'] ?? 0;
$attachment = [
'type' => $attachment_type, // Fetch the basic attachment data
'title' => $attachment_title, $attachment = ParseUrl::getSiteinfoCached($attachment_url);
'text' => $attachment_text,
'url' => $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)) { if (!empty($attachment_img_src)) {
$attachment['images'] = [ $attachment['images'] = [
@ -232,6 +236,8 @@ function item_post(App $a) {
'height' => $attachment_img_height 'height' => $attachment_img_height
] ]
]; ];
} else {
unset($attachment['images']);
} }
$att_bbcode = "\n" . PageInfo::getFooterFromData($attachment); $att_bbcode = "\n" . PageInfo::getFooterFromData($attachment);

View file

@ -163,31 +163,31 @@ class OEmbed
} }
} }
if (!empty($data['title']) && empty($oembed->title)) { if (!empty($data['title'])) {
$oembed->title = $data['title']; $oembed->title = $data['title'];
} }
if (!empty($data['text']) && empty($oembed->description)) { if (!empty($data['text'])) {
$oembed->description = $data['text']; $oembed->description = $data['text'];
} }
if (!empty($data['publisher']) && empty($oembed->provider_name)) { if (!empty($data['publisher_name'])) {
$oembed->provider_name = $data['publisher']; $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']; $oembed->provider_url = $data['publisher_url'];
} }
if (!empty($data['author']) && empty($oembed->author_name)) { if (!empty($data['author_name'])) {
$oembed->author_name = $data['author']; $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']; $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_url = $data['images'][0]['src'];
$oembed->thumbnail_width = $data['images'][0]['width']; $oembed->thumbnail_width = $data['images'][0]['width'];
$oembed->thumbnail_height = $data['images'][0]['height']; $oembed->thumbnail_height = $data['images'][0]['height'];

View file

@ -131,7 +131,7 @@ class PageInfo
// Escape some bad characters // Escape some bad characters
$text = "[attachment"; $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])) { if (!empty($data[$field])) {
$text .= " " . $field . "='" . str_replace(['[', ']'], ['[', ']'], htmlentities($data[$field], ENT_QUOTES, 'UTF-8', false)) . "'"; $text .= " " . $field . "='" . str_replace(['[', ']'], ['[', ']'], htmlentities($data[$field], ENT_QUOTES, 'UTF-8', false)) . "'";
} }

View file

@ -392,7 +392,7 @@ class ParseUrl
$siteinfo['text'] = trim($meta_tag['content']); $siteinfo['text'] = trim($meta_tag['content']);
break; break;
case 'dc.creator': case 'dc.creator':
$siteinfo['publisher'] = trim($meta_tag['content']); $siteinfo['publisher_name'] = trim($meta_tag['content']);
break; break;
case 'keywords': case 'keywords':
$keywords = explode(',', $meta_tag['content']); $keywords = explode(',', $meta_tag['content']);
@ -441,7 +441,7 @@ class ParseUrl
$siteinfo['text'] = trim($meta_tag['content']); $siteinfo['text'] = trim($meta_tag['content']);
break; break;
case 'og:site_name': case 'og:site_name':
$siteinfo['publisher'] = trim($meta_tag['content']); $siteinfo['publisher_name'] = trim($meta_tag['content']);
break; break;
case 'twitter:description': case 'twitter:description':
$siteinfo['text'] = trim($meta_tag['content']); $siteinfo['text'] = trim($meta_tag['content']);
@ -555,10 +555,10 @@ class ParseUrl
{ {
$jsonldinfo = []; $jsonldinfo = [];
if (is_array($jsonld['publisher'])) { if (!empty($jsonld['publisher']) && is_array($jsonld['publisher'])) {
$content = JsonLD::fetchElement($jsonld, 'publisher', 'name', '@type', 'Organization'); $content = JsonLD::fetchElement($jsonld, 'publisher', 'name', '@type', 'Organization');
if (!empty($content) && is_string($content)) { if (!empty($content) && is_string($content)) {
$jsonldinfo['publisher'] = trim($content); $jsonldinfo['publisher_name'] = trim($content);
} }
$content = JsonLD::fetchElement($jsonld, 'publisher', 'url', '@type', 'Organization'); $content = JsonLD::fetchElement($jsonld, 'publisher', 'url', '@type', 'Organization');
@ -570,15 +570,15 @@ class ParseUrl
if (!empty($brand)) { if (!empty($brand)) {
$content = JsonLD::fetchElement($brand, 'name', '@type', 'brand'); $content = JsonLD::fetchElement($brand, 'name', '@type', 'brand');
if (!empty($content) && is_string($content)) { 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'); $content = JsonLD::fetchElement($jsonld, 'author', 'name', '@type', 'Organization');
if (!empty($content) && is_string($content)) { 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', 'url', '@type', 'Organization');
@ -588,7 +588,7 @@ class ParseUrl
$content = JsonLD::fetchElement($jsonld, 'author', 'name', '@type', 'Person'); $content = JsonLD::fetchElement($jsonld, 'author', 'name', '@type', 'Person');
if (!empty($content) && is_string($content)) { 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, 'author', 'url', '@type', 'Person');
@ -692,7 +692,7 @@ class ParseUrl
$content = JsonLD::fetchElement($jsonld, 'name'); $content = JsonLD::fetchElement($jsonld, 'name');
if (!empty($content)) { if (!empty($content)) {
$jsonldinfo['publisher'] = trim($content); $jsonldinfo['publisher_name'] = trim($content);
} }
$content = JsonLD::fetchElement($jsonld, 'description'); $content = JsonLD::fetchElement($jsonld, 'description');
@ -729,7 +729,7 @@ class ParseUrl
$content = JsonLD::fetchElement($jsonld, 'name'); $content = JsonLD::fetchElement($jsonld, 'name');
if (!empty($content)) { if (!empty($content)) {
$jsonldinfo['publisher'] = trim($content); $jsonldinfo['publisher_name'] = trim($content);
} }
$content = JsonLD::fetchElement($jsonld, 'url'); $content = JsonLD::fetchElement($jsonld, 'url');
@ -739,7 +739,7 @@ class ParseUrl
$content = JsonLD::fetchElement($jsonld, 'logo', 'url', '@type', 'ImageObject'); $content = JsonLD::fetchElement($jsonld, 'logo', 'url', '@type', 'ImageObject');
if (!empty($content)) { if (!empty($content)) {
$jsonldinfo['publisher_image'] = trim($content); $jsonldinfo['publisher_img'] = trim($content);
} }
Logger::info('Fetched Organization information', ['url' => $siteinfo['url'], 'fetched' => $jsonldinfo]); Logger::info('Fetched Organization information', ['url' => $siteinfo['url'], 'fetched' => $jsonldinfo]);
@ -759,7 +759,7 @@ class ParseUrl
$content = JsonLD::fetchElement($jsonld, 'name'); $content = JsonLD::fetchElement($jsonld, 'name');
if (!empty($content)) { if (!empty($content)) {
$jsonldinfo['author'] = trim($content); $jsonldinfo['author_name'] = trim($content);
} }
$content = JsonLD::fetchElement($jsonld, 'description'); $content = JsonLD::fetchElement($jsonld, 'description');
@ -774,7 +774,7 @@ class ParseUrl
$content = JsonLD::fetchElement($jsonld, 'image', 'url', '@type', 'ImageObject'); $content = JsonLD::fetchElement($jsonld, 'image', 'url', '@type', 'ImageObject');
if (!empty($content)) { if (!empty($content)) {
$jsonldinfo['author_image'] = trim($content); $jsonldinfo['author_img'] = trim($content);
} }
Logger::info('Fetched Person information', ['url' => $siteinfo['url'], 'fetched' => $jsonldinfo]); Logger::info('Fetched Person information', ['url' => $siteinfo['url'], 'fetched' => $jsonldinfo]);