From 5713d23a9f25f03ed25591a9fb1d08a55d94fa70 Mon Sep 17 00:00:00 2001 From: Jeremy Dormitzer Date: Tue, 30 Oct 2018 17:19:16 -0400 Subject: [PATCH] Derefence all the objects --- includes/server/activities/announce.php | 3 ++- includes/server/activities/block.php | 4 +++- includes/server/activities/create.php | 9 +++++---- includes/server/activities/delete.php | 5 +++-- includes/server/activities/follow.php | 2 +- includes/server/activities/like.php | 5 +++-- includes/server/activities/reject.php | 3 ++- includes/server/activities/update.php | 5 +++-- includes/server/deliver.php | 5 +++++ 9 files changed, 27 insertions(+), 14 deletions(-) diff --git a/includes/server/activities/announce.php b/includes/server/activities/announce.php index fa8c896..e143c4c 100644 --- a/includes/server/activities/announce.php +++ b/includes/server/activities/announce.php @@ -3,6 +3,7 @@ namespace pterotype\activities\announce; require_once plugin_dir_path( __FILE__ ) . '../objects.php'; require_once plugin_dir_path( __FILE__ ) . '../shares.php'; +require_once plugin_dir_path( __FILE__ ) . '../../util.php'; function handle_inbox( $actor_slug, $activity ) { if ( !array_key_exists( 'object', $activity ) ) { @@ -12,7 +13,7 @@ function handle_inbox( $actor_slug, $activity ) { array( 'status' => 400 ) ); } - $object = $activity['object']; + $object = \pterotype\util\dereference_object( $activity['object'] ); if ( !array_key_exists( 'id', $object ) ) { return new \WP_Error( 'invalid_activity', diff --git a/includes/server/activities/block.php b/includes/server/activities/block.php index 9e7caed..18affe1 100644 --- a/includes/server/activities/block.php +++ b/includes/server/activities/block.php @@ -3,6 +3,7 @@ namespace pterotype\activities\block; require_once plugin_dir_path( __FILE__ ) . '../blocks.php'; require_once plugin_dir_path( __FILE__ ) . '../actors.php'; +require_once plugin_dir_path( __FILE__ ) . '../../util.php'; function handle_outbox( $actor, $activity ) { if ( !array_key_exists( 'object', $activity ) ) { @@ -13,7 +14,8 @@ function handle_outbox( $actor, $activity ) { ); } $actor_id = \pterotype\actors\get_actor_id( $actor ); - $res = \pterotype\blocks\create_block( $actor_id, $activity['object'] ); + $object = \pterotype\util\dereference_object( $activity['object'] ); + $res = \pterotype\blocks\create_block( $actor_id, $object ); if ( is_wp_error( $res ) ) { return $res; } diff --git a/includes/server/activities/create.php b/includes/server/activities/create.php index 049d6e6..4b56314 100644 --- a/includes/server/activities/create.php +++ b/includes/server/activities/create.php @@ -30,7 +30,7 @@ function handle_outbox( $actor_slug, $activity ) { 'invalid_actor', __( 'Expecting a valid actor', 'pterotype' ) ); } - $object = $activity['object']; + $object = \pterotype\util\dereference_object( $activity['object'] ); $attributed_actor = $activity['actor']; $object['attributedTo'] = $attributed_actor; reconcile_receivers( $object, $activity ); @@ -52,7 +52,7 @@ function handle_inbox( $actor_slug, $activity ) { array( 'status' => 400 ) ); } - $object = $activity['object']; + $object = \pterotype\util\dereference_object( $activity['object'] ); $object_row = \pterotype\objects\upsert_object( $object ); if ( is_wp_error( $object_row ) ) { return $object_row; @@ -125,7 +125,7 @@ function link_comment( $object ) { } function sync_comments( $activity ) { - $object = $activity['object']; + $object = \pterotype\util\dereference_object( $activity['object'] ); $object_id = \pterotype\objects\get_object_id( $object['id'] ); $comment_exists = \pterotype\commentlinks\get_comment_id( $object_id ); if ( $comment_exists ) { @@ -157,7 +157,7 @@ function sync_comments( $activity ) { link_new_comment( $comment_id, $object_id ); return; } else { - $parent = $parent_row->object; + $parent = \pterotype\util\dereference_object( $parent_row->object ); if ( ! array_key_exists( 'url', $parent ) ) { return; } @@ -189,6 +189,7 @@ function get_comment_id_from_url( $url ) { } function make_comment_from_object( $object, $post_id, $parent_comment_id = null ) { + $object = \pterotype\util\dereference_object( $object ); $actor = null; if ( array_key_exists( 'attributedTo', $object ) ) { $actor = \pterotype\util\dereference_object( $object['attributedTo'] ); diff --git a/includes/server/activities/delete.php b/includes/server/activities/delete.php index 0a6eae9..7759938 100644 --- a/includes/server/activities/delete.php +++ b/includes/server/activities/delete.php @@ -4,6 +4,7 @@ namespace pterotype\activities\delete; require_once plugin_dir_path( __FILE__ ) . '../objects.php'; require_once plugin_dir_path( __FILE__ ) . '../actors.php'; require_once plugin_dir_path( __FILE__ ) . '../../commentlinks.php'; +require_once plugin_dir_path( __FILE__ ) . '../../util.php'; function handle_outbox( $actor, $activity ) { if ( !array_key_exists( 'object', $activity ) ) { @@ -13,7 +14,7 @@ function handle_outbox( $actor, $activity ) { array( 'status' => 400 ) ); } - $object = $activity['object']; + $object = \pterotype\util\dereference_object( $activity['object'] ); $tombstone = \pterotype\objects\delete_object( $object ); if ( is_wp_error( $tombstone ) ) { return $tombstone; @@ -37,7 +38,7 @@ function handle_inbox( $actor_slug, $activity ) { array( 'status' => 400 ) ); } - $object = $activity['object']; + $object = \pterotype\util\dereference_object( $activity['object'] ); if ( !array_key_exists( 'id', $object ) ) { return new \WP_Error( 'invalid_activity', diff --git a/includes/server/activities/follow.php b/includes/server/activities/follow.php index 0e9e32a..2a4a887 100644 --- a/includes/server/activities/follow.php +++ b/includes/server/activities/follow.php @@ -15,7 +15,7 @@ function handle_outbox( $actor_slug, $activity ) { array( 'status' => 400 ) ); } - $object = $activity['object']; + $object = \pterotype\util\dereference_object( $activity['object'] ); $object_row = \pterotype\objects\upsert_object( $object ); $actor_id = \pterotype\actors\get_actor_id( $actor_slug ); $res = \pterotype\following\request_follow( $actor_id, $object_row->id ); diff --git a/includes/server/activities/like.php b/includes/server/activities/like.php index 6d3a44a..f6f90b7 100644 --- a/includes/server/activities/like.php +++ b/includes/server/activities/like.php @@ -4,6 +4,7 @@ namespace pterotype\activities\like; require_once plugin_dir_path( __FILE__ ) . '../likes.php'; require_once plugin_dir_path( __FILE__ ) . '../actors.php'; require_once plugin_dir_path( __FILE__ ) . '../objects.php'; +require_once plugin_dir_path( __FILE__ ) . '../../util.php'; function handle_outbox( $actor, $activity ) { if ( !array_key_exists( 'object', $activity ) ) { @@ -13,7 +14,7 @@ function handle_outbox( $actor, $activity ) { array( 'status' => 400 ) ); } - $object = $activity['object']; + $object = \pterotype\util\dereference_object( $activity['object'] ); if ( !array_key_exists( 'id', $object ) ) { return new \WP_Error( 'invalid_object', @@ -57,7 +58,7 @@ function handle_inbox( $actor, $activity ) { array( 'status' => 400 ) ); } - $object = $activity['object']; + $object = \pterotype\util\dereference_object( $activity['object'] ); if ( !array_key_exists( 'id', $object ) ) { return new \WP_Error( 'invalid_object', diff --git a/includes/server/activities/reject.php b/includes/server/activities/reject.php index 0d44067..bb2d1ce 100644 --- a/includes/server/activities/reject.php +++ b/includes/server/activities/reject.php @@ -4,6 +4,7 @@ namespace pterotype\activities\reject; require_once plugin_dir_path( __FILE__ ) . '../following.php'; require_once plugin_dir_path( __FILE__ ) . '../objects.php'; require_once plugin_dir_path( __FILE__ ) . '../actors.php'; +require_once plugin_dir_path( __FILE__ ) . '../../util.php'; function handle_inbox( $actor_slug, $activity ) { if ( !array_key_exists( 'object', $activity ) ) { @@ -13,7 +14,7 @@ function handle_inbox( $actor_slug, $activity ) { array( 'status' => 400 ) ); } - $object = $activity['object']; + $object = \pterotype\util\dereference_object( $activity['object'] ); if ( array_key_exists( 'type', $object ) ) { switch ( $object['type'] ) { case 'Follow': diff --git a/includes/server/activities/update.php b/includes/server/activities/update.php index c4fd783..68d4dd4 100644 --- a/includes/server/activities/update.php +++ b/includes/server/activities/update.php @@ -3,6 +3,7 @@ namespace pterotype\activities\update; require_once plugin_dir_path( __FILE__ ) . '../objects.php'; require_once plugin_dir_path( __FILE__ ) . '../../commentlinks.php'; +require_once plugin_dir_path( __FILE__ ) . '../../util.php'; require_once plugin_dir_path( __FILE__ ) . 'create.php'; function handle_outbox( $actor_slug, $activity ) { @@ -20,7 +21,7 @@ function handle_outbox( $actor_slug, $activity ) { array( 'status' => 400 ) ); } - $update_object = $activity['object']; + $update_object = \pterotype\util\dereference_object( $activity['object'] ); if ( !array_key_exists( 'id', $update_object ) ) { return new \WP_Error( 'invalid_object', @@ -62,7 +63,7 @@ function handle_inbox( $actor_slug, $activity ) { array( 'status' => 400 ) ); } - $object = $activity['object']; + $object = \pterotype\util\dereference_object( $activity['object'] ); if ( !array_key_exists( 'id', $object ) ) { return new \WP_Error( 'invalid_activity', diff --git a/includes/server/deliver.php b/includes/server/deliver.php index 5eced57..bd398b4 100644 --- a/includes/server/deliver.php +++ b/includes/server/deliver.php @@ -21,8 +21,13 @@ function deliver_activity( $actor_slug, $activity ) { $recipients = array_values( array_unique( $recipients ) ); if ( array_key_exists( 'actor', $activity ) ) { $actor = \pterotype\util\dereference_object( $activity['actor'] ); + $activity['actor'] = $actor; $recipients = remove_actor_inbox_from_recipients( $actor, $recipients ); } + if ( array_key_exists( 'object', $activity ) ) { + $object = \pterotype\util\dereference_object( $activity['object'] ); + $activity['object'] = $object; + } $activity = \pterotype\objects\strip_private_fields( $activity ); post_activity_to_inboxes( $actor_id, $activity, $recipients ); }