diff --git a/feed-parsers/class-feed-parser-activitypub.php b/feed-parsers/class-feed-parser-activitypub.php index 6381284e..5a6083ab 100644 --- a/feed-parsers/class-feed-parser-activitypub.php +++ b/feed-parsers/class-feed-parser-activitypub.php @@ -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' ), + '' . esc_html( $friend_user->display_name ) . '' + ); + $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': @@ -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'] = ''; - $details['new-summary'] = ''; + if ( ! empty( $activity['icon']['url'] ) && $friend_user->get_avatar_url() !== $activity['icon']['url'] ) { + $details['old-icon'] = ''; + $details['new-icon'] = ''; $friend_user->update_user_icon_url( $activity['icon']['url'] ); + $message .= ' ' . __( 'Updated icon.', 'friends' ); } $friend_user->save(); diff --git a/includes/class-friends.php b/includes/class-friends.php index feee5e26..7289408e 100644 --- a/includes/class-friends.php +++ b/includes/class-friends.php @@ -9,8 +9,6 @@ namespace Friends; -use stdClass; - /** * This is the class for the Friends Plugin. * diff --git a/includes/class-frontend.php b/includes/class-frontend.php index 2179bada..6dbd34bb 100644 --- a/includes/class-frontend.php +++ b/includes/class-frontend.php @@ -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 ); } diff --git a/includes/class-logging.php b/includes/class-logging.php index e72e5186..6527a56f 100644 --- a/includes/class-logging.php +++ b/includes/class-logging.php @@ -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', ) diff --git a/includes/class-subscription.php b/includes/class-subscription.php index c99c03db..bfd9db2c 100644 --- a/includes/class-subscription.php +++ b/includes/class-subscription.php @@ -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' ), ); }