big refactoring to use namespaces for a better code structure
This commit is contained in:
parent
30b939b5a1
commit
40b2651b7e
24 changed files with 342 additions and 253 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -3,3 +3,4 @@
|
||||||
package-lock.json
|
package-lock.json
|
||||||
composer.lock
|
composer.lock
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
.idea/
|
||||||
|
|
2
LICENSE
2
LICENSE
|
@ -1,6 +1,6 @@
|
||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2018 Matthias Pfefferle
|
Copyright (c) 2019 Matthias Pfefferle
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
**Tags:** OStatus, fediverse, activitypub, activitystream
|
**Tags:** OStatus, fediverse, activitypub, activitystream
|
||||||
**Requires at least:** 4.7
|
**Requires at least:** 4.7
|
||||||
**Tested up to:** 5.1
|
**Tested up to:** 5.1
|
||||||
**Stable tag:** 0.4.4
|
**Stable tag:** 0.5.0
|
||||||
**Requires PHP:** 5.6
|
**Requires PHP:** 5.6
|
||||||
**License:** MIT
|
**License:** MIT
|
||||||
**License URI:** http://opensource.org/licenses/MIT
|
**License URI:** http://opensource.org/licenses/MIT
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
* Plugin Name: ActivityPub
|
* Plugin Name: ActivityPub
|
||||||
* Plugin URI: https://github.com/pfefferle/wordpress-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.
|
* Description: The ActivityPub protocol is a decentralized social networking protocol based upon the ActivityStreams 2.0 data format.
|
||||||
* Version: 0.4.4
|
* Version: 0.5.0
|
||||||
* Author: Matthias Pfefferle
|
* Author: Matthias Pfefferle
|
||||||
* Author URI: https://notiz.blog/
|
* Author URI: https://notiz.blog/
|
||||||
* License: MIT
|
* License: MIT
|
||||||
|
@ -12,77 +12,61 @@
|
||||||
* Domain Path: /languages
|
* Domain Path: /languages
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
namespace Activitypub;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize plugin
|
* Initialize pluginut
|
||||||
*/
|
*/
|
||||||
function activitypub_init() {
|
function init() {
|
||||||
defined( 'ACTIVITYPUB_HASHTAGS_REGEXP' ) || define( 'ACTIVITYPUB_HASHTAGS_REGEXP', '(^|\s|>)#([^\s<>]+)\b' );
|
defined( 'ACTIVITYPUB_HASHTAGS_REGEXP' ) || define( 'ACTIVITYPUB_HASHTAGS_REGEXP', '(^|\s|>)#([^\s<>]+)\b' );
|
||||||
|
|
||||||
require_once dirname( __FILE__ ) . '/includes/class-activitypub-signature.php';
|
require_once dirname( __FILE__ ) . '/includes/class-signature.php';
|
||||||
require_once dirname( __FILE__ ) . '/includes/class-activitypub-activity.php';
|
require_once dirname( __FILE__ ) . '/includes/class-activity.php';
|
||||||
require_once dirname( __FILE__ ) . '/includes/class-db-activitypub-followers.php';
|
require_once dirname( __FILE__ ) . '/includes/db/class-followers.php';
|
||||||
require_once dirname( __FILE__ ) . '/includes/functions.php';
|
require_once dirname( __FILE__ ) . '/includes/functions.php';
|
||||||
|
|
||||||
require_once dirname( __FILE__ ) . '/includes/class-activitypub-post.php';
|
require_once dirname( __FILE__ ) . '/includes/class-post.php';
|
||||||
add_filter( 'activitypub_the_summary', array( 'Activitypub_Post', 'add_backlink' ), 10, 2 );
|
\Activitypub\Post::init();
|
||||||
add_filter( 'activitypub_the_content', array( 'Activitypub_Post', 'add_backlink' ), 10, 2 );
|
|
||||||
|
|
||||||
require_once dirname( __FILE__ ) . '/includes/class-activitypub.php';
|
require_once dirname( __FILE__ ) . '/includes/class-activitypub.php';
|
||||||
add_filter( 'template_include', array( 'Activitypub', 'render_json_template' ), 99 );
|
\Activitypub\ActivityPub::init();
|
||||||
add_filter( 'query_vars', array( 'Activitypub', 'add_query_vars' ) );
|
|
||||||
add_action( 'init', array( 'Activitypub', 'add_rewrite_endpoint' ) );
|
|
||||||
add_filter( 'pre_get_avatar_data', array( 'Activitypub', 'pre_get_avatar_data' ), 11, 2 );
|
|
||||||
|
|
||||||
// Configure the REST API route
|
// Configure the REST API route
|
||||||
require_once dirname( __FILE__ ) . '/includes/class-rest-activitypub-outbox.php';
|
require_once dirname( __FILE__ ) . '/includes/rest/class-outbox.php';
|
||||||
add_action( 'rest_api_init', array( 'Rest_Activitypub_Outbox', 'register_routes' ) );
|
\Activitypub\Rest\Outbox::init();
|
||||||
add_action( 'activitypub_send_post_activity', array( 'Rest_Activitypub_Outbox', 'send_post_activity' ) );
|
|
||||||
add_action( 'activitypub_send_update_activity', array( 'Rest_Activitypub_Outbox', 'send_update_activity' ) );
|
|
||||||
|
|
||||||
require_once dirname( __FILE__ ) . '/includes/class-rest-activitypub-inbox.php';
|
require_once dirname( __FILE__ ) . '/includes/rest/class-inbox.php';
|
||||||
add_action( 'rest_api_init', array( 'Rest_Activitypub_Inbox', 'register_routes' ) );
|
\Activitypub\Rest\Inbox::init();
|
||||||
//add_filter( 'rest_pre_serve_request', array( 'Rest_Activitypub_Inbox', 'serve_request' ), 11, 4 );
|
|
||||||
add_action( 'activitypub_inbox_follow', array( 'Rest_Activitypub_Inbox', 'handle_follow' ), 10, 2 );
|
|
||||||
add_action( 'activitypub_inbox_unfollow', array( 'Rest_Activitypub_Inbox', 'handle_unfollow' ), 10, 2 );
|
|
||||||
//add_action( 'activitypub_inbox_like', array( 'Rest_Activitypub_Inbox', 'handle_reaction' ), 10, 2 );
|
|
||||||
//add_action( 'activitypub_inbox_announce', array( 'Rest_Activitypub_Inbox', 'handle_reaction' ), 10, 2 );
|
|
||||||
add_action( 'activitypub_inbox_create', array( 'Rest_Activitypub_Inbox', 'handle_create' ), 10, 2 );
|
|
||||||
|
|
||||||
require_once dirname( __FILE__ ) . '/includes/class-rest-activitypub-followers.php';
|
require_once dirname( __FILE__ ) . '/includes/rest/class-followers.php';
|
||||||
add_action( 'rest_api_init', array( 'Rest_Activitypub_Followers', 'register_routes' ) );
|
\Activitypub\Rest\Followers::init();
|
||||||
|
|
||||||
require_once dirname( __FILE__ ) . '/includes/class-rest-activitypub-webfinger.php';
|
require_once dirname( __FILE__ ) . '/includes/rest/class-webfinger.php';
|
||||||
add_action( 'rest_api_init', array( 'Rest_Activitypub_Webfinger', 'register_routes' ) );
|
\Activitypub\Rest\Webfinger::init();
|
||||||
add_action( 'webfinger_user_data', array( 'Rest_Activitypub_Webfinger', 'add_webfinger_discovery' ), 10, 3 );
|
|
||||||
|
|
||||||
require_once dirname( __FILE__ ) . '/includes/class-rest-activitypub-nodeinfo.php';
|
require_once dirname( __FILE__ ) . '/includes/rest/class-nodeinfo.php';
|
||||||
add_action( 'rest_api_init', array( 'Rest_Activitypub_Nodeinfo', 'register_routes' ) );
|
\Activitypub\Rest\NodeInfo::init();
|
||||||
add_filter( 'nodeinfo_data', array( 'Rest_Activitypub_Nodeinfo', 'add_nodeinfo_discovery' ), 10, 2 );
|
|
||||||
add_filter( 'nodeinfo2_data', array( 'Rest_Activitypub_Nodeinfo', 'add_nodeinfo2_discovery' ), 10 );
|
|
||||||
|
|
||||||
add_post_type_support( 'post', 'activitypub' );
|
add_post_type_support( 'post', 'activitypub' );
|
||||||
add_post_type_support( 'page', 'activitypub' );
|
add_post_type_support( 'page', 'activitypub' );
|
||||||
|
|
||||||
$post_types = get_post_types_by_support( 'activitypub' );
|
$post_types = get_post_types_by_support( 'activitypub' );
|
||||||
add_action( 'transition_post_status', array( 'Activitypub', 'schedule_post_activity' ), 10, 3 );
|
add_action( 'transition_post_status', array( '\Activitypub\Activitypub', 'schedule_post_activity' ), 10, 3 );
|
||||||
|
|
||||||
require_once dirname( __FILE__ ) . '/includes/class-activitypub-admin.php';
|
require_once dirname( __FILE__ ) . '/includes/class-admin.php';
|
||||||
add_action( 'admin_menu', array( 'Activitypub_Admin', 'admin_menu' ) );
|
\Activitypub\Admin::init();
|
||||||
add_action( 'admin_init', array( 'Activitypub_Admin', 'register_settings' ) );
|
|
||||||
add_action( 'show_user_profile', array( 'Activitypub_Admin', 'add_fediverse_profile' ) );
|
|
||||||
|
|
||||||
if ( '1' === get_option( 'activitypub_use_hashtags', '1' ) ) {
|
if ( '1' === get_option( 'activitypub_use_hashtags', '1' ) ) {
|
||||||
require_once dirname( __FILE__ ) . '/includes/class-activitypub-hashtag.php';
|
require_once dirname( __FILE__ ) . '/includes/class-hashtag.php';
|
||||||
add_filter( 'wp_insert_post', array( 'Activitypub_Hashtag', 'insert_post' ), 99, 2 );
|
\Activitypub\Hashtag::init();
|
||||||
add_filter( 'the_content', array( 'Activitypub_Hashtag', 'the_content' ), 99, 2 );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
add_action( 'plugins_loaded', 'activitypub_init' );
|
add_action( 'plugins_loaded', '\Activitypub\init' );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add rewrite rules
|
* Add rewrite rules
|
||||||
*/
|
*/
|
||||||
function activitypub_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/1.0/webfinger', 'top' );
|
||||||
}
|
}
|
||||||
|
@ -92,14 +76,14 @@ function activitypub_add_rewrite_rules() {
|
||||||
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/1.0/nodeinfo2', 'top' );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
add_action( 'init', 'activitypub_add_rewrite_rules', 1 );
|
add_action( 'init', '\Activitypub\add_rewrite_rules', 1 );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Flush rewrite rules;
|
* Flush rewrite rules;
|
||||||
*/
|
*/
|
||||||
function activitypub_flush_rewrite_rules() {
|
function flush_rewrite_rules() {
|
||||||
activitypub_add_rewrite_rules();
|
\Activitypub\add_rewrite_rules();
|
||||||
flush_rewrite_rules();
|
flush_rewrite_rules();
|
||||||
}
|
}
|
||||||
register_activation_hook( __FILE__, 'activitypub_flush_rewrite_rules' );
|
register_activation_hook( __FILE__, '\Activitypub\flush_rewrite_rules' );
|
||||||
register_deactivation_hook( __FILE__, 'flush_rewrite_rules' );
|
register_deactivation_hook( __FILE__, '\flush_rewrite_rules' );
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
<?php
|
<?php
|
||||||
|
namespace Activitypub;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ActivityPub Post Class
|
* ActivityPub Post Class
|
||||||
*
|
*
|
||||||
* @author Matthias Pfefferle
|
* @author Matthias Pfefferle
|
||||||
*/
|
*/
|
||||||
class Activitypub_Activity {
|
class Activity {
|
||||||
private $context = array( 'https://www.w3.org/ns/activitystreams' );
|
private $context = array( 'https://www.w3.org/ns/activitystreams' );
|
||||||
private $published = '';
|
private $published = '';
|
||||||
private $id = '';
|
private $id = '';
|
||||||
|
@ -22,7 +24,7 @@ class Activitypub_Activity {
|
||||||
if ( 'none' === $context ) {
|
if ( 'none' === $context ) {
|
||||||
$this->context = null;
|
$this->context = null;
|
||||||
} elseif ( 'full' === $context ) {
|
} elseif ( 'full' === $context ) {
|
||||||
$this->context = get_activitypub_context();
|
$this->context = \Activitypub\get_context();
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->type = ucfirst( $type );
|
$this->type = ucfirst( $type );
|
|
@ -1,10 +1,18 @@
|
||||||
<?php
|
<?php
|
||||||
|
namespace Activitypub;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ActivityPub Class
|
* ActivityPub Class
|
||||||
*
|
*
|
||||||
* @author Matthias Pfefferle
|
* @author Matthias Pfefferle
|
||||||
*/
|
*/
|
||||||
class Activitypub {
|
class Activitypub {
|
||||||
|
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_action( 'init', array( '\Activitypub\Activitypub', 'add_rewrite_endpoint' ) );
|
||||||
|
add_filter( 'pre_get_avatar_data', array( '\Activitypub\Activitypub', 'pre_get_avatar_data' ), 11, 2 );
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Return a AS2 JSON version of an author, post or page
|
* Return a AS2 JSON version of an author, post or page
|
||||||
*
|
*
|
||||||
|
@ -93,9 +101,11 @@ class Activitypub {
|
||||||
* @return array $args
|
* @return array $args
|
||||||
*/
|
*/
|
||||||
public static function pre_get_avatar_data( $args, $id_or_email ) {
|
public static function pre_get_avatar_data( $args, $id_or_email ) {
|
||||||
if ( ! $id_or_email instanceof WP_Comment ||
|
if (
|
||||||
! isset( $id_or_email->comment_type ) ||
|
! $id_or_email instanceof \WP_Comment ||
|
||||||
$id_or_email->user_id ) {
|
! isset( $id_or_email->comment_type ) ||
|
||||||
|
$id_or_email->user_id
|
||||||
|
) {
|
||||||
return $args;
|
return $args;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,15 @@
|
||||||
<?php
|
<?php
|
||||||
|
namespace Activitypub;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ActivityPub Admin Class
|
* ActivityPub Admin Class
|
||||||
*/
|
*/
|
||||||
class Activitypub_Admin {
|
class Admin {
|
||||||
|
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 admin menu entry
|
* Add admin menu entry
|
||||||
*/
|
*/
|
||||||
|
@ -12,10 +19,10 @@ class Activitypub_Admin {
|
||||||
'ActivityPub',
|
'ActivityPub',
|
||||||
'manage_options',
|
'manage_options',
|
||||||
'activitypub',
|
'activitypub',
|
||||||
array( 'Activitypub_Admin', 'settings_page' )
|
array( '\Activitypub\Admin', 'settings_page' )
|
||||||
);
|
);
|
||||||
|
|
||||||
add_action( 'load-' . $settings_page, array( 'Activitypub_Admin', 'add_help_tab' ) );
|
add_action( 'load-' . $settings_page, array( '\Activitypub\Admin', 'add_help_tab' ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -90,9 +97,9 @@ class Activitypub_Admin {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function add_fediverse_profile( $user ) {
|
public static function add_fediverse_profile( $user ) {
|
||||||
?>
|
?>
|
||||||
<h2><?php esc_html_e( 'Fediverse', 'activitypub' ); ?></h2>
|
<h2><?php esc_html_e( 'Fediverse', 'activitypub' ); ?></h2>
|
||||||
<?php
|
<?php
|
||||||
activitypub_get_identifier_settings( $user->ID );
|
activitypub_get_identifier_settings( $user->ID );
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,8 +1,15 @@
|
||||||
<?php
|
<?php
|
||||||
|
namespace Activitypub;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ActivityPub Hashtag Class
|
* ActivityPub Hashtag Class
|
||||||
*/
|
*/
|
||||||
class Activitypub_Hashtag {
|
class Hashtag {
|
||||||
|
public static function init() {
|
||||||
|
add_filter( 'wp_insert_post', array( '\Activitypub\Hashtag', 'insert_post' ), 99, 2 );
|
||||||
|
add_filter( 'the_content', array( '\Activitypub\Hashtag', 'the_content' ), 99, 2 );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Filter to save #tags as real WordPress tags
|
* Filter to save #tags as real WordPress tags
|
||||||
*
|
*
|
||||||
|
@ -25,7 +32,7 @@ class Activitypub_Hashtag {
|
||||||
* @param string $the_content the post-content
|
* @param string $the_content the post-content
|
||||||
*/
|
*/
|
||||||
public static function the_content( $the_content ) {
|
public static function the_content( $the_content ) {
|
||||||
$the_content = preg_replace_callback( '/' . ACTIVITYPUB_HASHTAGS_REGEXP . '/i', array( 'Activitypub_Hashtag', 'replace_with_links' ), $the_content );
|
$the_content = preg_replace_callback( '/' . ACTIVITYPUB_HASHTAGS_REGEXP . '/i', array( '\Activitypub\Hashtag', 'replace_with_links' ), $the_content );
|
||||||
|
|
||||||
return $the_content;
|
return $the_content;
|
||||||
}
|
}
|
|
@ -1,12 +1,22 @@
|
||||||
<?php
|
<?php
|
||||||
|
namespace Activitypub;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ActivityPub Post Class
|
* ActivityPub Post Class
|
||||||
*
|
*
|
||||||
* @author Matthias Pfefferle
|
* @author Matthias Pfefferle
|
||||||
*/
|
*/
|
||||||
class Activitypub_Post {
|
class Post {
|
||||||
private $post;
|
private $post;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public static function init() {
|
||||||
|
add_filter( 'activitypub_the_summary', array( '\Activitypub\Post', 'add_backlink' ), 10, 2 );
|
||||||
|
add_filter( 'activitypub_the_content', array( '\Activitypub\Post', 'add_backlink' ), 10, 2 );
|
||||||
|
}
|
||||||
|
|
||||||
public function __construct( $post = null ) {
|
public function __construct( $post = null ) {
|
||||||
$this->post = get_post( $post );
|
$this->post = get_post( $post );
|
||||||
}
|
}
|
||||||
|
@ -65,7 +75,7 @@ class Activitypub_Post {
|
||||||
$max_images--;
|
$max_images--;
|
||||||
}
|
}
|
||||||
// then list any image attachments
|
// then list any image attachments
|
||||||
$query = new WP_Query(
|
$query = new \WP_Query(
|
||||||
array(
|
array(
|
||||||
'post_parent' => $id,
|
'post_parent' => $id,
|
||||||
'post_status' => 'inherit',
|
'post_status' => 'inherit',
|
||||||
|
@ -77,7 +87,7 @@ class Activitypub_Post {
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
foreach ( $query->get_posts() as $attachment ) {
|
foreach ( $query->get_posts() as $attachment ) {
|
||||||
if ( ! in_array( $attachment->ID, $image_ids ) ) {
|
if ( ! in_array( $attachment->ID, $image_ids, true ) ) {
|
||||||
$image_ids[] = $attachment->ID;
|
$image_ids[] = $attachment->ID;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -89,7 +99,7 @@ class Activitypub_Post {
|
||||||
if ( $thumbnail ) {
|
if ( $thumbnail ) {
|
||||||
$images[] = array(
|
$images[] = array(
|
||||||
'url' => $thumbnail[0],
|
'url' => $thumbnail[0],
|
||||||
'type' => $mimetype
|
'type' => $mimetype,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -100,9 +110,9 @@ class Activitypub_Post {
|
||||||
if ( $images ) {
|
if ( $images ) {
|
||||||
foreach ( $images as $image ) {
|
foreach ( $images as $image ) {
|
||||||
$attachment = array(
|
$attachment = array(
|
||||||
"type" => "Image",
|
'type' => 'Image',
|
||||||
"url" => $image['url'],
|
'url' => $image['url'],
|
||||||
"mediaType" => $image['type'],
|
'mediaType' => $image['type'],
|
||||||
);
|
);
|
||||||
$attachments[] = $attachment;
|
$attachments[] = $attachment;
|
||||||
}
|
}
|
||||||
|
@ -118,9 +128,9 @@ class Activitypub_Post {
|
||||||
if ( $post_tags ) {
|
if ( $post_tags ) {
|
||||||
foreach( $post_tags as $post_tag ) {
|
foreach( $post_tags as $post_tag ) {
|
||||||
$tag = array(
|
$tag = array(
|
||||||
"type" => "Hashtag",
|
'type' => 'Hashtag',
|
||||||
"href" => get_tag_link( $post_tag->term_id ),
|
'href' => get_tag_link( $post_tag->term_id ),
|
||||||
"name" => '#' . $post_tag->slug,
|
'name' => '#' . $post_tag->slug,
|
||||||
);
|
);
|
||||||
$tags[] = $tag;
|
$tags[] = $tag;
|
||||||
}
|
}
|
||||||
|
@ -266,7 +276,7 @@ class Activitypub_Post {
|
||||||
|
|
||||||
$allowed_html = apply_filters( 'activitypub_allowed_html', '<a><p>' );
|
$allowed_html = apply_filters( 'activitypub_allowed_html', '<a><p>' );
|
||||||
|
|
||||||
return trim( preg_replace( '/[\r\n]{2,}/', '', strip_tags( $decoded_content, $allowed_html) ) );
|
return trim( preg_replace( '/[\r\n]{2,}/', '', strip_tags( $decoded_content, $allowed_html ) ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -286,7 +296,7 @@ class Activitypub_Post {
|
||||||
|
|
||||||
$allowed_html = apply_filters( 'activitypub_allowed_html', '<a><p>' );
|
$allowed_html = apply_filters( 'activitypub_allowed_html', '<a><p>' );
|
||||||
|
|
||||||
return trim( preg_replace( '/[\r\n]{2,}/', '', strip_tags( $decoded_summary, $allowed_html) ) );
|
return trim( preg_replace( '/[\r\n]{2,}/', '', strip_tags( $decoded_summary, $allowed_html ) ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function add_backlink( $content, $post ) {
|
public static function add_backlink( $content, $post ) {
|
|
@ -1,6 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
|
namespace Activitypub;
|
||||||
|
|
||||||
class Activitypub_Signature {
|
class Signature {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param int $user_id
|
* @param int $user_id
|
|
@ -1,6 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
|
namespace Activitypub\Db;
|
||||||
|
|
||||||
class Db_Activitypub_Followers {
|
class Followers {
|
||||||
|
|
||||||
public static function get_followers( $author_id ) {
|
public static function get_followers( $author_id ) {
|
||||||
$followers = get_user_option( 'activitypub_followers', $author_id );
|
$followers = get_user_option( 'activitypub_followers', $author_id );
|
||||||
|
@ -17,7 +18,7 @@ class Db_Activitypub_Followers {
|
||||||
isset( $follower['id'] ) &&
|
isset( $follower['id'] ) &&
|
||||||
false !== filter_var( $follower['id'], FILTER_VALIDATE_URL )
|
false !== filter_var( $follower['id'], FILTER_VALIDATE_URL )
|
||||||
) {
|
) {
|
||||||
$followers[$key] = $follower['id'];
|
$followers[ $key ] = $follower['id'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,8 +39,8 @@ class Db_Activitypub_Followers {
|
||||||
$actor = $actor['id'];
|
$actor = $actor['id'];
|
||||||
}
|
}
|
||||||
|
|
||||||
return new WP_Error( 'invalid_actor_object', __( 'Unknown Actor schema', 'activitypub' ), array(
|
return new \WP_Error( 'invalid_actor_object', __( 'Unknown Actor schema', 'activitypub' ), array(
|
||||||
'status' => 404
|
'status' => 404,
|
||||||
) );
|
) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,8 +59,8 @@ class Db_Activitypub_Followers {
|
||||||
$followers = get_user_option( 'activitypub_followers', $author_id );
|
$followers = get_user_option( 'activitypub_followers', $author_id );
|
||||||
|
|
||||||
foreach ( $followers as $key => $value ) {
|
foreach ( $followers as $key => $value ) {
|
||||||
if ( $value === $actor) {
|
if ( $value === $actor ) {
|
||||||
unset( $followers[$key] );
|
unset( $followers[ $key ] );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
<?php
|
<?php
|
||||||
|
namespace Activitypub;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the ActivityPub default JSON-context
|
* Returns the ActivityPub default JSON-context
|
||||||
*
|
*
|
||||||
* @return array the activitypub context
|
* @return array the activitypub context
|
||||||
*/
|
*/
|
||||||
function get_activitypub_context() {
|
function get_context() {
|
||||||
$context = array(
|
$context = array(
|
||||||
'https://www.w3.org/ns/activitystreams',
|
'https://www.w3.org/ns/activitystreams',
|
||||||
'https://w3id.org/security/v1',
|
'https://w3id.org/security/v1',
|
||||||
|
@ -39,9 +41,9 @@ function get_activitypub_context() {
|
||||||
return apply_filters( 'activitypub_json_context', $context );
|
return apply_filters( 'activitypub_json_context', $context );
|
||||||
}
|
}
|
||||||
|
|
||||||
function activitypub_safe_remote_post( $url, $body, $user_id ) {
|
function safe_remote_post( $url, $body, $user_id ) {
|
||||||
$date = gmdate( 'D, d M Y H:i:s T' );
|
$date = gmdate( 'D, d M Y H:i:s T' );
|
||||||
$signature = Activitypub_Signature::generate_signature( $user_id, $url, $date );
|
$signature = \Activitypub\Signature::generate_signature( $user_id, $url, $date );
|
||||||
|
|
||||||
$wp_version = get_bloginfo( 'version' );
|
$wp_version = get_bloginfo( 'version' );
|
||||||
$user_agent = apply_filters( 'http_headers_useragent', 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' ) );
|
$user_agent = apply_filters( 'http_headers_useragent', 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' ) );
|
||||||
|
@ -69,10 +71,10 @@ function activitypub_safe_remote_post( $url, $body, $user_id ) {
|
||||||
*
|
*
|
||||||
* @return string The user-resource
|
* @return string The user-resource
|
||||||
*/
|
*/
|
||||||
function activitypub_get_webfinger_resource( $user_id ) {
|
function get_webfinger_resource( $user_id ) {
|
||||||
// use WebFinger plugin if installed
|
// use WebFinger plugin if installed
|
||||||
if ( function_exists( 'get_webfinger_resource' ) ) {
|
if ( function_exists( '\get_webfinger_resource' ) ) {
|
||||||
return get_webfinger_resource( $user_id, false );
|
return \get_webfinger_resource( $user_id, false );
|
||||||
}
|
}
|
||||||
|
|
||||||
$user = get_user_by( 'id', $user_id );
|
$user = get_user_by( 'id', $user_id );
|
||||||
|
@ -86,7 +88,7 @@ function activitypub_get_webfinger_resource( $user_id ) {
|
||||||
* @param [type] $actor [description]
|
* @param [type] $actor [description]
|
||||||
* @return [type] [description]
|
* @return [type] [description]
|
||||||
*/
|
*/
|
||||||
function activitypub_get_remote_metadata_by_actor( $actor ) {
|
function get_remote_metadata_by_actor( $actor ) {
|
||||||
$metadata = get_transient( 'activitypub_' . $actor );
|
$metadata = get_transient( 'activitypub_' . $actor );
|
||||||
|
|
||||||
if ( $metadata ) {
|
if ( $metadata ) {
|
||||||
|
@ -94,7 +96,7 @@ function activitypub_get_remote_metadata_by_actor( $actor ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ! wp_http_validate_url( $actor ) ) {
|
if ( ! wp_http_validate_url( $actor ) ) {
|
||||||
return new WP_Error( 'activitypub_no_valid_actor_url', __( 'The "actor" is no valid URL', 'activitypub' ), $actor );
|
return new \WP_Error( 'activitypub_no_valid_actor_url', __( 'The "actor" is no valid URL', 'activitypub' ), $actor );
|
||||||
}
|
}
|
||||||
|
|
||||||
$wp_version = get_bloginfo( 'version' );
|
$wp_version = get_bloginfo( 'version' );
|
||||||
|
@ -118,7 +120,7 @@ function activitypub_get_remote_metadata_by_actor( $actor ) {
|
||||||
$metadata = json_decode( $metadata, true );
|
$metadata = json_decode( $metadata, true );
|
||||||
|
|
||||||
if ( ! $metadata ) {
|
if ( ! $metadata ) {
|
||||||
return new WP_Error( 'activitypub_invalid_json', __( 'No valid JSON data', 'activitypub' ), $actor );
|
return new \WP_Error( 'activitypub_invalid_json', __( 'No valid JSON data', 'activitypub' ), $actor );
|
||||||
}
|
}
|
||||||
|
|
||||||
set_transient( 'activitypub_' . $actor, $metadata, WEEK_IN_SECONDS );
|
set_transient( 'activitypub_' . $actor, $metadata, WEEK_IN_SECONDS );
|
||||||
|
@ -131,8 +133,8 @@ function activitypub_get_remote_metadata_by_actor( $actor ) {
|
||||||
* @param [type] $actor [description]
|
* @param [type] $actor [description]
|
||||||
* @return [type] [description]
|
* @return [type] [description]
|
||||||
*/
|
*/
|
||||||
function activitypub_get_inbox_by_actor( $actor ) {
|
function get_inbox_by_actor( $actor ) {
|
||||||
$metadata = activitypub_get_remote_metadata_by_actor( $actor );
|
$metadata = get_remote_metadata_by_actor( $actor );
|
||||||
|
|
||||||
if ( is_wp_error( $metadata ) ) {
|
if ( is_wp_error( $metadata ) ) {
|
||||||
return $metadata;
|
return $metadata;
|
||||||
|
@ -146,7 +148,7 @@ function activitypub_get_inbox_by_actor( $actor ) {
|
||||||
return $metadata['inbox'];
|
return $metadata['inbox'];
|
||||||
}
|
}
|
||||||
|
|
||||||
return new WP_Error( 'activitypub_no_inbox', __( 'No "Inbox" found', 'activitypub' ), $metadata );
|
return new \WP_Error( 'activitypub_no_inbox', __( 'No "Inbox" found', 'activitypub' ), $metadata );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -154,8 +156,8 @@ function activitypub_get_inbox_by_actor( $actor ) {
|
||||||
* @param [type] $actor [description]
|
* @param [type] $actor [description]
|
||||||
* @return [type] [description]
|
* @return [type] [description]
|
||||||
*/
|
*/
|
||||||
function activitypub_get_publickey_by_actor( $actor, $key_id ) {
|
function get_publickey_by_actor( $actor, $key_id ) {
|
||||||
$metadata = activitypub_get_remote_metadata_by_actor( $actor );
|
$metadata = get_remote_metadata_by_actor( $actor );
|
||||||
|
|
||||||
if ( is_wp_error( $metadata ) ) {
|
if ( is_wp_error( $metadata ) ) {
|
||||||
return $metadata;
|
return $metadata;
|
||||||
|
@ -172,19 +174,19 @@ function activitypub_get_publickey_by_actor( $actor, $key_id ) {
|
||||||
return $metadata['publicKey']['publicKeyPem'];
|
return $metadata['publicKey']['publicKeyPem'];
|
||||||
}
|
}
|
||||||
|
|
||||||
return new WP_Error( 'activitypub_no_public_key', __( 'No "Public-Key" found', 'activitypub' ), $metadata );
|
return new \WP_Error( 'activitypub_no_public_key', __( 'No "Public-Key" found', 'activitypub' ), $metadata );
|
||||||
}
|
}
|
||||||
|
|
||||||
function activitypub_get_follower_inboxes( $user_id, $followers ) {
|
function get_follower_inboxes( $user_id, $followers ) {
|
||||||
$inboxes = array();
|
$inboxes = array();
|
||||||
foreach ( $followers as $follower ) {
|
foreach ( $followers as $follower ) {
|
||||||
$inboxes[] = activitypub_get_inbox_by_actor( $follower );
|
$inboxes[] = \Activitypub\get_inbox_by_actor( $follower );
|
||||||
}
|
}
|
||||||
|
|
||||||
return array_unique( $inboxes );
|
return array_unique( $inboxes );
|
||||||
}
|
}
|
||||||
|
|
||||||
function activitypub_get_identifier_settings( $user_id ) {
|
function get_identifier_settings( $user_id ) {
|
||||||
?>
|
?>
|
||||||
<table class="form-table">
|
<table class="form-table">
|
||||||
<tbody>
|
<tbody>
|
||||||
|
@ -193,8 +195,8 @@ function activitypub_get_identifier_settings( $user_id ) {
|
||||||
<label><?php esc_html_e( 'Profile identifier', 'activitypub' ); ?></label>
|
<label><?php esc_html_e( 'Profile identifier', 'activitypub' ); ?></label>
|
||||||
</th>
|
</th>
|
||||||
<td>
|
<td>
|
||||||
<p><code><?php echo activitypub_get_webfinger_resource( $user_id ); ?></code> or <code><?php echo get_author_posts_url( $user_id ); ?></code></p>
|
<p><code><?php echo \Activitypub\get_webfinger_resource( $user_id ); ?></code> or <code><?php echo get_author_posts_url( $user_id ); ?></code></p>
|
||||||
<p class="description"><?php printf( __( 'Try to follow "@%s" in the mastodon/friendi.ca search field.', 'activitypub' ), activitypub_get_webfinger_resource( $user_id ) ); ?></p>
|
<p class="description"><?php printf( __( 'Try to follow "@%s" in the mastodon/friendi.ca search field.', 'activitypub' ), \Activitypub\get_webfinger_resource( $user_id ) ); ?></p>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
|
@ -202,8 +204,8 @@ function activitypub_get_identifier_settings( $user_id ) {
|
||||||
<?php
|
<?php
|
||||||
}
|
}
|
||||||
|
|
||||||
function activitypub_get_followers( $user_id ) {
|
function get_followers( $user_id ) {
|
||||||
$followers = Db_Activitypub_Followers::get_followers( $user_id );
|
$followers = \Activitypub\Db\Followers::get_followers( $user_id );
|
||||||
|
|
||||||
if ( ! $followers ) {
|
if ( ! $followers ) {
|
||||||
return array();
|
return array();
|
||||||
|
@ -212,8 +214,8 @@ function activitypub_get_followers( $user_id ) {
|
||||||
return $followers;
|
return $followers;
|
||||||
}
|
}
|
||||||
|
|
||||||
function activitypub_count_followers( $user_id ) {
|
function count_followers( $user_id ) {
|
||||||
$followers = activitypub_get_followers( $user_id );
|
$followers = \Activitypub\get_followers( $user_id );
|
||||||
|
|
||||||
return count( $followers );
|
return count( $followers );
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,11 @@
|
||||||
<?php
|
<?php
|
||||||
|
namespace Activitypub\Rest;
|
||||||
|
|
||||||
|
class Followers {
|
||||||
|
public static function init() {
|
||||||
|
add_action( 'rest_api_init', array( '\Activitypub\Rest\Followers', 'register_routes' ) );
|
||||||
|
}
|
||||||
|
|
||||||
class Rest_Activitypub_Followers {
|
|
||||||
/**
|
/**
|
||||||
* Register routes
|
* Register routes
|
||||||
*/
|
*/
|
||||||
|
@ -8,8 +13,8 @@ class Rest_Activitypub_Followers {
|
||||||
register_rest_route(
|
register_rest_route(
|
||||||
'activitypub/1.0', '/users/(?P<id>\d+)/followers', array(
|
'activitypub/1.0', '/users/(?P<id>\d+)/followers', array(
|
||||||
array(
|
array(
|
||||||
'methods' => WP_REST_Server::READABLE,
|
'methods' => \WP_REST_Server::READABLE,
|
||||||
'callback' => array( 'Rest_Activitypub_Followers', 'get' ),
|
'callback' => array( '\Activitypub\Rest\Followers', 'get' ),
|
||||||
'args' => self::request_parameters(),
|
'args' => self::request_parameters(),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
@ -21,10 +26,11 @@ class Rest_Activitypub_Followers {
|
||||||
$user = get_user_by( 'ID', $user_id );
|
$user = get_user_by( 'ID', $user_id );
|
||||||
|
|
||||||
if ( ! $user ) {
|
if ( ! $user ) {
|
||||||
return new WP_Error( 'rest_invalid_param', __( 'User not found', 'activitypub' ), array(
|
return new \WP_Error( 'rest_invalid_param', __( 'User not found', 'activitypub' ), array(
|
||||||
'status' => 404, 'params' => array(
|
'status' => 404,
|
||||||
'user_id' => __( 'User not found', 'activitypub' )
|
'params' => array(
|
||||||
)
|
'user_id' => __( 'User not found', 'activitypub' ),
|
||||||
|
),
|
||||||
) );
|
) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,20 +41,20 @@ class Rest_Activitypub_Followers {
|
||||||
*/
|
*/
|
||||||
do_action( 'activitypub_outbox_pre' );
|
do_action( 'activitypub_outbox_pre' );
|
||||||
|
|
||||||
$json = new stdClass();
|
$json = new \stdClass();
|
||||||
|
|
||||||
$json->{'@context'} = get_activitypub_context();
|
$json->{'@context'} = get_activitypub_context();
|
||||||
|
|
||||||
$followers = Db_Activitypub_Followers::get_followers( $user_id );
|
$followers = \Activitypub\Db\Followers::get_followers( $user_id );
|
||||||
|
|
||||||
if ( ! is_array( $followers ) ) {
|
if ( ! is_array( $followers ) ) {
|
||||||
$followers = array();
|
$followers = array();
|
||||||
}
|
}
|
||||||
|
|
||||||
$json->totlaItems = count( $followers );
|
$json->totlaItems = count( $followers ); // phpcs:ignore
|
||||||
$json->orderedItems = $followers;
|
$json->orderedItems = $followers; // phpcs:ignore
|
||||||
|
|
||||||
$response = new WP_REST_Response( $json, 200 );
|
$response = new \WP_REST_Response( $json, 200 );
|
||||||
$response->header( 'Content-Type', 'application/activity+json' );
|
$response->header( 'Content-Type', 'application/activity+json' );
|
||||||
|
|
||||||
return $response;
|
return $response;
|
|
@ -1,10 +1,21 @@
|
||||||
<?php
|
<?php
|
||||||
|
namespace Activitypub\Rest;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ActivityPub Inbox Class
|
* ActivityPub Inbox Class
|
||||||
*
|
*
|
||||||
* @author Matthias Pfefferle
|
* @author Matthias Pfefferle
|
||||||
*/
|
*/
|
||||||
class Rest_Activitypub_Inbox {
|
class Inbox {
|
||||||
|
public static function init() {
|
||||||
|
add_action( 'rest_api_init', array( '\Activitypub\Rest\Inbox', 'register_routes' ) );
|
||||||
|
//add_filter( 'rest_pre_serve_request', array( '\Activitypub\Rest\Inbox', 'serve_request' ), 11, 4 );
|
||||||
|
add_action( 'activitypub_inbox_follow', array( '\Activitypub\Rest\Inbox', 'handle_follow' ), 10, 2 );
|
||||||
|
add_action( 'activitypub_inbox_unfollow', array( '\Activitypub\Rest\Inbox', 'handle_unfollow' ), 10, 2 );
|
||||||
|
//add_action( 'activitypub_inbox_like', array( '\Activitypub\Rest\Inbox', 'handle_reaction' ), 10, 2 );
|
||||||
|
//add_action( 'activitypub_inbox_announce', array( '\Activitypub\Rest\Inbox', 'handle_reaction' ), 10, 2 );
|
||||||
|
add_action( 'activitypub_inbox_create', array( '\Activitypub\Rest\Inbox', 'handle_create' ), 10, 2 );
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Register routes
|
* Register routes
|
||||||
*/
|
*/
|
||||||
|
@ -12,8 +23,8 @@ class Rest_Activitypub_Inbox {
|
||||||
register_rest_route(
|
register_rest_route(
|
||||||
'activitypub/1.0', '/inbox', array(
|
'activitypub/1.0', '/inbox', array(
|
||||||
array(
|
array(
|
||||||
'methods' => WP_REST_Server::EDITABLE,
|
'methods' => \WP_REST_Server::EDITABLE,
|
||||||
'callback' => array( 'Rest_Activitypub_Inbox', 'global_inbox' ),
|
'callback' => array( '\Activitypub\Rest\Inbox', 'global_inbox' ),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
@ -21,8 +32,8 @@ class Rest_Activitypub_Inbox {
|
||||||
register_rest_route(
|
register_rest_route(
|
||||||
'activitypub/1.0', '/users/(?P<id>\d+)/inbox', array(
|
'activitypub/1.0', '/users/(?P<id>\d+)/inbox', array(
|
||||||
array(
|
array(
|
||||||
'methods' => WP_REST_Server::EDITABLE,
|
'methods' => \WP_REST_Server::EDITABLE,
|
||||||
'callback' => array( 'Rest_Activitypub_Inbox', 'user_inbox' ),
|
'callback' => array( '\Activitypub\Rest\Inbox', 'user_inbox' ),
|
||||||
'args' => self::request_parameters(),
|
'args' => self::request_parameters(),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
@ -56,7 +67,7 @@ class Rest_Activitypub_Inbox {
|
||||||
|
|
||||||
$headers = $request->get_headers();
|
$headers = $request->get_headers();
|
||||||
|
|
||||||
//Activitypub_Signature::verify_signature( $headers, $key );
|
//\Activitypub\Signature::verify_signature( $headers, $key );
|
||||||
|
|
||||||
return $served;
|
return $served;
|
||||||
}
|
}
|
||||||
|
@ -79,13 +90,13 @@ class Rest_Activitypub_Inbox {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ! is_array( $data ) || ! array_key_exists( 'type', $data ) ) {
|
if ( ! is_array( $data ) || ! array_key_exists( 'type', $data ) ) {
|
||||||
return new WP_Error( 'rest_invalid_data', __( 'Invalid payload', 'activitypub' ), array( 'status' => 422 ) );
|
return new \WP_Error( 'rest_invalid_data', __( 'Invalid payload', 'activitypub' ), array( 'status' => 422 ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
do_action( 'activitypub_inbox', $data, $author_id, $type );
|
do_action( 'activitypub_inbox', $data, $author_id, $type );
|
||||||
do_action( "activitypub_inbox_{$type}", $data, $author_id );
|
do_action( "activitypub_inbox_{$type}", $data, $author_id );
|
||||||
|
|
||||||
return new WP_REST_Response( array(), 202 );
|
return new \WP_REST_Response( array(), 202 );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -97,7 +108,7 @@ class Rest_Activitypub_Inbox {
|
||||||
*/
|
*/
|
||||||
public static function global_inbox( $request ) {
|
public static function global_inbox( $request ) {
|
||||||
// Create the response object
|
// Create the response object
|
||||||
return new WP_Error( 'rest_not_implemented', __( 'This method is not yet implemented', 'activitypub' ), array( 'status' => 501 ) );
|
return new \WP_Error( 'rest_not_implemented', __( 'This method is not yet implemented', 'activitypub' ), array( 'status' => 501 ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -128,24 +139,24 @@ class Rest_Activitypub_Inbox {
|
||||||
*/
|
*/
|
||||||
public static function handle_follow( $object, $user_id ) {
|
public static function handle_follow( $object, $user_id ) {
|
||||||
if ( ! array_key_exists( 'actor', $object ) ) {
|
if ( ! array_key_exists( 'actor', $object ) ) {
|
||||||
return new WP_Error( 'activitypub_no_actor', __( 'No "Actor" found', 'activitypub' ), $metadata );
|
return new \WP_Error( 'activitypub_no_actor', __( 'No "Actor" found', 'activitypub' ), $metadata );
|
||||||
}
|
}
|
||||||
|
|
||||||
// save follower
|
// save follower
|
||||||
Db_Activitypub_Followers::add_follower( $object['actor'], $user_id );
|
\Activitypub\Db\Followers::add_follower( $object['actor'], $user_id );
|
||||||
|
|
||||||
// get inbox
|
// get inbox
|
||||||
$inbox = activitypub_get_inbox_by_actor( $object['actor'] );
|
$inbox = \Activitypub\get_inbox_by_actor( $object['actor'] );
|
||||||
|
|
||||||
// send "Accept" activity
|
// send "Accept" activity
|
||||||
$activity = new Activitypub_Activity( 'Accept', Activitypub_Activity::TYPE_SIMPLE );
|
$activity = new \Activitypub\Activity( 'Accept', \Activitypub\Activity::TYPE_SIMPLE );
|
||||||
$activity->set_object( $object );
|
$activity->set_object( $object );
|
||||||
$activity->set_actor( get_author_posts_url( $user_id ) );
|
$activity->set_actor( get_author_posts_url( $user_id ) );
|
||||||
$activity->set_to( $object['actor'] );
|
$activity->set_to( $object['actor'] );
|
||||||
|
|
||||||
$activity = $activity->to_simple_json();
|
$activity = $activity->to_simple_json();
|
||||||
|
|
||||||
$response = activitypub_safe_remote_post( $inbox, $activity, $user_id );
|
$response = \Activitypub\safe_remote_post( $inbox, $activity, $user_id );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -156,10 +167,10 @@ class Rest_Activitypub_Inbox {
|
||||||
*/
|
*/
|
||||||
public static function handle_unfollow( $object, $user_id ) {
|
public static function handle_unfollow( $object, $user_id ) {
|
||||||
if ( ! array_key_exists( 'actor', $object ) ) {
|
if ( ! array_key_exists( 'actor', $object ) ) {
|
||||||
return new WP_Error( 'activitypub_no_actor', __( 'No "Actor" found', 'activitypub' ), $metadata );
|
return new \WP_Error( 'activitypub_no_actor', __( 'No "Actor" found', 'activitypub' ), $metadata );
|
||||||
}
|
}
|
||||||
|
|
||||||
Db_Activitypub_Followers::remove_follower( $object['actor'], $user_id );
|
\Activitypub\Db\Followers::remove_follower( $object['actor'], $user_id );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -170,10 +181,10 @@ class Rest_Activitypub_Inbox {
|
||||||
*/
|
*/
|
||||||
public static function handle_reaction( $object, $user_id ) {
|
public static function handle_reaction( $object, $user_id ) {
|
||||||
if ( ! array_key_exists( 'actor', $object ) ) {
|
if ( ! array_key_exists( 'actor', $object ) ) {
|
||||||
return new WP_Error( 'activitypub_no_actor', __( 'No "Actor" found', 'activitypub' ), $metadata );
|
return new \WP_Error( 'activitypub_no_actor', __( 'No "Actor" found', 'activitypub' ), $metadata );
|
||||||
}
|
}
|
||||||
|
|
||||||
$meta = activitypub_get_remote_metadata_by_actor( $object['actor'] );
|
$meta = \Activitypub\get_remote_metadata_by_actor( $object['actor'] );
|
||||||
|
|
||||||
$commentdata = array(
|
$commentdata = array(
|
||||||
'comment_post_ID' => url_to_postid( $object['object'] ),
|
'comment_post_ID' => url_to_postid( $object['object'] ),
|
||||||
|
@ -207,10 +218,10 @@ class Rest_Activitypub_Inbox {
|
||||||
*/
|
*/
|
||||||
public static function handle_create( $object, $user_id ) {
|
public static function handle_create( $object, $user_id ) {
|
||||||
if ( ! array_key_exists( 'actor', $object ) ) {
|
if ( ! array_key_exists( 'actor', $object ) ) {
|
||||||
return new WP_Error( 'activitypub_no_actor', __( 'No "Actor" found', 'activitypub' ), $metadata );
|
return new \WP_Error( 'activitypub_no_actor', __( 'No "Actor" found', 'activitypub' ), $metadata );
|
||||||
}
|
}
|
||||||
|
|
||||||
$meta = activitypub_get_remote_metadata_by_actor( $object['actor'] );
|
$meta = \Activitypub\get_remote_metadata_by_actor( $object['actor'] );
|
||||||
|
|
||||||
$commentdata = array(
|
$commentdata = array(
|
||||||
'comment_post_ID' => url_to_postid( $object['object']['inReplyTo'] ),
|
'comment_post_ID' => url_to_postid( $object['object']['inReplyTo'] ),
|
|
@ -1,6 +1,12 @@
|
||||||
<?php
|
<?php
|
||||||
|
namespace Activitypub\Rest;
|
||||||
|
|
||||||
class Rest_Activitypub_Nodeinfo {
|
class Nodeinfo {
|
||||||
|
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 );
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Register routes
|
* Register routes
|
||||||
*/
|
*/
|
||||||
|
@ -8,8 +14,8 @@ class Rest_Activitypub_Nodeinfo {
|
||||||
register_rest_route(
|
register_rest_route(
|
||||||
'activitypub/1.0', '/nodeinfo/discovery', array(
|
'activitypub/1.0', '/nodeinfo/discovery', array(
|
||||||
array(
|
array(
|
||||||
'methods' => WP_REST_Server::READABLE,
|
'methods' => \WP_REST_Server::READABLE,
|
||||||
'callback' => array( 'Rest_Activitypub_Nodeinfo', 'discovery' ),
|
'callback' => array( '\Activitypub\Rest\Nodeinfo', 'discovery' ),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
@ -17,8 +23,8 @@ class Rest_Activitypub_Nodeinfo {
|
||||||
register_rest_route(
|
register_rest_route(
|
||||||
'activitypub/1.0', '/nodeinfo', array(
|
'activitypub/1.0', '/nodeinfo', array(
|
||||||
array(
|
array(
|
||||||
'methods' => WP_REST_Server::READABLE,
|
'methods' => \WP_REST_Server::READABLE,
|
||||||
'callback' => array( 'Rest_Activitypub_Nodeinfo', 'nodeinfo' ),
|
'callback' => array( '\Activitypub\Rest\Nodeinfo', 'nodeinfo' ),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
@ -26,8 +32,8 @@ class Rest_Activitypub_Nodeinfo {
|
||||||
register_rest_route(
|
register_rest_route(
|
||||||
'activitypub/1.0', '/nodeinfo2', array(
|
'activitypub/1.0', '/nodeinfo2', array(
|
||||||
array(
|
array(
|
||||||
'methods' => WP_REST_Server::READABLE,
|
'methods' => \WP_REST_Server::READABLE,
|
||||||
'callback' => array( 'Rest_Activitypub_Nodeinfo', 'nodeinfo2' ),
|
'callback' => array( '\Activitypub\Rest\Nodeinfo', 'nodeinfo2' ),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
@ -37,6 +43,7 @@ class Rest_Activitypub_Nodeinfo {
|
||||||
* Render NodeInfo file
|
* Render NodeInfo file
|
||||||
*
|
*
|
||||||
* @param WP_REST_Request $request
|
* @param WP_REST_Request $request
|
||||||
|
*
|
||||||
* @return WP_REST_Response
|
* @return WP_REST_Response
|
||||||
*/
|
*/
|
||||||
public static function nodeinfo( $request ) {
|
public static function nodeinfo( $request ) {
|
||||||
|
@ -61,22 +68,23 @@ class Rest_Activitypub_Nodeinfo {
|
||||||
);
|
);
|
||||||
|
|
||||||
$nodeinfo['openRegistrations'] = false;
|
$nodeinfo['openRegistrations'] = false;
|
||||||
$nodeinfo['protocols'] = array('activitypub');
|
$nodeinfo['protocols'] = array( 'activitypub' );
|
||||||
|
|
||||||
$nodeinfo['services'] = array(
|
$nodeinfo['services'] = array(
|
||||||
'inbound' => array(),
|
'inbound' => array(),
|
||||||
'outbound' => array(),
|
'outbound' => array(),
|
||||||
);
|
);
|
||||||
|
|
||||||
$nodeinfo['metadata'] = new stdClass;
|
$nodeinfo['metadata'] = new \stdClass();
|
||||||
|
|
||||||
return new WP_REST_Response( $nodeinfo, 200 );
|
return new \WP_REST_Response( $nodeinfo, 200 );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Render NodeInfo file
|
* Render NodeInfo file
|
||||||
*
|
*
|
||||||
* @param WP_REST_Request $request
|
* @param WP_REST_Request $request
|
||||||
|
*
|
||||||
* @return WP_REST_Response
|
* @return WP_REST_Response
|
||||||
*/
|
*/
|
||||||
public static function nodeinfo2( $request ) {
|
public static function nodeinfo2( $request ) {
|
||||||
|
@ -103,22 +111,23 @@ class Rest_Activitypub_Nodeinfo {
|
||||||
);
|
);
|
||||||
|
|
||||||
$nodeinfo['openRegistrations'] = false;
|
$nodeinfo['openRegistrations'] = false;
|
||||||
$nodeinfo['protocols'] = array('activitypub');
|
$nodeinfo['protocols'] = array( 'activitypub' );
|
||||||
|
|
||||||
$nodeinfo['services'] = array(
|
$nodeinfo['services'] = array(
|
||||||
'inbound' => array(),
|
'inbound' => array(),
|
||||||
'outbound' => array(),
|
'outbound' => array(),
|
||||||
);
|
);
|
||||||
|
|
||||||
$nodeinfo['metadata'] = new stdClass;
|
$nodeinfo['metadata'] = new \stdClass();
|
||||||
|
|
||||||
return new WP_REST_Response( $nodeinfo, 200 );
|
return new \WP_REST_Response( $nodeinfo, 200 );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Render NodeInfo discovery file
|
* Render NodeInfo discovery file
|
||||||
*
|
*
|
||||||
* @param WP_REST_Request $request
|
* @param WP_REST_Request $request
|
||||||
|
*
|
||||||
* @return WP_REST_Response
|
* @return WP_REST_Response
|
||||||
*/
|
*/
|
||||||
public static function discovery( $request ) {
|
public static function discovery( $request ) {
|
||||||
|
@ -130,33 +139,38 @@ class Rest_Activitypub_Nodeinfo {
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
return new WP_REST_Response( $discovery, 200 );
|
return new \WP_REST_Response( $discovery, 200 );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extend NodeInfo data
|
* Extend NodeInfo data
|
||||||
*
|
*
|
||||||
* @param array $nodeinfo NodeInfo data
|
* @param array $nodeinfo NodeInfo data
|
||||||
* @param array updated data
|
* @param string The NodeInfo Version
|
||||||
|
*
|
||||||
|
* @return array The extended array
|
||||||
*/
|
*/
|
||||||
public static function add_nodeinfo_discovery( $nodeinfo, $version ) {
|
public static function add_nodeinfo_discovery( $nodeinfo, $version ) {
|
||||||
if ( '2.0' == $version) {
|
if ( '2.0' === $version ) {
|
||||||
$nodeinfo['protocols'][] = 'activitypub';
|
$nodeinfo['protocols'][] = 'activitypub';
|
||||||
} else {
|
} else {
|
||||||
$nodeinfo['protocols']['inbound'][] = 'activitypub';
|
$nodeinfo['protocols']['inbound'][] = 'activitypub';
|
||||||
$nodeinfo['protocols']['outbound'][] = 'activitypub';
|
$nodeinfo['protocols']['outbound'][] = 'activitypub';
|
||||||
}
|
}
|
||||||
|
|
||||||
return $nodeinfo;
|
return $nodeinfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extend NodeInfo2 data
|
* Extend NodeInfo2 data
|
||||||
*
|
*
|
||||||
* @param array $nodeinfo NodeInfo2 data
|
* @param array $nodeinfo NodeInfo2 data
|
||||||
* @param array updated data
|
*
|
||||||
|
* @return array The extended array
|
||||||
*/
|
*/
|
||||||
public static function add_nodeinfo2_discovery( $nodeinfo ) {
|
public static function add_nodeinfo2_discovery( $nodeinfo ) {
|
||||||
$nodeinfo['protocols'][] = 'activitypub';
|
$nodeinfo['protocols'][] = 'activitypub';
|
||||||
|
|
||||||
return $nodeinfo;
|
return $nodeinfo;
|
||||||
}
|
}
|
||||||
}
|
}
|
19
includes/rest/class-ostatus.php
Normal file
19
includes/rest/class-ostatus.php
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
<?php
|
||||||
|
namespace Activitypub\Rest;
|
||||||
|
|
||||||
|
class Ostatus {
|
||||||
|
/**
|
||||||
|
* Register routes
|
||||||
|
*/
|
||||||
|
public static function register_routes() {
|
||||||
|
register_rest_route(
|
||||||
|
'activitypub/1.0', '/ostatus/remote-follow', array(
|
||||||
|
array(
|
||||||
|
'methods' => \WP_REST_Server::READABLE,
|
||||||
|
'callback' => array( '\Activitypub\Rest\Ostatus', 'webfinger' ),
|
||||||
|
'args' => self::request_parameters(),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,10 +1,22 @@
|
||||||
<?php
|
<?php
|
||||||
|
namespace Activitypub\Rest;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ActivityPub Outbox Class
|
* ActivityPub Outbox Class
|
||||||
*
|
*
|
||||||
* @author Matthias Pfefferle
|
* @author Matthias Pfefferle
|
||||||
*/
|
*/
|
||||||
class Rest_Activitypub_Outbox {
|
class Outbox {
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function init() {
|
||||||
|
add_action( 'rest_api_init', array( '\Activitypub\Rest\Outbox', 'register_routes' ) );
|
||||||
|
add_action( 'activitypub_send_post_activity', array( '\Activitypub\Rest\Outbox', 'send_post_activity' ) );
|
||||||
|
add_action( 'activitypub_send_update_activity', array( '\Activitypub\Rest\Outbox', 'send_update_activity' ) );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register routes
|
* Register routes
|
||||||
|
@ -13,8 +25,8 @@ class Rest_Activitypub_Outbox {
|
||||||
register_rest_route(
|
register_rest_route(
|
||||||
'activitypub/1.0', '/users/(?P<id>\d+)/outbox', array(
|
'activitypub/1.0', '/users/(?P<id>\d+)/outbox', array(
|
||||||
array(
|
array(
|
||||||
'methods' => WP_REST_Server::READABLE,
|
'methods' => \WP_REST_Server::READABLE,
|
||||||
'callback' => array( 'Rest_Activitypub_Outbox', 'user_outbox' ),
|
'callback' => array( '\Activitypub\Rest\Outbox', 'user_outbox' ),
|
||||||
'args' => self::request_parameters(),
|
'args' => self::request_parameters(),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
@ -32,10 +44,11 @@ class Rest_Activitypub_Outbox {
|
||||||
$author = get_user_by( 'ID', $user_id );
|
$author = get_user_by( 'ID', $user_id );
|
||||||
|
|
||||||
if ( ! $author ) {
|
if ( ! $author ) {
|
||||||
return new WP_Error( 'rest_invalid_param', __( 'User not found', 'activitypub' ), array(
|
return new \WP_Error( 'rest_invalid_param', __( 'User not found', 'activitypub' ), array(
|
||||||
'status' => 404, 'params' => array(
|
'status' => 404,
|
||||||
'user_id' => __( 'User not found', 'activitypub' )
|
'params' => array(
|
||||||
)
|
'user_id' => __( 'User not found', 'activitypub' ),
|
||||||
|
),
|
||||||
) );
|
) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,17 +59,17 @@ class Rest_Activitypub_Outbox {
|
||||||
*/
|
*/
|
||||||
do_action( 'activitypub_outbox_pre' );
|
do_action( 'activitypub_outbox_pre' );
|
||||||
|
|
||||||
$json = new stdClass();
|
$json = new \stdClass();
|
||||||
|
|
||||||
$json->{'@context'} = get_activitypub_context();
|
$json->{'@context'} = \Activitypub\get_context();
|
||||||
$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->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, "/activitypub/1.0/users/$user_id/outbox" ); // phpcs:ignore
|
||||||
|
|
||||||
$count_posts = wp_count_posts();
|
$count_posts = wp_count_posts();
|
||||||
$json->totalItems = intval( $count_posts->publish );
|
$json->totalItems = intval( $count_posts->publish ); // phpcs:ignore
|
||||||
|
|
||||||
$posts = get_posts( array(
|
$posts = get_posts( array(
|
||||||
'posts_per_page' => 10,
|
'posts_per_page' => 10,
|
||||||
|
@ -64,16 +77,16 @@ class Rest_Activitypub_Outbox {
|
||||||
'offset' => $page * 10,
|
'offset' => $page * 10,
|
||||||
) );
|
) );
|
||||||
|
|
||||||
$json->first = add_query_arg( 'page', 0, $json->partOf );
|
$json->first = add_query_arg( 'page', 0, $json->partOf ); // phpcs:ignore
|
||||||
$json->last = add_query_arg( 'page', ( ceil ( $json->totalItems / 10 ) ) - 1, $json->partOf );
|
$json->last = add_query_arg( 'page', ( ceil ( $json->totalItems / 10 ) ) - 1, $json->partOf ); // phpcs:ignore
|
||||||
|
|
||||||
if ( ( ceil ( $json->totalItems / 10 ) ) - 1 > $page ) {
|
if ( ( ceil ( $json->totalItems / 10 ) ) - 1 > $page ) { // phpcs:ignore
|
||||||
$json->next = add_query_arg( 'page', ++$page, $json->partOf );
|
$json->next = add_query_arg( 'page', ++$page, $json->partOf ); // phpcs:ignore
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ( $posts as $post ) {
|
foreach ( $posts as $post ) {
|
||||||
$activitypub_post = new Activitypub_Post( $post );
|
$activitypub_post = new \Activitypub\Post( $post );
|
||||||
$activitypub_activity = new Activitypub_Activity( 'Create', Activitypub_Activity::TYPE_NONE );
|
$activitypub_activity = new \Activitypub\Activity( 'Create', \Activitypub\Activity::TYPE_NONE );
|
||||||
$activitypub_activity->from_post( $activitypub_post->to_array() );
|
$activitypub_activity->from_post( $activitypub_post->to_array() );
|
||||||
$json->orderedItems[] = $activitypub_activity->to_array(); // phpcs:ignore
|
$json->orderedItems[] = $activitypub_activity->to_array(); // phpcs:ignore
|
||||||
}
|
}
|
||||||
|
@ -86,7 +99,7 @@ class Rest_Activitypub_Outbox {
|
||||||
*/
|
*/
|
||||||
do_action( 'activitypub_outbox_post' );
|
do_action( 'activitypub_outbox_post' );
|
||||||
|
|
||||||
$response = new WP_REST_Response( $json, 200 );
|
$response = new \WP_REST_Response( $json, 200 );
|
||||||
|
|
||||||
$response->header( 'Content-Type', 'application/activity+json' );
|
$response->header( 'Content-Type', 'application/activity+json' );
|
||||||
|
|
||||||
|
@ -112,16 +125,16 @@ class Rest_Activitypub_Outbox {
|
||||||
$post = get_post( $post_id );
|
$post = get_post( $post_id );
|
||||||
$user_id = $post->post_author;
|
$user_id = $post->post_author;
|
||||||
|
|
||||||
$activitypub_post = new Activitypub_Post( $post );
|
$activitypub_post = new \Activitypub\Post( $post );
|
||||||
$activitypub_activity = new Activitypub_Activity( 'Create', Activitypub_Activity::TYPE_FULL );
|
$activitypub_activity = new \Activitypub\Activity( 'Create', \Activitypub\Activity::TYPE_FULL );
|
||||||
$activitypub_activity->from_post( $activitypub_post->to_array() );
|
$activitypub_activity->from_post( $activitypub_post->to_array() );
|
||||||
|
|
||||||
$activity = $activitypub_activity->to_json(); // phpcs:ignore
|
$activity = $activitypub_activity->to_json(); // phpcs:ignore
|
||||||
|
|
||||||
$followers = Db_Activitypub_Followers::get_followers( $user_id );
|
$followers = \Activitypub\Db\Followers::get_followers( $user_id );
|
||||||
|
|
||||||
foreach ( activitypub_get_follower_inboxes( $user_id, $followers ) as $inbox ) {
|
foreach ( \Activitypub\get_follower_inboxes( $user_id, $followers ) as $inbox ) {
|
||||||
$response = activitypub_safe_remote_post( $inbox, $activity, $user_id );
|
$response = \Activitypub\safe_remote_post( $inbox, $activity, $user_id );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,16 +142,16 @@ class Rest_Activitypub_Outbox {
|
||||||
$post = get_post( $post_id );
|
$post = get_post( $post_id );
|
||||||
$user_id = $post->post_author;
|
$user_id = $post->post_author;
|
||||||
|
|
||||||
$activitypub_post = new Activitypub_Post( $post );
|
$activitypub_post = new \Activitypub\Post( $post );
|
||||||
$activitypub_activity = new Activitypub_Activity( 'Update', Activitypub_Activity::TYPE_FULL );
|
$activitypub_activity = new \Activitypub\Activity( 'Update', \Activitypub\Activity::TYPE_FULL );
|
||||||
$activitypub_activity->from_post( $activitypub_post->to_array() );
|
$activitypub_activity->from_post( $activitypub_post->to_array() );
|
||||||
|
|
||||||
$activity = $activitypub_activity->to_json(); // phpcs:ignore
|
$activity = $activitypub_activity->to_json(); // phpcs:ignore
|
||||||
|
|
||||||
$followers = Db_Activitypub_Followers::get_followers( $user_id );
|
$followers = \Activitypub\Db\Followers::get_followers( $user_id );
|
||||||
|
|
||||||
foreach ( activitypub_get_follower_inboxes( $user_id, $followers ) as $inbox ) {
|
foreach ( \Activitypub\get_follower_inboxes( $user_id, $followers ) as $inbox ) {
|
||||||
$response = activitypub_safe_remote_post( $inbox, $activity, $user_id );
|
$response = \Activitypub\safe_remote_post( $inbox, $activity, $user_id );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,6 +1,11 @@
|
||||||
<?php
|
<?php
|
||||||
|
namespace Activitypub\Rest;
|
||||||
|
|
||||||
class Rest_Activitypub_Webfinger {
|
class Webfinger {
|
||||||
|
public static function init() {
|
||||||
|
add_action( 'rest_api_init', array( '\Activitypub\Rest\Webfinger', 'register_routes' ) );
|
||||||
|
add_action( 'webfinger_user_data', array( '\Activitypub\Rest\Webfinger', 'add_webfinger_discovery' ), 10, 3 );
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Register routes
|
* Register routes
|
||||||
*/
|
*/
|
||||||
|
@ -8,8 +13,8 @@ class Rest_Activitypub_Webfinger {
|
||||||
register_rest_route(
|
register_rest_route(
|
||||||
'activitypub/1.0', '/webfinger', array(
|
'activitypub/1.0', '/webfinger', array(
|
||||||
array(
|
array(
|
||||||
'methods' => WP_REST_Server::READABLE,
|
'methods' => \WP_REST_Server::READABLE,
|
||||||
'callback' => array( 'Rest_Activitypub_Webfinger', 'webfinger' ),
|
'callback' => array( '\Activitypub\Rest\Webfinger', 'webfinger' ),
|
||||||
'args' => self::request_parameters(),
|
'args' => self::request_parameters(),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
@ -29,20 +34,20 @@ class Rest_Activitypub_Webfinger {
|
||||||
$matched = preg_match( '/^acct:([^@]+)@(.+)$/', $resource, $matches );
|
$matched = preg_match( '/^acct:([^@]+)@(.+)$/', $resource, $matches );
|
||||||
|
|
||||||
if ( ! $matched ) {
|
if ( ! $matched ) {
|
||||||
return new WP_Error( 'activitypub_unsupported_resource', __( 'Resouce is invalid', 'activitypub' ), array( 'status' => 400 ) );
|
return new \WP_Error( 'activitypub_unsupported_resource', __( 'Resouce is invalid', 'activitypub' ), array( 'status' => 400 ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
$resource_identifier = $matches[1];
|
$resource_identifier = $matches[1];
|
||||||
$resource_host = $matches[2];
|
$resource_host = $matches[2];
|
||||||
|
|
||||||
if ( wp_parse_url( home_url( '/' ), PHP_URL_HOST ) !== $resource_host ) {
|
if ( wp_parse_url( home_url( '/' ), PHP_URL_HOST ) !== $resource_host ) {
|
||||||
return new WP_Error( 'activitypub_wrong_host', __( 'Resouce host does not match blog host', 'activitypub' ), array( 'status' => 404 ) );
|
return new \WP_Error( 'activitypub_wrong_host', __( 'Resouce host does not match blog host', 'activitypub' ), array( 'status' => 404 ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
$user = get_user_by( 'login', esc_sql( $resource_identifier ) );
|
$user = get_user_by( 'login', esc_sql( $resource_identifier ) );
|
||||||
|
|
||||||
if ( ! $user ) {
|
if ( ! $user ) {
|
||||||
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(
|
$json = array(
|
||||||
|
@ -64,7 +69,7 @@ class Rest_Activitypub_Webfinger {
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
return new WP_REST_Response( $json, 200 );
|
return new \WP_REST_Response( $json, 200 );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
|
@ -2,9 +2,9 @@
|
||||||
# This file is distributed under the MIT.
|
# This file is distributed under the MIT.
|
||||||
msgid ""
|
msgid ""
|
||||||
msgstr ""
|
msgstr ""
|
||||||
"Project-Id-Version: ActivityPub 0.4.3\n"
|
"Project-Id-Version: ActivityPub 0.5.0\n"
|
||||||
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/activitypub\n"
|
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/activitypub\n"
|
||||||
"POT-Creation-Date: 2019-02-20 20:05:05+00:00\n"
|
"POT-Creation-Date: 2019-02-24 11:06:41+00:00\n"
|
||||||
"MIME-Version: 1.0\n"
|
"MIME-Version: 1.0\n"
|
||||||
"Content-Type: text/plain; charset=utf-8\n"
|
"Content-Type: text/plain; charset=utf-8\n"
|
||||||
"Content-Transfer-Encoding: 8bit\n"
|
"Content-Transfer-Encoding: 8bit\n"
|
||||||
|
@ -13,24 +13,24 @@ msgstr ""
|
||||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||||
"X-Generator: grunt-wp-i18n1.0.2\n"
|
"X-Generator: grunt-wp-i18n1.0.2\n"
|
||||||
|
|
||||||
#: includes/class-activitypub-admin.php:35
|
#: includes/class-admin.php:42
|
||||||
msgid "Use summary or full content"
|
msgid "Use summary or full content"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: includes/class-activitypub-admin.php:47
|
#: includes/class-admin.php:54
|
||||||
msgid "The Activity-Object-Type"
|
msgid "The Activity-Object-Type"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: includes/class-activitypub-admin.php:59
|
#: includes/class-admin.php:66 includes/class-admin.php:73
|
||||||
#: includes/class-activitypub-admin.php:66 templates/settings-page.php:33
|
#: templates/settings-page.php:33
|
||||||
msgid "Use the Shortlink instead of the permalink"
|
msgid "Use the Shortlink instead of the permalink"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: includes/class-activitypub-admin.php:76
|
#: includes/class-admin.php:83
|
||||||
msgid "Overview"
|
msgid "Overview"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: includes/class-activitypub-admin.php:78
|
#: includes/class-admin.php:85
|
||||||
msgid ""
|
msgid ""
|
||||||
"ActivityPub is a decentralized social networking protocol based on the "
|
"ActivityPub is a decentralized social networking protocol based on the "
|
||||||
"ActivityStreams 2.0 data format. ActivityPub is an official W3C recommended "
|
"ActivityStreams 2.0 data format. ActivityPub is an official W3C recommended "
|
||||||
|
@ -40,91 +40,87 @@ msgid ""
|
||||||
"subscribing to content."
|
"subscribing to content."
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: includes/class-activitypub-admin.php:83
|
#: includes/class-admin.php:90
|
||||||
msgid "For more information:"
|
msgid "For more information:"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: includes/class-activitypub-admin.php:84
|
#: includes/class-admin.php:91
|
||||||
msgid "<a href=\"https://activitypub.rocks/\">Test Suite</a>"
|
msgid "<a href=\"https://activitypub.rocks/\">Test Suite</a>"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: includes/class-activitypub-admin.php:85
|
#: includes/class-admin.php:92
|
||||||
msgid "<a href=\"https://www.w3.org/TR/activitypub/\">W3C Spec</a>"
|
msgid "<a href=\"https://www.w3.org/TR/activitypub/\">W3C Spec</a>"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: includes/class-activitypub-admin.php:86
|
#: includes/class-admin.php:93
|
||||||
msgid ""
|
msgid ""
|
||||||
"<a href=\"https://github.com/pfefferle/wordpress-activitypub/issues\">Give "
|
"<a href=\"https://github.com/pfefferle/wordpress-activitypub/issues\">Give "
|
||||||
"us feedback</a>"
|
"us feedback</a>"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: includes/class-activitypub-admin.php:88
|
#: includes/class-admin.php:95
|
||||||
msgid "<a href=\"https://notiz.blog/donate\">Donate</a>"
|
msgid "<a href=\"https://notiz.blog/donate\">Donate</a>"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: includes/class-activitypub-admin.php:94
|
#: includes/class-admin.php:101
|
||||||
msgid "Fediverse"
|
msgid "Fediverse"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: includes/class-db-activitypub-followers.php:41
|
#: includes/db/class-followers.php:42
|
||||||
msgid "Unknown Actor schema"
|
msgid "Unknown Actor schema"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: includes/class-rest-activitypub-followers.php:24
|
#: includes/functions.php:99
|
||||||
#: includes/class-rest-activitypub-followers.php:26
|
|
||||||
#: includes/class-rest-activitypub-outbox.php:35
|
|
||||||
#: includes/class-rest-activitypub-outbox.php:37
|
|
||||||
#: includes/class-rest-activitypub-webfinger.php:45
|
|
||||||
msgid "User not found"
|
|
||||||
msgstr ""
|
|
||||||
|
|
||||||
#: includes/class-rest-activitypub-inbox.php:82
|
|
||||||
msgid "Invalid payload"
|
|
||||||
msgstr ""
|
|
||||||
|
|
||||||
#: includes/class-rest-activitypub-inbox.php:100
|
|
||||||
msgid "This method is not yet implemented"
|
|
||||||
msgstr ""
|
|
||||||
|
|
||||||
#: includes/class-rest-activitypub-inbox.php:131
|
|
||||||
#: includes/class-rest-activitypub-inbox.php:159
|
|
||||||
#: includes/class-rest-activitypub-inbox.php:173
|
|
||||||
#: includes/class-rest-activitypub-inbox.php:210
|
|
||||||
msgid "No \"Actor\" found"
|
|
||||||
msgstr ""
|
|
||||||
|
|
||||||
#: includes/class-rest-activitypub-webfinger.php:32
|
|
||||||
msgid "Resouce is invalid"
|
|
||||||
msgstr ""
|
|
||||||
|
|
||||||
#: includes/class-rest-activitypub-webfinger.php:39
|
|
||||||
msgid "Resouce host does not match blog host"
|
|
||||||
msgstr ""
|
|
||||||
|
|
||||||
#: includes/functions.php:97
|
|
||||||
msgid "The \"actor\" is no valid URL"
|
msgid "The \"actor\" is no valid URL"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: includes/functions.php:121
|
#: includes/functions.php:123
|
||||||
msgid "No valid JSON data"
|
msgid "No valid JSON data"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: includes/functions.php:149
|
#: includes/functions.php:151
|
||||||
msgid "No \"Inbox\" found"
|
msgid "No \"Inbox\" found"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: includes/functions.php:175
|
#: includes/functions.php:177
|
||||||
msgid "No \"Public-Key\" found"
|
msgid "No \"Public-Key\" found"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: includes/functions.php:193
|
#: includes/functions.php:195
|
||||||
msgid "Profile identifier"
|
msgid "Profile identifier"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: includes/functions.php:197
|
#: includes/functions.php:199
|
||||||
msgid "Try to follow \"@%s\" in the mastodon/friendi.ca search field."
|
msgid "Try to follow \"@%s\" in the mastodon/friendi.ca search field."
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
#: includes/rest/class-followers.php:29 includes/rest/class-followers.php:32
|
||||||
|
#: includes/rest/class-outbox.php:47 includes/rest/class-outbox.php:50
|
||||||
|
#: includes/rest/class-webfinger.php:50
|
||||||
|
msgid "User not found"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#: includes/rest/class-inbox.php:93
|
||||||
|
msgid "Invalid payload"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#: includes/rest/class-inbox.php:111
|
||||||
|
msgid "This method is not yet implemented"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#: includes/rest/class-inbox.php:142 includes/rest/class-inbox.php:170
|
||||||
|
#: includes/rest/class-inbox.php:184 includes/rest/class-inbox.php:221
|
||||||
|
msgid "No \"Actor\" found"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#: includes/rest/class-webfinger.php:37
|
||||||
|
msgid "Resouce is invalid"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#: includes/rest/class-webfinger.php:44
|
||||||
|
msgid "Resouce host does not match blog host"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
#: templates/json-author.php:49
|
#: templates/json-author.php:49
|
||||||
msgid "Blog"
|
msgid "Blog"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
|
@ -4,7 +4,7 @@ Donate link: https://notiz.blog/donate/
|
||||||
Tags: OStatus, fediverse, activitypub, activitystream
|
Tags: OStatus, fediverse, activitypub, activitystream
|
||||||
Requires at least: 4.7
|
Requires at least: 4.7
|
||||||
Tested up to: 5.1
|
Tested up to: 5.1
|
||||||
Stable tag: 0.4.4
|
Stable tag: 0.5.0
|
||||||
Requires PHP: 5.6
|
Requires PHP: 5.6
|
||||||
License: MIT
|
License: MIT
|
||||||
License URI: http://opensource.org/licenses/MIT
|
License URI: http://opensource.org/licenses/MIT
|
||||||
|
|
|
@ -3,7 +3,7 @@ $author_id = get_the_author_meta( 'ID' );
|
||||||
|
|
||||||
$json = new stdClass();
|
$json = new stdClass();
|
||||||
|
|
||||||
$json->{'@context'} = get_activitypub_context();
|
$json->{'@context'} = \Activitypub\get_context();
|
||||||
$json->id = get_author_posts_url( $author_id );
|
$json->id = get_author_posts_url( $author_id );
|
||||||
$json->type = 'Person';
|
$json->type = 'Person';
|
||||||
$json->name = get_the_author_meta( 'display_name', $author_id );
|
$json->name = get_the_author_meta( 'display_name', $author_id );
|
||||||
|
@ -38,7 +38,7 @@ $json->manuallyApprovesFollowers = apply_filters( 'activitypub_json_manually_app
|
||||||
$json->publicKey = array(
|
$json->publicKey = array(
|
||||||
'id' => get_author_posts_url( $author_id ) . '#main-key',
|
'id' => get_author_posts_url( $author_id ) . '#main-key',
|
||||||
'owner' => get_author_posts_url( $author_id ),
|
'owner' => get_author_posts_url( $author_id ),
|
||||||
'publicKeyPem' => trim( Activitypub_Signature::get_public_key( $author_id ) ),
|
'publicKeyPem' => trim( \Activitypub\Signature::get_public_key( $author_id ) ),
|
||||||
);
|
);
|
||||||
|
|
||||||
$json->tag = array();
|
$json->tag = array();
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
<?php
|
<?php
|
||||||
$post = get_post();
|
$post = get_post();
|
||||||
|
|
||||||
$activitypub_post = new Activitypub_Post( $post );
|
$activitypub_post = new \Activitypub\Post( $post );
|
||||||
$activitypub_activity = new Activitypub_Activity( 'Create', Activitypub_Activity::TYPE_FULL );
|
$activitypub_activity = new \Activitypub\Activity( 'Create', \Activitypub\Activity::TYPE_FULL );
|
||||||
$activitypub_activity->from_post( $activitypub_post->to_array() );
|
$activitypub_activity->from_post( $activitypub_post->to_array() );
|
||||||
|
|
||||||
// filter output
|
// filter output
|
||||||
|
|
|
@ -80,7 +80,7 @@
|
||||||
|
|
||||||
<p><?php esc_html_e( 'All profile related settings.', 'activitypub' ); ?></p>
|
<p><?php esc_html_e( 'All profile related settings.', 'activitypub' ); ?></p>
|
||||||
|
|
||||||
<?php activitypub_get_identifier_settings( get_current_user_id() ); ?>
|
<?php \Activitypub\get_identifier_settings( get_current_user_id() ); ?>
|
||||||
|
|
||||||
<?php do_settings_fields( 'activitypub', 'profile' ); ?>
|
<?php do_settings_fields( 'activitypub', 'profile' ); ?>
|
||||||
|
|
||||||
|
@ -95,9 +95,9 @@
|
||||||
<label><?php esc_html_e( 'List of followers', 'activitypub' ); ?></label>
|
<label><?php esc_html_e( 'List of followers', 'activitypub' ); ?></label>
|
||||||
</th>
|
</th>
|
||||||
<td>
|
<td>
|
||||||
<?php if ( Db_Activitypub_Followers::get_followers( get_current_user_id() ) ) { ?>
|
<?php if ( \Activitypub\Db\Followers::get_followers( get_current_user_id() ) ) { ?>
|
||||||
<ul>
|
<ul>
|
||||||
<?php foreach( Db_Activitypub_Followers::get_followers( get_current_user_id() ) as $follower ) { ?>
|
<?php foreach( \Activitypub\Db\Followers::get_followers( get_current_user_id() ) as $follower ) { ?>
|
||||||
<li><?php echo esc_attr( $follower ); ?></li>
|
<li><?php echo esc_attr( $follower ); ?></li>
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
|
@ -9,7 +9,7 @@ class Test_Db_Activitypub_Followers extends WP_UnitTestCase {
|
||||||
);
|
);
|
||||||
update_user_meta( 1, 'activitypub_followers', $followers );
|
update_user_meta( 1, 'activitypub_followers', $followers );
|
||||||
|
|
||||||
$db_followers = Db_Activitypub_Followers::get_followers( 1 );
|
$db_followers = \Activitypub\Db\Followers::get_followers( 1 );
|
||||||
|
|
||||||
$this->assertEquals( 3, count( $db_followers ) );
|
$this->assertEquals( 3, count( $db_followers ) );
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue