[WIP] Hack on comments
This commit is contained in:
parent
3293e50d71
commit
0de2b2c7e1
@ -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',
|
||||
|
@ -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(
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
Loading…
Reference in New Issue
Block a user