2020-04-07 13:03:04 +00:00
|
|
|
<?php
|
2024-10-09 12:44:17 +00:00
|
|
|
/**
|
|
|
|
* Debug Class.
|
|
|
|
*
|
|
|
|
* @package Activitypub
|
|
|
|
*/
|
|
|
|
|
2020-04-07 13:03:04 +00:00
|
|
|
namespace Activitypub;
|
|
|
|
|
2023-10-22 22:20:53 +00:00
|
|
|
use WP_DEBUG;
|
|
|
|
use WP_DEBUG_LOG;
|
|
|
|
|
2020-04-07 13:03:04 +00:00
|
|
|
/**
|
2024-10-09 12:44:17 +00:00
|
|
|
* ActivityPub Debug Class.
|
2020-04-07 13:03:04 +00:00
|
|
|
*
|
|
|
|
* @author Matthias Pfefferle
|
|
|
|
*/
|
|
|
|
class Debug {
|
|
|
|
/**
|
2024-10-09 12:44:17 +00:00
|
|
|
* Initialize the class, registering WordPress hooks.
|
2020-04-07 13:03:04 +00:00
|
|
|
*/
|
|
|
|
public static function init() {
|
2024-03-28 09:39:50 +00:00
|
|
|
if ( WP_DEBUG_LOG ) {
|
2024-10-09 12:44:17 +00:00
|
|
|
\add_action( 'activitypub_safe_remote_post_response', array( self::class, 'log_remote_post_responses' ), 10, 2 );
|
|
|
|
\add_action( 'activitypub_inbox', array( self::class, 'log_inbox' ), 10, 3 );
|
2020-04-07 13:03:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-09 12:44:17 +00:00
|
|
|
/**
|
|
|
|
* Log the responses of remote post requests.
|
|
|
|
*
|
|
|
|
* @param array $response The response from the remote server.
|
|
|
|
* @param string $url The URL of the remote server.
|
|
|
|
*/
|
|
|
|
public static function log_remote_post_responses( $response, $url ) {
|
|
|
|
// phpcs:ignore WordPress.PHP.DevelopmentFunctions
|
|
|
|
\error_log( "[OUTBOX] Request to: {$url} with Response: " . \print_r( $response, true ) );
|
2020-04-07 13:03:04 +00:00
|
|
|
}
|
|
|
|
|
2024-10-09 12:44:17 +00:00
|
|
|
/**
|
|
|
|
* Log the inbox requests.
|
|
|
|
*
|
|
|
|
* @param array $data The Activity array.
|
|
|
|
* @param int $user_id The ID of the local blog user.
|
|
|
|
* @param string $type The type of the request.
|
|
|
|
*/
|
|
|
|
public static function log_inbox( $data, $user_id, $type ) {
|
|
|
|
$type = strtolower( $type );
|
|
|
|
|
|
|
|
if ( 'delete' !== $type ) {
|
|
|
|
$url = object_to_uri( $data['actor'] );
|
|
|
|
// phpcs:ignore WordPress.PHP.DevelopmentFunctions
|
|
|
|
\error_log( "[INBOX] Request From: {$url} with Activity: " . \print_r( $data, true ) );
|
2020-04-07 13:03:04 +00:00
|
|
|
}
|
|
|
|
}
|
2024-10-09 12:44:17 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Write a log entry.
|
|
|
|
*
|
|
|
|
* @param mixed $log The log entry.
|
|
|
|
*/
|
|
|
|
public static function write_log( $log ) {
|
|
|
|
// phpcs:ignore WordPress.PHP.DevelopmentFunctions
|
|
|
|
\error_log( \print_r( $log, true ) );
|
|
|
|
}
|
2020-04-07 13:03:04 +00:00
|
|
|
}
|