| 1 |
<?php |
| 2 |
$author_id = get_the_author_meta( 'ID' ); |
| 3 |
|
| 4 |
$json = new stdClass(); |
| 5 |
|
| 6 |
$json->{'@context'} = \Activitypub\get_context(); |
| 7 |
$json->id = get_author_posts_url( $author_id ); |
| 8 |
$json->type = 'Person'; |
| 9 |
$json->name = get_the_author_meta( 'display_name', $author_id ); |
| 10 |
$json->summary = html_entity_decode( |
| 11 |
get_the_author_meta( 'description', $author_id ), |
| 12 |
ENT_QUOTES, |
| 13 |
'UTF-8' |
| 14 |
); |
| 15 |
$json->preferredUsername = get_the_author_meta( 'login', $author_id ); // phpcs:ignore |
| 16 |
$json->url = get_author_posts_url( $author_id ); |
| 17 |
$json->icon = array( |
| 18 |
'type' => 'Image', |
| 19 |
'url' => get_avatar_url( $author_id, array( 'size' => 120 ) ), |
| 20 |
); |
| 21 |
|
| 22 |
if ( has_header_image() ) { |
| 23 |
$json->image = array( |
| 24 |
'type' => 'Image', |
| 25 |
'url' => get_header_image(), |
| 26 |
); |
| 27 |
} |
| 28 |
|
| 29 |
$json->inbox = get_rest_url( null, "/activitypub/1.0/users/$author_id/inbox" ); |
| 30 |
$json->outbox = get_rest_url( null, "/activitypub/1.0/users/$author_id/outbox" ); |
| 31 |
$json->followers = get_rest_url( null, "/activitypub/1.0/users/$author_id/followers" ); |
| 32 |
$json->following = get_rest_url( null, "/activitypub/1.0/users/$author_id/following" ); |
| 33 |
|
| 34 |
$json->manuallyApprovesFollowers = apply_filters( 'activitypub_json_manually_approves_followers', __return_false() ); // phpcs:ignore |
| 35 |
|
| 36 |
// phpcs:ignore |
| 37 |
$json->publicKey = array( |
| 38 |
'id' => get_author_posts_url( $author_id ) . '#main-key', |
| 39 |
'owner' => get_author_posts_url( $author_id ), |
| 40 |
'publicKeyPem' => trim( \Activitypub\Signature::get_public_key( $author_id ) ), |
| 41 |
); |
| 42 |
|
| 43 |
$json->tag = array(); |
| 44 |
$json->attachment = array(); |
| 45 |
|
| 46 |
$json->attachment[] = array( |
| 47 |
'type' => 'PropertyValue', |
| 48 |
'name' => __( 'Blog', 'activitypub' ), |
| 49 |
'value' => html_entity_decode( |
| 50 |
'<a rel="me" title="' . esc_attr( home_url( '/' ) ) . '" target="_blank" href="' . home_url( '/' ) . '">' . wp_parse_url( home_url( '/' ), PHP_URL_HOST ) . '</a>', |
| 51 |
ENT_QUOTES, |
| 52 |
'UTF-8' |
| 53 |
), |
| 54 |
); |
| 55 |
|
| 56 |
$json->attachment[] = array( |
| 57 |
'type' => 'PropertyValue', |
| 58 |
'name' => __( 'Profile', 'activitypub' ), |
| 59 |
'value' => html_entity_decode( |
| 60 |
'<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>', |
| 61 |
ENT_QUOTES, |
| 62 |
'UTF-8' |
| 63 |
), |
| 64 |
); |
| 65 |
|
| 66 |
if ( get_the_author_meta( 'user_url', $author_id ) ) { |
| 67 |
$json->attachment[] = array( |
| 68 |
'type' => 'PropertyValue', |
| 69 |
'name' => __( 'Website', 'activitypub' ), |
| 70 |
'value' => html_entity_decode( |
| 71 |
'<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>', |
| 72 |
ENT_QUOTES, |
| 73 |
'UTF-8' |
| 74 |
), |
| 75 |
); |
| 76 |
} |
| 77 |
|
| 78 |
//$json->endpoints = array( |
| 79 |
// 'sharedInbox' => get_rest_url( null, '/activitypub/1.0/inbox' ), |
| 80 |
//); |
| 81 |
|
| 82 |
// filter output |
| 83 |
$json = apply_filters( 'activitypub_json_author_array', $json ); |
| 84 |
|
| 85 |
/* |
| 86 |
* Action triggerd prior to the ActivityPub profile being created and sent to the client |
| 87 |
*/ |
| 88 |
do_action( 'activitypub_json_author_pre' ); |
| 89 |
|
| 90 |
$options = 0; |
| 91 |
// JSON_PRETTY_PRINT added in PHP 5.4 |
| 92 |
if ( get_query_var( 'pretty' ) ) { |
| 93 |
$options |= JSON_PRETTY_PRINT; // phpcs:ignore |
| 94 |
} |
| 95 |
|
| 96 |
$options |= JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_QUOT; |
| 97 |
|
| 98 |
/* |
| 99 |
* Options to be passed to json_encode() |
| 100 |
* |
| 101 |
* @param int $options The current options flags |
| 102 |
*/ |
| 103 |
$options = apply_filters( 'activitypub_json_author_options', $options ); |
| 104 |
|
| 105 |
header( 'Content-Type: application/activity+json' ); |
| 106 |
echo wp_json_encode( $json, $options ); |
| 107 |
|
| 108 |
/* |
| 109 |
* Action triggerd after the ActivityPub profile has been created and sent to the client |
| 110 |
*/ |
| 111 |
do_action( 'activitypub_json_author_post' ); |
| 112 |
|