2022-09-27 23:28:45 +02:00
|
|
|
<?php
|
2022-12-23 12:10:42 +01:00
|
|
|
$post = \get_post(); // phpcs:ignore
|
|
|
|
$page = \get_query_var( 'page' ); // phpcs:ignore
|
2022-09-27 23:28:45 +02:00
|
|
|
|
|
|
|
$args = array(
|
|
|
|
'status' => 'approve',
|
|
|
|
'number' => '10',
|
2022-12-23 12:10:42 +01:00
|
|
|
'offset' => $page,
|
|
|
|
'type' => 'activitypub',
|
2022-09-27 23:28:45 +02:00
|
|
|
'post_id' => $post->ID,
|
2022-12-23 12:10:42 +01:00
|
|
|
'order' => 'ASC',
|
2022-09-27 23:28:45 +02:00
|
|
|
);
|
2022-12-23 12:10:42 +01:00
|
|
|
$comments = get_comments( $args ); // phpcs:ignore
|
2022-09-27 23:28:45 +02:00
|
|
|
|
|
|
|
$replies_request = \add_query_arg( $_SERVER['QUERY_STRING'], '', $post->guid );
|
2022-12-23 12:10:42 +01:00
|
|
|
$collection_id = \remove_query_arg( array( 'page', 'replytocom' ), $replies_request );
|
2022-09-27 23:28:45 +02:00
|
|
|
|
|
|
|
$json = new \stdClass();
|
|
|
|
$json->{'@context'} = 'https://www.w3.org/ns/activitystreams';
|
|
|
|
$json->id = $collection_id;
|
|
|
|
|
2022-12-23 12:10:42 +01:00
|
|
|
$collection_page = new \stdClass();
|
|
|
|
$collection_page->type = 'CollectionPage';
|
|
|
|
$collection_page->partOf = $collection_id; // phpcs:ignore
|
|
|
|
$collection_page->totalItems = \count( $comments ); // phpcs:ignore
|
2022-09-27 23:28:45 +02:00
|
|
|
|
2022-12-23 12:10:42 +01:00
|
|
|
if ( $page && ( ( \ceil ( $collection_page->totalItems / 10 ) ) > $page ) ) { // phpcs:ignore
|
|
|
|
$collection_page->first = \add_query_arg( 'page', 1, $collection_page->partOf ); // phpcs:ignore
|
|
|
|
$collection_page->next = \add_query_arg( 'page', $page + 1, $collection_page->partOf ); // phpcs:ignore
|
|
|
|
$collection_page->last = \add_query_arg( 'page', \ceil ( $collection_page->totalItems / 10 ), $collection_page->partOf ); // phpcs:ignore
|
2022-09-27 23:28:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
foreach ( $comments as $comment ) {
|
2022-12-23 12:10:42 +01:00
|
|
|
$remote_url = \get_comment_meta( $comment->comment_ID, 'source_url', true );
|
|
|
|
if ( $remote_url ) { //
|
|
|
|
$collection_page->items[] = $remote_url;
|
|
|
|
} else {
|
|
|
|
$activitypub_comment = new \Activitypub\Model\Comment( $comment );
|
|
|
|
$activitypub_activity = new \Activitypub\Model\Activity( 'Create', \Activitypub\Model\Activity::TYPE_NONE );
|
|
|
|
$activitypub_activity->from_post( $activitypub_comment->to_array() );
|
|
|
|
$collection_page->items[] = $activitypub_activity->to_array(); // phpcs:ignore
|
|
|
|
}
|
2022-09-27 23:28:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( ! \get_query_var( 'collection_page' ) ) {
|
2022-12-23 12:10:42 +01:00
|
|
|
$json->type = 'Collection';
|
|
|
|
//if +10, embed first
|
|
|
|
$json->first = $collection_page;
|
2022-09-27 23:28:45 +02:00
|
|
|
} else {
|
2022-12-23 12:10:42 +01:00
|
|
|
$json = $collection_page;
|
|
|
|
|
2022-09-27 23:28:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// filter output
|
|
|
|
$json = \apply_filters( 'activitypub_json_replies_array', $json );
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Action triggerd prior to the ActivityPub profile being created and sent to the client
|
|
|
|
*/
|
|
|
|
\do_action( 'activitypub_json_replies_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_replies_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_replies_comment' );
|