| 1 |
<?php |
| 2 |
/** |
| 3 |
* Plugin Name: ActivityPub |
| 4 |
* Plugin URI: https://github.com/pfefferle/wordpress-activitypub/ |
| 5 |
* Description: The ActivityPub protocol is a decentralized social networking protocol based upon the ActivityStreams 2.0 data format. |
| 6 |
* Version: 0.4.2 |
| 7 |
* Author: Matthias Pfefferle |
| 8 |
* Author URI: https://notiz.blog/ |
| 9 |
* License: MIT |
| 10 |
* License URI: http://opensource.org/licenses/MIT |
| 11 |
* Text Domain: activitypub |
| 12 |
* Domain Path: /languages |
| 13 |
*/ |
| 14 |
|
| 15 |
/** |
| 16 |
* Initialize plugin |
| 17 |
*/ |
| 18 |
function activitypub_init() { |
| 19 |
defined( 'ACTIVITYPUB_HASHTAGS_REGEXP' ) || define( 'ACTIVITYPUB_HASHTAGS_REGEXP', '(^|\s|>)#([^\s<>]+)\b' ); |
| 20 |
|
| 21 |
require_once dirname( __FILE__ ) . '/includes/class-activitypub-signature.php'; |
| 22 |
require_once dirname( __FILE__ ) . '/includes/class-activitypub-activity.php'; |
| 23 |
require_once dirname( __FILE__ ) . '/includes/class-db-activitypub-followers.php'; |
| 24 |
require_once dirname( __FILE__ ) . '/includes/functions.php'; |
| 25 |
|
| 26 |
require_once dirname( __FILE__ ) . '/includes/class-activitypub-post.php'; |
| 27 |
add_filter( 'activitypub_the_summary', array( 'Activitypub_Post', 'add_backlink' ), 10, 2 ); |
| 28 |
add_filter( 'activitypub_the_content', array( 'Activitypub_Post', 'add_backlink' ), 10, 2 ); |
| 29 |
|
| 30 |
require_once dirname( __FILE__ ) . '/includes/class-activitypub.php'; |
| 31 |
add_filter( 'template_include', array( 'Activitypub', 'render_json_template' ), 99 ); |
| 32 |
add_filter( 'query_vars', array( 'Activitypub', 'add_query_vars' ) ); |
| 33 |
add_action( 'init', array( 'Activitypub', 'add_rewrite_endpoint' ) ); |
| 34 |
|
| 35 |
// Configure the REST API route |
| 36 |
require_once dirname( __FILE__ ) . '/includes/class-rest-activitypub-outbox.php'; |
| 37 |
add_action( 'rest_api_init', array( 'Rest_Activitypub_Outbox', 'register_routes' ) ); |
| 38 |
add_action( 'activitypub_send_post_activity', array( 'Rest_Activitypub_Outbox', 'send_post_activity' ) ); |
| 39 |
add_action( 'activitypub_send_update_activity', array( 'Rest_Activitypub_Outbox', 'send_update_activity' ) ); |
| 40 |
|
| 41 |
require_once dirname( __FILE__ ) . '/includes/class-rest-activitypub-inbox.php'; |
| 42 |
add_action( 'rest_api_init', array( 'Rest_Activitypub_Inbox', 'register_routes' ) ); |
| 43 |
//add_filter( 'rest_pre_serve_request', array( 'Rest_Activitypub_Inbox', 'serve_request' ), 11, 4 ); |
| 44 |
add_action( 'activitypub_inbox_follow', array( 'Rest_Activitypub_Inbox', 'handle_follow' ), 10, 2 ); |
| 45 |
add_action( 'activitypub_inbox_unfollow', array( 'Rest_Activitypub_Inbox', 'handle_unfollow' ), 10, 2 ); |
| 46 |
//add_action( 'activitypub_inbox_like', array( 'Rest_Activitypub_Inbox', 'handle_reaction' ), 10, 2 ); |
| 47 |
//add_action( 'activitypub_inbox_announce', array( 'Rest_Activitypub_Inbox', 'handle_reaction' ), 10, 2 ); |
| 48 |
add_action( 'activitypub_inbox_create', array( 'Rest_Activitypub_Inbox', 'handle_create' ), 10, 2 ); |
| 49 |
|
| 50 |
require_once dirname( __FILE__ ) . '/includes/class-rest-activitypub-followers.php'; |
| 51 |
add_action( 'rest_api_init', array( 'Rest_Activitypub_Followers', 'register_routes' ) ); |
| 52 |
|
| 53 |
require_once dirname( __FILE__ ) . '/includes/class-rest-activitypub-webfinger.php'; |
| 54 |
add_action( 'rest_api_init', array( 'Rest_Activitypub_Webfinger', 'register_routes' ) ); |
| 55 |
add_action( 'webfinger_user_data', array( 'Rest_Activitypub_Webfinger', 'add_webfinger_discovery' ), 10, 3 ); |
| 56 |
|
| 57 |
require_once dirname( __FILE__ ) . '/includes/class-rest-activitypub-nodeinfo.php'; |
| 58 |
add_action( 'rest_api_init', array( 'Rest_Activitypub_Nodeinfo', 'register_routes' ) ); |
| 59 |
add_filter( 'nodeinfo_data', array( 'Rest_Activitypub_Nodeinfo', 'add_nodeinfo_discovery' ), 10, 2 ); |
| 60 |
add_filter( 'nodeinfo2_data', array( 'Rest_Activitypub_Nodeinfo', 'add_nodeinfo2_discovery' ), 10 ); |
| 61 |
|
| 62 |
add_post_type_support( 'post', 'activitypub' ); |
| 63 |
add_post_type_support( 'page', 'activitypub' ); |
| 64 |
|
| 65 |
$post_types = get_post_types_by_support( 'activitypub' ); |
| 66 |
add_action( 'transition_post_status', array( 'Activitypub', 'schedule_post_activity' ), 10, 3 ); |
| 67 |
|
| 68 |
require_once dirname( __FILE__ ) . '/includes/class-activitypub-admin.php'; |
| 69 |
add_action( 'admin_menu', array( 'Activitypub_Admin', 'admin_menu' ) ); |
| 70 |
add_action( 'admin_init', array( 'Activitypub_Admin', 'register_settings' ) ); |
| 71 |
add_action( 'show_user_profile', array( 'Activitypub_Admin', 'add_fediverse_profile' ) ); |
| 72 |
|
| 73 |
if ( '1' === get_option( 'activitypub_use_hashtags', '1' ) ) { |
| 74 |
require_once dirname( __FILE__ ) . '/includes/class-activitypub-hashtag.php'; |
| 75 |
add_filter( 'wp_insert_post', array( 'Activitypub_Hashtag', 'insert_post' ), 99, 2 ); |
| 76 |
add_filter( 'the_content', array( 'Activitypub_Hashtag', 'the_content' ), 99, 2 ); |
| 77 |
} |
| 78 |
} |
| 79 |
add_action( 'plugins_loaded', 'activitypub_init' ); |
| 80 |
|
| 81 |
/** |
| 82 |
* Add rewrite rules |
| 83 |
*/ |
| 84 |
function activitypub_add_rewrite_rules() { |
| 85 |
if ( ! class_exists( 'Webfinger' ) ) { |
| 86 |
add_rewrite_rule( '^.well-known/webfinger', 'index.php?rest_route=/activitypub/1.0/webfinger', 'top' ); |
| 87 |
} |
| 88 |
|
| 89 |
if ( ! class_exists( 'Nodeinfo' ) ) { |
| 90 |
add_rewrite_rule( '^.well-known/nodeinfo', 'index.php?rest_route=/activitypub/1.0/nodeinfo/discovery', 'top' ); |
| 91 |
add_rewrite_rule( '^.well-known/x-nodeinfo2', 'index.php?rest_route=/activitypub/1.0/nodeinfo2', 'top' ); |
| 92 |
} |
| 93 |
} |
| 94 |
add_action( 'init', 'activitypub_add_rewrite_rules', 1 ); |
| 95 |
|
| 96 |
/** |
| 97 |
* Flush rewrite rules; |
| 98 |
*/ |
| 99 |
function activitypub_flush_rewrite_rules() { |
| 100 |
activitypub_add_rewrite_rules(); |
| 101 |
flush_rewrite_rules(); |
| 102 |
} |
| 103 |
register_activation_hook( __FILE__, 'activitypub_flush_rewrite_rules' ); |
| 104 |
register_deactivation_hook( __FILE__, 'flush_rewrite_rules' ); |
| 105 |
|