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 );
$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' ) );
$args = array(
'timeout' => 100,
@ -66,7 +72,14 @@ class Http {
$signature = Signature::generate_signature( Users::APPLICATION_USER_ID, 'get', $url, $date );
$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' ) );
$args = array(
'timeout' => apply_filters( 'activitypub_remote_get_timeout', 100 ),
'limit_response_size' => 1048576,

View file

@ -1,6 +1,7 @@
<?php
namespace Activitypub;
use Activitypub\Model\Blog_User;
use Activitypub\Collection\Followers;
/**
@ -16,10 +17,23 @@ class Migration {
\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() {
return get_plugin_version();
}
/**
* The current version of the database structure.
*
* @return string The current version.
*/
public static function get_version() {
return get_option( 'activitypub_db_version', 0 );
}
@ -27,7 +41,7 @@ class Migration {
/**
* 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() {
return (bool) version_compare(
@ -63,6 +77,7 @@ class Migration {
* @return void
*/
private static function migrate_from_0_17() {
// migrate followers
foreach ( get_users( array( 'fields' => 'ID' ) ) as $user_id ) {
$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.
*/
@ -105,9 +105,19 @@ class Blog_User extends User {
// get random item of $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() {
$username = \get_option( 'activitypub_blog_user_identifier' );
@ -118,6 +128,11 @@ class Blog_User extends User {
return self::get_default_username();
}
/**
* Get the User-Icon.
*
* @return array|null The User-Icon.
*/
public function get_icon() {
$image = wp_get_attachment_image_src( get_theme_mod( 'custom_logo' ) );
@ -131,6 +146,11 @@ class Blog_User extends User {
return null;
}
/**
* Get the User-Header-Image.
*
* @return array|null The User-Header-Image.
*/
public function get_header_image() {
if ( \has_header_image() ) {
return array(
@ -175,6 +195,8 @@ class Blog_User extends User {
}
/**
* Get the User-Private-Key.
*
* @param int $user_id
*
* @return mixed