| 1 |
<?php |
| 2 |
namespace Activitypub; |
| 3 |
|
| 4 |
use WP_DEBUG; |
| 5 |
use WP_DEBUG_LOG; |
| 6 |
|
| 7 |
use function Activitypub\object_to_uri; |
| 8 |
|
| 9 |
/** |
| 10 |
* ActivityPub Debug Class |
| 11 |
* |
| 12 |
* @author Matthias Pfefferle |
| 13 |
*/ |
| 14 |
class Debug { |
| 15 |
/** |
| 16 |
* Initialize the class, registering WordPress hooks |
| 17 |
*/ |
| 18 |
public static function init() { |
| 19 |
if ( WP_DEBUG_LOG ) { |
| 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 ); |
| 22 |
} |
| 23 |
} |
| 24 |
|
| 25 |
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed, VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
| 26 |
public static function log_remote_post_responses( $response, $url, $body, $user_id ) { |
| 27 |
// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log, WordPress.PHP.DevelopmentFunctions.error_log_print_r |
| 28 |
\error_log( "[OUTBOX] Request to: {$url} with Response: " . \print_r( $response, true ) ); |
| 29 |
} |
| 30 |
|
| 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'] ); |
| 37 |
// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log, WordPress.PHP.DevelopmentFunctions.error_log_print_r |
| 38 |
\error_log( "[INBOX] Request From: {$url} with Activity: " . \print_r( $data, true ) ); |
| 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 ) ); |
| 45 |
} |
| 46 |
} |
| 47 |
|