2024-08-16 10:55:16 +00:00
|
|
|
<?php
|
2024-10-07 11:25:51 +00:00
|
|
|
/**
|
|
|
|
* Like handler file.
|
|
|
|
*
|
|
|
|
* @package Activitypub
|
|
|
|
*/
|
|
|
|
|
2024-08-16 10:55:16 +00:00
|
|
|
namespace Activitypub\Handler;
|
|
|
|
|
|
|
|
use Activitypub\Comment;
|
|
|
|
use Activitypub\Collection\Interactions;
|
|
|
|
|
|
|
|
use function Activitypub\object_to_uri;
|
|
|
|
|
|
|
|
/**
|
2024-10-07 11:25:51 +00:00
|
|
|
* Handle Like requests.
|
2024-08-16 10:55:16 +00:00
|
|
|
*/
|
|
|
|
class Like {
|
|
|
|
/**
|
2024-10-07 11:25:51 +00:00
|
|
|
* Initialize the class, registering WordPress hooks.
|
2024-08-16 10:55:16 +00:00
|
|
|
*/
|
|
|
|
public static function init() {
|
|
|
|
\add_action(
|
|
|
|
'activitypub_inbox_like',
|
|
|
|
array( self::class, 'handle_like' ),
|
|
|
|
10,
|
|
|
|
3
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2024-10-07 11:25:51 +00:00
|
|
|
* Handles "Like" requests.
|
2024-08-16 10:55:16 +00:00
|
|
|
*
|
2024-10-07 11:25:51 +00:00
|
|
|
* @param array $array The Activity array.
|
|
|
|
* @param int $user_id The ID of the local blog user.
|
|
|
|
* @param \Activitypub\Activity\Activity $activity The Activity object.
|
2024-08-16 10:55:16 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public static function handle_like( $array, $user_id, $activity = null ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.arrayFound,VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable,Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed
|
|
|
|
if ( ACTIVITYPUB_DISABLE_INCOMING_INTERACTIONS ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$url = object_to_uri( $array['object'] );
|
|
|
|
|
|
|
|
if ( empty( $url ) ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$exists = Comment::object_id_to_comment( esc_url_raw( $url ) );
|
|
|
|
if ( $exists ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$state = Interactions::add_reaction( $array );
|
|
|
|
$reaction = null;
|
|
|
|
|
|
|
|
if ( $state && ! is_wp_error( $state ) ) {
|
|
|
|
$reaction = get_comment( $state );
|
|
|
|
}
|
|
|
|
|
|
|
|
do_action( 'activitypub_handled_like', $array, $user_id, $state, $reaction );
|
|
|
|
}
|
|
|
|
}
|