PluginProbe
ActivityPub / 3.2.3
ActivityPub v3.2.3
9.3.1 9.3.0 9.2.2 9.2.1 9.2.0 9.1.0 9.0.2 9.0.1 9.0.0 8.3.0 8.2.1 8.2.0 8.1.1 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.2.0 1.3.0 2.0.0 2.0.1 2.1.0 2.1.1 All 160 releases
activitypub / includes / handler / class-like.php

class-like.php in ActivityPub 3.2.3, at includes/handler/class-like.php

60 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Activitypub\Handler;
3
4 use Activitypub\Comment;
5 use Activitypub\Collection\Interactions;
6
7 use function Activitypub\object_to_uri;
8
9 /**
10 * Handle Like requests
11 */
12 class Like {
13 /**
14 * Initialize the class, registering WordPress hooks
15 */
16 public static function init() {
17 \add_action(
18 'activitypub_inbox_like',
19 array( self::class, 'handle_like' ),
20 10,
21 3
22 );
23 }
24
25 /**
26 * Handles "Like" requests
27 *
28 * @param array $array The Activity array.
29 * @param int $user_id The ID of the local blog user.
30 * @param \Activitypub\Activity $activity The Activity object.
31 *
32 * @return void
33 */
34 public static function handle_like( $array, $user_id, $activity = null ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.arrayFound,VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable,Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed
35 if ( ACTIVITYPUB_DISABLE_INCOMING_INTERACTIONS ) {
36 return;
37 }
38
39 $url = object_to_uri( $array['object'] );
40
41 if ( empty( $url ) ) {
42 return;
43 }
44
45 $exists = Comment::object_id_to_comment( esc_url_raw( $url ) );
46 if ( $exists ) {
47 return;
48 }
49
50 $state = Interactions::add_reaction( $array );
51 $reaction = null;
52
53 if ( $state && ! is_wp_error( $state ) ) {
54 $reaction = get_comment( $state );
55 }
56
57 do_action( 'activitypub_handled_like', $array, $user_id, $state, $reaction );
58 }
59 }
60