query( " CREATE TABLE IF NOT EXISTS activitypub_outbox ( id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, actor VARCHAR(128) NOT NULL, activity TEXT NOT NULL ); " ); } function persist_activity( $actor, $activity ) { // TODO validate activity and actor; handle errors global $wpdb; $activity_json = wp_json_encode($activity); $wpdb->insert( 'activitypub_outbox', array( "actor" => $actor, "activity" => $activity_json, ) ); $persisted = json_decode( $wpdb->get_var( sprintf( "SELECT activity FROM activitypub_outbox WHERE id = %d", $wpdb->insert_id ) ) ); $response = new WP_REST_Response( $persisted ); $response->set_status( 201 ); // TODO set location header of response to created object URL return $response; } function handle_activity( $actor, $activity ) { if ( !array_key_exists( "type", $activity ) ) { return new WP_Error( 'invalid_activity', __( 'Invalid activity', 'activitypub' ), array( 'status' => 400 ) ); } switch ( $activity["type"] ) { case "Create": break; case "Update": break; case "Delete": break; case "Follow": break; case "Add": break; case "Remove": break; case "Like": break; case "Block": break; case "Undo": break; default: // handle wrapping object in Create activity break; } } ?>