| 1 |
<?php |
| 2 |
|
| 3 |
namespace Activitypub; |
| 4 |
|
| 5 |
/** |
| 6 |
* Notification class. |
| 7 |
*/ |
| 8 |
class Notification { |
| 9 |
/** |
| 10 |
* The type of the notification. |
| 11 |
* |
| 12 |
* @var string |
| 13 |
*/ |
| 14 |
public $type; |
| 15 |
|
| 16 |
/** |
| 17 |
* The actor URL. |
| 18 |
* |
| 19 |
* @var string |
| 20 |
*/ |
| 21 |
public $actor; |
| 22 |
|
| 23 |
/** |
| 24 |
* The Activity object. |
| 25 |
* |
| 26 |
* @var array |
| 27 |
*/ |
| 28 |
public $object; |
| 29 |
|
| 30 |
/** |
| 31 |
* The WordPress User-Id. |
| 32 |
* |
| 33 |
* @var int |
| 34 |
*/ |
| 35 |
public $target; |
| 36 |
|
| 37 |
/** |
| 38 |
* Notification constructor. |
| 39 |
* |
| 40 |
* @param string $type The type of the notification. |
| 41 |
* @param string $actor The actor URL. |
| 42 |
* @param array $object The Activity object. |
| 43 |
* @param int $target The WordPress User-Id. |
| 44 |
*/ |
| 45 |
public function __construct( $type, $actor, $object, $target ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.objectFound |
| 46 |
$this->type = $type; |
| 47 |
$this->actor = $actor; |
| 48 |
$this->object = $object; |
| 49 |
$this->target = $target; |
| 50 |
} |
| 51 |
|
| 52 |
/** |
| 53 |
* Send the notification. |
| 54 |
*/ |
| 55 |
public function send() { |
| 56 |
$type = \strtolower( $this->type ); |
| 57 |
|
| 58 |
do_action( 'activitypub_notification', $this ); |
| 59 |
do_action( "activitypub_notification_{$type}", $this ); |
| 60 |
} |
| 61 |
} |
| 62 |
|