| @@ -11,9 +11,8 @@ | ||
| 11 | 11 | use Activitypub\Collection\Interactions; |
| 12 | 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. |
| @@ -136,9 +123,9 @@ | ||
| 136 | 123 | $response = new \WP_Error( 'rest_unknown_collection_type', 'Unknown collection type.', array( 'status' => 404 ) ); |
| 137 | 124 | } |
| 138 | 125 | |
| 139 | 126 | // Prepend ActivityPub Context. |
| 140 | - $response = \array_merge( array( '@context' => Base_Object::JSON_LD_CONTEXT ), $response ); | |
| 127 | + $response = array_merge( array( '@context' => Base_Object::JSON_LD_CONTEXT ), $response ); | |
| 141 | 128 | $response = \rest_ensure_response( $response ); |
| 142 | 129 | $response->header( 'Content-Type', 'application/activity+json; charset=' . \get_option( 'blog_charset' ) ); |
| 143 | 130 | |
| 144 | 131 | return $response; |
| @@ -180,9 +167,9 @@ | ||
| 180 | 167 | $likes = 0; |
| 181 | 168 | } |
| 182 | 169 | |
| 183 | 170 | return array( |
| 184 | - 'id' => get_rest_url_by_path( \sprintf( 'posts/%d/likes', $wp_object->ID ) ), | |
| 171 | + 'id' => get_rest_url_by_path( sprintf( 'posts/%d/likes', $wp_object->ID ) ), | |
| 185 | 172 | 'type' => 'Collection', |
| 186 | 173 | 'totalItems' => $likes, |
| 187 | 174 | ); |
| 188 | 175 | } |
| @@ -196,15 +183,15 @@ | ||
| 196 | 183 | * @return array Response collection of shares. |
| 197 | 184 | */ |
| 198 | 185 | public function get_shares( $request, $wp_object ) { |
| 199 | 186 | if ( $wp_object instanceof \WP_Post ) { |
| 200 | - $shares = Interactions::count_by_type( $wp_object->ID, 'repost' ) + Interactions::count_by_type( $wp_object->ID, 'quote' ); | |
| 187 | + $shares = Interactions::count_by_type( $wp_object->ID, 'repost' ); | |
| 201 | 188 | } else { |
| 202 | 189 | $shares = 0; |
| 203 | 190 | } |
| 204 | 191 | |
| 205 | 192 | return array( |
| 206 | - 'id' => get_rest_url_by_path( \sprintf( 'posts/%d/shares', $wp_object->ID ) ), | |
| 193 | + 'id' => get_rest_url_by_path( sprintf( 'posts/%d/shares', $wp_object->ID ) ), | |
| 207 | 194 | 'type' => 'Collection', |
| 208 | 195 | 'totalItems' => $shares, |
| 209 | 196 | ); |
| 210 | 197 | } |