Compare commits

...

7 commits

Author SHA1 Message Date
a66dc74577 added comments about removing some old stuff
Some checks failed
PHP Code Checker / PHP Code Checker (pull_request) Failing after 36s
PHPUnit / PHPUnit – PHP 8.1 (pull_request) Successful in 1m0s
PHPUnit / PHPUnit – PHP 8.2 (pull_request) Successful in 1m1s
PHPUnit / PHPUnit – PHP 8.3 (pull_request) Successful in 1m3s
2024-09-29 12:52:17 +02:00
516bfd33d8 fixed wrong nullable type declaration 2024-09-29 11:45:17 +02:00
c469b7a00e made format_time() private 2024-09-29 11:44:47 +02:00
39632560ff added comments 2024-09-29 11:44:21 +02:00
f0b73d8674 duplicated code 2024-09-29 11:44:14 +02:00
7c9424526d improved readability of get_summary by using ternary operator 2024-09-29 11:43:59 +02:00
f99f009e2e splitted up format time function 2024-09-29 11:42:52 +02:00
4 changed files with 28 additions and 23 deletions

View file

@ -161,11 +161,19 @@ abstract class Event extends Post {
/**
* Compose a human readable formatted start time.
*
* @param bool $is_start_time Whether format the events start or end time.
*/
protected function format_time( $is_start_time = true ) {
$time = $is_start_time ? $this->get_start_time() : $this->get_end_time();
protected function format_start_time(): string {
return $this->format_time( $this->get_start_time() );
}
/**
* Compose a human readable formatted end time.
*/
protected function format_end_time(): string {
return $this->format_time( $this->get_end_time() );
}
static private function format_time( $time ) {
if ( is_null( $time ) ) {
return '';
}
@ -218,6 +226,9 @@ abstract class Event extends Post {
* @return string $summary The custom event summary.
*/
public function get_summary(): ?string {
// this will result in race conditions and is imho a bad idea
// - either use the (userdefined) template of the activitypub plugin as it is
// - or implement our own templating (based on the activitypub plugin templates / by reusing their code heavily)
add_filter( 'activitypub_object_content_template', array( self::class, 'remove_ap_permalink_from_template' ), 2 );
$excerpt = $this->extract_excerpt();
// BeforeFirstRelease: decide whether this should be a admin setting.
@ -228,8 +239,8 @@ abstract class Event extends Post {
remove_filter( 'activitypub_object_content_template', array( self::class, 'remove_ap_permalink_from_template' ) );
$category = $this->format_category();
$start_time = $this->format_time();
$end_time = $this->format_time( false );
$start_time = $this->format_start_time();
$end_time = $this->format_end_time();
$address = $this->format_address();
$formatted_items = array();
@ -304,7 +315,7 @@ abstract class Event extends Post {
$activitypub_object->set_to(
array(
'https://www.w3.org/ns/activitystreams#Public',
$this->get_actor_object()->get_followers(),
$this->get_actor_object()->get_followers(), // this fails on my machine
)
);

View file

@ -45,7 +45,7 @@ final class Events_Manager extends Event_Transformer {
* @access public
* @return string Widget name.
*/
public function get_transformer_name() {
public function get_transformer_name() { // todo can we remove this or is this in use?
return 'activitypub-event-transformers/events-manager';
}
@ -58,7 +58,7 @@ final class Events_Manager extends Event_Transformer {
* @access public
* @return string Widget title.
*/
public function get_transformer_label() {
public function get_transformer_label() { // todo can we remove this or is this in use?
return 'Events Manager';
}
@ -71,7 +71,7 @@ final class Events_Manager extends Event_Transformer {
* @access public
* @return array Widget categories.
*/
public static function get_supported_post_types() {
public static function get_supported_post_types() { // todo can we remove this or is this in use?
return array();
}

View file

@ -29,7 +29,7 @@ final class GatherPress extends Event {
*
* @var Event
*/
protected $ap_object;
protected $ap_object; // todo can we remove this or is this in use?
/**
* The current GatherPress Event object.
@ -69,7 +69,7 @@ final class GatherPress extends Event {
* @access public
* @return array Widget categories.
*/
public static function get_supported_post_types() {
public static function get_supported_post_types() { // todo can we remove this or is this in use?
return array( GatherPress_Event::POST_TYPE );
}
@ -158,13 +158,9 @@ final class GatherPress extends Event {
* @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();
}
$excerpt = $this->wp_object->post_excerpt
?: get_post_meta( $this->wp_object->ID, 'event-summary', true )
?: $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 );

View file

@ -28,7 +28,7 @@ final class VS_Event_List extends Event_Transformer {
*
* @var Event
*/
protected $ap_object;
protected $ap_object; // todo can we remove this or is this in use?
/**
* Get the event location.
@ -113,10 +113,8 @@ final class VS_Event_List extends Event_Transformer {
protected function get_excerpt(): ?string {
if ( get_post_meta( $this->wp_object->ID, 'event-summary', true ) ) {
return get_post_meta( $this->wp_object->ID, 'event-summary', true );
} elseif ( $this->wp_object->excerpt ) {
return $this->wp_object->post_excerpt;
} else {
return null;
return parent::extract_excerpt(); // todo naming not uniform
}
}
}