2023-05-24 16:32:00 +02:00
|
|
|
<?php
|
|
|
|
namespace Activitypub\Model;
|
|
|
|
|
|
|
|
use WP_Query;
|
2023-06-01 11:45:07 +02:00
|
|
|
use Activitypub\Signature;
|
2023-07-03 11:20:44 +02:00
|
|
|
use Activitypub\Collection\Users;
|
2023-05-24 16:32:00 +02:00
|
|
|
|
2023-06-01 11:45:07 +02:00
|
|
|
use function Activitypub\get_rest_url_by_path;
|
|
|
|
|
2023-05-24 16:32:00 +02:00
|
|
|
class Application_User extends Blog_User {
|
|
|
|
/**
|
|
|
|
* The User-ID
|
|
|
|
*
|
|
|
|
* @var int
|
|
|
|
*/
|
2023-07-03 11:20:44 +02:00
|
|
|
protected $_id = Users::APPLICATION_USER_ID; // phpcs:ignore PSR2.Classes.PropertyDeclaration.Underscore
|
2023-05-24 16:32:00 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The User-Type
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2023-06-28 14:22:27 +02:00
|
|
|
protected $type = 'Application';
|
2023-05-24 16:32:00 +02:00
|
|
|
|
2023-09-01 18:32:56 +02:00
|
|
|
/**
|
|
|
|
* If the User is discoverable.
|
|
|
|
*
|
|
|
|
* @var boolean
|
|
|
|
*/
|
|
|
|
protected $discoverable = false;
|
|
|
|
|
2023-05-24 16:32:00 +02:00
|
|
|
/**
|
|
|
|
* Get the User-Url.
|
|
|
|
*
|
|
|
|
* @return string The User-Url.
|
|
|
|
*/
|
|
|
|
public function get_url() {
|
2023-06-01 11:45:07 +02:00
|
|
|
return get_rest_url_by_path( 'application' );
|
2023-05-24 16:32:00 +02:00
|
|
|
}
|
2023-05-24 17:40:48 +02:00
|
|
|
|
|
|
|
public function get_name() {
|
2023-06-01 11:45:07 +02:00
|
|
|
return 'application';
|
|
|
|
}
|
|
|
|
|
2023-09-01 18:32:56 +02:00
|
|
|
public function get_preferred_username() {
|
2023-06-01 11:45:07 +02:00
|
|
|
return $this::get_name();
|
2023-05-24 17:40:48 +02:00
|
|
|
}
|
2023-05-31 10:31:49 +02:00
|
|
|
|
2023-06-28 18:02:14 +02:00
|
|
|
public function get__public_key() {
|
2023-06-01 12:47:08 +02:00
|
|
|
$key = \get_option( 'activitypub_application_user_public_key' );
|
2023-05-31 10:31:49 +02:00
|
|
|
|
|
|
|
if ( $key ) {
|
|
|
|
return $key;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->generate_key_pair();
|
|
|
|
|
2023-06-01 12:47:08 +02:00
|
|
|
$key = \get_option( 'activitypub_application_user_public_key' );
|
2023-05-31 10:31:49 +02:00
|
|
|
|
|
|
|
return $key;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param int $user_id
|
|
|
|
*
|
|
|
|
* @return mixed
|
|
|
|
*/
|
2023-06-28 18:02:14 +02:00
|
|
|
public function get__private_key() {
|
2023-06-01 12:47:08 +02:00
|
|
|
$key = \get_option( 'activitypub_application_user_private_key' );
|
2023-05-31 10:31:49 +02:00
|
|
|
|
|
|
|
if ( $key ) {
|
|
|
|
return $key;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->generate_key_pair();
|
|
|
|
|
2023-06-01 12:47:08 +02:00
|
|
|
return \get_option( 'activitypub_application_user_private_key' );
|
2023-05-31 10:31:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private function generate_key_pair() {
|
|
|
|
$key_pair = Signature::generate_key_pair();
|
|
|
|
|
|
|
|
if ( ! is_wp_error( $key_pair ) ) {
|
2023-06-01 12:47:08 +02:00
|
|
|
\update_option( 'activitypub_application_user_public_key', $key_pair['public_key'] );
|
|
|
|
\update_option( 'activitypub_application_user_private_key', $key_pair['private_key'] );
|
2023-05-31 10:31:49 +02:00
|
|
|
}
|
|
|
|
}
|
2023-06-28 16:43:41 +02:00
|
|
|
|
|
|
|
public function get_followers() {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function get_following() {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function get_attachment() {
|
|
|
|
return array();
|
|
|
|
}
|
2023-08-09 13:07:30 +02:00
|
|
|
|
|
|
|
public function get_featured_tags() {
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function get_featured() {
|
|
|
|
return array();
|
|
|
|
}
|
2023-05-24 16:32:00 +02:00
|
|
|
}
|