Skip to content

Commit

Permalink
Log post updates
Browse files Browse the repository at this point in the history
  • Loading branch information
akirk committed Dec 31, 2024
1 parent f63da85 commit 43142d9
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 16 deletions.
46 changes: 37 additions & 9 deletions feed-parsers/class-feed-parser-activitypub.php
Original file line number Diff line number Diff line change
Expand Up @@ -930,7 +930,31 @@ protected function process_incoming_activity( $type, $activity, $user_id, $user_
if ( isset( $activity['object']['type'] ) && 'Person' === $activity['object']['type'] ) {
return $this->handle_incoming_update_person( $activity['object'], $user_feed );
}
return $this->handle_incoming_create( $activity['object'] );
$item = $this->handle_incoming_create( $activity['object'] );
if ( isset( $activity['object']['type'] ) && 'Note' === $activity['object']['type'] ) {
$friend_user = $user_feed->get_friend_user();
$message = sprintf(
// translators: %s is the user login.
__( 'Received post update for %s', 'friends' ),
'<a href="' . esc_url( $friend_user->get_local_friends_page_url() ) . '">' . esc_html( $friend_user->display_name ) . '</a>'
);
$details = array();
$post_id = Feed::url_to_postid( $item->permalink );
if ( $post_id ) {
$_post = get_post( $post_id );
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 ) );
$renderer = new \WP_Text_Diff_Renderer_inline();
$details['content'] = $renderer->render( $diff );
}
$details['post_id'] = $post_id;
$details['activity'] = $activity;

Logging::log( 'post-update', $message, $details, self::SLUG, 0, $friend_user->ID );
}
return $item;
case 'delete':
return $this->handle_incoming_delete( $activity['object'] );
case 'announce':
Expand Down Expand Up @@ -1073,17 +1097,21 @@ private function handle_incoming_update_person( $activity, User_Feed $user_feed

$details = array();

if ( ! empty( $activity['summary'] ) ) {
$details['old-summary'] = $friend_user->description;
$details['new-summary'] = $activity['summary'];

if ( ! empty( $activity['summary'] ) && $friend_user->description !== $activity['summary'] ) {
if ( ! class_exists( 'WP_Text_Diff_Renderer_inline', false ) ) {
require ABSPATH . WPINC . '/wp-diff.php';
}
$diff = new \Text_Diff( explode( ' ', $friend_user->description ), explode( ' ', $activity['summary'] ) );
$renderer = new \WP_Text_Diff_Renderer_inline();
$details['summary'] = $renderer->render( $diff );
$friend_user->description = $activity['summary'];
$message .= __( 'Updated description.', 'friends' );
$message .= ' ' . __( 'Updated description.', 'friends' );
}
if ( ! empty( $activity['icon']['url'] ) ) {
$details['old-summary'] = '<img src="' . esc_url( $friend_user->get_avatar_url() ) . '" style="max-height: 32px; max-width: 32px" />';
$details['new-summary'] = '<img src="' . esc_url( $activity['icon']['url'] ) . '" style="max-height: 32px; max-width: 32px" />';
if ( ! empty( $activity['icon']['url'] ) && $friend_user->get_avatar_url() !== $activity['icon']['url'] ) {
$details['old-icon'] = '<img src="' . esc_url( $friend_user->get_avatar_url() ) . '" style="max-height: 32px; max-width: 32px" />';
$details['new-icon'] = '<img src="' . esc_url( $activity['icon']['url'] ) . '" style="max-height: 32px; max-width: 32px" />';
$friend_user->update_user_icon_url( $activity['icon']['url'] );
$message .= ' ' . __( 'Updated icon.', 'friends' );
}
$friend_user->save();

Expand Down
2 changes: 0 additions & 2 deletions includes/class-friends.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

namespace Friends;

use stdClass;

/**
* This is the class for the Friends Plugin.
*
Expand Down
4 changes: 4 additions & 0 deletions includes/class-frontend.php
Original file line number Diff line number Diff line change
Expand Up @@ -905,6 +905,10 @@ public function template_override( $template ) {
$wp_query->is_404 = false;

status_header( 200 );
if ( 'frontend/index' === $this->template ) {
$args['frontend_default_view'] = get_user_option( 'friends_frontend_default_view', get_current_user_id() );

}
return Friends::template_loader()->get_template_part( $this->template, null, $args, false );
}

Expand Down
2 changes: 1 addition & 1 deletion includes/class-logging.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public static function log( $type, $message, $details, $module, $user_id ) {
array(
'post_type' => self::CPT,
'post_title' => $message,
'post_content' => wp_json_encode( $details, JSON_PRETTY_PRINT ),
'post_content' => wp_json_encode( $details, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE ),
'post_author' => $user_id,
'post_status' => 'publish',
)
Expand Down
8 changes: 4 additions & 4 deletions includes/class-subscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ public function __construct( \WP_Term $term ) {
$this->data = (object) array(
'ID' => $this->ID,
'user_login' => $term->name,
'display_name' => get_metadata( 'term', $term->term_id, 'display_name', true ),
'user_url' => get_metadata( 'term', $term->term_id, 'user_url', true ),
'description' => get_metadata( 'term', $term->term_id, 'description', true ),
'user_registered' => get_metadata( 'term', $term->term_id, 'created', true ),
'display_name' => $this->get_user_option( 'display_name' ),
'user_url' => $this->get_user_option( 'user_url' ),
'description' => $this->get_user_option( 'description' ),
'user_registered' => $this->get_user_option( 'created' ),
);
}

Expand Down

0 comments on commit 43142d9

Please sign in to comment.