From b49569de479d6c7e35ad77e67d7e43c51f1ec25f Mon Sep 17 00:00:00 2001 From: Lai Power Date: Fri, 19 Aug 2022 16:15:51 +0000 Subject: [PATCH] updated plugin `ActivityPub` version 0.13.4 --- .../plugins/activitypub/activitypub.php | 25 +++++++++++--- .../activitypub/includes/class-admin.php | 24 +++++++++---- .../activitypub/includes/functions.php | 12 ++++--- .../includes/model/class-activity.php | 2 +- .../activitypub/includes/model/class-post.php | 2 +- .../includes/peer/class-followers.php | 10 ++++-- .../includes/rest/class-followers.php | 20 +++++++---- .../includes/rest/class-following.php | 20 +++++++---- .../activitypub/includes/rest/class-inbox.php | 32 ++++++++++------- .../includes/rest/class-nodeinfo.php | 12 +++++-- .../includes/rest/class-ostatus.php | 4 ++- .../includes/rest/class-outbox.php | 34 ++++++++++++------- .../includes/rest/class-webfinger.php | 15 ++++---- wp-content/plugins/activitypub/readme.txt | 8 +++-- 14 files changed, 149 insertions(+), 71 deletions(-) diff --git a/wp-content/plugins/activitypub/activitypub.php b/wp-content/plugins/activitypub/activitypub.php index dd7b6737..d802cd7b 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.3 + * Version: 0.13.4 * Author: Matthias Pfefferle * Author URI: https://notiz.blog/ * License: MIT @@ -72,9 +72,12 @@ function init() { \Activitypub\Health_Check::init(); require_once \dirname( __FILE__ ) . '/includes/rest/class-server.php'; - \add_filter( 'wp_rest_server_class', function() { - return '\Activitypub\Rest\Server'; - } ); + \add_filter( + 'wp_rest_server_class', + function() { + return '\Activitypub\Rest\Server'; + } + ); if ( \WP_DEBUG ) { require_once \dirname( __FILE__ ) . '/includes/debug.php'; @@ -82,6 +85,20 @@ function init() { } \add_action( 'plugins_loaded', '\Activitypub\init' ); +/** + * Add plugin settings link + */ +function plugin_settings_link( $actions ) { + $settings_link[] = \sprintf( + '%2s', + \menu_page_url( 'activitypub', false ), + \__( 'Settings', 'activitypub' ) + ); + + return \array_merge( $settings_link, $actions ); +} +\add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), '\Activitypub\plugin_settings_link' ); + /** * Add rewrite rules */ diff --git a/wp-content/plugins/activitypub/includes/class-admin.php b/wp-content/plugins/activitypub/includes/class-admin.php index 14ed13c4..9e1eedb8 100644 --- a/wp-content/plugins/activitypub/includes/class-admin.php +++ b/wp-content/plugins/activitypub/includes/class-admin.php @@ -54,7 +54,9 @@ class Admin { */ public static function register_settings() { \register_setting( - 'activitypub', 'activitypub_post_content_type', array( + 'activitypub', + 'activitypub_post_content_type', + array( 'type' => 'string', 'description' => \__( 'Use title and link, summary, full or custom content', 'activitypub' ), 'show_in_rest' => array( @@ -66,7 +68,9 @@ class Admin { ) ); \register_setting( - 'activitypub', 'activitypub_custom_post_content', array( + 'activitypub', + 'activitypub_custom_post_content', + array( 'type' => 'string', 'description' => \__( 'Define your own custom post template', 'activitypub' ), 'show_in_rest' => true, @@ -74,7 +78,9 @@ class Admin { ) ); \register_setting( - 'activitypub', 'activitypub_object_type', array( + 'activitypub', + 'activitypub_object_type', + array( 'type' => 'string', 'description' => \__( 'The Activity-Object-Type', 'activitypub' ), 'show_in_rest' => array( @@ -86,21 +92,27 @@ class Admin { ) ); \register_setting( - 'activitypub', 'activitypub_use_hashtags', array( + 'activitypub', + 'activitypub_use_hashtags', + array( 'type' => 'boolean', 'description' => \__( 'Add hashtags in the content as native tags and replace the #tag with the tag-link', 'activitypub' ), 'default' => 0, ) ); \register_setting( - 'activitypub', 'activitypub_allowed_html', array( + 'activitypub', + 'activitypub_allowed_html', + array( 'type' => 'string', 'description' => \__( 'List of HTML elements that are allowed in activities.', 'activitypub' ), 'default' => ACTIVITYPUB_ALLOWED_HTML, ) ); \register_setting( - 'activitypub', 'activitypub_support_post_types', array( + 'activitypub', + 'activitypub_support_post_types', + array( 'type' => 'string', 'description' => \esc_html__( 'Enable ActivityPub support for post types', 'activitypub' ), 'show_in_rest' => true, diff --git a/wp-content/plugins/activitypub/includes/functions.php b/wp-content/plugins/activitypub/includes/functions.php index a5a84952..3c33664d 100644 --- a/wp-content/plugins/activitypub/includes/functions.php +++ b/wp-content/plugins/activitypub/includes/functions.php @@ -123,11 +123,13 @@ function get_remote_metadata_by_actor( $actor ) { return new \WP_Error( 'activitypub_no_valid_actor_url', \__( 'The "actor" is no valid URL', 'activitypub' ), $actor ); } - $user = \get_users( array ( - 'number' => 1, - 'who' => 'authors', - 'fields' => 'ID', - ) ); + $user = \get_users( + array( + 'number' => 1, + 'who' => 'authors', + 'fields' => 'ID', + ) + ); // we just need any user to generate a request signature $user_id = \reset( $user ); diff --git a/wp-content/plugins/activitypub/includes/model/class-activity.php b/wp-content/plugins/activitypub/includes/model/class-activity.php index b6cc2515..eb96d116 100644 --- a/wp-content/plugins/activitypub/includes/model/class-activity.php +++ b/wp-content/plugins/activitypub/includes/model/class-activity.php @@ -30,7 +30,7 @@ class Activity { } $this->type = \ucfirst( $type ); - $this->published = \date( 'Y-m-d\TH:i:s\Z', \strtotime( 'now' ) ); + $this->published = \gmdate( 'Y-m-d\TH:i:s\Z', \strtotime( 'now' ) ); } public function __call( $method, $params ) { diff --git a/wp-content/plugins/activitypub/includes/model/class-post.php b/wp-content/plugins/activitypub/includes/model/class-post.php index 33b9411e..e8851991 100644 --- a/wp-content/plugins/activitypub/includes/model/class-post.php +++ b/wp-content/plugins/activitypub/includes/model/class-post.php @@ -46,7 +46,7 @@ class Post { $array = array( 'id' => $this->id, 'type' => $this->object_type, - 'published' => \date( 'Y-m-d\TH:i:s\Z', \strtotime( $post->post_date_gmt ) ), + 'published' => \gmdate( 'Y-m-d\TH:i:s\Z', \strtotime( $post->post_date_gmt ) ), 'attributedTo' => \get_author_posts_url( $post->post_author ), 'summary' => $this->summary, 'inReplyTo' => null, diff --git a/wp-content/plugins/activitypub/includes/peer/class-followers.php b/wp-content/plugins/activitypub/includes/peer/class-followers.php index c1846a48..abc18e32 100644 --- a/wp-content/plugins/activitypub/includes/peer/class-followers.php +++ b/wp-content/plugins/activitypub/includes/peer/class-followers.php @@ -50,9 +50,13 @@ class Followers { $actor = $actor['id']; } - return new \WP_Error( 'invalid_actor_object', \__( 'Unknown Actor schema', 'activitypub' ), array( - 'status' => 404, - ) ); + return new \WP_Error( + 'invalid_actor_object', + \__( 'Unknown Actor schema', 'activitypub' ), + array( + 'status' => 404, + ) + ); } if ( ! \is_array( $followers ) ) { diff --git a/wp-content/plugins/activitypub/includes/rest/class-followers.php b/wp-content/plugins/activitypub/includes/rest/class-followers.php index f246edd0..34392ce0 100644 --- a/wp-content/plugins/activitypub/includes/rest/class-followers.php +++ b/wp-content/plugins/activitypub/includes/rest/class-followers.php @@ -21,7 +21,9 @@ class Followers { */ public static function register_routes() { \register_rest_route( - 'activitypub/1.0', '/users/(?P\d+)/followers', array( + 'activitypub/1.0', + '/users/(?P\d+)/followers', + array( array( 'methods' => \WP_REST_Server::READABLE, 'callback' => array( '\Activitypub\Rest\Followers', 'get' ), @@ -44,12 +46,16 @@ class Followers { $user = \get_user_by( 'ID', $user_id ); if ( ! $user ) { - return new \WP_Error( 'rest_invalid_param', \__( 'User not found', 'activitypub' ), array( - 'status' => 404, - 'params' => array( - 'user_id' => \__( 'User not found', 'activitypub' ), - ), - ) ); + return new \WP_Error( + 'rest_invalid_param', + \__( 'User not found', 'activitypub' ), + array( + 'status' => 404, + 'params' => array( + 'user_id' => \__( 'User not found', 'activitypub' ), + ), + ) + ); } /* diff --git a/wp-content/plugins/activitypub/includes/rest/class-following.php b/wp-content/plugins/activitypub/includes/rest/class-following.php index 8e375974..06d3f0b3 100644 --- a/wp-content/plugins/activitypub/includes/rest/class-following.php +++ b/wp-content/plugins/activitypub/includes/rest/class-following.php @@ -21,7 +21,9 @@ class Following { */ public static function register_routes() { \register_rest_route( - 'activitypub/1.0', '/users/(?P\d+)/following', array( + 'activitypub/1.0', + '/users/(?P\d+)/following', + array( array( 'methods' => \WP_REST_Server::READABLE, 'callback' => array( '\Activitypub\Rest\Following', 'get' ), @@ -44,12 +46,16 @@ class Following { $user = \get_user_by( 'ID', $user_id ); if ( ! $user ) { - return new \WP_Error( 'rest_invalid_param', \__( 'User not found', 'activitypub' ), array( - 'status' => 404, - 'params' => array( - 'user_id' => \__( 'User not found', 'activitypub' ), - ), - ) ); + return new \WP_Error( + 'rest_invalid_param', + \__( 'User not found', 'activitypub' ), + array( + 'status' => 404, + 'params' => array( + 'user_id' => \__( 'User not found', 'activitypub' ), + ), + ) + ); } /* diff --git a/wp-content/plugins/activitypub/includes/rest/class-inbox.php b/wp-content/plugins/activitypub/includes/rest/class-inbox.php index 11790705..1ffe4514 100644 --- a/wp-content/plugins/activitypub/includes/rest/class-inbox.php +++ b/wp-content/plugins/activitypub/includes/rest/class-inbox.php @@ -27,7 +27,9 @@ class Inbox { */ public static function register_routes() { \register_rest_route( - 'activitypub/1.0', '/inbox', array( + 'activitypub/1.0', + '/inbox', + array( array( 'methods' => \WP_REST_Server::EDITABLE, 'callback' => array( '\Activitypub\Rest\Inbox', 'shared_inbox_post' ), @@ -38,7 +40,9 @@ class Inbox { ); \register_rest_route( - 'activitypub/1.0', '/users/(?P\d+)/inbox', array( + 'activitypub/1.0', + '/users/(?P\d+)/inbox', + array( array( 'methods' => \WP_REST_Server::EDITABLE, 'callback' => array( '\Activitypub\Rest\Inbox', 'user_inbox_post' ), @@ -161,16 +165,20 @@ class Inbox { $users = self::extract_recipients( $data ); if ( ! $users ) { - return new \WP_Error( 'rest_invalid_param', \__( 'No recipients found', 'activitypub' ), array( - 'status' => 404, - 'params' => array( - 'to' => \__( 'Please check/validate "to" field', 'activitypub' ), - 'bto' => \__( 'Please check/validate "bto" field', 'activitypub' ), - 'cc' => \__( 'Please check/validate "cc" field', 'activitypub' ), - 'bcc' => \__( 'Please check/validate "bcc" field', 'activitypub' ), - 'audience' => \__( 'Please check/validate "audience" field', 'activitypub' ), - ), - ) ); + return new \WP_Error( + 'rest_invalid_param', + \__( 'No recipients found', 'activitypub' ), + array( + 'status' => 404, + 'params' => array( + 'to' => \__( 'Please check/validate "to" field', 'activitypub' ), + 'bto' => \__( 'Please check/validate "bto" field', 'activitypub' ), + 'cc' => \__( 'Please check/validate "cc" field', 'activitypub' ), + 'bcc' => \__( 'Please check/validate "bcc" field', 'activitypub' ), + 'audience' => \__( 'Please check/validate "audience" field', 'activitypub' ), + ), + ) + ); } foreach ( $users as $user ) { diff --git a/wp-content/plugins/activitypub/includes/rest/class-nodeinfo.php b/wp-content/plugins/activitypub/includes/rest/class-nodeinfo.php index acbc6aba..d4b394fa 100644 --- a/wp-content/plugins/activitypub/includes/rest/class-nodeinfo.php +++ b/wp-content/plugins/activitypub/includes/rest/class-nodeinfo.php @@ -23,7 +23,9 @@ class Nodeinfo { */ public static function register_routes() { \register_rest_route( - 'activitypub/1.0', '/nodeinfo/discovery', array( + 'activitypub/1.0', + '/nodeinfo/discovery', + array( array( 'methods' => \WP_REST_Server::READABLE, 'callback' => array( '\Activitypub\Rest\Nodeinfo', 'discovery' ), @@ -33,7 +35,9 @@ class Nodeinfo { ); \register_rest_route( - 'activitypub/1.0', '/nodeinfo', array( + 'activitypub/1.0', + '/nodeinfo', + array( array( 'methods' => \WP_REST_Server::READABLE, 'callback' => array( '\Activitypub\Rest\Nodeinfo', 'nodeinfo' ), @@ -43,7 +47,9 @@ class Nodeinfo { ); \register_rest_route( - 'activitypub/1.0', '/nodeinfo2', array( + 'activitypub/1.0', + '/nodeinfo2', + array( array( 'methods' => \WP_REST_Server::READABLE, 'callback' => array( '\Activitypub\Rest\Nodeinfo', 'nodeinfo2' ), diff --git a/wp-content/plugins/activitypub/includes/rest/class-ostatus.php b/wp-content/plugins/activitypub/includes/rest/class-ostatus.php index 4e4dda9b..45ff9010 100644 --- a/wp-content/plugins/activitypub/includes/rest/class-ostatus.php +++ b/wp-content/plugins/activitypub/includes/rest/class-ostatus.php @@ -14,7 +14,9 @@ class Ostatus { */ public static function register_routes() { \register_rest_route( - 'activitypub/1.0', '/ostatus/remote-follow', array( + 'activitypub/1.0', + '/ostatus/remote-follow', + array( array( 'methods' => \WP_REST_Server::READABLE, 'callback' => array( '\Activitypub\Rest\Ostatus', 'get' ), diff --git a/wp-content/plugins/activitypub/includes/rest/class-outbox.php b/wp-content/plugins/activitypub/includes/rest/class-outbox.php index fb1e7813..55bb5237 100644 --- a/wp-content/plugins/activitypub/includes/rest/class-outbox.php +++ b/wp-content/plugins/activitypub/includes/rest/class-outbox.php @@ -21,7 +21,9 @@ class Outbox { */ public static function register_routes() { \register_rest_route( - 'activitypub/1.0', '/users/(?P\d+)/outbox', array( + 'activitypub/1.0', + '/users/(?P\d+)/outbox', + array( array( 'methods' => \WP_REST_Server::READABLE, 'callback' => array( '\Activitypub\Rest\Outbox', 'user_outbox_get' ), @@ -43,12 +45,16 @@ class Outbox { $author = \get_user_by( 'ID', $user_id ); if ( ! $author ) { - return new \WP_Error( 'rest_invalid_param', \__( 'User not found', 'activitypub' ), array( - 'status' => 404, - 'params' => array( - 'user_id' => \__( 'User not found', 'activitypub' ), - ), - ) ); + return new \WP_Error( + 'rest_invalid_param', + \__( 'User not found', 'activitypub' ), + array( + 'status' => 404, + 'params' => array( + 'user_id' => \__( 'User not found', 'activitypub' ), + ), + ) + ); } $page = $request->get_param( 'page', 0 ); @@ -78,12 +84,14 @@ class Outbox { } if ( $page ) { - $posts = \get_posts( array( - 'posts_per_page' => 10, - 'author' => $user_id, - 'offset' => ( $page - 1 ) * 10, - 'post_type' => 'post', - ) ); + $posts = \get_posts( + array( + 'posts_per_page' => 10, + 'author' => $user_id, + 'offset' => ( $page - 1 ) * 10, + 'post_type' => 'post', + ) + ); foreach ( $posts as $post ) { $activitypub_post = new \Activitypub\Model\Post( $post ); diff --git a/wp-content/plugins/activitypub/includes/rest/class-webfinger.php b/wp-content/plugins/activitypub/includes/rest/class-webfinger.php index b5d3e4cb..60eb5d2f 100644 --- a/wp-content/plugins/activitypub/includes/rest/class-webfinger.php +++ b/wp-content/plugins/activitypub/includes/rest/class-webfinger.php @@ -22,7 +22,9 @@ class Webfinger { */ public static function register_routes() { \register_rest_route( - 'activitypub/1.0', '/webfinger', array( + 'activitypub/1.0', + '/webfinger', + array( array( 'methods' => \WP_REST_Server::READABLE, 'callback' => array( '\Activitypub\Rest\Webfinger', 'webfinger' ), @@ -42,15 +44,16 @@ class Webfinger { public static function webfinger( $request ) { $resource = $request->get_param( 'resource' ); - $matches = array(); - $matched = \preg_match( '/^acct:([^@]+)@(.+)$/', $resource, $matches ); + $matched = \str_contains( $resource, '@' ); if ( ! $matched ) { return new \WP_Error( 'activitypub_unsupported_resource', \__( 'Resource is invalid', 'activitypub' ), array( 'status' => 400 ) ); } - $resource_identifier = $matches[1]; - $resource_host = $matches[2]; + $resource = \str_replace( 'acct:', '', $resource ); + + $resource_identifier = \substr( $resource, 0, \strrpos( $resource, '@' ) ); + $resource_host = \substr( \strrchr( $resource, '@' ), 1 ); if ( \wp_parse_url( \home_url( '/' ), \PHP_URL_HOST ) !== $resource_host ) { return new \WP_Error( 'activitypub_wrong_host', \__( 'Resource host does not match blog host', 'activitypub' ), array( 'status' => 404 ) ); @@ -95,7 +98,7 @@ class Webfinger { $params['resource'] = array( 'required' => true, 'type' => 'string', - 'pattern' => '^acct:([^@]+)@(.+)$', + 'pattern' => '^acct:(.+)@(.+)$', ); return $params; diff --git a/wp-content/plugins/activitypub/readme.txt b/wp-content/plugins/activitypub/readme.txt index 244327cf..f2ec63f8 100644 --- a/wp-content/plugins/activitypub/readme.txt +++ b/wp-content/plugins/activitypub/readme.txt @@ -3,8 +3,8 @@ Contributors: pfefferle, mediaformat Donate link: https://notiz.blog/donate/ Tags: OStatus, fediverse, activitypub, activitystream Requires at least: 4.7 -Tested up to: 5.9 -Stable tag: 0.13.3 +Tested up to: 6.0 +Stable tag: 0.13.4 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.4 = + +* fix webfinger for email identifiers + = 0.13.3 = * fix: Create and Note should not have the same ActivityPub ID