Skip to content

Commit

Permalink
Provide a default metadata if its missing from the image
Browse files Browse the repository at this point in the history
  • Loading branch information
akirk committed May 12, 2024
1 parent 93a4642 commit 31558f6
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions feed-parsers/class-feed-parser-activitypub.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ public function mastodon_api_status_add_attachments( $status, $post_id, $request
}

foreach ( $matches as $match ) {
$status->content = str_replace( $match[0], '', $status->content );
if ( ! preg_match( '/<img src="(?P<url>[^"]+)" width="(?P<width>[^"]*)" height="(?P<height>[^"]*)"/', $match[2], $block ) ) {
continue;
}
Expand All @@ -259,11 +260,15 @@ public function mastodon_api_status_add_attachments( $status, $post_id, $request
'aspect' => $block['width'] / $block['height'],
);
} else {
continue;
$attachment->meta = array(
'width' => 0,
'height' => 0,
'size' => 0x0,
'aspect' => 1,
);
}
$attachment->description = '';
$status->media_attachments[] = $attachment;
$status->content = str_replace( $match[0], '', $status->content );
}
return $status;
}
Expand Down

0 comments on commit 31558f6

Please sign in to comment.