wordpress-activitypub-event.../includes/activitypub/transformer/class-event.php

80 lines
1.9 KiB
PHP
Raw Normal View History

2024-06-30 14:17:59 +02:00
<?php
/**
* Replace the default ActivityPub Transformer
*
* @package activity-event-transformers
* @license AGPL-3.0-or-later
*/
namespace Activitypub_Event_Extensions\Activitypub\Transformer;
2024-07-05 11:31:46 +02:00
use Activitypub\Activity\Extended_Object\Event as Event_Object;
use Activitypub\Model\Blog;
2024-06-30 14:17:59 +02:00
use Activitypub\Transformer\Post;
2024-07-05 11:31:46 +02:00
use function Activitypub\get_rest_url_by_path;
2024-06-30 14:17:59 +02:00
/**
* Base transformer for WordPress event post types to ActivityPub events.
*/
class Event extends Post {
/**
* Returns the User-URL of the Author of the Post.
*
* If `single_user` mode is enabled, the URL of the Blog-User is returned.
*
* @return string The User-URL.
*/
protected function get_attributed_to() {
$blog = new Blog();
return $blog->get_id();
}
2024-07-05 11:31:46 +02:00
/**
* Returns the ActivityStreams 2.0 Object-Type for an Event.
*
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-event
*
* @return string The Event Object-Type.
*/
protected function get_object_type() {
return 'Event';
}
/**
* Generic function that converts an WP-Event object to an ActivityPub-Event object.
*
* @return Event_Object
*/
public function to_object() {
$activitypub_object = new Event_Object();
$activitypub_object = $this->transform_object_properties( $activitypub_object );
$published = \strtotime( $this->wp_object->post_date_gmt );
$activitypub_object->set_published( \gmdate( 'Y-m-d\TH:i:s\Z', $published ) );
$updated = \strtotime( $this->wp_object->post_modified_gmt );
if ( $updated > $published ) {
$activitypub_object->set_updated( \gmdate( 'Y-m-d\TH:i:s\Z', $updated ) );
}
$activitypub_object->set_content_map(
array(
$this->get_locale() => $this->get_content(),
)
);
$path = sprintf( 'actors/%d/followers', intval( $this->wp_object->post_author ) );
$activitypub_object->set_to(
array(
'https://www.w3.org/ns/activitystreams#Public',
get_rest_url_by_path( $path ),
)
);
return $activitypub_object;
}
2024-06-30 14:17:59 +02:00
}