wordpress-activitypub/templates/comment-json.php

37 lines
1.1 KiB
PHP
Raw Permalink Normal View History

2022-04-15 03:04:43 +02:00
<?php
2022-12-23 12:10:42 +01:00
$comment = \get_comment( \get_query_var( 'replytocom' ) ); // phpcs:ignore
2022-04-15 03:04:43 +02:00
2023-10-06 15:45:58 +02:00
$object = new \Activitypub\Transformer\Comment( $comment );
$json = \array_merge( array( '@context' => \Activitypub\get_context() ), $object->to_object()->to_array() );
2022-04-15 03:04:43 +02:00
// filter output
$json = \apply_filters( 'activitypub_json_comment_array', $json );
/*
* Action triggerd prior to the ActivityPub profile being created and sent to the client
*/
\do_action( 'activitypub_json_comment_pre' );
$options = 0;
// JSON_PRETTY_PRINT added in PHP 5.4
if ( \get_query_var( 'pretty' ) ) {
$options |= \JSON_PRETTY_PRINT; // phpcs:ignore
}
$options |= \JSON_HEX_TAG | \JSON_HEX_AMP | \JSON_HEX_QUOT;
/*
* Options to be passed to json_encode()
*
* @param int $options The current options flags
*/
$options = \apply_filters( 'activitypub_json_comment_options', $options );
\header( 'Content-Type: application/activity+json' );
echo \wp_json_encode( $json, $options );
/*
* Action triggerd after the ActivityPub profile has been created and sent to the client
*/
\do_action( 'activitypub_json_comment_comment' );