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
|
||||
composer.lock
|
||||
.DS_Store
|
||||
.idea/
|
||||
|
|
2
LICENSE
2
LICENSE
|
@ -1,6 +1,6 @@
|
|||
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
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
**Tags:** OStatus, fediverse, activitypub, activitystream
|
||||
**Requires at least:** 4.7
|
||||
**Tested up to:** 5.1
|
||||
**Stable tag:** 0.4.4
|
||||
**Stable tag:** 0.5.0
|
||||
**Requires PHP:** 5.6
|
||||
**License:** MIT
|
||||
**License URI:** http://opensource.org/licenses/MIT
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
* Plugin Name: ActivityPub
|
||||
* Plugin URI: https://github.com/pfefferle/wordpress-activitypub/
|
||||
* Description: The ActivityPub protocol is a decentralized social networking protocol based upon the ActivityStreams 2.0 data format.
|
||||
* Version: 0.4.4
|
||||
* Version: 0.5.0
|
||||
* Author: Matthias Pfefferle
|
||||
* Author URI: https://notiz.blog/
|
||||
* License: MIT
|
||||
|
@ -12,77 +12,61 @@
|
|||
* 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' );
|
||||
|
||||
require_once dirname( __FILE__ ) . '/includes/class-activitypub-signature.php';
|
||||
require_once dirname( __FILE__ ) . '/includes/class-activitypub-activity.php';
|
||||
require_once dirname( __FILE__ ) . '/includes/class-db-activitypub-followers.php';
|
||||
require_once dirname( __FILE__ ) . '/includes/class-signature.php';
|
||||
require_once dirname( __FILE__ ) . '/includes/class-activity.php';
|
||||
require_once dirname( __FILE__ ) . '/includes/db/class-followers.php';
|
||||
require_once dirname( __FILE__ ) . '/includes/functions.php';
|
||||
|
||||
require_once dirname( __FILE__ ) . '/includes/class-activitypub-post.php';
|
||||
add_filter( 'activitypub_the_summary', array( 'Activitypub_Post', 'add_backlink' ), 10, 2 );
|
||||
add_filter( 'activitypub_the_content', array( 'Activitypub_Post', 'add_backlink' ), 10, 2 );
|
||||
require_once dirname( __FILE__ ) . '/includes/class-post.php';
|
||||
\Activitypub\Post::init();
|
||||
|
||||
require_once dirname( __FILE__ ) . '/includes/class-activitypub.php';
|
||||
add_filter( 'template_include', array( 'Activitypub', 'render_json_template' ), 99 );
|
||||
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 );
|
||||
\Activitypub\ActivityPub::init();
|
||||
|
||||
// Configure the REST API route
|
||||
require_once dirname( __FILE__ ) . '/includes/class-rest-activitypub-outbox.php';
|
||||
add_action( 'rest_api_init', array( 'Rest_Activitypub_Outbox', 'register_routes' ) );
|
||||
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/rest/class-outbox.php';
|
||||
\Activitypub\Rest\Outbox::init();
|
||||
|
||||
require_once dirname( __FILE__ ) . '/includes/class-rest-activitypub-inbox.php';
|
||||
add_action( 'rest_api_init', array( 'Rest_Activitypub_Inbox', 'register_routes' ) );
|
||||
//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/rest/class-inbox.php';
|
||||
\Activitypub\Rest\Inbox::init();
|
||||
|
||||
require_once dirname( __FILE__ ) . '/includes/class-rest-activitypub-followers.php';
|
||||
add_action( 'rest_api_init', array( 'Rest_Activitypub_Followers', 'register_routes' ) );
|
||||
require_once dirname( __FILE__ ) . '/includes/rest/class-followers.php';
|
||||
\Activitypub\Rest\Followers::init();
|
||||
|
||||
require_once dirname( __FILE__ ) . '/includes/class-rest-activitypub-webfinger.php';
|
||||
add_action( 'rest_api_init', array( 'Rest_Activitypub_Webfinger', 'register_routes' ) );
|
||||
add_action( 'webfinger_user_data', array( 'Rest_Activitypub_Webfinger', 'add_webfinger_discovery' ), 10, 3 );
|
||||
require_once dirname( __FILE__ ) . '/includes/rest/class-webfinger.php';
|
||||
\Activitypub\Rest\Webfinger::init();
|
||||
|
||||
require_once dirname( __FILE__ ) . '/includes/class-rest-activitypub-nodeinfo.php';
|
||||
add_action( 'rest_api_init', array( 'Rest_Activitypub_Nodeinfo', 'register_routes' ) );
|
||||
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 );
|
||||
require_once dirname( __FILE__ ) . '/includes/rest/class-nodeinfo.php';
|
||||
\Activitypub\Rest\NodeInfo::init();
|
||||
|
||||
add_post_type_support( 'post', 'activitypub' );
|
||||
add_post_type_support( 'page', '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';
|
||||
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' ) );
|
||||
require_once dirname( __FILE__ ) . '/includes/class-admin.php';
|
||||
\Activitypub\Admin::init();
|
||||
|
||||
if ( '1' === get_option( 'activitypub_use_hashtags', '1' ) ) {
|
||||
require_once dirname( __FILE__ ) . '/includes/class-activitypub-hashtag.php';
|
||||
add_filter( 'wp_insert_post', array( 'Activitypub_Hashtag', 'insert_post' ), 99, 2 );
|
||||
add_filter( 'the_content', array( 'Activitypub_Hashtag', 'the_content' ), 99, 2 );
|
||||
require_once dirname( __FILE__ ) . '/includes/class-hashtag.php';
|
||||
\Activitypub\Hashtag::init();
|
||||
}
|
||||
}
|
||||
add_action( 'plugins_loaded', 'activitypub_init' );
|
||||
add_action( 'plugins_loaded', '\Activitypub\init' );
|
||||
|
||||
/**
|
||||
* Add rewrite rules
|
||||
*/
|
||||
function activitypub_add_rewrite_rules() {
|
||||
function add_rewrite_rules() {
|
||||
if ( ! class_exists( 'Webfinger' ) ) {
|
||||
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_action( 'init', 'activitypub_add_rewrite_rules', 1 );
|
||||
add_action( 'init', '\Activitypub\add_rewrite_rules', 1 );
|
||||
|
||||
/**
|
||||
* Flush rewrite rules;
|
||||
*/
|
||||
function activitypub_flush_rewrite_rules() {
|
||||
activitypub_add_rewrite_rules();
|
||||
function flush_rewrite_rules() {
|
||||
\Activitypub\add_rewrite_rules();
|
||||
flush_rewrite_rules();
|
||||
}
|
||||
register_activation_hook( __FILE__, 'activitypub_flush_rewrite_rules' );
|
||||
register_deactivation_hook( __FILE__, 'flush_rewrite_rules' );
|
||||
register_activation_hook( __FILE__, '\Activitypub\flush_rewrite_rules' );
|
||||
register_deactivation_hook( __FILE__, '\flush_rewrite_rules' );
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
<?php
|
||||
namespace Activitypub;
|
||||
|
||||
/**
|
||||
* ActivityPub Post Class
|
||||
*
|
||||
* @author Matthias Pfefferle
|
||||
*/
|
||||
class Activitypub_Activity {
|
||||
class Activity {
|
||||
private $context = array( 'https://www.w3.org/ns/activitystreams' );
|
||||
private $published = '';
|
||||
private $id = '';
|
||||
|
@ -22,7 +24,7 @@ class Activitypub_Activity {
|
|||
if ( 'none' === $context ) {
|
||||
$this->context = null;
|
||||
} elseif ( 'full' === $context ) {
|
||||
$this->context = get_activitypub_context();
|
||||
$this->context = \Activitypub\get_context();
|
||||
}
|
||||
|
||||
$this->type = ucfirst( $type );
|
|
@ -1,10 +1,18 @@
|
|||
<?php
|
||||
namespace Activitypub;
|
||||
|
||||
/**
|
||||
* ActivityPub Class
|
||||
*
|
||||
* @author Matthias Pfefferle
|
||||
*/
|
||||
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
|
||||
*
|
||||
|
@ -93,9 +101,11 @@ class Activitypub {
|
|||
* @return array $args
|
||||
*/
|
||||
public static function pre_get_avatar_data( $args, $id_or_email ) {
|
||||
if ( ! $id_or_email instanceof WP_Comment ||
|
||||
if (
|
||||
! $id_or_email instanceof \WP_Comment ||
|
||||
! isset( $id_or_email->comment_type ) ||
|
||||
$id_or_email->user_id ) {
|
||||
$id_or_email->user_id
|
||||
) {
|
||||
return $args;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,8 +1,15 @@
|
|||
<?php
|
||||
namespace Activitypub;
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
|
@ -12,10 +19,10 @@ class Activitypub_Admin {
|
|||
'ActivityPub',
|
||||
'manage_options',
|
||||
'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' ) );
|
||||
}
|
||||
|
||||
/**
|
|
@ -1,8 +1,15 @@
|
|||
<?php
|
||||
namespace Activitypub;
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
|
@ -25,7 +32,7 @@ class Activitypub_Hashtag {
|
|||
* @param string $the_content the post-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;
|
||||
}
|
|
@ -1,12 +1,22 @@
|
|||
<?php
|
||||
namespace Activitypub;
|
||||
|
||||
/**
|
||||
* ActivityPub Post Class
|
||||
*
|
||||
* @author Matthias Pfefferle
|
||||
*/
|
||||
class Activitypub_Post {
|
||||
class 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 ) {
|
||||
$this->post = get_post( $post );
|
||||
}
|
||||
|
@ -65,7 +75,7 @@ class Activitypub_Post {
|
|||
$max_images--;
|
||||
}
|
||||
// then list any image attachments
|
||||
$query = new WP_Query(
|
||||
$query = new \WP_Query(
|
||||
array(
|
||||
'post_parent' => $id,
|
||||
'post_status' => 'inherit',
|
||||
|
@ -77,7 +87,7 @@ class Activitypub_Post {
|
|||
)
|
||||
);
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -89,7 +99,7 @@ class Activitypub_Post {
|
|||
if ( $thumbnail ) {
|
||||
$images[] = array(
|
||||
'url' => $thumbnail[0],
|
||||
'type' => $mimetype
|
||||
'type' => $mimetype,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -100,9 +110,9 @@ class Activitypub_Post {
|
|||
if ( $images ) {
|
||||
foreach ( $images as $image ) {
|
||||
$attachment = array(
|
||||
"type" => "Image",
|
||||
"url" => $image['url'],
|
||||
"mediaType" => $image['type'],
|
||||
'type' => 'Image',
|
||||
'url' => $image['url'],
|
||||
'mediaType' => $image['type'],
|
||||
);
|
||||
$attachments[] = $attachment;
|
||||
}
|
||||
|
@ -118,9 +128,9 @@ class Activitypub_Post {
|
|||
if ( $post_tags ) {
|
||||
foreach( $post_tags as $post_tag ) {
|
||||
$tag = array(
|
||||
"type" => "Hashtag",
|
||||
"href" => get_tag_link( $post_tag->term_id ),
|
||||
"name" => '#' . $post_tag->slug,
|
||||
'type' => 'Hashtag',
|
||||
'href' => get_tag_link( $post_tag->term_id ),
|
||||
'name' => '#' . $post_tag->slug,
|
||||
);
|
||||
$tags[] = $tag;
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
<?php
|
||||
namespace Activitypub;
|
||||
|
||||
class Activitypub_Signature {
|
||||
class Signature {
|
||||
|
||||
/**
|
||||
* @param int $user_id
|
|
@ -1,6 +1,7 @@
|
|||
<?php
|
||||
namespace Activitypub\Db;
|
||||
|
||||
class Db_Activitypub_Followers {
|
||||
class Followers {
|
||||
|
||||
public static function get_followers( $author_id ) {
|
||||
$followers = get_user_option( 'activitypub_followers', $author_id );
|
||||
|
@ -38,8 +39,8 @@ class Db_Activitypub_Followers {
|
|||
$actor = $actor['id'];
|
||||
}
|
||||
|
||||
return new WP_Error( 'invalid_actor_object', __( 'Unknown Actor schema', 'activitypub' ), array(
|
||||
'status' => 404
|
||||
return new \WP_Error( 'invalid_actor_object', __( 'Unknown Actor schema', 'activitypub' ), array(
|
||||
'status' => 404,
|
||||
) );
|
||||
}
|
||||
|
|
@ -1,10 +1,12 @@
|
|||
<?php
|
||||
namespace Activitypub;
|
||||
|
||||
/**
|
||||
* Returns the ActivityPub default JSON-context
|
||||
*
|
||||
* @return array the activitypub context
|
||||
*/
|
||||
function get_activitypub_context() {
|
||||
function get_context() {
|
||||
$context = array(
|
||||
'https://www.w3.org/ns/activitystreams',
|
||||
'https://w3id.org/security/v1',
|
||||
|
@ -39,9 +41,9 @@ function get_activitypub_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' );
|
||||
$signature = Activitypub_Signature::generate_signature( $user_id, $url, $date );
|
||||
$signature = \Activitypub\Signature::generate_signature( $user_id, $url, $date );
|
||||
|
||||
$wp_version = get_bloginfo( 'version' );
|
||||
$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
|
||||
*/
|
||||
function activitypub_get_webfinger_resource( $user_id ) {
|
||||
function get_webfinger_resource( $user_id ) {
|
||||
// use WebFinger plugin if installed
|
||||
if ( function_exists( 'get_webfinger_resource' ) ) {
|
||||
return get_webfinger_resource( $user_id, false );
|
||||
if ( function_exists( '\get_webfinger_resource' ) ) {
|
||||
return \get_webfinger_resource( $user_id, false );
|
||||
}
|
||||
|
||||
$user = get_user_by( 'id', $user_id );
|
||||
|
@ -86,7 +88,7 @@ function activitypub_get_webfinger_resource( $user_id ) {
|
|||
* @param [type] $actor [description]
|
||||
* @return [type] [description]
|
||||
*/
|
||||
function activitypub_get_remote_metadata_by_actor( $actor ) {
|
||||
function get_remote_metadata_by_actor( $actor ) {
|
||||
$metadata = get_transient( 'activitypub_' . $actor );
|
||||
|
||||
if ( $metadata ) {
|
||||
|
@ -94,7 +96,7 @@ function activitypub_get_remote_metadata_by_actor( $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' );
|
||||
|
@ -118,7 +120,7 @@ function activitypub_get_remote_metadata_by_actor( $actor ) {
|
|||
$metadata = json_decode( $metadata, true );
|
||||
|
||||
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 );
|
||||
|
@ -131,8 +133,8 @@ function activitypub_get_remote_metadata_by_actor( $actor ) {
|
|||
* @param [type] $actor [description]
|
||||
* @return [type] [description]
|
||||
*/
|
||||
function activitypub_get_inbox_by_actor( $actor ) {
|
||||
$metadata = activitypub_get_remote_metadata_by_actor( $actor );
|
||||
function get_inbox_by_actor( $actor ) {
|
||||
$metadata = get_remote_metadata_by_actor( $actor );
|
||||
|
||||
if ( is_wp_error( $metadata ) ) {
|
||||
return $metadata;
|
||||
|
@ -146,7 +148,7 @@ function activitypub_get_inbox_by_actor( $actor ) {
|
|||
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]
|
||||
* @return [type] [description]
|
||||
*/
|
||||
function activitypub_get_publickey_by_actor( $actor, $key_id ) {
|
||||
$metadata = activitypub_get_remote_metadata_by_actor( $actor );
|
||||
function get_publickey_by_actor( $actor, $key_id ) {
|
||||
$metadata = get_remote_metadata_by_actor( $actor );
|
||||
|
||||
if ( is_wp_error( $metadata ) ) {
|
||||
return $metadata;
|
||||
|
@ -172,19 +174,19 @@ function activitypub_get_publickey_by_actor( $actor, $key_id ) {
|
|||
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();
|
||||
foreach ( $followers as $follower ) {
|
||||
$inboxes[] = activitypub_get_inbox_by_actor( $follower );
|
||||
$inboxes[] = \Activitypub\get_inbox_by_actor( $follower );
|
||||
}
|
||||
|
||||
return array_unique( $inboxes );
|
||||
}
|
||||
|
||||
function activitypub_get_identifier_settings( $user_id ) {
|
||||
function get_identifier_settings( $user_id ) {
|
||||
?>
|
||||
<table class="form-table">
|
||||
<tbody>
|
||||
|
@ -193,8 +195,8 @@ function activitypub_get_identifier_settings( $user_id ) {
|
|||
<label><?php esc_html_e( 'Profile identifier', 'activitypub' ); ?></label>
|
||||
</th>
|
||||
<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 class="description"><?php printf( __( 'Try to follow "@%s" in the mastodon/friendi.ca search field.', 'activitypub' ), activitypub_get_webfinger_resource( $user_id ) ); ?></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>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
@ -202,8 +204,8 @@ function activitypub_get_identifier_settings( $user_id ) {
|
|||
<?php
|
||||
}
|
||||
|
||||
function activitypub_get_followers( $user_id ) {
|
||||
$followers = Db_Activitypub_Followers::get_followers( $user_id );
|
||||
function get_followers( $user_id ) {
|
||||
$followers = \Activitypub\Db\Followers::get_followers( $user_id );
|
||||
|
||||
if ( ! $followers ) {
|
||||
return array();
|
||||
|
@ -212,8 +214,8 @@ function activitypub_get_followers( $user_id ) {
|
|||
return $followers;
|
||||
}
|
||||
|
||||
function activitypub_count_followers( $user_id ) {
|
||||
$followers = activitypub_get_followers( $user_id );
|
||||
function count_followers( $user_id ) {
|
||||
$followers = \Activitypub\get_followers( $user_id );
|
||||
|
||||
return count( $followers );
|
||||
}
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
<?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
|
||||
*/
|
||||
|
@ -8,8 +13,8 @@ class Rest_Activitypub_Followers {
|
|||
register_rest_route(
|
||||
'activitypub/1.0', '/users/(?P<id>\d+)/followers', array(
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( 'Rest_Activitypub_Followers', 'get' ),
|
||||
'methods' => \WP_REST_Server::READABLE,
|
||||
'callback' => array( '\Activitypub\Rest\Followers', 'get' ),
|
||||
'args' => self::request_parameters(),
|
||||
),
|
||||
)
|
||||
|
@ -21,10 +26,11 @@ class Rest_Activitypub_Followers {
|
|||
$user = get_user_by( 'ID', $user_id );
|
||||
|
||||
if ( ! $user ) {
|
||||
return new WP_Error( 'rest_invalid_param', __( 'User not found', 'activitypub' ), array(
|
||||
'status' => 404, 'params' => array(
|
||||
'user_id' => __( 'User not found', 'activitypub' )
|
||||
)
|
||||
return new \WP_Error( 'rest_invalid_param', __( 'User not found', 'activitypub' ), array(
|
||||
'status' => 404,
|
||||
'params' => array(
|
||||
'user_id' => __( 'User not found', 'activitypub' ),
|
||||
),
|
||||
) );
|
||||
}
|
||||
|
||||
|
@ -35,20 +41,20 @@ class Rest_Activitypub_Followers {
|
|||
*/
|
||||
do_action( 'activitypub_outbox_pre' );
|
||||
|
||||
$json = new stdClass();
|
||||
$json = new \stdClass();
|
||||
|
||||
$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 ) ) {
|
||||
$followers = array();
|
||||
}
|
||||
|
||||
$json->totlaItems = count( $followers );
|
||||
$json->orderedItems = $followers;
|
||||
$json->totlaItems = count( $followers ); // phpcs:ignore
|
||||
$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' );
|
||||
|
||||
return $response;
|
|
@ -1,10 +1,21 @@
|
|||
<?php
|
||||
namespace Activitypub\Rest;
|
||||
|
||||
/**
|
||||
* ActivityPub Inbox Class
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
|
@ -12,8 +23,8 @@ class Rest_Activitypub_Inbox {
|
|||
register_rest_route(
|
||||
'activitypub/1.0', '/inbox', array(
|
||||
array(
|
||||
'methods' => WP_REST_Server::EDITABLE,
|
||||
'callback' => array( 'Rest_Activitypub_Inbox', 'global_inbox' ),
|
||||
'methods' => \WP_REST_Server::EDITABLE,
|
||||
'callback' => array( '\Activitypub\Rest\Inbox', 'global_inbox' ),
|
||||
),
|
||||
)
|
||||
);
|
||||
|
@ -21,8 +32,8 @@ class Rest_Activitypub_Inbox {
|
|||
register_rest_route(
|
||||
'activitypub/1.0', '/users/(?P<id>\d+)/inbox', array(
|
||||
array(
|
||||
'methods' => WP_REST_Server::EDITABLE,
|
||||
'callback' => array( 'Rest_Activitypub_Inbox', 'user_inbox' ),
|
||||
'methods' => \WP_REST_Server::EDITABLE,
|
||||
'callback' => array( '\Activitypub\Rest\Inbox', 'user_inbox' ),
|
||||
'args' => self::request_parameters(),
|
||||
),
|
||||
)
|
||||
|
@ -56,7 +67,7 @@ class Rest_Activitypub_Inbox {
|
|||
|
||||
$headers = $request->get_headers();
|
||||
|
||||
//Activitypub_Signature::verify_signature( $headers, $key );
|
||||
//\Activitypub\Signature::verify_signature( $headers, $key );
|
||||
|
||||
return $served;
|
||||
}
|
||||
|
@ -79,13 +90,13 @@ class Rest_Activitypub_Inbox {
|
|||
}
|
||||
|
||||
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_{$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 ) {
|
||||
// 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 ) {
|
||||
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
|
||||
Db_Activitypub_Followers::add_follower( $object['actor'], $user_id );
|
||||
\Activitypub\Db\Followers::add_follower( $object['actor'], $user_id );
|
||||
|
||||
// get inbox
|
||||
$inbox = activitypub_get_inbox_by_actor( $object['actor'] );
|
||||
$inbox = \Activitypub\get_inbox_by_actor( $object['actor'] );
|
||||
|
||||
// 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_actor( get_author_posts_url( $user_id ) );
|
||||
$activity->set_to( $object['actor'] );
|
||||
|
||||
$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 ) {
|
||||
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 ) {
|
||||
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(
|
||||
'comment_post_ID' => url_to_postid( $object['object'] ),
|
||||
|
@ -207,10 +218,10 @@ class Rest_Activitypub_Inbox {
|
|||
*/
|
||||
public static function handle_create( $object, $user_id ) {
|
||||
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(
|
||||
'comment_post_ID' => url_to_postid( $object['object']['inReplyTo'] ),
|
|
@ -1,6 +1,12 @@
|
|||
<?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
|
||||
*/
|
||||
|
@ -8,8 +14,8 @@ class Rest_Activitypub_Nodeinfo {
|
|||
register_rest_route(
|
||||
'activitypub/1.0', '/nodeinfo/discovery', array(
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( 'Rest_Activitypub_Nodeinfo', 'discovery' ),
|
||||
'methods' => \WP_REST_Server::READABLE,
|
||||
'callback' => array( '\Activitypub\Rest\Nodeinfo', 'discovery' ),
|
||||
),
|
||||
)
|
||||
);
|
||||
|
@ -17,8 +23,8 @@ class Rest_Activitypub_Nodeinfo {
|
|||
register_rest_route(
|
||||
'activitypub/1.0', '/nodeinfo', array(
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( 'Rest_Activitypub_Nodeinfo', 'nodeinfo' ),
|
||||
'methods' => \WP_REST_Server::READABLE,
|
||||
'callback' => array( '\Activitypub\Rest\Nodeinfo', 'nodeinfo' ),
|
||||
),
|
||||
)
|
||||
);
|
||||
|
@ -26,8 +32,8 @@ class Rest_Activitypub_Nodeinfo {
|
|||
register_rest_route(
|
||||
'activitypub/1.0', '/nodeinfo2', array(
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( 'Rest_Activitypub_Nodeinfo', 'nodeinfo2' ),
|
||||
'methods' => \WP_REST_Server::READABLE,
|
||||
'callback' => array( '\Activitypub\Rest\Nodeinfo', 'nodeinfo2' ),
|
||||
),
|
||||
)
|
||||
);
|
||||
|
@ -37,6 +43,7 @@ class Rest_Activitypub_Nodeinfo {
|
|||
* Render NodeInfo file
|
||||
*
|
||||
* @param WP_REST_Request $request
|
||||
*
|
||||
* @return WP_REST_Response
|
||||
*/
|
||||
public static function nodeinfo( $request ) {
|
||||
|
@ -68,15 +75,16 @@ class Rest_Activitypub_Nodeinfo {
|
|||
'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
|
||||
*
|
||||
* @param WP_REST_Request $request
|
||||
*
|
||||
* @return WP_REST_Response
|
||||
*/
|
||||
public static function nodeinfo2( $request ) {
|
||||
|
@ -110,15 +118,16 @@ class Rest_Activitypub_Nodeinfo {
|
|||
'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
|
||||
*
|
||||
* @param WP_REST_Request $request
|
||||
*
|
||||
* @return WP_REST_Response
|
||||
*/
|
||||
public static function discovery( $request ) {
|
||||
|
@ -130,22 +139,25 @@ class Rest_Activitypub_Nodeinfo {
|
|||
),
|
||||
);
|
||||
|
||||
return new WP_REST_Response( $discovery, 200 );
|
||||
return new \WP_REST_Response( $discovery, 200 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Extend 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 ) {
|
||||
if ( '2.0' == $version) {
|
||||
if ( '2.0' === $version ) {
|
||||
$nodeinfo['protocols'][] = 'activitypub';
|
||||
} else {
|
||||
$nodeinfo['protocols']['inbound'][] = 'activitypub';
|
||||
$nodeinfo['protocols']['outbound'][] = 'activitypub';
|
||||
}
|
||||
|
||||
return $nodeinfo;
|
||||
}
|
||||
|
||||
|
@ -153,10 +165,12 @@ class Rest_Activitypub_Nodeinfo {
|
|||
* Extend NodeInfo2 data
|
||||
*
|
||||
* @param array $nodeinfo NodeInfo2 data
|
||||
* @param array updated data
|
||||
*
|
||||
* @return array The extended array
|
||||
*/
|
||||
public static function add_nodeinfo2_discovery( $nodeinfo ) {
|
||||
$nodeinfo['protocols'][] = 'activitypub';
|
||||
|
||||
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
|
||||
namespace Activitypub\Rest;
|
||||
|
||||
/**
|
||||
* ActivityPub Outbox Class
|
||||
*
|
||||
* @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
|
||||
|
@ -13,8 +25,8 @@ class Rest_Activitypub_Outbox {
|
|||
register_rest_route(
|
||||
'activitypub/1.0', '/users/(?P<id>\d+)/outbox', array(
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( 'Rest_Activitypub_Outbox', 'user_outbox' ),
|
||||
'methods' => \WP_REST_Server::READABLE,
|
||||
'callback' => array( '\Activitypub\Rest\Outbox', 'user_outbox' ),
|
||||
'args' => self::request_parameters(),
|
||||
),
|
||||
)
|
||||
|
@ -32,10 +44,11 @@ class Rest_Activitypub_Outbox {
|
|||
$author = get_user_by( 'ID', $user_id );
|
||||
|
||||
if ( ! $author ) {
|
||||
return new WP_Error( 'rest_invalid_param', __( 'User not found', 'activitypub' ), array(
|
||||
'status' => 404, 'params' => array(
|
||||
'user_id' => __( 'User not found', 'activitypub' )
|
||||
)
|
||||
return new \WP_Error( 'rest_invalid_param', __( 'User not found', 'activitypub' ), array(
|
||||
'status' => 404,
|
||||
'params' => array(
|
||||
'user_id' => __( 'User not found', 'activitypub' ),
|
||||
),
|
||||
) );
|
||||
}
|
||||
|
||||
|
@ -46,17 +59,17 @@ class Rest_Activitypub_Outbox {
|
|||
*/
|
||||
do_action( 'activitypub_outbox_pre' );
|
||||
|
||||
$json = new stdClass();
|
||||
$json = new \stdClass();
|
||||
|
||||
$json->{'@context'} = get_activitypub_context();
|
||||
$json->id = home_url( add_query_arg( NULL, NULL ) );
|
||||
$json->{'@context'} = \Activitypub\get_context();
|
||||
$json->id = home_url( add_query_arg( null, null ) );
|
||||
$json->generator = 'http://wordpress.org/?v=' . get_bloginfo_rss( 'version' );
|
||||
$json->actor = get_author_posts_url( $user_id );
|
||||
$json->type = 'OrderedCollectionPage';
|
||||
$json->partOf = get_rest_url( null, "/activitypub/1.0/users/$user_id/outbox" ); // phpcs:ignore
|
||||
|
||||
$count_posts = wp_count_posts();
|
||||
$json->totalItems = intval( $count_posts->publish );
|
||||
$json->totalItems = intval( $count_posts->publish ); // phpcs:ignore
|
||||
|
||||
$posts = get_posts( array(
|
||||
'posts_per_page' => 10,
|
||||
|
@ -64,16 +77,16 @@ class Rest_Activitypub_Outbox {
|
|||
'offset' => $page * 10,
|
||||
) );
|
||||
|
||||
$json->first = add_query_arg( 'page', 0, $json->partOf );
|
||||
$json->last = add_query_arg( 'page', ( ceil ( $json->totalItems / 10 ) ) - 1, $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 ); // phpcs:ignore
|
||||
|
||||
if ( ( ceil ( $json->totalItems / 10 ) ) - 1 > $page ) {
|
||||
$json->next = add_query_arg( 'page', ++$page, $json->partOf );
|
||||
if ( ( ceil ( $json->totalItems / 10 ) ) - 1 > $page ) { // phpcs:ignore
|
||||
$json->next = add_query_arg( 'page', ++$page, $json->partOf ); // phpcs:ignore
|
||||
}
|
||||
|
||||
foreach ( $posts as $post ) {
|
||||
$activitypub_post = new Activitypub_Post( $post );
|
||||
$activitypub_activity = new Activitypub_Activity( 'Create', Activitypub_Activity::TYPE_NONE );
|
||||
$activitypub_post = new \Activitypub\Post( $post );
|
||||
$activitypub_activity = new \Activitypub\Activity( 'Create', \Activitypub\Activity::TYPE_NONE );
|
||||
$activitypub_activity->from_post( $activitypub_post->to_array() );
|
||||
$json->orderedItems[] = $activitypub_activity->to_array(); // phpcs:ignore
|
||||
}
|
||||
|
@ -86,7 +99,7 @@ class Rest_Activitypub_Outbox {
|
|||
*/
|
||||
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' );
|
||||
|
||||
|
@ -112,16 +125,16 @@ class Rest_Activitypub_Outbox {
|
|||
$post = get_post( $post_id );
|
||||
$user_id = $post->post_author;
|
||||
|
||||
$activitypub_post = new Activitypub_Post( $post );
|
||||
$activitypub_activity = new Activitypub_Activity( 'Create', Activitypub_Activity::TYPE_FULL );
|
||||
$activitypub_post = new \Activitypub\Post( $post );
|
||||
$activitypub_activity = new \Activitypub\Activity( 'Create', \Activitypub\Activity::TYPE_FULL );
|
||||
$activitypub_activity->from_post( $activitypub_post->to_array() );
|
||||
|
||||
$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 ) {
|
||||
$response = activitypub_safe_remote_post( $inbox, $activity, $user_id );
|
||||
foreach ( \Activitypub\get_follower_inboxes( $user_id, $followers ) as $inbox ) {
|
||||
$response = \Activitypub\safe_remote_post( $inbox, $activity, $user_id );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -129,16 +142,16 @@ class Rest_Activitypub_Outbox {
|
|||
$post = get_post( $post_id );
|
||||
$user_id = $post->post_author;
|
||||
|
||||
$activitypub_post = new Activitypub_Post( $post );
|
||||
$activitypub_activity = new Activitypub_Activity( 'Update', Activitypub_Activity::TYPE_FULL );
|
||||
$activitypub_post = new \Activitypub\Post( $post );
|
||||
$activitypub_activity = new \Activitypub\Activity( 'Update', \Activitypub\Activity::TYPE_FULL );
|
||||
$activitypub_activity->from_post( $activitypub_post->to_array() );
|
||||
|
||||
$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 ) {
|
||||
$response = activitypub_safe_remote_post( $inbox, $activity, $user_id );
|
||||
foreach ( \Activitypub\get_follower_inboxes( $user_id, $followers ) as $inbox ) {
|
||||
$response = \Activitypub\safe_remote_post( $inbox, $activity, $user_id );
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,6 +1,11 @@
|
|||
<?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
|
||||
*/
|
||||
|
@ -8,8 +13,8 @@ class Rest_Activitypub_Webfinger {
|
|||
register_rest_route(
|
||||
'activitypub/1.0', '/webfinger', array(
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( 'Rest_Activitypub_Webfinger', 'webfinger' ),
|
||||
'methods' => \WP_REST_Server::READABLE,
|
||||
'callback' => array( '\Activitypub\Rest\Webfinger', 'webfinger' ),
|
||||
'args' => self::request_parameters(),
|
||||
),
|
||||
)
|
||||
|
@ -29,20 +34,20 @@ class Rest_Activitypub_Webfinger {
|
|||
$matched = preg_match( '/^acct:([^@]+)@(.+)$/', $resource, $matches );
|
||||
|
||||
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_host = $matches[2];
|
||||
|
||||
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 ) );
|
||||
|
||||
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(
|
||||
|
@ -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.
|
||||
msgid ""
|
||||
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"
|
||||
"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"
|
||||
"Content-Type: text/plain; charset=utf-8\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
|
@ -13,24 +13,24 @@ msgstr ""
|
|||
"Language-Team: LANGUAGE <LL@li.org>\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"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-activitypub-admin.php:47
|
||||
#: includes/class-admin.php:54
|
||||
msgid "The Activity-Object-Type"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-activitypub-admin.php:59
|
||||
#: includes/class-activitypub-admin.php:66 templates/settings-page.php:33
|
||||
#: includes/class-admin.php:66 includes/class-admin.php:73
|
||||
#: templates/settings-page.php:33
|
||||
msgid "Use the Shortlink instead of the permalink"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-activitypub-admin.php:76
|
||||
#: includes/class-admin.php:83
|
||||
msgid "Overview"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-activitypub-admin.php:78
|
||||
#: includes/class-admin.php:85
|
||||
msgid ""
|
||||
"ActivityPub is a decentralized social networking protocol based on the "
|
||||
"ActivityStreams 2.0 data format. ActivityPub is an official W3C recommended "
|
||||
|
@ -40,91 +40,87 @@ msgid ""
|
|||
"subscribing to content."
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-activitypub-admin.php:83
|
||||
#: includes/class-admin.php:90
|
||||
msgid "For more information:"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-activitypub-admin.php:84
|
||||
#: includes/class-admin.php:91
|
||||
msgid "<a href=\"https://activitypub.rocks/\">Test Suite</a>"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-activitypub-admin.php:85
|
||||
#: includes/class-admin.php:92
|
||||
msgid "<a href=\"https://www.w3.org/TR/activitypub/\">W3C Spec</a>"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-activitypub-admin.php:86
|
||||
#: includes/class-admin.php:93
|
||||
msgid ""
|
||||
"<a href=\"https://github.com/pfefferle/wordpress-activitypub/issues\">Give "
|
||||
"us feedback</a>"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-activitypub-admin.php:88
|
||||
#: includes/class-admin.php:95
|
||||
msgid "<a href=\"https://notiz.blog/donate\">Donate</a>"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-activitypub-admin.php:94
|
||||
#: includes/class-admin.php:101
|
||||
msgid "Fediverse"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-db-activitypub-followers.php:41
|
||||
#: includes/db/class-followers.php:42
|
||||
msgid "Unknown Actor schema"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-rest-activitypub-followers.php:24
|
||||
#: 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
|
||||
#: includes/functions.php:99
|
||||
msgid "The \"actor\" is no valid URL"
|
||||
msgstr ""
|
||||
|
||||
#: includes/functions.php:121
|
||||
#: includes/functions.php:123
|
||||
msgid "No valid JSON data"
|
||||
msgstr ""
|
||||
|
||||
#: includes/functions.php:149
|
||||
#: includes/functions.php:151
|
||||
msgid "No \"Inbox\" found"
|
||||
msgstr ""
|
||||
|
||||
#: includes/functions.php:175
|
||||
#: includes/functions.php:177
|
||||
msgid "No \"Public-Key\" found"
|
||||
msgstr ""
|
||||
|
||||
#: includes/functions.php:193
|
||||
#: includes/functions.php:195
|
||||
msgid "Profile identifier"
|
||||
msgstr ""
|
||||
|
||||
#: includes/functions.php:197
|
||||
#: includes/functions.php:199
|
||||
msgid "Try to follow \"@%s\" in the mastodon/friendi.ca search field."
|
||||
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
|
||||
msgid "Blog"
|
||||
msgstr ""
|
||||
|
|
|
@ -4,7 +4,7 @@ Donate link: https://notiz.blog/donate/
|
|||
Tags: OStatus, fediverse, activitypub, activitystream
|
||||
Requires at least: 4.7
|
||||
Tested up to: 5.1
|
||||
Stable tag: 0.4.4
|
||||
Stable tag: 0.5.0
|
||||
Requires PHP: 5.6
|
||||
License: MIT
|
||||
License URI: http://opensource.org/licenses/MIT
|
||||
|
|
|
@ -3,7 +3,7 @@ $author_id = get_the_author_meta( 'ID' );
|
|||
|
||||
$json = new stdClass();
|
||||
|
||||
$json->{'@context'} = get_activitypub_context();
|
||||
$json->{'@context'} = \Activitypub\get_context();
|
||||
$json->id = get_author_posts_url( $author_id );
|
||||
$json->type = 'Person';
|
||||
$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(
|
||||
'id' => get_author_posts_url( $author_id ) . '#main-key',
|
||||
'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();
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
<?php
|
||||
$post = get_post();
|
||||
|
||||
$activitypub_post = new Activitypub_Post( $post );
|
||||
$activitypub_activity = new Activitypub_Activity( 'Create', Activitypub_Activity::TYPE_FULL );
|
||||
$activitypub_post = new \Activitypub\Post( $post );
|
||||
$activitypub_activity = new \Activitypub\Activity( 'Create', \Activitypub\Activity::TYPE_FULL );
|
||||
$activitypub_activity->from_post( $activitypub_post->to_array() );
|
||||
|
||||
// filter output
|
||||
|
|
|
@ -80,7 +80,7 @@
|
|||
|
||||
<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' ); ?>
|
||||
|
||||
|
@ -95,9 +95,9 @@
|
|||
<label><?php esc_html_e( 'List of followers', 'activitypub' ); ?></label>
|
||||
</th>
|
||||
<td>
|
||||
<?php if ( Db_Activitypub_Followers::get_followers( get_current_user_id() ) ) { ?>
|
||||
<?php if ( \Activitypub\Db\Followers::get_followers( get_current_user_id() ) ) { ?>
|
||||
<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>
|
||||
<?php } ?>
|
||||
</ul>
|
||||
|
|
|
@ -9,7 +9,7 @@ class Test_Db_Activitypub_Followers extends WP_UnitTestCase {
|
|||
);
|
||||
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 ) );
|
||||
|
||||
|
|
Loading…
Reference in a new issue