2020-04-07 13:03:04 +00:00
|
|
|
<?php
|
|
|
|
namespace Activitypub\Model;
|
|
|
|
|
2024-02-08 12:31:25 +00:00
|
|
|
use Activitypub\Collection\Users;
|
2023-10-22 22:20:53 +00:00
|
|
|
use Activitypub\Transformer\Post as Post_Transformer;
|
|
|
|
|
2020-04-07 13:03:04 +00:00
|
|
|
/**
|
|
|
|
* ActivityPub Post Class
|
|
|
|
*
|
|
|
|
* @author Matthias Pfefferle
|
|
|
|
*/
|
|
|
|
class Post {
|
2023-03-17 22:33:51 +00:00
|
|
|
/**
|
2023-10-22 22:20:53 +00:00
|
|
|
* The \Activitypub\Activity\Base_Object object.
|
2023-03-17 22:33:51 +00:00
|
|
|
*
|
2023-10-22 22:20:53 +00:00
|
|
|
* @var \Activitypub\Activity\Base_Object
|
2023-03-17 22:33:51 +00:00
|
|
|
*/
|
2023-10-22 22:20:53 +00:00
|
|
|
protected $object;
|
2023-03-17 22:33:51 +00:00
|
|
|
|
|
|
|
/**
|
2023-10-22 22:20:53 +00:00
|
|
|
* The WordPress Post Object.
|
2023-03-17 22:33:51 +00:00
|
|
|
*
|
2023-10-22 22:20:53 +00:00
|
|
|
* @var WP_Post
|
2023-03-17 22:33:51 +00:00
|
|
|
*/
|
2023-10-22 22:20:53 +00:00
|
|
|
private $post;
|
2023-03-17 22:33:51 +00:00
|
|
|
|
|
|
|
/**
|
2023-10-22 22:20:53 +00:00
|
|
|
* Constructor
|
2023-03-17 22:33:51 +00:00
|
|
|
*
|
2023-10-22 22:20:53 +00:00
|
|
|
* @param WP_Post $post
|
|
|
|
* @param int $post_author
|
2023-03-17 22:33:51 +00:00
|
|
|
*/
|
2023-10-22 22:20:53 +00:00
|
|
|
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed, VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
|
|
|
|
public function __construct( $post, $post_author = null ) {
|
|
|
|
_deprecated_function( __CLASS__, '1.0.0', '\Activitypub\Transformer\Post' );
|
2023-03-17 22:33:51 +00:00
|
|
|
|
2023-10-22 22:20:53 +00:00
|
|
|
$this->post = $post;
|
|
|
|
$this->object = Post_Transformer::transform( $post )->to_object();
|
|
|
|
}
|
2020-04-07 13:03:04 +00:00
|
|
|
|
2023-03-17 22:33:51 +00:00
|
|
|
/**
|
2023-10-22 22:20:53 +00:00
|
|
|
* Returns the User ID.
|
2023-03-17 22:33:51 +00:00
|
|
|
*
|
2023-10-22 22:20:53 +00:00
|
|
|
* @return int the User ID.
|
2023-03-17 22:33:51 +00:00
|
|
|
*/
|
2023-10-22 22:20:53 +00:00
|
|
|
public function get_user_id() {
|
|
|
|
return apply_filters( 'activitypub_post_user_id', $this->post->post_author, $this->post );
|
|
|
|
}
|
2020-04-07 13:03:04 +00:00
|
|
|
|
2023-03-17 22:33:51 +00:00
|
|
|
/**
|
2023-10-22 22:20:53 +00:00
|
|
|
* Converts this Object into an Array.
|
2023-03-17 22:33:51 +00:00
|
|
|
*
|
2023-10-22 22:20:53 +00:00
|
|
|
* @return array the array representation of a Post.
|
2023-03-17 22:33:51 +00:00
|
|
|
*/
|
2023-10-22 22:20:53 +00:00
|
|
|
public function to_array() {
|
|
|
|
return \apply_filters( 'activitypub_post', $this->object->to_array(), $this->post );
|
2020-04-07 13:03:04 +00:00
|
|
|
}
|
|
|
|
|
2023-03-17 22:33:51 +00:00
|
|
|
/**
|
2023-10-22 22:20:53 +00:00
|
|
|
* Returns the Actor of this Object.
|
2023-03-17 22:33:51 +00:00
|
|
|
*
|
2023-10-22 22:20:53 +00:00
|
|
|
* @return string The URL of the Actor.
|
2023-03-17 22:33:51 +00:00
|
|
|
*/
|
2023-10-22 22:20:53 +00:00
|
|
|
public function get_actor() {
|
2024-02-08 12:31:25 +00:00
|
|
|
$user = Users::get_by_id( $this->get_user_id() );
|
2020-12-25 19:23:08 +00:00
|
|
|
|
2023-10-22 22:20:53 +00:00
|
|
|
return $user->get_url();
|
2020-04-07 13:03:04 +00:00
|
|
|
}
|
|
|
|
|
2023-03-17 22:33:51 +00:00
|
|
|
/**
|
2023-10-22 22:20:53 +00:00
|
|
|
* Converts this Object into a JSON String
|
2023-03-17 22:33:51 +00:00
|
|
|
*
|
2023-10-22 22:20:53 +00:00
|
|
|
* @return string
|
2023-03-17 22:33:51 +00:00
|
|
|
*/
|
2023-10-22 22:20:53 +00:00
|
|
|
public function to_json() {
|
|
|
|
return \wp_json_encode( $this->to_array(), \JSON_HEX_TAG | \JSON_HEX_AMP | \JSON_HEX_QUOT );
|
2020-04-07 13:03:04 +00:00
|
|
|
}
|
|
|
|
|
2023-03-17 22:33:51 +00:00
|
|
|
/**
|
2023-10-22 22:20:53 +00:00
|
|
|
* Returns the URL of an Activity Object
|
2023-03-17 22:33:51 +00:00
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2023-10-22 22:20:53 +00:00
|
|
|
public function get_url() {
|
|
|
|
return $this->object->get_url();
|
2020-12-25 19:23:08 +00:00
|
|
|
}
|
|
|
|
|
2023-03-17 22:33:51 +00:00
|
|
|
/**
|
|
|
|
* Returns the ID of an Activity Object
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function get_id() {
|
2023-10-22 22:20:53 +00:00
|
|
|
return $this->object->get_id();
|
2020-04-07 13:03:04 +00:00
|
|
|
}
|
|
|
|
|
2023-03-17 22:33:51 +00:00
|
|
|
/**
|
|
|
|
* Returns a list of Image Attachments
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function get_attachments() {
|
2023-10-22 22:20:53 +00:00
|
|
|
return $this->object->get_attachment();
|
2020-04-07 13:03:04 +00:00
|
|
|
}
|
|
|
|
|
2023-03-17 22:33:51 +00:00
|
|
|
/**
|
|
|
|
* Returns a list of Tags, used in the Post
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function get_tags() {
|
2023-10-22 22:20:53 +00:00
|
|
|
return $this->object->get_tag();
|
2020-04-07 13:03:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the as2 object-type for a given post
|
|
|
|
*
|
|
|
|
* @return string the object-type
|
|
|
|
*/
|
2023-03-17 22:33:51 +00:00
|
|
|
public function get_object_type() {
|
2023-10-22 22:20:53 +00:00
|
|
|
return $this->object->get_type();
|
2020-04-07 13:03:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2023-03-17 22:33:51 +00:00
|
|
|
* Returns the content for the ActivityPub Item.
|
2020-04-07 13:03:04 +00:00
|
|
|
*
|
2023-03-17 22:33:51 +00:00
|
|
|
* @return string the content
|
2020-04-07 13:03:04 +00:00
|
|
|
*/
|
2023-03-17 22:33:51 +00:00
|
|
|
public function get_content() {
|
2023-10-22 22:20:53 +00:00
|
|
|
return $this->object->get_content();
|
2020-04-07 13:03:04 +00:00
|
|
|
}
|
|
|
|
}
|