This commit is contained in:
Matthias Pfefferle 2018-09-24 23:45:11 +02:00
parent eda294fa51
commit b73b8e8f25
3 changed files with 20 additions and 11 deletions

View file

@ -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;

View file

@ -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 ),
);

View file

@ -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' ) ) {