diff --git a/composer.json b/composer.json index 19faa44..c361ebd 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,7 @@ "type": "phpbb-extension", "description": "An official phpBB extension that allows users to embed content from allowed sites using a [media] BBCode, or from simply posting a supported URL in plain text.", "homepage": "https://www.phpbb.com/customise/db/extension/mediaembed/", - "version": "2.0.4", + "version": "2.0.5-dev", "license": "GPL-2.0-only", "authors": [ { diff --git a/event/main_listener.php b/event/main_listener.php index 4e19f2d..5cc81e6 100644 --- a/event/main_listener.php +++ b/event/main_listener.php @@ -55,6 +55,9 @@ class main_listener implements EventSubscriberInterface /** @var bool Disable the media tag (bbcode parsing) */ protected $disable_tag = false; + /** @var bool|null Cached result of is_phpbb4() */ + protected $is_phpbb4; + /** * {@inheritDoc} */ @@ -105,7 +108,15 @@ public function __construct(auth $auth, config $config, db_text $config_text, la public function add_custom_sites($event) { $phpbb4_builtins = array_flip([ - 'applepodcasts', 'bluesky', 'bunny', 'mastodon', 'pastebin', 'threads', 'twitter', + 'applepodcasts', + 'bluesky', + 'bunny', + 'facebook', + 'mastodon', + 'pastebin', + 'threads', + 'twitter', + 'vk', ]); foreach ($this->custom_sites->get_collection() as $site) @@ -113,7 +124,7 @@ public function add_custom_sites($event) $name = basename($site, ext::YML); // Skip built-in sites when running phpBB 4 - if ($this->is_phpbb4() && isset($phpbb4_builtins[$name])) + if (isset($phpbb4_builtins[$name]) && $this->is_phpbb4()) { continue; } @@ -177,10 +188,10 @@ public function modify_tag_templates($event) { // force YouTube to use the no cookies until the user starts video playback, and fix referrer policy issues $tag = $event['configurator']->tags['YOUTUBE']; - $tag->template = str_replace(['www.youtube.com'], 'www.youtube-nocookie.com', $tag->template); + $tag->template = str_replace('www.youtube.com', 'www.youtube-nocookie.com', $tag->template); if (!$this->is_phpbb4()) { - $tag->template = str_replace([' allowfullscreen'], ' referrerpolicy="origin" allowfullscreen', $tag->template); + $tag->template = str_replace(' allowfullscreen', ' referrerpolicy="origin" allowfullscreen', $tag->template); } $event['configurator']->finalize(); @@ -403,6 +414,11 @@ public function append_agreement() */ private function is_phpbb4() { - return phpbb_version_compare($this->config['version'], '4.0.0-a1', '>='); + if ($this->is_phpbb4 === null) + { + $this->is_phpbb4 = phpbb_version_compare($this->config['version'], '4.0.0-a1', '>='); + } + + return $this->is_phpbb4; } }