From 531bdc17b034ed1948e4f1e611f5af4933449509 Mon Sep 17 00:00:00 2001 From: Matthias Pfefferle Date: Thu, 2 Feb 2023 08:18:10 +0100 Subject: [PATCH] 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];