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.
|
2023-10-13 11:02:56 +02:00
|
|
|
* Version: 1.0.7
|
2023-03-11 10:58:05 +01:00
|
|
|
* Author: Matthias Pfefferle & Automattic
|
|
|
|
* Author URI: https://automattic.com/
|
2018-08-18 12:35:39 +02:00
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2019-02-24 12:07:41 +01:00
|
|
|
namespace Activitypub;
|
|
|
|
|
2023-10-18 11:26:42 +02:00
|
|
|
use WP_CLI;
|
|
|
|
|
2023-10-12 15:52:11 +02:00
|
|
|
use function Activitypub\is_blog_public;
|
2023-09-15 10:38:47 +02:00
|
|
|
use function Activitypub\site_supports_blocks;
|
|
|
|
|
2023-10-10 08:12:15 +02:00
|
|
|
require_once __DIR__ . '/includes/compat.php';
|
2023-10-04 18:15:53 +02:00
|
|
|
require_once __DIR__ . '/includes/functions.php';
|
2023-05-19 02:30:08 +02:00
|
|
|
|
2018-08-18 12:35:39 +02:00
|
|
|
/**
|
2023-10-04 18:15:53 +02:00
|
|
|
* Initialize the plugin constants.
|
2018-08-18 12:35:39 +02:00
|
|
|
*/
|
2023-10-10 20:45:32 +02:00
|
|
|
\defined( 'ACTIVITYPUB_REST_NAMESPACE' ) || \define( 'ACTIVITYPUB_REST_NAMESPACE', 'activitypub/1.0' );
|
|
|
|
\defined( 'ACTIVITYPUB_EXCERPT_LENGTH' ) || \define( 'ACTIVITYPUB_EXCERPT_LENGTH', 400 );
|
|
|
|
\defined( 'ACTIVITYPUB_SHOW_PLUGIN_RECOMMENDATIONS' ) || \define( 'ACTIVITYPUB_SHOW_PLUGIN_RECOMMENDATIONS', true );
|
|
|
|
\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_USERNAME_REGEXP' ) || \define( 'ACTIVITYPUB_USERNAME_REGEXP', '(?:([A-Za-z0-9_-]+)@((?:[A-Za-z0-9_-]+\.)+[A-Za-z]+))' );
|
|
|
|
\defined( 'ACTIVITYPUB_CUSTOM_POST_CONTENT' ) || \define( 'ACTIVITYPUB_CUSTOM_POST_CONTENT', "<strong>[ap_title]</strong>\n\n[ap_content]\n\n[ap_hashtags]\n\n[ap_shortlink]" );
|
|
|
|
\defined( 'ACTIVITYPUB_AUTHORIZED_FETCH' ) || \define( 'ACTIVITYPUB_AUTHORIZED_FETCH', false );
|
|
|
|
\defined( 'ACTIVITYPUB_DISABLE_REWRITES' ) || \define( 'ACTIVITYPUB_DISABLE_REWRITES', false );
|
2023-06-28 14:22:27 +02:00
|
|
|
|
2023-10-10 20:45:32 +02: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__ ) );
|
|
|
|
\define( 'ACTIVITYPUB_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
|
2019-01-22 20:51:22 +01:00
|
|
|
|
2023-10-04 18:15:53 +02:00
|
|
|
/**
|
|
|
|
* Initialize REST routes.
|
|
|
|
*/
|
|
|
|
function rest_init() {
|
2023-05-24 17:27:46 +02:00
|
|
|
Rest\Users::init();
|
2023-04-20 15:22:11 +02:00
|
|
|
Rest\Outbox::init();
|
|
|
|
Rest\Inbox::init();
|
|
|
|
Rest\Followers::init();
|
|
|
|
Rest\Following::init();
|
|
|
|
Rest\Webfinger::init();
|
2023-05-18 07:49:33 +02:00
|
|
|
Rest\Server::init();
|
2023-08-09 13:07:30 +02:00
|
|
|
Rest\Collection::init();
|
2019-02-24 12:07:41 +01:00
|
|
|
|
2023-10-04 18:15:53 +02:00
|
|
|
// load NodeInfo endpoints only if blog is public
|
2023-10-12 15:52:11 +02:00
|
|
|
if ( is_blog_public() ) {
|
2023-10-04 18:15:53 +02:00
|
|
|
Rest\NodeInfo::init();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
\add_action( 'rest_api_init', __NAMESPACE__ . '\rest_init' );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize plugin.
|
|
|
|
*/
|
|
|
|
function plugin_init() {
|
|
|
|
\add_action( 'init', array( __NAMESPACE__ . '\Migration', 'init' ) );
|
|
|
|
\add_action( 'init', array( __NAMESPACE__ . '\Activitypub', 'init' ) );
|
|
|
|
\add_action( 'init', array( __NAMESPACE__ . '\Activity_Dispatcher', 'init' ) );
|
|
|
|
\add_action( 'init', array( __NAMESPACE__ . '\Collection\Followers', 'init' ) );
|
|
|
|
\add_action( 'init', array( __NAMESPACE__ . '\Admin', 'init' ) );
|
|
|
|
\add_action( 'init', array( __NAMESPACE__ . '\Hashtag', 'init' ) );
|
|
|
|
\add_action( 'init', array( __NAMESPACE__ . '\Mention', 'init' ) );
|
|
|
|
\add_action( 'init', array( __NAMESPACE__ . '\Health_Check', 'init' ) );
|
|
|
|
\add_action( 'init', array( __NAMESPACE__ . '\Scheduler', 'init' ) );
|
2023-09-15 10:38:47 +02:00
|
|
|
|
|
|
|
if ( site_supports_blocks() ) {
|
2023-10-04 18:15:53 +02:00
|
|
|
\add_action( 'init', array( __NAMESPACE__ . '\Blocks', 'init' ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
$debug_file = __DIR__ . '/includes/debug.php';
|
|
|
|
if ( \WP_DEBUG && file_exists( $debug_file ) && is_readable( $debug_file ) ) {
|
|
|
|
require_once $debug_file;
|
|
|
|
Debug::init();
|
2023-09-15 10:38:47 +02:00
|
|
|
}
|
2023-10-11 11:09:37 +02:00
|
|
|
|
|
|
|
require_once __DIR__ . '/integration/class-webfinger.php';
|
|
|
|
Integration\Webfinger::init();
|
|
|
|
|
|
|
|
require_once __DIR__ . '/integration/class-nodeinfo.php';
|
|
|
|
Integration\Nodeinfo::init();
|
2023-05-04 15:17:05 +02:00
|
|
|
}
|
2023-10-04 18:15:53 +02:00
|
|
|
\add_action( 'plugins_loaded', __NAMESPACE__ . '\plugin_init' );
|
2020-02-21 11:11:03 +01:00
|
|
|
|
2023-05-05 09:57:47 +02:00
|
|
|
/**
|
|
|
|
* Class Autoloader
|
|
|
|
*/
|
2023-10-04 18:15:53 +02:00
|
|
|
\spl_autoload_register(
|
2023-05-11 14:55:11 +02:00
|
|
|
function ( $full_class ) {
|
2023-07-20 03:39:58 +02:00
|
|
|
$base_dir = __DIR__ . '/includes/';
|
2023-07-27 00:46:36 +02:00
|
|
|
$base = 'Activitypub\\';
|
2023-05-04 15:17:05 +02:00
|
|
|
|
2023-07-27 00:46:36 +02:00
|
|
|
if ( strncmp( $full_class, $base, strlen( $base ) ) === 0 ) {
|
2023-07-27 19:35:28 +02:00
|
|
|
$maybe_uppercase = str_replace( $base, '', $full_class );
|
|
|
|
$class = strtolower( $maybe_uppercase );
|
|
|
|
// All classes should be capitalized. If this is instead looking for a lowercase method, we ignore that.
|
|
|
|
if ( $maybe_uppercase === $class ) {
|
|
|
|
return;
|
|
|
|
}
|
2020-02-21 11:11:03 +01:00
|
|
|
|
2023-05-10 18:45:48 +02:00
|
|
|
if ( false !== strpos( $class, '\\' ) ) {
|
2023-05-11 14:38:57 +02:00
|
|
|
$parts = explode( '\\', $class );
|
|
|
|
$class = array_pop( $parts );
|
|
|
|
$sub_dir = implode( '/', $parts );
|
2023-05-11 09:09:13 +02:00
|
|
|
$base_dir = $base_dir . $sub_dir . '/';
|
2023-05-04 15:17:05 +02:00
|
|
|
}
|
|
|
|
|
2023-05-10 18:50:20 +02:00
|
|
|
$filename = 'class-' . strtr( $class, '_', '-' );
|
2023-05-04 15:17:05 +02:00
|
|
|
$file = $base_dir . $filename . '.php';
|
|
|
|
|
2023-05-10 18:53:09 +02:00
|
|
|
if ( file_exists( $file ) && is_readable( $file ) ) {
|
2023-05-04 15:17:05 +02:00
|
|
|
require_once $file;
|
2023-05-11 14:55:11 +02:00
|
|
|
} else {
|
|
|
|
// translators: %s is the class name
|
|
|
|
\wp_die( sprintf( esc_html__( 'Required class not found or not readable: %s', 'activitypub' ), esc_html( $full_class ) ) );
|
2023-05-04 15:17:05 +02:00
|
|
|
}
|
|
|
|
}
|
2021-07-23 15:46:28 +02:00
|
|
|
}
|
2023-05-04 15:17:05 +02:00
|
|
|
);
|
|
|
|
|
2022-05-08 08:33:47 +02:00
|
|
|
/**
|
|
|
|
* Add plugin settings link
|
|
|
|
*/
|
|
|
|
function plugin_settings_link( $actions ) {
|
2023-07-18 22:02:27 +02:00
|
|
|
$settings_link = array();
|
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 );
|
|
|
|
}
|
2023-05-04 15:17:05 +02:00
|
|
|
\add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), __NAMESPACE__ . '\plugin_settings_link' );
|
|
|
|
|
|
|
|
\register_activation_hook(
|
|
|
|
__FILE__,
|
|
|
|
array(
|
|
|
|
__NAMESPACE__ . '\Activitypub',
|
|
|
|
'activate',
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
\register_deactivation_hook(
|
|
|
|
__FILE__,
|
|
|
|
array(
|
|
|
|
__NAMESPACE__ . '\Activitypub',
|
|
|
|
'deactivate',
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2023-05-17 10:25:31 +02:00
|
|
|
\register_uninstall_hook(
|
2023-05-04 15:17:05 +02:00
|
|
|
__FILE__,
|
|
|
|
array(
|
|
|
|
__NAMESPACE__ . '\Activitypub',
|
|
|
|
'uninstall',
|
|
|
|
)
|
|
|
|
);
|
2022-05-08 08:33:47 +02:00
|
|
|
|
2021-09-15 17:00:20 +02:00
|
|
|
/**
|
|
|
|
* Only load code that needs BuddyPress to run once BP is loaded and initialized.
|
|
|
|
*/
|
2023-05-22 10:58:13 +02:00
|
|
|
add_action(
|
|
|
|
'bp_include',
|
|
|
|
function() {
|
2023-07-20 03:39:58 +02:00
|
|
|
require_once __DIR__ . '/integration/class-buddypress.php';
|
2023-05-22 10:58:13 +02:00
|
|
|
Integration\Buddypress::init();
|
|
|
|
},
|
|
|
|
0
|
|
|
|
);
|
|
|
|
|
2023-05-02 09:27:35 +02:00
|
|
|
/**
|
|
|
|
* `get_plugin_data` wrapper
|
|
|
|
*
|
|
|
|
* @return array The plugin metadata array
|
|
|
|
*/
|
|
|
|
function get_plugin_meta( $default_headers = array() ) {
|
|
|
|
if ( ! $default_headers ) {
|
|
|
|
$default_headers = array(
|
|
|
|
'Name' => 'Plugin Name',
|
|
|
|
'PluginURI' => 'Plugin URI',
|
|
|
|
'Version' => 'Version',
|
|
|
|
'Description' => 'Description',
|
|
|
|
'Author' => 'Author',
|
|
|
|
'AuthorURI' => 'Author URI',
|
|
|
|
'TextDomain' => 'Text Domain',
|
|
|
|
'DomainPath' => 'Domain Path',
|
|
|
|
'Network' => 'Network',
|
|
|
|
'RequiresWP' => 'Requires at least',
|
|
|
|
'RequiresPHP' => 'Requires PHP',
|
|
|
|
'UpdateURI' => 'Update URI',
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return \get_file_data( __FILE__, $default_headers, 'plugin' );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Plugin Version Number used for caching.
|
|
|
|
*/
|
|
|
|
function get_plugin_version() {
|
|
|
|
$meta = get_plugin_meta( array( 'Version' => 'Version' ) );
|
|
|
|
|
|
|
|
return $meta['Version'];
|
|
|
|
}
|
2023-10-18 11:26:42 +02:00
|
|
|
|
|
|
|
// Check for CLI env, to add the CLI commands
|
|
|
|
if ( defined( 'WP_CLI' ) && WP_CLI ) {
|
|
|
|
require_once __DIR__ . '/includes/class-cli.php';
|
|
|
|
WP_CLI::add_command( 'activitypub', __NAMESPACE__ . '\Cli' );
|
|
|
|
}
|