wordpress-activitypub/activitypub.php

182 lines
5.1 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.
2023-03-03 09:06:43 +01:00
* Version: 0.17.0
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
*/
namespace Activitypub;
\defined( 'ACTIVITYPUB_REST_NAMESPACE' ) || \define( 'ACTIVITYPUB_REST_NAMESPACE', 'activitypub/1.0' );
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() {
2023-01-13 22:11:52 +01:00
\defined( 'ACTIVITYPUB_EXCERPT_LENGTH' ) || \define( 'ACTIVITYPUB_EXCERPT_LENGTH', 400 );
2023-05-05 13:58:17 +02:00
\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]+))' );
2023-05-09 13:02:30 +02:00
\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]" );
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
Migration::init();
2023-04-20 15:22:11 +02:00
Activitypub::init();
2023-05-17 09:02:09 +02:00
Activity_Dispatcher::init();
Collection\Followers::init();
2018-09-05 22:03:57 +02:00
// Configure the REST API route
2023-04-20 15:22:11 +02:00
Rest\Outbox::init();
Rest\Inbox::init();
Rest\Followers::init();
Rest\Following::init();
Rest\Webfinger::init();
2023-04-20 15:22:11 +02:00
Admin::init();
Hashtag::init();
Shortcodes::init();
Mention::init();
Health_Check::init();
Scheduler::init();
2023-05-04 15:17:05 +02:00
}
2023-05-19 22:37:05 +02:00
\add_action( 'plugins_loaded', __NAMESPACE__ . '\init' );
2023-05-05 09:57:47 +02:00
/**
* Class Autoloader
*/
2023-05-04 15:17:05 +02:00
spl_autoload_register(
function ( $full_class ) {
$base_dir = \dirname( __FILE__ ) . '/includes/';
2023-05-04 15:17:05 +02:00
$base = 'activitypub';
$class = strtolower( $full_class );
2023-05-04 15:17:05 +02:00
if ( strncmp( $class, $base, strlen( $base ) ) === 0 ) {
$class = str_replace( 'activitypub\\', '', $class );
if ( false !== strpos( $class, '\\' ) ) {
$parts = explode( '\\', $class );
$class = array_pop( $parts );
$sub_dir = implode( '/', $parts );
$base_dir = $base_dir . $sub_dir . '/';
2023-05-04 15:17:05 +02:00
}
$filename = 'class-' . strtr( $class, '_', '-' );
2023-05-04 15:17:05 +02:00
$file = $base_dir . $filename . '.php';
if ( file_exists( $file ) && is_readable( $file ) ) {
2023-05-04 15:17:05 +02:00
require_once $file;
} 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
);
require_once \dirname( __FILE__ ) . '/includes/functions.php';
// load NodeInfo endpoints only if blog is public
if ( \get_option( 'blog_public', 1 ) ) {
2023-05-04 15:17:05 +02:00
Rest\NodeInfo::init();
}
2023-05-11 14:40:47 +02:00
$debug_file = \dirname( __FILE__ ) . '/includes/debug.php';
if ( \WP_DEBUG && file_exists( $debug_file ) && is_readable( $debug_file ) ) {
require_once $debug_file;
2023-05-17 09:02:09 +02:00
Debug::init();
2018-08-18 12:35:39 +02:00
}
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 );
}
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',
)
);
/**
* 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';
2023-04-20 15:22:11 +02:00
Integration\Buddypress::init();
}
2023-05-19 22:37:05 +02:00
add_action( 'bp_include', __NAMESPACE__ . '\enable_buddypress_features' );
/**
* `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'];
}