From f89dd048a4cbce1cf3b95cd6d88aa5ee967f80b2 Mon Sep 17 00:00:00 2001 From: Jeremy Dormitzer Date: Tue, 2 Oct 2018 13:27:29 -0400 Subject: [PATCH] [WIP] Register webfinger route --- includes/init.php | 6 ++++++ includes/server/actors.php | 2 ++ includes/server/webfinger.php | 29 +++++++++++++++++++++++++++++ pterotype.php | 14 ++++++++++++-- 4 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 includes/server/webfinger.php diff --git a/includes/init.php b/includes/init.php index 1bde597..f07b1ed 100644 --- a/includes/init.php +++ b/includes/init.php @@ -4,6 +4,7 @@ namespace init; require_once plugin_dir_path( __FILE__ ) . 'server/api.php'; require_once plugin_dir_path( __FILE__ ) . 'server/actors.php'; require_once plugin_dir_path( __FILE__ ) . 'migrations.php'; +require_once plugin_dir_path( __FILE__ ) . 'server/webfinger.php'; add_action( 'rest_api_init', function() { \api\register_routes(); @@ -21,4 +22,9 @@ add_action( 'pterotype_init', function() { add_action( 'pterotype_load', function() { \migrations\run_migrations(); } ); + +add_action( 'generate_rewrite_rules', '\webfinger\generate_rewrite_rules', 111 ); +add_action( 'parse_request', '\webfinger\parse_request', 111 ); +add_filter( 'query_vars', '\webfinger\query_vars' ); +add_action( 'well_known_webfinger', '\webfinger\handle' ); ?> diff --git a/includes/server/actors.php b/includes/server/actors.php index 17558f7..0daed00 100644 --- a/includes/server/actors.php +++ b/includes/server/actors.php @@ -68,6 +68,8 @@ function get_blog_actor() { null, sprintf( '/pterotype/v1/actor/%s/outbox', PTEROTYPE_BLOG_ACTOR_SLUG ) ), 'name' => get_bloginfo( 'name' ), + // TODO in the future, make this configurable, both here and in the Webfinger handler + 'preferredUsername' => 'blog', 'summary' => get_bloginfo( 'description' ), 'url' => network_site_url( '/' ), ); diff --git a/includes/server/webfinger.php b/includes/server/webfinger.php new file mode 100644 index 0000000..e411010 --- /dev/null +++ b/includes/server/webfinger.php @@ -0,0 +1,29 @@ + 'index.php?well-known=webfinger' + ); + $wp_rewrite->rules = $dot_well_known + $wp_rewrite->rules; +} + +function parse_request( $req ) { + if ( ! array_key_exists( 'well-known', $req->query_vars ) ) { + return; + } + if ( $req->query_vars['well-known'] === 'webfinger' ) { + do_action( 'well_known_webfinger', $req->query_vars ); + } +} + +function query_vars( $query_vars ) { + $query_vars[] = 'well-known'; + return $query_vars; +} + +function handle( $query ) { + echo var_dump( $query ); + exit; +} +?> diff --git a/pterotype.php b/pterotype.php index 86a8f08..1cb848a 100644 --- a/pterotype.php +++ b/pterotype.php @@ -8,9 +8,19 @@ define( 'PTEROTYPE_VERSION', '0.0.4' ); function pterotype_init() { do_action( 'pterotype_init' ); + flush_rewrite_rules(); } -do_action( 'pterotype_load' ); +function pterotype_deactive() { + do_action( 'pterotype_deactivate' ); + flush_rewrite_rules(); +} -register_activation_hook( __FILE__, 'pterotype_init'); +function pterotype_load() { + do_action( 'pterotype_load' ); +} + +add_action( 'plugins_loaded', 'pterotype_load' ); +register_activation_hook( __FILE__, 'pterotype_init' ); +register_deactivation_hook( __FILE__, 'pterotype_deactivate' ); ?>