PluginProbe
ActivityPub / 5.7.0
ActivityPub v5.7.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
← All changes | includes/rest/class-replies-controller.php +12 -21 8.2.15.7.0 View file →
@@ -7,13 +7,12 @@
7 7
8 8 namespace Activitypub\Rest;
9 9
10 10 use Activitypub\Activity\Base_Object;
11 +use Activitypub\Collection\Replies;
11 12 use Activitypub\Collection\Interactions;
12 -use Activitypub\Collection\Replies;
13 13
14 14 use function Activitypub\get_rest_url_by_path;
15 -use function Activitypub\is_post_publicly_queryable;
16 15
17 16 /**
18 17 * ActivityPub Replies_Controller class.
19 18 */
@@ -30,9 +29,9 @@
30 29 * The base of this controller's route.
31 30 *
32 31 * @var string
33 32 */
34 - protected $rest_base = '(?P<object_type>[\w\-\.]+)s/(?P<id>[\d]+)/(?P<type>[\w\-\.]+)';
33 + protected $rest_base = '(?P<object_type>[\w\-\.]+)s/(?P<id>[\w\-\.]+)/(?P<type>[\w\-\.]+)';
35 34
36 35 /**
37 36 * Register routes.
38 37 */
@@ -49,10 +48,9 @@
49 48 'required' => true,
50 49 ),
51 50 'id' => array(
52 51 'description' => 'The ID of the object.',
53 - 'type' => 'integer',
54 - 'minimum' => 1,
52 + 'type' => 'string',
55 53 'required' => true,
56 54 ),
57 55 'type' => array(
58 56 'description' => 'The type of collection to query.',
@@ -91,24 +89,13 @@
91 89 $id = (int) $request->get_param( 'id' );
92 90
93 91 if ( 'comment' === $object_type ) {
94 92 $wp_object = \get_comment( $id );
95 -
96 - /*
97 - * A comment inherits the visibility of its parent post. Reject
98 - * collections for comments whose parent post is not currently
99 - * publicly queryable, so we don't leak metadata for private,
100 - * draft, password-protected, or local-only posts — including
101 - * posts that were once federated and have since been made
102 - * non-public.
103 - */
104 - $publicly_queryable = $wp_object && is_post_publicly_queryable( $wp_object->comment_post_ID );
105 93 } else {
106 - $wp_object = \get_post( $id );
107 - $publicly_queryable = $wp_object && is_post_publicly_queryable( $wp_object );
94 + $wp_object = \get_post( $id );
108 95 }
109 96
110 - if ( ! $publicly_queryable ) {
97 + if ( ! isset( $wp_object ) || \is_wp_error( $wp_object ) ) {
111 98 return new \WP_Error(
112 99 'activitypub_replies_collection_does_not_exist',
113 100 \sprintf(
114 101 // translators: %s: The type (post, comment, etc.) for which no replies collection exists.
@@ -179,13 +166,15 @@
179 166 } else {
180 167 $likes = 0;
181 168 }
182 169
183 - return array(
170 + $response = array(
184 171 'id' => get_rest_url_by_path( sprintf( 'posts/%d/likes', $wp_object->ID ) ),
185 172 'type' => 'Collection',
186 173 'totalItems' => $likes,
187 174 );
175 +
176 + return $response;
188 177 }
189 178
190 179 /**
191 180 * Retrieves a collection of shares.
@@ -196,18 +185,20 @@
196 185 * @return array Response collection of shares.
197 186 */
198 187 public function get_shares( $request, $wp_object ) {
199 188 if ( $wp_object instanceof \WP_Post ) {
200 - $shares = Interactions::count_by_type( $wp_object->ID, 'repost' ) + Interactions::count_by_type( $wp_object->ID, 'quote' );
189 + $shares = Interactions::count_by_type( $wp_object->ID, 'repost' );
201 190 } else {
202 191 $shares = 0;
203 192 }
204 193
205 - return array(
194 + $response = array(
206 195 'id' => get_rest_url_by_path( sprintf( 'posts/%d/shares', $wp_object->ID ) ),
207 196 'type' => 'Collection',
208 197 'totalItems' => $shares,
209 198 );
199 +
200 + return $response;
210 201 }
211 202
212 203 /**
213 204 * Retrieves the schema for the Replies endpoint.