From a85bbc7333c7f4055cd819efa6fd7999699f0f8c Mon Sep 17 00:00:00 2001 From: Jeremy Dormitzer Date: Sat, 20 Oct 2018 22:34:20 -0400 Subject: [PATCH] Prefix all namespaces with "pterotype" --- includes/client/posts.php | 10 ++--- includes/init.php | 26 ++++++------- includes/pgp.php | 2 +- includes/schema.php | 2 +- includes/server/activities/accept.php | 18 ++++----- includes/server/activities/announce.php | 8 ++-- includes/server/activities/block.php | 6 +-- includes/server/activities/create.php | 8 ++-- includes/server/activities/delete.php | 8 ++-- includes/server/activities/follow.php | 18 ++++----- includes/server/activities/like.php | 22 +++++------ includes/server/activities/reject.php | 8 ++-- includes/server/activities/undo.php | 50 ++++++++++++------------- includes/server/activities/update.php | 10 ++--- includes/server/actors.php | 18 ++++----- includes/server/api.php | 22 +++++------ includes/server/async.php | 4 +- includes/server/blocks.php | 2 +- includes/server/collections.php | 2 +- includes/server/deliver.php | 32 ++++++++-------- includes/server/followers.php | 20 +++++----- includes/server/following.php | 6 +-- includes/server/inbox.php | 40 ++++++++++---------- includes/server/likes.php | 4 +- includes/server/objects.php | 14 +++---- includes/server/outbox.php | 46 +++++++++++------------ includes/server/shares.php | 4 +- includes/server/webfinger.php | 4 +- includes/util.php | 2 +- 29 files changed, 208 insertions(+), 208 deletions(-) diff --git a/includes/client/posts.php b/includes/client/posts.php index 92b4d1a..5d6939b 100644 --- a/includes/client/posts.php +++ b/includes/client/posts.php @@ -1,5 +1,5 @@ diff --git a/includes/pgp.php b/includes/pgp.php index 58d29ab..e5008cd 100644 --- a/includes/pgp.php +++ b/includes/pgp.php @@ -1,5 +1,5 @@ 400 ) ); } - $object = \util\dereference_object( $activity['object'] ); + $object = \pterotype\util\dereference_object( $activity['object'] ); if ( array_key_exists( 'type', $object ) ) { switch ( $object['type'] ) { case 'Follow': if ( !array_key_exists( 'object', $object ) ) { break; } - $follow_object = \util\dereference_object( $object['object'] ); + $follow_object = \pterotype\util\dereference_object( $object['object'] ); if ( !array_key_exists( 'id', $follow_object ) ) { break; } - $object_id = \objects\get_object_by_activitypub_id( $follow_object['id'] ); + $object_id = \pterotype\objects\get_object_by_activitypub_id( $follow_object['id'] ); if ( is_wp_error( $object_id ) ) { break; } - $actor_id = \actors\get_actor_id( $actor_slug ); - \following\accept_follow( $actor_id, $object_id ); + $actor_id = \pterotype\actors\get_actor_id( $actor_slug ); + \pterotype\following\accept_follow( $actor_id, $object_id ); break; default: break; @@ -48,15 +48,15 @@ function handle_outbox( $actor_slug, $activity ) { array( 'status' => 400 ) ); } - $object = \util\dereference_object( $activity['object'] ); + $object = \pterotype\util\dereference_object( $activity['object'] ); if ( array_key_exists( 'type', $object ) ) { switch ( $object['type'] ) { case 'Follow': if ( !array_key_exists( 'actor', $object ) ) { break; } - $follower = \util\dereference_object( $object['actor'] ); - \followers\add_follower( $actor_slug, $follower ); + $follower = \pterotype\util\dereference_object( $object['actor'] ); + \pterotype\followers\add_follower( $actor_slug, $follower ); break; } } diff --git a/includes/server/activities/announce.php b/includes/server/activities/announce.php index 3dc5aad..fa8c896 100644 --- a/includes/server/activities/announce.php +++ b/includes/server/activities/announce.php @@ -1,5 +1,5 @@ 400 ) ); } - if ( !\objects\is_local_object( $object ) ) { + if ( !\pterotype\objects\is_local_object( $object ) ) { return $activity; } - $object_id = \objects\get_object_id( $object['id'] ); + $object_id = \pterotype\objects\get_object_id( $object['id'] ); if ( !$object_id ) { return new \WP_Error( 'not_found', @@ -39,7 +39,7 @@ function handle_inbox( $actor_slug, $activity ) { array( 'status' => 404 ) ); } - \shares\add_share( $object_id, $activity_id ); + \pterotype\shares\add_share( $object_id, $activity_id ); return $activity; } ?> diff --git a/includes/server/activities/block.php b/includes/server/activities/block.php index 44a3a82..9e7caed 100644 --- a/includes/server/activities/block.php +++ b/includes/server/activities/block.php @@ -1,5 +1,5 @@ 400 ) ); } - $actor_id = \actors\get_actor_id( $actor ); - $res = \blocks\create_block( $actor_id, $activity['object'] ); + $actor_id = \pterotype\actors\get_actor_id( $actor ); + $res = \pterotype\blocks\create_block( $actor_id, $activity['object'] ); if ( is_wp_error( $res ) ) { return $res; } diff --git a/includes/server/activities/create.php b/includes/server/activities/create.php index aeb35ea..3a64be3 100644 --- a/includes/server/activities/create.php +++ b/includes/server/activities/create.php @@ -1,5 +1,5 @@ id ); + $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 ); if ( is_wp_error( $res ) ) { return $res; } @@ -37,8 +37,8 @@ function handle_inbox( $actor_slug, $activity ) { array( 'status' => 400 ) ); } - $follower = \util\dereference_object( $activity['actor'] ); - \objects\upsert_object( $follower ); + $follower = \pterotype\util\dereference_object( $activity['actor'] ); + \pterotype\objects\upsert_object( $follower ); $accept = make_accept( $actor_slug, $activity ); if ( is_wp_error( $accept ) ) { return $accept; @@ -55,11 +55,11 @@ function actor_is_object( $actor_slug, $activity ) { if ( !array_key_exists( 'object', $activity ) ) { return false; } - $actor = \actors\get_actor_by_slug( $actor_slug ); + $actor = \pterotype\actors\get_actor_by_slug( $actor_slug ); if ( is_wp_error( $actor ) ) { return false; } - $object = \util\dereference_object( $activity['object'] ); + $object = \pterotype\util\dereference_object( $activity['object'] ); if ( !array_key_exists( 'type', $object ) ) { return false; } @@ -82,7 +82,7 @@ function make_accept( $actor_slug, $follow ) { $accept = array( '@context' => array( 'https://www.w3.org/ns/activitystreams' ), 'type' => 'Accept', - 'actor' => \actors\get_actor_by_slug( $actor_slug ), + 'actor' => \pterotype\actors\get_actor_by_slug( $actor_slug ), 'object' => $follow, 'to' => $follow['actor'], ); diff --git a/includes/server/activities/like.php b/includes/server/activities/like.php index 04abb37..6d3a44a 100644 --- a/includes/server/activities/like.php +++ b/includes/server/activities/like.php @@ -1,5 +1,5 @@ 400 ) ); } - $object_row = \objects\upsert_object( $object ); - $actor_id = \actors\get_actor_id( $actor ); - $res = \likes\create_local_actor_like( $actor_id, $object_row->id ); + $object_row = \pterotype\objects\upsert_object( $object ); + $actor_id = \pterotype\actors\get_actor_id( $actor ); + $res = \pterotype\likes\create_local_actor_like( $actor_id, $object_row->id ); if ( is_wp_error( $res ) ) { return $res; } - if ( \objects\is_local_object( $object ) ) { - $activity_id = \objects\get_object_id( $activity['id'] ); + if ( \pterotype\objects\is_local_object( $object ) ) { + $activity_id = \pterotype\objects\get_object_id( $activity['id'] ); if ( !$activity_id ) { return new \WP_Error( 'not_found', @@ -37,7 +37,7 @@ function handle_outbox( $actor, $activity ) { ); } $object_id = $object_row->id; - \likes\record_like( $object_id, $activity_id ); + \pterotype\likes\record_like( $object_id, $activity_id ); } return $activity; } @@ -65,8 +65,8 @@ function handle_inbox( $actor, $activity ) { array( 'status' => 400 ) ); } - if ( \objects\is_local_object( $object ) ) { - $activity_id = \objects\get_object_id( $activity['id'] ); + if ( \pterotype\objects\is_local_object( $object ) ) { + $activity_id = \pterotype\objects\get_object_id( $activity['id'] ); if ( !$activity_id ) { return new \WP_Error( 'not_found', @@ -74,7 +74,7 @@ function handle_inbox( $actor, $activity ) { array( 'status' => 404 ) ); } - $object_id = \objects\get_object_id( $object['id'] ); + $object_id = \pterotype\objects\get_object_id( $object['id'] ); if ( !$object_id ) { return new \WP_Error( 'not_found', @@ -82,7 +82,7 @@ function handle_inbox( $actor, $activity ) { array( 'status' => 404 ) ); } - \likes\record_like( $object_id, $activity_id ); + \pterotype\likes\record_like( $object_id, $activity_id ); } return $activity; } diff --git a/includes/server/activities/reject.php b/includes/server/activities/reject.php index 9acccf7..0d44067 100644 --- a/includes/server/activities/reject.php +++ b/includes/server/activities/reject.php @@ -1,5 +1,5 @@ 400 ) ); } - $liked_object_url = \util\get_id( $object['object'] ); + $liked_object_url = \pterotype\util\get_id( $object['object'] ); if ( !$liked_object_url ) { break; } - $liked_object_id = \objects\get_object_id( $liked_object_url ); + $liked_object_id = \pterotype\objects\get_object_id( $liked_object_url ); if ( !$liked_object_id ) { break; } - \likes\delete_local_actor_like( $actor_id, $liked_object_id ); - $like_id = \objects\get_object_id( $object['id'] ); + \pterotype\likes\delete_local_actor_like( $actor_id, $liked_object_id ); + $like_id = \pterotype\objects\get_object_id( $object['id'] ); if ( !$like_id ) { break; } - \likes\delete_object_like( $liked_object_id, $like_id ); + \pterotype\likes\delete_object_like( $liked_object_id, $like_id ); break; case 'Block': if ( !array_key_exists( 'object', $object ) ) { break; } - $blocked_object_url = \util\get_id( $object['object'] ); + $blocked_object_url = \pterotype\util\get_id( $object['object'] ); if ( !$blocked_object_url ) { break; } - $res = \blocks\delete_block( $actor_id, $blocked_object_url ); + $res = \pterotype\blocks\delete_block( $actor_id, $blocked_object_url ); if ( is_wp_error( $res ) ) { return $res; } @@ -62,15 +62,15 @@ function handle_outbox( $actor_slug, $activity ) { if ( !array_key_exists( 'object', $object ) ) { break; } - $follow_object_url = \util\get_id( $object['object'] ); + $follow_object_url = \pterotype\util\get_id( $object['object'] ); if ( !$follow_object_url ) { break; } - $follow_object_id = \objects\get_object_id( $follow_object_url ); + $follow_object_id = \pterotype\objects\get_object_id( $follow_object_url ); if ( !$follow_object_id ) { break; } - \following\reject_follow( $actor_id, $follow_object_id ); + \pterotype\following\reject_follow( $actor_id, $follow_object_id ); break; // TODO I should support Undoing these as well case 'Add': @@ -88,7 +88,7 @@ function handle_inbox( $actor_slug, $activity ) { if ( is_wp_error( $object ) ) { return $object; } - $actor_id = \actors\get_actor_id( $actor_slug ); + $actor_id = \pterotype\actors\get_actor_id( $actor_slug ); if ( !$actor_id ) { return new \WP_Error( 'not_found', @@ -101,17 +101,17 @@ function handle_inbox( $actor_slug, $activity ) { if ( !array_key_exists( 'object', $object ) ) { break; } - if ( \objects\is_local_object( $object['object'] ) ) { - $object_url = \objects\get_object_id( $object['object'] ); + if ( \pterotype\objects\is_local_object( $object['object'] ) ) { + $object_url = \pterotype\objects\get_object_id( $object['object'] ); if ( !$object_url ) { break; } - $object_id = \objects\get_object_id( $object_url ); - $like_id = \objects\get_object_id( $object['id'] ); + $object_id = \pterotype\objects\get_object_id( $object_url ); + $like_id = \pterotype\objects\get_object_id( $object['id'] ); if ( !$like_id ) { break; } - \likes\delete_object_like( $object_id, $like_id ); + \pterotype\likes\delete_object_like( $object_id, $like_id ); } break; case 'Follow': @@ -119,13 +119,13 @@ function handle_inbox( $actor_slug, $activity ) { break; } $follower = $object['actor']; - \followers\remove_follower( $actor_slug, $follower ); + \pterotype\followers\remove_follower( $actor_slug, $follower ); break; case 'Accept': if ( !array_key_exists( 'object', $object ) ) { break; } - $accept_object = \util\dereference_object( $object['object'] ); + $accept_object = \pterotype\util\dereference_object( $object['object'] ); if ( is_wp_error( $object ) ) { break; } @@ -133,13 +133,13 @@ function handle_inbox( $actor_slug, $activity ) { if ( !array_key_exists( 'object', $accept_object ) ) { break; } - $followed_object_url = \util\get_id( $accept_object['object'] ); - $followed_object_id = \objects\get_object_id( $followed_object_url ); + $followed_object_url = \pterotype\util\get_id( $accept_object['object'] ); + $followed_object_id = \pterotype\objects\get_object_id( $followed_object_url ); if ( !$followed_object_id ) { break; } // Put the follow request back into the PENDING state - \following\request_follow( $actor_id, $followed_object_id ); + \pterotype\following\request_follow( $actor_id, $followed_object_id ); } break; default: @@ -163,7 +163,7 @@ function validate_undo( $activity ) { array( 'status' => 400 ) ); } - $object = \util\dereference_object( $activity['object'] ); + $object = \pterotype\util\dereference_object( $activity['object'] ); if ( is_wp_error( $object ) ) { return $object; } @@ -181,7 +181,7 @@ function validate_undo( $activity ) { array( 'status' => 400 ) ); } - if ( !\util\is_same_object( $activity['actor'], $object['actor'] ) ) { + if ( !\pterotype\util\is_same_object( $activity['actor'], $object['actor'] ) ) { return new \WP_Error( 'unauthorized', __( 'Unauthorzed Undo activity', 'pterotype' ), diff --git a/includes/server/activities/update.php b/includes/server/activities/update.php index ab2140d..41cc6ce 100644 --- a/includes/server/activities/update.php +++ b/includes/server/activities/update.php @@ -1,5 +1,5 @@ 400 ) ); } - $existing_object = \objects\get_object_by_activitypub_id( $update_object['id'] ); + $existing_object = \pterotype\objects\get_object_by_activitypub_id( $update_object['id'] ); if ( is_wp_error( $existing_object ) ) { return $existing_object; } $updated_object = array_merge( $existing_object, $update_object ); - $updated_object = \objects\update_object( $updated_object ); + $updated_object = \pterotype\objects\update_object( $updated_object ); if ( is_wp_error( $updated_object ) ) { return $updated_object; } @@ -72,7 +72,7 @@ function handle_inbox( $actor_slug, $activity ) { if ( is_wp_error( $authorized ) ) { return $authorized; } - $object_row = \objects\upsert_object( $object ); + $object_row = \pterotype\objects\upsert_object( $object ); if ( is_wp_error( $object_row ) ) { return $object_row; } @@ -94,7 +94,7 @@ function check_authorization( $activity ) { } function make_update( $actor_slug, $object ) { - $actor = \actors\get_actor_by_slug( $actor_slug ); + $actor = \pterotype\actors\get_actor_by_slug( $actor_slug ); if ( is_wp_error( $actor ) ) { return $actor; } diff --git a/includes/server/actors.php b/includes/server/actors.php index 6172c9e..dca4ce9 100644 --- a/includes/server/actors.php +++ b/includes/server/actors.php @@ -1,5 +1,5 @@ get_rest_url( null, sprintf( '/pterotype/v1/actor/%s', PTEROTYPE_BLOG_ACTOR_SLUG ) ), - 'publicKeyPem' => \pgp\get_public_key( $actor_id ), + 'publicKeyPem' => \pterotype\pgp\get_public_key( $actor_id ), ), ); if ( has_custom_logo() ) { @@ -124,7 +124,7 @@ function get_user_actor( $user ) { 'owner' => get_rest_url( null, sprintf( '/pterotype/v1/actor/%s', $handle ) ), - 'publicKeyPem' => \pgp\get_public_key( $actor_id ), + 'publicKeyPem' => \pterotype\pgp\get_public_key( $actor_id ), ), ); return $actor; @@ -138,18 +138,18 @@ function initialize_actors() { foreach ( $user_slugs as $user_slug ) { create_actor( $user_slug, 'user' ); $actor_id = get_actor_id( $user_slug ); - $keys_created = \pgp\get_public_key( $actor_id ); + $keys_created = \pterotype\pgp\get_public_key( $actor_id ); if ( ! $keys_created ) { - $keys = \pgp\gen_key( $user_slug ); - \pgp\persist_key( $actor_id, $keys['publickey'], $keys['privatekey'] ); + $keys = \pterotype\pgp\gen_key( $user_slug ); + \pterotype\pgp\persist_key( $actor_id, $keys['publickey'], $keys['privatekey'] ); } } create_actor( PTEROTYPE_BLOG_ACTOR_SLUG, 'blog' ); $blog_actor_id = get_actor_id( PTEROTYPE_BLOG_ACTOR_SLUG ); - $keys_created = \pgp\get_public_key( $blog_actor_id ); + $keys_created = \pterotype\pgp\get_public_key( $blog_actor_id ); if ( ! $keys_created ) { - $keys = \pgp\gen_key( PTEROTYPE_BLOG_ACTOR_SLUG ); - \pgp\persist_key( $blog_actor_id, $keys['publickey'], $keys['privatekey'] ); + $keys = \pterotype\pgp\gen_key( PTEROTYPE_BLOG_ACTOR_SLUG ); + \pterotype\pgp\persist_key( $blog_actor_id, $keys['publickey'], $keys['privatekey'] ); } } diff --git a/includes/server/api.php b/includes/server/api.php index d7fc881..940f736 100644 --- a/includes/server/api.php +++ b/includes/server/api.php @@ -1,5 +1,5 @@ get_url_params()['actor']; - return \actors\get_actor_by_slug( $actor ); + return \pterotype\actors\get_actor_by_slug( $actor ); } function post_to_outbox( $request ) { $actor_slug = $request->get_url_params()['actor']; $activity = json_decode( $request->get_body(), true ); - return \outbox\handle_activity( $actor_slug, $activity ); + return \pterotype\outbox\handle_activity( $actor_slug, $activity ); } function get_outbox( $request ) { $actor_slug = $request->get_url_params()['actor']; - return \outbox\get_outbox( $actor_slug ); + return \pterotype\outbox\get_outbox( $actor_slug ); } function post_to_inbox( $request ) { $actor_slug = $request->get_url_params()['actor']; $activity = json_decode( $request->get_body(), true ); - return \inbox\handle_activity( $actor_slug, $activity ); + return \pterotype\inbox\handle_activity( $actor_slug, $activity ); } function get_inbox( $request ) { $actor_slug = $request->get_url_params()['actor']; - return \inbox\get_inbox( $actor_slug ); + return \pterotype\inbox\get_inbox( $actor_slug ); } function get_object( $request ) { $id = $request->get_url_params()['id']; - return \objects\get_object( $id ); + return \pterotype\objects\get_object( $id ); } function get_following( $request ) { $actor_slug = $request->get_url_params()['actor']; - return \following\get_following_collection( $actor_slug ); + return \pterotype\following\get_following_collection( $actor_slug ); } function get_followers( $request ) { $actor_slug = $request->get_url_params()['actor']; - return \followers\get_followers_collection( $actor_slug ); + return \pterotype\followers\get_followers_collection( $actor_slug ); } function get_likes( $request ) { $object_id = $request->get_url_params()['object']; - return \likes\get_likes_collection( $object_id ); + return \pterotype\likes\get_likes_collection( $object_id ); } function get_shares( $request ) { $object_id = $request->get_url_params()['object']; - return \shares\get_shares_collection( $object_id ); + return \pterotype\shares\get_shares_collection( $object_id ); } function user_can_post_to_outbox() { diff --git a/includes/server/async.php b/includes/server/async.php index fe90b0d..51d8bb3 100644 --- a/includes/server/async.php +++ b/includes/server/async.php @@ -1,5 +1,5 @@ set_method('POST'); $request->set_body( $activity ); @@ -144,12 +144,12 @@ function post_activity_to_inboxes( $actor_id, $activity, $recipients ) { ), 'data_format' => 'body', ); - \util\log( 'debug.html', 'Request:' ); - \util\log( 'debug.html', "POST $inbox" ); - \util\log_var( 'debug.html', $args ); + \pterotype\util\log( 'debug.html', 'Request:' ); + \pterotype\util\log( 'debug.html', "POST $inbox" ); + \pterotype\util\log_var( 'debug.html', $args ); $response = wp_remote_post( $inbox, $args ); - \util\log( 'debug.html', 'Response:' ); - \util\log_var( 'debug.html', $response ); + \pterotype\util\log( 'debug.html', 'Response:' ); + \pterotype\util\log_var( 'debug.html', $response ); } } } @@ -169,11 +169,11 @@ function get_signing_string( $inbox_url, $date_str ) { } function signature_header( $inbox_url, $actor_id, $date_str ) { - $actor = \actors\get_actor( $actor_id ); + $actor = \pterotype\actors\get_actor( $actor_id ); $key_id = $actor['publicKey']['id']; $signing_string = get_signing_string( $inbox_url, $date_str ); - \util\log_var( 'debug.html', $signing_string, false ); - $signature = \pgp\sign_data( $signing_string, $actor_id ); + \pterotype\util\log_var( 'debug.html', $signing_string, false ); + $signature = \pterotype\pgp\sign_data( $signing_string, $actor_id ); $headers = '(request-target) host date'; return "keyId=\"$key_id\",headers=\"$headers\",signature=\"$signature\""; } diff --git a/includes/server/followers.php b/includes/server/followers.php index 13ddb87..07e941d 100644 --- a/includes/server/followers.php +++ b/includes/server/followers.php @@ -1,5 +1,5 @@ 404 ) ); } - $follower = \util\dereference_object( $follower ); + $follower = \pterotype\util\dereference_object( $follower ); if ( !array_key_exists( 'id', $follower ) ) { return new \WP_Error( 'invalid_object', @@ -23,9 +23,9 @@ function add_follower( $actor_slug, $follower ) { array( 'status' => 400 ) ); } - $object_id = \objects\get_object_id( $follower['id'] ); + $object_id = \pterotype\objects\get_object_id( $follower['id'] ); if ( !$object_id ) { - $row = \objects\upsert_object( $follower ); + $row = \pterotype\objects\upsert_object( $follower ); $object_id = $row->id; } return $wpdb->query( $wpdb->prepare( @@ -36,7 +36,7 @@ function add_follower( $actor_slug, $follower ) { function remove_follower( $actor_slug, $follower ) { global $wpdb; - $actor_id = \actors\get_actor_id( $actor_slug ); + $actor_id = \pterotype\actors\get_actor_id( $actor_slug ); if ( !$actor_id ) { return new \WP_Error( 'not_found', @@ -44,7 +44,7 @@ function remove_follower( $actor_slug, $follower ) { array( 'status' => 404 ) ); } - $follower = \util\dereference_object( $follower ); + $follower = \pterotype\util\dereference_object( $follower ); if ( !array_key_exists( 'id', $follower ) ) { return new \WP_Error( 'invalid_object', @@ -52,7 +52,7 @@ function remove_follower( $actor_slug, $follower ) { array( 'status' => 400 ) ); } - $object_id = \objects\get_object_id( $follower['id'] ); + $object_id = \pterotype\objects\get_object_id( $follower['id'] ); if ( !$object_id ) { return new \WP_Error( 'not_found', @@ -71,7 +71,7 @@ function remove_follower( $actor_slug, $follower ) { function get_followers_collection( $actor_slug ) { global $wpdb; - $actor_id = \actors\get_actor_id( $actor_slug ); + $actor_id = \pterotype\actors\get_actor_id( $actor_slug ); if ( !$actor_id ) { return new \WP_Error( 'not_found', @@ -94,7 +94,7 @@ function get_followers_collection( $actor_slug ) { if ( !$followers ) { $followers = array(); } - $collection = \collections\make_ordered_collection( array_map( + $collection = \pterotype\collections\make_ordered_collection( array_map( function ( $result ) { return json_decode( $result['object'], true ); }, diff --git a/includes/server/following.php b/includes/server/following.php index 032df4f..88d3bdc 100644 --- a/includes/server/following.php +++ b/includes/server/following.php @@ -1,5 +1,5 @@ 404 ) @@ -62,7 +62,7 @@ function get_following_collection( $actor_slug ) { if ( !$objects ) { $objects = array(); } - $collection = \collections\make_ordered_collection( array_map( + $collection = \pterotype\collections\make_ordered_collection( array_map( function( $result ) { return json_decode( $result['object'], true ); }, diff --git a/includes/server/inbox.php b/includes/server/inbox.php index f246545..7fca103 100644 --- a/includes/server/inbox.php +++ b/includes/server/inbox.php @@ -7,7 +7,7 @@ When an Activity is received (i.e. POSTed) to an Actor's inbox, the server must: 2. Perform the side effects of receiving the Activity 3. Persist the activity in the actor's inbox (and the attached object, if necessary) */ -namespace inbox; +namespace pterotype\inbox; require_once plugin_dir_path( __FILE__ ) . 'objects.php'; require_once plugin_dir_path( __FILE__ ) . 'deliver.php'; @@ -28,7 +28,7 @@ function handle_activity( $actor_slug, $activity ) { // A good strategy would just be to make sure all activities are idempotent, e.g. // don't create multiple Accepts of the same Follow // TODO verify the authenticity of the activity - $activity = \util\dereference_object( $activity ); + $activity = \pterotype\util\dereference_object( $activity ); if ( !array_key_exists( 'type', $activity ) ) { return new \WP_Error( 'invalid_activity', @@ -43,28 +43,28 @@ function handle_activity( $actor_slug, $activity ) { } switch ( $activity['type'] ) { case 'Create': - $activity = \activities\create\handle_inbox( $actor_slug, $activity ); + $activity = \pterotype\activities\create\handle_inbox( $actor_slug, $activity ); break; case 'Update': - $activity = \activities\update\handle_inbox( $actor_slug, $activity ); + $activity = \pterotype\activities\update\handle_inbox( $actor_slug, $activity ); break; case 'Delete': - $activity = \activities\delete\handle_inbox( $actor_slug, $activity ); + $activity = \pterotype\activities\delete\handle_inbox( $actor_slug, $activity ); break; case 'Follow': - $activity = \activities\follow\handle_inbox( $actor_slug, $activity ); + $activity = \pterotype\activities\follow\handle_inbox( $actor_slug, $activity ); break; case 'Accept': - $activity = \activities\accept\handle_inbox( $actor_slug, $activity ); + $activity = \pterotype\activities\accept\handle_inbox( $actor_slug, $activity ); break; case 'Reject': - $activity = \activities\reject\handle_inbox( $actor_slug, $activity ); + $activity = \pterotype\activities\reject\handle_inbox( $actor_slug, $activity ); break; case 'Announce': - $activity = \activities\announce\handle_inbox( $actor_slug, $activity ); + $activity = \pterotype\activities\announce\handle_inbox( $actor_slug, $activity ); break; case 'Undo': - $activity = \activities\undo\handle_inbox( $actor_slug, $activity ); + $activity = \pterotype\activities\undo\handle_inbox( $actor_slug, $activity ); break; } if ( is_wp_error( $activity ) ) { @@ -78,7 +78,7 @@ function forward_activity( $actor_slug, $activity ) { if ( !array_key_exists( 'id', $activity ) ) { return; } - $seen_before = \objects\get_object_id( $activity['id'] ); + $seen_before = \pterotype\objects\get_object_id( $activity['id'] ); if ( $seen_before ) { return; } @@ -92,14 +92,14 @@ function forward_activity( $actor_slug, $activity ) { if ( count( $collections ) === 0 ) { return; } - \deliver\deliver_activity( $actor_slug, $activity ); + \pterotype\deliver\pterotype\deliver_activity( $actor_slug, $activity ); } function references_local_object( $object, $depth ) { if ( $depth === 12 ) { return false; } - if ( \objects\is_local_object( $object ) ) { + if ( \pterotype\objects\is_local_object( $object ) ) { return true; } $fields = array_intersect_key( @@ -114,11 +114,11 @@ function references_local_object( $object, $depth ) { if ( $result ) { return $result; } - $dereferenced = \util\dereference_object( $field_value ); + $dereferenced = \pterotype\util\dereference_object( $field_value ); if ( is_wp_error( $dereferenced ) ) { return false; } else { - return \objects\is_local_object( $dereferenced ); + return \pterotype\objects\is_local_object( $dereferenced ); } } return false; @@ -126,19 +126,19 @@ function references_local_object( $object, $depth ) { function persist_activity( $actor_slug, $activity ) { global $wpdb; - $row = \objects\upsert_object( $activity ); + $row = \pterotype\objects\upsert_object( $activity ); if ( is_wp_error( $row ) ) { return $row; } $activity = $row->object; - $activity_id = \objects\get_object_id( $activity['id'] ); + $activity_id = \pterotype\objects\get_object_id( $activity['id'] ); if ( !$activity_id ) { return new \WP_Error( 'db_error', __( 'Error retrieving activity id', 'pterotype' ) ); } - $actor_id = \actors\get_actor_id( $actor_slug ); + $actor_id = \pterotype\actors\get_actor_id( $actor_slug ); $seen_before = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}pterotype_inbox WHERE actor_id = %d AND object_id = %d", @@ -167,7 +167,7 @@ function persist_activity( $actor_slug, $activity ) { function get_inbox( $actor_slug ) { global $wpdb; - $actor_id = \actors\get_actor_id( $actor_slug ); + $actor_id = \pterotype\actors\get_actor_id( $actor_slug ); if ( !$actor_id ) { return new \WP_Error( 'not_found', @@ -187,7 +187,7 @@ function get_inbox( $actor_slug ) { ", $actor_id ), ARRAY_A ); - return \collections\make_ordered_collection( array_map( + return \pterotype\collections\make_ordered_collection( array_map( function ( $result ) { return json_decode( $result['object'], true ); }, diff --git a/includes/server/likes.php b/includes/server/likes.php index c0dd31a..c5aff87 100644 --- a/includes/server/likes.php +++ b/includes/server/likes.php @@ -1,5 +1,5 @@ insert_id; - $actor_id = \actors\get_actor_id( $actor_slug ); + $actor_id = \pterotype\actors\get_actor_id( $actor_slug ); $res = $wpdb->insert( $wpdb->prefix . 'pterotype_outbox', array( 'actor_id' => $actor_id, 'object_id' => $activity_id, @@ -186,6 +186,6 @@ function persist_activity( $actor_slug, $activity ) { } function wrap_object_in_create( $actor_slug, $object ) { - return \activities\create\make_create( $actor_slug, $object ); + return \pterotype\activities\create\make_create( $actor_slug, $object ); } ?> diff --git a/includes/server/shares.php b/includes/server/shares.php index 7bf70cd..41c412c 100644 --- a/includes/server/shares.php +++ b/includes/server/shares.php @@ -1,5 +1,5 @@