Compare commits

..

No commits in common. "993fc2b24f9b9914cbcc6d3189b8ec537bee327a" and "228dba06ae166f709abb955209057301da7e6c7b" have entirely different histories.

3 changed files with 44 additions and 4 deletions

View file

@ -174,9 +174,7 @@ abstract class Event extends Post {
}
/**
* Compose a human readable formatted time.
*
* @param ?string $time The time which needs to be formatted
* Compose a human readable formatted time from the parameter $time.
*/
private static function format_time( $time ) {
if ( is_null( $time ) ) {

View file

@ -150,6 +150,23 @@ final class Events_Manager extends Event_Transformer {
return count( $em_bookings->bookings );
}
/**
* Hardcoded function for generating a summary.
*/
public function get_summary(): ?string {
if ( $this->em_event->post_excerpt ) {
$excerpt = $this->em_event->post_excerpt;
} else {
$excerpt = $this->get_content();
}
$address = $this->em_event->get_location()->location_name;
$start_time = strtotime( $this->get_start_time() );
$datetime_format = get_option( 'date_format' ) . ' ' . get_option( 'time_format' );
$start_time_string = wp_date( $datetime_format, $start_time );
$summary = "📍 {$address}\n📅 {$start_time_string}\n\n{$excerpt}";
return $summary;
}
/**
* Get the event link as an ActivityPub Link object, but as an associative array.
*

View file

@ -129,6 +129,31 @@ final class GatherPress extends Event {
return $user->get_url();
}
/**
* Create a custom summary.
*
* It contains also the most important meta-information. The summary is often used when the
* ActivityPub object type 'Event' is not supported, e.g. in Mastodon.
*
* @return string $summary The custom event summary.
*/
public function get_summary(): string {
if ( $this->wp_object->excerpt ) {
$excerpt = $this->wp_object->post_excerpt;
} elseif ( get_post_meta( $this->wp_object->ID, 'event-summary', true ) ) {
$excerpt = get_post_meta( $this->wp_object->ID, 'event-summary', true );
} else {
$excerpt = $this->get_content();
}
$address = get_post_meta( $this->wp_object->ID, 'event-location', true );
$start_time = get_post_meta( $this->wp_object->ID, 'event-start-date', true );
$datetime_format = get_option( 'date_format' ) . ' ' . get_option( 'time_format' );
$start_time_string = wp_date( $datetime_format, $start_time );
$summary = "📍 {$address}\n📅 {$start_time_string}\n\n{$excerpt}";
return $summary;
}
/**
* Get the content.
*/