2018-09-27 22:27:23 +02:00
|
|
|
<?php
|
2019-09-27 11:36:52 +02:00
|
|
|
$author_id = \get_the_author_meta( 'ID' );
|
2018-09-27 22:27:23 +02:00
|
|
|
|
2019-09-27 11:36:52 +02:00
|
|
|
$json = new \stdClass();
|
2018-09-27 22:27:23 +02:00
|
|
|
|
2019-02-24 12:07:41 +01:00
|
|
|
$json->{'@context'} = \Activitypub\get_context();
|
2019-09-27 11:36:52 +02:00
|
|
|
$json->id = \get_author_posts_url( $author_id );
|
2018-09-27 22:27:23 +02:00
|
|
|
$json->type = 'Person';
|
2019-09-27 11:36:52 +02:00
|
|
|
$json->name = \get_the_author_meta( 'display_name', $author_id );
|
|
|
|
$json->summary = \html_entity_decode(
|
2023-03-14 18:37:20 +01:00
|
|
|
\Activitypub\get_author_description( $author_id ),
|
2020-05-12 19:42:09 +02:00
|
|
|
\ENT_QUOTES,
|
2018-12-08 00:02:18 +01:00
|
|
|
'UTF-8'
|
|
|
|
);
|
2019-09-27 11:36:52 +02:00
|
|
|
$json->preferredUsername = \get_the_author_meta( 'login', $author_id ); // phpcs:ignore
|
|
|
|
$json->url = \get_author_posts_url( $author_id );
|
2018-09-27 22:27:23 +02:00
|
|
|
$json->icon = array(
|
|
|
|
'type' => 'Image',
|
2019-09-27 11:36:52 +02:00
|
|
|
'url' => \get_avatar_url( $author_id, array( 'size' => 120 ) ),
|
2018-09-27 22:27:23 +02:00
|
|
|
);
|
|
|
|
|
2023-02-20 18:42:00 +01:00
|
|
|
$json->published = \gmdate( 'Y-m-d\TH:i:s\Z', \strtotime( \get_the_author_meta( 'registered', $author_id ) ) );
|
|
|
|
|
2019-09-27 11:36:52 +02:00
|
|
|
if ( \has_header_image() ) {
|
2018-09-27 22:27:23 +02:00
|
|
|
$json->image = array(
|
|
|
|
'type' => 'Image',
|
2019-09-27 11:36:52 +02:00
|
|
|
'url' => \get_header_image(),
|
2018-09-27 22:27:23 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-05-12 21:58:50 +02:00
|
|
|
$json->inbox = get_rest_url_by_path( sprintf( 'users/%d/inbox', $author_id ) );
|
|
|
|
$json->outbox = get_rest_url_by_path( sprintf( 'users/%d/outbox', $author_id ) );
|
|
|
|
$json->followers = get_rest_url_by_path( sprintf( 'users/%d/followers', $author_id ) );
|
|
|
|
$json->following = get_rest_url_by_path( sprintf( 'users/%d/following', $author_id ) );
|
2018-09-27 22:27:23 +02:00
|
|
|
|
2020-05-12 20:30:06 +02:00
|
|
|
$json->manuallyApprovesFollowers = \apply_filters( 'activitypub_json_manually_approves_followers', \__return_false() ); // phpcs:ignore
|
2018-09-27 22:27:23 +02:00
|
|
|
|
2018-10-02 22:25:40 +02:00
|
|
|
// phpcs:ignore
|
|
|
|
$json->publicKey = array(
|
2019-09-27 11:36:52 +02:00
|
|
|
'id' => \get_author_posts_url( $author_id ) . '#main-key',
|
|
|
|
'owner' => \get_author_posts_url( $author_id ),
|
|
|
|
'publicKeyPem' => \trim( \Activitypub\Signature::get_public_key( $author_id ) ),
|
2018-10-02 22:25:40 +02:00
|
|
|
);
|
2018-09-27 22:27:23 +02:00
|
|
|
|
|
|
|
$json->tag = array();
|
|
|
|
$json->attachment = array();
|
2018-11-04 21:38:11 +01:00
|
|
|
|
2021-09-15 17:00:20 +02:00
|
|
|
$json->attachment['blog_url'] = array(
|
2018-11-04 21:38:11 +01:00
|
|
|
'type' => 'PropertyValue',
|
2020-05-12 20:30:06 +02:00
|
|
|
'name' => \__( 'Blog', 'activitypub' ),
|
2019-09-27 11:36:52 +02:00
|
|
|
'value' => \html_entity_decode(
|
2020-05-12 19:42:09 +02:00
|
|
|
'<a rel="me" title="' . \esc_attr( \home_url( '/' ) ) . '" target="_blank" href="' . \home_url( '/' ) . '">' . \wp_parse_url( \home_url( '/' ), \PHP_URL_HOST ) . '</a>',
|
|
|
|
\ENT_QUOTES,
|
2018-12-08 00:02:18 +01:00
|
|
|
'UTF-8'
|
|
|
|
),
|
2018-11-04 21:38:11 +01:00
|
|
|
);
|
|
|
|
|
2021-09-15 17:00:20 +02:00
|
|
|
$json->attachment['profile_url'] = array(
|
2018-11-04 21:38:11 +01:00
|
|
|
'type' => 'PropertyValue',
|
2020-05-12 20:30:06 +02:00
|
|
|
'name' => \__( 'Profile', 'activitypub' ),
|
2019-09-27 11:36:52 +02:00
|
|
|
'value' => \html_entity_decode(
|
2020-05-12 19:42:09 +02:00
|
|
|
'<a rel="me" title="' . \esc_attr( \get_author_posts_url( $author_id ) ) . '" target="_blank" href="' . \get_author_posts_url( $author_id ) . '">' . \wp_parse_url( \get_author_posts_url( $author_id ), \PHP_URL_HOST ) . '</a>',
|
|
|
|
\ENT_QUOTES,
|
2018-12-08 00:02:18 +01:00
|
|
|
'UTF-8'
|
|
|
|
),
|
2018-11-04 21:38:11 +01:00
|
|
|
);
|
|
|
|
|
2019-09-27 11:36:52 +02:00
|
|
|
if ( \get_the_author_meta( 'user_url', $author_id ) ) {
|
2021-09-15 17:00:20 +02:00
|
|
|
$json->attachment['user_url'] = array(
|
2018-11-04 21:38:11 +01:00
|
|
|
'type' => 'PropertyValue',
|
2020-05-12 20:30:06 +02:00
|
|
|
'name' => \__( 'Website', 'activitypub' ),
|
2019-09-27 11:36:52 +02:00
|
|
|
'value' => \html_entity_decode(
|
2020-05-12 19:42:09 +02:00
|
|
|
'<a rel="me" title="' . \esc_attr( \get_the_author_meta( 'user_url', $author_id ) ) . '" target="_blank" href="' . \get_the_author_meta( 'user_url', $author_id ) . '">' . \wp_parse_url( \get_the_author_meta( 'user_url', $author_id ), \PHP_URL_HOST ) . '</a>',
|
|
|
|
\ENT_QUOTES,
|
2018-12-08 00:02:18 +01:00
|
|
|
'UTF-8'
|
|
|
|
),
|
2018-11-04 21:38:11 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-09-27 22:27:23 +02:00
|
|
|
// filter output
|
2021-06-08 10:28:45 +02:00
|
|
|
$json = \apply_filters( 'activitypub_json_author_array', $json, $author_id );
|
2018-09-27 22:27:23 +02:00
|
|
|
|
2021-09-15 17:00:20 +02:00
|
|
|
// migrate to ActivityPub standard
|
|
|
|
$json->attachment = array_values( $json->attachment );
|
|
|
|
|
2018-09-27 22:27:23 +02:00
|
|
|
/*
|
|
|
|
* Action triggerd prior to the ActivityPub profile being created and sent to the client
|
|
|
|
*/
|
2021-06-08 10:28:45 +02:00
|
|
|
\do_action( 'activitypub_json_author_pre', $author_id );
|
2018-09-27 22:27:23 +02:00
|
|
|
|
|
|
|
$options = 0;
|
|
|
|
// JSON_PRETTY_PRINT added in PHP 5.4
|
2019-09-27 11:36:52 +02:00
|
|
|
if ( \get_query_var( 'pretty' ) ) {
|
2020-05-12 19:42:09 +02:00
|
|
|
$options |= \JSON_PRETTY_PRINT; // phpcs:ignore
|
2018-09-27 22:27:23 +02:00
|
|
|
}
|
|
|
|
|
2020-05-12 19:42:09 +02:00
|
|
|
$options |= \JSON_HEX_TAG | \JSON_HEX_AMP | \JSON_HEX_QUOT;
|
2019-02-02 23:56:05 +01:00
|
|
|
|
2018-09-27 22:27:23 +02:00
|
|
|
/*
|
|
|
|
* Options to be passed to json_encode()
|
|
|
|
*
|
|
|
|
* @param int $options The current options flags
|
|
|
|
*/
|
2021-06-08 10:28:45 +02:00
|
|
|
$options = \apply_filters( 'activitypub_json_author_options', $options, $author_id );
|
2018-09-27 22:27:23 +02:00
|
|
|
|
2019-09-27 11:36:52 +02:00
|
|
|
\header( 'Content-Type: application/activity+json' );
|
|
|
|
echo \wp_json_encode( $json, $options );
|
2018-09-27 22:27:23 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Action triggerd after the ActivityPub profile has been created and sent to the client
|
|
|
|
*/
|
2021-06-08 10:28:45 +02:00
|
|
|
\do_action( 'activitypub_json_author_post', $author_id );
|