mirror of
https://github.com/Automattic/wordpress-activitypub
synced 2024-10-18 17:43:33 +00:00
00a57c39a4
* PHPCS: Enable Commenting sniff * Apply suggestions from code review Co-authored-by: Matthias Pfefferle <pfefferle@users.noreply.github.com> * Fix param alignment. --------- Co-authored-by: Matthias Pfefferle <pfefferle@users.noreply.github.com>
65 lines
1.5 KiB
PHP
65 lines
1.5 KiB
PHP
<?php
|
|
/**
|
|
* Like handler file.
|
|
*
|
|
* @package Activitypub
|
|
*/
|
|
|
|
namespace Activitypub\Handler;
|
|
|
|
use Activitypub\Comment;
|
|
use Activitypub\Collection\Interactions;
|
|
|
|
use function Activitypub\object_to_uri;
|
|
|
|
/**
|
|
* Handle Like requests.
|
|
*/
|
|
class Like {
|
|
/**
|
|
* Initialize the class, registering WordPress hooks.
|
|
*/
|
|
public static function init() {
|
|
\add_action(
|
|
'activitypub_inbox_like',
|
|
array( self::class, 'handle_like' ),
|
|
10,
|
|
3
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Handles "Like" requests.
|
|
*
|
|
* @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.
|
|
*
|
|
* @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 );
|
|
}
|
|
}
|