PluginProbe
ActivityPub / 5.7.0
ActivityPub v5.7.0
9.3.1 9.3.0 9.2.2 9.2.1 9.2.0 9.1.0 9.0.2 9.0.1 9.0.0 8.3.0 8.2.1 8.2.0 8.1.1 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.2.0 1.3.0 2.0.0 2.0.1 2.1.0 2.1.1 All 160 releases
← All changes | includes/class-debug.php +55 -33 2.1.05.7.0 View file →
@@ -1,57 +1,79 @@
1 1 <?php
2 +/**
3 + * Debug Class.
4 + *
5 + * @package Activitypub
6 + */
7 +
2 8 namespace Activitypub;
3 9
4 -use WP_DEBUG;
5 -use WP_DEBUG_LOG;
6 -
7 10 /**
8 - * ActivityPub Debug Class
11 + * ActivityPub Debug Class.
9 12 *
10 13 * @author Matthias Pfefferle
11 14 */
12 15 class Debug {
13 16 /**
14 - * Initialize the class, registering WordPress hooks
17 + * Initialize the class, registering WordPress hooks.
15 18 */
16 19 public static function init() {
17 - if ( WP_DEBUG_LOG ) {
18 - \add_action( 'activitypub_safe_remote_post_response', array( self::class, 'log_remote_post_responses' ), 10, 4 );
20 + if ( \WP_DEBUG && \WP_DEBUG_LOG ) {
21 + \add_action( 'activitypub_safe_remote_post_response', array( self::class, 'log_remote_post_responses' ), 10, 2 );
22 + \add_action( 'activitypub_inbox', array( self::class, 'log_inbox' ), 10, 3 );
23 +
24 + \add_action( 'activitypub_sent_to_inbox', array( self::class, 'log_sent_to_inbox' ), 10, 2 );
19 25 }
20 - if ( is_user_logged_in() ) {
21 - \add_filter( 'comment_text', array( self::class, 'show_comment_source' ), 10, 2 );
22 - }
23 26 }
24 27
25 - public static function show_comment_source( $comment_text, $comment ) {
26 - $was_sent = \get_comment_meta( $comment->comment_ID, 'activitypub_status', true );
28 + /**
29 + * Log the responses of remote post requests.
30 + *
31 + * @param array $response The response from the remote server.
32 + * @param string $url The URL of the remote server.
33 + */
34 + public static function log_remote_post_responses( $response, $url ) {
35 + // phpcs:ignore WordPress.PHP.DevelopmentFunctions
36 + \error_log( "[OUTBOX] Request to: {$url} with Response: " . \print_r( $response, true ) );
37 + }
27 38
28 - if ( $was_sent ) {
29 - // translators: %s is the federation state of the comment
30 - $comment_text .= '<p><small>' . sprintf( \__( 'Activitypub → (%s)', 'activitypub' ), $was_sent ) . '</small></p>';
31 - }
39 + /**
40 + * Log the inbox requests.
41 + *
42 + * @param array $data The Activity array.
43 + * @param int $user_id The ID of the local blog user.
44 + * @param string $type The type of the request.
45 + */
46 + public static function log_inbox( $data, $user_id, $type ) {
47 + $type = strtolower( $type );
32 48
33 - $was_received = \get_comment_meta( $comment->comment_ID, 'protocol', true );
34 -
35 - if ( 'activitypub' === $was_received ) {
36 - $comment_text .= '<p><small>' . \__( '← ActivityPub', 'activitypub' ) . '</small></p>';
49 + if ( 'delete' !== $type ) {
50 + $actor = $data['actor'] ?? '';
51 + $url = object_to_uri( $actor );
52 + // phpcs:ignore WordPress.PHP.DevelopmentFunctions
53 + \error_log( "[INBOX] Request From: {$url} with Activity: " . \print_r( $data, true ) );
37 54 }
38 -
39 - return $comment_text;
40 55 }
41 56
42 - // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed, VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
43 - public static function log_remote_post_responses( $response, $url, $body, $user_id ) {
44 - // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log, WordPress.PHP.DevelopmentFunctions.error_log_print_r
45 - \error_log( "Request to: {$url} with response: " . \print_r( $response, true ) );
57 + /**
58 + * Log the sent to follower action.
59 + *
60 + * @param array $result The result of the remote post request.
61 + * @param string $inbox The inbox URL.
62 + */
63 + public static function log_sent_to_inbox( $result, $inbox ) {
64 + if ( \is_wp_error( $result ) ) {
65 + // phpcs:ignore WordPress.PHP.DevelopmentFunctions
66 + \error_log( "[DISPATCHER] Failed Request to: {$inbox} with Result: " . \print_r( $result, true ) );
67 + }
46 68 }
47 69
70 + /**
71 + * Write a log entry.
72 + *
73 + * @param mixed $log The log entry.
74 + */
48 75 public static function write_log( $log ) {
49 - if ( \is_array( $log ) || \is_object( $log ) ) {
50 - // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log, WordPress.PHP.DevelopmentFunctions.error_log_print_r
51 - \error_log( \print_r( $log, true ) );
52 - } else {
53 - // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log
54 - \error_log( $log );
55 - }
76 + // phpcs:ignore WordPress.PHP.DevelopmentFunctions
77 + \error_log( \print_r( $log, true ) );
56 78 }
57 79 }