| 1 |
<?php |
| 2 |
namespace Activitypub\Handler; |
| 3 |
|
| 4 |
use Activitypub\Http; |
| 5 |
|
| 6 |
use function Activitypub\is_activity_public; |
| 7 |
|
| 8 |
/** |
| 9 |
* Handle Create requests |
| 10 |
*/ |
| 11 |
class Announce { |
| 12 |
/** |
| 13 |
* Initialize the class, registering WordPress hooks |
| 14 |
*/ |
| 15 |
public static function init() { |
| 16 |
\add_action( |
| 17 |
'activitypub_inbox_announce', |
| 18 |
array( self::class, 'handle_announce' ), |
| 19 |
10, |
| 20 |
3 |
| 21 |
); |
| 22 |
} |
| 23 |
|
| 24 |
/** |
| 25 |
* Handles "Announce" requests |
| 26 |
* |
| 27 |
* @param array $array The activity-object |
| 28 |
* @param int $user_id The id of the local blog-user |
| 29 |
* @param Activitypub\Activity $activity The activity object |
| 30 |
* |
| 31 |
* @return void |
| 32 |
*/ |
| 33 |
public static function handle_announce( $array, $user_id, $activity = null ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.arrayFound |
| 34 |
if ( ACTIVITYPUB_DISABLE_INCOMING_INTERACTIONS ) { |
| 35 |
return; |
| 36 |
} |
| 37 |
|
| 38 |
if ( ! isset( $array['object'] ) ) { |
| 39 |
return; |
| 40 |
} |
| 41 |
|
| 42 |
// check if Activity is public or not |
| 43 |
if ( ! is_activity_public( $array ) ) { |
| 44 |
// @todo maybe send email |
| 45 |
return; |
| 46 |
} |
| 47 |
|
| 48 |
// @todo save the `Announce`-Activity itself |
| 49 |
|
| 50 |
if ( is_string( $array['object'] ) ) { |
| 51 |
$object = Http::get_remote_object( $array['object'] ); |
| 52 |
} else { |
| 53 |
$object = $array['object']; |
| 54 |
} |
| 55 |
|
| 56 |
if ( ! $object || is_wp_error( $object ) ) { |
| 57 |
return; |
| 58 |
} |
| 59 |
|
| 60 |
if ( ! isset( $object['type'] ) ) { |
| 61 |
return; |
| 62 |
} |
| 63 |
|
| 64 |
$type = \strtolower( $object['type'] ); |
| 65 |
|
| 66 |
\do_action( 'activitypub_inbox', $object, $user_id, $type, $activity ); |
| 67 |
\do_action( "activitypub_inbox_{$type}", $object, $user_id, $activity ); |
| 68 |
} |
| 69 |
} |
| 70 |
|