|
4 | 4 | use WP_Post; |
5 | 5 | use Activitypub\Shortcodes; |
6 | 6 | use Activitypub\Model\Blog; |
7 | | -use Activitypub\Transformer\Base; |
8 | 7 | use Activitypub\Collection\Users; |
| 8 | +use Activitypub\Transformer\Base; |
9 | 9 |
|
10 | 10 | use function Activitypub\esc_hashtag; |
11 | 11 | use function Activitypub\is_single_user; |
12 | 12 | use function Activitypub\get_enclosures; |
13 | | -use function Activitypub\generate_post_summary; |
14 | | -use function Activitypub\get_rest_url_by_path; |
15 | 13 | use function Activitypub\site_supports_blocks; |
| 14 | +use function Activitypub\get_rest_url_by_path; |
| 15 | +use function Activitypub\is_user_type_disabled; |
| 16 | +use function Activitypub\generate_post_summary; |
16 | 17 |
|
17 | 18 | /** |
18 | 19 | * WordPress Post Transformer |
|
25 | 26 | * - Activitypub\Activity\Base_Object |
26 | 27 | */ |
27 | 28 | class Post extends Base { |
| 29 | + /** |
| 30 | + * The User as Actor Object. |
| 31 | + * |
| 32 | + * @var Activitypub\Activity\Actor |
| 33 | + */ |
| 34 | + private $actor_object = null; |
| 35 | + |
28 | 36 | /** |
29 | 37 | * Returns the ID of the WordPress Post. |
30 | 38 | * |
@@ -71,18 +79,46 @@ public function to_object() { |
71 | 79 | $this->get_locale() => $this->get_content(), |
72 | 80 | ) |
73 | 81 | ); |
74 | | - $path = sprintf( 'actors/%d/followers', intval( $post->post_author ) ); |
75 | 82 |
|
76 | 83 | $object->set_to( |
77 | 84 | array( |
78 | 85 | 'https://www.w3.org/ns/activitystreams#Public', |
79 | | - get_rest_url_by_path( $path ), |
| 86 | + $this->get_actor_object()->get_followers(), |
80 | 87 | ) |
81 | 88 | ); |
82 | 89 |
|
83 | 90 | return $object; |
84 | 91 | } |
85 | 92 |
|
| 93 | + /** |
| 94 | + * Returns the User-Object of the Author of the Post. |
| 95 | + * |
| 96 | + * If `single_user` mode is enabled, the Blog-User is returned. |
| 97 | + * |
| 98 | + * @return Activitypub\Activity\Actor The User-Object. |
| 99 | + */ |
| 100 | + protected function get_actor_object() { |
| 101 | + if ( $this->actor_object ) { |
| 102 | + return $this->actor_object; |
| 103 | + } |
| 104 | + |
| 105 | + $blog_user = new Blog(); |
| 106 | + $this->actor_object = $blog_user; |
| 107 | + |
| 108 | + if ( is_single_user() ) { |
| 109 | + return $blog_user; |
| 110 | + } |
| 111 | + |
| 112 | + $user = Users::get_by_id( $this->wp_object->post_author ); |
| 113 | + |
| 114 | + if ( $user && ! is_wp_error( $user ) ) { |
| 115 | + $this->actor_object = $user; |
| 116 | + return $user; |
| 117 | + } |
| 118 | + |
| 119 | + return $blog_user; |
| 120 | + } |
| 121 | + |
86 | 122 | /** |
87 | 123 | * Returns the ID of the Post. |
88 | 124 | * |
@@ -128,19 +164,7 @@ public function get_url() { |
128 | 164 | * @return string The User-URL. |
129 | 165 | */ |
130 | 166 | protected function get_attributed_to() { |
131 | | - $blog_user = new Blog(); |
132 | | - |
133 | | - if ( is_single_user() ) { |
134 | | - return $blog_user->get_url(); |
135 | | - } |
136 | | - |
137 | | - $user = Users::get_by_id( $this->wp_object->post_author ); |
138 | | - |
139 | | - if ( $user && ! is_wp_error( $user ) ) { |
140 | | - return $user->get_url(); |
141 | | - } |
142 | | - |
143 | | - return $blog_user->get_url(); |
| 167 | + return $this->get_actor_object()->get_url(); |
144 | 168 | } |
145 | 169 |
|
146 | 170 | /** |
|
0 commit comments