wordpress-activitypub/activitypub.php
Matthias Pfefferle 4e653f5f75 0.1.0
* added basic WebFinger support
* added basic NodeInfo support
* fully functional "follow" activity
* send new posts to your followers
* receive comments from your followers
2018-12-20 11:33:08 +01:00

93 lines
4.4 KiB
PHP

<?php
/**
* Plugin Name: ActivityPub
* Plugin URI: https://github.com/pfefferle/wordpress-activitypub/
* Description: The ActivityPub protocol is a decentralized social networking protocol based upon the ActivityStreams 2.0 data format.
* Version: 0.1.0
* Author: Matthias Pfefferle
* Author URI: https://notiz.blog/
* License: MIT
* License URI: http://opensource.org/licenses/MIT
* Text Domain: activitypub
* Domain Path: /languages
*/
/**
* Initialize plugin
*/
function activitypub_init() {
require_once dirname( __FILE__ ) . '/includes/class-activitypub-signature.php';
require_once dirname( __FILE__ ) . '/includes/class-activitypub-post.php';
require_once dirname( __FILE__ ) . '/includes/class-activitypub-activity.php';
require_once dirname( __FILE__ ) . '/includes/class-db-activitypub-followers.php';
require_once dirname( __FILE__ ) . '/includes/functions.php';
require_once dirname( __FILE__ ) . '/includes/class-activitypub.php';
add_filter( 'template_include', array( 'Activitypub', 'render_json_template' ), 99 );
add_filter( 'query_vars', array( 'Activitypub', 'add_query_vars' ) );
add_action( 'init', array( 'Activitypub', 'add_rewrite_endpoint' ) );
// Configure the REST API route
require_once dirname( __FILE__ ) . '/includes/class-rest-activitypub-outbox.php';
add_action( 'rest_api_init', array( 'Rest_Activitypub_Outbox', 'register_routes' ) );
add_action( 'activitypub_send_post_activity', array( 'Rest_Activitypub_Outbox', 'send_post_activity' ) );
require_once dirname( __FILE__ ) . '/includes/class-rest-activitypub-inbox.php';
add_action( 'rest_api_init', array( 'Rest_Activitypub_Inbox', 'register_routes' ) );
//add_filter( 'rest_pre_serve_request', array( 'Rest_Activitypub_Inbox', 'serve_request' ), 11, 4 );
add_action( 'activitypub_inbox_follow', array( 'Rest_Activitypub_Inbox', 'handle_follow' ), 10, 2 );
add_action( 'activitypub_inbox_unfollow', array( 'Rest_Activitypub_Inbox', 'handle_unfollow' ), 10, 2 );
add_action( 'activitypub_inbox_like', array( 'Rest_Activitypub_Inbox', 'handle_reaction' ), 10, 2 );
add_action( 'activitypub_inbox_announce', array( 'Rest_Activitypub_Inbox', 'handle_reaction' ), 10, 2 );
add_action( 'activitypub_inbox_create', array( 'Rest_Activitypub_Inbox', 'handle_create' ), 10, 2 );
require_once dirname( __FILE__ ) . '/includes/class-rest-activitypub-followers.php';
add_action( 'rest_api_init', array( 'Rest_Activitypub_Followers', 'register_routes' ) );
require_once dirname( __FILE__ ) . '/includes/class-rest-activitypub-webfinger.php';
add_action( 'rest_api_init', array( 'Rest_Activitypub_Webfinger', 'register_routes' ) );
add_action( 'webfinger_user_data', array( 'Rest_Activitypub_Webfinger', 'add_webfinger_discovery' ), 10, 3 );
require_once dirname( __FILE__ ) . '/includes/class-rest-activitypub-nodeinfo.php';
add_action( 'rest_api_init', array( 'Rest_Activitypub_Nodeinfo', 'register_routes' ) );
add_filter( 'nodeinfo_data', array( 'Rest_Activitypub_Nodeinfo', 'add_nodeinfo_discovery' ), 10, 2 );
add_filter( 'nodeinfo2_data', array( 'Rest_Activitypub_Nodeinfo', 'add_nodeinfo2_discovery' ), 10 );
add_post_type_support( 'post', 'activitypub' );
add_post_type_support( 'page', 'activitypub' );
$post_types = get_post_types_by_support( 'activitypub' );
foreach ( $post_types as $post_type ) {
add_action( 'publish_' . $post_type, array( 'Activitypub', 'schedule_post_activity' ) );
}
require_once dirname( __FILE__ ) . '/includes/class-activitypub-admin.php';
add_action( 'admin_menu', array( 'Activitypub_Admin', 'admin_menu' ) );
add_action( 'admin_init', array( 'Activitypub_Admin', 'register_settings' ) );
}
add_action( 'plugins_loaded', 'activitypub_init' );
/**
* Add rewrite rules
*/
function activitypub_add_rewrite_rules() {
if ( ! class_exists( 'Webfinger' ) ) {
add_rewrite_rule( '^.well-known/webfinger', 'index.php?rest_route=/activitypub/1.0/webfinger', 'top' );
}
if ( ! class_exists( 'Nodeinfo' ) ) {
add_rewrite_rule( '^.well-known/nodeinfo', 'index.php?rest_route=/activitypub/1.0/nodeinfo/discovery', 'top' );
add_rewrite_rule( '^.well-known/x-nodeinfo2', 'index.php?rest_route=/activitypub/1.0/nodeinfo2', 'top' );
}
}
add_action( 'init', 'activitypub_add_rewrite_rules', 1 );
/**
* Flush rewrite rules;
*/
function activitypub_flush_rewrite_rules() {
activitypub_add_rewrite_rules();
flush_rewrite_rules();
}
register_activation_hook( __FILE__, 'activitypub_flush_rewrite_rules' );
register_deactivation_hook( __FILE__, 'flush_rewrite_rules' );