| 1 |
<?php |
| 2 |
namespace Activitypub\Integration; |
| 3 |
|
| 4 |
/** |
| 5 |
* Stream Connector for ActivityPub |
| 6 |
* |
| 7 |
* This class is a Stream Connector for the Stream plugin. |
| 8 |
* |
| 9 |
* @see https://wordpress.org/plugins/stream/ |
| 10 |
*/ |
| 11 |
class Stream_Connector extends \WP_Stream\Connector { |
| 12 |
/** |
| 13 |
* Connector slug |
| 14 |
* |
| 15 |
* @var string |
| 16 |
*/ |
| 17 |
public $name = 'activitypub'; |
| 18 |
|
| 19 |
/** |
| 20 |
* Actions registered for this connector |
| 21 |
* |
| 22 |
* @var array |
| 23 |
*/ |
| 24 |
public $actions = array( |
| 25 |
'activitypub_notification_follow', |
| 26 |
); |
| 27 |
|
| 28 |
/** |
| 29 |
* Return translated connector label |
| 30 |
* |
| 31 |
* @return string |
| 32 |
*/ |
| 33 |
public function get_label() { |
| 34 |
return __( 'ActivityPub', 'activitypub' ); |
| 35 |
} |
| 36 |
|
| 37 |
/** |
| 38 |
* Return translated context labels |
| 39 |
* |
| 40 |
* @return array |
| 41 |
*/ |
| 42 |
public function get_context_labels() { |
| 43 |
return array(); |
| 44 |
} |
| 45 |
|
| 46 |
/** |
| 47 |
* Return translated action labels |
| 48 |
* |
| 49 |
* @return array |
| 50 |
*/ |
| 51 |
public function get_action_labels() { |
| 52 |
return array(); |
| 53 |
} |
| 54 |
|
| 55 |
/** |
| 56 |
* Callback for activitypub_notification_follow |
| 57 |
* |
| 58 |
* @param \Activitypub\Notification $notification The notification object |
| 59 |
* |
| 60 |
* @return void |
| 61 |
*/ |
| 62 |
public function callback_activitypub_notification_follow( $notification ) { |
| 63 |
$this->log( |
| 64 |
sprintf( |
| 65 |
// translators: %s is a URL |
| 66 |
__( 'New Follower: %s', 'activitypub' ), |
| 67 |
$notification->actor |
| 68 |
), |
| 69 |
array( |
| 70 |
'notification' => \wp_json_encode( $notification, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE ), |
| 71 |
), |
| 72 |
null, |
| 73 |
'notification', |
| 74 |
$notification->type, |
| 75 |
$notification->target |
| 76 |
); |
| 77 |
} |
| 78 |
} |
| 79 |
|