diff --git a/event/main_listener.php b/event/main_listener.php index b1a2f0c..07ed675 100644 --- a/event/main_listener.php +++ b/event/main_listener.php @@ -78,7 +78,7 @@ public static function getSubscribedEvents() * Constructor * * @param auth $auth - * @param config $config + * @param config $config * @param db_text $config_text * @param language $language * @param template $template @@ -104,12 +104,22 @@ public function __construct(auth $auth, config $config, db_text $config_text, la */ public function add_custom_sites($event) { + $is_phpbb4 = phpbb_version_compare($this->config['version'], '4.0.0-a1', '>='); + $phpbb4_builtins = array_flip([ + 'applepodcasts', 'bluesky', 'bunny', 'mastodon', 'pastebin', 'threads', 'twitter', + ]); + foreach ($this->custom_sites->get_collection() as $site) { - $event['configurator']->MediaEmbed->defaultSites->add( - basename($site, ext::YML), - Yaml::parse(file_get_contents($site)) - ); + $name = basename($site, ext::YML); + + // Skip built-in sites when running phpBB 4 + if ($is_phpbb4 && isset($phpbb4_builtins[$name])) + { + continue; + } + + $event['configurator']->MediaEmbed->defaultSites->add($name, Yaml::parseFile($site)); } } diff --git a/tests/event/listener_test.php b/tests/event/listener_test.php index a374862..b546447 100644 --- a/tests/event/listener_test.php +++ b/tests/event/listener_test.php @@ -189,10 +189,14 @@ public function test_configure_media_embed($tag, $code, $id, $exists, $parse_url { $this->custom_sites->expects(self::once()) ->method('get_collection') - ->willReturn([__DIR__ . '/../fixtures/sites/ok.yml']); + ->willReturn([ + __DIR__ . '/../fixtures/sites/ok.yml', + __DIR__ . '/../fixtures/sites/bluesky.yml', // this is to test that phpbb4 filtering works + ]); // Update configs with test values $this->config['media_embed_parse_urls'] = $parse_urls; + $this->config['version'] = '4.0.0'; // this is to test that phpbb4 filtering works // Get the s9e configurator $configurator = $this->container