Merge branch 'master' into optimize-publish

This commit is contained in:
Matthias Pfefferle 2023-02-20 18:22:17 +01:00 committed by GitHub
commit 08ce46a1a4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 169 additions and 42 deletions

View file

@ -4,7 +4,7 @@
**Tags:** OStatus, fediverse, activitypub, activitystream **Tags:** OStatus, fediverse, activitypub, activitystream
**Requires at least:** 4.7 **Requires at least:** 4.7
**Tested up to:** 6.1 **Tested up to:** 6.1
**Stable tag:** 0.16.0 **Stable tag:** 0.16.3
**Requires PHP:** 5.6 **Requires PHP:** 5.6
**License:** MIT **License:** MIT
**License URI:** http://opensource.org/licenses/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). 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 ### ### 0.16.0 ###
* Add "Outgoing Mentions" ([#213](https://github.com/pfefferle/wordpress-activitypub/pull/213)) props [@akirk](https://github.com/akirk) * Add "Outgoing Mentions" ([#213](https://github.com/pfefferle/wordpress-activitypub/pull/213)) props [@akirk](https://github.com/akirk)

View file

@ -3,7 +3,7 @@
* Plugin Name: ActivityPub * Plugin Name: ActivityPub
* Plugin URI: https://github.com/pfefferle/wordpress-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. * 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: Matthias Pfefferle
* Author URI: https://notiz.blog/ * Author URI: https://notiz.blog/
* License: MIT * License: MIT

View file

@ -1,6 +1,7 @@
version: '2' version: '2'
services: services:
test-db: test-db:
platform: linux/x86_64
image: mysql:5.7 image: mysql:5.7
environment: environment:
MYSQL_DATABASE: activitypub-test MYSQL_DATABASE: activitypub-test

View file

@ -106,13 +106,11 @@ class Shortcodes {
// An empty string will make wp_trim_excerpt do stuff we do not want. // An empty string will make wp_trim_excerpt do stuff we do not want.
if ( '' !== $content ) { if ( '' !== $content ) {
$excerpt = \strip_shortcodes( $content ); $excerpt = \strip_shortcodes( $content );
/** This filter is documented in wp-includes/post-template.php */ /** This filter is documented in wp-includes/post-template.php */
$excerpt = \apply_filters( 'the_content', $excerpt ); $excerpt = \apply_filters( 'the_content', $excerpt );
$excerpt = \str_replace( ']]>', ']]>', $excerpt ); $excerpt = \str_replace( ']]>', ']]>', $excerpt );
} }
} }
@ -199,6 +197,9 @@ class Shortcodes {
$content = \get_post_field( 'post_content', $post ); $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'] ) { if ( 'yes' === $atts['apply_filters'] ) {
$content = \apply_filters( 'the_content', $content ); $content = \apply_filters( 'the_content', $content );
} else { } else {
@ -207,6 +208,8 @@ class Shortcodes {
$content = wp_filter_content_tags( $content ); $content = wp_filter_content_tags( $content );
} }
$content = \trim( \preg_replace( '/[\n\r\t]/', '', $content ) );
return $content; return $content;
} }

View file

@ -177,7 +177,7 @@ class Post {
'tag' => $this->get_tags(), 'tag' => $this->get_tags(),
); );
return \apply_filters( 'activitypub_post', $array ); return \apply_filters( 'activitypub_post', $array, $this->post );
} }
/** /**
@ -402,10 +402,13 @@ class Post {
* @return string the content * @return string the content
*/ */
public function get_content() { public function get_content() {
global $post;
if ( $this->content ) { if ( $this->content ) {
return $this->content; return $this->content;
} }
// phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
$post = $this->post; $post = $this->post;
$content = $this->get_post_content_template(); $content = $this->get_post_content_template();
@ -415,12 +418,11 @@ class Post {
wp_reset_postdata(); wp_reset_postdata();
$content = \wpautop( \wp_kses( $content, $this->allowed_tags ) ); $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 = \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; $this->content = $content;
return $content; return $content;
@ -433,15 +435,15 @@ class Post {
*/ */
public function get_post_content_template() { public function get_post_content_template() {
if ( 'excerpt' === \get_option( 'activitypub_post_content_type', 'content' ) ) { 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' ) ) { 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' ) ) { 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. // Upgrade from old template codes to shortcodes.
@ -488,29 +490,4 @@ class Post {
return $content; 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( '<a rel="tag" class="u-tag u-category" href="%s">#%s</a>', \get_tag_link( $tag ), $tag->slug );
}
return \implode( ' ', $hash_tags );
}
} }

View file

@ -491,11 +491,21 @@ class Inbox {
foreach ( array( 'to', 'bto', 'cc', 'bcc', 'audience' ) as $i ) { foreach ( array( 'to', 'bto', 'cc', 'bcc', 'audience' ) as $i ) {
if ( array_key_exists( $i, $data ) ) { 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'] ) ) { 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 );
} }
} }

View file

@ -103,6 +103,7 @@ class Outbox {
foreach ( $posts as $post ) { foreach ( $posts as $post ) {
$activitypub_post = new \Activitypub\Model\Post( $post ); $activitypub_post = new \Activitypub\Model\Post( $post );
$activitypub_activity = new \Activitypub\Model\Activity( 'Create', false ); $activitypub_activity = new \Activitypub\Model\Activity( 'Create', false );
$activitypub_activity->from_post( $activitypub_post ); $activitypub_activity->from_post( $activitypub_post );
$json->orderedItems[] = $activitypub_activity->to_array(); // phpcs:ignore $json->orderedItems[] = $activitypub_activity->to_array(); // phpcs:ignore
} }

View file

@ -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.", "description": "The ActivityPub protocol is a decentralized social networking protocol based upon the ActivityStreams 2.0 data format.",
"repository": { "repository": {
"type": "git", "type": "git",

View file

@ -4,7 +4,7 @@ Donate link: https://notiz.blog/donate/
Tags: OStatus, fediverse, activitypub, activitystream Tags: OStatus, fediverse, activitypub, activitystream
Requires at least: 4.7 Requires at least: 4.7
Tested up to: 6.1 Tested up to: 6.1
Stable tag: 0.16.0 Stable tag: 0.16.3
Requires PHP: 5.6 Requires PHP: 5.6
License: MIT License: MIT
License URI: http://opensource.org/licenses/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). 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 = = 0.16.0 =
* Add "Outgoing Mentions" ([#213](https://github.com/pfefferle/wordpress-activitypub/pull/213)) props [@akirk](https://github.com/akirk) * Add "Outgoing Mentions" ([#213](https://github.com/pfefferle/wordpress-activitypub/pull/213)) props [@akirk](https://github.com/akirk)

View file

@ -30,6 +30,8 @@ class Test_Activitypub_Activity_Dispatcher extends ActivityPub_TestCase_Cache_HT
$activitypub_post = new \Activitypub\Model\Post( $post ); $activitypub_post = new \Activitypub\Model\Post( $post );
\Activitypub\Activity_Dispatcher::send_create_activity( $activitypub_post ); \Activitypub\Activity_Dispatcher::send_create_activity( $activitypub_post );
$this->assertNotEmpty( $activitypub_post->get_content() );
$this->assertSame( 2, $pre_http_request->get_call_count() ); $this->assertSame( 2, $pre_http_request->get_call_count() );
$all_args = $pre_http_request->get_args(); $all_args = $pre_http_request->get_args();
$first_call_args = array_shift( $all_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_post = new \Activitypub\Model\Post( $post );
\Activitypub\Activity_Dispatcher::send_create_activity( $activitypub_post ); \Activitypub\Activity_Dispatcher::send_create_activity( $activitypub_post );
$this->assertNotEmpty( $activitypub_post->get_content() );
$this->assertSame( 1, $pre_http_request->get_call_count() ); $this->assertSame( 1, $pre_http_request->get_call_count() );
$all_args = $pre_http_request->get_args(); $all_args = $pre_http_request->get_args();
$first_call_args = $all_args[0]; $first_call_args = $all_args[0];

View file

@ -0,0 +1,75 @@
<?php
class Test_Activitypub_Rest_Inbox extends WP_UnitTestCase {
/**
* @dataProvider the_data_provider
*/
public function test_is_activity_public( $data, $check ) {
$this->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,
),
);
}
}

View file

@ -0,0 +1,30 @@
<?php
class Test_Activitypub_Shortcodes extends WP_UnitTestCase {
public function test_content() {
global $post;
$post_id = -99; // 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 = '<script>test</script>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( '<p>hallo</p>', $content );
}
}