| 1 |
<?php |
| 2 |
/** |
| 3 |
* Notification file. |
| 4 |
* |
| 5 |
* @package Activitypub |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace Activitypub; |
| 9 |
|
| 10 |
/** |
| 11 |
* Notification class. |
| 12 |
*/ |
| 13 |
class Notification { |
| 14 |
/** |
| 15 |
* The type of the notification. |
| 16 |
* |
| 17 |
* @var string |
| 18 |
*/ |
| 19 |
public $type; |
| 20 |
|
| 21 |
/** |
| 22 |
* The actor URL. |
| 23 |
* |
| 24 |
* @var string |
| 25 |
*/ |
| 26 |
public $actor; |
| 27 |
|
| 28 |
/** |
| 29 |
* The Activity object. |
| 30 |
* |
| 31 |
* @var array |
| 32 |
*/ |
| 33 |
public $object; |
| 34 |
|
| 35 |
/** |
| 36 |
* The WordPress User-Id. |
| 37 |
* |
| 38 |
* @var int |
| 39 |
*/ |
| 40 |
public $target; |
| 41 |
|
| 42 |
/** |
| 43 |
* Notification constructor. |
| 44 |
* |
| 45 |
* @param string $type The type of the notification. |
| 46 |
* @param string $actor The actor URL. |
| 47 |
* @param array $activity The Activity object. |
| 48 |
* @param int $target The WordPress User-Id. |
| 49 |
*/ |
| 50 |
public function __construct( $type, $actor, $activity, $target ) { |
| 51 |
$this->type = $type; |
| 52 |
$this->actor = $actor; |
| 53 |
$this->object = $activity; |
| 54 |
$this->target = $target; |
| 55 |
} |
| 56 |
|
| 57 |
/** |
| 58 |
* Send the notification. |
| 59 |
*/ |
| 60 |
public function send() { |
| 61 |
$type = \strtolower( $this->type ); |
| 62 |
|
| 63 |
/** |
| 64 |
* Action to send ActivityPub notifications. |
| 65 |
* |
| 66 |
* @param Notification $this The notification object. |
| 67 |
*/ |
| 68 |
do_action( 'activitypub_notification', $this ); |
| 69 |
|
| 70 |
/** |
| 71 |
* Type-specific action to send ActivityPub notifications. |
| 72 |
* |
| 73 |
* @param Notification $this The notification object. |
| 74 |
*/ |
| 75 |
do_action( "activitypub_notification_{$type}", $this ); |
| 76 |
} |
| 77 |
} |
| 78 |
|