From 02fe7d600a5b815d0513fdaa3b993e7be67c799e Mon Sep 17 00:00:00 2001 From: Jeremy Dormitzer Date: Wed, 13 Mar 2019 22:55:47 -0400 Subject: [PATCH] Compact actor before delivery; improve excerpt generation --- includes/client/posts.php | 7 ++----- includes/server/activities/create.php | 2 +- includes/server/activities/delete.php | 2 +- includes/server/activities/follow.php | 3 ++- includes/server/activities/update.php | 2 +- includes/server/deliver.php | 7 ++++++- 6 files changed, 13 insertions(+), 10 deletions(-) diff --git a/includes/client/posts.php b/includes/client/posts.php index cc20df1..ad795df 100644 --- a/includes/client/posts.php +++ b/includes/client/posts.php @@ -48,14 +48,11 @@ function post_to_object( $post ) { return; } setup_postdata( $post ); + $GLOBALS['post'] = $post; $permalink = get_permalink( $post ); $summary = null; if ( $post->post_content ) { - $summary = \html_entity_decode( - get_the_excerpt( $post ), - ENT_QUOTES, - 'UTF-8' - ); + $summary = apply_filters( 'get_the_excerpt', get_post_field( 'post_excerpt', $post->ID ) ); } $matches = array(); if ( preg_match( '/(.+)__trashed\/$/', $permalink, $matches ) ) { diff --git a/includes/server/activities/create.php b/includes/server/activities/create.php index 429808f..994f130 100644 --- a/includes/server/activities/create.php +++ b/includes/server/activities/create.php @@ -102,7 +102,7 @@ function make_create( $actor_slug, $object ) { $activity = array( '@context' => array( 'https://www.w3.org/ns/activitystreams' ), 'type' => 'Create', - 'actor' => $actor, + 'actor' => $actor['id'], 'object' => $object ); return $activity; diff --git a/includes/server/activities/delete.php b/includes/server/activities/delete.php index 7430b58..64e115d 100644 --- a/includes/server/activities/delete.php +++ b/includes/server/activities/delete.php @@ -92,7 +92,7 @@ function make_delete( $actor_slug, $object ) { return array( '@context' => array( 'https://www.w3.org/ns/activitystreams' ), 'type' => 'Delete', - 'actor' => $actor, + 'actor' => $actor['id'], 'object' => $object ); } diff --git a/includes/server/activities/follow.php b/includes/server/activities/follow.php index 0e9e32a..e6e8c44 100644 --- a/includes/server/activities/follow.php +++ b/includes/server/activities/follow.php @@ -79,10 +79,11 @@ function make_accept( $actor_slug, $follow ) { array( 'status' => 400 ) ); } + $actor = \pterotype\actors\get_actor_by_slug( $actor_slug ); $accept = array( '@context' => array( 'https://www.w3.org/ns/activitystreams' ), 'type' => 'Accept', - 'actor' => \pterotype\actors\get_actor_by_slug( $actor_slug ), + 'actor' => $actor['id'], 'object' => $follow, 'to' => $follow['actor'], ); diff --git a/includes/server/activities/update.php b/includes/server/activities/update.php index a31d1ae..116236a 100644 --- a/includes/server/activities/update.php +++ b/includes/server/activities/update.php @@ -107,7 +107,7 @@ function make_update( $actor_slug, $object ) { return array( '@context' => array( 'https://www.w3.org/ns/activitystreams' ), 'type' => 'Update', - 'actor' => $actor, + 'actor' => $actor['id'], 'object' => $object ); } diff --git a/includes/server/deliver.php b/includes/server/deliver.php index f070bf9..6fecd7f 100644 --- a/includes/server/deliver.php +++ b/includes/server/deliver.php @@ -125,7 +125,12 @@ function get_recipient_urls( $object, $depth, $acc ) { } function post_activity_to_inboxes( $actor_id, $activity, $recipients, $deliver_locally = true ) { - $activity = \pterotype\util\decompact_object( $activity, array( 'actor', 'object' ) ); + $activity = \pterotype\util\decompact_object( $activity, array( 'object' ) ); + if ( array_key_exists( 'actor', $activity ) && + is_array( $activity['actor'] ) && + array_key_exists( 'id', $activity['actor'] ) ) { + $activity['actor'] = $activity['actor']['id']; + } foreach ( $recipients as $inbox ) { if ( $inbox === 'https://www.w3.org/ns/activitystreams#Public' ) { continue;