updated plugin ActivityPub
version 5.8.0
This commit is contained in:
40
wp-content/plugins/activitypub/integration/class-akismet.php
Normal file
40
wp-content/plugins/activitypub/integration/class-akismet.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
/**
|
||||
* Akismet integration.
|
||||
*
|
||||
* @package Activitypub
|
||||
*/
|
||||
|
||||
namespace Activitypub\Integration;
|
||||
|
||||
use function Activitypub\was_comment_received;
|
||||
|
||||
/**
|
||||
* Compatibility with the Akismet plugin.
|
||||
*
|
||||
* @see https://wordpress.org/plugins/akismet/
|
||||
*/
|
||||
class Akismet {
|
||||
/**
|
||||
* Initialize the class, registering WordPress hooks.
|
||||
*/
|
||||
public static function init() {
|
||||
\add_filter( 'comment_row_actions', array( self::class, 'comment_row_actions' ), 10, 2 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the "history" action from the comment row actions.
|
||||
*
|
||||
* @param array $actions The existing actions.
|
||||
* @param int|\WP_Comment $comment The comment object or ID.
|
||||
*
|
||||
* @return array The modified actions.
|
||||
*/
|
||||
public static function comment_row_actions( $actions, $comment ) {
|
||||
if ( was_comment_received( $comment ) ) {
|
||||
unset( $actions['history'] );
|
||||
}
|
||||
|
||||
return $actions;
|
||||
}
|
||||
}
|
@ -10,10 +10,11 @@ namespace Activitypub\Integration;
|
||||
use DateTime;
|
||||
use Activitypub\Webfinger as Webfinger_Util;
|
||||
use Activitypub\Http;
|
||||
use Activitypub\Collection\Users;
|
||||
use Activitypub\Mention;
|
||||
use Activitypub\Collection\Actors;
|
||||
use Activitypub\Collection\Followers;
|
||||
use Activitypub\Collection\Extra_Fields;
|
||||
use Enable_Mastodon_Apps\Mastodon_API;
|
||||
use Activitypub\Transformer\Factory;
|
||||
use Enable_Mastodon_Apps\Entity\Account;
|
||||
use Enable_Mastodon_Apps\Entity\Status;
|
||||
use Enable_Mastodon_Apps\Entity\Media_Attachment;
|
||||
@ -36,12 +37,14 @@ class Enable_Mastodon_Apps {
|
||||
\add_filter( 'mastodon_api_account_followers', array( self::class, 'api_account_followers' ), 10, 2 );
|
||||
\add_filter( 'mastodon_api_account', array( self::class, 'api_account_external' ), 15, 2 );
|
||||
\add_filter( 'mastodon_api_account', array( self::class, 'api_account_internal' ), 9, 2 );
|
||||
\add_filter( 'mastodon_api_status', array( self::class, 'api_status' ), 9, 2 );
|
||||
\add_filter( 'mastodon_api_search', array( self::class, 'api_search' ), 40, 2 );
|
||||
\add_filter( 'mastodon_api_search', array( self::class, 'api_search_by_url' ), 40, 2 );
|
||||
\add_filter( 'mastodon_api_get_posts_query_args', array( self::class, 'api_get_posts_query_args' ) );
|
||||
\add_filter( 'mastodon_api_statuses', array( self::class, 'api_statuses_external' ), 10, 2 );
|
||||
\add_filter( 'mastodon_api_status_context', array( self::class, 'api_get_replies' ), 10, 23 );
|
||||
\add_action( 'mastodon_api_update_credentials', array( self::class, 'api_update_credentials' ), 10, 2 );
|
||||
\add_filter( 'mastodon_api_status_context', array( self::class, 'api_get_replies' ), 10, 3 );
|
||||
\add_filter( 'mastodon_api_update_credentials', array( self::class, 'api_update_credentials' ), 10, 2 );
|
||||
\add_filter( 'mastodon_api_submit_status_text', array( Mention::class, 'the_content' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -58,7 +61,7 @@ class Enable_Mastodon_Apps {
|
||||
// Check if the blog user is permissible for this user.
|
||||
user_can( $user_id, 'activitypub' )
|
||||
) {
|
||||
return Users::BLOG_USER_ID;
|
||||
return Actors::BLOG_USER_ID;
|
||||
}
|
||||
|
||||
return $user_id;
|
||||
@ -77,7 +80,7 @@ class Enable_Mastodon_Apps {
|
||||
}
|
||||
|
||||
$user_id = self::maybe_map_user_to_blog( $user_id );
|
||||
$user = Users::get_by_id( $user_id );
|
||||
$user = Actors::get_by_id( $user_id );
|
||||
if ( ! $user || is_wp_error( $user ) ) {
|
||||
return $data;
|
||||
}
|
||||
@ -139,7 +142,7 @@ class Enable_Mastodon_Apps {
|
||||
// The Mastodon API submits a simple hash for every field.
|
||||
// We can reasonably assume a similar order for our operations below.
|
||||
$ids = wp_list_pluck( Extra_Fields::get_actor_fields( $user_id ), 'ID' );
|
||||
$is_blog = Users::BLOG_USER_ID === $user_id;
|
||||
$is_blog = Actors::BLOG_USER_ID === $user_id;
|
||||
$post_type = $is_blog ? Extra_Fields::BLOG_POST_TYPE : Extra_Fields::USER_POST_TYPE;
|
||||
|
||||
foreach ( $fields as $i => $field ) {
|
||||
@ -190,7 +193,7 @@ class Enable_Mastodon_Apps {
|
||||
if ( $acct && ! is_wp_error( $acct ) ) {
|
||||
$acct = \str_replace( 'acct:', '', $acct );
|
||||
} else {
|
||||
$acct = $item->get_url();
|
||||
$acct = $item->get_id();
|
||||
}
|
||||
|
||||
$account = new Account();
|
||||
@ -239,7 +242,7 @@ class Enable_Mastodon_Apps {
|
||||
return $user_data;
|
||||
}
|
||||
|
||||
$user = Users::get_by_various( $user_id );
|
||||
$user = Actors::get_by_various( $user_id );
|
||||
|
||||
if ( $user && ! is_wp_error( $user ) ) {
|
||||
return $user_data;
|
||||
@ -269,7 +272,7 @@ class Enable_Mastodon_Apps {
|
||||
*/
|
||||
public static function api_account_internal( $user_data, $user_id ) {
|
||||
$user_id_to_use = self::maybe_map_user_to_blog( $user_id );
|
||||
$user = Users::get_by_id( $user_id_to_use );
|
||||
$user = Actors::get_by_id( $user_id_to_use );
|
||||
|
||||
if ( ! $user || is_wp_error( $user ) ) {
|
||||
return $user_data;
|
||||
@ -324,6 +327,44 @@ class Enable_Mastodon_Apps {
|
||||
return $account;
|
||||
}
|
||||
|
||||
/**
|
||||
* Use our representation of posts to power each status item.
|
||||
* Includes proper referncing of 3rd party comments that arrived via federation.
|
||||
*
|
||||
* @param null|Status $status The status, typically null to allow later filters their shot.
|
||||
* @param int $post_id The post ID.
|
||||
* @return Status|null The status.
|
||||
*/
|
||||
public static function api_status( $status, $post_id ) {
|
||||
$post = \get_post( $post_id );
|
||||
if ( ! $post ) {
|
||||
return $status;
|
||||
}
|
||||
|
||||
return self::api_post_status( $post_id );
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms a WordPress post into a Mastodon-compatible status object.
|
||||
*
|
||||
* Takes a post ID, transforms it into an ActivityPub object, and converts
|
||||
* it to a Mastodon API status format including the author's account info.
|
||||
*
|
||||
* @param int $post_id The WordPress post ID to transform.
|
||||
* @return Status|null The Mastodon API status object, or null if the post is not found
|
||||
*/
|
||||
private static function api_post_status( $post_id ) {
|
||||
$post = Factory::get_transformer( get_post( $post_id ) );
|
||||
if ( is_wp_error( $post ) ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$data = $post->to_object()->to_array();
|
||||
$account = self::api_account_internal( null, get_post_field( 'post_author', $post_id ) );
|
||||
|
||||
return self::activity_to_status( $data, $account, $post_id );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get account for actor.
|
||||
*
|
||||
@ -332,7 +373,7 @@ class Enable_Mastodon_Apps {
|
||||
* @return Account|null The account.
|
||||
*/
|
||||
private static function get_account_for_actor( $uri ) {
|
||||
if ( ! is_string( $uri ) ) {
|
||||
if ( ! is_string( $uri ) || empty( $uri ) ) {
|
||||
return null;
|
||||
}
|
||||
$data = get_remote_metadata_by_actor( $uri );
|
||||
@ -343,6 +384,10 @@ class Enable_Mastodon_Apps {
|
||||
$account = new Account();
|
||||
|
||||
$acct = Webfinger_Util::uri_to_acct( $uri );
|
||||
if ( ! $acct || is_wp_error( $acct ) ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ( str_starts_with( $acct, 'acct:' ) ) {
|
||||
$acct = substr( $acct, 5 );
|
||||
}
|
||||
@ -489,22 +534,23 @@ class Enable_Mastodon_Apps {
|
||||
*
|
||||
* @param array $item The activity.
|
||||
* @param Account $account The account.
|
||||
* @param int $post_id The post ID. Optional, but will be preferred in the Status.
|
||||
*
|
||||
* @return Status|null The status.
|
||||
*/
|
||||
private static function activity_to_status( $item, $account ) {
|
||||
private static function activity_to_status( $item, $account, $post_id = null ) {
|
||||
if ( isset( $item['object'] ) ) {
|
||||
$object = $item['object'];
|
||||
} else {
|
||||
$object = $item;
|
||||
}
|
||||
|
||||
if ( ! isset( $object['type'] ) || 'Note' !== $object['type'] ) {
|
||||
if ( ! isset( $object['type'] ) || 'Note' !== $object['type'] || ! $account ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$status = new Status();
|
||||
$status->id = $object['id'];
|
||||
$status->id = $post_id ?? $object['id'];
|
||||
$status->created_at = new DateTime( $object['published'] );
|
||||
$status->content = $object['content'];
|
||||
$status->account = $account;
|
||||
@ -624,7 +670,7 @@ class Enable_Mastodon_Apps {
|
||||
$posts['orderedItems']
|
||||
);
|
||||
$activitypub_statuses = array_merge( $activitypub_statuses, array_filter( $new_statuses ) );
|
||||
$url = $posts['next'];
|
||||
$url = $posts['next'] ?? null;
|
||||
|
||||
if ( count( $activitypub_statuses ) >= $limit ) {
|
||||
break;
|
||||
@ -649,20 +695,37 @@ class Enable_Mastodon_Apps {
|
||||
return $context;
|
||||
}
|
||||
|
||||
$replies_url = $meta['replies']['first']['next'];
|
||||
$replies = Http::get_remote_object( $replies_url, true );
|
||||
if ( is_wp_error( $replies ) || ! isset( $replies['items'] ) ) {
|
||||
if ( ! empty( $meta['replies']['first']['items'] ) ) {
|
||||
$replies = $meta['replies']['first'];
|
||||
} elseif ( isset( $meta['replies']['first']['next'] ) ) {
|
||||
$replies_url = $meta['replies']['first']['next'];
|
||||
$replies = Http::get_remote_object( $replies_url, true );
|
||||
if ( is_wp_error( $replies ) || ! isset( $replies['items'] ) ) {
|
||||
return $context;
|
||||
}
|
||||
} else {
|
||||
return $context;
|
||||
}
|
||||
|
||||
foreach ( $replies['items'] as $url ) {
|
||||
$response = Http::get( $url, true );
|
||||
if ( is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) !== 200 ) {
|
||||
continue;
|
||||
}
|
||||
$status = json_decode( wp_remote_retrieve_body( $response ), true );
|
||||
if ( ! $status || is_wp_error( $status ) ) {
|
||||
continue;
|
||||
foreach ( $replies['items'] as $reply ) {
|
||||
if ( isset( $reply['id'] ) && is_string( $reply['id'] ) && isset( $reply['content'] ) && is_string( $reply['content'] ) ) {
|
||||
$status = $reply;
|
||||
} else {
|
||||
if ( is_string( $reply ) ) {
|
||||
$url = $reply;
|
||||
} elseif ( isset( $reply['url'] ) && is_string( $reply['url'] ) ) {
|
||||
$url = $reply['url'];
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
$response = Http::get( $url, true );
|
||||
if ( is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) !== 200 ) {
|
||||
continue;
|
||||
}
|
||||
$status = json_decode( wp_remote_retrieve_body( $response ), true );
|
||||
if ( ! $status || is_wp_error( $status ) ) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
$account = self::get_account_for_actor( $status['attributedTo'] );
|
||||
|
@ -7,6 +7,8 @@
|
||||
|
||||
namespace Activitypub\Integration;
|
||||
|
||||
use Activitypub\Comment;
|
||||
|
||||
/**
|
||||
* Jetpack integration class.
|
||||
*/
|
||||
@ -17,6 +19,8 @@ class Jetpack {
|
||||
*/
|
||||
public static function init() {
|
||||
\add_filter( 'jetpack_sync_post_meta_whitelist', array( self::class, 'add_sync_meta' ) );
|
||||
\add_filter( 'jetpack_json_api_comment_types', array( self::class, 'add_comment_types' ) );
|
||||
\add_filter( 'jetpack_api_include_comment_types_count', array( self::class, 'add_comment_types' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -31,10 +35,20 @@ class Jetpack {
|
||||
return $allow_list;
|
||||
}
|
||||
$activitypub_meta_keys = array(
|
||||
'activitypub_user_id',
|
||||
'activitypub_inbox',
|
||||
'activitypub_actor_json',
|
||||
'_activitypub_user_id',
|
||||
'_activitypub_inbox',
|
||||
'_activitypub_actor_json',
|
||||
);
|
||||
return \array_merge( $allow_list, $activitypub_meta_keys );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add custom comment types to the list of comment types.
|
||||
*
|
||||
* @param array $comment_types Default comment types.
|
||||
* @return array
|
||||
*/
|
||||
public static function add_comment_types( $comment_types ) {
|
||||
return array_unique( \array_merge( $comment_types, Comment::get_comment_type_slugs() ) );
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
/**
|
||||
* Multisite Language Switcher integration class file.
|
||||
*
|
||||
* @package Activitypub
|
||||
*/
|
||||
|
||||
namespace Activitypub\Integration;
|
||||
|
||||
use Activitypub\Collection\Outbox;
|
||||
|
||||
/**
|
||||
* Compatibility with the Multisite Language Switcher plugin.
|
||||
*
|
||||
* @see https://github.com/lloc/Multisite-Language-Switcher/
|
||||
*/
|
||||
class Multisite_Language_Switcher {
|
||||
/**
|
||||
* Initialize the class, registering WordPress hooks.
|
||||
*/
|
||||
public static function init() {
|
||||
\add_action( 'save_post', array( self::class, 'ignore_outbox_post' ), 9, 2 );
|
||||
\add_action( 'save_post', array( self::class, 'unignore_outbox_post' ), 11, 2 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Short-circuit saving Multisite Language Switcher data for the Outbox post type.
|
||||
*
|
||||
* @param int $post_id The post id.
|
||||
* @param WP_Post $post The post object.
|
||||
*/
|
||||
public static function ignore_outbox_post( $post_id, $post ) {
|
||||
if ( Outbox::POST_TYPE === $post->post_type ) {
|
||||
\add_action( 'msls_main_save', '__return_null' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove short-circuit for Multisite Language Switcher data.
|
||||
*
|
||||
* @param int $post_id The post id.
|
||||
* @param WP_Post $post The post object.
|
||||
*/
|
||||
public static function unignore_outbox_post( $post_id, $post ) {
|
||||
if ( Outbox::POST_TYPE === $post->post_type ) {
|
||||
\remove_action( 'msls_main_save', '__return_null' );
|
||||
}
|
||||
}
|
||||
}
|
@ -24,7 +24,7 @@ class Nodeinfo {
|
||||
\add_filter( 'nodeinfo_data', array( self::class, 'add_nodeinfo_data' ), 10, 2 );
|
||||
\add_filter( 'nodeinfo2_data', array( self::class, 'add_nodeinfo2_data' ) );
|
||||
|
||||
\add_filter( 'wellknown_nodeinfo_data', array( self::class, 'add_wellknown_nodeinfo_data' ), 10, 2 );
|
||||
\add_filter( 'wellknown_nodeinfo_data', array( self::class, 'add_wellknown_nodeinfo_data' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -45,8 +45,8 @@ class Nodeinfo {
|
||||
|
||||
$nodeinfo['usage']['users'] = array(
|
||||
'total' => get_total_users(),
|
||||
'activeMonth' => get_active_users( '1 month ago' ),
|
||||
'activeHalfyear' => get_active_users( '6 month ago' ),
|
||||
'activeMonth' => get_active_users(),
|
||||
'activeHalfyear' => get_active_users( 6 ),
|
||||
);
|
||||
|
||||
return $nodeinfo;
|
||||
@ -64,8 +64,8 @@ class Nodeinfo {
|
||||
|
||||
$nodeinfo['usage']['users'] = array(
|
||||
'total' => get_total_users(),
|
||||
'activeMonth' => get_active_users( '1 month ago' ),
|
||||
'activeHalfyear' => get_active_users( '6 month ago' ),
|
||||
'activeMonth' => get_active_users(),
|
||||
'activeHalfyear' => get_active_users( 6 ),
|
||||
);
|
||||
|
||||
return $nodeinfo;
|
||||
|
@ -8,7 +8,7 @@
|
||||
namespace Activitypub\Integration;
|
||||
|
||||
use Activitypub\Model\Blog;
|
||||
use Activitypub\Collection\Users;
|
||||
use Activitypub\Collection\Actors;
|
||||
|
||||
use function Activitypub\is_single_user;
|
||||
use function Activitypub\is_user_type_disabled;
|
||||
@ -72,13 +72,13 @@ class Opengraph {
|
||||
$user_id = \get_post_field( 'post_author', \get_queried_object_id() );
|
||||
} elseif ( ! is_user_type_disabled( 'blog' ) ) {
|
||||
// Use the Blog-User for any other page, if the Blog-User is not disabled.
|
||||
$user_id = Users::BLOG_USER_ID;
|
||||
$user_id = Actors::BLOG_USER_ID;
|
||||
} else {
|
||||
// Do not add any metadata otherwise.
|
||||
return $metadata;
|
||||
}
|
||||
|
||||
$user = Users::get_by_id( $user_id );
|
||||
$user = Actors::get_by_id( $user_id );
|
||||
|
||||
if ( ! $user || \is_wp_error( $user ) ) {
|
||||
return $metadata;
|
||||
|
@ -9,6 +9,7 @@ namespace Activitypub\Integration;
|
||||
|
||||
use Activitypub\Transformer\Post;
|
||||
|
||||
use function Activitypub\object_to_uri;
|
||||
use function Activitypub\generate_post_summary;
|
||||
|
||||
/**
|
||||
@ -28,20 +29,23 @@ class Seriously_Simple_Podcasting extends Post {
|
||||
* @return array The attachments array.
|
||||
*/
|
||||
public function get_attachment() {
|
||||
$post = $this->wp_object;
|
||||
$attachments = parent::get_attachment();
|
||||
|
||||
$post = $this->item;
|
||||
$attachment = array(
|
||||
'type' => \esc_attr( \get_post_meta( $post->ID, 'episode_type', true ) ),
|
||||
'type' => \esc_attr( ucfirst( \get_post_meta( $post->ID, 'episode_type', true ) ?? 'Audio' ) ),
|
||||
'url' => \esc_url( \get_post_meta( $post->ID, 'audio_file', true ) ),
|
||||
'name' => \esc_attr( \get_the_title( $post->ID ) ),
|
||||
'icon' => \esc_url( \get_post_meta( $post->ID, 'cover_image', true ) ),
|
||||
'name' => \esc_attr( \get_the_title( $post->ID ) ?? '' ),
|
||||
);
|
||||
|
||||
$attachment = array_filter( $attachment );
|
||||
array_unshift( $attachments, $attachment );
|
||||
$icon = \get_post_meta( $post->ID, 'cover_image', true );
|
||||
if ( ! $icon ) {
|
||||
$icon = $this->get_icon();
|
||||
}
|
||||
|
||||
return $attachments;
|
||||
if ( $icon ) {
|
||||
$attachment['icon'] = \esc_url( object_to_uri( $icon ) );
|
||||
}
|
||||
|
||||
return array( $attachment );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -63,6 +67,6 @@ class Seriously_Simple_Podcasting extends Post {
|
||||
* @return string The content.
|
||||
*/
|
||||
public function get_content() {
|
||||
return generate_post_summary( $this->wp_object );
|
||||
return generate_post_summary( $this->item );
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,10 @@
|
||||
|
||||
namespace Activitypub\Integration;
|
||||
|
||||
use Activitypub\Collection\Actors;
|
||||
use function Activitypub\url_to_authorid;
|
||||
use function Activitypub\url_to_commentid;
|
||||
|
||||
/**
|
||||
* Stream Connector for ActivityPub.
|
||||
*
|
||||
@ -29,6 +33,9 @@ class Stream_Connector extends \WP_Stream\Connector {
|
||||
*/
|
||||
public $actions = array(
|
||||
'activitypub_notification_follow',
|
||||
'activitypub_sent_to_inbox',
|
||||
'activitypub_outbox_processing_complete',
|
||||
'activitypub_outbox_processing_batch_complete',
|
||||
);
|
||||
|
||||
/**
|
||||
@ -55,7 +62,49 @@ class Stream_Connector extends \WP_Stream\Connector {
|
||||
* @return array
|
||||
*/
|
||||
public function get_action_labels() {
|
||||
return array();
|
||||
return array(
|
||||
'processed' => __( 'Processed', 'activitypub' ),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add action links to Stream drop row in admin list screen
|
||||
*
|
||||
* @filter wp_stream_action_links_{connector}
|
||||
*
|
||||
* @param array $links Previous links registered.
|
||||
* @param Record $record Stream record.
|
||||
*
|
||||
* @return array Action links
|
||||
*/
|
||||
public function action_links( $links, $record ) {
|
||||
if ( 'processed' === $record->action ) {
|
||||
$error = json_decode( $record->get_meta( 'error', true ), true );
|
||||
|
||||
if ( $error ) {
|
||||
$message = sprintf(
|
||||
'<details><summary>%1$s</summary><pre>%2$s</pre></details>',
|
||||
__( 'Inbox Error', 'activitypub' ),
|
||||
wp_json_encode( $error )
|
||||
);
|
||||
|
||||
$links[ $message ] = '';
|
||||
}
|
||||
|
||||
$debug = json_decode( $record->get_meta( 'debug', true ), true );
|
||||
|
||||
if ( $debug ) {
|
||||
$message = sprintf(
|
||||
'<details><summary>%1$s</summary><pre>%2$s</pre></details>',
|
||||
__( 'Debug', 'activitypub' ),
|
||||
wp_json_encode( $debug )
|
||||
);
|
||||
|
||||
$links[ $message ] = '';
|
||||
}
|
||||
}
|
||||
|
||||
return $links;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -79,4 +128,123 @@ class Stream_Connector extends \WP_Stream\Connector {
|
||||
$notification->target
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for activitypub_outbox_processing_complete.
|
||||
*
|
||||
* @param array $inboxes The inboxes.
|
||||
* @param string $json The ActivityPub Activity JSON.
|
||||
* @param int $actor_id The actor ID.
|
||||
* @param int $outbox_item_id The Outbox item ID.
|
||||
*/
|
||||
public function callback_activitypub_outbox_processing_complete( $inboxes, $json, $actor_id, $outbox_item_id ) {
|
||||
$outbox_item = \get_post( $outbox_item_id );
|
||||
$outbox_data = $this->prepare_outbox_data_for_response( $outbox_item );
|
||||
|
||||
$this->log(
|
||||
sprintf(
|
||||
// translators: %s is a URL.
|
||||
__( 'Outbox processing complete: %s', 'activitypub' ),
|
||||
$outbox_data['title']
|
||||
),
|
||||
array(
|
||||
'debug' => wp_json_encode(
|
||||
array(
|
||||
'actor_id' => $actor_id,
|
||||
'outbox_item_id' => $outbox_item_id,
|
||||
)
|
||||
),
|
||||
),
|
||||
$outbox_data['id'],
|
||||
$outbox_data['type'],
|
||||
'processed'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for activitypub_outbox_processing_batch_complete.
|
||||
*
|
||||
* @param array $inboxes The inboxes.
|
||||
* @param string $json The ActivityPub Activity JSON.
|
||||
* @param int $actor_id The actor ID.
|
||||
* @param int $outbox_item_id The Outbox item ID.
|
||||
* @param int $batch_size The batch size.
|
||||
* @param int $offset The offset.
|
||||
*/
|
||||
public function callback_activitypub_outbox_processing_batch_complete( $inboxes, $json, $actor_id, $outbox_item_id, $batch_size, $offset ) {
|
||||
$outbox_item = \get_post( $outbox_item_id );
|
||||
$outbox_data = $this->prepare_outbox_data_for_response( $outbox_item );
|
||||
|
||||
$this->log(
|
||||
sprintf(
|
||||
// translators: %s is a URL.
|
||||
__( 'Outbox processing batch complete: %s', 'activitypub' ),
|
||||
$outbox_data['title']
|
||||
),
|
||||
array(
|
||||
'debug' => wp_json_encode(
|
||||
array(
|
||||
'actor_id' => $actor_id,
|
||||
'outbox_item_id' => $outbox_item_id,
|
||||
'batch_size' => $batch_size,
|
||||
'offset' => $offset,
|
||||
)
|
||||
),
|
||||
),
|
||||
$outbox_data['id'],
|
||||
$outbox_data['type'],
|
||||
'processed'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the title of the outbox object.
|
||||
*
|
||||
* @param \WP_Post $outbox_item The outbox item.
|
||||
*
|
||||
* @return array The title, object ID, and object type of the outbox object.
|
||||
*/
|
||||
protected function prepare_outbox_data_for_response( $outbox_item ) {
|
||||
$object_id = $outbox_item->ID;
|
||||
$object_type = $outbox_item->post_type;
|
||||
$object_title = $outbox_item->post_title;
|
||||
|
||||
$post_id = url_to_postid( $outbox_item->post_title );
|
||||
if ( $post_id ) {
|
||||
$post = get_post( $post_id );
|
||||
|
||||
$object_id = $post_id;
|
||||
$object_type = $post->post_type;
|
||||
$object_title = $post->post_title;
|
||||
} else {
|
||||
$comment_id = url_to_commentid( $outbox_item->post_title );
|
||||
if ( $comment_id ) {
|
||||
$comment = get_comment( $comment_id );
|
||||
|
||||
$object_id = $comment_id;
|
||||
$object_type = 'comments';
|
||||
$object_title = $comment->comment_content;
|
||||
} else {
|
||||
$author_id = url_to_authorid( $outbox_item->post_title );
|
||||
if ( null !== $author_id ) {
|
||||
$object_id = $author_id;
|
||||
$object_type = 'profiles';
|
||||
|
||||
if ( $author_id ) {
|
||||
$object_title = get_userdata( $author_id )->display_name;
|
||||
} elseif ( Actors::BLOG_USER_ID === $author_id ) {
|
||||
$object_title = __( 'Blog User', 'activitypub' );
|
||||
} elseif ( Actors::APPLICATION_USER_ID === $author_id ) {
|
||||
$object_title = __( 'Application User', 'activitypub' );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return array(
|
||||
'id' => $object_id,
|
||||
'type' => $object_type,
|
||||
'title' => $object_title,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
namespace Activitypub\Integration;
|
||||
|
||||
use Activitypub\Collection\Users as User_Collection;
|
||||
use Activitypub\Collection\Actors;
|
||||
|
||||
use function Activitypub\get_rest_url_by_path;
|
||||
|
||||
@ -35,7 +35,7 @@ class Webfinger {
|
||||
* @return array The jrd array.
|
||||
*/
|
||||
public static function add_user_discovery( $jrd, $uri, $user ) {
|
||||
$user = User_Collection::get_by_id( $user->ID );
|
||||
$user = Actors::get_by_id( $user->ID );
|
||||
|
||||
if ( ! $user || is_wp_error( $user ) ) {
|
||||
return $jrd;
|
||||
@ -43,13 +43,16 @@ class Webfinger {
|
||||
|
||||
$jrd['subject'] = sprintf( 'acct:%s', $user->get_webfinger() );
|
||||
|
||||
$jrd['aliases'][] = $user->get_id();
|
||||
$jrd['aliases'][] = $user->get_url();
|
||||
$jrd['aliases'][] = $user->get_alternate_url();
|
||||
$jrd['aliases'] = array_unique( $jrd['aliases'] );
|
||||
$jrd['aliases'] = array_values( $jrd['aliases'] );
|
||||
|
||||
$jrd['links'][] = array(
|
||||
'rel' => 'self',
|
||||
'type' => 'application/activity+json',
|
||||
'href' => $user->get_url(),
|
||||
'href' => $user->get_id(),
|
||||
);
|
||||
|
||||
$jrd['links'][] = array(
|
||||
@ -69,32 +72,34 @@ class Webfinger {
|
||||
* @return array|\WP_Error The jrd array or WP_Error.
|
||||
*/
|
||||
public static function add_pseudo_user_discovery( $jrd, $uri ) {
|
||||
$user = User_Collection::get_by_resource( $uri );
|
||||
$user = Actors::get_by_resource( $uri );
|
||||
|
||||
if ( \is_wp_error( $user ) ) {
|
||||
return $user;
|
||||
}
|
||||
|
||||
$aliases = array(
|
||||
$user->get_id(),
|
||||
$user->get_url(),
|
||||
$user->get_alternate_url(),
|
||||
);
|
||||
|
||||
$aliases = array_unique( $aliases );
|
||||
$aliases = array_values( $aliases );
|
||||
|
||||
$profile = array(
|
||||
'subject' => sprintf( 'acct:%s', $user->get_webfinger() ),
|
||||
'aliases' => array_values( array_unique( $aliases ) ),
|
||||
'aliases' => $aliases,
|
||||
'links' => array(
|
||||
array(
|
||||
'rel' => 'self',
|
||||
'type' => 'application/activity+json',
|
||||
'href' => $user->get_url(),
|
||||
'href' => $user->get_id(),
|
||||
),
|
||||
array(
|
||||
'rel' => 'http://webfinger.net/rel/profile-page',
|
||||
'type' => 'text/html',
|
||||
'href' => $user->get_url(),
|
||||
'href' => $user->get_id(),
|
||||
),
|
||||
array(
|
||||
'rel' => 'http://ostatus.org/schema/1.0/subscribe',
|
||||
|
44
wp-content/plugins/activitypub/integration/class-wpml.php
Normal file
44
wp-content/plugins/activitypub/integration/class-wpml.php
Normal file
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
/**
|
||||
* WPML integration.
|
||||
*
|
||||
* @package Activitypub
|
||||
*/
|
||||
|
||||
namespace Activitypub\Integration;
|
||||
|
||||
/**
|
||||
* Compatibility with the WPML Multilingual CMS plugin.
|
||||
*
|
||||
* @see https://wpml.org/
|
||||
*/
|
||||
class WPML {
|
||||
/**
|
||||
* Initialize the class, registering WordPress hooks.
|
||||
*/
|
||||
public static function init() {
|
||||
\add_filter( 'activitypub_locale', array( self::class, 'get_wpml_post_locale' ), 10, 2 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the post locale from the WPML post data.
|
||||
*
|
||||
* @param string $lang The language code.
|
||||
* @param int $post The post object.
|
||||
*
|
||||
* @return string The modified language code.
|
||||
*/
|
||||
public static function get_wpml_post_locale( $lang, $post ) {
|
||||
if ( ! $post instanceof \WP_Post ) {
|
||||
return $lang;
|
||||
}
|
||||
|
||||
$language_details = apply_filters( 'wpml_post_language_details', null, $post->ID );
|
||||
|
||||
if ( is_array( $language_details ) && isset( $language_details['language_code'] ) ) {
|
||||
$lang = $language_details['language_code'];
|
||||
}
|
||||
|
||||
return $lang;
|
||||
}
|
||||
}
|
@ -7,6 +7,8 @@
|
||||
|
||||
namespace Activitypub\Integration;
|
||||
|
||||
\Activitypub\Autoloader::register_path( __NAMESPACE__, __DIR__ );
|
||||
|
||||
/**
|
||||
* Initialize the ActivityPub integrations.
|
||||
*/
|
||||
@ -19,7 +21,6 @@ function plugin_init() {
|
||||
*
|
||||
* @see https://wordpress.org/plugins/webfinger/
|
||||
*/
|
||||
require_once __DIR__ . '/class-webfinger.php';
|
||||
Webfinger::init();
|
||||
|
||||
/**
|
||||
@ -30,7 +31,6 @@ function plugin_init() {
|
||||
*
|
||||
* @see https://wordpress.org/plugins/nodeinfo/
|
||||
*/
|
||||
require_once __DIR__ . '/class-nodeinfo.php';
|
||||
Nodeinfo::init();
|
||||
|
||||
/**
|
||||
@ -41,7 +41,6 @@ function plugin_init() {
|
||||
* @see https://wordpress.org/plugins/enable-mastodon-apps/
|
||||
*/
|
||||
if ( \defined( 'ENABLE_MASTODON_APPS_VERSION' ) ) {
|
||||
require_once __DIR__ . '/class-enable-mastodon-apps.php';
|
||||
Enable_Mastodon_Apps::init();
|
||||
}
|
||||
|
||||
@ -53,7 +52,6 @@ function plugin_init() {
|
||||
* @see https://wordpress.org/plugins/opengraph/
|
||||
*/
|
||||
if ( '1' === \get_option( 'activitypub_use_opengraph', '1' ) ) {
|
||||
require_once __DIR__ . '/class-opengraph.php';
|
||||
Opengraph::init();
|
||||
}
|
||||
|
||||
@ -65,10 +63,31 @@ function plugin_init() {
|
||||
* @see https://jetpack.com/
|
||||
*/
|
||||
if ( \defined( 'JETPACK__VERSION' ) && ! \defined( 'IS_WPCOM' ) ) {
|
||||
require_once __DIR__ . '/class-jetpack.php';
|
||||
Jetpack::init();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds Akismet support.
|
||||
*
|
||||
* This class handles the compatibility with the Akismet plugin.
|
||||
*
|
||||
* @see https://wordpress.org/plugins/akismet/
|
||||
*/
|
||||
if ( \defined( 'AKISMET_VERSION' ) ) {
|
||||
Akismet::init();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds Multisite Language Switcher support.
|
||||
*
|
||||
* This class handles the compatibility with the Multisite Language Switcher plugin.
|
||||
*
|
||||
* @see https://wordpress.org/plugins/multisite-language-switcher/
|
||||
*/
|
||||
if ( \defined( 'MSLS_PLUGIN_VERSION' ) ) {
|
||||
Multisite_Language_Switcher::init();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds Seriously Simple Podcasting support.
|
||||
*
|
||||
@ -84,7 +103,6 @@ function plugin_init() {
|
||||
'WP_Post' === $object_class &&
|
||||
\get_post_meta( $data->ID, 'audio_file', true )
|
||||
) {
|
||||
require_once __DIR__ . '/class-seriously-simple-podcasting.php';
|
||||
return new Seriously_Simple_Podcasting( $data );
|
||||
}
|
||||
return $transformer;
|
||||
@ -93,6 +111,17 @@ function plugin_init() {
|
||||
3
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds WPML Multilingual CMS (plugin) support.
|
||||
*
|
||||
* This class handles the compatibility with the WPML plugin.
|
||||
*
|
||||
* @see https://wpml.org/
|
||||
*/
|
||||
if ( \defined( 'ICL_SITEPRESS_VERSION' ) ) {
|
||||
WPML::init();
|
||||
}
|
||||
}
|
||||
\add_action( 'plugins_loaded', __NAMESPACE__ . '\plugin_init' );
|
||||
|
||||
@ -104,22 +133,9 @@ function plugin_init() {
|
||||
* @return array The Stream connectors with the ActivityPub connector.
|
||||
*/
|
||||
function register_stream_connector( $classes ) {
|
||||
require plugin_dir_path( __FILE__ ) . '/class-stream-connector.php';
|
||||
$class = new Stream_Connector();
|
||||
|
||||
$class_name = '\Activitypub\Integration\Stream_Connector';
|
||||
|
||||
if ( ! class_exists( $class_name ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
wp_stream_get_instance();
|
||||
$class = new $class_name();
|
||||
|
||||
if ( ! method_exists( $class, 'is_dependency_satisfied' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( $class->is_dependency_satisfied() ) {
|
||||
if ( method_exists( $class, 'is_dependency_satisfied' ) && $class->is_dependency_satisfied() ) {
|
||||
$classes[] = $class;
|
||||
}
|
||||
|
||||
@ -145,11 +161,4 @@ add_filter(
|
||||
*
|
||||
* @see https://buddypress.org/
|
||||
*/
|
||||
add_action(
|
||||
'bp_include',
|
||||
function () {
|
||||
require_once __DIR__ . '/class-buddypress.php';
|
||||
Buddypress::init();
|
||||
},
|
||||
0
|
||||
);
|
||||
add_action( 'bp_include', array( __NAMESPACE__ . '\Buddypress', 'init' ), 0 );
|
||||
|
Reference in New Issue
Block a user