From ae26609e5ea679d28f89bcedfb1bd91c330d0093 Mon Sep 17 00:00:00 2001 From: Matthias Pfefferle Date: Wed, 13 Dec 2023 11:33:34 +0100 Subject: [PATCH 1/9] update FAQ --- README.md | 2 +- readme.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e83f274..ed1bda8 100644 --- a/README.md +++ b/README.md @@ -68,10 +68,10 @@ Implemented: * share posts * receive comments/reactions * signature verification +* threaded comments support To implement: -* threaded comments support * replace shortcodes with blocks for layout ### What is "ActivityPub for WordPress" ### diff --git a/readme.txt b/readme.txt index 40f210a..93885ae 100644 --- a/readme.txt +++ b/readme.txt @@ -68,10 +68,10 @@ Implemented: * share posts * receive comments/reactions * signature verification +* threaded comments support To implement: -* threaded comments support * replace shortcodes with blocks for layout = What is "ActivityPub for WordPress" = From 97e2bbfe7a1d92111c163e6f5c3636fe7474844c Mon Sep 17 00:00:00 2001 From: Matthias Pfefferle Date: Fri, 15 Dec 2023 07:45:11 +0100 Subject: [PATCH 2/9] remove systems cron warning fix #525 --- includes/class-health-check.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/includes/class-health-check.php b/includes/class-health-check.php index 74a6f9e..22d95f2 100644 --- a/includes/class-health-check.php +++ b/includes/class-health-check.php @@ -39,11 +39,6 @@ class Health_Check { 'test' => array( self::class, 'test_webfinger' ), ); - $tests['direct']['activitypub_test_system_cron'] = array( - 'label' => __( 'System Cron Test', 'activitypub' ), - 'test' => array( self::class, 'test_system_cron' ), - ); - return $tests; } From a47c9cd7aeb923298cc9301ec698f725399cd54b Mon Sep 17 00:00:00 2001 From: Kan-Ru Chen Date: Sat, 16 Dec 2023 15:36:45 +0900 Subject: [PATCH 3/9] replace `excerpt_more` with custom filter `activitypub_excerpt_more` for better consistency (#610) --- includes/class-shortcodes.php | 3 +-- tests/test-class-activitypub-shortcodes.php | 30 +++++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/includes/class-shortcodes.php b/includes/class-shortcodes.php index 491a6ad..922c10d 100644 --- a/includes/class-shortcodes.php +++ b/includes/class-shortcodes.php @@ -127,8 +127,7 @@ class Shortcodes { // Strip out any remaining tags. $excerpt = \wp_strip_all_tags( $excerpt ); - /** This filter is documented in wp-includes/formatting.php */ - $excerpt_more = \apply_filters( 'excerpt_more', ' [...]' ); + $excerpt_more = \apply_filters( 'activitypub_excerpt_more', ' […]' ); $excerpt_more_len = strlen( $excerpt_more ); // We now have a excerpt, but we need to check it's length, it may be longer than we want for two reasons: diff --git a/tests/test-class-activitypub-shortcodes.php b/tests/test-class-activitypub-shortcodes.php index b1413e8..7b592e0 100644 --- a/tests/test-class-activitypub-shortcodes.php +++ b/tests/test-class-activitypub-shortcodes.php @@ -62,4 +62,34 @@ class Test_Activitypub_Shortcodes extends WP_UnitTestCase { $this->assertEquals( '', $content ); Shortcodes::unregister(); } + + public function test_excerpt() { + Shortcodes::register(); + global $post; + + $post_id = -97; // negative ID, to avoid clash with a valid post + $post = new stdClass(); + $post->ID = $post_id; + $post->post_author = 1; + $post->post_date = current_time( 'mysql' ); + $post->post_date_gmt = current_time( 'mysql', 1 ); + $post->post_title = 'Some title or other'; + $post->post_content = 'Lorem ipsum dolor sit amet, consectetur.'; + $post->post_status = 'publish'; + $post->comment_status = 'closed'; + $post->ping_status = 'closed'; + $post->post_name = 'fake-page-' . rand( 1, 99999 ); // append random number to avoid clash + $post->post_type = 'page'; + $post->filter = 'raw'; // important! + + $content = '[ap_excerpt length="25"]'; + + // Fill in the shortcodes. + setup_postdata( $post ); + $content = do_shortcode( $content ); + wp_reset_postdata(); + + $this->assertEquals( "

Lorem ipsum […]

\n", $content ); + Shortcodes::unregister(); + } } From 39c9288987c10f83c3273382bcaaae485f6f499b Mon Sep 17 00:00:00 2001 From: Matthias Pfefferle Date: Thu, 21 Dec 2023 10:04:15 +0100 Subject: [PATCH 4/9] Improve/webfinger (#616) * Fix some WebFinger issues * update changelog --- README.md | 3 ++- includes/model/class-application-user.php | 9 +++++++++ includes/model/class-blog-user.php | 8 ++++---- includes/model/class-user.php | 4 ++-- includes/rest/class-webfinger.php | 5 ++++- integration/class-webfinger.php | 9 +++++++-- readme.txt | 3 ++- 7 files changed, 30 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index ed1bda8..73223e4 100644 --- a/README.md +++ b/README.md @@ -111,7 +111,8 @@ Project maintained on GitHub at [automattic/wordpress-activitypub](https://githu * Fixed: Normalize attributes that can have mixed value types * Added: URL support for WebFinger * Added: Make Post-Template filterable -* Addes: CSS class for ActivityPub comments to allow custom designs +* Added: CSS class for ActivityPub comments to allow custom designs +* Improved: WebFinger endpoints ### 1.3.0 ### diff --git a/includes/model/class-application-user.php b/includes/model/class-application-user.php index cf4d9cc..c9faded 100644 --- a/includes/model/class-application-user.php +++ b/includes/model/class-application-user.php @@ -38,6 +38,15 @@ class Application_User extends Blog_User { return get_rest_url_by_path( 'application' ); } + /** + * Returns the User-URL with @-Prefix for the username. + * + * @return string The User-URL with @-Prefix for the username. + */ + public function get_alternate_url() { + return \esc_url( \trailingslashit( get_home_url() ) . '@' . $this->get_preferred_username() ); + } + public function get_name() { return 'application'; } diff --git a/includes/model/class-blog-user.php b/includes/model/class-blog-user.php index 21a066e..53f07d4 100644 --- a/includes/model/class-blog-user.php +++ b/includes/model/class-blog-user.php @@ -100,12 +100,12 @@ class Blog_User extends User { } /** - * Returns the User-URL with @-Prefix for the username. + * Get blog's homepage URL. * - * @return string The User-URL with @-Prefix for the username. + * @return string The User-Url. */ - public function get_at_url() { - return \esc_url( \trailingslashit( get_home_url() ) . '@' . $this->get_preferred_username() ); + public function get_alternate_url() { + return \esc_url( \trailingslashit( get_home_url() ) ); } /** diff --git a/includes/model/class-user.php b/includes/model/class-user.php index 95c83d7..c713434 100644 --- a/includes/model/class-user.php +++ b/includes/model/class-user.php @@ -135,8 +135,8 @@ class User extends Actor { * * @return string The User-URL with @-Prefix for the username. */ - public function get_at_url() { - return \esc_url( \trailingslashit( get_home_url() ) . '@' . $this->get_username() ); + public function get_alternate_url() { + return \esc_url( \trailingslashit( get_home_url() ) . '@' . $this->get_preferred_username() ); } public function get_preferred_username() { diff --git a/includes/rest/class-webfinger.php b/includes/rest/class-webfinger.php index 52abd9f..765044b 100644 --- a/includes/rest/class-webfinger.php +++ b/includes/rest/class-webfinger.php @@ -94,10 +94,13 @@ class Webfinger { $aliases = array( $user->get_url(), + $user->get_alternate_url(), ); + $aliases = array_unique( $aliases ); + $profile = array( - 'subject' => $resource, + 'subject' => sprintf( 'acct:%s', $user->get_resource() ), 'aliases' => array_values( array_unique( $aliases ) ), 'links' => array( array( diff --git a/integration/class-webfinger.php b/integration/class-webfinger.php index 6b3b6dd..e5fdd5d 100644 --- a/integration/class-webfinger.php +++ b/integration/class-webfinger.php @@ -14,8 +14,8 @@ class Webfinger { * Initialize the class, registering WordPress hooks */ public static function init() { - \add_filter( 'webfinger_user_data', array( self::class, 'add_user_discovery' ), 10, 3 ); - \add_filter( 'webfinger_data', array( self::class, 'add_pseudo_user_discovery' ), 99, 2 ); + \add_filter( 'webfinger_user_data', array( self::class, 'add_user_discovery' ), 1, 3 ); + \add_filter( 'webfinger_data', array( self::class, 'add_pseudo_user_discovery' ), 1, 2 ); } /** @@ -34,6 +34,11 @@ class Webfinger { return $array; } + $array['subject'] = sprintf( 'acct:%s', $user->get_resource() ); + + $array['aliases'][] = $user->get_url(); + $array['aliases'][] = $user->get_alternate_url(); + $array['links'][] = array( 'rel' => 'self', 'type' => 'application/activity+json', diff --git a/readme.txt b/readme.txt index 93885ae..e0797d2 100644 --- a/readme.txt +++ b/readme.txt @@ -111,7 +111,8 @@ Project maintained on GitHub at [automattic/wordpress-activitypub](https://githu * Fixed: Normalize attributes that can have mixed value types * Added: URL support for WebFinger * Added: Make Post-Template filterable -* Addes: CSS class for ActivityPub comments to allow custom designs +* Added: CSS class for ActivityPub comments to allow custom designs +* Improved: WebFinger endpoints = 1.3.0 = From 6f1a9a1f7fb957d6989316ea7a6f3d418cc8db82 Mon Sep 17 00:00:00 2001 From: Matthias Pfefferle Date: Thu, 21 Dec 2023 10:06:37 +0100 Subject: [PATCH 5/9] added FEP-2677 (#613) * added FEP-2677 This PR enables [FEP-2677: Identifying the Application Actor](https://codeberg.org/fediverse/fep/src/branch/main/fep/2677/fep-2677.md) @Menrath I needed a small task for in between ;) * update changelog --- FEDERATION.md | 1 + README.md | 1 + includes/rest/class-nodeinfo.php | 4 ++++ integration/class-nodeinfo.php | 27 +++++++++++++++++++++++---- readme.txt | 1 + 5 files changed, 30 insertions(+), 4 deletions(-) diff --git a/FEDERATION.md b/FEDERATION.md index 078fef4..831d5af 100644 --- a/FEDERATION.md +++ b/FEDERATION.md @@ -14,6 +14,7 @@ The WordPress plugin largely follows ActivityPub's server-to-server specificatio - [FEP-f1d5: NodeInfo in Fediverse Software](https://codeberg.org/fediverse/fep/src/branch/main/fep/f1d5/fep-f1d5.md) - [FEP-67ff: FEDERATION.md](https://codeberg.org/fediverse/fep/src/branch/main/fep/67ff/fep-67ff.md) - [FEP-5feb: Search indexing consent for actors](https://codeberg.org/fediverse/fep/src/branch/main/fep/5feb/fep-5feb.md) +- [FEP-2677: Identifying the Application Actor](https://codeberg.org/fediverse/fep/src/branch/main/fep/2677/fep-2677.md) Partially supported FEPs diff --git a/README.md b/README.md index 73223e4..7947c21 100644 --- a/README.md +++ b/README.md @@ -112,6 +112,7 @@ Project maintained on GitHub at [automattic/wordpress-activitypub](https://githu * Added: URL support for WebFinger * Added: Make Post-Template filterable * Added: CSS class for ActivityPub comments to allow custom designs +* Added: FEP-2677: Identifying the Application Actor * Improved: WebFinger endpoints ### 1.3.0 ### diff --git a/includes/rest/class-nodeinfo.php b/includes/rest/class-nodeinfo.php index 62151ff..7f1f094 100644 --- a/includes/rest/class-nodeinfo.php +++ b/includes/rest/class-nodeinfo.php @@ -169,6 +169,10 @@ class Nodeinfo { 'rel' => 'http://nodeinfo.diaspora.software/ns/schema/2.0', 'href' => get_rest_url_by_path( 'nodeinfo' ), ), + array( + 'rel' => 'https://www.w3.org/ns/activitystreams#Application', + 'href' => get_rest_url_by_path( 'application' ), + ), ); return new \WP_REST_Response( $discovery, 200 ); diff --git a/integration/class-nodeinfo.php b/integration/class-nodeinfo.php index dea6c67..59492c1 100644 --- a/integration/class-nodeinfo.php +++ b/integration/class-nodeinfo.php @@ -3,6 +3,7 @@ namespace Activitypub\Integration; use function Activitypub\get_total_users; use function Activitypub\get_active_users; +use function Activitypub\get_rest_url_by_path; /** * Compatibility with the NodeInfo plugin @@ -14,8 +15,10 @@ class Nodeinfo { * Initialize the class, registering WordPress hooks */ public static function init() { - \add_filter( 'nodeinfo_data', array( self::class, 'add_nodeinfo_discovery' ), 10, 2 ); - \add_filter( 'nodeinfo2_data', array( self::class, 'add_nodeinfo2_discovery' ), 10 ); + \add_filter( 'nodeinfo_data', array( self::class, 'add_nodeinfo_data' ), 10, 2 ); + \add_filter( 'nodeinfo2_data', array( self::class, 'add_nodeinfo2_data' ), 10 ); + + \add_filter( 'wellknown_nodeinfo_data', array( self::class, 'add_wellknown_nodeinfo_data' ), 10, 2 ); } /** @@ -26,7 +29,7 @@ class Nodeinfo { * * @return array The extended array */ - public static function add_nodeinfo_discovery( $nodeinfo, $version ) { + public static function nodeinfo_data( $nodeinfo, $version ) { if ( $version >= '2.0' ) { $nodeinfo['protocols'][] = 'activitypub'; } else { @@ -50,7 +53,7 @@ class Nodeinfo { * * @return array The extended array */ - public static function add_nodeinfo2_discovery( $nodeinfo ) { + public static function nodeinfo2_data( $nodeinfo ) { $nodeinfo['protocols'][] = 'activitypub'; $nodeinfo['usage']['users'] = array( @@ -61,4 +64,20 @@ class Nodeinfo { return $nodeinfo; } + + /** + * Extend the well-known nodeinfo data + * + * @param array $data The well-known nodeinfo data + * + * @return array The extended array + */ + public static function add_wellknown_nodeinfo_data( $data ) { + $data['links'][] = array( + 'rel' => 'https://www.w3.org/ns/activitystreams#Application', + 'href' => get_rest_url_by_path( 'application' ), + ); + + return $data; + } } diff --git a/readme.txt b/readme.txt index e0797d2..c15b43f 100644 --- a/readme.txt +++ b/readme.txt @@ -112,6 +112,7 @@ Project maintained on GitHub at [automattic/wordpress-activitypub](https://githu * Added: URL support for WebFinger * Added: Make Post-Template filterable * Added: CSS class for ActivityPub comments to allow custom designs +* Added: FEP-2677: Identifying the Application Actor * Improved: WebFinger endpoints = 1.3.0 = From f4cab6647d9c61178a55cb3b1b81421605827ae2 Mon Sep 17 00:00:00 2001 From: Matthias Pfefferle Date: Thu, 21 Dec 2023 10:10:55 +0100 Subject: [PATCH 6/9] fix application user --- includes/model/class-application-user.php | 4 ++++ includes/rest/class-webfinger.php | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/includes/model/class-application-user.php b/includes/model/class-application-user.php index c9faded..8fb4ee6 100644 --- a/includes/model/class-application-user.php +++ b/includes/model/class-application-user.php @@ -78,4 +78,8 @@ class Application_User extends Blog_User { public function get_indexable() { return false; } + + public function get_type() { + return $this->type; + } } diff --git a/includes/rest/class-webfinger.php b/includes/rest/class-webfinger.php index 765044b..fac408e 100644 --- a/includes/rest/class-webfinger.php +++ b/includes/rest/class-webfinger.php @@ -116,9 +116,9 @@ class Webfinger { ), ); - if ( 'Group' === $user->get_type() ) { + if ( 'Person' !== $user->get_type() ) { $profile['links'][0]['properties'] = array( - 'https://www.w3.org/ns/activitystreams#type' => 'Group', + 'https://www.w3.org/ns/activitystreams#type' => $user->get_type(), ); } From 5ce8f28852ba3cc806c793d1662578131ebf61f4 Mon Sep 17 00:00:00 2001 From: Matthias Pfefferle Date: Thu, 21 Dec 2023 15:19:18 +0100 Subject: [PATCH 7/9] fix nodeinfo integration --- integration/class-nodeinfo.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/integration/class-nodeinfo.php b/integration/class-nodeinfo.php index 59492c1..02f3a64 100644 --- a/integration/class-nodeinfo.php +++ b/integration/class-nodeinfo.php @@ -29,7 +29,7 @@ class Nodeinfo { * * @return array The extended array */ - public static function nodeinfo_data( $nodeinfo, $version ) { + public static function add_nodeinfo_data( $nodeinfo, $version ) { if ( $version >= '2.0' ) { $nodeinfo['protocols'][] = 'activitypub'; } else { @@ -53,7 +53,7 @@ class Nodeinfo { * * @return array The extended array */ - public static function nodeinfo2_data( $nodeinfo ) { + public static function add_nodeinfo2_data( $nodeinfo ) { $nodeinfo['protocols'][] = 'activitypub'; $nodeinfo['usage']['users'] = array( From 45e6ace890ed4cad7c74f30a24f09171515bb245 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Menrath?= <99024746+Menrath@users.noreply.github.com> Date: Thu, 21 Dec 2023 16:05:32 +0100 Subject: [PATCH 8/9] Add nodeinfo metadata (#618) * add nodeinfo metadata nodeName, nodeDescription and nodeIcon * Fix CS: double space typo --- includes/rest/class-nodeinfo.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/includes/rest/class-nodeinfo.php b/includes/rest/class-nodeinfo.php index 7f1f094..0c49026 100644 --- a/includes/rest/class-nodeinfo.php +++ b/includes/rest/class-nodeinfo.php @@ -105,6 +105,12 @@ class Nodeinfo { 'outbound' => array(), ); + $nodeinfo['metadata'] = array( + 'nodeName' => \get_bloginfo( 'name' ), + 'nodeDescription' => \get_bloginfo( 'description' ), + 'nodeIcon' => \get_site_icon_url(), + ); + return new WP_REST_Response( $nodeinfo, 200 ); } From a3ea9955d98c93999f3a5572ce293b9ee35addaf Mon Sep 17 00:00:00 2001 From: Matthias Pfefferle Date: Thu, 21 Dec 2023 17:27:43 +0100 Subject: [PATCH 9/9] fix issue with wrong object init! --- includes/activity/class-activity.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/activity/class-activity.php b/includes/activity/class-activity.php index 96ee095..68caa34 100644 --- a/includes/activity/class-activity.php +++ b/includes/activity/class-activity.php @@ -196,7 +196,7 @@ class Activity extends Base_Object { public function set_object( $object ) { // convert array to object if ( is_array( $object ) ) { - $object = Base_Object::init_from_array( $object ); + $object = self::init_from_array( $object ); } // set object