Add Event Sources Logic (ActivityPub follows) #86
6 changed files with 31 additions and 36 deletions
|
@ -10,9 +10,8 @@
|
|||
namespace Event_Bridge_For_ActivityPub\ActivityPub\Transmogrifier;
|
||||
|
||||
use Activitypub\Activity\Extended_Object\Event;
|
||||
use DateTime;
|
||||
use Event_Bridge_For_ActivityPub\ActivityPub\Model\Event_Source;
|
||||
use Event_Bridge_For_ActivityPub\ActivityPub\Collection\Event_Sources;
|
||||
use Exception;
|
||||
use WP_Error;
|
||||
|
||||
use function Activitypub\sanitize_url;
|
||||
|
@ -33,6 +32,13 @@ abstract class Base {
|
|||
*/
|
||||
protected $activitypub_event;
|
||||
|
||||
/**
|
||||
* The current Event object.
|
||||
*
|
||||
* @var Event_Source
|
||||
*/
|
||||
protected $event_source;
|
||||
|
||||
/**
|
||||
* Internal function to actually save the event.
|
||||
*
|
||||
|
@ -54,6 +60,7 @@ abstract class Base {
|
|||
}
|
||||
|
||||
$this->activitypub_event = $activitypub_event;
|
||||
$this->event_source = $event_source;
|
||||
|
||||
$post_id = $this->save_event();
|
||||
|
||||
|
@ -67,7 +74,6 @@ abstract class Base {
|
|||
'event_bridge_for_activitypub_write_log',
|
||||
array( "[ACTIVITYPUB] Processed incoming event {$event_id} from {$event_source_activitypub_id}" )
|
||||
);
|
||||
update_post_meta( $post_id, '_event_bridge_for_activitypub_is_remote_cached', true );
|
||||
update_post_meta( $post_id, '_event_bridge_for_activitypub_event_source', absint( $event_source_post_id ) );
|
||||
update_post_meta( $post_id, 'activitypub_content_visibility', constant( 'ACTIVITYPUB_CONTENT_VISIBILITY_LOCAL' ) ?? '' );
|
||||
} else {
|
||||
|
|
|
@ -96,7 +96,7 @@ class The_Events_Calendar extends Base {
|
|||
}
|
||||
}
|
||||
|
||||
if ( $post_id && get_post_meta( $post_id, '_event_bridge_for_activitypub_is_remote_cached', true ) ) {
|
||||
if ( $post_id && get_post_meta( $post_id, '_event_bridge_for_activitypub_event_source', true ) ) {
|
||||
$result = tribe_venues()->where( 'id', $post_id )->set_args( $this->get_venue_args( $location ) )->save();
|
||||
if ( array_key_exists( $post_id, $result ) && $result[ $post_id ] ) {
|
||||
return $post_id;
|
||||
|
@ -105,7 +105,7 @@ class The_Events_Calendar extends Base {
|
|||
$post = tribe_venues()->set_args( $this->get_venue_args( $location ) )->create();
|
||||
if ( $post ) {
|
||||
$post_id = $post->ID;
|
||||
update_post_meta( $post_id, '_event_bridge_for_activitypub_is_remote_cached', true );
|
||||
update_post_meta( $post_id, '_event_bridge_for_activitypub_event_source', $this->event_source->get__id() );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -90,32 +90,6 @@ class Event_Sources {
|
|||
if ( ! $event_plugin_integration instanceof Feature_Event_Sources && $event_plugin_integration instanceof Event_Plugin_Integration ) {
|
||||
continue;
|
||||
}
|
||||
\register_post_meta(
|
||||
$event_plugin_integration::get_post_type(),
|
||||
'_event_bridge_for_activitypub_is_remote_cached',
|
||||
array(
|
||||
'type' => 'string',
|
||||
'single' => false,
|
||||
'sanitize_callback' => function ( $value ) {
|
||||
return sanitize_url( $value );
|
||||
},
|
||||
)
|
||||
);
|
||||
|
||||
$location_post_type = $event_plugin_integration::get_location_post_type();
|
||||
if ( $location_post_type ) {
|
||||
\register_post_meta(
|
||||
$location_post_type,
|
||||
'_event_bridge_for_activitypub_is_remote_cached',
|
||||
array(
|
||||
'type' => 'string',
|
||||
'single' => false,
|
||||
'sanitize_callback' => function ( $value ) {
|
||||
return sanitize_url( $value );
|
||||
},
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
\register_post_meta(
|
||||
$event_plugin_integration::get_post_type(),
|
||||
|
@ -126,6 +100,21 @@ class Event_Sources {
|
|||
'sanitize_callback' => 'absint',
|
||||
)
|
||||
);
|
||||
|
||||
$location_post_type = $event_plugin_integration::get_location_post_type();
|
||||
if ( $location_post_type ) {
|
||||
\register_post_meta(
|
||||
$location_post_type,
|
||||
'_event_bridge_for_activitypub_event_source',
|
||||
array(
|
||||
'type' => 'string',
|
||||
'single' => false,
|
||||
'sanitize_callback' => function ( $value ) {
|
||||
return sanitize_url( $value );
|
||||
},
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -205,7 +194,7 @@ class Event_Sources {
|
|||
* @return bool
|
||||
*/
|
||||
public static function is_cached_external_event_post( $post ): bool {
|
||||
if ( get_post_meta( $post->ID, '_event_bridge_for_activitypub_is_remote_cached', true ) ) {
|
||||
if ( get_post_meta( $post->ID, '_event_bridge_for_activitypub_event_source', true ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -103,7 +103,7 @@ final class GatherPress extends Event_Plugin_Integration implements Feature_Even
|
|||
WHERE {$wpdb->prefix}posts.post_type = 'gatherpress_event'
|
||||
AND {$wpdb->prefix}posts.post_status = 'publish'
|
||||
AND {$wpdb->prefix}gatherpress_events.datetime_end_gmt <= %s
|
||||
AND {$wpdb->prefix}postmeta.meta_key = '_event_bridge_for_activitypub_is_remote_cached'
|
||||
AND {$wpdb->prefix}postmeta.meta_key = '_event_bridge_for_activitypub_event_source'
|
||||
",
|
||||
$ends_before_time_string
|
||||
),
|
||||
|
@ -129,7 +129,7 @@ final class GatherPress extends Event_Plugin_Integration implements Feature_Even
|
|||
if ( $post && 'gatherpress_event' === $post->post_type ) {
|
||||
// Add your custom logic here to decide whether to force the link.
|
||||
// For example, force it only if a specific meta field exists.
|
||||
if ( get_post_meta( $post->ID, '_event_bridge_for_activitypub_is_remote_cached', true ) ) {
|
||||
if ( get_post_meta( $post->ID, '_event_bridge_for_activitypub_event_source', true ) ) {
|
||||
return true; // Force the online event link.
|
||||
}
|
||||
}
|
||||
|
|
|
@ -127,7 +127,7 @@ final class The_Events_Calendar extends Event_plugin_Integration implements Feat
|
|||
*/
|
||||
public static function add_is_activitypub_remote_cached_to_query( $schema_entry ) {
|
||||
$schema_entry['meta_query']['is-remote-cached'] = array(
|
||||
'key' => '_event_bridge_for_activitypub_is_remote_cached',
|
||||
'key' => '_event_bridge_for_activitypub_event_source',
|
||||
'compare' => 'EXISTS',
|
||||
);
|
||||
return $schema_entry;
|
||||
|
|
|
@ -96,7 +96,7 @@ final class VS_Event_List extends Event_Plugin_Integration implements Feature_Ev
|
|||
'meta_query' => array(
|
||||
'relation' => 'AND',
|
||||
array(
|
||||
'key' => '_event_bridge_for_activitypub_is_remote_cached',
|
||||
'key' => '_event_bridge_for_activitypub_event_source',
|
||||
'compare' => 'EXISTS',
|
||||
),
|
||||
array(
|
||||
|
|
Loading…
Reference in a new issue