60 lines
1.5 KiB
PHP
60 lines
1.5 KiB
PHP
|
<?php
|
||
|
/**
|
||
|
* Event-Source (=ActivityPub Actor that is followed) model.
|
||
|
*
|
||
|
* @package ActivityPub_Event_Bridge
|
||
|
* @license AGPL-3.0-or-later
|
||
|
*/
|
||
|
|
||
|
namespace ActivityPub_Event_Bridge\ActivityPub;
|
||
|
|
||
|
use Activitypub\Activity\Actor;
|
||
|
use ActivityPub_Event_Bridge\ActivityPub\Collection\Event_Sources;
|
||
|
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;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Convert a Custom-Post-Type input to an \ActivityPub_Event_Bridge\ActivityPub\Model\Event_Source.
|
||
|
*
|
||
|
* @param \WP_Post $post The post object.
|
||
|
* @return \ActivityPub_Event_Bridge\ActivityPub\Event_Source|WP_Error
|
||
|
*/
|
||
|
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;
|
||
|
}
|
||
|
}
|