Skip to content

Commit

Permalink
Imrove "FEP-b2b8: Long-form Text" support (#982)
Browse files Browse the repository at this point in the history
* add image support

* add FEP support to federation.md
  • Loading branch information
pfefferle authored Nov 11, 2024
1 parent 31efbf9 commit 9ab694a
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
1 change: 1 addition & 0 deletions FEDERATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ The WordPress plugin largely follows ActivityPub's server-to-server specificatio
- [FEP-2677: Identifying the Application Actor](https://codeberg.org/fediverse/fep/src/branch/main/fep/2677/fep-2677.md)
- [FEP-2c59: Discovery of a Webfinger address from an ActivityPub actor](https://codeberg.org/fediverse/fep/src/branch/main/fep/2c59/fep-2c59.md)
- [FEP-fb2a: Actor metadata](https://codeberg.org/fediverse/fep/src/branch/main/fep/fb2a/fep-fb2a.md)
- [FEP-b2b8: Long-form Text](https://codeberg.org/fediverse/fep/src/branch/main/fep/b2b8/fep-b2b8.md)

Partially supported FEPs

Expand Down
53 changes: 53 additions & 0 deletions includes/transformer/class-post.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,59 @@ protected function get_attributed_to() {
return $this->get_actor_object()->get_id();
}

/**
* Returns the featured image as `Image`.
*
* @return array|null The Image or null if no image is available.
*/
protected function get_image() {
$post_id = $this->wp_object->ID;

// List post thumbnail first if this post has one.
if (
! \function_exists( 'has_post_thumbnail' ) ||
! \has_post_thumbnail( $post_id )
) {
return null;
}

$id = \get_post_thumbnail_id( $post_id );
$image_size = 'large';

/**
* Filter the image URL returned for each post.
*
* @param array|false $thumbnail The image URL, or false if no image is available.
* @param int $id The attachment ID.
* @param string $image_size The image size to retrieve. Set to 'large' by default.
*/
$thumbnail = apply_filters(
'activitypub_get_image',
self::get_wordpress_attachment( $id, $image_size ),
$id,
$image_size
);

if ( ! $thumbnail ) {
return null;
}

$mime_type = \get_post_mime_type( $id );

$image = array(
'type' => 'Image',
'url' => \esc_url( $thumbnail[0] ),
'mediaType' => \esc_attr( $mime_type ),
);

$alt = \get_post_meta( $id, '_wp_attachment_image_alt', true );
if ( $alt ) {
$image['name'] = \wp_strip_all_tags( \html_entity_decode( $alt ) );
}

return $image;
}

/**
* Generates all Media Attachments for a Post.
*
Expand Down

0 comments on commit 9ab694a

Please sign in to comment.