PluginProbe
ActivityPub / 2.5.0
ActivityPub v2.5.0
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.5.0, at includes/model/class-post.php

137 lines 2.7 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\Factory;
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( __METHOD__, '1.0.0', '\Activitypub\Transformer\Factory::get_transformer' );
36
37 $transformer = Factory::get_transformer( $post );
38
39 if ( ! \is_wp_error( $transformer ) ) {
40 $this->post = $post;
41 $this->object = $transformer->to_object();
42 }
43 }
44
45 /**
46 * Returns the User ID.
47 *
48 * @return int the User ID.
49 */
50 public function get_user_id() {
51 return apply_filters( 'activitypub_post_user_id', $this->post->post_author, $this->post );
52 }
53
54 /**
55 * Converts this Object into an Array.
56 *
57 * @return array the array representation of a Post.
58 */
59 public function to_array() {
60 return \apply_filters( 'activitypub_post', $this->object->to_array(), $this->post );
61 }
62
63 /**
64 * Returns the Actor of this Object.
65 *
66 * @return string The URL of the Actor.
67 */
68 public function get_actor() {
69 $user = Users::get_by_id( $this->get_user_id() );
70
71 return $user->get_url();
72 }
73
74 /**
75 * Converts this Object into a JSON String
76 *
77 * @return string
78 */
79 public function to_json() {
80 return \wp_json_encode( $this->to_array(), \JSON_HEX_TAG | \JSON_HEX_AMP | \JSON_HEX_QUOT );
81 }
82
83 /**
84 * Returns the URL of an Activity Object
85 *
86 * @return string
87 */
88 public function get_url() {
89 return $this->object->get_url();
90 }
91
92 /**
93 * Returns the ID of an Activity Object
94 *
95 * @return string
96 */
97 public function get_id() {
98 return $this->object->get_id();
99 }
100
101 /**
102 * Returns a list of Image Attachments
103 *
104 * @return array
105 */
106 public function get_attachments() {
107 return $this->object->get_attachment();
108 }
109
110 /**
111 * Returns a list of Tags, used in the Post
112 *
113 * @return array
114 */
115 public function get_tags() {
116 return $this->object->get_tag();
117 }
118
119 /**
120 * Returns the as2 object-type for a given post
121 *
122 * @return string the object-type
123 */
124 public function get_object_type() {
125 return $this->object->get_type();
126 }
127
128 /**
129 * Returns the content for the ActivityPub Item.
130 *
131 * @return string the content
132 */
133 public function get_content() {
134 return $this->object->get_content();
135 }
136 }
137