Created
September 28, 2017 01:29
-
-
Save Elsensee/7e87a11b464194109a00d943d4a95b51 to your computer and use it in GitHub Desktop.
Patch for "External images as link" extension (for phpBB 3.2.0 and 3.2.1)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/event/listener.php b/event/listener.php | |
index 07bc2c4..818596d 100644 | |
--- a/event/listener.php | |
+++ b/event/listener.php | |
@@ -67,6 +67,7 @@ class listener implements EventSubscriberInterface | |
// 3.2 TextFormatter events (will only trigger in >=3.2) | |
'core.text_formatter_s9e_configure_after' => 'configure_textformatter', | |
'core.text_formatter_s9e_renderer_setup' => 'setup_textformatter_renderer', | |
+ 'core.text_formatter_s9e_parse_after' => 'legacy_replace', | |
); | |
} | |
@@ -183,4 +184,23 @@ class listener implements EventSubscriberInterface | |
$renderer = $event['renderer']->get_renderer(); | |
$renderer->setParameter('S_IMG_SECURE_URLS', ($this->config['extimgaslink_config'] & constants::SECURE_SITES) === constants::SECURE_SITES); | |
} | |
+ | |
+ /** | |
+ * Catch all img tags that slip through because of | |
+ * using an outdated version of s9e's TextFormatter | |
+ * | |
+ * @param \phpbb\event\data $event | |
+ * @return null | |
+ */ | |
+ public function legacy_replace($event) | |
+ { | |
+ /** @var \s9e\TextFormatter\Parser $parser */ | |
+ $parser = $event['parser']->get_parser(); | |
+ $xml = $event['xml']; | |
+ $xml = preg_replace_callback('#\[img\][^<>]+\[/img\]#i', function ($matches) use ($parser) { | |
+ return preg_replace('#<([rt])>(.+)</\1>#i', '$2', $parser->parse($matches[0])); | |
+ }, $xml); | |
+ | |
+ $event['xml'] = $xml; | |
+ } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment