| @@ -3,8 +3,10 @@ | ||
| 3 | 3 | |
| 4 | 4 | use WP_DEBUG; |
| 5 | 5 | use WP_DEBUG_LOG; |
| 6 | 6 | |
| 7 | +use function Activitypub\object_to_uri; | |
| 8 | + | |
| 7 | 9 | /** |
| 8 | 10 | * ActivityPub Debug Class |
| 9 | 11 | * |
| 10 | 12 | * @author Matthias Pfefferle |
| @@ -13,24 +15,32 @@ | ||
| 13 | 15 | /** |
| 14 | 16 | * Initialize the class, registering WordPress hooks |
| 15 | 17 | */ |
| 16 | 18 | public static function init() { |
| 17 | - if ( WP_DEBUG && WP_DEBUG_LOG ) { | |
| 19 | + if ( WP_DEBUG_LOG ) { | |
| 18 | 20 | \add_action( 'activitypub_safe_remote_post_response', array( self::class, 'log_remote_post_responses' ), 10, 4 ); |
| 21 | + \add_action( 'activitypub_inbox', array( self::class, 'log_inbox' ), 10, 4 ); | |
| 19 | 22 | } |
| 20 | 23 | } |
| 21 | 24 | |
| 25 | + // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed, VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable | |
| 22 | 26 | public static function log_remote_post_responses( $response, $url, $body, $user_id ) { |
| 23 | 27 | // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log, WordPress.PHP.DevelopmentFunctions.error_log_print_r |
| 24 | - \error_log( "Request to: {$url} with response: " . \print_r( $response, true ) ); | |
| 28 | + \error_log( "[OUTBOX] Request to: {$url} with Response: " . \print_r( $response, true ) ); | |
| 25 | 29 | } |
| 26 | 30 | |
| 27 | - public static function write_log( $log ) { | |
| 28 | - if ( \is_array( $log ) || \is_object( $log ) ) { | |
| 31 | + // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed, VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable | |
| 32 | + public static function log_inbox( $data, $user_id, $type, $activity ) { | |
| 33 | + $type = strtolower( $type ); | |
| 34 | + | |
| 35 | + if ( 'delete' !== $type ) { | |
| 36 | + $url = object_to_uri( $data['actor'] ); | |
| 29 | 37 | // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log, WordPress.PHP.DevelopmentFunctions.error_log_print_r |
| 30 | - \error_log( \print_r( $log, true ) ); | |
| 31 | - } else { | |
| 32 | - // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log | |
| 33 | - \error_log( $log ); | |
| 38 | + \error_log( "[INBOX] Request From: {$url} with Activity: " . \print_r( $data, true ) ); | |
| 34 | 39 | } |
| 40 | + } | |
| 41 | + | |
| 42 | + public static function write_log( $log ) { | |
| 43 | + // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log, WordPress.PHP.DevelopmentFunctions.error_log_print_r | |
| 44 | + \error_log( \print_r( $log, true ) ); | |
| 35 | 45 | } |
| 36 | 46 | } |