diff --git a/includes/class-activity-dispatcher.php b/includes/class-activity-dispatcher.php index 16194ea..90a286c 100644 --- a/includes/class-activity-dispatcher.php +++ b/includes/class-activity-dispatcher.php @@ -5,7 +5,7 @@ use WP_Post; use Activitypub\Activity\Activity; use Activitypub\Collection\Users; use Activitypub\Collection\Followers; -use Activitypub\Transformer\Transformers_Manager; +use Activitypub\Transformer\Transformer_Factory; use function Activitypub\is_single_user; use function Activitypub\is_user_disabled; @@ -65,7 +65,7 @@ class Activity_Dispatcher { return; } - $object = Transformers_Manager::instance()->transform( $wp_post ); + $object = Transformer_Factory::instance()->transform( $wp_post ); $activity = new Activity(); $activity->set_type( $type ); @@ -101,7 +101,7 @@ class Activity_Dispatcher { return; } - $object = Transformers_Manager::instance()->transform( $wp_post ); + $object = Transformer_Factory::instance()->transform( $wp_post ); $activity = new Activity(); $activity->set_type( 'Announce' ); diff --git a/includes/rest/class-collection.php b/includes/rest/class-collection.php index 1b2b0ec..78b068e 100644 --- a/includes/rest/class-collection.php +++ b/includes/rest/class-collection.php @@ -4,7 +4,7 @@ namespace Activitypub\Rest; use WP_Error; use WP_REST_Server; use WP_REST_Response; -use Activitypub\Transformer\Transformers_Manager; +use Activitypub\Transformer\Transformer_Factory; use Activitypub\Activity\Activity; use Activitypub\Collection\Users as User_Collection; @@ -168,7 +168,7 @@ class Collection { ); foreach ( $posts as $post ) { - $response['orderedItems'][] = Transformers_Manager::instance()->transform( $post ); + $response['orderedItems'][] = Transformer_Factory::instance()->transform( $post ); } $rest_response = new WP_REST_Response( $response, 200 ); diff --git a/includes/rest/class-outbox.php b/includes/rest/class-outbox.php index 73a4335..f6ac487 100644 --- a/includes/rest/class-outbox.php +++ b/includes/rest/class-outbox.php @@ -5,7 +5,7 @@ use stdClass; use WP_Error; use WP_REST_Server; use WP_REST_Response; -use Activitypub\Transformer\Transformers_Manager; +use Activitypub\Transformer\Transformer_Factory; use Activitypub\Activity\Activity; use Activitypub\Collection\Users as User_Collection; @@ -105,7 +105,7 @@ class Outbox { ); foreach ( $posts as $post ) { - $object = \Activitypub\Transformer\Transformers_Manager::instance()->transform( $post ); + $object = \Activitypub\Transformer\Transformer_Factory::instance()->transform( $post ); $activity = new Activity(); $activity->set_type( 'Create' ); $activity->set_context( null ); diff --git a/includes/transformer/class-post.php b/includes/transformer/class-post.php index dd89ea5..068bf63 100644 --- a/includes/transformer/class-post.php +++ b/includes/transformer/class-post.php @@ -116,17 +116,20 @@ class Post extends Base { * @return \Activitypub\Activity\Base_Object The ActivityPub Object */ public function transform() { + if ( ! $this->wp_post ) { + return; + } $object = new Base_Object(); $object->set_id( $this->get_id() ); $object->set_url( $this->get_url() ); $object->set_type( $this->get_object_type() ); - $published = \strtotime( $wp_post->post_date_gmt ); + $published = \strtotime( $this->$wp_post->post_date_gmt ); $object->set_published( \gmdate( 'Y-m-d\TH:i:s\Z', $published ) ); - $updated = \strtotime( $wp_post->post_modified_gmt ); + $updated = \strtotime( $this->$wp_post->post_modified_gmt ); if ( $updated > $published ) { $object->set_updated( \gmdate( 'Y-m-d\TH:i:s\Z', $updated ) ); @@ -135,7 +138,7 @@ class Post extends Base { $object->set_attributed_to( $this->get_attributed_to() ); $object->set_content( $this->get_content() ); $object->set_content_map( $this->get_content_map ); - $path = sprintf( 'users/%d/followers', intval( $wp_post->post_author ) ); + $path = sprintf( 'users/%d/followers', intval( $this->$wp_post->post_author ) ); $object->set_to( array( diff --git a/includes/transformer/class-transformers-manager.php b/includes/transformer/class-transformer-factory.php similarity index 98% rename from includes/transformer/class-transformers-manager.php rename to includes/transformer/class-transformer-factory.php index 3bef89c..65b07da 100644 --- a/includes/transformer/class-transformers-manager.php +++ b/includes/transformer/class-transformer-factory.php @@ -26,7 +26,7 @@ if ( ! defined( 'ABSPATH' ) ) { * * @since version_number_transformer_management_placeholder */ -class Transformers_Manager { +class Transformer_Factory { const DEFAULT_TRANSFORMER_MAPPING = array( 'post' => ACTIVITYPUB_DEFAULT_TRANSFORMER, 'page' => ACTIVITYPUB_DEFAULT_TRANSFORMER, @@ -229,7 +229,7 @@ class Transformers_Manager { * * @since version_number_transformer_management_placeholder * - * @param Transformers_Manager $this The widgets manager. + * @param Transformer_Factory $this The widgets manager. */ do_action( 'activitypub_transformers_register', $this ); } diff --git a/templates/post-json.php b/templates/post-json.php index cc28114..996d229 100644 --- a/templates/post-json.php +++ b/templates/post-json.php @@ -2,7 +2,7 @@ // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited $post = \get_post(); -$object = \Activitypub\Transformer\Transformers_Manager::instance()->transform( $post ); +$object = \Activitypub\Transformer\Transformer_Factory::instance()->transform( $post ); $json = \array_merge( array( '@context' => \Activitypub\get_context() ), $object->to_array() ); diff --git a/templates/settings.php b/templates/settings.php index 19535b4..76da57e 100644 --- a/templates/settings.php +++ b/templates/settings.php @@ -237,7 +237,7 @@ return $object->name; }, $all_public_post_types); - $transformer_manager = \Activitypub\Transformer\Transformers_Manager::instance(); + $transformer_manager = \Activitypub\Transformer\Transformer_Factory::instance(); $transformers = $transformer_manager->get_transformers(); ?> diff --git a/tests/test-class-activitypub-activity.php b/tests/test-class-activitypub-activity.php index 9531c78..4748106 100644 --- a/tests/test-class-activitypub-activity.php +++ b/tests/test-class-activitypub-activity.php @@ -18,7 +18,7 @@ class Test_Activitypub_Activity extends WP_UnitTestCase { ); $wp_post = get_post( $post ); - $activitypub_post = \Activitypub\Transformer\Transformers_Manager::instance()->transform(); + $activitypub_post = \Activitypub\Transformer\Transformer_Factory::instance()->transform(); $activitypub_activity = new \Activitypub\Activity\Activity(); $activitypub_activity->set_type( 'Create' ); diff --git a/tests/test-class-activitypub-post.php b/tests/test-class-activitypub-post.php index 038c115..b91a6d2 100644 --- a/tests/test-class-activitypub-post.php +++ b/tests/test-class-activitypub-post.php @@ -10,13 +10,13 @@ class Test_Activitypub_Post extends WP_UnitTestCase { $permalink = \get_permalink( $post ); - $activitypub_post = \Activitypub\Transformer\Transformers_Manager::instance()->transform( get_post( $post ) ); + $activitypub_post = \Activitypub\Transformer\Transformer_Factory::instance()->transform( get_post( $post ) ); $this->assertEquals( $permalink, $activitypub_post->get_id() ); \wp_trash_post( $post ); - $activitypub_post = \Activitypub\Transformer\Transformers_Manager::instance()->transform( get_post( $post ) ); + $activitypub_post = \Activitypub\Transformer\Transformer_Factory::instance()->transform( get_post( $post ) ); $this->assertEquals( $permalink, $activitypub_post->get_id() ); diff --git a/tests/test-class-activitypub-rest-post-signature-verification.php b/tests/test-class-activitypub-rest-post-signature-verification.php index c988f82..98e7855 100644 --- a/tests/test-class-activitypub-rest-post-signature-verification.php +++ b/tests/test-class-activitypub-rest-post-signature-verification.php @@ -10,7 +10,7 @@ class Test_Activitypub_Signature_Verification extends WP_UnitTestCase { ) ); $remote_actor = \get_author_posts_url( 2 ); - $activitypub_post = \Activitypub\Transformer\Transformers_Manager::instance()->transform( get_post( $post ) ); + $activitypub_post = \Activitypub\Transformer\Transformer_Factory::instance()->transform( get_post( $post ) ); $activitypub_activity = new Activitypub\Activity\Activity( 'Create' ); $activitypub_activity->set_type( 'Create' ); $activitypub_activity->set_object( $activitypub_post ); @@ -82,7 +82,7 @@ class Test_Activitypub_Signature_Verification extends WP_UnitTestCase { ); $remote_actor = \get_author_posts_url( 2 ); $remote_actor_inbox = Activitypub\get_rest_url_by_path( '/inbox' ); - $activitypub_post = \Activitypub\Transformer\Transformers_Manager::instance()->transform( get_post( $post ) ); + $activitypub_post = \Activitypub\Transformer\Transformer_Factory::instance()->transform( get_post( $post ) ); $activitypub_activity = new Activitypub\Activity\Activity(); $activitypub_activity->set_type( 'Create' ); $activitypub_activity->set_object( $activitypub_post );