PluginProbe
ActivityPub / 0.3.2
ActivityPub v0.3.2
9.3.1 9.3.0 9.2.2 9.2.1 9.2.0 9.1.0 9.0.2 9.0.1 9.0.0 8.3.0 8.2.1 8.2.0 8.1.1 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.2.0 1.3.0 2.0.0 2.0.1 2.1.0 2.1.1 All 160 releases
activitypub / templates / json-author.php

json-author.php in ActivityPub 0.3.2, at templates/json-author.php

113 lines 3.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 $author_id = get_the_author_meta( 'ID' );
3
4 $json = new stdClass();
5
6 $json->{'@context'} = get_activitypub_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 } else {
28 $json->image = array();
29 }
30
31 $json->inbox = get_rest_url( null, "/activitypub/1.0/users/$author_id/inbox" );
32 $json->outbox = get_rest_url( null, "/activitypub/1.0/users/$author_id/outbox" );
33 $json->followers = get_rest_url( null, "/activitypub/1.0/users/$author_id/followers" );
34
35 $json->manuallyApprovesFollowers = apply_filters( 'activitypub_json_manually_approves_followers', __return_false() ); // phpcs:ignore
36
37 // phpcs:ignore
38 $json->publicKey = array(
39 'id' => get_author_posts_url( $author_id ) . '#main-key',
40 'owner' => get_author_posts_url( $author_id ),
41 'publicKeyPem' => trim( Activitypub_Signature::get_public_key( $author_id ) ),
42 );
43
44 $json->tag = array();
45 $json->attachment = array();
46
47 $json->attachment[] = array(
48 'type' => 'PropertyValue',
49 'name' => __( 'Blog', 'activitypub' ),
50 'value' => html_entity_decode(
51 '<a rel="me" title="' . esc_attr( home_url( '/' ) ) . '" target="_blank" href="' . home_url( '/' ) . '">' . wp_parse_url( home_url( '/' ), PHP_URL_HOST ) . '</a>',
52 ENT_QUOTES,
53 'UTF-8'
54 ),
55 );
56
57 $json->attachment[] = array(
58 'type' => 'PropertyValue',
59 'name' => __( 'Profile', 'activitypub' ),
60 'value' => html_entity_decode(
61 '<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>',
62 ENT_QUOTES,
63 'UTF-8'
64 ),
65 );
66
67 if ( get_the_author_meta( 'user_url', $author_id ) ) {
68 $json->attachment[] = array(
69 'type' => 'PropertyValue',
70 'name' => __( 'Website', 'activitypub' ),
71 'value' => html_entity_decode(
72 '<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>',
73 ENT_QUOTES,
74 'UTF-8'
75 ),
76 );
77 }
78
79 //$json->endpoints = array(
80 // 'sharedInbox' => get_rest_url( null, '/activitypub/1.0/inbox' ),
81 //);
82
83 // filter output
84 $json = apply_filters( 'activitypub_json_author_array', $json );
85
86 /*
87 * Action triggerd prior to the ActivityPub profile being created and sent to the client
88 */
89 do_action( 'activitypub_json_author_pre' );
90
91 $options = 0;
92 // JSON_PRETTY_PRINT added in PHP 5.4
93 if ( get_query_var( 'pretty' ) ) {
94 $options |= JSON_PRETTY_PRINT; // phpcs:ignore
95 }
96
97 $options |= JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_QUOT;
98
99 /*
100 * Options to be passed to json_encode()
101 *
102 * @param int $options The current options flags
103 */
104 $options = apply_filters( 'activitypub_json_author_options', $options );
105
106 header( 'Content-Type: application/activity+json' );
107 echo wp_json_encode( $json, $options );
108
109 /*
110 * Action triggerd after the ActivityPub profile has been created and sent to the client
111 */
112 do_action( 'activitypub_json_author_post' );
113