2023-10-22 22:20:53 +00:00
|
|
|
<?php
|
|
|
|
namespace Activitypub\Transformer;
|
|
|
|
|
|
|
|
use WP_Post;
|
2024-02-08 12:31:25 +00:00
|
|
|
use Activitypub\Shortcodes;
|
2024-06-27 12:10:38 +00:00
|
|
|
use Activitypub\Model\Blog;
|
2024-02-08 12:31:25 +00:00
|
|
|
use Activitypub\Transformer\Base;
|
|
|
|
use Activitypub\Collection\Users;
|
2023-10-22 22:20:53 +00:00
|
|
|
|
|
|
|
use function Activitypub\esc_hashtag;
|
|
|
|
use function Activitypub\is_single_user;
|
2024-06-27 12:10:38 +00:00
|
|
|
use function Activitypub\get_enclosures;
|
2023-10-22 22:20:53 +00:00
|
|
|
use function Activitypub\get_rest_url_by_path;
|
|
|
|
use function Activitypub\site_supports_blocks;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* WordPress Post Transformer
|
|
|
|
*
|
2024-02-08 12:31:25 +00:00
|
|
|
* The Post Transformer is responsible for transforming a WP_Post object into different other
|
2023-10-22 22:20:53 +00:00
|
|
|
* Object-Types.
|
|
|
|
*
|
|
|
|
* Currently supported are:
|
|
|
|
*
|
|
|
|
* - Activitypub\Activity\Base_Object
|
|
|
|
*/
|
2024-02-08 12:31:25 +00:00
|
|
|
class Post extends Base {
|
2023-10-22 22:20:53 +00:00
|
|
|
/**
|
2024-02-08 12:31:25 +00:00
|
|
|
* Returns the ID of the WordPress Post.
|
2023-10-22 22:20:53 +00:00
|
|
|
*
|
2024-02-08 12:31:25 +00:00
|
|
|
* @return int The ID of the WordPress Post
|
2023-10-22 22:20:53 +00:00
|
|
|
*/
|
2024-02-08 12:31:25 +00:00
|
|
|
public function get_wp_user_id() {
|
|
|
|
return $this->wp_object->post_author;
|
2023-10-22 22:20:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2024-02-08 12:31:25 +00:00
|
|
|
* Change the User-ID of the WordPress Post.
|
2023-10-22 22:20:53 +00:00
|
|
|
*
|
2024-02-08 12:31:25 +00:00
|
|
|
* @return int The User-ID of the WordPress Post
|
2023-10-22 22:20:53 +00:00
|
|
|
*/
|
2024-02-08 12:31:25 +00:00
|
|
|
public function change_wp_user_id( $user_id ) {
|
|
|
|
$this->wp_object->post_author = $user_id;
|
|
|
|
|
|
|
|
return $this;
|
2023-10-22 22:20:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Transforms the WP_Post object to an ActivityPub Object
|
|
|
|
*
|
|
|
|
* @see \Activitypub\Activity\Base_Object
|
|
|
|
*
|
|
|
|
* @return \Activitypub\Activity\Base_Object The ActivityPub Object
|
|
|
|
*/
|
|
|
|
public function to_object() {
|
2024-02-08 12:31:25 +00:00
|
|
|
$post = $this->wp_object;
|
|
|
|
$object = parent::to_object();
|
2023-10-22 22:20:53 +00:00
|
|
|
|
2024-02-08 12:31:25 +00:00
|
|
|
$published = \strtotime( $post->post_date_gmt );
|
2023-10-22 22:20:53 +00:00
|
|
|
|
|
|
|
$object->set_published( \gmdate( 'Y-m-d\TH:i:s\Z', $published ) );
|
|
|
|
|
2024-02-08 12:31:25 +00:00
|
|
|
$updated = \strtotime( $post->post_modified_gmt );
|
2023-10-22 22:20:53 +00:00
|
|
|
|
|
|
|
if ( $updated > $published ) {
|
|
|
|
$object->set_updated( \gmdate( 'Y-m-d\TH:i:s\Z', $updated ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
$object->set_content_map(
|
|
|
|
array(
|
2023-12-08 23:23:11 +00:00
|
|
|
$this->get_locale() => $this->get_content(),
|
2023-10-22 22:20:53 +00:00
|
|
|
)
|
|
|
|
);
|
2024-06-27 12:10:38 +00:00
|
|
|
$path = sprintf( 'actors/%d/followers', intval( $post->post_author ) );
|
2023-10-22 22:20:53 +00:00
|
|
|
|
|
|
|
$object->set_to(
|
|
|
|
array(
|
|
|
|
'https://www.w3.org/ns/activitystreams#Public',
|
|
|
|
get_rest_url_by_path( $path ),
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
return $object;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the ID of the Post.
|
|
|
|
*
|
|
|
|
* @return string The Posts ID.
|
|
|
|
*/
|
|
|
|
public function get_id() {
|
|
|
|
return $this->get_url();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the URL of the Post.
|
|
|
|
*
|
|
|
|
* @return string The Posts URL.
|
|
|
|
*/
|
|
|
|
public function get_url() {
|
2024-02-08 12:31:25 +00:00
|
|
|
$post = $this->wp_object;
|
2023-10-22 22:20:53 +00:00
|
|
|
|
|
|
|
if ( 'trash' === get_post_status( $post ) ) {
|
|
|
|
$permalink = \get_post_meta( $post->ID, 'activitypub_canonical_url', true );
|
2024-07-19 19:46:05 +00:00
|
|
|
} elseif ( 'draft' === get_post_status( $post ) && get_sample_permalink( $post->ID ) ) {
|
|
|
|
$sample = get_sample_permalink( $post->ID );
|
|
|
|
$permalink = str_replace( array( '%pagename%', '%postname%' ), $sample[1], $sample[0] );
|
2023-10-22 22:20:53 +00:00
|
|
|
} else {
|
|
|
|
$permalink = \get_permalink( $post );
|
|
|
|
}
|
|
|
|
|
|
|
|
return \esc_url( $permalink );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the User-URL of the Author of the Post.
|
|
|
|
*
|
|
|
|
* If `single_user` mode is enabled, the URL of the Blog-User is returned.
|
|
|
|
*
|
|
|
|
* @return string The User-URL.
|
|
|
|
*/
|
|
|
|
protected function get_attributed_to() {
|
2024-06-27 12:10:38 +00:00
|
|
|
$blog_user = new Blog();
|
2024-02-08 12:31:25 +00:00
|
|
|
|
2023-10-22 22:20:53 +00:00
|
|
|
if ( is_single_user() ) {
|
2024-02-08 12:31:25 +00:00
|
|
|
return $blog_user->get_url();
|
|
|
|
}
|
|
|
|
|
|
|
|
$user = Users::get_by_id( $this->wp_object->post_author );
|
|
|
|
|
|
|
|
if ( $user && ! is_wp_error( $user ) ) {
|
2023-10-22 22:20:53 +00:00
|
|
|
return $user->get_url();
|
|
|
|
}
|
|
|
|
|
2024-02-08 12:31:25 +00:00
|
|
|
return $blog_user->get_url();
|
2023-10-22 22:20:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2023-12-08 23:23:11 +00:00
|
|
|
* Generates all Media Attachments for a Post.
|
2023-10-22 22:20:53 +00:00
|
|
|
*
|
2023-12-08 23:23:11 +00:00
|
|
|
* @return array The Attachments.
|
|
|
|
*/
|
2024-02-08 12:31:25 +00:00
|
|
|
protected function get_attachment() {
|
2024-07-19 19:46:05 +00:00
|
|
|
// Remove attachments from drafts.
|
|
|
|
if ( 'draft' === \get_post_status( $this->wp_object ) ) {
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
2023-12-08 23:23:11 +00:00
|
|
|
// Once upon a time we only supported images, but we now support audio/video as well.
|
|
|
|
// We maintain the image-centric naming for backwards compatibility.
|
2024-06-27 12:10:38 +00:00
|
|
|
$max_media = \intval(
|
|
|
|
\apply_filters(
|
|
|
|
'activitypub_max_image_attachments',
|
|
|
|
\get_option( 'activitypub_max_image_attachments', ACTIVITYPUB_MAX_IMAGE_ATTACHMENTS )
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$media = array(
|
|
|
|
'audio' => array(),
|
|
|
|
'video' => array(),
|
|
|
|
'image' => array(),
|
|
|
|
);
|
|
|
|
$id = $this->wp_object->ID;
|
|
|
|
|
|
|
|
// list post thumbnail first if this post has one
|
|
|
|
if ( \function_exists( 'has_post_thumbnail' ) && \has_post_thumbnail( $id ) ) {
|
|
|
|
$media['image'][] = array( 'id' => \get_post_thumbnail_id( $id ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
$media = $this->get_enclosures( $media );
|
2023-12-08 23:23:11 +00:00
|
|
|
|
2024-02-08 12:31:25 +00:00
|
|
|
if ( site_supports_blocks() && \has_blocks( $this->wp_object->post_content ) ) {
|
2024-06-27 12:10:38 +00:00
|
|
|
$media = $this->get_block_attachments( $media, $max_media );
|
2024-04-19 10:49:31 +00:00
|
|
|
} else {
|
2024-06-27 12:10:38 +00:00
|
|
|
$media = $this->get_classic_editor_images( $media, $max_media );
|
2023-12-08 23:23:11 +00:00
|
|
|
}
|
|
|
|
|
2024-06-27 12:10:38 +00:00
|
|
|
$media = self::filter_media_by_object_type( $media, \get_post_format( $this->wp_object ), $this->wp_object );
|
2024-04-19 10:49:31 +00:00
|
|
|
$unique_ids = \array_unique( \array_column( $media, 'id' ) );
|
|
|
|
$media = \array_intersect_key( $media, $unique_ids );
|
|
|
|
$media = \array_slice( $media, 0, $max_media );
|
|
|
|
|
|
|
|
return \array_filter( \array_map( array( self::class, 'wp_attachment_to_activity_attachment' ), $media ) );
|
2023-12-08 23:23:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get media attachments from blocks. They will be formatted as ActivityPub attachments, not as WP attachments.
|
|
|
|
*
|
2024-06-27 12:10:38 +00:00
|
|
|
* @param array $media The media array grouped by type.
|
|
|
|
* @param int $max_media The maximum number of attachments to return.
|
2023-12-08 23:23:11 +00:00
|
|
|
*
|
|
|
|
* @return array The attachments.
|
2023-10-22 22:20:53 +00:00
|
|
|
*/
|
2024-06-27 12:10:38 +00:00
|
|
|
protected function get_block_attachments( $media, $max_media ) {
|
2023-12-08 23:23:11 +00:00
|
|
|
// max media can't be negative or zero
|
|
|
|
if ( $max_media <= 0 ) {
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
2024-06-27 12:10:38 +00:00
|
|
|
$blocks = \parse_blocks( $this->wp_object->post_content );
|
|
|
|
$media = self::get_media_from_blocks( $blocks, $media );
|
2023-12-08 23:23:11 +00:00
|
|
|
|
2024-06-27 12:10:38 +00:00
|
|
|
return $media;
|
2023-10-22 22:20:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2023-12-08 23:23:11 +00:00
|
|
|
* Get image attachments from the classic editor.
|
2024-02-08 12:31:25 +00:00
|
|
|
* This is imperfect as the contained images aren't necessarily the
|
|
|
|
* same as the attachments.
|
|
|
|
*
|
|
|
|
* @param int $max_images The maximum number of images to return.
|
|
|
|
*
|
|
|
|
* @return array The attachment IDs.
|
|
|
|
*/
|
|
|
|
protected function get_classic_editor_image_attachments( $max_images ) {
|
|
|
|
// max images can't be negative or zero
|
|
|
|
if ( $max_images <= 0 ) {
|
|
|
|
return array();
|
|
|
|
}
|
2024-06-27 12:10:38 +00:00
|
|
|
|
2024-04-19 10:49:31 +00:00
|
|
|
$images = array();
|
2024-06-27 12:10:38 +00:00
|
|
|
$query = new \WP_Query(
|
2024-02-08 12:31:25 +00:00
|
|
|
array(
|
|
|
|
'post_parent' => $this->wp_object->ID,
|
|
|
|
'post_status' => 'inherit',
|
|
|
|
'post_type' => 'attachment',
|
|
|
|
'post_mime_type' => 'image',
|
|
|
|
'order' => 'ASC',
|
|
|
|
'orderby' => 'menu_order ID',
|
|
|
|
'posts_per_page' => $max_images,
|
|
|
|
)
|
|
|
|
);
|
2024-06-27 12:10:38 +00:00
|
|
|
|
2024-02-08 12:31:25 +00:00
|
|
|
foreach ( $query->get_posts() as $attachment ) {
|
2024-04-19 10:49:31 +00:00
|
|
|
if ( ! \in_array( $attachment->ID, $images, true ) ) {
|
|
|
|
$images[] = array( 'id' => $attachment->ID );
|
2024-02-08 12:31:25 +00:00
|
|
|
}
|
|
|
|
}
|
2024-04-19 10:49:31 +00:00
|
|
|
|
|
|
|
return $images;
|
2024-02-08 12:31:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get image embeds from the classic editor by parsing HTML.
|
|
|
|
*
|
|
|
|
* @param int $max_images The maximum number of images to return.
|
|
|
|
*
|
2024-04-19 10:49:31 +00:00
|
|
|
* @return array The attachments.
|
2024-02-08 12:31:25 +00:00
|
|
|
*/
|
|
|
|
protected function get_classic_editor_image_embeds( $max_images ) {
|
|
|
|
// if someone calls that function directly, bail
|
|
|
|
if ( ! \class_exists( '\WP_HTML_Tag_Processor' ) ) {
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
|
|
|
// max images can't be negative or zero
|
|
|
|
if ( $max_images <= 0 ) {
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
2024-04-19 10:49:31 +00:00
|
|
|
$images = array();
|
|
|
|
$base = \wp_get_upload_dir()['baseurl'];
|
|
|
|
$content = \get_post_field( 'post_content', $this->wp_object );
|
|
|
|
$tags = new \WP_HTML_Tag_Processor( $content );
|
2024-02-08 12:31:25 +00:00
|
|
|
|
|
|
|
// This linter warning is a false positive - we have to
|
2024-04-19 10:49:31 +00:00
|
|
|
// re-count each time here as we modify $images.
|
2024-02-08 12:31:25 +00:00
|
|
|
// phpcs:ignore Squiz.PHP.DisallowSizeFunctionsInLoops.Found
|
2024-06-27 12:10:38 +00:00
|
|
|
while ( $tags->next_tag( 'img' ) && ( \count( $images ) <= $max_images ) ) {
|
2024-02-08 12:31:25 +00:00
|
|
|
$src = $tags->get_attribute( 'src' );
|
|
|
|
|
|
|
|
// If the img source is in our uploads dir, get the
|
|
|
|
// associated ID. Note: if there's a -500x500
|
|
|
|
// type suffix, we remove it, but we try the original
|
|
|
|
// first in case the original image is actually called
|
|
|
|
// that. Likewise, we try adding the -scaled suffix for
|
|
|
|
// the case that this is a small version of an image
|
|
|
|
// that was big enough to get scaled down on upload:
|
|
|
|
// https://make.wordpress.org/core/2019/10/09/introducing-handling-of-big-images-in-wordpress-5-3/
|
|
|
|
if ( null !== $src && \str_starts_with( $src, $base ) ) {
|
|
|
|
$img_id = \attachment_url_to_postid( $src );
|
|
|
|
|
|
|
|
if ( 0 === $img_id ) {
|
|
|
|
$count = 0;
|
|
|
|
$src = preg_replace( '/-(?:\d+x\d+)(\.[a-zA-Z]+)$/', '$1', $src, 1, $count );
|
|
|
|
if ( $count > 0 ) {
|
|
|
|
$img_id = \attachment_url_to_postid( $src );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( 0 === $img_id ) {
|
|
|
|
$src = preg_replace( '/(\.[a-zA-Z]+)$/', '-scaled$1', $src );
|
|
|
|
$img_id = \attachment_url_to_postid( $src );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( 0 !== $img_id ) {
|
2024-04-19 10:49:31 +00:00
|
|
|
$images[] = array(
|
|
|
|
'id' => $img_id,
|
|
|
|
'alt' => $tags->get_attribute( 'alt' ),
|
|
|
|
);
|
2024-02-08 12:31:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-04-19 10:49:31 +00:00
|
|
|
|
|
|
|
return $images;
|
2024-02-08 12:31:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get post images from the classic editor.
|
2023-12-08 23:23:11 +00:00
|
|
|
* Note that audio/video attachments are only supported in the block editor.
|
|
|
|
*
|
2024-06-27 12:10:38 +00:00
|
|
|
* @param array $media The media array grouped by type.
|
|
|
|
* @param int $max_images The maximum number of images to return.
|
2023-10-22 22:20:53 +00:00
|
|
|
*
|
2023-12-08 23:23:11 +00:00
|
|
|
* @return array The attachments.
|
|
|
|
*/
|
2024-06-27 12:10:38 +00:00
|
|
|
protected function get_classic_editor_images( $media, $max_images ) {
|
2023-12-08 23:23:11 +00:00
|
|
|
// max images can't be negative or zero
|
|
|
|
if ( $max_images <= 0 ) {
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
2024-06-27 12:10:38 +00:00
|
|
|
if ( \count( $media['image'] ) <= $max_images ) {
|
|
|
|
if ( \class_exists( '\WP_HTML_Tag_Processor' ) ) {
|
|
|
|
$media['image'] = \array_merge( $media['image'], $this->get_classic_editor_image_embeds( $max_images ) );
|
|
|
|
} else {
|
|
|
|
$media['image'] = \array_merge( $media['image'], $this->get_classic_editor_image_attachments( $max_images ) );
|
|
|
|
}
|
|
|
|
}
|
2023-12-08 23:23:11 +00:00
|
|
|
|
2024-06-27 12:10:38 +00:00
|
|
|
return $media;
|
|
|
|
}
|
2023-12-08 23:23:11 +00:00
|
|
|
|
2024-06-27 12:10:38 +00:00
|
|
|
/**
|
|
|
|
* Get enclosures for a post.
|
|
|
|
*
|
|
|
|
* @param array $media The media array grouped by type.
|
|
|
|
*
|
|
|
|
* @return array The media array extended with enclosures.
|
|
|
|
*/
|
|
|
|
public function get_enclosures( $media ) {
|
|
|
|
$enclosures = get_enclosures( $this->wp_object->ID );
|
|
|
|
|
|
|
|
if ( ! $enclosures ) {
|
|
|
|
return $media;
|
2023-12-08 23:23:11 +00:00
|
|
|
}
|
|
|
|
|
2024-06-27 12:10:38 +00:00
|
|
|
foreach ( $enclosures as $enclosure ) {
|
|
|
|
// check if URL is an attachment
|
|
|
|
$attachment_id = \attachment_url_to_postid( $enclosure['url'] );
|
|
|
|
if ( $attachment_id ) {
|
|
|
|
$enclosure['id'] = $attachment_id;
|
|
|
|
$enclosure['url'] = \wp_get_attachment_url( $attachment_id );
|
|
|
|
$enclosure['mediaType'] = \get_post_mime_type( $attachment_id );
|
|
|
|
}
|
|
|
|
|
|
|
|
$mime_type = $enclosure['mediaType'];
|
|
|
|
$mime_type_parts = \explode( '/', $mime_type );
|
|
|
|
|
|
|
|
switch ( $mime_type_parts[0] ) {
|
|
|
|
case 'image':
|
|
|
|
$media['image'][] = $enclosure;
|
|
|
|
break;
|
|
|
|
case 'audio':
|
|
|
|
$media['audio'][] = $enclosure;
|
|
|
|
break;
|
|
|
|
case 'video':
|
|
|
|
$media['video'][] = $enclosure;
|
|
|
|
break;
|
2023-12-08 23:23:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-06-27 12:10:38 +00:00
|
|
|
return $media;
|
2023-12-08 23:23:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Recursively get media IDs from blocks.
|
|
|
|
* @param array $blocks The blocks to search for media IDs
|
2024-04-19 10:49:31 +00:00
|
|
|
* @param array $media The media IDs to append new IDs to
|
2023-12-08 23:23:11 +00:00
|
|
|
* @param int $max_media The maximum number of media to return.
|
|
|
|
*
|
2023-10-22 22:20:53 +00:00
|
|
|
* @return array The image IDs.
|
|
|
|
*/
|
2024-04-19 10:49:31 +00:00
|
|
|
protected static function get_media_from_blocks( $blocks, $media ) {
|
2023-10-22 22:20:53 +00:00
|
|
|
foreach ( $blocks as $block ) {
|
|
|
|
// recurse into inner blocks
|
|
|
|
if ( ! empty( $block['innerBlocks'] ) ) {
|
2024-04-19 10:49:31 +00:00
|
|
|
$media = self::get_media_from_blocks( $block['innerBlocks'], $media );
|
2023-10-22 22:20:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch ( $block['blockName'] ) {
|
|
|
|
case 'core/image':
|
|
|
|
case 'core/cover':
|
2024-04-19 10:49:31 +00:00
|
|
|
if ( ! empty( $block['attrs']['id'] ) ) {
|
|
|
|
$alt = '';
|
2024-05-09 15:26:55 +00:00
|
|
|
$check = preg_match( '/<img.*?alt\s*=\s*([\"\'])(.*?)\1.*>/i', $block['innerHTML'], $match );
|
2024-04-19 10:49:31 +00:00
|
|
|
|
|
|
|
if ( $check ) {
|
2024-05-09 15:26:55 +00:00
|
|
|
$alt = $match[2];
|
2024-04-19 10:49:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$media['image'][] = array(
|
|
|
|
'id' => $block['attrs']['id'],
|
|
|
|
'alt' => $alt,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
break;
|
2023-12-08 23:23:11 +00:00
|
|
|
case 'core/audio':
|
2024-04-19 10:49:31 +00:00
|
|
|
if ( ! empty( $block['attrs']['id'] ) ) {
|
|
|
|
$media['audio'][] = array( 'id' => $block['attrs']['id'] );
|
|
|
|
}
|
|
|
|
break;
|
2023-12-08 23:23:11 +00:00
|
|
|
case 'core/video':
|
|
|
|
case 'videopress/video':
|
2023-10-22 22:20:53 +00:00
|
|
|
if ( ! empty( $block['attrs']['id'] ) ) {
|
2024-04-19 10:49:31 +00:00
|
|
|
$media['video'][] = array( 'id' => $block['attrs']['id'] );
|
2023-10-22 22:20:53 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'jetpack/slideshow':
|
|
|
|
case 'jetpack/tiled-gallery':
|
|
|
|
if ( ! empty( $block['attrs']['ids'] ) ) {
|
2024-04-19 10:49:31 +00:00
|
|
|
$media['image'] = array_merge(
|
|
|
|
$media['image'],
|
|
|
|
array_map(
|
|
|
|
function ( $id ) {
|
|
|
|
return array( 'id' => $id );
|
|
|
|
},
|
|
|
|
$block['attrs']['ids']
|
|
|
|
)
|
|
|
|
);
|
2023-10-22 22:20:53 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'jetpack/image-compare':
|
|
|
|
if ( ! empty( $block['attrs']['beforeImageId'] ) ) {
|
2024-04-19 10:49:31 +00:00
|
|
|
$media['image'][] = array( 'id' => $block['attrs']['beforeImageId'] );
|
2023-10-22 22:20:53 +00:00
|
|
|
}
|
|
|
|
if ( ! empty( $block['attrs']['afterImageId'] ) ) {
|
2024-04-19 10:49:31 +00:00
|
|
|
$media['image'][] = array( 'id' => $block['attrs']['afterImageId'] );
|
2023-10-22 22:20:53 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2024-04-19 10:49:31 +00:00
|
|
|
}
|
2023-10-22 22:20:53 +00:00
|
|
|
|
2024-04-19 10:49:31 +00:00
|
|
|
return $media;
|
|
|
|
}
|
2023-12-08 23:23:11 +00:00
|
|
|
|
2024-04-19 10:49:31 +00:00
|
|
|
/**
|
|
|
|
* Filter media IDs by object type.
|
|
|
|
*
|
2024-06-27 12:10:38 +00:00
|
|
|
* @param array $media The media array grouped by type.
|
|
|
|
* @param string $type The object type.
|
2024-04-19 10:49:31 +00:00
|
|
|
*
|
|
|
|
* @return array The filtered media IDs.
|
|
|
|
*/
|
2024-06-27 12:10:38 +00:00
|
|
|
protected static function filter_media_by_object_type( $media, $type, $wp_object ) {
|
|
|
|
$type = \apply_filters( 'filter_media_by_object_type', \strtolower( $type ), $wp_object );
|
2024-04-19 10:49:31 +00:00
|
|
|
|
|
|
|
if ( ! empty( $media[ $type ] ) ) {
|
|
|
|
return $media[ $type ];
|
2023-10-22 22:20:53 +00:00
|
|
|
}
|
|
|
|
|
2024-06-27 12:10:38 +00:00
|
|
|
return array_filter( array_merge( array(), ...array_values( $media ) ) );
|
2023-10-22 22:20:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2023-12-08 23:23:11 +00:00
|
|
|
* Converts a WordPress Attachment to an ActivityPub Attachment.
|
2023-10-22 22:20:53 +00:00
|
|
|
*
|
2024-04-19 10:49:31 +00:00
|
|
|
* @param array $media The Attachment array.
|
2023-12-08 23:23:11 +00:00
|
|
|
*
|
|
|
|
* @return array The ActivityPub Attachment.
|
2023-10-22 22:20:53 +00:00
|
|
|
*/
|
2024-04-19 10:49:31 +00:00
|
|
|
public static function wp_attachment_to_activity_attachment( $media ) {
|
2024-06-27 12:10:38 +00:00
|
|
|
if ( ! isset( $media['id'] ) ) {
|
|
|
|
return $media;
|
|
|
|
}
|
|
|
|
|
2024-04-19 10:49:31 +00:00
|
|
|
$id = $media['id'];
|
|
|
|
$attachment = array();
|
|
|
|
$mime_type = \get_post_mime_type( $id );
|
2023-12-08 23:23:11 +00:00
|
|
|
$mime_type_parts = \explode( '/', $mime_type );
|
|
|
|
// switching on image/audio/video
|
|
|
|
switch ( $mime_type_parts[0] ) {
|
|
|
|
case 'image':
|
2024-06-27 12:10:38 +00:00
|
|
|
$image_size = 'large';
|
2023-12-08 23:23:11 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Filter the image URL returned for each post.
|
|
|
|
*
|
2024-05-09 15:26:55 +00:00
|
|
|
* @param array|false $thumbnail The image URL, or false if no image is available.
|
|
|
|
* @param int $id The attachment ID.
|
2024-06-27 12:10:38 +00:00
|
|
|
* @param string $image_size The image size to retrieve. Set to 'large' by default.
|
2023-12-08 23:23:11 +00:00
|
|
|
*/
|
|
|
|
$thumbnail = apply_filters(
|
|
|
|
'activitypub_get_image',
|
2024-02-08 12:31:25 +00:00
|
|
|
self::get_wordpress_attachment( $id, $image_size ),
|
2023-12-08 23:23:11 +00:00
|
|
|
$id,
|
|
|
|
$image_size
|
|
|
|
);
|
2023-10-22 22:20:53 +00:00
|
|
|
|
2023-12-08 23:23:11 +00:00
|
|
|
if ( $thumbnail ) {
|
|
|
|
$image = array(
|
|
|
|
'type' => 'Image',
|
2024-04-19 10:49:31 +00:00
|
|
|
'url' => \esc_url( $thumbnail[0] ),
|
|
|
|
'mediaType' => \esc_attr( $mime_type ),
|
2023-12-08 23:23:11 +00:00
|
|
|
);
|
2023-10-22 22:20:53 +00:00
|
|
|
|
2024-04-19 10:49:31 +00:00
|
|
|
if ( ! empty( $media['alt'] ) ) {
|
2024-05-09 15:26:55 +00:00
|
|
|
$image['name'] = \wp_strip_all_tags( \html_entity_decode( $media['alt'] ) );
|
2024-04-19 10:49:31 +00:00
|
|
|
} else {
|
|
|
|
$alt = \get_post_meta( $id, '_wp_attachment_image_alt', true );
|
|
|
|
if ( $alt ) {
|
2024-05-09 15:26:55 +00:00
|
|
|
$image['name'] = \wp_strip_all_tags( \html_entity_decode( $alt ) );
|
2024-04-19 10:49:31 +00:00
|
|
|
}
|
2023-10-22 22:20:53 +00:00
|
|
|
}
|
2024-04-19 10:49:31 +00:00
|
|
|
|
2023-12-08 23:23:11 +00:00
|
|
|
$attachment = $image;
|
2023-10-22 22:20:53 +00:00
|
|
|
}
|
2023-12-08 23:23:11 +00:00
|
|
|
break;
|
2023-10-22 22:20:53 +00:00
|
|
|
|
2023-12-08 23:23:11 +00:00
|
|
|
case 'audio':
|
|
|
|
case 'video':
|
|
|
|
$attachment = array(
|
|
|
|
'type' => 'Document',
|
2024-04-19 10:49:31 +00:00
|
|
|
'mediaType' => \esc_attr( $mime_type ),
|
|
|
|
'url' => \esc_url( \wp_get_attachment_url( $id ) ),
|
|
|
|
'name' => \esc_attr( \get_the_title( $id ) ),
|
2023-10-22 22:20:53 +00:00
|
|
|
);
|
2023-12-08 23:23:11 +00:00
|
|
|
$meta = wp_get_attachment_metadata( $id );
|
|
|
|
// height and width for videos
|
|
|
|
if ( isset( $meta['width'] ) && isset( $meta['height'] ) ) {
|
2024-04-19 10:49:31 +00:00
|
|
|
$attachment['width'] = \esc_attr( $meta['width'] );
|
|
|
|
$attachment['height'] = \esc_attr( $meta['height'] );
|
2023-10-22 22:20:53 +00:00
|
|
|
}
|
2023-12-08 23:23:11 +00:00
|
|
|
// @todo: add `icon` support for audio/video attachments. Maybe use post thumbnail?
|
|
|
|
break;
|
2023-10-22 22:20:53 +00:00
|
|
|
}
|
|
|
|
|
2023-12-08 23:23:11 +00:00
|
|
|
return \apply_filters( 'activitypub_attachment', $attachment, $id );
|
2023-10-22 22:20:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return details about an image attachment.
|
|
|
|
*
|
|
|
|
* @param int $id The attachment ID.
|
2024-06-27 12:10:38 +00:00
|
|
|
* @param string $image_size The image size to retrieve. Set to 'large' by default.
|
2023-10-22 22:20:53 +00:00
|
|
|
*
|
|
|
|
* @return array|false Array of image data, or boolean false if no image is available.
|
|
|
|
*/
|
2024-06-27 12:10:38 +00:00
|
|
|
protected static function get_wordpress_attachment( $id, $image_size = 'large' ) {
|
2023-10-22 22:20:53 +00:00
|
|
|
/**
|
|
|
|
* Hook into the image retrieval process. Before image retrieval.
|
|
|
|
*
|
|
|
|
* @param int $id The attachment ID.
|
2024-06-27 12:10:38 +00:00
|
|
|
* @param string $image_size The image size to retrieve. Set to 'large' by default.
|
2023-10-22 22:20:53 +00:00
|
|
|
*/
|
|
|
|
do_action( 'activitypub_get_image_pre', $id, $image_size );
|
|
|
|
|
2023-12-08 23:23:11 +00:00
|
|
|
$image = \wp_get_attachment_image_src( $id, $image_size );
|
2023-10-22 22:20:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Hook into the image retrieval process. After image retrieval.
|
|
|
|
*
|
|
|
|
* @param int $id The attachment ID.
|
2024-06-27 12:10:38 +00:00
|
|
|
* @param string $image_size The image size to retrieve. Set to 'large' by default.
|
2023-10-22 22:20:53 +00:00
|
|
|
*/
|
|
|
|
do_action( 'activitypub_get_image_post', $id, $image_size );
|
|
|
|
|
2023-12-08 23:23:11 +00:00
|
|
|
return $image;
|
2023-10-22 22:20:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the ActivityStreams 2.0 Object-Type for a Post based on the
|
|
|
|
* settings and the Post-Type.
|
|
|
|
*
|
|
|
|
* @see https://www.w3.org/TR/activitystreams-vocabulary/#activity-types
|
|
|
|
*
|
|
|
|
* @return string The Object-Type.
|
|
|
|
*/
|
2024-02-08 12:31:25 +00:00
|
|
|
protected function get_type() {
|
2024-04-19 10:49:31 +00:00
|
|
|
$post_format_setting = \get_option( 'activitypub_object_type', ACTIVITYPUB_DEFAULT_OBJECT_TYPE );
|
|
|
|
|
|
|
|
if ( 'wordpress-post-format' !== $post_format_setting ) {
|
|
|
|
return \ucfirst( $post_format_setting );
|
|
|
|
}
|
|
|
|
|
|
|
|
$has_title = post_type_supports( $this->wp_object->post_type, 'title' );
|
|
|
|
|
|
|
|
if ( ! $has_title ) {
|
|
|
|
return 'Note';
|
2023-10-22 22:20:53 +00:00
|
|
|
}
|
|
|
|
|
2023-12-08 23:23:11 +00:00
|
|
|
// Default to Article.
|
2024-06-27 12:10:38 +00:00
|
|
|
$object_type = 'Note';
|
2024-04-19 10:49:31 +00:00
|
|
|
$post_format = 'standard';
|
|
|
|
|
|
|
|
if ( \get_theme_support( 'post-formats' ) ) {
|
|
|
|
$post_format = \get_post_format( $this->wp_object );
|
|
|
|
}
|
|
|
|
|
2024-02-08 12:31:25 +00:00
|
|
|
$post_type = \get_post_type( $this->wp_object );
|
2023-10-22 22:20:53 +00:00
|
|
|
switch ( $post_type ) {
|
|
|
|
case 'post':
|
|
|
|
switch ( $post_format ) {
|
2024-06-27 12:10:38 +00:00
|
|
|
case 'standard':
|
|
|
|
case '':
|
|
|
|
$object_type = 'Article';
|
2023-10-22 22:20:53 +00:00
|
|
|
break;
|
|
|
|
default:
|
2024-06-27 12:10:38 +00:00
|
|
|
$object_type = 'Note';
|
2023-10-22 22:20:53 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'page':
|
|
|
|
$object_type = 'Page';
|
|
|
|
break;
|
|
|
|
default:
|
2024-06-27 12:10:38 +00:00
|
|
|
$object_type = 'Note';
|
2023-10-22 22:20:53 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $object_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a list of Mentions, used in the Post.
|
|
|
|
*
|
|
|
|
* @see https://docs.joinmastodon.org/spec/activitypub/#Mention
|
|
|
|
*
|
|
|
|
* @return array The list of Mentions.
|
|
|
|
*/
|
|
|
|
protected function get_cc() {
|
|
|
|
$cc = array();
|
|
|
|
|
|
|
|
$mentions = $this->get_mentions();
|
|
|
|
if ( $mentions ) {
|
|
|
|
foreach ( $mentions as $url ) {
|
|
|
|
$cc[] = $url;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $cc;
|
|
|
|
}
|
|
|
|
|
2024-06-27 12:10:38 +00:00
|
|
|
|
|
|
|
public function get_audience() {
|
|
|
|
if ( is_single_user() ) {
|
|
|
|
return null;
|
|
|
|
} else {
|
|
|
|
$blog = new Blog();
|
|
|
|
return $blog->get_id();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-22 22:20:53 +00:00
|
|
|
/**
|
|
|
|
* Returns a list of Tags, used in the Post.
|
|
|
|
*
|
|
|
|
* This includes Hash-Tags and Mentions.
|
|
|
|
*
|
|
|
|
* @return array The list of Tags.
|
|
|
|
*/
|
2024-02-08 12:31:25 +00:00
|
|
|
protected function get_tag() {
|
2023-10-22 22:20:53 +00:00
|
|
|
$tags = array();
|
|
|
|
|
2024-02-08 12:31:25 +00:00
|
|
|
$post_tags = \get_the_tags( $this->wp_object->ID );
|
2023-10-22 22:20:53 +00:00
|
|
|
if ( $post_tags ) {
|
|
|
|
foreach ( $post_tags as $post_tag ) {
|
|
|
|
$tag = array(
|
|
|
|
'type' => 'Hashtag',
|
|
|
|
'href' => \esc_url( \get_tag_link( $post_tag->term_id ) ),
|
|
|
|
'name' => esc_hashtag( $post_tag->name ),
|
|
|
|
);
|
|
|
|
$tags[] = $tag;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$mentions = $this->get_mentions();
|
|
|
|
if ( $mentions ) {
|
|
|
|
foreach ( $mentions as $mention => $url ) {
|
|
|
|
$tag = array(
|
|
|
|
'type' => 'Mention',
|
|
|
|
'href' => \esc_url( $url ),
|
|
|
|
'name' => \esc_html( $mention ),
|
|
|
|
);
|
|
|
|
$tags[] = $tag;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $tags;
|
|
|
|
}
|
|
|
|
|
2024-04-19 10:49:31 +00:00
|
|
|
/**
|
|
|
|
* Returns the summary for the ActivityPub Item.
|
|
|
|
*
|
|
|
|
* The summary will be generated based on the user settings and only if the
|
|
|
|
* object type is not set to `note`.
|
|
|
|
*
|
|
|
|
* @return string|null The summary or null if the object type is `note`.
|
|
|
|
*/
|
|
|
|
protected function get_summary() {
|
|
|
|
if ( 'Note' === $this->get_type() ) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2024-07-19 19:46:05 +00:00
|
|
|
// Remove Teaser from drafts.
|
|
|
|
if ( 'draft' === \get_post_status( $this->wp_object ) ) {
|
|
|
|
return \__( '(This post is being modified)', 'activitypub' );
|
|
|
|
}
|
|
|
|
|
2024-04-19 10:49:31 +00:00
|
|
|
$content = \get_post_field( 'post_content', $this->wp_object->ID );
|
|
|
|
$content = \html_entity_decode( $content );
|
|
|
|
$content = \wp_strip_all_tags( $content );
|
|
|
|
$content = \trim( $content );
|
|
|
|
$content = \preg_replace( '/\R+/m', "\n\n", $content );
|
|
|
|
$content = \preg_replace( '/[\r\t]/', '', $content );
|
|
|
|
|
|
|
|
$excerpt_more = \apply_filters( 'activitypub_excerpt_more', '[...]' );
|
|
|
|
$length = 500;
|
|
|
|
$length = $length - strlen( $excerpt_more );
|
|
|
|
|
|
|
|
if ( \strlen( $content ) > $length ) {
|
|
|
|
$content = \wordwrap( $content, $length, '</activitypub-summary>' );
|
|
|
|
$content = \explode( '</activitypub-summary>', $content, 2 );
|
|
|
|
$content = $content[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
return $content . ' ' . $excerpt_more;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the title for the ActivityPub Item.
|
|
|
|
*
|
|
|
|
* The title will be generated based on the user settings and only if the
|
|
|
|
* object type is not set to `note`.
|
|
|
|
*
|
|
|
|
* @return string|null The title or null if the object type is `note`.
|
|
|
|
*/
|
|
|
|
protected function get_name() {
|
|
|
|
if ( 'Note' === $this->get_type() ) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
$title = \get_the_title( $this->wp_object->ID );
|
|
|
|
|
|
|
|
if ( $title ) {
|
|
|
|
return \wp_strip_all_tags(
|
|
|
|
\html_entity_decode(
|
|
|
|
$title
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2023-10-22 22:20:53 +00:00
|
|
|
/**
|
|
|
|
* Returns the content for the ActivityPub Item.
|
|
|
|
*
|
|
|
|
* The content will be generated based on the user settings.
|
|
|
|
*
|
|
|
|
* @return string The content.
|
|
|
|
*/
|
|
|
|
protected function get_content() {
|
2024-07-19 19:46:05 +00:00
|
|
|
// Remove Content from drafts.
|
|
|
|
if ( 'draft' === \get_post_status( $this->wp_object ) ) {
|
|
|
|
return \__( '(This post is being modified)', 'activitypub' );
|
|
|
|
}
|
|
|
|
|
2023-10-22 22:20:53 +00:00
|
|
|
global $post;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Provides an action hook so plugins can add their own hooks/filters before AP content is generated.
|
|
|
|
*
|
|
|
|
* Example: if a plugin adds a filter to `the_content` to add a button to the end of posts, it can also remove that filter here.
|
|
|
|
*
|
|
|
|
* @param WP_Post $post The post object.
|
|
|
|
*/
|
|
|
|
do_action( 'activitypub_before_get_content', $post );
|
|
|
|
|
2024-06-27 12:10:38 +00:00
|
|
|
add_filter( 'render_block_core/embed', array( self::class, 'revert_embed_links' ), 10, 2 );
|
|
|
|
|
2023-10-22 22:20:53 +00:00
|
|
|
// phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
|
2024-02-08 12:31:25 +00:00
|
|
|
$post = $this->wp_object;
|
2023-10-22 22:20:53 +00:00
|
|
|
$content = $this->get_post_content_template();
|
|
|
|
|
2023-12-08 23:23:11 +00:00
|
|
|
// Register our shortcodes just in time.
|
|
|
|
Shortcodes::register();
|
2023-10-22 22:20:53 +00:00
|
|
|
// Fill in the shortcodes.
|
|
|
|
setup_postdata( $post );
|
|
|
|
$content = do_shortcode( $content );
|
|
|
|
wp_reset_postdata();
|
|
|
|
|
|
|
|
$content = \wpautop( $content );
|
|
|
|
$content = \preg_replace( '/[\n\r\t]/', '', $content );
|
|
|
|
$content = \trim( $content );
|
|
|
|
|
|
|
|
$content = \apply_filters( 'activitypub_the_content', $content, $post );
|
|
|
|
|
2023-12-08 23:23:11 +00:00
|
|
|
// Don't need these any more, should never appear in a post.
|
|
|
|
Shortcodes::unregister();
|
|
|
|
|
2023-10-22 22:20:53 +00:00
|
|
|
return $content;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the template to use to generate the content of the activitypub item.
|
|
|
|
*
|
|
|
|
* @return string The Template.
|
|
|
|
*/
|
|
|
|
protected function get_post_content_template() {
|
2024-02-08 12:31:25 +00:00
|
|
|
$type = \get_option( 'activitypub_post_content_type', 'content' );
|
2023-10-22 22:20:53 +00:00
|
|
|
|
2024-02-08 12:31:25 +00:00
|
|
|
switch ( $type ) {
|
|
|
|
case 'excerpt':
|
|
|
|
$template = "[ap_excerpt]\n\n[ap_permalink type=\"html\"]";
|
|
|
|
break;
|
|
|
|
case 'title':
|
2024-04-19 10:49:31 +00:00
|
|
|
$template = "<h2>[ap_title]</h2>\n\n[ap_permalink type=\"html\"]";
|
2024-02-08 12:31:25 +00:00
|
|
|
break;
|
|
|
|
case 'content':
|
|
|
|
$template = "[ap_content]\n\n[ap_permalink type=\"html\"]\n\n[ap_hashtags]";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
$template = \get_option( 'activitypub_custom_post_content', ACTIVITYPUB_CUSTOM_POST_CONTENT );
|
|
|
|
break;
|
2023-10-22 22:20:53 +00:00
|
|
|
}
|
|
|
|
|
2024-04-19 10:49:31 +00:00
|
|
|
$post_format_setting = \get_option( 'activitypub_object_type', ACTIVITYPUB_DEFAULT_OBJECT_TYPE );
|
|
|
|
|
|
|
|
if ( 'wordpress-post-format' === $post_format_setting ) {
|
|
|
|
$template = '[ap_content]';
|
|
|
|
}
|
|
|
|
|
2024-02-08 12:31:25 +00:00
|
|
|
return apply_filters( 'activitypub_object_content_template', $template, $this->wp_object );
|
2023-10-22 22:20:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper function to get the @-Mentions from the post content.
|
|
|
|
*
|
|
|
|
* @return array The list of @-Mentions.
|
|
|
|
*/
|
|
|
|
protected function get_mentions() {
|
2024-02-08 12:31:25 +00:00
|
|
|
return apply_filters( 'activitypub_extract_mentions', array(), $this->wp_object->post_content, $this->wp_object );
|
2023-10-22 22:20:53 +00:00
|
|
|
}
|
2023-12-08 23:23:11 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the locale of the post.
|
|
|
|
*
|
|
|
|
* @return string The locale of the post.
|
|
|
|
*/
|
|
|
|
public function get_locale() {
|
2024-02-08 12:31:25 +00:00
|
|
|
$post_id = $this->wp_object->ID;
|
2023-12-08 23:23:11 +00:00
|
|
|
$lang = \strtolower( \strtok( \get_locale(), '_-' ) );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Filter the locale of the post.
|
|
|
|
*
|
|
|
|
* @param string $lang The locale of the post.
|
|
|
|
* @param int $post_id The post ID.
|
|
|
|
* @param WP_Post $post The post object.
|
|
|
|
*
|
|
|
|
* @return string The filtered locale of the post.
|
|
|
|
*/
|
2024-02-08 12:31:25 +00:00
|
|
|
return apply_filters( 'activitypub_post_locale', $lang, $post_id, $this->wp_object );
|
2023-12-08 23:23:11 +00:00
|
|
|
}
|
2024-06-27 12:10:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Transform Embed blocks to block level link.
|
|
|
|
*
|
|
|
|
* Remote servers will simply drop iframe elements, rendering incomplete content.
|
|
|
|
*
|
|
|
|
* @see https://www.w3.org/TR/activitypub/#security-sanitizing-content
|
|
|
|
* @see https://www.w3.org/wiki/ActivityPub/Primer/HTML
|
|
|
|
*
|
|
|
|
* @param string $block_content The block content (html)
|
|
|
|
* @param object $block The block object
|
|
|
|
*
|
|
|
|
* @return string A block level link
|
|
|
|
*/
|
|
|
|
public static function revert_embed_links( $block_content, $block ) {
|
|
|
|
return '<p><a href="' . esc_url( $block['attrs']['url'] ) . '">' . $block['attrs']['url'] . '</a></p>';
|
|
|
|
}
|
2023-10-22 22:20:53 +00:00
|
|
|
}
|