PluginProbe
ActivityPub / 8.0.2
ActivityPub v8.0.2
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-post-controller.php +24 -28 9.2.08.0.2 View file →
@@ -34,9 +34,9 @@
34 34 * The base of this controller's route.
35 35 *
36 36 * @var string
37 37 */
38 - protected $rest_base = 'posts/(?P<id>[\d]+)';
38 + protected $rest_base = 'posts/(?P<id>[-]?\d+)';
39 39
40 40 /**
41 41 * Register routes.
42 42 */
@@ -46,12 +46,10 @@
46 46 '/' . $this->rest_base . '/reactions',
47 47 array(
48 48 'args' => array(
49 49 'id' => array(
50 - 'required' => true,
51 - 'type' => 'integer',
52 - 'minimum' => 1,
53 - 'validate_callback' => 'Activitypub\is_post_publicly_queryable',
50 + 'required' => true,
51 + 'type' => 'integer',
54 52 ),
55 53 ),
56 54 array(
57 55 'methods' => \WP_REST_Server::READABLE,
@@ -66,12 +64,10 @@
66 64 '/' . $this->rest_base . '/context',
67 65 array(
68 66 'args' => array(
69 67 'id' => array(
70 - 'required' => true,
71 - 'type' => 'integer',
72 - 'minimum' => 1,
73 - 'validate_callback' => 'Activitypub\is_post_publicly_queryable',
68 + 'required' => true,
69 + 'type' => 'integer',
74 70 ),
75 71 ),
76 72 array(
77 73 'methods' => \WP_REST_Server::READABLE,
@@ -86,13 +82,11 @@
86 82 '/' . $this->rest_base . '/remote-intent',
87 83 array(
88 84 'args' => array(
89 85 'id' => array(
90 - 'description' => 'Unique identifier for the post.',
91 - 'type' => 'integer',
92 - 'minimum' => 1,
93 - 'required' => true,
94 - 'validate_callback' => 'Activitypub\is_post_publicly_queryable',
86 + 'description' => 'Unique identifier for the post.',
87 + 'type' => 'integer',
88 + 'required' => true,
95 89 ),
96 90 ),
97 91 array(
98 92 'methods' => \WP_REST_Server::READABLE,
@@ -126,9 +120,14 @@
126 120 * @return \WP_REST_Response|\WP_Error Response object on success, or WP_Error object on failure.
127 121 */
128 122 public function get_reactions( $request ) {
129 123 $post_id = $request->get_param( 'id' );
124 + $post = \get_post( $post_id );
130 125
126 + if ( ! $post ) {
127 + return new \WP_Error( 'activitypub_post_not_found', 'Post not found', array( 'status' => 404 ) );
128 + }
129 +
131 130 $reactions = array();
132 131
133 132 foreach ( Comment::get_comment_types() as $type_object ) {
134 133 $comments = \get_comments(
@@ -160,20 +159,12 @@
160 159 $reactions[ $type_object['collection'] ] = array(
161 160 'label' => $label,
162 161 'items' => \array_map(
163 162 static function ( $comment ) {
164 - /*
165 - * Decode entities first so a stored pseudo-tag like
166 - * `&lt;img&gt;` becomes a real `<img>` for the next
167 - * step to remove, then strip any tags so the JSON
168 - * response contains only plain text. `esc_url_raw()`
169 - * rejects `javascript:` and other unsafe schemes without
170 - * HTML-encoding ampersands (this is JSON, not markup).
171 - */
172 163 return array(
173 - 'name' => \wp_strip_all_tags( \html_entity_decode( $comment->comment_author, ENT_QUOTES ) ),
174 - 'url' => \esc_url_raw( $comment->comment_author_url ),
175 - 'avatar' => \esc_url_raw( \get_avatar_url( $comment ) ),
164 + 'name' => html_entity_decode( $comment->comment_author ),
165 + 'url' => $comment->comment_author_url,
166 + 'avatar' => \get_avatar_url( $comment ),
176 167 );
177 168 },
178 169 $comments
179 170 ),
@@ -190,16 +181,17 @@
190 181 *
191 182 * @return \WP_REST_Response|\WP_Error Response object on success, or WP_Error object on failure.
192 183 */
193 184 public function get_context( $request ) {
194 - $post_id = $request->get_param( 'id' );
185 + $post_id = $request->get_param( 'id' );
186 +
195 187 $collection = Replies::get_context_collection( $post_id );
196 188
197 189 if ( false === $collection ) {
198 - return new \WP_Error( 'activitypub_post_not_found', \__( 'Post not found', 'activitypub' ), array( 'status' => 404 ) );
190 + return new \WP_Error( 'activitypub_post_not_found', 'Post not found', array( 'status' => 404 ) );
199 191 }
200 192
201 - $response = \array_merge(
193 + $response = array_merge(
202 194 array(
203 195 '@context' => Base_Object::JSON_LD_CONTEXT,
204 196 'id' => get_rest_url_by_path( \sprintf( 'posts/%d/context', $post_id ) ),
205 197 ),
@@ -225,8 +217,12 @@
225 217 $post_id = $request->get_param( 'id' );
226 218 $resource = $request->get_param( 'resource' );
227 219 $intent = $request->get_param( 'intent' );
228 220 $post = \get_post( $post_id );
221 +
222 + if ( ! $post || 'publish' !== \get_post_status( $post ) ) {
223 + return new \WP_Error( 'activitypub_post_not_found', \__( 'Post not found.', 'activitypub' ), array( 'status' => 404 ) );
224 + }
229 225
230 226 $template = Webfinger::get_intent_endpoint( $resource, $intent, true );
231 227
232 228 if ( \is_wp_error( $template ) ) {