Skip to content

Commit ac9022f

Browse files
committed
some small changes
1 parent 52f0d81 commit ac9022f

File tree

4 files changed

+48
-7
lines changed

4 files changed

+48
-7
lines changed

activitypub.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,13 @@ function activitypub_init() {
1919
require_once dirname( __FILE__ ) . '/includes/functions.php';
2020

2121
require_once dirname( __FILE__ ) . '/includes/class-activitypub.php';
22-
add_filter( 'template_include', array( 'Activity_Pub', 'render_profile' ), 99 );
23-
add_action( 'webfinger_user_data', array( 'Activity_Pub', 'add_webfinger_discovery' ), 10, 3 );
24-
add_filter( 'query_vars', array( 'Activity_Pub', 'add_query_vars' ) );
25-
add_action( 'init', array( 'Activity_Pub', 'add_rewrite_endpoint' ) );
22+
add_filter( 'template_include', array( 'Activitypub', 'render_profile' ), 99 );
23+
add_action( 'webfinger_user_data', array( 'Activitypub', 'add_webfinger_discovery' ), 10, 3 );
24+
add_filter( 'query_vars', array( 'Activitypub', 'add_query_vars' ) );
25+
add_action( 'init', array( 'Activitypub', 'add_rewrite_endpoint' ) );
26+
27+
require_once dirname( __FILE__ ) . '/includes/class-activitypub-outbox.php';
28+
// Configure the REST API route
29+
add_action( 'rest_api_init', array( 'Activitypub_Outbox', 'register_routes' ) );
2630
}
2731
add_action( 'plugins_loaded', 'activitypub_init' );
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
/**
3+
* ActivityPub Outbox Class
4+
*
5+
* @author Matthias Pfefferle
6+
*/
7+
class Activitypub_Outbox {
8+
/**
9+
* Register the Route.
10+
*/
11+
public static function register_routes() {
12+
register_rest_route(
13+
'activitypub/1.0', '/outbox', array(
14+
array(
15+
'methods' => WP_REST_Server::READABLE,
16+
'callback' => array( 'Activitypub_Outbox', 'get' ),
17+
),
18+
)
19+
);
20+
}
21+
22+
public static function get( $request ) {
23+
$outbox = new stdClass();
24+
25+
$outbox->{'@context'} = array(
26+
'https://www.w3.org/ns/activitystreams',
27+
'https://w3id.org/security/v1',
28+
);
29+
30+
//var_dump($request->get_param('page'));
31+
32+
return new WP_REST_Response( $outbox, 200 );
33+
}
34+
}

includes/class-activitypub.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
class Activity_Pub {
3+
class Activitypub {
44
public static function render_profile( $template ) {
55
if ( ! is_author() ) {
66
return $template;

templates/author-profile.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
$json->type = 'Person';
1919
$json->name = get_the_author_meta( 'display_name', $author_id );
2020
$json->summary = get_the_author_meta( 'description', $author_id );
21-
$json->preferredUsername = get_the_author();
21+
$json->preferredUsername = get_the_author(); // phpcs:ignore
2222
$json->url = get_author_posts_url( $author_id );
2323
$json->icon = array(
2424
'type' => 'Image',
@@ -32,7 +32,10 @@
3232
);
3333
}
3434

35+
$json->outbox = get_rest_url( null, '/activitypub/1.0/outbox' );
36+
3537
if ( method_exists( 'Magic_Sig', 'get_public_key' ) ) {
38+
// phpcs:ignore
3639
$json->publicKey = array(
3740
'id' => get_author_posts_url( $author_id ) . '#key',
3841
'owner' => get_author_posts_url( $author_id ),
@@ -53,7 +56,7 @@
5356
$options = 0;
5457
// JSON_PRETTY_PRINT added in PHP 5.4
5558
if ( get_query_var( 'pretty' ) ) {
56-
$options |= JSON_PRETTY_PRINT;
59+
$options |= JSON_PRETTY_PRINT; // phpcs:ignore
5760
}
5861

5962
/*

0 commit comments

Comments
 (0)