diff --git a/activitypub.php b/activitypub.php index 7320f0c..35e6de8 100644 --- a/activitypub.php +++ b/activitypub.php @@ -39,50 +39,50 @@ function init() { require_once \dirname( __FILE__ ) . '/includes/model/class-post.php'; require_once \dirname( __FILE__ ) . '/includes/class-activity-dispatcher.php'; - \Activitypub\Activity_Dispatcher::init(); + Activity_Dispatcher::init(); require_once \dirname( __FILE__ ) . '/includes/class-activitypub.php'; - \Activitypub\Activitypub::init(); + Activitypub::init(); // Configure the REST API route require_once \dirname( __FILE__ ) . '/includes/rest/class-outbox.php'; - \Activitypub\Rest\Outbox::init(); + Rest\Outbox::init(); require_once \dirname( __FILE__ ) . '/includes/rest/class-inbox.php'; - \Activitypub\Rest\Inbox::init(); + Rest\Inbox::init(); require_once \dirname( __FILE__ ) . '/includes/rest/class-followers.php'; - \Activitypub\Rest\Followers::init(); + Rest\Followers::init(); require_once \dirname( __FILE__ ) . '/includes/rest/class-following.php'; - \Activitypub\Rest\Following::init(); + Rest\Following::init(); require_once \dirname( __FILE__ ) . '/includes/rest/class-webfinger.php'; - \Activitypub\Rest\Webfinger::init(); + Rest\Webfinger::init(); // load NodeInfo endpoints only if blog is public if ( true === (bool) \get_option( 'blog_public', 1 ) ) { require_once \dirname( __FILE__ ) . '/includes/rest/class-nodeinfo.php'; - \Activitypub\Rest\NodeInfo::init(); + Rest\NodeInfo::init(); } require_once \dirname( __FILE__ ) . '/includes/class-admin.php'; - \Activitypub\Admin::init(); + Admin::init(); require_once \dirname( __FILE__ ) . '/includes/class-hashtag.php'; - \Activitypub\Hashtag::init(); + Hashtag::init(); require_once \dirname( __FILE__ ) . '/includes/class-shortcodes.php'; - \Activitypub\Shortcodes::init(); + Shortcodes::init(); require_once \dirname( __FILE__ ) . '/includes/class-mention.php'; - \Activitypub\Mention::init(); + Mention::init(); require_once \dirname( __FILE__ ) . '/includes/class-debug.php'; - \Activitypub\Debug::init(); + Debug::init(); require_once \dirname( __FILE__ ) . '/includes/class-health-check.php'; - \Activitypub\Health_Check::init(); + Health_Check::init(); if ( \WP_DEBUG ) { require_once \dirname( __FILE__ ) . '/includes/debug.php'; @@ -136,6 +136,6 @@ function flush_rewrite_rules() { */ function enable_buddypress_features() { require_once \dirname( __FILE__ ) . '/integration/class-buddypress.php'; - \Activitypub\Integration\Buddypress::init(); + Integration\Buddypress::init(); } add_action( 'bp_include', '\Activitypub\enable_buddypress_features' ); diff --git a/includes/class-activity-dispatcher.php b/includes/class-activity-dispatcher.php index 6df83e7..57fee1a 100644 --- a/includes/class-activity-dispatcher.php +++ b/includes/class-activity-dispatcher.php @@ -1,6 +1,9 @@ get_post_author(); - $activitypub_activity = new \Activitypub\Model\Activity( $activity_type ); + $activitypub_activity = new Activity( $activity_type ); $activitypub_activity->from_post( $activitypub_post ); $inboxes = \Activitypub\get_follower_inboxes( $user_id, $activitypub_activity->get_cc() ); diff --git a/includes/class-activitypub.php b/includes/class-activitypub.php index 4a60915..4730515 100644 --- a/includes/class-activitypub.php +++ b/includes/class-activitypub.php @@ -11,9 +11,9 @@ class Activitypub { * Initialize the class, registering WordPress hooks. */ public static function init() { - \add_filter( 'template_include', array( '\Activitypub\Activitypub', 'render_json_template' ), 99 ); - \add_filter( 'query_vars', array( '\Activitypub\Activitypub', 'add_query_vars' ) ); - \add_filter( 'pre_get_avatar_data', array( '\Activitypub\Activitypub', 'pre_get_avatar_data' ), 11, 2 ); + \add_filter( 'template_include', array( self::class, 'render_json_template' ), 99 ); + \add_filter( 'query_vars', array( self::class, 'add_query_vars' ) ); + \add_filter( 'pre_get_avatar_data', array( self::class, 'pre_get_avatar_data' ), 11, 2 ); // Add support for ActivityPub to custom post types $post_types = \get_option( 'activitypub_support_post_types', array( 'post', 'page' ) ) ? \get_option( 'activitypub_support_post_types', array( 'post', 'page' ) ) : array(); @@ -22,9 +22,9 @@ class Activitypub { \add_post_type_support( $post_type, 'activitypub' ); } - \add_action( 'transition_post_status', array( '\Activitypub\Activitypub', 'schedule_post_activity' ), 33, 3 ); - \add_action( 'wp_trash_post', array( '\Activitypub\Activitypub', 'trash_post' ), 1 ); - \add_action( 'untrash_post', array( '\Activitypub\Activitypub', 'untrash_post' ), 1 ); + \add_action( 'transition_post_status', array( self::class, 'schedule_post_activity' ), 33, 3 ); + \add_action( 'wp_trash_post', array( self::class, 'trash_post' ), 1 ); + \add_action( 'untrash_post', array( self::class, 'untrash_post' ), 1 ); } /** diff --git a/includes/class-admin.php b/includes/class-admin.php index e98d547..220ed9b 100644 --- a/includes/class-admin.php +++ b/includes/class-admin.php @@ -11,10 +11,10 @@ class Admin { * Initialize the class, registering WordPress hooks */ public static function init() { - \add_action( 'admin_menu', array( '\Activitypub\Admin', 'admin_menu' ) ); - \add_action( 'admin_init', array( '\Activitypub\Admin', 'register_settings' ) ); - \add_action( 'show_user_profile', array( '\Activitypub\Admin', 'add_fediverse_profile' ) ); - \add_action( 'admin_enqueue_scripts', array( '\Activitypub\Admin', 'enqueue_scripts' ) ); + \add_action( 'admin_menu', array( self::class, 'admin_menu' ) ); + \add_action( 'admin_init', array( self::class, 'register_settings' ) ); + \add_action( 'show_user_profile', array( self::class, 'add_fediverse_profile' ) ); + \add_action( 'admin_enqueue_scripts', array( self::class, 'enqueue_scripts' ) ); } /** @@ -26,14 +26,14 @@ class Admin { 'ActivityPub', 'manage_options', 'activitypub', - array( '\Activitypub\Admin', 'settings_page' ) + array( self::class, 'settings_page' ) ); - \add_action( 'load-' . $settings_page, array( '\Activitypub\Admin', 'add_settings_help_tab' ) ); + \add_action( 'load-' . $settings_page, array( self::class, 'add_settings_help_tab' ) ); - $followers_list_page = \add_users_page( \__( 'Followers', 'activitypub' ), \__( 'Followers (Fediverse)', 'activitypub' ), 'read', 'activitypub-followers-list', array( '\Activitypub\Admin', 'followers_list_page' ) ); + $followers_list_page = \add_users_page( \__( 'Followers', 'activitypub' ), \__( 'Followers (Fediverse)', 'activitypub' ), 'read', 'activitypub-followers-list', array( self::class, 'followers_list_page' ) ); - \add_action( 'load-' . $followers_list_page, array( '\Activitypub\Admin', 'add_followers_list_help_tab' ) ); + \add_action( 'load-' . $followers_list_page, array( self::class, 'add_followers_list_help_tab' ) ); } /** diff --git a/includes/class-debug.php b/includes/class-debug.php index 767d4a9..36f8bda 100644 --- a/includes/class-debug.php +++ b/includes/class-debug.php @@ -1,6 +1,9 @@ \__( 'Author URL test', 'activitypub' ), - 'test' => array( '\Activitypub\Health_Check', 'test_author_url' ), + 'test' => array( self::class, 'test_author_url' ), ); $tests['direct']['activitypub_test_webfinger'] = array( 'label' => __( 'WebFinger Test', 'activitypub' ), - 'test' => array( '\Activitypub\Health_Check', 'test_webfinger' ), + 'test' => array( self::class, 'test_webfinger' ), ); return $tests; diff --git a/includes/class-mention.php b/includes/class-mention.php index 7c8672a..e0930cc 100644 --- a/includes/class-mention.php +++ b/includes/class-mention.php @@ -11,8 +11,8 @@ class Mention { * Initialize the class, registering WordPress hooks */ public static function init() { - \add_filter( 'the_content', array( '\Activitypub\Mention', 'the_content' ), 99, 2 ); - \add_filter( 'activitypub_extract_mentions', array( '\Activitypub\Mention', 'extract_mentions' ), 99, 2 ); + \add_filter( 'the_content', array( self::class, 'the_content' ), 99, 2 ); + \add_filter( 'activitypub_extract_mentions', array( self::class, 'extract_mentions' ), 99, 2 ); } /** @@ -46,7 +46,7 @@ class Mention { $the_content ); - $the_content = \preg_replace_callback( '/@' . ACTIVITYPUB_USERNAME_REGEXP . '/', array( '\Activitypub\Mention', 'replace_with_links' ), $the_content ); + $the_content = \preg_replace_callback( '/@' . ACTIVITYPUB_USERNAME_REGEXP . '/', array( self::class, 'replace_with_links' ), $the_content ); $the_content = str_replace( array_reverse( array_keys( $protected_tags ) ), array_reverse( array_values( $protected_tags ) ), $the_content ); diff --git a/includes/class-webfinger.php b/includes/class-webfinger.php index c7d2cba..1581853 100644 --- a/includes/class-webfinger.php +++ b/includes/class-webfinger.php @@ -1,6 +1,8 @@ \WP_REST_Server::READABLE, - 'callback' => array( '\Activitypub\Rest\Followers', 'get' ), + 'callback' => array( self::class, 'get' ), 'args' => self::request_parameters(), 'permission_callback' => '__return_true', ), diff --git a/includes/rest/class-following.php b/includes/rest/class-following.php index d7caff4..52a95e7 100644 --- a/includes/rest/class-following.php +++ b/includes/rest/class-following.php @@ -13,7 +13,7 @@ class Following { * Initialize the class, registering WordPress hooks */ public static function init() { - \add_action( 'rest_api_init', array( '\Activitypub\Rest\Following', 'register_routes' ) ); + \add_action( 'rest_api_init', array( self::class, 'register_routes' ) ); } /** @@ -26,7 +26,7 @@ class Following { array( array( 'methods' => \WP_REST_Server::READABLE, - 'callback' => array( '\Activitypub\Rest\Following', 'get' ), + 'callback' => array( self::class, 'get' ), 'args' => self::request_parameters(), 'permission_callback' => '__return_true', ), diff --git a/includes/rest/class-inbox.php b/includes/rest/class-inbox.php index 86aefd4..1a63108 100644 --- a/includes/rest/class-inbox.php +++ b/includes/rest/class-inbox.php @@ -1,6 +1,8 @@ \WP_REST_Server::EDITABLE, - 'callback' => array( '\Activitypub\Rest\Inbox', 'shared_inbox_post' ), + 'callback' => array( self::class, 'shared_inbox_post' ), 'args' => self::shared_inbox_post_parameters(), 'permission_callback' => '__return_true', ), @@ -45,13 +47,13 @@ class Inbox { array( array( 'methods' => \WP_REST_Server::EDITABLE, - 'callback' => array( '\Activitypub\Rest\Inbox', 'user_inbox_post' ), + 'callback' => array( self::class, 'user_inbox_post' ), 'args' => self::user_inbox_post_parameters(), 'permission_callback' => '__return_true', ), array( 'methods' => \WP_REST_Server::READABLE, - 'callback' => array( '\Activitypub\Rest\Inbox', 'user_inbox_get' ), + 'callback' => array( self::class, 'user_inbox_get' ), 'args' => self::user_inbox_get_parameters(), 'permission_callback' => '__return_true', ), @@ -356,7 +358,7 @@ class Inbox { $inbox = \Activitypub\get_inbox_by_actor( $object['actor'] ); // send "Accept" activity - $activity = new \Activitypub\Model\Activity( 'Accept' ); + $activity = new Activity( 'Accept' ); $activity->set_object( $object ); $activity->set_actor( \get_author_posts_url( $user_id ) ); $activity->set_to( $object['actor'] ); diff --git a/includes/rest/class-nodeinfo.php b/includes/rest/class-nodeinfo.php index 3106c5e..100fdd3 100644 --- a/includes/rest/class-nodeinfo.php +++ b/includes/rest/class-nodeinfo.php @@ -13,9 +13,9 @@ class Nodeinfo { * Initialize the class, registering WordPress hooks */ public static function init() { - \add_action( 'rest_api_init', array( '\Activitypub\Rest\Nodeinfo', 'register_routes' ) ); - \add_filter( 'nodeinfo_data', array( '\Activitypub\Rest\Nodeinfo', 'add_nodeinfo_discovery' ), 10, 2 ); - \add_filter( 'nodeinfo2_data', array( '\Activitypub\Rest\Nodeinfo', 'add_nodeinfo2_discovery' ), 10 ); + \add_action( 'rest_api_init', array( self::class, 'register_routes' ) ); + \add_filter( 'nodeinfo_data', array( self::class, 'add_nodeinfo_discovery' ), 10, 2 ); + \add_filter( 'nodeinfo2_data', array( self::class, 'add_nodeinfo2_discovery' ), 10 ); } /** @@ -28,7 +28,7 @@ class Nodeinfo { array( array( 'methods' => \WP_REST_Server::READABLE, - 'callback' => array( '\Activitypub\Rest\Nodeinfo', 'discovery' ), + 'callback' => array( self::class, 'discovery' ), 'permission_callback' => '__return_true', ), ) @@ -40,7 +40,7 @@ class Nodeinfo { array( array( 'methods' => \WP_REST_Server::READABLE, - 'callback' => array( '\Activitypub\Rest\Nodeinfo', 'nodeinfo' ), + 'callback' => array( self::class, 'nodeinfo' ), 'permission_callback' => '__return_true', ), ) @@ -52,7 +52,7 @@ class Nodeinfo { array( array( 'methods' => \WP_REST_Server::READABLE, - 'callback' => array( '\Activitypub\Rest\Nodeinfo', 'nodeinfo2' ), + 'callback' => array( self::class, 'nodeinfo2' ), 'permission_callback' => '__return_true', ), ) diff --git a/includes/rest/class-outbox.php b/includes/rest/class-outbox.php index 8749d11..905dfd5 100644 --- a/includes/rest/class-outbox.php +++ b/includes/rest/class-outbox.php @@ -13,7 +13,7 @@ class Outbox { * Initialize the class, registering WordPress hooks */ public static function init() { - \add_action( 'rest_api_init', array( '\Activitypub\Rest\Outbox', 'register_routes' ) ); + \add_action( 'rest_api_init', array( self::class, 'register_routes' ) ); } /** @@ -26,7 +26,7 @@ class Outbox { array( array( 'methods' => \WP_REST_Server::READABLE, - 'callback' => array( '\Activitypub\Rest\Outbox', 'user_outbox_get' ), + 'callback' => array( self::class, 'user_outbox_get' ), 'args' => self::request_parameters(), 'permission_callback' => '__return_true', ), diff --git a/includes/rest/class-webfinger.php b/includes/rest/class-webfinger.php index 0c6d5f1..d41cf25 100644 --- a/includes/rest/class-webfinger.php +++ b/includes/rest/class-webfinger.php @@ -1,6 +1,9 @@ \WP_REST_Server::READABLE, - 'callback' => array( '\Activitypub\Rest\Webfinger', 'webfinger' ), + 'callback' => array( self::class, 'webfinger' ), 'args' => self::request_parameters(), 'permission_callback' => '__return_true', ), @@ -45,7 +48,7 @@ class Webfinger { $resource = $request->get_param( 'resource' ); if ( \strpos( $resource, '@' ) === false ) { - return new \WP_Error( 'activitypub_unsupported_resource', \__( 'Resource is invalid', 'activitypub' ), array( 'status' => 400 ) ); + return new WP_Error( 'activitypub_unsupported_resource', \__( 'Resource is invalid', 'activitypub' ), array( 'status' => 400 ) ); } $resource = \str_replace( 'acct:', '', $resource ); @@ -54,13 +57,13 @@ class Webfinger { $resource_host = \substr( \strrchr( $resource, '@' ), 1 ); if ( \wp_parse_url( \home_url( '/' ), \PHP_URL_HOST ) !== $resource_host ) { - return new \WP_Error( 'activitypub_wrong_host', \__( 'Resource host does not match blog host', 'activitypub' ), array( 'status' => 404 ) ); + return new WP_Error( 'activitypub_wrong_host', \__( 'Resource host does not match blog host', 'activitypub' ), array( 'status' => 404 ) ); } $user = \get_user_by( 'login', \esc_sql( $resource_identifier ) ); if ( ! $user || ! user_can( $user, 'publish_posts' ) ) { - return new \WP_Error( 'activitypub_user_not_found', \__( 'User not found', 'activitypub' ), array( 'status' => 404 ) ); + return new WP_Error( 'activitypub_user_not_found', \__( 'User not found', 'activitypub' ), array( 'status' => 404 ) ); } $json = array( @@ -82,7 +85,7 @@ class Webfinger { ), ); - return new \WP_REST_Response( $json, 200 ); + return new WP_REST_Response( $json, 200 ); } /**