Merge branch 'master' into Comments
This commit is contained in:
commit
63a8502205
13 changed files with 72 additions and 76 deletions
|
@ -17,12 +17,13 @@ namespace Activitypub;
|
||||||
|
|
||||||
use function Activitypub\site_supports_blocks;
|
use function Activitypub\site_supports_blocks;
|
||||||
|
|
||||||
\defined( 'ACTIVITYPUB_REST_NAMESPACE' ) || \define( 'ACTIVITYPUB_REST_NAMESPACE', 'activitypub/1.0' );
|
require_once __DIR__ . '/includes/functions.php';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize plugin
|
* Initialize the plugin constants.
|
||||||
*/
|
*/
|
||||||
function init() {
|
function define_constants() {
|
||||||
|
\defined( 'ACTIVITYPUB_REST_NAMESPACE' ) || \define( 'ACTIVITYPUB_REST_NAMESPACE', 'activitypub/1.0' );
|
||||||
\defined( 'ACTIVITYPUB_EXCERPT_LENGTH' ) || \define( 'ACTIVITYPUB_EXCERPT_LENGTH', 400 );
|
\defined( 'ACTIVITYPUB_EXCERPT_LENGTH' ) || \define( 'ACTIVITYPUB_EXCERPT_LENGTH', 400 );
|
||||||
\defined( 'ACTIVITYPUB_SHOW_PLUGIN_RECOMMENDATIONS' ) || \define( 'ACTIVITYPUB_SHOW_PLUGIN_RECOMMENDATIONS', true );
|
\defined( 'ACTIVITYPUB_SHOW_PLUGIN_RECOMMENDATIONS' ) || \define( 'ACTIVITYPUB_SHOW_PLUGIN_RECOMMENDATIONS', true );
|
||||||
\defined( 'ACTIVITYPUB_MAX_IMAGE_ATTACHMENTS' ) || \define( 'ACTIVITYPUB_MAX_IMAGE_ATTACHMENTS', 3 );
|
\defined( 'ACTIVITYPUB_MAX_IMAGE_ATTACHMENTS' ) || \define( 'ACTIVITYPUB_MAX_IMAGE_ATTACHMENTS', 3 );
|
||||||
|
@ -30,19 +31,18 @@ function init() {
|
||||||
\defined( 'ACTIVITYPUB_USERNAME_REGEXP' ) || \define( 'ACTIVITYPUB_USERNAME_REGEXP', '(?:([A-Za-z0-9_-]+)@((?:[A-Za-z0-9_-]+\.)+[A-Za-z]+))' );
|
\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_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_AUTHORIZED_FETCH' ) || \define( 'ACTIVITYPUB_AUTHORIZED_FETCH', false );
|
||||||
|
\defined( 'ACTIVITYPUB_DISABLE_REWRITES' ) || \define( 'ACTIVITYPUB_DISABLE_REWRITES', false );
|
||||||
|
|
||||||
\define( 'ACTIVITYPUB_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
|
\define( 'ACTIVITYPUB_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
|
||||||
\define( 'ACTIVITYPUB_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
|
\define( 'ACTIVITYPUB_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
|
||||||
\define( 'ACTIVITYPUB_PLUGIN_FILE', plugin_dir_path( __FILE__ ) . '/' . basename( __FILE__ ) );
|
\define( 'ACTIVITYPUB_PLUGIN_FILE', plugin_dir_path( __FILE__ ) . '/' . basename( __FILE__ ) );
|
||||||
\define( 'ACTIVITYPUB_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
|
\define( 'ACTIVITYPUB_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
|
||||||
|
}
|
||||||
|
|
||||||
Migration::init();
|
/**
|
||||||
Activitypub::init();
|
* Initialize REST routes.
|
||||||
Activity_Dispatcher::init();
|
*/
|
||||||
Collection\Followers::init();
|
function rest_init() {
|
||||||
Comments::init();
|
|
||||||
|
|
||||||
// Configure the REST API route
|
|
||||||
Rest\Users::init();
|
Rest\Users::init();
|
||||||
Rest\Outbox::init();
|
Rest\Outbox::init();
|
||||||
Rest\Inbox::init();
|
Rest\Inbox::init();
|
||||||
|
@ -52,23 +52,46 @@ function init() {
|
||||||
Rest\Server::init();
|
Rest\Server::init();
|
||||||
Rest\Collection::init();
|
Rest\Collection::init();
|
||||||
|
|
||||||
Admin::init();
|
// load NodeInfo endpoints only if blog is public
|
||||||
Hashtag::init();
|
if ( \get_option( 'blog_public', 1 ) ) {
|
||||||
Shortcodes::init();
|
Rest\NodeInfo::init();
|
||||||
Mention::init();
|
|
||||||
Health_Check::init();
|
|
||||||
Scheduler::init();
|
|
||||||
|
|
||||||
if ( site_supports_blocks() ) {
|
|
||||||
Blocks::init();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
\add_action( 'init', __NAMESPACE__ . '\init' );
|
\add_action( 'rest_api_init', __NAMESPACE__ . '\rest_init' );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize plugin.
|
||||||
|
*/
|
||||||
|
function plugin_init() {
|
||||||
|
define_constants();
|
||||||
|
|
||||||
|
\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__ . '\Shortcodes', 'init' ) );
|
||||||
|
\add_action( 'init', array( __NAMESPACE__ . '\Mention', 'init' ) );
|
||||||
|
\add_action( 'init', array( __NAMESPACE__ . '\Health_Check', 'init' ) );
|
||||||
|
\add_action( 'init', array( __NAMESPACE__ . '\Scheduler', 'init' ) );
|
||||||
|
|
||||||
|
if ( site_supports_blocks() ) {
|
||||||
|
\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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
\add_action( 'plugins_loaded', __NAMESPACE__ . '\plugin_init' );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Autoloader
|
* Class Autoloader
|
||||||
*/
|
*/
|
||||||
spl_autoload_register(
|
\spl_autoload_register(
|
||||||
function ( $full_class ) {
|
function ( $full_class ) {
|
||||||
$base_dir = __DIR__ . '/includes/';
|
$base_dir = __DIR__ . '/includes/';
|
||||||
$base = 'Activitypub\\';
|
$base = 'Activitypub\\';
|
||||||
|
@ -101,19 +124,6 @@ spl_autoload_register(
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
require_once __DIR__ . '/includes/functions.php';
|
|
||||||
|
|
||||||
// load NodeInfo endpoints only if blog is public
|
|
||||||
if ( \get_option( 'blog_public', 1 ) ) {
|
|
||||||
Rest\NodeInfo::init();
|
|
||||||
}
|
|
||||||
|
|
||||||
$debug_file = __DIR__ . '/includes/debug.php';
|
|
||||||
if ( \WP_DEBUG && file_exists( $debug_file ) && is_readable( $debug_file ) ) {
|
|
||||||
require_once $debug_file;
|
|
||||||
Debug::init();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add plugin settings link
|
* Add plugin settings link
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -236,6 +236,12 @@ class Activitypub {
|
||||||
* Add rewrite rules
|
* Add rewrite rules
|
||||||
*/
|
*/
|
||||||
public static function add_rewrite_rules() {
|
public static function add_rewrite_rules() {
|
||||||
|
// If another system needs to take precedence over the ActivityPub rewrite rules,
|
||||||
|
// they can define their own and will manually call the appropriate functions as required.
|
||||||
|
if ( ACTIVITYPUB_DISABLE_REWRITES ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if ( ! \class_exists( 'Webfinger' ) ) {
|
if ( ! \class_exists( 'Webfinger' ) ) {
|
||||||
\add_rewrite_rule(
|
\add_rewrite_rule(
|
||||||
'^.well-known/webfinger',
|
'^.well-known/webfinger',
|
||||||
|
|
|
@ -25,7 +25,7 @@ class Collection {
|
||||||
* Initialize the class, registering WordPress hooks
|
* Initialize the class, registering WordPress hooks
|
||||||
*/
|
*/
|
||||||
public static function init() {
|
public static function init() {
|
||||||
\add_action( 'rest_api_init', array( self::class, 'register_routes' ) );
|
self::register_routes();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -22,7 +22,7 @@ class Followers {
|
||||||
* Initialize the class, registering WordPress hooks
|
* Initialize the class, registering WordPress hooks
|
||||||
*/
|
*/
|
||||||
public static function init() {
|
public static function init() {
|
||||||
\add_action( 'rest_api_init', array( self::class, 'register_routes' ) );
|
self::register_routes();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -18,7 +18,8 @@ class Following {
|
||||||
* Initialize the class, registering WordPress hooks
|
* Initialize the class, registering WordPress hooks
|
||||||
*/
|
*/
|
||||||
public static function init() {
|
public static function init() {
|
||||||
\add_action( 'rest_api_init', array( self::class, 'register_routes' ) );
|
self::register_routes();
|
||||||
|
|
||||||
\add_filter( 'activitypub_rest_following', array( self::class, 'default_following' ), 10, 2 );
|
\add_filter( 'activitypub_rest_following', array( self::class, 'default_following' ), 10, 2 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@ class Inbox {
|
||||||
* Initialize the class, registering WordPress hooks
|
* Initialize the class, registering WordPress hooks
|
||||||
*/
|
*/
|
||||||
public static function init() {
|
public static function init() {
|
||||||
\add_action( 'rest_api_init', array( self::class, 'register_routes' ) );
|
self::register_routes();
|
||||||
|
|
||||||
\add_action( 'activitypub_inbox_create', array( self::class, 'handle_create' ), 10, 2 );
|
\add_action( 'activitypub_inbox_create', array( self::class, 'handle_create' ), 10, 2 );
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,8 @@ class Nodeinfo {
|
||||||
* Initialize the class, registering WordPress hooks
|
* Initialize the class, registering WordPress hooks
|
||||||
*/
|
*/
|
||||||
public static function init() {
|
public static function init() {
|
||||||
\add_action( 'rest_api_init', array( self::class, 'register_routes' ) );
|
self::register_routes();
|
||||||
|
|
||||||
\add_filter( 'nodeinfo_data', array( self::class, 'add_nodeinfo_discovery' ), 10, 2 );
|
\add_filter( 'nodeinfo_data', array( self::class, 'add_nodeinfo_discovery' ), 10, 2 );
|
||||||
\add_filter( 'nodeinfo2_data', array( self::class, 'add_nodeinfo2_discovery' ), 10 );
|
\add_filter( 'nodeinfo2_data', array( self::class, 'add_nodeinfo2_discovery' ), 10 );
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,33 +0,0 @@
|
||||||
<?php
|
|
||||||
namespace Activitypub\Rest;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ActivityPub OStatus REST-Class
|
|
||||||
*
|
|
||||||
* @author Matthias Pfefferle
|
|
||||||
*
|
|
||||||
* @see https://www.w3.org/community/ostatus/
|
|
||||||
*/
|
|
||||||
class Ostatus {
|
|
||||||
/**
|
|
||||||
* Register routes
|
|
||||||
*/
|
|
||||||
public static function register_routes() {
|
|
||||||
\register_rest_route(
|
|
||||||
ACTIVITYPUB_REST_NAMESPACE,
|
|
||||||
'/ostatus/remote-follow',
|
|
||||||
array(
|
|
||||||
array(
|
|
||||||
'methods' => \WP_REST_Server::READABLE,
|
|
||||||
'callback' => array( '\Activitypub\Rest\Ostatus', 'get' ),
|
|
||||||
// 'args' => self::request_parameters(),
|
|
||||||
'permission_callback' => '__return_true',
|
|
||||||
),
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function get() {
|
|
||||||
// @todo implement
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -24,7 +24,7 @@ class Outbox {
|
||||||
* Initialize the class, registering WordPress hooks
|
* Initialize the class, registering WordPress hooks
|
||||||
*/
|
*/
|
||||||
public static function init() {
|
public static function init() {
|
||||||
\add_action( 'rest_api_init', array( self::class, 'register_routes' ) );
|
self::register_routes();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -18,7 +18,8 @@ class Server {
|
||||||
* Initialize the class, registering WordPress hooks
|
* Initialize the class, registering WordPress hooks
|
||||||
*/
|
*/
|
||||||
public static function init() {
|
public static function init() {
|
||||||
\add_action( 'rest_api_init', array( self::class, 'register_routes' ) );
|
self::register_routes();
|
||||||
|
|
||||||
\add_filter( 'rest_request_before_callbacks', array( self::class, 'authorize_activitypub_requests' ), 10, 3 );
|
\add_filter( 'rest_request_before_callbacks', array( self::class, 'authorize_activitypub_requests' ), 10, 3 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@ class Users {
|
||||||
* Initialize the class, registering WordPress hooks
|
* Initialize the class, registering WordPress hooks
|
||||||
*/
|
*/
|
||||||
public static function init() {
|
public static function init() {
|
||||||
\add_action( 'rest_api_init', array( self::class, 'register_routes' ) );
|
self::register_routes();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -19,7 +19,8 @@ class Webfinger {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function init() {
|
public static function init() {
|
||||||
\add_action( 'rest_api_init', array( self::class, 'register_routes' ) );
|
self::register_routes();
|
||||||
|
|
||||||
\add_filter( 'webfinger_user_data', array( self::class, 'add_user_discovery' ), 10, 3 );
|
\add_filter( 'webfinger_user_data', array( self::class, 'add_user_discovery' ), 10, 3 );
|
||||||
\add_filter( 'webfinger_data', array( self::class, 'add_pseudo_user_discovery' ), 99, 2 );
|
\add_filter( 'webfinger_data', array( self::class, 'add_pseudo_user_discovery' ), 99, 2 );
|
||||||
}
|
}
|
||||||
|
|
|
@ -452,6 +452,15 @@ class Post {
|
||||||
protected function get_content() {
|
protected function get_content() {
|
||||||
global $post;
|
global $post;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides an action hook so plugins can add their own hooks/filters before AP content is generated.
|
||||||
|
*
|
||||||
|
* Example: if a plugin adds a filter to `the_content` to add a button to the end of posts, it can also remove that filter here.
|
||||||
|
*
|
||||||
|
* @param WP_Post $post The post object.
|
||||||
|
*/
|
||||||
|
do_action( 'activitypub_before_get_content', $post );
|
||||||
|
|
||||||
// phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
|
// phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
|
||||||
$post = $this->wp_post;
|
$post = $this->wp_post;
|
||||||
$content = $this->get_post_content_template();
|
$content = $this->get_post_content_template();
|
||||||
|
|
Loading…
Reference in a new issue