Skip to content

Commit

Permalink
Fix word diff
Browse files Browse the repository at this point in the history
  • Loading branch information
akirk committed Jan 2, 2025
1 parent a1e665d commit 91c11b6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
22 changes: 14 additions & 8 deletions feed-parsers/class-feed-parser-activitypub.php
Original file line number Diff line number Diff line change
Expand Up @@ -945,14 +945,19 @@ protected function process_incoming_activity( $type, $activity, $user_id, $user_
if ( ! class_exists( 'WP_Text_Diff_Renderer_inline', false ) ) {
require ABSPATH . WPINC . '/wp-diff.php';
}
$diff = new \Text_Diff( explode( ' ', $item->content ), explode( ' ', $post->post_content ) );
$diff = new \Text_Diff( explode( 'PHP_EOL', wp_strip_all_tags( $item->content ) ), explode( 'PHP_EOL', wp_strip_all_tags( $_post->post_content ) ) );
$renderer = new \WP_Text_Diff_Renderer_inline();
$details['content'] = $renderer->render( $diff );
if ( empty( $details['content'] ) ) {
unset( $details['content'] );
}
}
$details['post_id'] = $post_id;
$details['activity'] = $activity;

Logging::log( 'post-update', $message, $details, self::SLUG, 0, $friend_user->ID );
if ( ! empty( $details ) ) {
$details['post_id'] = $post_id;
$details['activity'] = $activity;
Logging::log( 'post-update', $message, $details, self::SLUG, 0, $friend_user->ID );
}
}
return $item;
case 'delete':
Expand Down Expand Up @@ -1102,7 +1107,7 @@ private function handle_incoming_update_person( $activity, User_Feed $user_feed
require ABSPATH . WPINC . '/wp-diff.php';
}
$summary = wp_encode_emoji( $activity['summary'] );
$diff = new \Text_Diff( explode( ' ', $friend_user->description ), explode( ' ', $summary ) );
$diff = new \Text_Diff( explode( PHP_EOL, $friend_user->description ), explode( PHP_EOL, $summary ) );
$renderer = new \WP_Text_Diff_Renderer_inline();
$details['summary'] = $renderer->render( $diff );
$friend_user->description = $summary;
Expand All @@ -1116,9 +1121,10 @@ private function handle_incoming_update_person( $activity, User_Feed $user_feed
}
$friend_user->save();

$details['object'] = $activity;

Logging::log( 'user-update', $message, $details, self::SLUG, 0, $friend_user->ID );
if ( ! empty( $details ) ) {
$details['object'] = $activity;
Logging::log( 'user-update', $message, $details, self::SLUG, 0, $friend_user->ID );
}

return null; // No feed item to submit.
}
Expand Down
11 changes: 11 additions & 0 deletions templates/admin/logs.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@
*/

?>
<style>
del {
background-color: #ffabaf;
text-decoration: none;
}

ins {
background-color: #68de7c;
text-decoration: none;
}
</style>
<table class="widefat">
<thead>
<tr>
Expand Down

0 comments on commit 91c11b6

Please sign in to comment.