Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/changelog/2383-from-description
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: changed

Reorganize integration loader and move Stream integration into dedicated folder structure.
168 changes: 76 additions & 92 deletions integration/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@
* Initialize the ActivityPub integrations.
*/
function plugin_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 Classic Editor support.
*
Expand All @@ -27,26 +38,6 @@ function plugin_init() {
Classic_Editor::init();
}

/**
* Adds WebFinger (plugin) support.
*
* This class handles the compatibility with the WebFinger plugin
* and coordinates the internal WebFinger implementation.
*
* @see https://wordpress.org/plugins/webfinger/
*/
Webfinger::init();

/**
* Adds NodeInfo (plugin) support.
*
* This class handles the compatibility with the NodeInfo plugin
* and coordinates the internal NodeInfo implementation.
*
* @see https://wordpress.org/plugins/nodeinfo/
*/
Nodeinfo::init();

/**
* Adds Enable Mastodon Apps support.
*
Expand All @@ -58,17 +49,6 @@ function plugin_init() {
Enable_Mastodon_Apps::init();
}

/**
* Adds OpenGraph support.
*
* This class handles the compatibility with the OpenGraph plugin.
*
* @see https://wordpress.org/plugins/opengraph/
*/
if ( '1' === \get_option( 'activitypub_use_opengraph', '1' ) ) {
Opengraph::init();
}

/**
* Adds Jetpack support.
*
Expand All @@ -81,15 +61,13 @@ function plugin_init() {
}

/**
* Adds Akismet support.
* Adds LiteSpeed Cache support.
*
* This class handles the compatibility with the Akismet plugin.
* The check for whether LiteSpeed Cache is loaded and initialized happens inside Litespeed_Cache::init().
*
* @see https://wordpress.org/plugins/akismet/
* @see https://wordpress.org/plugins/litespeed-cache/
*/
if ( \defined( 'AKISMET_VERSION' ) ) {
Akismet::init();
}
Litespeed_Cache::init();

/**
* Adds Multisite Language Switcher support.
Expand All @@ -102,6 +80,27 @@ function plugin_init() {
Multisite_Language_Switcher::init();
}

/**
* Adds NodeInfo (plugin) support.
*
* This class handles the compatibility with the NodeInfo plugin
* and coordinates the internal NodeInfo implementation.
*
* @see https://wordpress.org/plugins/nodeinfo/
*/
Nodeinfo::init();

/**
* Adds OpenGraph support.
*
* This class handles the compatibility with the OpenGraph plugin.
*
* @see https://wordpress.org/plugins/opengraph/
*/
if ( '1' === \get_option( 'activitypub_use_opengraph', '1' ) ) {
Opengraph::init();
}

/**
* Adds Seriously Simple Podcasting support.
*
Expand All @@ -127,48 +126,65 @@ function ( $transformer, $data, $object_class ) {
}

/**
* Adds WPML Multilingual CMS (plugin) support.
* Adds Stream support.
*
* This class handles the compatibility with the WPML plugin.
* This class handles the compatibility with the Stream plugin.
*
* @see https://wpml.org/
* @see https://wordpress.org/plugins/stream/
*/
if ( \defined( 'ICL_SITEPRESS_VERSION' ) ) {
WPML::init();
}
Stream\Stream::init();

if ( \class_exists( 'WP_Rest_Cache_Plugin\Includes\Plugin' ) ) {
WP_Rest_Cache::init();
}
/**
* Adds Surge support.
*
* Only load code that needs Surge to run once Surge is loaded and initialized.
*
* @see https://wordpress.org/plugins/surge/
*/
Surge::init();

/**
* Adds Yoast SEO support.
* Adds WebFinger (plugin) support.
*
* This class handles the compatibility with Yoast SEO.
* This class handles the compatibility with the WebFinger plugin
* and coordinates the internal WebFinger implementation.
*
* @see https://wordpress.org/plugins/wordpress-seo/
* @see https://wordpress.org/plugins/webfinger/
*/
if ( \defined( 'WPSEO_VERSION' ) ) {
Yoast_Seo::init();
Webfinger::init();

/**
* Adds WP REST Cache support.
*
* This class handles the compatibility with the WP REST Cache plugin.
*
* @see https://wordpress.org/plugins/wp-rest-cache/
*/
if ( \class_exists( 'WP_Rest_Cache_Plugin\Includes\Plugin' ) ) {
WP_Rest_Cache::init();
}

/**
* Load the Surge integration.
* Adds WPML Multilingual CMS (plugin) support.
*
* Only load code that needs Surge to run once Surge is loaded and initialized.
* This class handles the compatibility with the WPML plugin.
*
* @see https://wordpress.org/plugins/surge/
* @see https://wpml.org/
*/
Surge::init();
if ( \defined( 'ICL_SITEPRESS_VERSION' ) ) {
WPML::init();
}

/**
* Load the LiteSpeed Cache integration.
* Adds Yoast SEO support.
*
* The check for whether LiteSpeed Cache is loaded and initialized happens inside Litespeed_Cache::init().
* This class handles the compatibility with Yoast SEO.
*
* @see https://wordpress.org/plugins/litespeed-cache/
* @see https://wordpress.org/plugins/wordpress-seo/
*/
Litespeed_Cache::init();
if ( \defined( 'WPSEO_VERSION' ) ) {
Yoast_Seo::init();
}
}
\add_action( 'plugins_loaded', __NAMESPACE__ . '\plugin_init' );

Expand All @@ -180,43 +196,11 @@ function ( $transformer, $data, $object_class ) {
\register_activation_hook( ACTIVITYPUB_PLUGIN_FILE, array( __NAMESPACE__ . '\LiteSpeed_Cache', 'add_htaccess_rules' ) );
\register_deactivation_hook( ACTIVITYPUB_PLUGIN_FILE, array( __NAMESPACE__ . '\LiteSpeed_Cache', 'remove_htaccess_rules' ) );


/**
* Register the Stream Connector for ActivityPub.
*
* @param array $classes The Stream connectors.
*
* @return array The Stream connectors with the ActivityPub connector.
*/
function register_stream_connector( $classes ) {
$class = new Stream_Connector();

if ( method_exists( $class, 'is_dependency_satisfied' ) && $class->is_dependency_satisfied() ) {
$classes[] = $class;
}

return $classes;
}
add_filter( 'wp_stream_connectors', __NAMESPACE__ . '\register_stream_connector' );

// Excluded ActivityPub post types from the Stream.
add_filter(
'wp_stream_posts_exclude_post_types',
function ( $post_types ) {
$post_types[] = 'ap_actor';
$post_types[] = 'ap_extrafield';
$post_types[] = 'ap_extrafield_blog';
$post_types[] = 'ap_post';

return $post_types;
}
);

/**
* Load the BuddyPress integration.
*
* Only load code that needs BuddyPress to run once BP is loaded and initialized.
*
* @see https://buddypress.org/
*/
add_action( 'bp_include', array( __NAMESPACE__ . '\Buddypress', 'init' ), 0 );
\add_action( 'bp_include', array( __NAMESPACE__ . '\Buddypress', 'init' ), 0 );
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @package Activitypub
*/

namespace Activitypub\Integration;
namespace Activitypub\Integration\Stream;

use Activitypub\Collection\Actors;

Expand All @@ -19,7 +19,7 @@
*
* @see https://wordpress.org/plugins/stream/
*/
class Stream_Connector extends \WP_Stream\Connector {
class Connector extends \WP_Stream\Connector {
/**
* Connector slug.
*
Expand All @@ -45,7 +45,7 @@ class Stream_Connector extends \WP_Stream\Connector {
* @return string
*/
public function get_label() {
return __( 'ActivityPub', 'activitypub' );
return \__( 'ActivityPub', 'activitypub' );
}

/**
Expand All @@ -64,7 +64,7 @@ public function get_context_labels() {
*/
public function get_action_labels() {
return array(
'processed' => __( 'Processed', 'activitypub' ),
'processed' => \__( 'Processed', 'activitypub' ),
);
}

Expand All @@ -80,25 +80,25 @@ public function get_action_labels() {
*/
public function action_links( $links, $record ) {
if ( 'processed' === $record->action ) {
$error = json_decode( $record->get_meta( 'error', true ), true );
$error = \json_decode( $record->get_meta( 'error', true ), true );

if ( $error ) {
$message = sprintf(
$message = \sprintf(
'<details><summary>%1$s</summary><pre>%2$s</pre></details>',
__( 'Inbox Error', 'activitypub' ),
wp_json_encode( $error )
\__( 'Inbox Error', 'activitypub' ),
\wp_json_encode( $error )
);

$links[ $message ] = '';
}

$debug = json_decode( $record->get_meta( 'debug', true ), true );
$debug = \json_decode( $record->get_meta( 'debug', true ), true );

if ( $debug ) {
$message = sprintf(
$message = \sprintf(
'<details><summary>%1$s</summary><pre>%2$s</pre></details>',
__( 'Debug', 'activitypub' ),
wp_json_encode( $debug )
\__( 'Debug', 'activitypub' ),
\wp_json_encode( $debug )
);

$links[ $message ] = '';
Expand Down Expand Up @@ -149,13 +149,13 @@ public function callback_activitypub_outbox_processing_complete( $inboxes, $json
$outbox_data = $this->prepare_outbox_data_for_response( $outbox_item );

$this->log(
sprintf(
\sprintf(
// translators: %s is a URL.
__( 'Outbox processing complete: %s', 'activitypub' ),
\__( 'Outbox processing complete: %s', 'activitypub' ),
$outbox_data['title']
),
array(
'debug' => wp_json_encode(
'debug' => \wp_json_encode(
array(
'actor_id' => $actor_id,
'outbox_item_id' => $outbox_item_id,
Expand Down Expand Up @@ -183,13 +183,10 @@ public function callback_activitypub_outbox_processing_batch_complete( $inboxes,
$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']
),
// translators: %s is a URL.
\sprintf( \__( 'Outbox processing batch complete: %s', 'activitypub' ), $outbox_data['title'] ),
array(
'debug' => wp_json_encode(
'debug' => \wp_json_encode(
array(
'actor_id' => $actor_id,
'outbox_item_id' => $outbox_item_id,
Expand All @@ -216,17 +213,17 @@ protected function prepare_outbox_data_for_response( $outbox_item ) {
$object_type = $outbox_item->post_type;
$object_title = $outbox_item->post_title;

$post_id = url_to_postid( $outbox_item->post_title );
$post_id = \url_to_postid( $outbox_item->post_title );
if ( $post_id ) {
$post = get_post( $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 );
$comment = \get_comment( $comment_id );

$object_id = $comment_id;
$object_type = 'comments';
Expand All @@ -238,11 +235,11 @@ protected function prepare_outbox_data_for_response( $outbox_item ) {
$object_type = 'profiles';

if ( $author_id ) {
$object_title = get_userdata( $author_id )->display_name;
$object_title = \get_userdata( $author_id )->display_name;
} elseif ( Actors::BLOG_USER_ID === $author_id ) {
$object_title = __( 'Blog User', 'activitypub' );
$object_title = \__( 'Blog User', 'activitypub' );
} elseif ( Actors::APPLICATION_USER_ID === $author_id ) {
$object_title = __( 'Application User', 'activitypub' );
$object_title = \__( 'Application User', 'activitypub' );
}
}
}
Expand Down
Loading