From d809b0b18e1f65acff6575886aa7e89ef3fb4c93 Mon Sep 17 00:00:00 2001
From: discomrade <83621080+discomrade@users.noreply.github.com>
Date: Sat, 31 Aug 2024 21:28:59 +0100
Subject: [PATCH] [bbcode] allow relative image links
This is useful for CSP when a site is hosted on multiple domains, such as a mirror.
---
ext/bbcode/info.php | 1 +
ext/bbcode/main.php | 1 +
2 files changed, 2 insertions(+)
diff --git a/ext/bbcode/info.php b/ext/bbcode/info.php
index 218b4bba..f893ad86 100644
--- a/ext/bbcode/info.php
+++ b/ext/bbcode/info.php
@@ -34,6 +34,7 @@ class BBCodeInfo extends ExtensionInfo
Link tags:
- [img]url[/img]
+
- [img]site://_images/image.jpg[/img]
- [url]https://code.shishnet.org/[/url]
- [url=https://code.shishnet.org/]some text[/url]
- [url]site://ext_doc/bbcode[/url]
diff --git a/ext/bbcode/main.php b/ext/bbcode/main.php
index 35dc0fd1..358a43d5 100644
--- a/ext/bbcode/main.php
+++ b/ext/bbcode/main.php
@@ -29,6 +29,7 @@ class BBCode extends FormatterExtension
$text = preg_replace_ex('!\[url\]((?:https?|ftp|irc|mailto)://.*?)\[/url\]!s', '$1', $text);
$text = preg_replace_ex('!\[email\](.*?)\[/email\]!s', '$1', $text);
$text = preg_replace_ex('!\[img\](https?:\/\/.*?)\[/img\]!s', '', $text);
+ $text = preg_replace_ex('!\[img\]site://(.*?)(#c\d+)?\[/img\]!s', '', $text);
$text = preg_replace_ex('!\[\[([^\|\]]+)\|([^\]]+)\]\]!s', '$2', $text);
$text = preg_replace_ex('!\[\[([^\]]+)\]\]!s', '$1', $text);
$text = preg_replace_ex("!\n\s*\n!", "\n\n", $text);