Skip to content

Commit 9f09bfb

Browse files
committed
re-add Post model
workaround for #639
1 parent e23c65f commit 9f09bfb

File tree

1 file changed

+131
-0
lines changed

1 file changed

+131
-0
lines changed

includes/model/class-post.php

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

0 commit comments

Comments
 (0)