diff --git a/README.md b/README.md index 1e405f8..a0ba36f 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.3 **Requires PHP:** 5.6 **License:** MIT **License URI:** http://opensource.org/licenses/MIT @@ -88,6 +88,19 @@ 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.3 ### + +* "cc", "to", ... fields can either be an array or a string +* Remove "style" and "script" HTML elements from content + +### 0.16.2 ### + +* Fix fatal error in outbox + +### 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..92a2aa7 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.3 * Author: Matthias Pfefferle * Author URI: https://notiz.blog/ * License: MIT diff --git a/docker-compose-test.yml b/docker-compose-test.yml index a293823..4c69e44 100644 --- a/docker-compose-test.yml +++ b/docker-compose-test.yml @@ -1,6 +1,7 @@ version: '2' services: test-db: + platform: linux/x86_64 image: mysql:5.7 environment: MYSQL_DATABASE: activitypub-test diff --git a/includes/class-shortcodes.php b/includes/class-shortcodes.php index b6fc4ad..ad2efe5 100644 --- a/includes/class-shortcodes.php +++ b/includes/class-shortcodes.php @@ -106,13 +106,11 @@ class Shortcodes { // An empty string will make wp_trim_excerpt do stuff we do not want. if ( '' !== $content ) { - $excerpt = \strip_shortcodes( $content ); /** This filter is documented in wp-includes/post-template.php */ $excerpt = \apply_filters( 'the_content', $excerpt ); $excerpt = \str_replace( ']]>', ']]>', $excerpt ); - } } @@ -199,6 +197,9 @@ class Shortcodes { $content = \get_post_field( 'post_content', $post ); + // replace script and style elements + $content = \preg_replace( '@<(script|style)[^>]*?>.*?\\1>@si', '', $content ); + if ( 'yes' === $atts['apply_filters'] ) { $content = \apply_filters( 'the_content', $content ); } else { @@ -207,6 +208,8 @@ class Shortcodes { $content = wp_filter_content_tags( $content ); } + $content = \trim( \preg_replace( '/[\n\r\t]/', '', $content ) ); + return $content; } diff --git a/includes/model/class-post.php b/includes/model/class-post.php index 0929277..4c2d780 100644 --- a/includes/model/class-post.php +++ b/includes/model/class-post.php @@ -177,7 +177,7 @@ class Post { 'tag' => $this->get_tags(), ); - return \apply_filters( 'activitypub_post', $array ); + return \apply_filters( 'activitypub_post', $array, $this->post ); } /** @@ -402,11 +402,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. @@ -415,12 +418,11 @@ class Post { wp_reset_postdata(); $content = \wpautop( \wp_kses( $content, $this->allowed_tags ) ); - - $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\t]/', '', $content ) ); + $content = \apply_filters( 'activitypub_the_content', $content, $post ); + $content = \html_entity_decode( $content, \ENT_QUOTES, 'UTF-8' ); + $this->content = $content; return $content; @@ -433,15 +435,15 @@ class Post { */ public function get_post_content_template() { if ( 'excerpt' === \get_option( 'activitypub_post_content_type', 'content' ) ) { - return "[ap_excerpt]\n\n[ap_permalink]"; + return "[ap_excerpt]\n\n[ap_permalink type=\"html\"]"; } if ( 'title' === \get_option( 'activitypub_post_content_type', 'content' ) ) { - return "[ap_title]\n\n[ap_permalink]"; + return "[ap_title]\n\n[ap_permalink type=\"html\"]"; } if ( 'content' === \get_option( 'activitypub_post_content_type', 'content' ) ) { - return "[ap_content]\n\n[ap_hashtags]\n\n[ap_permalink]"; + return "[ap_content]\n\n[ap_hashtags]\n\n[ap_permalink type=\"html\"]"; } // Upgrade from old template codes to shortcodes. @@ -488,29 +490,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( '#%s', \get_tag_link( $tag ), $tag->slug ); - } - - return \implode( ' ', $hash_tags ); - } } diff --git a/includes/rest/class-inbox.php b/includes/rest/class-inbox.php index 1eab8a5..86aefd4 100644 --- a/includes/rest/class-inbox.php +++ b/includes/rest/class-inbox.php @@ -491,11 +491,21 @@ class Inbox { foreach ( array( 'to', 'bto', 'cc', 'bcc', 'audience' ) as $i ) { if ( array_key_exists( $i, $data ) ) { - $recipient_items = array_merge( $recipient_items, $data[ $i ] ); + if ( is_array( $data[ $i ] ) ) { + $recipient = $data[ $i ]; + } else { + $recipient = array( $data[ $i ] ); + } + $recipient_items = array_merge( $recipient_items, $recipient ); } if ( array_key_exists( $i, $data['object'] ) ) { - $recipient_items = array_merge( $recipient_items, $data[ $i ] ); + if ( is_array( $data['object'][ $i ] ) ) { + $recipient = $data['object'][ $i ]; + } else { + $recipient = array( $data['object'][ $i ] ); + } + $recipient_items = array_merge( $recipient_items, $recipient ); } } diff --git a/includes/rest/class-outbox.php b/includes/rest/class-outbox.php index 677e2ff..8749d11 100644 --- a/includes/rest/class-outbox.php +++ b/includes/rest/class-outbox.php @@ -103,6 +103,7 @@ class Outbox { foreach ( $posts as $post ) { $activitypub_post = new \Activitypub\Model\Post( $post ); $activitypub_activity = new \Activitypub\Model\Activity( 'Create', false ); + $activitypub_activity->from_post( $activitypub_post ); $json->orderedItems[] = $activitypub_activity->to_array(); // phpcs:ignore } diff --git a/package.json b/package.json index b06ccaf..741ae18 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "activitypub", + "name": "wordpress-activitypub", "description": "The ActivityPub protocol is a decentralized social networking protocol based upon the ActivityStreams 2.0 data format.", "repository": { "type": "git", diff --git a/readme.txt b/readme.txt index cb22943..387ed30 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.3 Requires PHP: 5.6 License: MIT License URI: http://opensource.org/licenses/MIT @@ -88,6 +88,19 @@ 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.3 = + +* "cc", "to", ... fields can either be an array or a string +* Remove "style" and "script" HTML elements from content + += 0.16.2 = + +* Fix fatal error in outbox + += 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 ec62b2d..0e503e5 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_create_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_create_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]; diff --git a/tests/test-class-activitypub-rest-inbox.php b/tests/test-class-activitypub-rest-inbox.php new file mode 100644 index 0000000..58f16f3 --- /dev/null +++ b/tests/test-class-activitypub-rest-inbox.php @@ -0,0 +1,75 @@ +assertEquals( $check, Activitypub\Rest\Inbox::is_activity_public( $data ) ); + } + + public function the_data_provider() { + return array( + array( + array( + 'cc' => array( + 'https://example.org/@test', + 'https://example.com/@test2', + ), + 'to' => 'https://www.w3.org/ns/activitystreams#Public', + 'object' => array(), + ), + true, + ), + array( + array( + 'cc' => array( + 'https://example.org/@test', + 'https://example.com/@test2', + ), + 'to' => array( + 'https://www.w3.org/ns/activitystreams#Public', + ), + 'object' => array(), + ), + true, + ), + array( + array( + 'cc' => array( + 'https://example.org/@test', + 'https://example.com/@test2', + ), + 'object' => array(), + ), + false, + ), + array( + array( + 'cc' => array( + 'https://example.org/@test', + 'https://example.com/@test2', + ), + 'object' => array( + 'to' => 'https://www.w3.org/ns/activitystreams#Public', + ), + ), + true, + ), + array( + array( + 'cc' => array( + 'https://example.org/@test', + 'https://example.com/@test2', + ), + 'object' => array( + 'to' => array( + 'https://www.w3.org/ns/activitystreams#Public', + ), + ), + ), + true, + ), + ); + } +} diff --git a/tests/test-class-activitypub-shortcodes.php b/tests/test-class-activitypub-shortcodes.php new file mode 100644 index 0000000..ac97910 --- /dev/null +++ b/tests/test-class-activitypub-shortcodes.php @@ -0,0 +1,30 @@ +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 = 'hallo'; + $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_content]'; + + // Fill in the shortcodes. + setup_postdata( $post ); + $content = do_shortcode( $content ); + wp_reset_postdata(); + + $this->assertEquals( '
hallo
', $content ); + } +}