refactoring

This commit is contained in:
Matthias Pfefferle 2023-07-11 14:34:11 +02:00
parent e0d767ed98
commit 002d4e7981
3 changed files with 58 additions and 3 deletions

View file

@ -25,6 +25,12 @@ class Http {
$signature = Signature::generate_signature( $user_id, 'post', $url, $date, $digest ); $signature = Signature::generate_signature( $user_id, 'post', $url, $date, $digest );
$wp_version = \get_bloginfo( 'version' ); $wp_version = \get_bloginfo( 'version' );
/**
* Filter the HTTP headers user agent.
*
* @param string $user_agent The user agent string.
*/
$user_agent = \apply_filters( 'http_headers_useragent', 'WordPress/' . $wp_version . '; ' . \get_bloginfo( 'url' ) ); $user_agent = \apply_filters( 'http_headers_useragent', 'WordPress/' . $wp_version . '; ' . \get_bloginfo( 'url' ) );
$args = array( $args = array(
'timeout' => 100, 'timeout' => 100,
@ -66,7 +72,14 @@ class Http {
$signature = Signature::generate_signature( Users::APPLICATION_USER_ID, 'get', $url, $date ); $signature = Signature::generate_signature( Users::APPLICATION_USER_ID, 'get', $url, $date );
$wp_version = \get_bloginfo( 'version' ); $wp_version = \get_bloginfo( 'version' );
/**
* Filter the HTTP headers user agent.
*
* @param string $user_agent The user agent string.
*/
$user_agent = \apply_filters( 'http_headers_useragent', 'WordPress/' . $wp_version . '; ' . \get_bloginfo( 'url' ) ); $user_agent = \apply_filters( 'http_headers_useragent', 'WordPress/' . $wp_version . '; ' . \get_bloginfo( 'url' ) );
$args = array( $args = array(
'timeout' => apply_filters( 'activitypub_remote_get_timeout', 100 ), 'timeout' => apply_filters( 'activitypub_remote_get_timeout', 100 ),
'limit_response_size' => 1048576, 'limit_response_size' => 1048576,

View file

@ -1,6 +1,7 @@
<?php <?php
namespace Activitypub; namespace Activitypub;
use Activitypub\Model\Blog_User;
use Activitypub\Collection\Followers; use Activitypub\Collection\Followers;
/** /**
@ -16,10 +17,23 @@ class Migration {
\add_action( 'activitypub_schedule_migration', array( self::class, 'maybe_migrate' ) ); \add_action( 'activitypub_schedule_migration', array( self::class, 'maybe_migrate' ) );
} }
/**
* Get the target version.
*
* This is the version that the database structure will be updated to.
* It is the same as the plugin version.
*
* @return string The target version.
*/
public static function get_target_version() { public static function get_target_version() {
return get_plugin_version(); return get_plugin_version();
} }
/**
* The current version of the database structure.
*
* @return string The current version.
*/
public static function get_version() { public static function get_version() {
return get_option( 'activitypub_db_version', 0 ); return get_option( 'activitypub_db_version', 0 );
} }
@ -27,7 +41,7 @@ class Migration {
/** /**
* Whether the database structure is up to date. * Whether the database structure is up to date.
* *
* @return bool * @return bool True if the database structure is up to date, false otherwise.
*/ */
public static function is_latest_version() { public static function is_latest_version() {
return (bool) version_compare( return (bool) version_compare(
@ -63,6 +77,7 @@ class Migration {
* @return void * @return void
*/ */
private static function migrate_from_0_17() { private static function migrate_from_0_17() {
// migrate followers
foreach ( get_users( array( 'fields' => 'ID' ) ) as $user_id ) { foreach ( get_users( array( 'fields' => 'ID' ) ) as $user_id ) {
$followers = get_user_meta( $user_id, 'activitypub_followers', true ); $followers = get_user_meta( $user_id, 'activitypub_followers', true );
@ -72,6 +87,11 @@ class Migration {
} }
} }
} }
// set the default username for the Blog User
if ( ! \get_option( 'activitypub_blog_user_identifier' ) ) {
\update_option( 'activitypub_blog_user_identifier', Blog_User::get_default_username() );
}
} }
/** /**

View file

@ -71,7 +71,7 @@ class Blog_User extends User {
} }
/** /**
* Generate and save a default Username. * Generate a default Username.
* *
* @return string The auto-generated Username. * @return string The auto-generated Username.
*/ */
@ -105,9 +105,19 @@ class Blog_User extends User {
// get random item of $default_identifier // get random item of $default_identifier
$default = $default_identifier[ \array_rand( $default_identifier ) ]; $default = $default_identifier[ \array_rand( $default_identifier ) ];
return $default; /**
* Filter the default blog username.
*
* @param string $default The default username.
*/
return apply_filters( 'activitypub_default_blog_username', $default );
} }
/**
* Get the preferred User-Name.
*
* @return string The User-Name.
*/
public function get_preferred_username() { public function get_preferred_username() {
$username = \get_option( 'activitypub_blog_user_identifier' ); $username = \get_option( 'activitypub_blog_user_identifier' );
@ -118,6 +128,11 @@ class Blog_User extends User {
return self::get_default_username(); return self::get_default_username();
} }
/**
* Get the User-Icon.
*
* @return array|null The User-Icon.
*/
public function get_icon() { public function get_icon() {
$image = wp_get_attachment_image_src( get_theme_mod( 'custom_logo' ) ); $image = wp_get_attachment_image_src( get_theme_mod( 'custom_logo' ) );
@ -131,6 +146,11 @@ class Blog_User extends User {
return null; return null;
} }
/**
* Get the User-Header-Image.
*
* @return array|null The User-Header-Image.
*/
public function get_header_image() { public function get_header_image() {
if ( \has_header_image() ) { if ( \has_header_image() ) {
return array( return array(
@ -175,6 +195,8 @@ class Blog_User extends User {
} }
/** /**
* Get the User-Private-Key.
*
* @param int $user_id * @param int $user_id
* *
* @return mixed * @return mixed