modified file smtp-mailer

This commit is contained in:
2024-06-27 12:11:15 +00:00
committed by Gitium
parent 91db4aebe1
commit 19e351ef3b
1005 changed files with 230351 additions and 8670 deletions

View File

@ -98,6 +98,11 @@ class Activity_Dispatcher {
return;
}
// do not announce replies
if ( $wp_object instanceof WP_Comment ) {
return;
}
$transformer = Factory::get_transformer( $wp_object );
$transformer->change_wp_user_id( Users::BLOG_USER_ID );

View File

@ -276,7 +276,7 @@ class Comment {
}
// check for local comment
if ( \wp_parse_url( \site_url(), \PHP_URL_HOST ) === \wp_parse_url( $url, \PHP_URL_HOST ) ) {
if ( \wp_parse_url( \home_url(), \PHP_URL_HOST ) === \wp_parse_url( $url, \PHP_URL_HOST ) ) {
$query = \wp_parse_url( $url, \PHP_URL_QUERY );
if ( $query ) {
@ -379,12 +379,7 @@ class Comment {
}
// generate URI based on comment ID
return \add_query_arg(
array(
'c' => $comment->comment_ID,
),
\trailingslashit( site_url() )
);
return \add_query_arg( 'c', $comment->comment_ID, \home_url() );
}
/**

View File

@ -27,7 +27,7 @@ class Health_Check {
}
public static function add_tests( $tests ) {
if ( ! is_user_type_disabled( 'user' ) ) {
if ( ! is_user_disabled( get_current_user_id() ) ) {
$tests['direct']['activitypub_test_author_url'] = array(
'label' => \__( 'Author URL test', 'activitypub' ),
'test' => array( self::class, 'test_author_url' ),

View File

@ -66,14 +66,26 @@ class Http {
/**
* Send a GET Request with the needed HTTP Headers
*
* @param string $url The URL endpoint
* @param int $user_id The WordPress User-ID
* @param string $url The URL endpoint
* @param bool|int $cached If the result should be cached, or its duration. Default: 1hr.
*
* @return array|WP_Error The GET Response or an WP_ERROR
*/
public static function get( $url ) {
public static function get( $url, $cached = false ) {
\do_action( 'activitypub_pre_http_get', $url );
if ( $cached ) {
$transient_key = self::generate_cache_key( $url );
$response = \get_transient( $transient_key );
if ( $response ) {
\do_action( 'activitypub_safe_remote_get_response', $response, $url );
return $response;
}
}
$date = \gmdate( 'D, d M Y H:i:s T' );
$signature = Signature::generate_signature( Users::APPLICATION_USER_ID, 'get', $url, $date );
@ -108,6 +120,14 @@ class Http {
\do_action( 'activitypub_safe_remote_get_response', $response, $url );
if ( $cached ) {
$cache_duration = $cached;
if ( ! is_int( $cache_duration ) ) {
$cache_duration = HOUR_IN_SECONDS;
}
\set_transient( $transient_key, $response, $cache_duration );
}
return $response;
}
@ -130,4 +150,8 @@ class Http {
return false;
}
public static function generate_cache_key( $url ) {
return 'activitypub_http_' . \md5( $url );
}
}

View File

@ -253,6 +253,11 @@ class Scheduler {
} elseif ( empty( $meta ) || ! is_array( $meta ) || is_wp_error( $meta ) ) {
if ( $follower->count_errors() >= 5 ) {
$follower->delete();
\wp_schedule_single_event(
\time(),
'activitypub_delete_actor_interactions',
array( $follower->get_id() )
);
} else {
Followers::add_error( $follower->get__id(), $meta );
}

View File

@ -379,10 +379,10 @@ class Signature {
if ( \preg_match( '/keyId="(.*?)"/ism', $signature, $matches ) ) {
$parsed_header['keyId'] = trim( $matches[1] );
}
if ( \preg_match( '/created=([0-9]*)/ism', $signature, $matches ) ) {
if ( \preg_match( '/created=["|\']*([0-9]*)["|\']*/ism', $signature, $matches ) ) {
$parsed_header['(created)'] = trim( $matches[1] );
}
if ( \preg_match( '/expires=([0-9]*)/ism', $signature, $matches ) ) {
if ( \preg_match( '/expires=["|\']*([0-9]*)["|\']*/ism', $signature, $matches ) ) {
$parsed_header['(expires)'] = trim( $matches[1] );
}
if ( \preg_match( '/algorithm="(.*?)"/ism', $signature, $matches ) ) {
@ -434,12 +434,22 @@ class Signature {
// created in future
return false;
}
if ( ! array_key_exists( '(created)', $headers ) ) {
$signed_data .= $header . ': ' . $signature_block['(created)'] . "\n";
continue;
}
}
if ( '(expires)' === $header ) {
if ( ! empty( $signature_block['(expires)'] ) && \intval( $signature_block['(expires)'] ) < \time() ) {
// expired in past
return false;
}
if ( ! array_key_exists( '(expires)', $headers ) ) {
$signed_data .= $header . ': ' . $signature_block['(expires)'] . "\n";
continue;
}
}
if ( 'date' === $header ) {
// allow a bit of leeway for misconfigured clocks.

View File

@ -4,6 +4,7 @@ namespace Activitypub\Collection;
use WP_Error;
use WP_Comment_Query;
use function Activitypub\object_to_uri;
use function Activitypub\url_to_commentid;
use function Activitypub\object_id_to_comment;
use function Activitypub\get_remote_metadata_by_actor;
@ -46,7 +47,8 @@ class Interactions {
return false;
}
$meta = get_remote_metadata_by_actor( $activity['actor'] );
$actor = object_to_uri( $activity['actor'] );
$meta = get_remote_metadata_by_actor( $actor );
if ( ! $meta || \is_wp_error( $meta ) ) {
return false;

View File

@ -7,6 +7,7 @@ use Activitypub\Model\User;
use Activitypub\Model\Blog_User;
use Activitypub\Model\Application_User;
use function Activitypub\object_to_uri;
use function Activitypub\url_to_authorid;
use function Activitypub\is_user_disabled;
@ -136,6 +137,8 @@ class Users {
* @return \Acitvitypub\Model\User The User.
*/
public static function get_by_resource( $resource ) {
$resource = object_to_uri( $resource );
$scheme = 'acct';
$match = array();
// try to extract the scheme and the host

View File

@ -52,6 +52,17 @@ function get_remote_metadata_by_actor( $actor, $cached = true ) {
if ( $pre ) {
return $pre;
}
if ( is_array( $actor ) ) {
if ( array_key_exists( 'id', $actor ) ) {
$actor = $actor['id'];
} elseif ( array_key_exists( 'url', $actor ) ) {
$actor = $actor['url'];
} else {
return new WP_Error( 'activitypub_no_valid_actor_identifier', \__( 'The "actor" identifier is not valid', 'activitypub' ), array( 'status' => 404, 'actor' => $actor ) );
}
}
if ( preg_match( '/^@?' . ACTIVITYPUB_USERNAME_REGEXP . '$/i', $actor ) ) {
$actor = Webfinger::resolve( $actor );
}
@ -134,7 +145,7 @@ function url_to_authorid( $url ) {
global $wp_rewrite;
// check if url hase the same host
if ( \wp_parse_url( \site_url(), \PHP_URL_HOST ) !== \wp_parse_url( $url, \PHP_URL_HOST ) ) {
if ( \wp_parse_url( \home_url(), \PHP_URL_HOST ) !== \wp_parse_url( $url, \PHP_URL_HOST ) ) {
return 0;
}

View File

@ -4,6 +4,8 @@ namespace Activitypub\Handler;
use Activitypub\Collection\Users;
use Activitypub\Collection\Followers;
use function Activitypub\object_to_uri;
/**
* Handle Undo requests
*/
@ -28,10 +30,10 @@ class Undo {
if (
isset( $activity['object']['type'] ) &&
'Follow' === $activity['object']['type'] &&
isset( $activity['object']['object'] ) &&
filter_var( $activity['object']['object'], FILTER_VALIDATE_URL )
isset( $activity['object']['object'] )
) {
$user = Users::get_by_resource( $activity['object']['object'] );
$user_id = object_to_uri( $activity['object']['object'] );
$user = Users::get_by_resource( $user_id );
if ( ! $user || is_wp_error( $user ) ) {
// If we can not find a user,
@ -40,8 +42,9 @@ class Undo {
}
$user_id = $user->get__id();
$actor = object_to_uri( $activity['actor'] );
Followers::remove_follower( $user_id, $activity['actor'] );
Followers::remove_follower( $user_id, $actor );
}
}
}

View File

@ -343,10 +343,10 @@ class Post extends Base {
case 'core/cover':
if ( ! empty( $block['attrs']['id'] ) ) {
$alt = '';
$check = preg_match( '/<img.*?alt=[\"\'](.*?)[\"\'].*>/i', $block['innerHTML'], $match );
$check = preg_match( '/<img.*?alt\s*=\s*([\"\'])(.*?)\1.*>/i', $block['innerHTML'], $match );
if ( $check ) {
$alt = $match[1];
$alt = $match[2];
}
$media['image'][] = array(
@ -432,8 +432,8 @@ class Post extends Base {
/**
* Filter the image URL returned for each post.
*
* @param array|false $thumbnail The image URL, or false if no image is available.
* @param int $id The attachment ID.
* @param array|false $thumbnail The image URL, or false if no image is available.
* @param int $id The attachment ID.
* @param string $image_size The image size to retrieve. Set to 'full' by default.
*/
$thumbnail = apply_filters(
@ -451,11 +451,11 @@ class Post extends Base {
);
if ( ! empty( $media['alt'] ) ) {
$image['name'] = \esc_attr( $media['alt'] );
$image['name'] = \wp_strip_all_tags( \html_entity_decode( $media['alt'] ) );
} else {
$alt = \get_post_meta( $id, '_wp_attachment_image_alt', true );
if ( $alt ) {
$image['name'] = \esc_attr( $alt );
$image['name'] = \wp_strip_all_tags( \html_entity_decode( $alt ) );
}
}