From 338c63d3e1a746a47bb940ac52d2176fc9c3828b Mon Sep 17 00:00:00 2001 From: Matthias Pfefferle Date: Tue, 1 Aug 2023 18:37:16 +0200 Subject: [PATCH] re-add post model (#386) --- includes/model/class-post.php | 131 ++++++++++++++++++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 includes/model/class-post.php diff --git a/includes/model/class-post.php b/includes/model/class-post.php new file mode 100644 index 0000000..d967ad9 --- /dev/null +++ b/includes/model/class-post.php @@ -0,0 +1,131 @@ +post = $post; + $this->object = Post_Transformer::transform( $post )->to_object(); + } + + /** + * Returns the User ID. + * + * @return int the User ID. + */ + public function get_user_id() { + return apply_filters( 'activitypub_post_user_id', $this->post->post_author, $this->post ); + } + + /** + * Converts this Object into an Array. + * + * @return array the array representation of a Post. + */ + public function to_array() { + return \apply_filters( 'activitypub_post', $this->object->to_array(), $this->post ); + } + + /** + * Returns the Actor of this Object. + * + * @return string The URL of the Actor. + */ + public function get_actor() { + $user = User_Factory::get_by_id( $this->get_user_id() ); + + return $user->get_url(); + } + + /** + * Converts this Object into a JSON String + * + * @return string + */ + public function to_json() { + return \wp_json_encode( $this->to_array(), \JSON_HEX_TAG | \JSON_HEX_AMP | \JSON_HEX_QUOT ); + } + + /** + * Returns the URL of an Activity Object + * + * @return string + */ + public function get_url() { + return $this->object->get_url(); + } + + /** + * Returns the ID of an Activity Object + * + * @return string + */ + public function get_id() { + return $this->object->get_id(); + } + + /** + * Returns a list of Image Attachments + * + * @return array + */ + public function get_attachments() { + return $this->object->get_attachment(); + } + + /** + * Returns a list of Tags, used in the Post + * + * @return array + */ + public function get_tags() { + return $this->object->get_tag(); + } + + /** + * Returns the as2 object-type for a given post + * + * @return string the object-type + */ + public function get_object_type() { + return $this->object->get_type(); + } + + /** + * Returns the content for the ActivityPub Item. + * + * @return string the content + */ + public function get_content() { + return $this->object->get_content(); + } +}