2018-08-18 10:35:39 +00: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.
|
2023-02-20 20:19:52 +00:00
|
|
|
* Version: 0.16.4
|
2018-08-18 10:35:39 +00:00
|
|
|
* Author: Matthias Pfefferle
|
|
|
|
* Author URI: https://notiz.blog/
|
|
|
|
* License: MIT
|
|
|
|
* License URI: http://opensource.org/licenses/MIT
|
2019-02-24 12:01:28 +00:00
|
|
|
* Requires PHP: 5.6
|
2018-08-18 10:35:39 +00:00
|
|
|
* Text Domain: activitypub
|
|
|
|
* Domain Path: /languages
|
|
|
|
*/
|
|
|
|
|
2019-02-24 11:07:41 +00:00
|
|
|
namespace Activitypub;
|
|
|
|
|
2018-08-18 10:35:39 +00:00
|
|
|
/**
|
2019-02-24 12:01:28 +00:00
|
|
|
* Initialize plugin
|
2018-08-18 10:35:39 +00:00
|
|
|
*/
|
2019-02-24 11:07:41 +00:00
|
|
|
function init() {
|
2023-01-13 21:11:52 +00:00
|
|
|
\defined( 'ACTIVITYPUB_EXCERPT_LENGTH' ) || \define( 'ACTIVITYPUB_EXCERPT_LENGTH', 400 );
|
2023-01-12 20:29:21 +00:00
|
|
|
\defined( 'ACTIVITYPUB_MAX_IMAGE_ATTACHMENTS' ) || \define( 'ACTIVITYPUB_MAX_IMAGE_ATTACHMENTS', 3 );
|
2022-11-17 19:34:23 +00:00
|
|
|
\defined( 'ACTIVITYPUB_HASHTAGS_REGEXP' ) || \define( 'ACTIVITYPUB_HASHTAGS_REGEXP', '(?:(?<=\s)|(?<=<p>)|(?<=<br>)|^)#([A-Za-z0-9_]+)(?:(?=\s|[[:punct:]]|$))' );
|
2022-12-13 09:59:17 +00:00
|
|
|
\defined( 'ACTIVITYPUB_USERNAME_REGEXP' ) || \define( 'ACTIVITYPUB_USERNAME_REGEXP', '(?:([A-Za-z0-9_-]+)@((?:[A-Za-z0-9_-]+\.)+[A-Za-z]+))' );
|
2022-12-09 10:59:24 +00:00
|
|
|
\defined( 'ACTIVITYPUB_ALLOWED_HTML' ) || \define( 'ACTIVITYPUB_ALLOWED_HTML', '<strong><a><p><ul><ol><li><code><blockquote><pre><img>' );
|
2023-01-13 20:47:13 +00:00
|
|
|
\defined( 'ACTIVITYPUB_CUSTOM_POST_CONTENT' ) || \define( 'ACTIVITYPUB_CUSTOM_POST_CONTENT', "<p><strong>[ap_title]</strong></p>\n\n[ap_content]\n\n<p>[ap_hashtags]</p>\n\n<p>[ap_shortlink]</p>" );
|
2022-12-02 17:23:56 +00: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 19:51:22 +00:00
|
|
|
|
2019-12-01 20:20:26 +00:00
|
|
|
require_once \dirname( __FILE__ ) . '/includes/table/followers-list.php';
|
|
|
|
require_once \dirname( __FILE__ ) . '/includes/class-signature.php';
|
2022-11-15 17:22:08 +00:00
|
|
|
require_once \dirname( __FILE__ ) . '/includes/class-webfinger.php';
|
2019-12-01 20:20:26 +00:00
|
|
|
require_once \dirname( __FILE__ ) . '/includes/peer/class-followers.php';
|
|
|
|
require_once \dirname( __FILE__ ) . '/includes/functions.php';
|
2018-08-18 10:35:39 +00:00
|
|
|
|
2019-12-01 20:20:26 +00:00
|
|
|
require_once \dirname( __FILE__ ) . '/includes/model/class-activity.php';
|
|
|
|
require_once \dirname( __FILE__ ) . '/includes/model/class-post.php';
|
2020-07-21 07:23:35 +00:00
|
|
|
|
|
|
|
require_once \dirname( __FILE__ ) . '/includes/class-activity-dispatcher.php';
|
|
|
|
\Activitypub\Activity_Dispatcher::init();
|
2019-02-02 22:56:05 +00:00
|
|
|
|
2019-12-01 20:20:26 +00:00
|
|
|
require_once \dirname( __FILE__ ) . '/includes/class-activitypub.php';
|
2019-08-18 19:54:11 +00:00
|
|
|
\Activitypub\Activitypub::init();
|
2018-09-05 20:03:57 +00:00
|
|
|
|
|
|
|
// Configure the REST API route
|
2019-12-01 20:20:26 +00:00
|
|
|
require_once \dirname( __FILE__ ) . '/includes/rest/class-outbox.php';
|
2019-02-24 11:07:41 +00:00
|
|
|
\Activitypub\Rest\Outbox::init();
|
|
|
|
|
2019-12-01 20:20:26 +00:00
|
|
|
require_once \dirname( __FILE__ ) . '/includes/rest/class-inbox.php';
|
2019-02-24 11:07:41 +00:00
|
|
|
\Activitypub\Rest\Inbox::init();
|
|
|
|
|
2019-12-01 20:20:26 +00:00
|
|
|
require_once \dirname( __FILE__ ) . '/includes/rest/class-followers.php';
|
2019-02-24 11:07:41 +00:00
|
|
|
\Activitypub\Rest\Followers::init();
|
|
|
|
|
2019-12-01 20:20:26 +00:00
|
|
|
require_once \dirname( __FILE__ ) . '/includes/rest/class-following.php';
|
2019-03-12 21:20:04 +00:00
|
|
|
\Activitypub\Rest\Following::init();
|
|
|
|
|
2019-12-01 20:20:26 +00:00
|
|
|
require_once \dirname( __FILE__ ) . '/includes/rest/class-webfinger.php';
|
2019-02-24 11:07:41 +00:00
|
|
|
\Activitypub\Rest\Webfinger::init();
|
|
|
|
|
2020-05-23 10:34:42 +00:00
|
|
|
// load NodeInfo endpoints only if blog is public
|
2021-05-10 12:39:54 +00:00
|
|
|
if ( true === (bool) \get_option( 'blog_public', 1 ) ) {
|
2020-05-23 10:34:42 +00:00
|
|
|
require_once \dirname( __FILE__ ) . '/includes/rest/class-nodeinfo.php';
|
|
|
|
\Activitypub\Rest\NodeInfo::init();
|
|
|
|
}
|
2018-12-09 20:54:57 +00:00
|
|
|
|
2019-12-01 20:20:26 +00:00
|
|
|
require_once \dirname( __FILE__ ) . '/includes/class-admin.php';
|
2019-02-24 11:07:41 +00:00
|
|
|
\Activitypub\Admin::init();
|
2019-01-22 19:51:22 +00:00
|
|
|
|
2019-12-01 20:20:26 +00:00
|
|
|
require_once \dirname( __FILE__ ) . '/includes/class-hashtag.php';
|
2019-03-02 20:10:42 +00:00
|
|
|
\Activitypub\Hashtag::init();
|
2019-08-18 21:27:06 +00:00
|
|
|
|
2023-01-23 16:59:13 +00:00
|
|
|
require_once \dirname( __FILE__ ) . '/includes/class-shortcodes.php';
|
|
|
|
\Activitypub\Shortcodes::init();
|
2023-01-27 13:30:50 +00:00
|
|
|
|
2022-12-09 10:59:24 +00:00
|
|
|
require_once \dirname( __FILE__ ) . '/includes/class-mention.php';
|
|
|
|
\Activitypub\Mention::init();
|
2023-01-23 16:59:13 +00:00
|
|
|
|
2019-12-01 20:20:26 +00:00
|
|
|
require_once \dirname( __FILE__ ) . '/includes/class-debug.php';
|
2019-09-28 12:17:58 +00:00
|
|
|
\Activitypub\Debug::init();
|
|
|
|
|
2019-12-01 20:20:26 +00:00
|
|
|
require_once \dirname( __FILE__ ) . '/includes/class-health-check.php';
|
2019-09-30 05:59:19 +00:00
|
|
|
\Activitypub\Health_Check::init();
|
2020-02-21 10:11:03 +00:00
|
|
|
|
2021-07-23 13:46:28 +00:00
|
|
|
if ( \WP_DEBUG ) {
|
|
|
|
require_once \dirname( __FILE__ ) . '/includes/debug.php';
|
|
|
|
}
|
2018-08-18 10:35:39 +00:00
|
|
|
}
|
2020-05-12 18:30:06 +00:00
|
|
|
\add_action( 'plugins_loaded', '\Activitypub\init' );
|
2018-12-09 20:54:57 +00:00
|
|
|
|
2022-05-08 06:33:47 +00:00
|
|
|
/**
|
|
|
|
* Add plugin settings link
|
|
|
|
*/
|
|
|
|
function plugin_settings_link( $actions ) {
|
2022-05-09 13:21:59 +00:00
|
|
|
$settings_link[] = \sprintf(
|
2022-05-08 06:50:39 +00:00
|
|
|
'<a href="%1s">%2s</a>',
|
|
|
|
\menu_page_url( 'activitypub', false ),
|
2022-05-09 13:24:12 +00:00
|
|
|
\__( 'Settings', 'activitypub' )
|
2022-05-08 06:33:47 +00:00
|
|
|
);
|
2022-05-08 06:50:39 +00:00
|
|
|
|
2022-05-08 06:33:47 +00:00
|
|
|
return \array_merge( $settings_link, $actions );
|
|
|
|
}
|
2022-05-09 13:21:59 +00:00
|
|
|
\add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), '\Activitypub\plugin_settings_link' );
|
2022-05-08 06:33:47 +00:00
|
|
|
|
2018-12-09 20:54:57 +00:00
|
|
|
/**
|
|
|
|
* Add rewrite rules
|
|
|
|
*/
|
2019-02-24 11:07:41 +00:00
|
|
|
function add_rewrite_rules() {
|
2019-09-27 08:12:59 +00:00
|
|
|
if ( ! \class_exists( 'Webfinger' ) ) {
|
|
|
|
\add_rewrite_rule( '^.well-known/webfinger', 'index.php?rest_route=/activitypub/1.0/webfinger', 'top' );
|
2018-12-09 20:54:57 +00:00
|
|
|
}
|
|
|
|
|
2022-11-15 19:45:46 +00:00
|
|
|
if ( ! \class_exists( 'Nodeinfo' ) || ! (bool) \get_option( 'blog_public', 1 ) ) {
|
2019-09-27 08:12:59 +00: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' );
|
2018-12-09 20:54:57 +00:00
|
|
|
}
|
2023-01-16 18:19:26 +00:00
|
|
|
|
|
|
|
\add_rewrite_endpoint( 'activitypub', EP_AUTHORS | EP_PERMALINK | EP_PAGES );
|
2018-12-09 20:54:57 +00:00
|
|
|
}
|
2019-09-27 08:12:59 +00:00
|
|
|
\add_action( 'init', '\Activitypub\add_rewrite_rules', 1 );
|
2018-12-09 20:54:57 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Flush rewrite rules;
|
|
|
|
*/
|
2019-02-24 11:07:41 +00:00
|
|
|
function flush_rewrite_rules() {
|
|
|
|
\Activitypub\add_rewrite_rules();
|
2019-03-02 19:31:55 +00:00
|
|
|
\flush_rewrite_rules();
|
2018-12-09 20:54:57 +00:00
|
|
|
}
|
2019-09-27 08:12:59 +00:00
|
|
|
\register_activation_hook( __FILE__, '\Activitypub\flush_rewrite_rules' );
|
|
|
|
\register_deactivation_hook( __FILE__, '\flush_rewrite_rules' );
|
2021-09-15 15:00:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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' );
|