fix accept-header bug

This commit is contained in:
Matthias Pfefferle 2019-09-30 07:59:19 +02:00
parent acca7d078c
commit 0152fc39a8
5 changed files with 26 additions and 14 deletions

View file

@ -84,6 +84,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). Project maintained on GitHub at [pfefferle/wordpress-activitypub](https://github.com/pfefferle/wordpress-activitypub).
### 0.8.3 ###
* fixed accept header bug
### 0.8.2 ### ### 0.8.2 ###
* add all required accept header * add all required accept header

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.8.2 * Version: 0.8.3
* Author: Matthias Pfefferle * Author: Matthias Pfefferle
* Author URI: https://notiz.blog/ * Author URI: https://notiz.blog/
* License: MIT * License: MIT
@ -64,8 +64,8 @@ function init() {
require_once dirname( __FILE__ ) . '/includes/class-debug.php'; require_once dirname( __FILE__ ) . '/includes/class-debug.php';
\Activitypub\Debug::init(); \Activitypub\Debug::init();
#require_once dirname( __FILE__ ) . '/includes/class-health-check.php'; require_once dirname( __FILE__ ) . '/includes/class-health-check.php';
#\Activitypub\Health_Check::init(); \Activitypub\Health_Check::init();
} }
add_action( 'plugins_loaded', '\Activitypub\init' ); add_action( 'plugins_loaded', '\Activitypub\init' );

View file

@ -24,6 +24,8 @@ class Activitypub {
} }
\add_action( 'transition_post_status', array( '\Activitypub\Activitypub', 'schedule_post_activity' ), 10, 3 ); \add_action( 'transition_post_status', array( '\Activitypub\Activitypub', 'schedule_post_activity' ), 10, 3 );
\add_action( 'trash_post', array( '\Activitypub\Activitypub', 'schedule_delete_activity' ), 10 );
} }
/** /**
@ -60,22 +62,22 @@ class Activitypub {
stristr( $accept_header, 'application/activity+json' ) || stristr( $accept_header, 'application/activity+json' ) ||
stristr( $accept_header, 'application/ld+json' ) stristr( $accept_header, 'application/ld+json' )
) { ) {
return $template; return $json_template;
} }
// accept header as an array // accept header as an array
$accept = \explode( ',', trim( $accept_header ) ); $accept = \explode( ',', trim( $accept_header ) );
if ( if (
! \in_array( 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"', $accept, true ) && \in_array( 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"', $accept, true ) ||
! \in_array( 'application/activity+json', $accept, true ) && \in_array( 'application/activity+json', $accept, true ) ||
! \in_array( 'application/ld+json', $accept, true ) && \in_array( 'application/ld+json', $accept, true ) ||
! \in_array( 'application/json', $accept, true ) \in_array( 'application/json', $accept, true )
) { ) {
return $template; return $json_template;
} }
return $json_template; return $template;
} }
/** /**
@ -113,9 +115,11 @@ class Activitypub {
} }
if ( 'publish' === $new_status && 'publish' !== $old_status ) { if ( 'publish' === $new_status && 'publish' !== $old_status ) {
\wp_schedule_single_event( time() + \wp_rand( 0, 120 ), 'activitypub_send_post_activity', array( $post->ID ) ); \wp_schedule_single_event( time(), 'activitypub_send_post_activity', array( $post->ID ) );
} elseif ( 'publish' === $new_status ) { } elseif ( 'publish' === $new_status ) {
\wp_schedule_single_event( time() + \wp_rand( 0, 120 ), 'activitypub_send_update_activity', array( $post->ID ) ); \wp_schedule_single_event( time(), 'activitypub_send_update_activity', array( $post->ID ) );
} elseif ( 'trash' === $new_status ) {
\wp_schedule_single_event( time(), 'activitypub_send_delete_activity', array( get_permalink( $post ) ) );
} }
} }

View file

@ -2,10 +2,10 @@
# This file is distributed under the MIT. # This file is distributed under the MIT.
msgid "" msgid ""
msgstr "" msgstr ""
"Project-Id-Version: ActivityPub 0.8.2\n" "Project-Id-Version: ActivityPub 0.8.3\n"
"Report-Msgid-Bugs-To: " "Report-Msgid-Bugs-To: "
"https://wordpress.org/support/plugin/wordpress-activitypub\n" "https://wordpress.org/support/plugin/wordpress-activitypub\n"
"POT-Creation-Date: 2019-09-29 18:04:39+00:00\n" "POT-Creation-Date: 2019-09-30 05:58:15+00:00\n"
"MIME-Version: 1.0\n" "MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n" "Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n" "Content-Transfer-Encoding: 8bit\n"

View file

@ -84,6 +84,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). Project maintained on GitHub at [pfefferle/wordpress-activitypub](https://github.com/pfefferle/wordpress-activitypub).
= 0.8.3 =
* fixed accept header bug
= 0.8.2 = = 0.8.2 =
* add all required accept header * add all required accept header