From 24648d6d7466cc1a68a07d979988780af4066be0 Mon Sep 17 00:00:00 2001 From: Matthias Pfefferle Date: Tue, 31 Jan 2023 09:56:48 +0100 Subject: [PATCH 1/9] fix server config See: https://wordpress.org/support/topic/jetpack-conflict-15/ --- activitypub.php | 10 +--------- includes/rest/class-server.php | 35 ---------------------------------- 2 files changed, 1 insertion(+), 44 deletions(-) delete mode 100644 includes/rest/class-server.php diff --git a/activitypub.php b/activitypub.php index 4d1abb1..cc07f5d 100644 --- a/activitypub.php +++ b/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.15.0 + * Version: 0.16.0 * Author: Matthias Pfefferle * Author URI: https://notiz.blog/ * License: MIT @@ -84,14 +84,6 @@ function init() { require_once \dirname( __FILE__ ) . '/includes/class-health-check.php'; \Activitypub\Health_Check::init(); - require_once \dirname( __FILE__ ) . '/includes/rest/class-server.php'; - \add_filter( - 'wp_rest_server_class', - function() { - return '\Activitypub\Rest\Server'; - } - ); - if ( \WP_DEBUG ) { require_once \dirname( __FILE__ ) . '/includes/debug.php'; } diff --git a/includes/rest/class-server.php b/includes/rest/class-server.php deleted file mode 100644 index ac89dca..0000000 --- a/includes/rest/class-server.php +++ /dev/null @@ -1,35 +0,0 @@ -get_content_type(); - - if ( ! $content_type ) { - return parent::dispatch( $request ); - } - - // check for content-sub-types like 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"' - if ( \preg_match( '/application\/([a-zA-Z+_-]+\+)json/', $content_type['value'] ) ) { - $request->set_header( 'Content-Type', 'application/json' ); - } - - // make request filterable - $request = \apply_filters( 'activitypub_pre_dispatch_request', $request ); - - return parent::dispatch( $request ); - } -} From 9902479cfd11a9193bc6f5c8ce9b8ba1b6cfe1da Mon Sep 17 00:00:00 2001 From: Matthias Pfefferle Date: Tue, 31 Jan 2023 09:57:00 +0100 Subject: [PATCH 2/9] update readme --- README.md | 8 ++++++-- readme.txt | 7 +++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 65d73c5..9a6d258 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ **Tags:** OStatus, fediverse, activitypub, activitystream **Requires at least:** 4.7 **Tested up to:** 6.1 -**Stable tag:** 0.15.0 +**Stable tag:** 0.16.0 **Requires PHP:** 5.6 **License:** MIT **License URI:** http://opensource.org/licenses/MIT @@ -88,9 +88,13 @@ 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). -### v.next ### +### 0.16.0 ### +* Add "Outgoing Mentions" ([#213](https://github.com/pfefferle/wordpress-activitypub/pull/213)) props [@akirk](https://github.com/akirk) * Add configuration item for number of images to attach. props [@mexon](https://github.com/mexon) +* Use shortcodes instead of custom templates, to setup the Activity Post-Content. props [@toolstack](https://github.com/toolstack) +* Remove custom REST Server, because the needed changes are now merged into Core. +* Fix hashtags. props [@akirk](https://github.com/akirk) ### 0.15.0 ### diff --git a/readme.txt b/readme.txt index e889ce9..65f02b3 100644 --- a/readme.txt +++ b/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: 6.1 -Stable tag: 0.15.0 +Stable tag: 0.16.0 Requires PHP: 5.6 License: MIT License URI: http://opensource.org/licenses/MIT @@ -88,10 +88,13 @@ 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). -= v.next = += 0.16.0 = +* Add "Outgoing Mentions" ([#213](https://github.com/pfefferle/wordpress-activitypub/pull/213)) props [@akirk](https://github.com/akirk) * Add configuration item for number of images to attach. props [@mexon](https://github.com/mexon) * Use shortcodes instead of custom templates, to setup the Activity Post-Content. props [@toolstack](https://github.com/toolstack) +* Remove custom REST Server, because the needed changes are now merged into Core. +* Fix hashtags. props [@akirk](https://github.com/akirk) = 0.15.0 = From 62f0c9a1bfa906003f0d7ede31bdec4302d98118 Mon Sep 17 00:00:00 2001 From: Matthias Pfefferle Date: Tue, 31 Jan 2023 17:12:30 +0100 Subject: [PATCH 3/9] updated readme --- README.md | 7 ++++--- readme.txt | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 9a6d258..1e405f8 100644 --- a/README.md +++ b/README.md @@ -91,10 +91,11 @@ Project maintained on GitHub at [pfefferle/wordpress-activitypub](https://github ### 0.16.0 ### * Add "Outgoing Mentions" ([#213](https://github.com/pfefferle/wordpress-activitypub/pull/213)) props [@akirk](https://github.com/akirk) -* Add configuration item for number of images to attach. props [@mexon](https://github.com/mexon) -* Use shortcodes instead of custom templates, to setup the Activity Post-Content. props [@toolstack](https://github.com/toolstack) +* Add configuration item for number of images to attach ([#248](https://github.com/pfefferle/wordpress-activitypub/pull/248)) props [@mexon](https://github.com/mexon) +* Use shortcodes instead of custom templates, to setup the Activity Post-Content ([#250](https://github.com/pfefferle/wordpress-activitypub/pull/250)) props [@toolstack](https://github.com/toolstack) * Remove custom REST Server, because the needed changes are now merged into Core. -* Fix hashtags. props [@akirk](https://github.com/akirk) +* Fix hashtags ([#261](https://github.com/pfefferle/wordpress-activitypub/pull/261)) props [@akirk](https://github.com/akirk) +* Change priorites, to maybe fix the hashtag issue ### 0.15.0 ### diff --git a/readme.txt b/readme.txt index 65f02b3..cb22943 100644 --- a/readme.txt +++ b/readme.txt @@ -91,10 +91,11 @@ Project maintained on GitHub at [pfefferle/wordpress-activitypub](https://github = 0.16.0 = * Add "Outgoing Mentions" ([#213](https://github.com/pfefferle/wordpress-activitypub/pull/213)) props [@akirk](https://github.com/akirk) -* Add configuration item for number of images to attach. props [@mexon](https://github.com/mexon) -* Use shortcodes instead of custom templates, to setup the Activity Post-Content. props [@toolstack](https://github.com/toolstack) +* Add configuration item for number of images to attach ([#248](https://github.com/pfefferle/wordpress-activitypub/pull/248)) props [@mexon](https://github.com/mexon) +* Use shortcodes instead of custom templates, to setup the Activity Post-Content ([#250](https://github.com/pfefferle/wordpress-activitypub/pull/250)) props [@toolstack](https://github.com/toolstack) * Remove custom REST Server, because the needed changes are now merged into Core. -* Fix hashtags. props [@akirk](https://github.com/akirk) +* Fix hashtags ([#261](https://github.com/pfefferle/wordpress-activitypub/pull/261)) props [@akirk](https://github.com/akirk) +* Change priorites, to maybe fix the hashtag issue = 0.15.0 = From 75881038f80cc17caa20ea58601c087043096dba Mon Sep 17 00:00:00 2001 From: Matthias Pfefferle Date: Tue, 31 Jan 2023 18:42:52 +0100 Subject: [PATCH 4/9] ignore docker files --- .distignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.distignore b/.distignore index 93fbfdb..782f2e8 100644 --- a/.distignore +++ b/.distignore @@ -22,6 +22,8 @@ bin composer.json composer.lock docker-compose.yml +docker-compose-test.yml +Dockerfile gulpfile.js package.json node_modules From bc8cb19c5df1a6092bb5020df6210dbe627d15bf Mon Sep 17 00:00:00 2001 From: Matthias Pfefferle Date: Tue, 31 Jan 2023 18:43:11 +0100 Subject: [PATCH 5/9] add an option to disable content filters --- includes/class-shortcodes.php | 16 +++++++++++++++- includes/help.php | 8 ++++---- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/includes/class-shortcodes.php b/includes/class-shortcodes.php index b7243d5..b6fc4ad 100644 --- a/includes/class-shortcodes.php +++ b/includes/class-shortcodes.php @@ -191,9 +191,23 @@ class Shortcodes { return ''; } + $atts = shortcode_atts( + array( 'apply_filters' => 'yes' ), + $atts, + $tag + ); + $content = \get_post_field( 'post_content', $post ); - return \apply_filters( 'the_content', $content ); + if ( 'yes' === $atts['apply_filters'] ) { + $content = \apply_filters( 'the_content', $content ); + } else { + $content = do_blocks( $content ); + $content = wptexturize( $content ); + $content = wp_filter_content_tags( $content ); + } + + return $content; } /** diff --git a/includes/help.php b/includes/help.php index 6039b9f..58339fb 100644 --- a/includes/help.php +++ b/includes/help.php @@ -9,14 +9,14 @@ '
' . '
[ap_title]
' . '
' . \wp_kses( __( 'The post\'s title.', 'activitypub' ), 'default' ) . '
' . - '
[ap_content]
' . - '
' . \wp_kses( __( 'The post\'s content.', 'activitypub' ), 'default' ) . '
' . + '
[ap_content apply_filters="yes"]
' . + '
' . \wp_kses( __( 'The post\'s content. With apply_filters you can decide if filters should be applied or not (default is yes). The values can be yes or no. apply_filters attribute is optional.', 'activitypub' ), 'default' ) . '
' . '
[ap_excerpt lenght="400"]
' . '
' . \wp_kses( __( 'The post\'s excerpt (default 400 chars). length attribute is optional.', 'activitypub' ), 'default' ) . '
' . '
[ap_permalink type="url"]
' . - '
' . \wp_kses( __( 'The post\'s permalink. Type can be either: url or html (an <a /> tag). type attribute is optional.', 'activitypub' ), 'default' ) . '
' . + '
' . \wp_kses( __( 'The post\'s permalink. type can be either: url or html (an <a /> tag). type attribute is optional.', 'activitypub' ), 'default' ) . '
' . '
[ap_shortlink type="url"]
' . - '
' . \wp_kses( __( 'The post\'s shortlink. Type can be either url or html (an <a /> tag). I can recommend Hum, to prettify the Shortlinks. type attribute is optional.', 'activitypub' ), 'default' ) . '
' . + '
' . \wp_kses( __( 'The post\'s shortlink. type can be either url or html (an <a /> tag). I can recommend Hum, to prettify the Shortlinks. type attribute is optional.', 'activitypub' ), 'default' ) . '
' . '
[ap_hashtags]
' . '
' . \wp_kses( __( 'The post\'s tags as hashtags.', 'activitypub' ), 'default' ) . '
' . '
[ap_hashcats]
' . From d4b1edcf39d255582d2b99498e03910ec22ab8b3 Mon Sep 17 00:00:00 2001 From: Matthias Pfefferle Date: Wed, 1 Feb 2023 00:13:55 +0100 Subject: [PATCH 6/9] fix update and delete dispatcher --- includes/class-activity-dispatcher.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/class-activity-dispatcher.php b/includes/class-activity-dispatcher.php index cf88231..f8abd38 100644 --- a/includes/class-activity-dispatcher.php +++ b/includes/class-activity-dispatcher.php @@ -67,7 +67,7 @@ class Activity_Dispatcher { $user_id = $activitypub_post->get_post_author(); $activitypub_activity = new \Activitypub\Model\Activity( 'Update', \Activitypub\Model\Activity::TYPE_FULL ); - $activitypub_activity->from_post( $activitypub_post->to_array() ); + $activitypub_activity->from_post( $activitypub_post ); foreach ( \Activitypub\get_follower_inboxes( $user_id ) as $inbox => $to ) { $activitypub_activity->set_to( $to ); @@ -87,7 +87,7 @@ class Activity_Dispatcher { $user_id = $activitypub_post->get_post_author(); $activitypub_activity = new \Activitypub\Model\Activity( 'Delete', \Activitypub\Model\Activity::TYPE_FULL ); - $activitypub_activity->from_post( $activitypub_post->to_array() ); + $activitypub_activity->from_post( $activitypub_post ); foreach ( \Activitypub\get_follower_inboxes( $user_id ) as $inbox => $to ) { $activitypub_activity->set_to( $to ); From 531bdc17b034ed1948e4f1e611f5af4933449509 Mon Sep 17 00:00:00 2001 From: Matthias Pfefferle Date: Thu, 2 Feb 2023 08:18:10 +0100 Subject: [PATCH 7/9] fix #266 --- README.md | 6 +++- activitypub.php | 2 +- includes/model/class-post.php | 32 +++---------------- readme.txt | 6 +++- ...-class-activitypub-activity-dispatcher.php | 4 +++ 5 files changed, 20 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index 1e405f8..a8a8001 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ **Tags:** OStatus, fediverse, activitypub, activitystream **Requires at least:** 4.7 **Tested up to:** 6.1 -**Stable tag:** 0.16.0 +**Stable tag:** 0.16.1 **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.16.1 ### + +* Fix "update and create, posts appear blank on Mastodon" issue + ### 0.16.0 ### * Add "Outgoing Mentions" ([#213](https://github.com/pfefferle/wordpress-activitypub/pull/213)) props [@akirk](https://github.com/akirk) diff --git a/activitypub.php b/activitypub.php index cc07f5d..b659520 100644 --- a/activitypub.php +++ b/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.16.0 + * Version: 0.16.1 * Author: Matthias Pfefferle * Author URI: https://notiz.blog/ * License: MIT diff --git a/includes/model/class-post.php b/includes/model/class-post.php index 543a890..ed7f453 100644 --- a/includes/model/class-post.php +++ b/includes/model/class-post.php @@ -369,11 +369,14 @@ class Post { * @return string the content */ public function get_content() { + global $post; + if ( $this->content ) { return $this->content; } - $post = $this->post; + // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited + $post = $this->post; $content = $this->get_post_content_template(); // Fill in the shortcodes. @@ -386,7 +389,7 @@ class Post { $filtered_content = \apply_filters( 'activitypub_the_content', $content, $post ); $decoded_content = \html_entity_decode( $filtered_content, \ENT_QUOTES, 'UTF-8' ); - $content = \trim( \preg_replace( '/[\n\r]/', '', $content ) ); + $content = \trim( \preg_replace( '/[\n\r\t]/', '', $content ) ); $this->content = $content; @@ -455,29 +458,4 @@ class Post { return $content; } - - /** - * Adds all tags as hashtags to the post/summary content - * - * @param string $content - * @param WP_Post $post - * - * @return string - */ - public function get_the_mentions() { - $post = $this->post; - $tags = \get_the_tags( $post->ID ); - - if ( ! $tags ) { - return ''; - } - - $hash_tags = array(); - - foreach ( $tags as $tag ) { - $hash_tags[] = \sprintf( '', \get_tag_link( $tag ), $tag->slug ); - } - - return \implode( ' ', $hash_tags ); - } } diff --git a/readme.txt b/readme.txt index cb22943..4e729ef 100644 --- a/readme.txt +++ b/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: 6.1 -Stable tag: 0.16.0 +Stable tag: 0.16.1 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.16.1 = + +* Fix "update and create, posts appear blank on Mastodon" issue + = 0.16.0 = * Add "Outgoing Mentions" ([#213](https://github.com/pfefferle/wordpress-activitypub/pull/213)) props [@akirk](https://github.com/akirk) diff --git a/tests/test-class-activitypub-activity-dispatcher.php b/tests/test-class-activitypub-activity-dispatcher.php index 6693ba1..dea7e38 100644 --- a/tests/test-class-activitypub-activity-dispatcher.php +++ b/tests/test-class-activitypub-activity-dispatcher.php @@ -30,6 +30,8 @@ class Test_Activitypub_Activity_Dispatcher extends ActivityPub_TestCase_Cache_HT $activitypub_post = new \Activitypub\Model\Post( $post ); \Activitypub\Activity_Dispatcher::send_post_activity( $activitypub_post ); + $this->assertNotEmpty( $activitypub_post->get_content() ); + $this->assertSame( 2, $pre_http_request->get_call_count() ); $all_args = $pre_http_request->get_args(); $first_call_args = array_shift( $all_args ); @@ -69,6 +71,8 @@ class Test_Activitypub_Activity_Dispatcher extends ActivityPub_TestCase_Cache_HT $activitypub_post = new \Activitypub\Model\Post( $post ); \Activitypub\Activity_Dispatcher::send_post_activity( $activitypub_post ); + $this->assertNotEmpty( $activitypub_post->get_content() ); + $this->assertSame( 1, $pre_http_request->get_call_count() ); $all_args = $pre_http_request->get_args(); $first_call_args = $all_args[0]; From 70859212d6d3d3ec757a17fc85a59ea6609679fc Mon Sep 17 00:00:00 2001 From: Matthias Pfefferle Date: Thu, 2 Feb 2023 08:50:17 +0100 Subject: [PATCH 8/9] fix #196 --- includes/model/class-post.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/model/class-post.php b/includes/model/class-post.php index ed7f453..5546c88 100644 --- a/includes/model/class-post.php +++ b/includes/model/class-post.php @@ -144,7 +144,7 @@ class Post { 'tag' => $this->get_tags(), ); - return \apply_filters( 'activitypub_post', $array ); + return \apply_filters( 'activitypub_post', $array, $this->post ); } /** From c89d8f2265dc3589f8ab0968ca11b4642aa80bd2 Mon Sep 17 00:00:00 2001 From: Matthias Pfefferle Date: Thu, 2 Feb 2023 18:13:21 +0100 Subject: [PATCH 9/9] fix #269 --- README.md | 6 +++++- activitypub.php | 2 +- includes/rest/class-outbox.php | 2 +- readme.txt | 6 +++++- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index a8a8001..9de8b8f 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ **Tags:** OStatus, fediverse, activitypub, activitystream **Requires at least:** 4.7 **Tested up to:** 6.1 -**Stable tag:** 0.16.1 +**Stable tag:** 0.16.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.16.2 ### + +* Fix fatal error in outbox + ### 0.16.1 ### * Fix "update and create, posts appear blank on Mastodon" issue diff --git a/activitypub.php b/activitypub.php index b659520..d30bf3f 100644 --- a/activitypub.php +++ b/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.16.1 + * Version: 0.16.2 * Author: Matthias Pfefferle * Author URI: https://notiz.blog/ * License: MIT diff --git a/includes/rest/class-outbox.php b/includes/rest/class-outbox.php index 7eec5ac..615f06b 100644 --- a/includes/rest/class-outbox.php +++ b/includes/rest/class-outbox.php @@ -103,7 +103,7 @@ class Outbox { foreach ( $posts as $post ) { $activitypub_post = new \Activitypub\Model\Post( $post ); $activitypub_activity = new \Activitypub\Model\Activity( 'Create', \Activitypub\Model\Activity::TYPE_NONE ); - $activitypub_activity->from_post( $activitypub_post->to_array() ); + $activitypub_activity->from_post( $activitypub_post ); $json->orderedItems[] = $activitypub_activity->to_array(); // phpcs:ignore } } diff --git a/readme.txt b/readme.txt index 4e729ef..ad6ad3d 100644 --- a/readme.txt +++ b/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: 6.1 -Stable tag: 0.16.1 +Stable tag: 0.16.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.16.2 = + +* Fix fatal error in outbox + = 0.16.1 = * Fix "update and create, posts appear blank on Mastodon" issue