transform users to actors
This commit is contained in:
parent
83ddca8f28
commit
c266c927da
20 changed files with 134 additions and 221 deletions
|
@ -28,7 +28,9 @@ function init() {
|
||||||
\defined( 'ACTIVITYPUB_USERNAME_REGEXP' ) || \define( 'ACTIVITYPUB_USERNAME_REGEXP', '(?:([A-Za-z0-9_-]+)@((?:[A-Za-z0-9_-]+\.)+[A-Za-z]+))' );
|
\defined( 'ACTIVITYPUB_USERNAME_REGEXP' ) || \define( 'ACTIVITYPUB_USERNAME_REGEXP', '(?:([A-Za-z0-9_-]+)@((?:[A-Za-z0-9_-]+\.)+[A-Za-z]+))' );
|
||||||
\defined( 'ACTIVITYPUB_CUSTOM_POST_CONTENT' ) || \define( 'ACTIVITYPUB_CUSTOM_POST_CONTENT', "<strong>[ap_title]</strong>\n\n[ap_content]\n\n[ap_hashtags]\n\n[ap_shortlink]" );
|
\defined( 'ACTIVITYPUB_CUSTOM_POST_CONTENT' ) || \define( 'ACTIVITYPUB_CUSTOM_POST_CONTENT', "<strong>[ap_title]</strong>\n\n[ap_content]\n\n[ap_hashtags]\n\n[ap_shortlink]" );
|
||||||
\defined( 'ACTIVITYPUB_SECURE_MODE' ) || \define( 'ACTIVITYPUB_SECURE_MODE', apply_filters( 'activitypub_secure_mode', $value = false ) );
|
\defined( 'ACTIVITYPUB_SECURE_MODE' ) || \define( 'ACTIVITYPUB_SECURE_MODE', apply_filters( 'activitypub_secure_mode', $value = false ) );
|
||||||
\defined( 'ACTIVITYPUB_SINGLE_USER_MODE' ) || \define( 'ACTIVITYPUB_SINGLE_USER_MODE', false );
|
|
||||||
|
\defined( 'ACTIVITYPUB_DISABLE_USER' ) || \define( 'ACTIVITYPUB_DISABLE_USER', false );
|
||||||
|
\defined( 'ACTIVITYPUB_DISABLE_BLOG_USER' ) || \define( 'ACTIVITYPUB_DISABLE_BLOG_USER', false );
|
||||||
|
|
||||||
\define( 'ACTIVITYPUB_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
|
\define( 'ACTIVITYPUB_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
|
||||||
\define( 'ACTIVITYPUB_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
|
\define( 'ACTIVITYPUB_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
|
||||||
|
|
|
@ -114,4 +114,18 @@ class Actor extends Base_Object {
|
||||||
* @var string|array|null
|
* @var string|array|null
|
||||||
*/
|
*/
|
||||||
protected $public_key;
|
protected $public_key;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* It's not part of the ActivityPub protocol but it's a quite common
|
||||||
|
* practice to lock an account. If anabled, new followers will not be
|
||||||
|
* automatically accepted, but will instead require you to manually
|
||||||
|
* approve them.
|
||||||
|
*
|
||||||
|
* WordPress does only support 'false' at the moment.
|
||||||
|
*
|
||||||
|
* @see https://docs.joinmastodon.org/spec/activitypub/#as
|
||||||
|
*
|
||||||
|
* @var boolean
|
||||||
|
*/
|
||||||
|
protected $manually_approves_followers = false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -577,16 +577,22 @@ class Base_Object {
|
||||||
|
|
||||||
foreach ( $vars as $key => $value ) {
|
foreach ( $vars as $key => $value ) {
|
||||||
// if value is empty, try to get it from a getter.
|
// if value is empty, try to get it from a getter.
|
||||||
if ( ! $value ) {
|
if ( ! isset( $value ) ) {
|
||||||
$value = call_user_func( array( $this, 'get_' . $key ) );
|
$value = call_user_func( array( $this, 'get_' . $key ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
// if value is still empty, ignore it for the array and continue.
|
// if value is still empty, ignore it for the array and continue.
|
||||||
if ( $value ) {
|
if ( isset( $value ) ) {
|
||||||
$array[ snake_to_camel_case( $key ) ] = $value;
|
$array[ snake_to_camel_case( $key ) ] = $value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$class = new \ReflectionClass( $this );
|
||||||
|
$class = strtolower( $class->getShortName() );
|
||||||
|
|
||||||
|
$array = \apply_filters( 'activitypub_activity_object_array', $array, $class, $this->id, $this );
|
||||||
|
$array = \apply_filters( "activitypub_activity_{$class}_object_array", $array, $this->id, $this );
|
||||||
|
|
||||||
return $array;
|
return $array;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,20 +0,0 @@
|
||||||
<?php
|
|
||||||
/**
|
|
||||||
* Inspired by the PHP ActivityPub Library by @Landrok
|
|
||||||
*
|
|
||||||
* @link https://github.com/landrok/activitypub
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Activitypub\Activity;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Represents an individual person.
|
|
||||||
*
|
|
||||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-person
|
|
||||||
*/
|
|
||||||
class Person extends Base_Object {
|
|
||||||
/**
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $type = 'Person';
|
|
||||||
}
|
|
|
@ -30,15 +30,6 @@ class Activitypub {
|
||||||
\add_action( 'init', array( self::class, 'add_rewrite_rules' ) );
|
\add_action( 'init', array( self::class, 'add_rewrite_rules' ) );
|
||||||
|
|
||||||
\add_action( 'after_setup_theme', array( self::class, 'theme_compat' ), 99 );
|
\add_action( 'after_setup_theme', array( self::class, 'theme_compat' ), 99 );
|
||||||
|
|
||||||
if ( is_single_user_mode() ) {
|
|
||||||
add_filter(
|
|
||||||
'activitypub_post_user_id',
|
|
||||||
function( $actor ) {
|
|
||||||
return User_Factory::BLOG_USER_ID;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -91,7 +82,7 @@ class Activitypub {
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if user can publish posts
|
// check if user can publish posts
|
||||||
if ( \is_author() && ! user_can( \get_the_author_meta( 'ID' ), 'publish_posts' ) ) {
|
if ( \is_author() && ! User_Factory::get_by_id( \get_the_author_meta( 'ID' ) ) ) {
|
||||||
return $template;
|
return $template;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,10 +13,6 @@ class Admin {
|
||||||
* Initialize the class, registering WordPress hooks
|
* Initialize the class, registering WordPress hooks
|
||||||
*/
|
*/
|
||||||
public static function init() {
|
public static function init() {
|
||||||
if ( ! current_user_can( 'publish_posts' ) ) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
\add_action( 'admin_menu', array( self::class, 'admin_menu' ) );
|
\add_action( 'admin_menu', array( self::class, 'admin_menu' ) );
|
||||||
\add_action( 'admin_init', array( self::class, 'register_settings' ) );
|
\add_action( 'admin_init', array( self::class, 'register_settings' ) );
|
||||||
\add_action( 'show_user_profile', array( self::class, 'add_profile' ) );
|
\add_action( 'show_user_profile', array( self::class, 'add_profile' ) );
|
||||||
|
@ -28,11 +24,6 @@ class Admin {
|
||||||
* Add admin menu entry
|
* Add admin menu entry
|
||||||
*/
|
*/
|
||||||
public static function admin_menu() {
|
public static function admin_menu() {
|
||||||
// user has to be able to publish posts
|
|
||||||
if ( ! current_user_can( 'publish_posts' ) ) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$settings_page = \add_options_page(
|
$settings_page = \add_options_page(
|
||||||
'Welcome',
|
'Welcome',
|
||||||
'ActivityPub',
|
'ActivityPub',
|
||||||
|
@ -43,10 +34,13 @@ class Admin {
|
||||||
|
|
||||||
\add_action( 'load-' . $settings_page, array( self::class, 'add_settings_help_tab' ) );
|
\add_action( 'load-' . $settings_page, array( self::class, 'add_settings_help_tab' ) );
|
||||||
|
|
||||||
|
// user has to be able to publish posts
|
||||||
|
if ( ! is_user_disabled( get_current_user_id() ) ) {
|
||||||
$followers_list_page = \add_users_page( \__( 'Followers', 'activitypub' ), \__( 'Followers', 'activitypub' ), 'read', 'activitypub-followers-list', array( self::class, 'followers_list_page' ) );
|
$followers_list_page = \add_users_page( \__( 'Followers', 'activitypub' ), \__( 'Followers', 'activitypub' ), 'read', 'activitypub-followers-list', array( self::class, 'followers_list_page' ) );
|
||||||
|
|
||||||
\add_action( 'load-' . $followers_list_page, array( self::class, 'add_followers_list_help_tab' ) );
|
\add_action( 'load-' . $followers_list_page, array( self::class, 'add_followers_list_help_tab' ) );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load settings page
|
* Load settings page
|
||||||
|
|
|
@ -34,21 +34,12 @@ class User_Factory {
|
||||||
$user_id = (int) $user_id;
|
$user_id = (int) $user_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if ( self::BLOG_USER_ID === $user_id ) {
|
||||||
self::BLOG_USER_ID === $user_id &&
|
return Blog_User::from_wp_user( $user_id );
|
||||||
is_user_enabled( $user_id )
|
} elseif ( self::APPLICATION_USER_ID === $user_id ) {
|
||||||
) {
|
return Application_User::from_wp_user( $user_id );
|
||||||
return new Blog_User( $user_id );
|
} elseif ( $user_id > 0 ) {
|
||||||
} elseif (
|
return User::from_wp_user( $user_id );
|
||||||
self::APPLICATION_USER_ID === $user_id &&
|
|
||||||
is_user_enabled( $user_id )
|
|
||||||
) {
|
|
||||||
return new Application_User( $user_id );
|
|
||||||
} elseif (
|
|
||||||
$user_id > 0 &&
|
|
||||||
is_user_enabled( $user_id )
|
|
||||||
) {
|
|
||||||
return new User( $user_id );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return new WP_Error(
|
return new WP_Error(
|
||||||
|
|
|
@ -270,42 +270,34 @@ function is_activitypub_request() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if the current site is in single-user mode.
|
* This function checks if a user is disabled for ActivityPub.
|
||||||
*
|
|
||||||
* @return boolean
|
|
||||||
*/
|
|
||||||
function is_single_user_mode() {
|
|
||||||
return ACTIVITYPUB_SINGLE_USER_MODE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This function checks if a user is enabled for ActivityPub.
|
|
||||||
*
|
*
|
||||||
* @param int $user_id The User-ID.
|
* @param int $user_id The User-ID.
|
||||||
*
|
*
|
||||||
* @return boolean True if the user is enabled, false otherwise.
|
* @return boolean True if the user is disabled, false otherwise.
|
||||||
*/
|
*/
|
||||||
function is_user_enabled( $user_id ) {
|
function is_user_disabled( $user_id ) {
|
||||||
switch ( $user_id ) {
|
switch ( $user_id ) {
|
||||||
// if the user is the application user, it's always enabled.
|
// if the user is the application user, it's always enabled.
|
||||||
case \Activitypub\User_Factory::APPLICATION_USER_ID:
|
case \Activitypub\User_Factory::APPLICATION_USER_ID:
|
||||||
return true;
|
return false;
|
||||||
// if the user is the blog user, it's only enabled in single-user mode.
|
// if the user is the blog user, it's only enabled in single-user mode.
|
||||||
case \Activitypub\User_Factory::BLOG_USER_ID:
|
case \Activitypub\User_Factory::BLOG_USER_ID:
|
||||||
if ( is_single_user_mode() ) {
|
if ( defined( 'ACTIVITYPUB_DISABLE_BLOG_USER' ) ) {
|
||||||
return true;
|
return ACTIVITYPUB_DISABLE_BLOG_USER;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
// if the user is any other user, it's enabled if it can publish posts.
|
// if the user is any other user, it's enabled if it can publish posts.
|
||||||
default:
|
default:
|
||||||
if (
|
if ( ! \user_can( $user_id, 'publish_posts' ) ) {
|
||||||
! is_single_user_mode() &&
|
|
||||||
\user_can( $user_id, 'publish_posts' )
|
|
||||||
) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( defined( 'ACTIVITYPUB_DISABLE_USER' ) ) {
|
||||||
|
return ACTIVITYPUB_DISABLE_USER;
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,23 +13,14 @@ class Application_User extends Blog_User {
|
||||||
*
|
*
|
||||||
* @var int
|
* @var int
|
||||||
*/
|
*/
|
||||||
public $user_id = User_Factory::APPLICATION_USER_ID;
|
protected $_id = User_Factory::APPLICATION_USER_ID; // phpcs:ignore PSR2.Classes.PropertyDeclaration.Underscore
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The User-Type
|
* The User-Type
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
private $type = 'Application';
|
protected $type = 'Application';
|
||||||
|
|
||||||
/**
|
|
||||||
* The User constructor.
|
|
||||||
*
|
|
||||||
* @param int $user_id The User-ID.
|
|
||||||
*/
|
|
||||||
public function __construct( $user_id = null ) {
|
|
||||||
// do nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the User-Url.
|
* Get the User-Url.
|
||||||
|
|
|
@ -11,22 +11,22 @@ class Blog_User extends User {
|
||||||
*
|
*
|
||||||
* @var int
|
* @var int
|
||||||
*/
|
*/
|
||||||
public $user_id = User_Factory::BLOG_USER_ID;
|
protected $_id = User_Factory::BLOG_USER_ID; // phpcs:ignore PSR2.Classes.PropertyDeclaration.Underscore
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The User-Type
|
* The User-Type
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
private $type = 'Person';
|
protected $type = 'Person';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The User constructor.
|
* The User constructor.
|
||||||
*
|
*
|
||||||
* @param int $user_id The User-ID.
|
* @param int $user_id The User-ID.
|
||||||
*/
|
*/
|
||||||
public function __construct( $user_id = null ) {
|
public function __construct() {
|
||||||
add_filter( 'activitypub_json_author_array', array( $this, 'add_api_endpoints' ), 10, 2 );
|
add_filter( 'activitypub_activity_blog_user_object_array', array( $this, 'add_api_endpoints' ), 10, 2 );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -61,10 +61,6 @@ class Blog_User extends User {
|
||||||
return \esc_url( \trailingslashit( get_home_url() ) . '@' . $this->get_username() );
|
return \esc_url( \trailingslashit( get_home_url() ) . '@' . $this->get_username() );
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get_canonical_url() {
|
|
||||||
return \get_home_url();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate and save a default Username.
|
* Generate and save a default Username.
|
||||||
*
|
*
|
||||||
|
|
|
@ -6,34 +6,45 @@ use WP_Error;
|
||||||
use Activitypub\Signature;
|
use Activitypub\Signature;
|
||||||
use Activitypub\Model\User;
|
use Activitypub\Model\User;
|
||||||
use Activitypub\User_Factory;
|
use Activitypub\User_Factory;
|
||||||
|
use Activitypub\Activity\Actor;
|
||||||
|
|
||||||
|
use function Activitypub\is_user_disabled;
|
||||||
use function Activitypub\get_rest_url_by_path;
|
use function Activitypub\get_rest_url_by_path;
|
||||||
|
|
||||||
class User {
|
class User extends Actor {
|
||||||
/**
|
/**
|
||||||
* The User-ID
|
* The User-ID
|
||||||
*
|
*
|
||||||
* @var int
|
* @var int
|
||||||
*/
|
*/
|
||||||
public $user_id;
|
protected $_id; // phpcs:ignore PSR2.Classes.PropertyDeclaration.Underscore
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The User-Type
|
* The User-Type
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
private $type = 'Person';
|
protected $type = 'Person';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The User constructor.
|
* The User constructor.
|
||||||
*
|
*
|
||||||
* @param numeric $user_id The User-ID.
|
* @param numeric $user_id The User-ID.
|
||||||
*/
|
*/
|
||||||
public function __construct( $user_id ) {
|
public function __construct() {
|
||||||
$this->user_id = $user_id;
|
add_filter( 'activitypub_activity_user_object_array', array( $this, 'add_api_endpoints' ), 10, 2 );
|
||||||
|
add_filter( 'activitypub_activity_user_object_array', array( $this, 'add_attachments' ), 10, 2 );
|
||||||
|
}
|
||||||
|
|
||||||
add_filter( 'activitypub_json_author_array', array( $this, 'add_api_endpoints' ), 10, 2 );
|
public static function from_wp_user( $user_id ) {
|
||||||
add_filter( 'activitypub_json_author_array', array( $this, 'add_attachments' ), 10, 2 );
|
if ( is_user_disabled( $user_id ) ) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$object = new static();
|
||||||
|
$object->_id = $user_id;
|
||||||
|
|
||||||
|
return $object;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -71,7 +82,7 @@ class User {
|
||||||
* @return string The User-Name.
|
* @return string The User-Name.
|
||||||
*/
|
*/
|
||||||
public function get_name() {
|
public function get_name() {
|
||||||
return \esc_attr( \get_the_author_meta( 'display_name', $this->user_id ) );
|
return \esc_attr( \get_the_author_meta( 'display_name', $this->_id ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -80,9 +91,9 @@ class User {
|
||||||
* @return string The User-Description.
|
* @return string The User-Description.
|
||||||
*/
|
*/
|
||||||
public function get_summary() {
|
public function get_summary() {
|
||||||
$description = get_user_meta( $this->user_id, 'activitypub_user_description', true );
|
$description = get_user_meta( $this->_id, 'activitypub_user_description', true );
|
||||||
if ( empty( $description ) ) {
|
if ( empty( $description ) ) {
|
||||||
$description = get_user_meta( $this->user_id, 'description', true );
|
$description = get_user_meta( $this->_id, 'description', true );
|
||||||
}
|
}
|
||||||
return \wpautop( \wp_kses( $description, 'default' ) );
|
return \wpautop( \wp_kses( $description, 'default' ) );
|
||||||
}
|
}
|
||||||
|
@ -93,44 +104,49 @@ class User {
|
||||||
* @return string The User-Url.
|
* @return string The User-Url.
|
||||||
*/
|
*/
|
||||||
public function get_url() {
|
public function get_url() {
|
||||||
return \esc_url( \get_author_posts_url( $this->user_id ) );
|
return \esc_url( \get_author_posts_url( $this->_id ) );
|
||||||
}
|
|
||||||
|
|
||||||
public function get_canonical_url() {
|
|
||||||
return $this->get_url();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get_at_url() {
|
public function get_at_url() {
|
||||||
return \esc_url( \trailingslashit( get_home_url() ) . '@' . $this->get_username() );
|
return \esc_url( \trailingslashit( get_home_url() ) . '@' . $this->get_username() );
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get_username() {
|
public function get_preferred_username() {
|
||||||
return \esc_attr( \get_the_author_meta( 'login', $this->user_id ) );
|
return \esc_attr( \get_the_author_meta( 'login', $this->_id ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get_avatar() {
|
public function get_icon() {
|
||||||
return \esc_url(
|
$icon = \esc_url(
|
||||||
\get_avatar_url(
|
\get_avatar_url(
|
||||||
$this->user_id,
|
$this->_id,
|
||||||
array( 'size' => 120 )
|
array( 'size' => 120 )
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
return array(
|
||||||
|
'type' => 'Image',
|
||||||
|
'url' => $icon,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get_header_image() {
|
public function get_image() {
|
||||||
if ( \has_header_image() ) {
|
if ( \has_header_image() ) {
|
||||||
return \esc_url( \get_header_image() );
|
$image = \esc_url( \get_header_image() );
|
||||||
|
return array(
|
||||||
|
'type' => 'Image',
|
||||||
|
'url' => $image,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get_published() {
|
public function get_published() {
|
||||||
return \gmdate( 'Y-m-d\TH:i:s\Z', \strtotime( \get_the_author_meta( 'registered', $this->user_id ) ) );
|
return \gmdate( 'Y-m-d\TH:i:s\Z', \strtotime( \get_the_author_meta( 'registered', $this->_id ) ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get_public_key() {
|
public function get_public_key() {
|
||||||
$key = \get_user_meta( $this->get_user_id(), 'magic_sig_public_key', true );
|
$key = \get_user_meta( $this->get__id(), 'magic_sig_public_key', true );
|
||||||
|
|
||||||
if ( $key ) {
|
if ( $key ) {
|
||||||
return $key;
|
return $key;
|
||||||
|
@ -138,7 +154,7 @@ class User {
|
||||||
|
|
||||||
$this->generate_key_pair();
|
$this->generate_key_pair();
|
||||||
|
|
||||||
return \get_user_meta( $this->get_user_id(), 'magic_sig_public_key', true );
|
return \get_user_meta( $this->get__id(), 'magic_sig_public_key', true );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -147,7 +163,7 @@ class User {
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function get_private_key() {
|
public function get_private_key() {
|
||||||
$key = \get_user_meta( $this->get_user_id(), 'magic_sig_private_key', true );
|
$key = \get_user_meta( $this->get__id(), 'magic_sig_private_key', true );
|
||||||
|
|
||||||
if ( $key ) {
|
if ( $key ) {
|
||||||
return $key;
|
return $key;
|
||||||
|
@ -155,70 +171,18 @@ class User {
|
||||||
|
|
||||||
$this->generate_key_pair();
|
$this->generate_key_pair();
|
||||||
|
|
||||||
return \get_user_meta( $this->get_user_id(), 'magic_sig_private_key', true );
|
return \get_user_meta( $this->get__id(), 'magic_sig_private_key', true );
|
||||||
}
|
}
|
||||||
|
|
||||||
private function generate_key_pair() {
|
private function generate_key_pair() {
|
||||||
$key_pair = Signature::generate_key_pair();
|
$key_pair = Signature::generate_key_pair();
|
||||||
|
|
||||||
if ( ! is_wp_error( $key_pair ) ) {
|
if ( ! is_wp_error( $key_pair ) ) {
|
||||||
\update_user_meta( $this->get_user_id(), 'magic_sig_public_key', $key_pair['public_key'], true );
|
\update_user_meta( $this->get__id(), 'magic_sig_public_key', $key_pair['public_key'], true );
|
||||||
\update_user_meta( $this->get_user_id(), 'magic_sig_private_key', $key_pair['private_key'], true );
|
\update_user_meta( $this->get__id(), 'magic_sig_private_key', $key_pair['private_key'], true );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Array representation of the User.
|
|
||||||
*
|
|
||||||
* @param bool $context Whether to include the @context.
|
|
||||||
*
|
|
||||||
* @return array The array representation of the User.
|
|
||||||
*/
|
|
||||||
public function to_array( $context = true ) {
|
|
||||||
$output = array();
|
|
||||||
|
|
||||||
if ( $context ) {
|
|
||||||
$output['@context'] = Activity::CONTEXT;
|
|
||||||
}
|
|
||||||
|
|
||||||
$output['id'] = $this->get_url();
|
|
||||||
$output['type'] = $this->get_type();
|
|
||||||
$output['name'] = $this->get_name();
|
|
||||||
$output['summary'] = \html_entity_decode(
|
|
||||||
$this->get_summary(),
|
|
||||||
\ENT_QUOTES,
|
|
||||||
'UTF-8'
|
|
||||||
);
|
|
||||||
$output['preferredUsername'] = $this->get_username(); // phpcs:ignore
|
|
||||||
$output['url'] = $this->get_url();
|
|
||||||
$output['icon'] = array(
|
|
||||||
'type' => 'Image',
|
|
||||||
'url' => $this->get_avatar(),
|
|
||||||
);
|
|
||||||
|
|
||||||
if ( $this->has_header_image() ) {
|
|
||||||
$output['image'] = array(
|
|
||||||
'type' => 'Image',
|
|
||||||
'url' => $this->get_header_image(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
$output['published'] = $this->get_published();
|
|
||||||
|
|
||||||
$output['publicKey'] = array(
|
|
||||||
'id' => $this->get_url() . '#main-key',
|
|
||||||
'owner' => $this->get_url(),
|
|
||||||
'publicKeyPem' => \trim( $this->get_public_key() ),
|
|
||||||
);
|
|
||||||
|
|
||||||
$output['manuallyApprovesFollowers'] = \apply_filters( 'activitypub_json_manually_approves_followers', \__return_false() ); // phpcs:ignore
|
|
||||||
|
|
||||||
// filter output
|
|
||||||
$output = \apply_filters( 'activitypub_json_author_array', $output, $this->user_id, $this );
|
|
||||||
|
|
||||||
return $output;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extend the User-Output with API-Endpoints.
|
* Extend the User-Output with API-Endpoints.
|
||||||
*
|
*
|
||||||
|
@ -283,6 +247,6 @@ class User {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get_resource() {
|
public function get_resource() {
|
||||||
return $this->get_username() . '@' . \wp_parse_url( \home_url(), \PHP_URL_HOST );
|
return $this->get_preferred_username() . '@' . \wp_parse_url( \home_url(), \PHP_URL_HOST );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,15 +72,15 @@ class Followers {
|
||||||
$json->actor = $user->get_id();
|
$json->actor = $user->get_id();
|
||||||
$json->type = 'OrderedCollectionPage';
|
$json->type = 'OrderedCollectionPage';
|
||||||
|
|
||||||
$json->partOf = get_rest_url_by_path( sprintf( 'users/%d/followers', $user->get_user_id() ) ); // phpcs:ignore
|
$json->partOf = get_rest_url_by_path( sprintf( 'users/%d/followers', $user->get__id() ) ); // phpcs:ignore
|
||||||
$json->first = $json->partOf; // phpcs:ignore
|
$json->first = $json->partOf; // phpcs:ignore
|
||||||
$json->totalItems = FollowerCollection::count_followers( $user->get_user_id() ); // phpcs:ignore
|
$json->totalItems = FollowerCollection::count_followers( $user->get__id() ); // phpcs:ignore
|
||||||
// phpcs:ignore
|
// phpcs:ignore
|
||||||
$json->orderedItems = array_map(
|
$json->orderedItems = array_map(
|
||||||
function( $item ) {
|
function( $item ) {
|
||||||
return $item->get_url();
|
return $item->get_url();
|
||||||
},
|
},
|
||||||
FollowerCollection::get_followers( $user->get_user_id() )
|
FollowerCollection::get_followers( $user->get__id() )
|
||||||
);
|
);
|
||||||
|
|
||||||
$response = new WP_REST_Response( $json, 200 );
|
$response = new WP_REST_Response( $json, 200 );
|
||||||
|
|
|
@ -67,7 +67,7 @@ class Following {
|
||||||
$json->actor = $user->get_id();
|
$json->actor = $user->get_id();
|
||||||
$json->type = 'OrderedCollectionPage';
|
$json->type = 'OrderedCollectionPage';
|
||||||
|
|
||||||
$json->partOf = get_rest_url_by_path( sprintf( 'users/%d/following', $user->get_user_id() ) ); // phpcs:ignore
|
$json->partOf = get_rest_url_by_path( sprintf( 'users/%d/following', $user->get__id() ) ); // phpcs:ignore
|
||||||
$json->totalItems = 0; // phpcs:ignore
|
$json->totalItems = 0; // phpcs:ignore
|
||||||
$json->orderedItems = apply_filters( 'activitypub_following', array(), $user ); // phpcs:ignore
|
$json->orderedItems = apply_filters( 'activitypub_following', array(), $user ); // phpcs:ignore
|
||||||
|
|
||||||
|
|
|
@ -93,7 +93,7 @@ class Inbox {
|
||||||
$json->id = \home_url( \add_query_arg( null, null ) );
|
$json->id = \home_url( \add_query_arg( null, null ) );
|
||||||
$json->generator = 'http://wordpress.org/?v=' . \get_bloginfo_rss( 'version' );
|
$json->generator = 'http://wordpress.org/?v=' . \get_bloginfo_rss( 'version' );
|
||||||
$json->type = 'OrderedCollectionPage';
|
$json->type = 'OrderedCollectionPage';
|
||||||
$json->partOf = get_rest_url_by_path( sprintf( 'users/%d/inbox', $user->get_user_id() ) ); // phpcs:ignore
|
$json->partOf = get_rest_url_by_path( sprintf( 'users/%d/inbox', $user->get__id() ) ); // phpcs:ignore
|
||||||
|
|
||||||
$json->totalItems = 0; // phpcs:ignore
|
$json->totalItems = 0; // phpcs:ignore
|
||||||
|
|
||||||
|
@ -136,8 +136,8 @@ class Inbox {
|
||||||
$type = $request->get_param( 'type' );
|
$type = $request->get_param( 'type' );
|
||||||
$type = \strtolower( $type );
|
$type = \strtolower( $type );
|
||||||
|
|
||||||
\do_action( 'activitypub_inbox', $data, $user->get_user_id(), $type );
|
\do_action( 'activitypub_inbox', $data, $user->get__id(), $type );
|
||||||
\do_action( "activitypub_inbox_{$type}", $data, $user->get_user_id() );
|
\do_action( "activitypub_inbox_{$type}", $data, $user->get__id() );
|
||||||
|
|
||||||
return new WP_REST_Response( array(), 202 );
|
return new WP_REST_Response( array(), 202 );
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,7 +75,7 @@ class Outbox {
|
||||||
$json->generator = 'http://wordpress.org/?v=' . \get_bloginfo_rss( 'version' );
|
$json->generator = 'http://wordpress.org/?v=' . \get_bloginfo_rss( 'version' );
|
||||||
$json->actor = $user->get_id();
|
$json->actor = $user->get_id();
|
||||||
$json->type = 'OrderedCollectionPage';
|
$json->type = 'OrderedCollectionPage';
|
||||||
$json->partOf = get_rest_url_by_path( sprintf( 'users/%d/outbox', $user->get_user_id() ) ); // phpcs:ignore
|
$json->partOf = get_rest_url_by_path( sprintf( 'users/%d/outbox', $user->get__id() ) ); // phpcs:ignore
|
||||||
$json->totalItems = 0; // phpcs:ignore
|
$json->totalItems = 0; // phpcs:ignore
|
||||||
|
|
||||||
// phpcs:ignore
|
// phpcs:ignore
|
||||||
|
@ -97,7 +97,7 @@ class Outbox {
|
||||||
$posts = \get_posts(
|
$posts = \get_posts(
|
||||||
array(
|
array(
|
||||||
'posts_per_page' => 10,
|
'posts_per_page' => 10,
|
||||||
'author' => $user->get_user_id(),
|
'author' => $user->get__id(),
|
||||||
'offset' => ( $page - 1 ) * 10,
|
'offset' => ( $page - 1 ) * 10,
|
||||||
'post_type' => $post_types,
|
'post_type' => $post_types,
|
||||||
)
|
)
|
||||||
|
|
|
@ -12,9 +12,13 @@
|
||||||
<?php \esc_html_e( 'Settings', 'activitypub' ); ?>
|
<?php \esc_html_e( 'Settings', 'activitypub' ); ?>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
|
<?php if ( ! \Activitypub\is_user_disabled( \ActivityPub\User_Factory::BLOG_USER_ID ) ) : ?>
|
||||||
|
|
||||||
<a href="<?php echo \esc_url_raw( admin_url( 'options-general.php?page=activitypub&tab=followers' ) ); ?>" class="activitypub-settings-tab <?php echo \esc_attr( $args['followers'] ); ?>">
|
<a href="<?php echo \esc_url_raw( admin_url( 'options-general.php?page=activitypub&tab=followers' ) ); ?>" class="activitypub-settings-tab <?php echo \esc_attr( $args['followers'] ); ?>">
|
||||||
<?php \esc_html_e( 'Followers', 'activitypub' ); ?>
|
<?php \esc_html_e( 'Followers', 'activitypub' ); ?>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
|
<?php endif; ?>
|
||||||
</nav>
|
</nav>
|
||||||
</div>
|
</div>
|
||||||
<hr class="wp-header-end">
|
<hr class="wp-header-end">
|
||||||
|
|
|
@ -4,7 +4,7 @@ $user = \Activitypub\User_Factory::get_by_id( \get_the_author_meta( 'ID' ) );
|
||||||
/*
|
/*
|
||||||
* Action triggerd prior to the ActivityPub profile being created and sent to the client
|
* Action triggerd prior to the ActivityPub profile being created and sent to the client
|
||||||
*/
|
*/
|
||||||
\do_action( 'activitypub_json_author_pre', $user->get_user_id() );
|
\do_action( 'activitypub_json_author_pre', $user->get__id() );
|
||||||
|
|
||||||
$options = 0;
|
$options = 0;
|
||||||
// JSON_PRETTY_PRINT added in PHP 5.4
|
// JSON_PRETTY_PRINT added in PHP 5.4
|
||||||
|
@ -19,7 +19,7 @@ $options |= \JSON_HEX_TAG | \JSON_HEX_AMP | \JSON_HEX_QUOT;
|
||||||
*
|
*
|
||||||
* @param int $options The current options flags
|
* @param int $options The current options flags
|
||||||
*/
|
*/
|
||||||
$options = \apply_filters( 'activitypub_json_author_options', $options, $user->get_user_id() );
|
$options = \apply_filters( 'activitypub_json_author_options', $options, $user->get__id() );
|
||||||
|
|
||||||
\header( 'Content-Type: application/activity+json' );
|
\header( 'Content-Type: application/activity+json' );
|
||||||
echo \wp_json_encode( $user->to_array(), $options );
|
echo \wp_json_encode( $user->to_array(), $options );
|
||||||
|
@ -27,4 +27,4 @@ echo \wp_json_encode( $user->to_array(), $options );
|
||||||
/*
|
/*
|
||||||
* Action triggerd after the ActivityPub profile has been created and sent to the client
|
* Action triggerd after the ActivityPub profile has been created and sent to the client
|
||||||
*/
|
*/
|
||||||
\do_action( 'activitypub_json_author_post', $user->get_user_id() );
|
\do_action( 'activitypub_json_author_post', $user->get__id() );
|
||||||
|
|
|
@ -4,7 +4,7 @@ $user = new \Activitypub\Model\Blog_User();
|
||||||
/*
|
/*
|
||||||
* Action triggerd prior to the ActivityPub profile being created and sent to the client
|
* Action triggerd prior to the ActivityPub profile being created and sent to the client
|
||||||
*/
|
*/
|
||||||
\do_action( 'activitypub_json_author_pre', $user->get_user_id() );
|
\do_action( 'activitypub_json_author_pre', $user->get__id() );
|
||||||
|
|
||||||
$options = 0;
|
$options = 0;
|
||||||
// JSON_PRETTY_PRINT added in PHP 5.4
|
// JSON_PRETTY_PRINT added in PHP 5.4
|
||||||
|
@ -19,7 +19,7 @@ $options |= \JSON_HEX_TAG | \JSON_HEX_AMP | \JSON_HEX_QUOT;
|
||||||
*
|
*
|
||||||
* @param int $options The current options flags
|
* @param int $options The current options flags
|
||||||
*/
|
*/
|
||||||
$options = \apply_filters( 'activitypub_json_author_options', $options, $user->get_user_id() );
|
$options = \apply_filters( 'activitypub_json_author_options', $options, $user->get__id() );
|
||||||
|
|
||||||
\header( 'Content-Type: application/activity+json' );
|
\header( 'Content-Type: application/activity+json' );
|
||||||
echo \wp_json_encode( $user->to_array(), $options );
|
echo \wp_json_encode( $user->to_array(), $options );
|
||||||
|
@ -27,4 +27,4 @@ echo \wp_json_encode( $user->to_array(), $options );
|
||||||
/*
|
/*
|
||||||
* Action triggerd after the ActivityPub profile has been created and sent to the client
|
* Action triggerd after the ActivityPub profile has been created and sent to the client
|
||||||
*/
|
*/
|
||||||
\do_action( 'activitypub_json_author_post', $user->get_user_id() );
|
\do_action( 'activitypub_json_author_post', $user->get__id() );
|
||||||
|
|
|
@ -31,37 +31,12 @@
|
||||||
<form method="post" action="options.php">
|
<form method="post" action="options.php">
|
||||||
<?php \settings_fields( 'activitypub' ); ?>
|
<?php \settings_fields( 'activitypub' ); ?>
|
||||||
|
|
||||||
|
<?php if ( ! \Activitypub\is_user_disabled( \ActivityPub\User_Factory::BLOG_USER_ID ) ) : ?>
|
||||||
|
|
||||||
<h3><?php \esc_html_e( 'Blog-User', 'activitypub' ); ?></h3>
|
<h3><?php \esc_html_e( 'Blog-User', 'activitypub' ); ?></h3>
|
||||||
|
|
||||||
<p><?php \esc_html_e( 'All settings for the Blog-User (Catch-All Account)', 'activitypub' ); ?></p>
|
<p><?php \esc_html_e( 'All settings for the Blog-User (Catch-All Account)', 'activitypub' ); ?></p>
|
||||||
|
|
||||||
<table class="form-table" id="activitypub-images">
|
|
||||||
<tbody>
|
|
||||||
<tr>
|
|
||||||
<th scope="row">
|
|
||||||
<?php \esc_html_e( 'Cover & Avatar', 'activitypub' ); ?>
|
|
||||||
</th>
|
|
||||||
<td>
|
|
||||||
<div class="header-image" style="background-image: url('<?php echo esc_url( get_header_image() ); ?>');">
|
|
||||||
<img class="logo" src="<?php echo esc_url( get_site_icon_url() ); ?>" />
|
|
||||||
</div>
|
|
||||||
<p class="description">
|
|
||||||
<?php
|
|
||||||
echo \wp_kses(
|
|
||||||
\sprintf(
|
|
||||||
// translators: %s is the link is to the customizer.
|
|
||||||
\__( 'Change the Avatar and the Cover using the <a href="%s">Customizer</a>.', 'activitypub' ),
|
|
||||||
\esc_url_raw( \admin_url( 'customize.php' ) )
|
|
||||||
),
|
|
||||||
'default'
|
|
||||||
);
|
|
||||||
?>
|
|
||||||
</p>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
|
|
||||||
<table class="form-table">
|
<table class="form-table">
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
<tr>
|
||||||
|
@ -83,6 +58,8 @@
|
||||||
|
|
||||||
<?php \do_settings_fields( 'activitypub', 'blog-user' ); ?>
|
<?php \do_settings_fields( 'activitypub', 'blog-user' ); ?>
|
||||||
|
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
<h3><?php \esc_html_e( 'Activities', 'activitypub' ); ?></h3>
|
<h3><?php \esc_html_e( 'Activities', 'activitypub' ); ?></h3>
|
||||||
|
|
||||||
<p><?php \esc_html_e( 'All activity related settings.', 'activitypub' ); ?></p>
|
<p><?php \esc_html_e( 'All activity related settings.', 'activitypub' ); ?></p>
|
||||||
|
|
|
@ -14,6 +14,9 @@
|
||||||
<h2><?php \esc_html_e( 'Welcome', 'activitypub' ); ?></h2>
|
<h2><?php \esc_html_e( 'Welcome', 'activitypub' ); ?></h2>
|
||||||
|
|
||||||
<p><?php \esc_html_e( 'With ActivityPub your blog becomes part of a federated social network. This means you can share and talk to everyone using the ActivityPub protocol, including users of Friendica, Pleroma and Mastodon.', 'activitypub' ); ?></p>
|
<p><?php \esc_html_e( 'With ActivityPub your blog becomes part of a federated social network. This means you can share and talk to everyone using the ActivityPub protocol, including users of Friendica, Pleroma and Mastodon.', 'activitypub' ); ?></p>
|
||||||
|
|
||||||
|
<?php if ( ! \Activitypub\is_user_disabled( \ActivityPub\User_Factory::BLOG_USER_ID ) ) : ?>
|
||||||
|
|
||||||
<h3><?php \esc_html_e( 'Blog Account', 'activitypub' ); ?></h3>
|
<h3><?php \esc_html_e( 'Blog Account', 'activitypub' ); ?></h3>
|
||||||
<p>
|
<p>
|
||||||
<?php
|
<?php
|
||||||
|
@ -33,6 +36,11 @@
|
||||||
);
|
);
|
||||||
?>
|
?>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<?php if ( ! \Activitypub\is_user_disabled( get_current_user_id() ) ) : ?>
|
||||||
|
|
||||||
<h3><?php \esc_html_e( 'Personal Account', 'activitypub' ); ?></h3>
|
<h3><?php \esc_html_e( 'Personal Account', 'activitypub' ); ?></h3>
|
||||||
<p>
|
<p>
|
||||||
<?php
|
<?php
|
||||||
|
@ -52,6 +60,9 @@
|
||||||
);
|
);
|
||||||
?>
|
?>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
<h3><?php \esc_html_e( 'Troubleshooting', 'activitypub' ); ?></h3>
|
<h3><?php \esc_html_e( 'Troubleshooting', 'activitypub' ); ?></h3>
|
||||||
<p>
|
<p>
|
||||||
<?php
|
<?php
|
||||||
|
|
Loading…
Reference in a new issue