diff --git a/includes/client/comments.php b/includes/client/comments.php index 082a306..4547264 100644 --- a/includes/client/comments.php +++ b/includes/client/comments.php @@ -96,13 +96,13 @@ function comment_to_object( $comment, $actor_slug ) { if ( $comment->comment_parent !== '0' ) { $parent_comment = \get_comment( $comment->comment_parent ); $parent_object = \pterotype\objects\get_object_by( - 'url', \get_comment_link( $parent_comment ) + 'url', get_comment_object_url( \get_comment_link( $parent_comment ) ) ); if ( $parent_object ) { $inReplyTo = $parent_object['id']; } } - $link = \get_comment_link( $comment ); + $link = get_comment_object_url ( \get_comment_link( $comment ) ); $object = array( '@context' => array( 'https://www.w3.org/ns/activitystreams' ), 'type' => 'Note', @@ -120,6 +120,19 @@ function comment_to_object( $comment, $actor_slug ) { return $object; } +function get_comment_object_url( $comment_link ) { + $parsed = \wp_parse_url( $comment_link ); + if ( ! $parsed ) { + return; + } + $anchor = $parsed['fragment']; + $base = $parsed['scheme'] . '://' . $parsed['host']; + if ( array_key_exists( 'port', $parsed ) ) { + $base = $base . ':' . $parsed['port']; + } + return $base . $parsed['path'] . '?pterotype_comment=' . $anchor; +} + function get_comment_to( $comment, $followers_id ) { $to = array( 'https://www.w3.org/ns/activitystreams#Public', diff --git a/includes/init.php b/includes/init.php index 539fcd8..fea8b82 100644 --- a/includes/init.php +++ b/includes/init.php @@ -35,6 +35,7 @@ add_action( 'pterotype_load', function() { add_action( 'generate_rewrite_rules', '\pterotype\webfinger\generate_rewrite_rules', 111 ); add_action( 'parse_request', '\pterotype\webfinger\parse_request', 111 ); add_filter( 'query_vars', '\pterotype\webfinger\query_vars' ); +add_filter( 'query_vars', '\pterotype\api\query_vars' ); add_action( 'well_known_webfinger', '\pterotype\webfinger\handle' ); add_action( 'transition_post_status', '\pterotype\posts\handle_post_status_change', 10, 3 ); add_action( diff --git a/includes/server/api.php b/includes/server/api.php index eea7753..ad382b7 100644 --- a/includes/server/api.php +++ b/includes/server/api.php @@ -109,8 +109,14 @@ function register_routes() { ) ); } +function query_vars( $query_vars ) { + $query_vars[] = 'pterotype_comment'; + return $query_vars; +} + function handle_non_api_requests() { global $wp; + global $wp_query; $accept = $_SERVER['HTTP_ACCEPT']; if ( strpos( $accept, 'application/ld+json' ) !== false ) { $current_url = \trailingslashit( @@ -123,6 +129,12 @@ function handle_non_api_requests() { echo wp_json_encode( $object ); exit; } + } else if ( array_key_exists( 'pterotype_comment', $wp_query->query_vars ) ) { + $comment_anchor = $wp_query->query_vars['pterotype_comment']; + $current_url = \trailingslashit( home_url( $wp->request ) ); + $actual_url = $current_url . '#' . $comment_anchor; + \wp_redirect( $actual_url ); + exit; } } ?>