PluginProbe
ActivityPub / 2.0.1
ActivityPub v2.0.1
9.3.1 9.3.0 9.2.2 9.2.1 9.2.0 9.1.0 9.0.2 9.0.1 9.0.0 8.3.0 8.2.1 8.2.0 8.1.1 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.2.0 1.3.0 2.0.0 2.0.1 2.1.0 2.1.1 All 160 releases
activitypub / includes / model / class-post.php

class-post.php in ActivityPub 2.0.1, at includes/model/class-post.php

133 lines 2.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Activitypub\Model;
3
4 use Activitypub\Collection\Users;
5 use Activitypub\Transformer\Post as Post_Transformer;
6
7 /**
8 * ActivityPub Post Class
9 *
10 * @author Matthias Pfefferle
11 */
12 class Post {
13 /**
14 * The \Activitypub\Activity\Base_Object object.
15 *
16 * @var \Activitypub\Activity\Base_Object
17 */
18 protected $object;
19
20 /**
21 * The WordPress Post Object.
22 *
23 * @var WP_Post
24 */
25 private $post;
26
27 /**
28 * Constructor
29 *
30 * @param WP_Post $post
31 * @param int $post_author
32 */
33 // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed, VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
34 public function __construct( $post, $post_author = null ) {
35 _deprecated_function( __CLASS__, '1.0.0', '\Activitypub\Transformer\Post' );
36
37 $this->post = $post;
38 $this->object = Post_Transformer::transform( $post )->to_object();
39 }
40
41 /**
42 * Returns the User ID.
43 *
44 * @return int the User ID.
45 */
46 public function get_user_id() {
47 return apply_filters( 'activitypub_post_user_id', $this->post->post_author, $this->post );
48 }
49
50 /**
51 * Converts this Object into an Array.
52 *
53 * @return array the array representation of a Post.
54 */
55 public function to_array() {
56 return \apply_filters( 'activitypub_post', $this->object->to_array(), $this->post );
57 }
58
59 /**
60 * Returns the Actor of this Object.
61 *
62 * @return string The URL of the Actor.
63 */
64 public function get_actor() {
65 $user = Users::get_by_id( $this->get_user_id() );
66
67 return $user->get_url();
68 }
69
70 /**
71 * Converts this Object into a JSON String
72 *
73 * @return string
74 */
75 public function to_json() {
76 return \wp_json_encode( $this->to_array(), \JSON_HEX_TAG | \JSON_HEX_AMP | \JSON_HEX_QUOT );
77 }
78
79 /**
80 * Returns the URL of an Activity Object
81 *
82 * @return string
83 */
84 public function get_url() {
85 return $this->object->get_url();
86 }
87
88 /**
89 * Returns the ID of an Activity Object
90 *
91 * @return string
92 */
93 public function get_id() {
94 return $this->object->get_id();
95 }
96
97 /**
98 * Returns a list of Image Attachments
99 *
100 * @return array
101 */
102 public function get_attachments() {
103 return $this->object->get_attachment();
104 }
105
106 /**
107 * Returns a list of Tags, used in the Post
108 *
109 * @return array
110 */
111 public function get_tags() {
112 return $this->object->get_tag();
113 }
114
115 /**
116 * Returns the as2 object-type for a given post
117 *
118 * @return string the object-type
119 */
120 public function get_object_type() {
121 return $this->object->get_type();
122 }
123
124 /**
125 * Returns the content for the ActivityPub Item.
126 *
127 * @return string the content
128 */
129 public function get_content() {
130 return $this->object->get_content();
131 }
132 }
133