| @@ -12,16 +12,10 @@ | ||
| 12 | 12 | use Activitypub\Collection\Followers; |
| 13 | 13 | use Activitypub\Collection\Following; |
| 14 | 14 | use Activitypub\Collection\Inbox; |
| 15 | 15 | use Activitypub\Collection\Outbox; |
| 16 | +use Activitypub\Collection\Posts; | |
| 16 | 17 | use Activitypub\Collection\Remote_Actors; |
| 17 | -use Activitypub\Collection\Remote_Posts; | |
| 18 | -use Activitypub\OAuth\Client; | |
| 19 | -use Activitypub\OAuth\Scope; | |
| 20 | -use Activitypub\OAuth\Token; | |
| 21 | -use Activitypub\Rest\Reader_Terms_Controller; | |
| 22 | -use Activitypub\Rest\Remote_Actors_Controller; | |
| 23 | -use Activitypub\Rest\Remote_Posts_Controller; | |
| 24 | 18 | |
| 25 | 19 | /** |
| 26 | 20 | * Post Types class. |
| 27 | 21 | */ |
| @@ -35,10 +29,8 @@ | ||
| 35 | 29 | \add_action( 'init', array( self::class, 'register_outbox_post_type' ), 11 ); |
| 36 | 30 | \add_action( 'init', array( self::class, 'register_post_post_type' ), 11 ); |
| 37 | 31 | \add_action( 'init', array( self::class, 'register_extra_fields_post_types' ), 11 ); |
| 38 | 32 | \add_action( 'init', array( self::class, 'register_activitypub_post_meta' ), 11 ); |
| 39 | - \add_action( 'init', array( self::class, 'register_oauth_post_types' ), 11 ); | |
| 40 | - \add_action( 'init', array( self::class, 'register_tombstone_post_type' ), 11 ); | |
| 41 | 33 | |
| 42 | 34 | \add_action( 'rest_api_init', array( self::class, 'register_ap_actor_rest_field' ) ); |
| 43 | 35 | \add_action( 'rest_api_init', array( self::class, 'register_ap_post_actor_rest_field' ) ); |
| 44 | 36 | \add_action( 'rest_api_init', array( self::class, 'register_ap_post_rest_params' ) ); |
| @@ -44,11 +36,9 @@ | ||
| 44 | 36 | \add_action( 'rest_api_init', array( self::class, 'register_ap_post_rest_params' ) ); |
| 45 | 37 | |
| 46 | 38 | \add_filter( 'rest_ap_post_query', array( self::class, 'filter_ap_post_by_user' ), 10, 2 ); |
| 47 | 39 | \add_filter( 'rest_ap_object_type_query', array( self::class, 'filter_object_type_by_user' ), 10, 2 ); |
| 48 | - \add_filter( 'rest_ap_tag_query', array( self::class, 'filter_tag_by_user' ), 10, 2 ); | |
| 49 | 40 | \add_filter( 'rest_ap_object_type_collection_params', array( self::class, 'register_object_type_user_param' ) ); |
| 50 | - \add_filter( 'rest_ap_tag_collection_params', array( self::class, 'register_object_type_user_param' ) ); | |
| 51 | 41 | |
| 52 | 42 | \add_filter( 'activitypub_get_actor_extra_fields', array( Extra_Fields::class, 'default_actor_extra_fields' ), 10, 2 ); |
| 53 | 43 | |
| 54 | 44 | \add_filter( 'add_post_metadata', array( self::class, 'prevent_empty_post_meta' ), 10, 4 ); |
| @@ -66,24 +56,20 @@ | ||
| 66 | 56 | public static function register_remote_actors_post_type() { |
| 67 | 57 | \register_post_type( |
| 68 | 58 | Remote_Actors::POST_TYPE, |
| 69 | 59 | array( |
| 70 | - 'labels' => array( | |
| 60 | + 'labels' => array( | |
| 71 | 61 | 'name' => \_x( 'Followers', 'post_type plural name', 'activitypub' ), |
| 72 | 62 | 'singular_name' => \_x( 'Follower', 'post_type single name', 'activitypub' ), |
| 73 | 63 | ), |
| 74 | - 'public' => false, | |
| 75 | - 'capabilities' => array( | |
| 76 | - 'create_posts' => false, | |
| 77 | - ), | |
| 78 | - 'show_in_rest' => true, | |
| 79 | - 'rest_controller_class' => Remote_Actors_Controller::class, | |
| 80 | - 'hierarchical' => false, | |
| 81 | - 'rewrite' => false, | |
| 82 | - 'query_var' => false, | |
| 83 | - 'delete_with_user' => false, | |
| 84 | - 'can_export' => true, | |
| 85 | - 'supports' => array( 'custom-fields' ), | |
| 64 | + 'public' => false, | |
| 65 | + 'show_in_rest' => true, | |
| 66 | + 'hierarchical' => false, | |
| 67 | + 'rewrite' => false, | |
| 68 | + 'query_var' => false, | |
| 69 | + 'delete_with_user' => false, | |
| 70 | + 'can_export' => true, | |
| 71 | + 'supports' => array( 'custom-fields' ), | |
| 86 | 72 | ) |
| 87 | 73 | ); |
| 88 | 74 | |
| 89 | 75 | // Register meta for Remote Actors post type. |
| @@ -112,8 +98,9 @@ | ||
| 112 | 98 | Followers::FOLLOWER_META_KEY, |
| 113 | 99 | array( |
| 114 | 100 | 'type' => 'string', |
| 115 | 101 | 'single' => false, |
| 102 | + 'show_in_rest' => true, | |
| 116 | 103 | 'sanitize_callback' => 'sanitize_text_field', |
| 117 | 104 | ) |
| 118 | 105 | ); |
| 119 | 106 | } |
| @@ -357,55 +344,52 @@ | ||
| 357 | 344 | * Register the Post post type. |
| 358 | 345 | */ |
| 359 | 346 | public static function register_post_post_type() { |
| 360 | 347 | \register_post_type( |
| 361 | - Remote_Posts::POST_TYPE, | |
| 348 | + Posts::POST_TYPE, | |
| 362 | 349 | array( |
| 363 | - 'labels' => array( | |
| 350 | + 'labels' => array( | |
| 364 | 351 | 'name' => \_x( 'Posts', 'post_type plural name', 'activitypub' ), |
| 365 | 352 | 'singular_name' => \_x( 'Post', 'post_type single name', 'activitypub' ), |
| 366 | 353 | ), |
| 367 | - 'map_meta_cap' => true, | |
| 368 | - 'public' => false, | |
| 369 | - 'capabilities' => array( | |
| 370 | - 'create_posts' => false, | |
| 354 | + 'capabilities' => array( | |
| 355 | + 'activitypub' => true, | |
| 371 | 356 | ), |
| 372 | - 'show_in_rest' => true, | |
| 373 | - 'rest_controller_class' => Remote_Posts_Controller::class, | |
| 374 | - 'rewrite' => false, | |
| 375 | - 'query_var' => false, | |
| 376 | - 'supports' => array( 'title', 'editor', 'author', 'custom-fields', 'excerpt', 'comments' ), | |
| 377 | - 'delete_with_user' => true, | |
| 378 | - 'can_export' => true, | |
| 379 | - 'exclude_from_search' => true, | |
| 380 | - 'taxonomies' => array( 'ap_tag', 'ap_object_type' ), | |
| 357 | + 'map_meta_cap' => true, | |
| 358 | + 'public' => false, | |
| 359 | + 'show_in_rest' => true, | |
| 360 | + 'rewrite' => false, | |
| 361 | + 'query_var' => false, | |
| 362 | + 'supports' => array( 'title', 'editor', 'author', 'custom-fields', 'excerpt', 'comments' ), | |
| 363 | + 'delete_with_user' => true, | |
| 364 | + 'can_export' => true, | |
| 365 | + 'exclude_from_search' => true, | |
| 366 | + 'taxonomies' => array( 'ap_tag', 'ap_object_type' ), | |
| 381 | 367 | ) |
| 382 | 368 | ); |
| 383 | 369 | |
| 384 | 370 | \register_taxonomy( |
| 385 | 371 | 'ap_tag', |
| 386 | - array( Remote_Posts::POST_TYPE ), | |
| 372 | + array( Posts::POST_TYPE ), | |
| 387 | 373 | array( |
| 388 | - 'public' => false, | |
| 389 | - 'query_var' => true, | |
| 390 | - 'show_in_rest' => true, | |
| 391 | - 'rest_controller_class' => Reader_Terms_Controller::class, | |
| 374 | + 'public' => false, | |
| 375 | + 'query_var' => true, | |
| 376 | + 'show_in_rest' => true, | |
| 392 | 377 | ) |
| 393 | 378 | ); |
| 394 | 379 | |
| 395 | 380 | \register_taxonomy( |
| 396 | 381 | 'ap_object_type', |
| 397 | - array( Remote_Posts::POST_TYPE ), | |
| 382 | + array( Posts::POST_TYPE ), | |
| 398 | 383 | array( |
| 399 | - 'public' => false, | |
| 400 | - 'query_var' => true, | |
| 401 | - 'show_in_rest' => true, | |
| 402 | - 'rest_controller_class' => Reader_Terms_Controller::class, | |
| 384 | + 'public' => false, | |
| 385 | + 'query_var' => true, | |
| 386 | + 'show_in_rest' => true, | |
| 403 | 387 | ) |
| 404 | 388 | ); |
| 405 | 389 | |
| 406 | 390 | \register_post_meta( |
| 407 | - Remote_Posts::POST_TYPE, | |
| 391 | + Posts::POST_TYPE, | |
| 408 | 392 | '_activitypub_remote_actor_id', |
| 409 | 393 | array( |
| 410 | 394 | 'type' => 'integer', |
| 411 | 395 | 'single' => true, |
| @@ -414,9 +398,9 @@ | ||
| 414 | 398 | ) |
| 415 | 399 | ); |
| 416 | 400 | |
| 417 | 401 | \register_post_meta( |
| 418 | - Remote_Posts::POST_TYPE, | |
| 402 | + Posts::POST_TYPE, | |
| 419 | 403 | '_activitypub_user_id', |
| 420 | 404 | array( |
| 421 | 405 | 'type' => 'integer', |
| 422 | 406 | 'single' => true, |
| @@ -472,143 +456,8 @@ | ||
| 472 | 456 | \do_action( 'activitypub_after_register_post_type' ); |
| 473 | 457 | } |
| 474 | 458 | |
| 475 | 459 | /** |
| 476 | - * Register OAuth 2.0 post types for C2S support. | |
| 477 | - * | |
| 478 | - * Registers post type for OAuth clients. | |
| 479 | - * Note: Tokens are stored in user meta and authorization codes in transients. | |
| 480 | - */ | |
| 481 | - public static function register_oauth_post_types() { | |
| 482 | - // OAuth Clients post type. | |
| 483 | - \register_post_type( | |
| 484 | - Client::POST_TYPE, | |
| 485 | - array( | |
| 486 | - 'labels' => array( | |
| 487 | - 'name' => \_x( 'OAuth Clients', 'post_type plural name', 'activitypub' ), | |
| 488 | - 'singular_name' => \_x( 'OAuth Client', 'post_type single name', 'activitypub' ), | |
| 489 | - ), | |
| 490 | - 'public' => false, | |
| 491 | - 'show_in_rest' => false, | |
| 492 | - 'hierarchical' => false, | |
| 493 | - 'rewrite' => false, | |
| 494 | - 'query_var' => false, | |
| 495 | - 'delete_with_user' => false, | |
| 496 | - 'can_export' => true, | |
| 497 | - 'supports' => array( 'title', 'editor', 'custom-fields' ), | |
| 498 | - 'exclude_from_search' => true, | |
| 499 | - ) | |
| 500 | - ); | |
| 501 | - | |
| 502 | - // OAuth Client meta. | |
| 503 | - \register_post_meta( | |
| 504 | - Client::POST_TYPE, | |
| 505 | - '_activitypub_client_id', | |
| 506 | - array( | |
| 507 | - 'type' => 'string', | |
| 508 | - 'single' => true, | |
| 509 | - 'description' => 'Unique OAuth client identifier (UUID).', | |
| 510 | - 'sanitize_callback' => 'sanitize_text_field', | |
| 511 | - ) | |
| 512 | - ); | |
| 513 | - | |
| 514 | - \register_post_meta( | |
| 515 | - Client::POST_TYPE, | |
| 516 | - '_activitypub_client_secret_hash', | |
| 517 | - array( | |
| 518 | - 'type' => 'string', | |
| 519 | - 'single' => true, | |
| 520 | - 'description' => 'SHA-256 hash of the client secret (null for public clients).', | |
| 521 | - 'sanitize_callback' => 'sanitize_text_field', | |
| 522 | - ) | |
| 523 | - ); | |
| 524 | - | |
| 525 | - \register_post_meta( | |
| 526 | - Client::POST_TYPE, | |
| 527 | - '_activitypub_redirect_uris', | |
| 528 | - array( | |
| 529 | - 'type' => 'array', | |
| 530 | - 'single' => true, | |
| 531 | - 'description' => 'Allowed redirect URIs for this client.', | |
| 532 | - 'sanitize_callback' => static function ( $value ) { | |
| 533 | - if ( ! \is_array( $value ) ) { | |
| 534 | - return array(); | |
| 535 | - } | |
| 536 | - return \array_map( array( Sanitize::class, 'redirect_uri' ), $value ); | |
| 537 | - }, | |
| 538 | - ) | |
| 539 | - ); | |
| 540 | - | |
| 541 | - \register_post_meta( | |
| 542 | - Client::POST_TYPE, | |
| 543 | - '_activitypub_allowed_scopes', | |
| 544 | - array( | |
| 545 | - 'type' => 'array', | |
| 546 | - 'single' => true, | |
| 547 | - 'description' => 'Allowed OAuth scopes for this client.', | |
| 548 | - 'sanitize_callback' => array( Scope::class, 'sanitize' ), | |
| 549 | - ) | |
| 550 | - ); | |
| 551 | - | |
| 552 | - \register_post_meta( | |
| 553 | - Client::POST_TYPE, | |
| 554 | - '_activitypub_is_public', | |
| 555 | - array( | |
| 556 | - 'type' => 'boolean', | |
| 557 | - 'single' => true, | |
| 558 | - 'description' => 'Whether this is a public client (PKCE-only, no secret).', | |
| 559 | - 'sanitize_callback' => 'rest_sanitize_boolean', | |
| 560 | - 'default' => true, | |
| 561 | - ) | |
| 562 | - ); | |
| 563 | - | |
| 564 | - \register_post_meta( | |
| 565 | - Client::POST_TYPE, | |
| 566 | - Token::USER_META_KEY, | |
| 567 | - array( | |
| 568 | - 'type' => 'integer', | |
| 569 | - 'single' => false, | |
| 570 | - 'description' => 'User IDs that have active tokens for this client.', | |
| 571 | - 'sanitize_callback' => 'absint', | |
| 572 | - ) | |
| 573 | - ); | |
| 574 | - } | |
| 575 | - | |
| 576 | - /** | |
| 577 | - * Register the ap_tombstone post type. | |
| 578 | - * | |
| 579 | - * Stores local tombstone URLs out of the autoloaded options row. | |
| 580 | - * The post type is fully internal — never queried publicly, never shown in UI. | |
| 581 | - * | |
| 582 | - * @since 8.3.0 | |
| 583 | - */ | |
| 584 | - public static function register_tombstone_post_type() { | |
| 585 | - \register_post_type( | |
| 586 | - Tombstone::POST_TYPE, | |
| 587 | - array( | |
| 588 | - 'labels' => array( | |
| 589 | - 'name' => \_x( 'Tombstones', 'post_type plural name', 'activitypub' ), | |
| 590 | - 'singular_name' => \_x( 'Tombstone', 'post_type single name', 'activitypub' ), | |
| 591 | - ), | |
| 592 | - 'public' => false, | |
| 593 | - 'publicly_queryable' => false, | |
| 594 | - 'show_ui' => false, | |
| 595 | - 'show_in_menu' => false, | |
| 596 | - 'show_in_nav_menus' => false, | |
| 597 | - 'show_in_admin_bar' => false, | |
| 598 | - 'show_in_rest' => false, | |
| 599 | - 'exclude_from_search' => true, | |
| 600 | - 'has_archive' => false, | |
| 601 | - 'rewrite' => false, | |
| 602 | - 'query_var' => false, | |
| 603 | - 'can_export' => false, | |
| 604 | - 'delete_with_user' => false, | |
| 605 | - 'supports' => array(), | |
| 606 | - ) | |
| 607 | - ); | |
| 608 | - } | |
| 609 | - | |
| 610 | - /** | |
| 611 | 460 | * Register post meta for ActivityPub supported post types. |
| 612 | 461 | */ |
| 613 | 462 | public static function register_activitypub_post_meta() { |
| 614 | 463 | $ap_post_types = \get_post_types_by_support( 'activitypub' ); |
| @@ -755,10 +604,10 @@ | ||
| 755 | 604 | } |
| 756 | 605 | return array( |
| 757 | 606 | 'username' => $actor->get_preferred_username(), |
| 758 | 607 | 'name' => $actor->get_name() ?? $actor->get_preferred_username(), |
| 759 | - 'icon' => \sanitize_url( object_to_uri( $actor->get_icon() ) ?? '' ), | |
| 760 | - 'url' => \sanitize_url( object_to_uri( $actor->get_url() ?? $actor->get_id() ) ?? '' ), | |
| 608 | + 'icon' => object_to_uri( $actor->get_icon() ), | |
| 609 | + 'url' => object_to_uri( $actor->get_url() ?? $actor->get_id() ), | |
| 761 | 610 | 'webfinger' => Remote_Actors::get_acct( $response['id'] ), |
| 762 | 611 | 'identifier' => $actor->get_id(), |
| 763 | 612 | ); |
| 764 | 613 | }, |
| @@ -803,29 +652,20 @@ | ||
| 803 | 652 | * @param \WP_REST_Request $request The REST API request. |
| 804 | 653 | * @return array Modified query arguments. |
| 805 | 654 | */ |
| 806 | 655 | public static function filter_ap_actor_query_by_follower( $args, $request ) { |
| 807 | - $follower_of = isset( $request['follower_of'] ) ? (int) $request['follower_of'] : null; | |
| 656 | + if ( ! empty( $request['follower_of'] ) ) { | |
| 657 | + // Add meta_query to filter by _activitypub_following. | |
| 658 | + if ( ! isset( $args['meta_query'] ) ) { | |
| 659 | + $args['meta_query'] = array(); // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query | |
| 660 | + } | |
| 808 | 661 | |
| 809 | - // Users who cannot list users may only ever see their own followers. | |
| 810 | - if ( ! \current_user_can( 'list_users' ) ) { | |
| 811 | - $follower_of = \get_current_user_id(); | |
| 662 | + $args['meta_query'][] = array( | |
| 663 | + 'key' => Followers::FOLLOWER_META_KEY, | |
| 664 | + 'value' => $request['follower_of'], | |
| 665 | + ); | |
| 812 | 666 | } |
| 813 | 667 | |
| 814 | - if ( null === $follower_of ) { | |
| 815 | - return $args; | |
| 816 | - } | |
| 817 | - | |
| 818 | - // Add meta_query to filter by _activitypub_following. | |
| 819 | - if ( ! isset( $args['meta_query'] ) ) { | |
| 820 | - $args['meta_query'] = array(); // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query | |
| 821 | - } | |
| 822 | - | |
| 823 | - $args['meta_query'][] = array( | |
| 824 | - 'key' => Followers::FOLLOWER_META_KEY, | |
| 825 | - 'value' => $follower_of, | |
| 826 | - ); | |
| 827 | - | |
| 828 | 668 | return $args; |
| 829 | 669 | } |
| 830 | 670 | |
| 831 | 671 | /** |
| @@ -832,9 +672,9 @@ | ||
| 832 | 672 | * Register a REST field for the ap_post post type to embed remote actor data. |
| 833 | 673 | */ |
| 834 | 674 | public static function register_ap_post_actor_rest_field() { |
| 835 | 675 | \register_rest_field( |
| 836 | - Remote_Posts::POST_TYPE, | |
| 676 | + Posts::POST_TYPE, | |
| 837 | 677 | 'actor_info', |
| 838 | 678 | array( |
| 839 | 679 | /** |
| 840 | 680 | * Get the remote actor data for an ap_post. |
| @@ -852,10 +692,10 @@ | ||
| 852 | 692 | |
| 853 | 693 | return array( |
| 854 | 694 | 'username' => $actor->get_preferred_username(), |
| 855 | 695 | 'name' => $actor->get_name() ?? $actor->get_preferred_username(), |
| 856 | - 'icon' => \sanitize_url( object_to_uri( $actor->get_icon() ) ?? '' ), | |
| 857 | - 'url' => \sanitize_url( object_to_uri( $actor->get_url() ?? $actor->get_id() ) ?? '' ), | |
| 696 | + 'icon' => object_to_uri( $actor->get_icon() ), | |
| 697 | + 'url' => object_to_uri( $actor->get_url() ?? $actor->get_id() ), | |
| 858 | 698 | 'webfinger' => Remote_Actors::get_acct( $id ), |
| 859 | 699 | 'identifier' => $actor->get_id(), |
| 860 | 700 | ); |
| 861 | 701 | }, |
| @@ -872,12 +712,12 @@ | ||
| 872 | 712 | * Register custom REST API parameters for ap_post endpoint. |
| 873 | 713 | */ |
| 874 | 714 | public static function register_ap_post_rest_params() { |
| 875 | 715 | \add_filter( |
| 876 | - 'rest_' . Remote_Posts::POST_TYPE . '_collection_params', | |
| 716 | + 'rest_' . Posts::POST_TYPE . '_collection_params', | |
| 877 | 717 | function ( $params ) { |
| 878 | 718 | $params['user_id'] = array( |
| 879 | - 'description' => \__( 'Filter posts by user ID (0 for site/blog actor).', 'activitypub' ), | |
| 719 | + 'description' => __( 'Filter posts by user ID (0 for site/blog actor).', 'activitypub' ), | |
| 880 | 720 | 'type' => 'integer', |
| 881 | 721 | 'sanitize_callback' => 'absint', |
| 882 | 722 | ); |
| 883 | 723 | |
| @@ -912,25 +752,8 @@ | ||
| 912 | 752 | * |
| 913 | 753 | * @return array Modified query arguments. |
| 914 | 754 | */ |
| 915 | 755 | public static function filter_ap_post_by_user( $args, $request ) { |
| 916 | - /* | |
| 917 | - * Scope to one actor's feed. `scope_user_id()` pins the value to the current user unless | |
| 918 | - * the caller can `list_users`, so only a privileged caller can ask for another actor or | |
| 919 | - * for 0, the site/blog actor. This runs for every request, whatever else is being | |
| 920 | - * filtered on, or a tag or object type filter would match the whole cache. | |
| 921 | - */ | |
| 922 | - if ( ! isset( $args['meta_query'] ) ) { | |
| 923 | - $args['meta_query'] = array(); // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query | |
| 924 | - } | |
| 925 | - | |
| 926 | - $args['meta_query'][] = array( | |
| 927 | - 'key' => '_activitypub_user_id', | |
| 928 | - 'value' => self::scope_user_id( isset( $request['user_id'] ) ? $request['user_id'] : null ), | |
| 929 | - 'compare' => '=', | |
| 930 | - ); | |
| 931 | - | |
| 932 | - // Filter by tag if provided. | |
| 933 | 756 | $ap_tag = $request->get_param( 'ap_tag' ); |
| 934 | 757 | if ( ! empty( $ap_tag ) ) { |
| 935 | 758 | if ( ! isset( $args['tax_query'] ) ) { |
| 936 | 759 | $args['tax_query'] = array(); // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query |
| @@ -940,10 +763,25 @@ | ||
| 940 | 763 | 'taxonomy' => 'ap_tag', |
| 941 | 764 | 'field' => 'term_id', |
| 942 | 765 | 'terms' => $ap_tag, |
| 943 | 766 | ); |
| 767 | + | |
| 768 | + return $args; | |
| 944 | 769 | } |
| 945 | 770 | |
| 771 | + // Filter by user_id (defaults to current user, use 0 for site/blog actor). | |
| 772 | + $user_id = isset( $request['user_id'] ) ? (int) $request['user_id'] : \get_current_user_id(); | |
| 773 | + | |
| 774 | + if ( ! isset( $args['meta_query'] ) ) { | |
| 775 | + $args['meta_query'] = array(); // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query | |
| 776 | + } | |
| 777 | + | |
| 778 | + $args['meta_query'][] = array( | |
| 779 | + 'key' => '_activitypub_user_id', | |
| 780 | + 'value' => $user_id, | |
| 781 | + 'compare' => '=', | |
| 782 | + ); | |
| 783 | + | |
| 946 | 784 | // Filter by object type if provided. |
| 947 | 785 | if ( ! empty( $request['ap_object_type'] ) ) { |
| 948 | 786 | if ( ! isset( $args['tax_query'] ) ) { |
| 949 | 787 | $args['tax_query'] = array(); // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query |
| @@ -959,35 +797,8 @@ | ||
| 959 | 797 | return $args; |
| 960 | 798 | } |
| 961 | 799 | |
| 962 | 800 | /** |
| 963 | - * Clamp a requested user ID to a feed the current user is allowed to read. | |
| 964 | - * | |
| 965 | - * Users who can list users may read any actor's reader data, everybody else is | |
| 966 | - * limited to their own. | |
| 967 | - * | |
| 968 | - * @since 9.3.0 | |
| 969 | - * | |
| 970 | - * @param int|null $requested_user_id The requested user ID, or null when none was given. | |
| 971 | - * @return int The user ID to scope the query to. | |
| 972 | - */ | |
| 973 | - private static function scope_user_id( $requested_user_id ) { | |
| 974 | - $current_user_id = \get_current_user_id(); | |
| 975 | - | |
| 976 | - if ( null === $requested_user_id ) { | |
| 977 | - return $current_user_id; | |
| 978 | - } | |
| 979 | - | |
| 980 | - $requested_user_id = (int) $requested_user_id; | |
| 981 | - | |
| 982 | - if ( $requested_user_id !== $current_user_id && ! \current_user_can( 'list_users' ) ) { | |
| 983 | - return $current_user_id; | |
| 984 | - } | |
| 985 | - | |
| 986 | - return $requested_user_id; | |
| 987 | - } | |
| 988 | - | |
| 989 | - /** | |
| 990 | 801 | * Register user_id parameter for ap_object_type taxonomy REST API. |
| 991 | 802 | * |
| 992 | 803 | * @param array $params Existing collection parameters. |
| 993 | 804 | * |
| @@ -994,9 +805,9 @@ | ||
| 994 | 805 | * @return array Modified collection parameters. |
| 995 | 806 | */ |
| 996 | 807 | public static function register_object_type_user_param( $params ) { |
| 997 | 808 | $params['user_id'] = array( |
| 998 | - 'description' => \__( 'Filter terms to those with posts from this user ID.', 'activitypub' ), | |
| 809 | + 'description' => __( 'Filter terms to those with posts from this user ID.', 'activitypub' ), | |
| 999 | 810 | 'type' => 'integer', |
| 1000 | 811 | 'sanitize_callback' => 'absint', |
| 1001 | 812 | ); |
| 1002 | 813 | |
| @@ -1013,40 +824,9 @@ | ||
| 1013 | 824 | * |
| 1014 | 825 | * @return array Modified query arguments. |
| 1015 | 826 | */ |
| 1016 | 827 | public static function filter_object_type_by_user( $args, $request ) { |
| 1017 | - return self::filter_terms_by_user( $args, $request, 'ap_object_type' ); | |
| 1018 | - } | |
| 1019 | - | |
| 1020 | - /** | |
| 1021 | - * Filter the ap_tag REST query to terms that have posts for the given user. | |
| 1022 | - * | |
| 1023 | - * @param array $args Query arguments. | |
| 1024 | - * @param \WP_REST_Request $request The REST API request. | |
| 1025 | - * | |
| 1026 | - * @return array Modified query arguments. | |
| 1027 | - */ | |
| 1028 | - public static function filter_tag_by_user( $args, $request ) { | |
| 1029 | - return self::filter_terms_by_user( $args, $request, 'ap_tag' ); | |
| 1030 | - } | |
| 1031 | - | |
| 1032 | - /** | |
| 1033 | - * Filter a reader taxonomy REST query to terms that have posts for the given user. | |
| 1034 | - * | |
| 1035 | - * @param array $args Query arguments. | |
| 1036 | - * @param \WP_REST_Request $request The REST API request. | |
| 1037 | - * @param string $taxonomy The taxonomy to scope. | |
| 1038 | - * | |
| 1039 | - * @return array Modified query arguments. | |
| 1040 | - */ | |
| 1041 | - private static function filter_terms_by_user( $args, $request, $taxonomy ) { | |
| 1042 | 828 | $user_id = $request->get_param( 'user_id' ); |
| 1043 | - | |
| 1044 | - // Users who cannot list users may only ever see terms from their own feed. | |
| 1045 | - if ( ! \current_user_can( 'list_users' ) ) { | |
| 1046 | - $user_id = \get_current_user_id(); | |
| 1047 | - } | |
| 1048 | - | |
| 1049 | 829 | if ( null === $user_id ) { |
| 1050 | 830 | return $args; |
| 1051 | 831 | } |
| 1052 | 832 | |
| @@ -1059,25 +839,19 @@ | ||
| 1059 | 839 | FROM {$wpdb->term_taxonomy} tt |
| 1060 | 840 | INNER JOIN {$wpdb->term_relationships} tr ON tt.term_taxonomy_id = tr.term_taxonomy_id |
| 1061 | 841 | INNER JOIN {$wpdb->posts} p ON tr.object_id = p.ID |
| 1062 | 842 | INNER JOIN {$wpdb->postmeta} pm ON p.ID = pm.post_id |
| 1063 | - WHERE tt.taxonomy = %s | |
| 1064 | - AND p.post_type = %s | |
| 843 | + WHERE tt.taxonomy = 'ap_object_type' | |
| 844 | + AND p.post_type = 'ap_post' | |
| 1065 | 845 | AND pm.meta_key = '_activitypub_user_id' |
| 1066 | 846 | AND pm.meta_value = %s", |
| 1067 | - $taxonomy, | |
| 1068 | - Remote_Posts::POST_TYPE, | |
| 1069 | 847 | $user_id |
| 1070 | 848 | ) |
| 1071 | 849 | ); |
| 1072 | 850 | |
| 1073 | - /* | |
| 1074 | - * `include => array( 0 )` does not restrict anything: `WP_Term_Query` adds the `IN` clause | |
| 1075 | - * only when the imploded id list is truthy, and the string "0" is not, so the clause is | |
| 1076 | - * dropped and every term comes back. An id that cannot exist forces the empty result. | |
| 1077 | - */ | |
| 1078 | 851 | if ( empty( $term_ids ) ) { |
| 1079 | - $term_ids = array( PHP_INT_MAX ); | |
| 852 | + // Force empty result. | |
| 853 | + $term_ids = array( 0 ); | |
| 1080 | 854 | } |
| 1081 | 855 | |
| 1082 | 856 | $args['include'] = \array_map( 'intval', $term_ids ); |
| 1083 | 857 | |
| @@ -1099,9 +873,9 @@ | ||
| 1099 | 873 | 'activitypub_max_image_attachments' => (string) \get_option( 'activitypub_max_image_attachments', ACTIVITYPUB_MAX_IMAGE_ATTACHMENTS ), |
| 1100 | 874 | ); |
| 1101 | 875 | |
| 1102 | 876 | if ( isset( $post_metas[ $meta_key ] ) && $post_metas[ $meta_key ] === (string) $meta_value ) { |
| 1103 | - if ( 'update_post_metadata' === \current_action() ) { | |
| 877 | + if ( 'update_post_metadata' === current_action() ) { | |
| 1104 | 878 | \delete_post_meta( $object_id, $meta_key ); |
| 1105 | 879 | } |
| 1106 | 880 | |
| 1107 | 881 | $check = true; |