Allow setting the REST namespace with ACTIVITYPUB_REST_NAMESPACE
This commit is contained in:
parent
154b0018af
commit
abfa7c7969
13 changed files with 34 additions and 29 deletions
|
@ -25,6 +25,7 @@ function init() {
|
||||||
\defined( 'ACTIVITYPUB_HASHTAGS_REGEXP' ) || \define( 'ACTIVITYPUB_HASHTAGS_REGEXP', '(?:(?<=\s)|(?<=<p>)|(?<=<br>)|^)#([A-Za-z0-9_]+)(?:(?=\s|[[:punct:]]|$))' );
|
\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_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_REST_NAMESPACE' ) || define( 'ACTIVITYPUB_REST_NAMESPACE', 'activitypub/1.0' );
|
||||||
|
|
||||||
\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__ ) );
|
||||||
|
@ -120,12 +121,12 @@ function plugin_settings_link( $actions ) {
|
||||||
*/
|
*/
|
||||||
function add_rewrite_rules() {
|
function add_rewrite_rules() {
|
||||||
if ( ! \class_exists( 'Webfinger' ) ) {
|
if ( ! \class_exists( 'Webfinger' ) ) {
|
||||||
\add_rewrite_rule( '^.well-known/webfinger', 'index.php?rest_route=/activitypub/1.0/webfinger', 'top' );
|
\add_rewrite_rule( '^.well-known/webfinger', 'index.php?rest_route=/' . ACTIVITYPUB_REST_NAMESPACE . '/webfinger', 'top' );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ! \class_exists( 'Nodeinfo' ) || ! (bool) \get_option( 'blog_public', 1 ) ) {
|
if ( ! \class_exists( 'Nodeinfo' ) || ! (bool) \get_option( 'blog_public', 1 ) ) {
|
||||||
\add_rewrite_rule( '^.well-known/nodeinfo', 'index.php?rest_route=/activitypub/1.0/nodeinfo/discovery', 'top' );
|
\add_rewrite_rule( '^.well-known/nodeinfo', 'index.php?rest_route=/' . ACTIVITYPUB_REST_NAMESPACE . '/nodeinfo/discovery', 'top' );
|
||||||
\add_rewrite_rule( '^.well-known/x-nodeinfo2', 'index.php?rest_route=/activitypub/1.0/nodeinfo2', 'top' );
|
\add_rewrite_rule( '^.well-known/x-nodeinfo2', 'index.php?rest_route=/' . ACTIVITYPUB_REST_NAMESPACE . '/nodeinfo2', 'top' );
|
||||||
}
|
}
|
||||||
|
|
||||||
\add_rewrite_endpoint( 'activitypub', EP_AUTHORS | EP_PERMALINK | EP_PAGES );
|
\add_rewrite_endpoint( 'activitypub', EP_AUTHORS | EP_PERMALINK | EP_PAGES );
|
||||||
|
|
|
@ -148,7 +148,8 @@ class Activity {
|
||||||
$this->published = $object['published'];
|
$this->published = $object['published'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->add_to( \get_rest_url( null, '/activitypub/1.0/users/' . intval( $post->get_post_author() ) . '/followers' ) );
|
$url = sprintf( '/%/users/%d/followers', ACTIVITYPUB_REST_NAMESPACE, intval( $post->get_post_author() ) );
|
||||||
|
$this->add_to( \get_rest_url( null, $url ) );
|
||||||
|
|
||||||
if ( isset( $this->object['attributedTo'] ) ) {
|
if ( isset( $this->object['attributedTo'] ) ) {
|
||||||
$this->actor = $this->object['attributedTo'];
|
$this->actor = $this->object['attributedTo'];
|
||||||
|
|
|
@ -142,7 +142,8 @@ class Post {
|
||||||
*/
|
*/
|
||||||
public function __construct( $post ) {
|
public function __construct( $post ) {
|
||||||
$this->post = \get_post( $post );
|
$this->post = \get_post( $post );
|
||||||
$this->add_to( \get_rest_url( null, '/activitypub/1.0/users/' . intval( $this->get_post_author() ) . '/followers' ) );
|
$url = sprintf( '/%/users/%d/followers', ACTIVITYPUB_REST_NAMESPACE, intval( $post->get_post_author() ) );
|
||||||
|
$this->add_to( \get_rest_url( null, $url ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -27,7 +27,7 @@ class Followers {
|
||||||
*/
|
*/
|
||||||
public static function register_routes() {
|
public static function register_routes() {
|
||||||
\register_rest_route(
|
\register_rest_route(
|
||||||
'activitypub/1.0',
|
ACTIVITYPUB_REST_NAMESPACE,
|
||||||
'/users/(?P<user_id>\d+)/followers',
|
'/users/(?P<user_id>\d+)/followers',
|
||||||
array(
|
array(
|
||||||
array(
|
array(
|
||||||
|
@ -78,7 +78,7 @@ class Followers {
|
||||||
$json->actor = \get_author_posts_url( $user_id );
|
$json->actor = \get_author_posts_url( $user_id );
|
||||||
$json->type = 'OrderedCollectionPage';
|
$json->type = 'OrderedCollectionPage';
|
||||||
|
|
||||||
$json->partOf = \get_rest_url( null, "/activitypub/1.0/users/$user_id/followers" ); // phpcs:ignore
|
$json->partOf = \get_rest_url( null, sprintf( '/%s/users/%d/followers', ACTIVITYPUB_REST_NAMESPACE, $user_id ) ); // phpcs:ignore
|
||||||
$json->first = $json->partOf; // phpcs:ignore
|
$json->first = $json->partOf; // phpcs:ignore
|
||||||
$json->totalItems = FollowerCollection::count_followers( $user_id ); // phpcs:ignore
|
$json->totalItems = FollowerCollection::count_followers( $user_id ); // phpcs:ignore
|
||||||
$json->orderedItems = FollowerCollection::get_followers( $user_id, ARRAY_N ); // phpcs:ignore
|
$json->orderedItems = FollowerCollection::get_followers( $user_id, ARRAY_N ); // phpcs:ignore
|
||||||
|
|
|
@ -21,7 +21,7 @@ class Following {
|
||||||
*/
|
*/
|
||||||
public static function register_routes() {
|
public static function register_routes() {
|
||||||
\register_rest_route(
|
\register_rest_route(
|
||||||
'activitypub/1.0',
|
ACTIVITYPUB_REST_NAMESPACE,
|
||||||
'/users/(?P<user_id>\d+)/following',
|
'/users/(?P<user_id>\d+)/following',
|
||||||
array(
|
array(
|
||||||
array(
|
array(
|
||||||
|
@ -72,7 +72,7 @@ class Following {
|
||||||
$json->actor = \get_author_posts_url( $user_id );
|
$json->actor = \get_author_posts_url( $user_id );
|
||||||
$json->type = 'OrderedCollectionPage';
|
$json->type = 'OrderedCollectionPage';
|
||||||
|
|
||||||
$json->partOf = \get_rest_url( null, "/activitypub/1.0/users/$user_id/following" ); // phpcs:ignore
|
$json->partOf = \get_rest_url( null, sprintf( '/%s/users/%d/following', ACTIVITYPUB_REST_NAMESPACE, $user_id ) ); // phpcs:ignore
|
||||||
$json->totalItems = 0; // phpcs:ignore
|
$json->totalItems = 0; // phpcs:ignore
|
||||||
$json->orderedItems = apply_filters( 'activitypub_following', array(), $user ); // phpcs:ignore
|
$json->orderedItems = apply_filters( 'activitypub_following', array(), $user ); // phpcs:ignore
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ class Inbox {
|
||||||
*/
|
*/
|
||||||
public static function register_routes() {
|
public static function register_routes() {
|
||||||
\register_rest_route(
|
\register_rest_route(
|
||||||
'activitypub/1.0',
|
ACTIVITYPUB_REST_NAMESPACE,
|
||||||
'/inbox',
|
'/inbox',
|
||||||
array(
|
array(
|
||||||
array(
|
array(
|
||||||
|
@ -39,7 +39,7 @@ class Inbox {
|
||||||
);
|
);
|
||||||
|
|
||||||
\register_rest_route(
|
\register_rest_route(
|
||||||
'activitypub/1.0',
|
ACTIVITYPUB_REST_NAMESPACE,
|
||||||
'/users/(?P<user_id>\d+)/inbox',
|
'/users/(?P<user_id>\d+)/inbox',
|
||||||
array(
|
array(
|
||||||
array(
|
array(
|
||||||
|
@ -108,7 +108,7 @@ class Inbox {
|
||||||
$json->id = \home_url( \add_query_arg( null, null ) );
|
$json->id = \home_url( \add_query_arg( null, null ) );
|
||||||
$json->generator = 'http://wordpress.org/?v=' . \get_bloginfo_rss( 'version' );
|
$json->generator = 'http://wordpress.org/?v=' . \get_bloginfo_rss( 'version' );
|
||||||
$json->type = 'OrderedCollectionPage';
|
$json->type = 'OrderedCollectionPage';
|
||||||
$json->partOf = \get_rest_url( null, "/activitypub/1.0/users/$user_id/inbox" ); // phpcs:ignore
|
$json->partOf = \get_rest_url( null, sprintf( '/%s/users/%d/inbox', ACTIVITYPUB_REST_NAMESPACE, $user_id ) ); // phpcs:ignore
|
||||||
|
|
||||||
$json->totalItems = 0; // phpcs:ignore
|
$json->totalItems = 0; // phpcs:ignore
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@ class Nodeinfo {
|
||||||
*/
|
*/
|
||||||
public static function register_routes() {
|
public static function register_routes() {
|
||||||
\register_rest_route(
|
\register_rest_route(
|
||||||
'activitypub/1.0',
|
ACTIVITYPUB_REST_NAMESPACE,
|
||||||
'/nodeinfo/discovery',
|
'/nodeinfo/discovery',
|
||||||
array(
|
array(
|
||||||
array(
|
array(
|
||||||
|
@ -35,7 +35,7 @@ class Nodeinfo {
|
||||||
);
|
);
|
||||||
|
|
||||||
\register_rest_route(
|
\register_rest_route(
|
||||||
'activitypub/1.0',
|
ACTIVITYPUB_REST_NAMESPACE,
|
||||||
'/nodeinfo',
|
'/nodeinfo',
|
||||||
array(
|
array(
|
||||||
array(
|
array(
|
||||||
|
@ -47,7 +47,7 @@ class Nodeinfo {
|
||||||
);
|
);
|
||||||
|
|
||||||
\register_rest_route(
|
\register_rest_route(
|
||||||
'activitypub/1.0',
|
ACTIVITYPUB_REST_NAMESPACE,
|
||||||
'/nodeinfo2',
|
'/nodeinfo2',
|
||||||
array(
|
array(
|
||||||
array(
|
array(
|
||||||
|
@ -173,7 +173,7 @@ class Nodeinfo {
|
||||||
$discovery['links'] = array(
|
$discovery['links'] = array(
|
||||||
array(
|
array(
|
||||||
'rel' => 'http://nodeinfo.diaspora.software/ns/schema/2.0',
|
'rel' => 'http://nodeinfo.diaspora.software/ns/schema/2.0',
|
||||||
'href' => \get_rest_url( null, 'activitypub/1.0/nodeinfo' ),
|
'href' => \get_rest_url( null, ACTIVITYPUB_REST_NAMESPACE . '/nodeinfo' ),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ class Ostatus {
|
||||||
*/
|
*/
|
||||||
public static function register_routes() {
|
public static function register_routes() {
|
||||||
\register_rest_route(
|
\register_rest_route(
|
||||||
'activitypub/1.0',
|
ACTIVITYPUB_REST_NAMESPACE,
|
||||||
'/ostatus/remote-follow',
|
'/ostatus/remote-follow',
|
||||||
array(
|
array(
|
||||||
array(
|
array(
|
||||||
|
|
|
@ -21,7 +21,7 @@ class Outbox {
|
||||||
*/
|
*/
|
||||||
public static function register_routes() {
|
public static function register_routes() {
|
||||||
\register_rest_route(
|
\register_rest_route(
|
||||||
'activitypub/1.0',
|
ACTIVITYPUB_REST_NAMESPACE,
|
||||||
'/users/(?P<user_id>\d+)/outbox',
|
'/users/(?P<user_id>\d+)/outbox',
|
||||||
array(
|
array(
|
||||||
array(
|
array(
|
||||||
|
@ -72,7 +72,7 @@ class Outbox {
|
||||||
$json->generator = 'http://wordpress.org/?v=' . \get_bloginfo_rss( 'version' );
|
$json->generator = 'http://wordpress.org/?v=' . \get_bloginfo_rss( 'version' );
|
||||||
$json->actor = \get_author_posts_url( $user_id );
|
$json->actor = \get_author_posts_url( $user_id );
|
||||||
$json->type = 'OrderedCollectionPage';
|
$json->type = 'OrderedCollectionPage';
|
||||||
$json->partOf = \get_rest_url( null, "/activitypub/1.0/users/$user_id/outbox" ); // phpcs:ignore
|
$json->partOf = \get_rest_url( null, sprintf( '/%s/users/%d/outbox', ACTIVITYPUB_REST_NAMESPACE, $user_id ) ); // phpcs:ignore
|
||||||
$json->totalItems = 0; // phpcs:ignore
|
$json->totalItems = 0; // phpcs:ignore
|
||||||
|
|
||||||
// phpcs:ignore
|
// phpcs:ignore
|
||||||
|
|
|
@ -25,7 +25,7 @@ class Webfinger {
|
||||||
*/
|
*/
|
||||||
public static function register_routes() {
|
public static function register_routes() {
|
||||||
\register_rest_route(
|
\register_rest_route(
|
||||||
'activitypub/1.0',
|
ACTIVITYPUB_REST_NAMESPACE,
|
||||||
'/webfinger',
|
'/webfinger',
|
||||||
array(
|
array(
|
||||||
array(
|
array(
|
||||||
|
|
|
@ -28,10 +28,10 @@ if ( \has_header_image() ) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$json->inbox = \get_rest_url( null, "/activitypub/1.0/users/$author_id/inbox" );
|
$json->inbox = \get_rest_url( null, sprintf( '/%s/users/%d/inbox', ACTIVITYPUB_REST_NAMESPACE, $author_id ) );
|
||||||
$json->outbox = \get_rest_url( null, "/activitypub/1.0/users/$author_id/outbox" );
|
$json->outbox = \get_rest_url( null, sprintf( '/%s/users/%d/outbox', ACTIVITYPUB_REST_NAMESPACE, $author_id ) );
|
||||||
$json->followers = \get_rest_url( null, "/activitypub/1.0/users/$author_id/followers" );
|
$json->followers = \get_rest_url( null, sprintf( '/%s/users/%d/followers', ACTIVITYPUB_REST_NAMESPACE, $author_id ) );
|
||||||
$json->following = \get_rest_url( null, "/activitypub/1.0/users/$author_id/following" );
|
$json->following = \get_rest_url( null, sprintf( '/%s/users/%d/following', ACTIVITYPUB_REST_NAMESPACE, $author_id ) );
|
||||||
|
|
||||||
$json->manuallyApprovesFollowers = \apply_filters( 'activitypub_json_manually_approves_followers', \__return_false() ); // phpcs:ignore
|
$json->manuallyApprovesFollowers = \apply_filters( 'activitypub_json_manually_approves_followers', \__return_false() ); // phpcs:ignore
|
||||||
|
|
||||||
|
|
|
@ -27,10 +27,12 @@ if ( \has_header_image() ) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$json->inbox = \get_rest_url( null, '/activitypub/1.0/blog/inbox' );
|
$blog_base = sprintf( '/%s/blog/', ACTIVITYPUB_REST_NAMESPACE );
|
||||||
$json->outbox = \get_rest_url( null, '/activitypub/1.0/blog/outbox' );
|
|
||||||
$json->followers = \get_rest_url( null, '/activitypub/1.0/blog/followers' );
|
$json->inbox = \get_rest_url( null, $blog_base . 'inbox' );
|
||||||
$json->following = \get_rest_url( null, '/activitypub/1.0/blog/following' );
|
$json->outbox = \get_rest_url( null, $blog_base . 'outbox' );
|
||||||
|
$json->followers = \get_rest_url( null, $blog_base . 'followers' );
|
||||||
|
$json->following = \get_rest_url( null, $blog_base . 'following' );
|
||||||
|
|
||||||
$json->manuallyApprovesFollowers = \apply_filters( 'activitypub_json_manually_approves_followers', \__return_false() ); // phpcs:ignore
|
$json->manuallyApprovesFollowers = \apply_filters( 'activitypub_json_manually_approves_followers', \__return_false() ); // phpcs:ignore
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ class Test_Activitypub_Activity extends WP_UnitTestCase {
|
||||||
$activitypub_activity = new \Activitypub\Model\Activity( 'Create' );
|
$activitypub_activity = new \Activitypub\Model\Activity( 'Create' );
|
||||||
$activitypub_activity->from_post( $activitypub_post );
|
$activitypub_activity->from_post( $activitypub_post );
|
||||||
|
|
||||||
$this->assertContains( \get_rest_url( null, '/activitypub/1.0/users/1/followers' ), $activitypub_activity->get_to() );
|
$this->assertContains( \get_rest_url( null, '/' . ACTIVITYPUB_REST_NAMESPACE . '/users/1/followers' ), $activitypub_activity->get_to() );
|
||||||
$this->assertContains( 'https://example.com/alex', $activitypub_activity->get_cc() );
|
$this->assertContains( 'https://example.com/alex', $activitypub_activity->get_cc() );
|
||||||
|
|
||||||
remove_all_filters( 'activitypub_extract_mentions' );
|
remove_all_filters( 'activitypub_extract_mentions' );
|
||||||
|
|
Loading…
Reference in a new issue