changed content/summary logic and removed the racecondition
Some checks failed
PHP Code Checker / PHP Code Checker (pull_request) Failing after 40s
PHPUnit / PHPUnit – PHP 8.1 (pull_request) Successful in 1m5s
PHPUnit / PHPUnit – PHP 8.2 (pull_request) Successful in 1m7s
PHPUnit / PHPUnit – PHP 8.3 (pull_request) Successful in 1m6s

This commit is contained in:
ruru4143 2024-09-30 18:55:59 +02:00
parent 64bf5b2a58
commit 66e06655c2
2 changed files with 23 additions and 52 deletions

View file

@ -231,15 +231,13 @@ abstract class Event extends Post {
* @return string $summary The custom event summary. * @return string $summary The custom event summary.
*/ */
public function get_summary(): ?string { public function get_summary(): ?string {
// this will result in race conditions and is imho a bad idea. // todo when do we add the filter? we could add it and just keep it?
// - either use the (userdefined) template of the activitypub plugin as it is. add_filter( 'activitypub_object_content_template', array( self::class, 'remove_ap_permalink_from_template' ), 2, 2);
// - 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->get_excerpt(); $excerpt = $this->get_excerpt();
// BeforeFirstRelease: decide whether this should be a admin setting. // BeforeFirstRelease: decide whether this should be a admin setting.
$fallback_to_content = true; $fallback_to_content = true;
if ( is_null( $excerpt ) && $fallback_to_content ) { if ( is_null( $excerpt ) && $fallback_to_content ) {
$excerpt = $this->get_content(); $excerpt = parent::get_content();
} }
remove_filter( 'activitypub_object_content_template', array( self::class, 'remove_ap_permalink_from_template' ) ); remove_filter( 'activitypub_object_content_template', array( self::class, 'remove_ap_permalink_from_template' ) );
@ -284,10 +282,17 @@ abstract class Event extends Post {
* used when converting a object, where the URL is usually appended anyway. * used when converting a object, where the URL is usually appended anyway.
* *
* @param string $template The template string. * @param string $template The template string.
* @param WP_Post|WP_Comment $wp_object The wp_object which was used to select the template.
*
*/ */
public static function remove_ap_permalink_from_template( $template ) { public static function remove_ap_permalink_from_template( $template, $wp_object ) {
$template = str_replace( '[ap_permalink]', '', $template );
$template = str_replace( '[ap_permalink type="html"]', '', $template ); // we could override the template here, to get out custom template from an option.
if ( $wp_object->post_type === "event" ) {
$template = str_replace( '[ap_permalink]', '', $template );
$template = str_replace( '[ap_permalink type="html"]', '', $template );
}
return $template; return $template;
} }
@ -328,32 +333,19 @@ abstract class Event extends Post {
} }
/** /**
* Gets the template to use to generate the content of the event. * Returns the content for the ActivityPub Item with
* *
* @return string The Template. * The content will be generated based on the user settings.
*
* @return string The content.
*/ */
protected function get_post_content_template() {
return "[ap_content]\n\n[ap_hashtags]";
// Decide: what kind of control does the user get?
// e.g. we could give the user way more control by only overriding (some) defaults like this:
/**
$type = \get_option( 'activitypub_post_content_type', 'content' );
switch ( $type ) {
case 'content':
return "[ap_content]\n\n[ap_hashtags]";
break;
default:
return parent::get_post_content_template();
break;
}
**/
}
protected function get_content() { protected function get_content() {
// /BeforeFirstRelease:
// * [ ] remove link at the end of the content.
// * [ ] add organizer.
// * [ ] do add Cancelled reason in the content.
// return parent::get_content();
return $this->wp_object->post_content; return $this->wp_object->post_content;
} }
} }

View file

@ -119,27 +119,6 @@ final class The_Events_Calendar extends Event {
return false; return false;
} }
/**
* Returns the content for the ActivityPub Item with
*
* The content will be generated based on the user settings.
*
* @return string The content.
*/
protected function get_content() {
// /BeforeFirstRelease:
// * [X] remove link at the end of the content.
// * [ ] add organizer.
// * [ ] do add Cancelled reason in the content.
// Add Organizer:
// $this->wp_object->post_content .= organizer_string;
// rest will be handled by parent::get_content().
$content = parent::get_content();
return $content;
}
/** /**
* Get the event location. * Get the event location.
* *