From a3fd251a0c7bc9cc0c71c74fa95033a9070c85e9 Mon Sep 17 00:00:00 2001 From: Lai Power Date: Mon, 20 Dec 2021 13:41:52 +0000 Subject: [PATCH] updated plugin `ActivityPub` version 0.13.2 --- .../plugins/activitypub/activitypub.php | 11 +++- .../activitypub/includes/rest/class-inbox.php | 15 +++-- .../integration/class-buddypress.php | 58 +++++++++++++++++++ wp-content/plugins/activitypub/readme.txt | 6 +- .../activitypub/templates/author-json.php | 9 ++- 5 files changed, 88 insertions(+), 11 deletions(-) create mode 100644 wp-content/plugins/activitypub/integration/class-buddypress.php diff --git a/wp-content/plugins/activitypub/activitypub.php b/wp-content/plugins/activitypub/activitypub.php index a52a6d58..c54be221 100644 --- a/wp-content/plugins/activitypub/activitypub.php +++ b/wp-content/plugins/activitypub/activitypub.php @@ -3,7 +3,7 @@ * Plugin Name: ActivityPub * Plugin URI: https://github.com/pfefferle/wordpress-activitypub/ * Description: The ActivityPub protocol is a decentralized social networking protocol based upon the ActivityStreams 2.0 data format. - * Version: 0.13.1 + * Version: 0.13.2 * Author: Matthias Pfefferle * Author URI: https://notiz.blog/ * License: MIT @@ -106,3 +106,12 @@ function flush_rewrite_rules() { } \register_activation_hook( __FILE__, '\Activitypub\flush_rewrite_rules' ); \register_deactivation_hook( __FILE__, '\flush_rewrite_rules' ); + +/** + * Only load code that needs BuddyPress to run once BP is loaded and initialized. + */ +function enable_buddypress_features() { + require_once \dirname( __FILE__ ) . '/integration/class-buddypress.php'; + \Activitypub\Integration\Buddypress::init(); +} +add_action( 'bp_include', '\Activitypub\enable_buddypress_features' ); diff --git a/wp-content/plugins/activitypub/includes/rest/class-inbox.php b/wp-content/plugins/activitypub/includes/rest/class-inbox.php index 4dcbd8ce..11790705 100644 --- a/wp-content/plugins/activitypub/includes/rest/class-inbox.php +++ b/wp-content/plugins/activitypub/includes/rest/class-inbox.php @@ -139,6 +139,7 @@ class Inbox { $data = $request->get_params(); $type = $request->get_param( 'type' ); + $type = \strtolower( $type ); \do_action( 'activitypub_inbox', $data, $user_id, $type ); \do_action( "activitypub_inbox_{$type}", $data, $user_id ); @@ -173,6 +174,8 @@ class Inbox { } foreach ( $users as $user ) { + $type = \strtolower( $type ); + \do_action( 'activitypub_inbox', $data, $user->ID, $type ); \do_action( "activitypub_inbox_{$type}", $data, $user->ID ); } @@ -216,9 +219,9 @@ class Inbox { 'required' => true, //'type' => 'enum', //'enum' => array( 'Create' ), - 'sanitize_callback' => function( $param, $request, $key ) { - return \strtolower( $param ); - }, + //'sanitize_callback' => function( $param, $request, $key ) { + // return \strtolower( $param ); + //}, ); $params['object'] = array( @@ -261,9 +264,9 @@ class Inbox { 'required' => true, //'type' => 'enum', //'enum' => array( 'Create' ), - 'sanitize_callback' => function( $param, $request, $key ) { - return \strtolower( $param ); - }, + //'sanitize_callback' => function( $param, $request, $key ) { + // return \strtolower( $param ); + //}, ); $params['object'] = array( diff --git a/wp-content/plugins/activitypub/integration/class-buddypress.php b/wp-content/plugins/activitypub/integration/class-buddypress.php new file mode 100644 index 00000000..1087f47b --- /dev/null +++ b/wp-content/plugins/activitypub/integration/class-buddypress.php @@ -0,0 +1,58 @@ +url = bp_core_get_user_domain( $author_id ); //add BP member profile URL as user URL + + // add BuddyPress' cover_image instead of WordPress' header_image + $cover_image_url = bp_attachments_get_attachment( 'url', array( 'item_id' => $author_id ) ); + + if ( $cover_image_url ) { + $object->image = array( + 'type' => 'Image', + 'url' => $cover_image_url, + ); + } + + // change profile URL to BuddyPress' profile URL + $object->attachment['profile_url'] = array( + 'type' => 'PropertyValue', + 'name' => \__( 'Profile', 'activitypub' ), + 'value' => \html_entity_decode( + '' . \wp_parse_url( \bp_core_get_user_domain( $author_id ), \PHP_URL_HOST ) . '', + \ENT_QUOTES, + 'UTF-8' + ), + ); + + // replace blog URL on multisite + if ( is_multisite() ) { + $user_blogs = get_blogs_of_user( $author_id ); //get sites of user to send as AP metadata + + if ( ! empty( $user_blogs ) ) { + unset( $object->attachment['blog_url'] ); + + foreach ( $user_blogs as $blog ) { + if ( 1 !== $blog->userblog_id ) { + $object->attachment[] = array( + 'type' => 'PropertyValue', + 'name' => $blog->blogname, + 'value' => \html_entity_decode( + '' . \wp_parse_url( $blog->siteurl, \PHP_URL_HOST ) . '', + \ENT_QUOTES, + 'UTF-8' + ), + ); + } + } + } + } + + return $object; + } +} diff --git a/wp-content/plugins/activitypub/readme.txt b/wp-content/plugins/activitypub/readme.txt index e6dc463e..16550323 100644 --- a/wp-content/plugins/activitypub/readme.txt +++ b/wp-content/plugins/activitypub/readme.txt @@ -4,7 +4,7 @@ Donate link: https://notiz.blog/donate/ Tags: OStatus, fediverse, activitypub, activitystream Requires at least: 4.7 Tested up to: 5.8 -Stable tag: 0.13.1 +Stable tag: 0.13.2 Requires PHP: 5.6 License: MIT License URI: http://opensource.org/licenses/MIT @@ -88,6 +88,10 @@ Where 'blog' is the path to the subdirectory at which your blog resides. Project maintained on GitHub at [pfefferle/wordpress-activitypub](https://github.com/pfefferle/wordpress-activitypub). += 0.13.2 = + +* fix Follow issue AGAIN + = 0.13.1 = * fix Inbox issue diff --git a/wp-content/plugins/activitypub/templates/author-json.php b/wp-content/plugins/activitypub/templates/author-json.php index ccaa167f..c5d39a5b 100644 --- a/wp-content/plugins/activitypub/templates/author-json.php +++ b/wp-content/plugins/activitypub/templates/author-json.php @@ -43,7 +43,7 @@ $json->publicKey = array( $json->tag = array(); $json->attachment = array(); -$json->attachment[] = array( +$json->attachment['blog_url'] = array( 'type' => 'PropertyValue', 'name' => \__( 'Blog', 'activitypub' ), 'value' => \html_entity_decode( @@ -53,7 +53,7 @@ $json->attachment[] = array( ), ); -$json->attachment[] = array( +$json->attachment['profile_url'] = array( 'type' => 'PropertyValue', 'name' => \__( 'Profile', 'activitypub' ), 'value' => \html_entity_decode( @@ -64,7 +64,7 @@ $json->attachment[] = array( ); if ( \get_the_author_meta( 'user_url', $author_id ) ) { - $json->attachment[] = array( + $json->attachment['user_url'] = array( 'type' => 'PropertyValue', 'name' => \__( 'Website', 'activitypub' ), 'value' => \html_entity_decode( @@ -84,6 +84,9 @@ $json->endpoints = array( // filter output $json = \apply_filters( 'activitypub_json_author_array', $json, $author_id ); +// migrate to ActivityPub standard +$json->attachment = array_values( $json->attachment ); + /* * Action triggerd prior to the ActivityPub profile being created and sent to the client */