| @@ -1,8 +1,13 @@ | ||
| 1 | 1 | <?php |
| 2 | +/** | |
| 3 | + * Delete handler file. | |
| 4 | + * | |
| 5 | + * @package Activitypub | |
| 6 | + */ | |
| 7 | + | |
| 2 | 8 | namespace Activitypub\Handler; |
| 3 | 9 | |
| 4 | -use WP_Error; | |
| 5 | 10 | use WP_REST_Request; |
| 6 | 11 | use Activitypub\Http; |
| 7 | 12 | use Activitypub\Collection\Followers; |
| 8 | 13 | use Activitypub\Collection\Interactions; |
| @@ -11,9 +16,9 @@ | ||
| 11 | 16 | * Handles Delete requests. |
| 12 | 17 | */ |
| 13 | 18 | class Delete { |
| 14 | 19 | /** |
| 15 | - * Initialize the class, registering WordPress hooks | |
| 20 | + * Initialize the class, registering WordPress hooks. | |
| 16 | 21 | */ |
| 17 | 22 | public static function init() { |
| 18 | 23 | \add_action( |
| 19 | 24 | 'activitypub_inbox_delete', |
| @@ -19,9 +24,9 @@ | ||
| 19 | 24 | 'activitypub_inbox_delete', |
| 20 | 25 | array( self::class, 'handle_delete' ) |
| 21 | 26 | ); |
| 22 | 27 | |
| 23 | - // defer signature verification for `Delete` requests. | |
| 28 | + // Defer signature verification for `Delete` requests. | |
| 24 | 29 | \add_filter( |
| 25 | 30 | 'activitypub_defer_signature_verification', |
| 26 | 31 | array( self::class, 'defer_signature_verification' ), |
| 27 | 32 | 10, |
| @@ -27,9 +32,9 @@ | ||
| 27 | 32 | 10, |
| 28 | 33 | 2 |
| 29 | 34 | ); |
| 30 | 35 | |
| 31 | - // side effect | |
| 36 | + // Side effect. | |
| 32 | 37 | \add_action( |
| 33 | 38 | 'activitypub_delete_actor_interactions', |
| 34 | 39 | array( self::class, 'delete_interactions' ) |
| 35 | 40 | ); |
| @@ -38,16 +43,18 @@ | ||
| 38 | 43 | /** |
| 39 | 44 | * Handles "Delete" requests. |
| 40 | 45 | * |
| 41 | 46 | * @param array $activity The delete activity. |
| 42 | - * @param int $user_id The ID of the user performing the delete activity. | |
| 43 | 47 | */ |
| 44 | 48 | public static function handle_delete( $activity ) { |
| 45 | 49 | $object_type = isset( $activity['object']['type'] ) ? $activity['object']['type'] : ''; |
| 46 | 50 | |
| 47 | 51 | switch ( $object_type ) { |
| 48 | - // Actor Types | |
| 49 | - // @see https://www.w3.org/TR/activitystreams-vocabulary/#actor-types | |
| 52 | + /* | |
| 53 | + * Actor Types. | |
| 54 | + * | |
| 55 | + * @see https://www.w3.org/TR/activitystreams-vocabulary/#actor-types | |
| 56 | + */ | |
| 50 | 57 | case 'Person': |
| 51 | 58 | case 'Group': |
| 52 | 59 | case 'Organization': |
| 53 | 60 | case 'Service': |
| @@ -53,10 +60,14 @@ | ||
| 53 | 60 | case 'Service': |
| 54 | 61 | case 'Application': |
| 55 | 62 | self::maybe_delete_follower( $activity ); |
| 56 | 63 | break; |
| 57 | - // Object and Link Types | |
| 58 | - // @see https://www.w3.org/TR/activitystreams-vocabulary/#object-types | |
| 64 | + | |
| 65 | + /* | |
| 66 | + * Object and Link Types. | |
| 67 | + * | |
| 68 | + * @see https://www.w3.org/TR/activitystreams-vocabulary/#object-types | |
| 69 | + */ | |
| 59 | 70 | case 'Note': |
| 60 | 71 | case 'Article': |
| 61 | 72 | case 'Image': |
| 62 | 73 | case 'Audio': |
| @@ -64,29 +75,36 @@ | ||
| 64 | 75 | case 'Event': |
| 65 | 76 | case 'Document': |
| 66 | 77 | self::maybe_delete_interaction( $activity ); |
| 67 | 78 | break; |
| 68 | - // Tombstone Type | |
| 69 | - // @see: https://www.w3.org/TR/activitystreams-vocabulary/#dfn-tombstone | |
| 79 | + | |
| 80 | + /* | |
| 81 | + * Tombstone Type. | |
| 82 | + * | |
| 83 | + * @see: https://www.w3.org/TR/activitystreams-vocabulary/#dfn-tombstone | |
| 84 | + */ | |
| 70 | 85 | case 'Tombstone': |
| 71 | 86 | self::maybe_delete_interaction( $activity ); |
| 72 | 87 | break; |
| 73 | - // Minimal Activity | |
| 74 | - // @see https://www.w3.org/TR/activitystreams-core/#example-1 | |
| 88 | + | |
| 89 | + /* | |
| 90 | + * Minimal Activity. | |
| 91 | + * | |
| 92 | + * @see https://www.w3.org/TR/activitystreams-core/#example-1 | |
| 93 | + */ | |
| 75 | 94 | default: |
| 76 | - // ignore non Minimal Activities. | |
| 95 | + // Ignore non Minimal Activities. | |
| 77 | 96 | if ( ! is_string( $activity['object'] ) ) { |
| 78 | 97 | return; |
| 79 | 98 | } |
| 80 | 99 | |
| 81 | - // check if Object is an Actor. | |
| 100 | + // Check if Object is an Actor. | |
| 82 | 101 | if ( $activity['actor'] === $activity['object'] ) { |
| 83 | 102 | self::maybe_delete_follower( $activity ); |
| 84 | - self::maybe_delete_interactions( $activity ); | |
| 85 | - } else { // assume a interaction otherwise. | |
| 103 | + } else { // Assume an interaction otherwise. | |
| 86 | 104 | self::maybe_delete_interaction( $activity ); |
| 87 | 105 | } |
| 88 | - // maybe handle Delete Activity for other Object Types. | |
| 106 | + // Maybe handle Delete Activity for other Object Types. | |
| 89 | 107 | break; |
| 90 | 108 | } |
| 91 | 109 | } |
| 92 | 110 | |
| @@ -95,13 +113,15 @@ | ||
| 95 | 113 | * |
| 96 | 114 | * @param array $activity The delete activity. |
| 97 | 115 | */ |
| 98 | 116 | public static function maybe_delete_follower( $activity ) { |
| 117 | + /* @var \Activitypub\Model\Follower $follower Follower object. */ | |
| 99 | 118 | $follower = Followers::get_follower_by_actor( $activity['actor'] ); |
| 100 | 119 | |
| 101 | - // verify if Actor is deleted. | |
| 120 | + // Verify that Actor is deleted. | |
| 102 | 121 | if ( $follower && Http::is_tombstone( $activity['actor'] ) ) { |
| 103 | 122 | $follower->delete(); |
| 123 | + self::maybe_delete_interactions( $activity ); | |
| 104 | 124 | } |
| 105 | 125 | } |
| 106 | 126 | |
| 107 | 127 | /** |
| @@ -109,9 +129,9 @@ | ||
| 109 | 129 | * |
| 110 | 130 | * @param array $activity The delete activity. |
| 111 | 131 | */ |
| 112 | 132 | public static function maybe_delete_interactions( $activity ) { |
| 113 | - // verify if Actor is deleted. | |
| 133 | + // Verify that Actor is deleted. | |
| 114 | 134 | if ( Http::is_tombstone( $activity['actor'] ) ) { |
| 115 | 135 | \wp_schedule_single_event( |
| 116 | 136 | \time(), |
| 117 | 137 | 'activitypub_delete_actor_interactions', |
| @@ -122,9 +142,9 @@ | ||
| 122 | 142 | |
| 123 | 143 | /** |
| 124 | 144 | * Delete comments from an Actor. |
| 125 | 145 | * |
| 126 | - * @param array $comments The comments to delete. | |
| 146 | + * @param string $actor The URL of the actor whose comments to delete. | |
| 127 | 147 | */ |
| 128 | 148 | public static function delete_interactions( $actor ) { |
| 129 | 149 | $comments = Interactions::get_interactions_by_actor( $actor ); |
| 130 | 150 | |
| @@ -129,9 +149,9 @@ | ||
| 129 | 149 | $comments = Interactions::get_interactions_by_actor( $actor ); |
| 130 | 150 | |
| 131 | 151 | if ( is_array( $comments ) ) { |
| 132 | 152 | foreach ( $comments as $comment ) { |
| 133 | - wp_delete_comment( $comment->comment_ID ); | |
| 153 | + wp_delete_comment( $comment->comment_ID, true ); | |
| 134 | 154 | } |
| 135 | 155 | } |
| 136 | 156 | } |
| 137 | 157 | |
| @@ -138,10 +158,8 @@ | ||
| 138 | 158 | /** |
| 139 | 159 | * Delete a Reaction if URL is a Tombstone. |
| 140 | 160 | * |
| 141 | 161 | * @param array $activity The delete activity. |
| 142 | - * | |
| 143 | - * @return void | |
| 144 | 162 | */ |
| 145 | 163 | public static function maybe_delete_interaction( $activity ) { |
| 146 | 164 | if ( is_array( $activity['object'] ) ) { |
| 147 | 165 | $id = $activity['object']['id']; |