diff --git a/includes/class-activitypub-outbox.php b/includes/class-activitypub-outbox.php index 9a4e383..e2ef4ef 100644 --- a/includes/class-activitypub-outbox.php +++ b/includes/class-activitypub-outbox.php @@ -60,8 +60,9 @@ class Activitypub_Outbox { ) ); $json->first = add_query_arg( 'page', 0, $json->partOf ); - $json->last = add_query_arg( 'page', ( $json->totalItems%10 )-1, $json->partOf ); - if ( $json->last < $page ) { + $json->last = add_query_arg( 'page', ( ceil ( $json->totalItems / 10 ) ) - 1, $json->partOf ); + + if ( ( ceil ( $json->totalItems / 10 ) ) - 1 > $page ) { $json->next = add_query_arg( 'page', ++$page, $json->partOf ); } @@ -87,21 +88,27 @@ class Activitypub_Outbox { public static function post_to_json( $post ) { $json = new stdClass(); - $json->published = $post->post_date; - $json->id = $post->guid; + $json->published = date( 'Y-m-d\TH:i:s\Z', strtotime( $post->post_date ) ); + $json->id = $post->guid . '&activitypub'; $json->type = 'Create'; - $json->actor = 'https://mastodon.social/users/pfefferle'; + $json->actor = get_author_posts_url( $post->post_author ); $json->to = array( 'https://www.w3.org/ns/activitystreams#Public' ); + $json->cc = array( 'https://www.w3.org/ns/activitystreams#Public' ); $json->object = array( 'id' => $post->guid, 'type' => 'Note', - 'published' => $post->post_date, + 'published' => date( 'Y-m-d\TH:i:s\Z', strtotime( $post->post_date ) ), 'to' => array( 'https://www.w3.org/ns/activitystreams#Public' ), - 'content' => $post->post_content, + 'cc' => array( 'https://www.w3.org/ns/activitystreams#Public' ), + 'summary' => null, + 'inReplyTo' => null, + 'content' => esc_html( $post->post_content ), 'contentMap' => array( strstr( get_locale(), '_', true ) => $post->post_content, ), + 'attachment' => array(), + 'tag' => array(), ); return $json; diff --git a/includes/class-activitypub.php b/includes/class-activitypub.php index 8fedde9..86da12f 100644 --- a/includes/class-activitypub.php +++ b/includes/class-activitypub.php @@ -30,7 +30,8 @@ class Activitypub { if ( ! 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 ) ) { return $template; } @@ -48,7 +49,7 @@ class Activitypub { public static function add_webfinger_discovery( $array, $resource, $user ) { $array['links'][] = array( 'rel' => 'self', - 'type' => 'aplication/activity+json', + 'type' => 'application/activity+json', 'href' => get_author_posts_url( $user->ID ), ); diff --git a/templates/profile.php b/templates/profile.php index cc17587..770a076 100644 --- a/templates/profile.php +++ b/templates/profile.php @@ -11,8 +11,8 @@ $json->{'@context'} = array( $json->id = get_author_posts_url( $author_id ); $json->type = 'Person'; $json->name = get_the_author_meta( 'display_name', $author_id ); -$json->summary = get_the_author_meta( 'description', $author_id ); -$json->preferredUsername = get_the_author(); // phpcs:ignore +$json->summary = wp_strip_all_tags( get_the_author_meta( 'description', $author_id ) ); +$json->preferredUsername = get_the_author_meta( 'login', $author_id ); // phpcs:ignore $json->url = get_author_posts_url( $author_id ); $json->icon = array( 'type' => 'Image', @@ -26,6 +26,7 @@ if ( has_header_image() ) { ); } +$json->inbox = get_rest_url( null, "/activitypub/1.0/users/$author_id/inbox" ); $json->outbox = get_rest_url( null, "/activitypub/1.0/users/$author_id/outbox" ); if ( method_exists( 'Magic_Sig', 'get_public_key' ) ) {