wordpress-event-bridge-for-.../includes/activitypub/model/class-event-source.php

60 lines
1.5 KiB
PHP
Raw Normal View History

2024-11-18 16:07:09 +01:00
<?php
/**
* Event-Source (=ActivityPub Actor that is followed) model.
*
2024-12-05 17:50:17 +01:00
* @package Event_Bridge_For_ActivityPub
2024-11-18 16:07:09 +01:00
* @license AGPL-3.0-or-later
*/
2024-12-07 20:07:47 +01:00
namespace Event_Bridge_For_ActivityPub\ActivityPub\Model;
2024-11-18 16:07:09 +01:00
use Activitypub\Activity\Actor;
2024-12-05 17:50:17 +01:00
use Event_Bridge_For_ActivityPub\ActivityPub\Collection\Event_Sources;
2024-11-18 16:07:09 +01:00
use WP_Error;
/**
* Event-Source (=ActivityPub Actor that is followed) model.
*/
class Event_Source extends Actor {
/**
* Get the Icon URL (Avatar).
*
* @return string The URL to the Avatar.
*/
public function get_icon_url() {
$icon = $this->get_icon();
if ( ! $icon ) {
return '';
}
if ( is_array( $icon ) ) {
return $icon['url'];
}
return $icon;
}
/**
2024-12-05 17:50:17 +01:00
* Convert a Custom-Post-Type input to an \Event_Bridge_For_ActivityPub\ActivityPub\Model\Event_Source.
2024-11-18 16:07:09 +01:00
*
* @param \WP_Post $post The post object.
2024-12-05 17:50:17 +01:00
* @return \Event_Bridge_For_ActivityPub\ActivityPub\Event_Source|WP_Error
2024-11-18 16:07:09 +01:00
*/
public static function init_from_cpt( $post ) {
if ( Event_Sources::POST_TYPE !== $post->post_type ) {
return false;
}
$actor_json = get_post_meta( $post->ID, 'activitypub_actor_json', true );
$object = self::init_from_json( $actor_json );
$object->set__id( $post->ID );
$object->set_id( $post->guid );
$object->set_name( $post->post_title );
$object->set_summary( $post->post_excerpt );
$object->set_published( gmdate( 'Y-m-d H:i:s', strtotime( $post->post_date ) ) );
$object->set_updated( gmdate( 'Y-m-d H:i:s', strtotime( $post->post_modified ) ) );
return $object;
}
}