}
$media['url'] = Network::sanitizeUrl($media['url']);
+
$media = self::unsetEmptyFields($media);
$media = DI::dbaDefinition()->truncateFieldsForTable('post-media', $media);
$imagedata = Images::getInfoFromURLCached($media['url'], empty($media['description']));
if ($imagedata) {
$media['mimetype'] = $imagedata['mime'];
- $media['size'] = $imagedata['size'];
- $media['width'] = $imagedata[0];
- $media['height'] = $imagedata[1];
+ $media['size'] = $imagedata['size'];
+ $media['width'] = $imagedata[0];
+ $media['height'] = $imagedata[1];
$media['blurhash'] = $imagedata['blurhash'] ?? null;
if (!empty($imagedata['description']) && empty($media['description'])) {
$media['description'] = $imagedata['description'];
// When the original picture is potentially animated but the preview isn't, we override the preview
if (in_array($media['mimetype'] ?? '', ['image/gif', 'image/png']) && !in_array($imagedata['mime'], ['image/gif', 'image/png'])) {
- $media['preview'] = $media['url'];
- $media['preview-width'] = $media['width'];
+ $media['preview'] = $media['url'];
+ $media['preview-width'] = $media['width'];
$media['preview-height'] = $media['height'];
return $media;
}
- $media['preview-width'] = $imagedata[0];
+ $media['preview-width'] = $imagedata[0];
$media['preview-height'] = $imagedata[1];
}
$gserver = DBA::selectFirst('gserver', ['url', 'site_name'], ['id' => $contact['gsid']]);
}
- $media['type'] = self::ACTIVITY;
- $media['media-uri-id'] = $item['uri-id'];
- $media['height'] = null;
- $media['width'] = null;
- $media['preview'] = null;
- $media['preview-height'] = null;
- $media['preview-width'] = null;
- $media['blurhash'] = null;
- $media['description'] = $item['body'];
- $media['name'] = $item['title'];
- $media['author-url'] = $item['author-link'];
- $media['author-name'] = $item['author-name'];
- $media['author-image'] = $contact['avatar'] ?? $item['author-avatar'];
- $media['publisher-url'] = $gserver['url'] ?? null;
- $media['publisher-name'] = $gserver['site_name'] ?? null;
+ $media['type'] = self::ACTIVITY;
+ $media['media-uri-id'] = $item['uri-id'];
+ $media['height'] = null;
+ $media['width'] = null;
+ $media['preview'] = null;
+ $media['preview-height'] = null;
+ $media['preview-width'] = null;
+ $media['blurhash'] = null;
+ $media['description'] = $item['body'];
+ $media['name'] = $item['title'];
+ $media['author-url'] = $item['author-link'];
+ $media['author-name'] = $item['author-name'];
+ $media['author-image'] = $contact['avatar'] ?? $item['author-avatar'];
+ $media['publisher-url'] = $gserver['url'] ?? null;
+ $media['publisher-name'] = $gserver['site_name'] ?? null;
$media['publisher-image'] = null;
Logger::debug('Activity detected', ['uri-id' => $media['uri-id'], 'url' => $media['url'], 'plink' => $item['plink'], 'uri' => $item['uri']]);
$gserver = DBA::selectFirst('gserver', ['url', 'site_name'], ['id' => $contact['gsid']]);
}
- $media['type'] = self::ACCOUNT;
- $media['media-uri-id'] = $contact['uri-id'];
- $media['height'] = null;
- $media['width'] = null;
- $media['preview'] = null;
- $media['preview-height'] = null;
- $media['preview-width'] = null;
- $media['blurhash'] = null;
- $media['description'] = $contact['about'];
- $media['name'] = $contact['name'];
- $media['author-url'] = $contact['url'];
- $media['author-name'] = $contact['name'];
- $media['author-image'] = $contact['avatar'];
- $media['publisher-url'] = $gserver['url'] ?? null;
- $media['publisher-name'] = $gserver['site_name'] ?? null;
+ $media['type'] = self::ACCOUNT;
+ $media['media-uri-id'] = $contact['uri-id'];
+ $media['height'] = null;
+ $media['width'] = null;
+ $media['preview'] = null;
+ $media['preview-height'] = null;
+ $media['preview-width'] = null;
+ $media['blurhash'] = null;
+ $media['description'] = $contact['about'];
+ $media['name'] = $contact['name'];
+ $media['author-url'] = $contact['url'];
+ $media['author-name'] = $contact['name'];
+ $media['author-image'] = $contact['avatar'];
+ $media['publisher-url'] = $gserver['url'] ?? null;
+ $media['publisher-name'] = $gserver['site_name'] ?? null;
$media['publisher-image'] = null;
Logger::debug('Account detected', ['uri-id' => $media['uri-id'], 'url' => $media['url'], 'uri' => $contact['url']]);
Logger::debug('Detected site data is empty, use suggested media data instead', ['uri-id' => $media['uri-id'], 'url' => $media['url'], 'type' => $data['type']]);
}
} else {
- $media['preview'] = $data['images'][0]['src'] ?? null;
- $media['preview-height'] = $data['images'][0]['height'] ?? null;
- $media['preview-width'] = $data['images'][0]['width'] ?? null;
- $media['blurhash'] = $data['images'][0]['blurhash'] ?? null;
- $media['description'] = $data['text'] ?? null;
- $media['name'] = $data['title'] ?? null;
- }
-
- $media['type'] = self::HTML;
- $media['size'] = $data['size'] ?? null;
- $media['author-url'] = $data['author_url'] ?? null;
- $media['author-name'] = $data['author_name'] ?? null;
- $media['author-image'] = $data['author_img'] ?? null;
- $media['publisher-url'] = $data['publisher_url'] ?? null;
- $media['publisher-name'] = $data['publisher_name'] ?? null;
- $media['publisher-image'] = $data['publisher_img'] ?? null;
+ $media['preview'] = $data['images'][0]['src'] ?? null;
+ $media['preview-height'] = $data['images'][0]['height'] ?? null;
+ $media['preview-width'] = $data['images'][0]['width'] ?? null;
+ $media['blurhash'] = $data['images'][0]['blurhash'] ?? null;
+ $media['description'] = $data['text'] ?? null;
+ $media['name'] = $data['title'] ?? null;
+ }
+
+ $media['type'] = self::HTML;
+ $media['size'] = $data['size'] ?? null;
+ $media['author-url'] = $data['author_url'] ?? null;
+ $media['author-name'] = $data['author_name'] ?? null;
+ $media['author-image'] = $data['author_img'] ?? null;
+ $media['publisher-url'] = $data['publisher_url'] ?? null;
+ $media['publisher-name'] = $data['publisher_name'] ?? null;
+ $media['publisher-image'] = $data['publisher_img'] ?? null;
return $media;
}
$photo = Photo::selectFirst(['type', 'datasize', 'width', 'height', 'blurhash'], ['resource-id' => $matches[1], 'scale' => $matches[2]]);
if (!empty($photo)) {
$media['mimetype'] = $photo['type'];
- $media['size'] = $photo['datasize'];
- $media['width'] = $photo['width'];
- $media['height'] = $photo['height'];
+ $media['size'] = $photo['datasize'];
+ $media['width'] = $photo['width'];
+ $media['height'] = $photo['height'];
$media['blurhash'] = $photo['blurhash'];
}
}
$photo = Photo::selectFirst(['width', 'height'], ['resource-id' => $matches[1], 'scale' => $matches[2]]);
if (!empty($photo)) {
- $media['preview-width'] = $photo['width'];
+ $media['preview-width'] = $photo['width'];
$media['preview-height'] = $photo['height'];
}
}
$filetype = strtolower($type[0]);
- $subtype = strtolower($type[1]);
+ $subtype = strtolower($type[1]);
if ($filetype == 'image') {
$type = self::IMAGE;
if (preg_match_all("#\[url=([^\]]+?)\]\s*\[img=([^\[\]]*)\]([^\[\]]*)\[\/img\]\s*\[/url\]$endmatchpattern#ism", $body, $pictures, PREG_SET_ORDER)) {
foreach ($pictures as $picture) {
if (self::isLinkToImagePage($picture[1], $picture[2])) {
- $body = str_replace($picture[0], '', $body);
+ $body = str_replace($picture[0], '', $body);
$image = str_replace(['-1.', '-2.'], '-0.', $picture[2]);
+
$attachments[$image] = [
'uri-id' => $uriid,
'type' => self::IMAGE,
];
} elseif (self::isLinkToPhoto($picture[1], $picture[2])) {
$body = str_replace($picture[0], '', $body);
+
$attachments[$picture[1]] = [
'uri-id' => $uriid,
'type' => self::IMAGE,
];
} elseif ($removepicturelinks) {
$body = str_replace($picture[0], '', $body);
+
$attachments[$picture[1]] = [
'uri-id' => $uriid,
'type' => self::UNKNOWN,
if (preg_match_all("/\[img=([^\[\]]*)\]([^\[\]]*)\[\/img\]$endmatchpattern/Usi", $body, $pictures, PREG_SET_ORDER)) {
foreach ($pictures as $picture) {
$body = str_replace($picture[0], '', $body);
+
$attachments[$picture[1]] = ['uri-id' => $uriid, 'type' => self::IMAGE, 'url' => $picture[1], 'description' => $picture[2]];
}
}
if (preg_match_all("#\[url=([^\]]+?)\]\s*\[img\]([^\[]+?)\[/img\]\s*\[/url\]$endmatchpattern#ism", $body, $pictures, PREG_SET_ORDER)) {
foreach ($pictures as $picture) {
if (self::isLinkToImagePage($picture[1], $picture[2])) {
- $body = str_replace($picture[0], '', $body);
+ $body = str_replace($picture[0], '', $body);
$image = str_replace(['-1.', '-2.'], '-0.', $picture[2]);
+
$attachments[$image] = [
'uri-id' => $uriid,
'type' => self::IMAGE,
];
} elseif (self::isLinkToPhoto($picture[1], $picture[2])) {
$body = str_replace($picture[0], '', $body);
+
$attachments[$picture[1]] = [
'uri-id' => $uriid,
'type' => self::IMAGE,
];
} elseif ($removepicturelinks) {
$body = str_replace($picture[0], '', $body);
+
$attachments[$picture[1]] = [
'uri-id' => $uriid,
'type' => self::UNKNOWN,
if (preg_match_all("/\[img\]([^\[\]]*)\[\/img\]$endmatchpattern/ism", $body, $pictures, PREG_SET_ORDER)) {
foreach ($pictures as $picture) {
$body = str_replace($picture[0], '', $body);
+
$attachments[$picture[1]] = ['uri-id' => $uriid, 'type' => self::IMAGE, 'url' => $picture[1]];
}
}
if (preg_match_all("/\[audio\]([^\[\]]*)\[\/audio\]$endmatchpattern/ism", $body, $audios, PREG_SET_ORDER)) {
foreach ($audios as $audio) {
$body = str_replace($audio[0], '', $body);
+
$attachments[$audio[1]] = ['uri-id' => $uriid, 'type' => self::AUDIO, 'url' => $audio[1]];
}
}
if (preg_match_all("/\[video\]([^\[\]]*)\[\/video\]$endmatchpattern/ism", $body, $videos, PREG_SET_ORDER)) {
foreach ($videos as $video) {
$body = str_replace($video[0], '', $body);
+
$attachments[$video[1]] = ['uri-id' => $uriid, 'type' => self::VIDEO, 'url' => $video[1]];
}
}
{
do {
$prebody = $body;
- $body = self::insertFromBody(0, $body, true);
+ $body = self::insertFromBody(0, $body, true);
} while ($prebody != $body);
return $body;
}
{
do {
$prebody = $body;
- $body = self::insertFromBody(0, $body, false, true);
+ $body = self::insertFromBody(0, $body, false, true);
} while ($prebody != $body);
return $body;
}
Logger::info('Adding attachment data', ['data' => $data]);
$attachment = [
- 'uri-id' => $uriid,
- 'type' => self::HTML,
- 'url' => $data['url'],
- 'preview' => $data['preview'] ?? null,
- 'description' => $data['description'] ?? null,
- 'name' => $data['title'] ?? null,
- 'author-url' => $data['author_url'] ?? null,
- 'author-name' => $data['author_name'] ?? null,
- 'publisher-url' => $data['provider_url'] ?? null,
+ 'uri-id' => $uriid,
+ 'type' => self::HTML,
+ 'url' => $data['url'],
+ 'preview' => $data['preview'] ?? null,
+ 'description' => $data['description'] ?? null,
+ 'name' => $data['title'] ?? null,
+ 'author-url' => $data['author_url'] ?? null,
+ 'author-name' => $data['author_name'] ?? null,
+ 'publisher-url' => $data['provider_url'] ?? null,
'publisher-name' => $data['provider_name'] ?? null,
];
if (!empty($data['image'])) {
}
foreach ($matches as $attachment) {
- $media['type'] = self::DOCUMENT;
- $media['uri-id'] = $uriid;
- $media['url'] = $attachment[1];
- $media['size'] = $attachment[2];
- $media['mimetype'] = $attachment[3];
+ $media['type'] = self::DOCUMENT;
+ $media['uri-id'] = $uriid;
+ $media['url'] = $attachment[1];
+ $media['size'] = $attachment[2];
+ $media['mimetype'] = $attachment[3];
$media['description'] = $attachment[4] ?? '';
self::insert($media);
}
$data = [
- 'type' => 'link',
- 'url' => $links[0]['url'],
- 'title' => $links[0]['name'],
- 'text' => $links[0]['description'],
+ 'type' => 'link',
+ 'url' => $links[0]['url'],
+ 'title' => $links[0]['name'],
+ 'text' => $links[0]['description'],
'publisher_name' => $links[0]['publisher-name'],
- 'publisher_url' => $links[0]['publisher-url'],
- 'publisher_img' => $links[0]['publisher-image'],
- 'author_name' => $links[0]['author-name'],
- 'author_url' => $links[0]['author-url'],
- 'author_img' => $links[0]['author-image'],
- 'images' => [[
- 'src' => $links[0]['preview'],
+ 'publisher_url' => $links[0]['publisher-url'],
+ 'publisher_img' => $links[0]['publisher-image'],
+ 'author_name' => $links[0]['author-name'],
+ 'author_url' => $links[0]['author-url'],
+ 'author_img' => $links[0]['author-image'],
+ 'images' => [[
+ 'src' => $links[0]['preview'],
'height' => $links[0]['preview-height'],
- 'width' => $links[0]['preview-width'],
+ 'width' => $links[0]['preview-width'],
]]
];
$body .= "\n" . PageInfo::getFooterFromData($data);