| @@ -14,9 +14,8 @@ | ||
| 14 | 14 | use Activitypub\Collection\Remote_Actors; |
| 15 | 15 | |
| 16 | 16 | use function Activitypub\add_to_outbox; |
| 17 | 17 | use function Activitypub\object_to_uri; |
| 18 | -use function Activitypub\user_can_activitypub; | |
| 19 | 18 | |
| 20 | 19 | /** |
| 21 | 20 | * Handler for QuoteRequest activities. |
| 22 | 21 | * |
| @@ -40,27 +39,21 @@ | ||
| 40 | 39 | * @param array $activity The activity object. |
| 41 | 40 | * @param int|int[] $user_ids The user ID(s). |
| 42 | 41 | */ |
| 43 | 42 | public static function handle_quote_request( $activity, $user_ids ) { |
| 43 | + // Extract the user ID (quote requests are always for a single user). | |
| 44 | + $user_id = \is_array( $user_ids ) ? \reset( $user_ids ) : $user_ids; | |
| 45 | + | |
| 44 | 46 | $state = true; |
| 45 | 47 | $post_id = \url_to_postid( object_to_uri( $activity['object'] ) ); |
| 46 | - $post = $post_id ? \get_post( $post_id ) : null; | |
| 47 | 48 | |
| 48 | - if ( ! $post ) { | |
| 49 | - $user_id = \is_array( $user_ids ) ? \reset( $user_ids ) : $user_ids; | |
| 49 | + if ( ! $post_id ) { | |
| 50 | 50 | self::queue_reject( $activity, $user_id ); |
| 51 | 51 | return; |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | - // Use the post author as the responding actor — they own the quoted content. | |
| 55 | - $user_id = (int) $post->post_author; | |
| 56 | 54 | $content_policy = \get_post_meta( $post_id, 'activitypub_interaction_policy_quote', true ); |
| 57 | 55 | |
| 58 | - // Fall back to global default if not set. | |
| 59 | - if ( ! $content_policy ) { | |
| 60 | - $content_policy = \get_option( 'activitypub_default_quote_policy', ACTIVITYPUB_INTERACTION_POLICY_ANYONE ); | |
| 61 | - } | |
| 62 | - | |
| 63 | 56 | switch ( $content_policy ) { |
| 64 | 57 | case ACTIVITYPUB_INTERACTION_POLICY_ME: |
| 65 | 58 | self::queue_reject( $activity, $user_id ); |
| 66 | 59 | $state = false; |
| @@ -98,9 +91,9 @@ | ||
| 98 | 91 | * @param int|int[]|null $user_ids The user ID(s). |
| 99 | 92 | * @param string $type The type of the activity. |
| 100 | 93 | */ |
| 101 | 94 | public static function handle_blocked_request( $activity, $user_ids, $type ) { |
| 102 | - if ( ! \in_array( \strtolower( $type ), array( 'quoterequest', 'quote_request' ), true ) ) { | |
| 95 | + if ( 'quoterequest' !== \strtolower( $type ) ) { | |
| 103 | 96 | return; |
| 104 | 97 | } |
| 105 | 98 | |
| 106 | 99 | // Extract the user ID (quote requests are always for a single user). |
| @@ -114,19 +107,14 @@ | ||
| 114 | 107 | * |
| 115 | 108 | * When a local quote comment is deleted, send a Reject activity to revoke |
| 116 | 109 | * the previously accepted QuoteRequest. |
| 117 | 110 | * |
| 118 | - * @param int $comment_id The comment ID being deleted. | |
| 119 | - * @param \WP_Comment|null $comment The comment object, or null if not available. | |
| 111 | + * @param int $comment_id The comment ID being deleted. | |
| 112 | + * @param \WP_Comment $comment The comment object. | |
| 120 | 113 | */ |
| 121 | 114 | public static function handle_quote_delete( $comment_id, $comment ) { |
| 122 | - // Try to get comment if not provided. | |
| 123 | - if ( ! $comment ) { | |
| 124 | - $comment = \get_comment( $comment_id ); | |
| 125 | - } | |
| 126 | - | |
| 127 | 115 | // Only handle quote comments. |
| 128 | - if ( ! $comment || 'quote' !== $comment->comment_type ) { | |
| 116 | + if ( 'quote' !== $comment->comment_type ) { | |
| 129 | 117 | return; |
| 130 | 118 | } |
| 131 | 119 | |
| 132 | 120 | // Get the post being quoted. |
| @@ -203,13 +191,8 @@ | ||
| 203 | 191 | * @param int $user_id The user ID. |
| 204 | 192 | * @param int $post_id The post ID. |
| 205 | 193 | */ |
| 206 | 194 | public static function queue_accept( $activity_object, $user_id, $post_id ) { |
| 207 | - // Fall back to the blog actor if the user has ActivityPub disabled. | |
| 208 | - if ( ! user_can_activitypub( $user_id ) ) { | |
| 209 | - $user_id = Actors::BLOG_USER_ID; | |
| 210 | - } | |
| 211 | - | |
| 212 | 195 | $actor = Actors::get_by_id( $user_id ); |
| 213 | 196 | |
| 214 | 197 | if ( \is_wp_error( $actor ) ) { |
| 215 | 198 | return; |
| @@ -217,9 +200,9 @@ | ||
| 217 | 200 | |
| 218 | 201 | $activity_object['instrument'] = object_to_uri( $activity_object['instrument'] ); |
| 219 | 202 | |
| 220 | 203 | $post_meta = \get_post_meta( $post_id, '_activitypub_quoted_by', false ); |
| 221 | - if ( \in_array( $activity_object['instrument'], $post_meta, true ) ) { | |
| 204 | + if ( in_array( $activity_object['instrument'], $post_meta, true ) ) { | |
| 222 | 205 | global $wpdb; |
| 223 | 206 | |
| 224 | 207 | // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching |
| 225 | 208 | $meta_id = $wpdb->get_var( |
| @@ -234,9 +217,9 @@ | ||
| 234 | 217 | $meta_id = \add_post_meta( $post_id, '_activitypub_quoted_by', $activity_object['instrument'] ); |
| 235 | 218 | } |
| 236 | 219 | |
| 237 | 220 | // Only send minimal data. |
| 238 | - $activity_object = \array_intersect_key( | |
| 221 | + $activity_object = array_intersect_key( | |
| 239 | 222 | $activity_object, |
| 240 | 223 | array( |
| 241 | 224 | 'id' => 1, |
| 242 | 225 | 'type' => 1, |
| @@ -272,13 +255,8 @@ | ||
| 272 | 255 | * @param array $activity_object The activity object. |
| 273 | 256 | * @param int $user_id The user ID. |
| 274 | 257 | */ |
| 275 | 258 | public static function queue_reject( $activity_object, $user_id ) { |
| 276 | - // Fall back to the blog actor if the user has ActivityPub disabled. | |
| 277 | - if ( ! user_can_activitypub( $user_id ) ) { | |
| 278 | - $user_id = Actors::BLOG_USER_ID; | |
| 279 | - } | |
| 280 | - | |
| 281 | 259 | $actor = Actors::get_by_id( $user_id ); |
| 282 | 260 | |
| 283 | 261 | if ( \is_wp_error( $actor ) ) { |
| 284 | 262 | return; |
| @@ -286,9 +264,9 @@ | ||
| 286 | 264 | |
| 287 | 265 | $activity_object['instrument'] = object_to_uri( $activity_object['instrument'] ); |
| 288 | 266 | |
| 289 | 267 | // Only send minimal data. |
| 290 | - $activity_object = \array_intersect_key( | |
| 268 | + $activity_object = array_intersect_key( | |
| 291 | 269 | $activity_object, |
| 292 | 270 | array( |
| 293 | 271 | 'id' => 1, |
| 294 | 272 | 'type' => 1, |