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 -26 9.3.08.0.2 View file →
@@ -13,9 +13,8 @@
13 13 use Activitypub\Sanitize;
14 14 use Activitypub\Webfinger;
15 15
16 16 use function Activitypub\get_post_id;
17 -use function Activitypub\get_reaction_author_name;
18 17 use function Activitypub\get_rest_url_by_path;
19 18
20 19 /**
21 20 * Class Post_Controller
@@ -35,9 +34,9 @@
35 34 * The base of this controller's route.
36 35 *
37 36 * @var string
38 37 */
39 - protected $rest_base = 'posts/(?P<id>[\d]+)';
38 + protected $rest_base = 'posts/(?P<id>[-]?\d+)';
40 39
41 40 /**
42 41 * Register routes.
43 42 */
@@ -47,12 +46,10 @@
47 46 '/' . $this->rest_base . '/reactions',
48 47 array(
49 48 'args' => array(
50 49 'id' => array(
51 - 'required' => true,
52 - 'type' => 'integer',
53 - 'minimum' => 1,
54 - 'validate_callback' => 'Activitypub\is_post_publicly_queryable',
50 + 'required' => true,
51 + 'type' => 'integer',
55 52 ),
56 53 ),
57 54 array(
58 55 'methods' => \WP_REST_Server::READABLE,
@@ -67,12 +64,10 @@
67 64 '/' . $this->rest_base . '/context',
68 65 array(
69 66 'args' => array(
70 67 'id' => array(
71 - 'required' => true,
72 - 'type' => 'integer',
73 - 'minimum' => 1,
74 - 'validate_callback' => 'Activitypub\is_post_publicly_queryable',
68 + 'required' => true,
69 + 'type' => 'integer',
75 70 ),
76 71 ),
77 72 array(
78 73 'methods' => \WP_REST_Server::READABLE,
@@ -87,13 +82,11 @@
87 82 '/' . $this->rest_base . '/remote-intent',
88 83 array(
89 84 'args' => array(
90 85 'id' => array(
91 - 'description' => 'Unique identifier for the post.',
92 - 'type' => 'integer',
93 - 'minimum' => 1,
94 - 'required' => true,
95 - 'validate_callback' => 'Activitypub\is_post_publicly_queryable',
86 + 'description' => 'Unique identifier for the post.',
87 + 'type' => 'integer',
88 + 'required' => true,
96 89 ),
97 90 ),
98 91 array(
99 92 'methods' => \WP_REST_Server::READABLE,
@@ -127,9 +120,14 @@
127 120 * @return \WP_REST_Response|\WP_Error Response object on success, or WP_Error object on failure.
128 121 */
129 122 public function get_reactions( $request ) {
130 123 $post_id = $request->get_param( 'id' );
124 + $post = \get_post( $post_id );
131 125
126 + if ( ! $post ) {
127 + return new \WP_Error( 'activitypub_post_not_found', 'Post not found', array( 'status' => 404 ) );
128 + }
129 +
132 130 $reactions = array();
133 131
134 132 foreach ( Comment::get_comment_types() as $type_object ) {
135 133 $comments = \get_comments(
@@ -161,17 +159,12 @@
161 159 $reactions[ $type_object['collection'] ] = array(
162 160 'label' => $label,
163 161 'items' => \array_map(
164 162 static function ( $comment ) {
165 - /*
166 - * `esc_url_raw()` rejects `javascript:` and other unsafe
167 - * schemes without HTML-encoding ampersands (this is JSON,
168 - * not markup).
169 - */
170 163 return array(
171 - 'name' => get_reaction_author_name( $comment ),
172 - 'url' => \esc_url_raw( $comment->comment_author_url ),
173 - '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 ),
174 167 );
175 168 },
176 169 $comments
177 170 ),
@@ -188,16 +181,17 @@
188 181 *
189 182 * @return \WP_REST_Response|\WP_Error Response object on success, or WP_Error object on failure.
190 183 */
191 184 public function get_context( $request ) {
192 - $post_id = $request->get_param( 'id' );
185 + $post_id = $request->get_param( 'id' );
186 +
193 187 $collection = Replies::get_context_collection( $post_id );
194 188
195 189 if ( false === $collection ) {
196 - 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 ) );
197 191 }
198 192
199 - $response = \array_merge(
193 + $response = array_merge(
200 194 array(
201 195 '@context' => Base_Object::JSON_LD_CONTEXT,
202 196 'id' => get_rest_url_by_path( \sprintf( 'posts/%d/context', $post_id ) ),
203 197 ),
@@ -223,8 +217,12 @@
223 217 $post_id = $request->get_param( 'id' );
224 218 $resource = $request->get_param( 'resource' );
225 219 $intent = $request->get_param( 'intent' );
226 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 + }
227 225
228 226 $template = Webfinger::get_intent_endpoint( $resource, $intent, true );
229 227
230 228 if ( \is_wp_error( $template ) ) {