wordpress-activitypub/activitypub.php

148 lines
5.4 KiB
PHP
Raw Normal View History

2018-08-18 12:35:39 +02:00
<?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.
2022-12-15 15:57:55 +01:00
* Version: 0.14.3
2018-08-18 12:35:39 +02:00
* Author: Matthias Pfefferle
* Author URI: https://notiz.blog/
* License: MIT
* License URI: http://opensource.org/licenses/MIT
2019-02-24 13:01:28 +01:00
* Requires PHP: 5.6
2018-08-18 12:35:39 +02:00
* Text Domain: activitypub
* Domain Path: /languages
*/
namespace Activitypub;
2018-08-18 12:35:39 +02:00
/**
2019-02-24 13:01:28 +01:00
* Initialize plugin
2018-08-18 12:35:39 +02:00
*/
function init() {
\defined( 'ACTIVITYPUB_MAX_IMAGE_ATTACHMENTS' ) || \define( 'ACTIVITYPUB_MAX_IMAGE_ATTACHMENTS', 3 );
\defined( 'ACTIVITYPUB_HASHTAGS_REGEXP' ) || \define( 'ACTIVITYPUB_HASHTAGS_REGEXP', '(?:(?<=\s)|(?<=<p>)|(?<=<br>)|^)#([A-Za-z0-9_]+)(?:(?=\s|[[:punct:]]|$))' );
\defined( 'ACTIVITYPUB_ALLOWED_HTML' ) || \define( 'ACTIVITYPUB_ALLOWED_HTML', '<strong><a><p><ul><ol><li><code><blockquote><pre><img>' );
\defined( 'ACTIVITYPUB_CUSTOM_POST_CONTENT' ) || \define( 'ACTIVITYPUB_CUSTOM_POST_CONTENT', "<p><strong>%title%</strong></p>\n\n%content%\n\n<p>%hashtags%</p>\n\n<p>%shortlink%</p>" );
2022-12-02 18:23:56 +01:00
\define( 'ACTIVITYPUB_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
\define( 'ACTIVITYPUB_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
\define( 'ACTIVITYPUB_PLUGIN_FILE', plugin_dir_path( __FILE__ ) . '/' . basename( __FILE__ ) );
2019-01-22 20:51:22 +01:00
require_once \dirname( __FILE__ ) . '/includes/table/followers-list.php';
require_once \dirname( __FILE__ ) . '/includes/class-signature.php';
require_once \dirname( __FILE__ ) . '/includes/class-webfinger.php';
require_once \dirname( __FILE__ ) . '/includes/peer/class-followers.php';
require_once \dirname( __FILE__ ) . '/includes/functions.php';
2018-08-18 12:35:39 +02:00
require_once \dirname( __FILE__ ) . '/includes/model/class-activity.php';
require_once \dirname( __FILE__ ) . '/includes/model/class-post.php';
require_once \dirname( __FILE__ ) . '/includes/class-activity-dispatcher.php';
\Activitypub\Activity_Dispatcher::init();
2019-02-02 23:56:05 +01:00
require_once \dirname( __FILE__ ) . '/includes/class-activitypub.php';
2019-08-18 21:54:11 +02:00
\Activitypub\Activitypub::init();
2018-09-05 22:03:57 +02:00
// Configure the REST API route
require_once \dirname( __FILE__ ) . '/includes/rest/class-outbox.php';
\Activitypub\Rest\Outbox::init();
require_once \dirname( __FILE__ ) . '/includes/rest/class-inbox.php';
\Activitypub\Rest\Inbox::init();
require_once \dirname( __FILE__ ) . '/includes/rest/class-followers.php';
\Activitypub\Rest\Followers::init();
require_once \dirname( __FILE__ ) . '/includes/rest/class-following.php';
2019-03-12 22:20:04 +01:00
\Activitypub\Rest\Following::init();
require_once \dirname( __FILE__ ) . '/includes/rest/class-webfinger.php';
\Activitypub\Rest\Webfinger::init();
// load NodeInfo endpoints only if blog is public
2021-05-10 14:39:54 +02:00
if ( true === (bool) \get_option( 'blog_public', 1 ) ) {
require_once \dirname( __FILE__ ) . '/includes/rest/class-nodeinfo.php';
\Activitypub\Rest\NodeInfo::init();
}
require_once \dirname( __FILE__ ) . '/includes/class-admin.php';
\Activitypub\Admin::init();
2019-01-22 20:51:22 +01:00
require_once \dirname( __FILE__ ) . '/includes/class-hashtag.php';
2019-03-02 21:10:42 +01:00
\Activitypub\Hashtag::init();
require_once \dirname( __FILE__ ) . '/includes/class-debug.php';
2019-09-28 14:17:58 +02:00
\Activitypub\Debug::init();
require_once \dirname( __FILE__ ) . '/includes/class-health-check.php';
2019-09-30 07:59:19 +02:00
\Activitypub\Health_Check::init();
require_once \dirname( __FILE__ ) . '/includes/rest/class-server.php';
2022-01-27 13:09:11 +01:00
\add_filter(
'wp_rest_server_class',
function() {
return '\Activitypub\Rest\Server';
}
);
2021-07-23 15:46:28 +02:00
if ( \WP_DEBUG ) {
require_once \dirname( __FILE__ ) . '/includes/debug.php';
}
2018-08-18 12:35:39 +02:00
}
2020-05-12 20:30:06 +02:00
\add_action( 'plugins_loaded', '\Activitypub\init' );
2022-05-08 08:33:47 +02:00
/**
* Add plugin settings link
*/
function plugin_settings_link( $actions ) {
2022-05-09 15:21:59 +02:00
$settings_link[] = \sprintf(
2022-05-08 08:50:39 +02:00
'<a href="%1s">%2s</a>',
\menu_page_url( 'activitypub', false ),
2022-05-09 15:24:12 +02:00
\__( 'Settings', 'activitypub' )
2022-05-08 08:33:47 +02:00
);
2022-05-08 08:50:39 +02:00
2022-05-08 08:33:47 +02:00
return \array_merge( $settings_link, $actions );
}
2022-05-09 15:21:59 +02:00
\add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), '\Activitypub\plugin_settings_link' );
2022-05-08 08:33:47 +02:00
/**
* Add rewrite rules
*/
function add_rewrite_rules() {
2019-09-27 10:12:59 +02:00
if ( ! \class_exists( 'Webfinger' ) ) {
\add_rewrite_rule( '^.well-known/webfinger', 'index.php?rest_route=/activitypub/1.0/webfinger', 'top' );
}
2022-11-15 20:45:46 +01:00
if ( ! \class_exists( 'Nodeinfo' ) || ! (bool) \get_option( 'blog_public', 1 ) ) {
2019-09-27 10:12:59 +02:00
\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' );
}
}
2019-09-27 10:12:59 +02:00
\add_action( 'init', '\Activitypub\add_rewrite_rules', 1 );
/**
* Flush rewrite rules;
*/
function flush_rewrite_rules() {
\Activitypub\add_rewrite_rules();
2019-03-02 20:31:55 +01:00
\flush_rewrite_rules();
}
2019-09-27 10:12:59 +02:00
\register_activation_hook( __FILE__, '\Activitypub\flush_rewrite_rules' );
\register_deactivation_hook( __FILE__, '\flush_rewrite_rules' );
/**
* Only load code that needs BuddyPress to run once BP is loaded and initialized.
*/
function enable_buddypress_features() {
require_once \dirname( __FILE__ ) . '/integration/class-buddypress.php';
\Activitypub\Integration\Buddypress::init();
}
add_action( 'bp_include', '\Activitypub\enable_buddypress_features' );
2022-11-09 15:08:32 +01:00
add_action(
'friends_load_parsers',
function( \Friends\Feed $friends_feed ) {
require_once __DIR__ . '/integration/class-friends-feed-parser-activitypub.php';
$friends_feed->register_parser( Friends_Feed_Parser_ActivityPub::SLUG, new Friends_Feed_Parser_ActivityPub( $friends_feed ) );
}
);