get_json_params(); if ( isset( $json_params['object']['type'] ) && 'Event' === $json_params['object']['type'] ) { $valid = true; } else { return $valid; } if ( empty( $json_params['type'] ) ) { return false; } if ( empty( $json_params['actor'] ) ) { return false; } if ( ! in_array( $json_params['type'], array( 'Create', 'Update', 'Delete', 'Announce' ), true ) || is_wp_error( $request ) ) { return $valid; } $object = $json_params['object']; if ( ! is_array( $object ) ) { return false; } $required = array( 'id', 'startTime', 'name', ); if ( array_intersect( $required, array_keys( $object ) ) !== $required ) { return false; } return $valid; } /** * Check if a given DateTime is already passed. * * @param string $time_string The ActivityPub like time string. * @return bool */ public static function is_time_passed( $time_string ) { // Create a DateTime object from the ActivityPub time string. $time = new DateTime( $time_string, new DateTimeZone( 'UTC' ) ); // Get the current time in UTC. $current_time = new DateTime( 'now', new DateTimeZone( 'UTC' ) ); // Compare the event time with the current time. return $time < $current_time; } /** * Check that an ActivityPub actor is an event source (i.e. it is followed by the ActivityPub blog actor). * * @param string $actor_id The actor ID. * @return bool True if the ActivityPub actor ID is followed, false otherwise. */ public static function actor_is_event_source( $actor_id ) { $event_sources = Event_Sources::get_event_sources(); foreach ( $event_sources as $event_source ) { if ( $actor_id === $event_source->get_id() ) { return true; } } return false; } }