Move some functions from class ...\Collection\Event_Sources to Event_Sources class in the root namespace.
All checks were successful
PHP Code Checker / PHP Code Checker (pull_request) Successful in 57s
PHPUnit / PHPUnit – PHP 7.4 (pull_request) Successful in 1m11s
PHPUnit / PHPUnit – PHP 8.0 (pull_request) Successful in 1m9s
PHPUnit / PHPUnit – PHP 8.1 (pull_request) Successful in 1m12s
PHPUnit / PHPUnit – PHP 8.2 (pull_request) Successful in 1m16s
PHPUnit / PHPUnit – PHP 8.3 (pull_request) Successful in 1m13s
PHPUnit / PHPUnit – PHP 8.4 (pull_request) Successful in 1m11s

This commit is contained in:
André Menrath 2024-12-18 15:09:22 +01:00
parent 984973e18d
commit be0a10dc22
2 changed files with 67 additions and 65 deletions

View file

@ -233,57 +233,6 @@ class Event_Sources {
return $result; return $result;
} }
/**
* Get an array will all unique hosts of all Event-Sources.
*
* @return array The Term list of Event Sources.
*/
public static function get_event_sources_hosts() {
$hosts = get_transient( 'event_bridge_for_activitypub_event_sources_hosts' );
if ( $hosts ) {
return $hosts;
}
$actors = self::get_event_sources_with_count()['actors'];
$hosts = array();
foreach ( $actors as $actor ) {
$url = wp_parse_url( $actor->get_id() );
if ( isset( $url['host'] ) ) {
$hosts[] = $url['host'];
}
}
set_transient( 'event_bridge_for_activitypub_event_sources_hosts', $hosts );
return array_unique( $hosts );
}
/**
* Get add Event Sources ActivityPub IDs.
*
* @return array The Term list of Event Sources.
*/
public static function get_event_sources_ids() {
$ids = get_transient( 'event_bridge_for_activitypub_event_sources_ids' );
if ( $ids ) {
return $ids;
}
$actors = self::get_event_sources_with_count()['actors'];
$ids = array();
foreach ( $actors as $actor ) {
$ids[] = $actor->get_id();
}
set_transient( 'event_bridge_for_activitypub_event_sources_ids', $ids );
return $ids;
}
/** /**
* Get all Event-Sources. * Get all Event-Sources.
* *
@ -462,15 +411,4 @@ class Event_Sources {
$activity = $activity->to_json(); $activity = $activity->to_json();
\Activitypub\safe_remote_post( $inbox, $activity, \Activitypub\Collection\Actors::BLOG_USER_ID ); \Activitypub\safe_remote_post( $inbox, $activity, \Activitypub\Collection\Actors::BLOG_USER_ID );
} }
/**
* Add Event Sources hosts to allowed hosts used by safe redirect.
*
* @param array $hosts The hosts before the filter.
* @return array
*/
public static function add_event_sources_hosts_to_allowed_redirect_hosts( $hosts ) {
$event_sources_hosts = self::get_event_sources_hosts();
return array_merge( $hosts, $event_sources_hosts );
}
} }

View file

@ -52,7 +52,7 @@ class Event_Sources {
\add_action( 'event_bridge_for_activitypub_event_sources_clear_cache', array( self::class, 'clear_cache' ) ); \add_action( 'event_bridge_for_activitypub_event_sources_clear_cache', array( self::class, 'clear_cache' ) );
// Add the actors followed by the event sources feature to the `follow` collection of the used ActivityPub actor. // Add the actors followed by the event sources feature to the `follow` collection of the used ActivityPub actor.
\add_filter( 'activitypub_rest_following', array( self::class, 'add_event_sources_to_following_collection' ), 10, 2 ); \add_filter( 'activitypub_rest_following', array( self::class, 'add_event_sources_to_follow_collection' ), 10, 2 );
} }
@ -227,12 +227,12 @@ class Event_Sources {
* *
* @return array The array of following urls. * @return array The array of following urls.
*/ */
public static function add_event_sources_to_following_collection( $follow_list, $user ) { public static function add_event_sources_to_follow_collection( $follow_list, $user ) {
if ( ! $user instanceof Blog ) { if ( ! $user instanceof Blog ) {
return $follow_list; return $follow_list;
} }
$event_sources = Event_Sources_Collection::get_event_sources_ids(); $event_sources = self::get_event_sources_ids();
if ( ! is_array( $event_sources ) ) { if ( ! is_array( $event_sources ) ) {
return $follow_list; return $follow_list;
@ -240,4 +240,68 @@ class Event_Sources {
return array_merge( $follow_list, $event_sources ); return array_merge( $follow_list, $event_sources );
} }
/**
* Get an array will all unique hosts of all Event-Sources.
*
* @return array The Term list of Event Sources.
*/
public static function get_event_sources_hosts() {
$hosts = get_transient( 'event_bridge_for_activitypub_event_sources_hosts' );
if ( $hosts ) {
return $hosts;
}
$actors = Event_Sources_Collection::get_event_sources_with_count()['actors'];
$hosts = array();
foreach ( $actors as $actor ) {
$url = wp_parse_url( $actor->get_id() );
if ( isset( $url['host'] ) ) {
$hosts[] = $url['host'];
}
}
$hosts = array_unique( $hosts );
set_transient( 'event_bridge_for_activitypub_event_sources_hosts', $hosts );
return $hosts;
}
/**
* Get add Event Sources ActivityPub IDs.
*
* @return array The Term list of Event Sources.
*/
public static function get_event_sources_ids() {
$ids = get_transient( 'event_bridge_for_activitypub_event_sources_ids' );
if ( $ids ) {
return $ids;
}
$actors = Event_Sources_Collection::get_event_sources_with_count()['actors'];
$ids = array();
foreach ( $actors as $actor ) {
$ids[] = $actor->get_id();
}
set_transient( 'event_bridge_for_activitypub_event_sources_ids', $ids );
return $ids;
}
/**
* Add Event Sources hosts to allowed hosts used by safe redirect.
*
* @param array $hosts The hosts before the filter.
* @return array
*/
public static function add_event_sources_hosts_to_allowed_redirect_hosts( $hosts ) {
$event_sources_hosts = self::get_event_sources_hosts();
return array_merge( $hosts, $event_sources_hosts );
}
} }