From e90f6022c05703d2efa7828a52d2d06f313e3e22 Mon Sep 17 00:00:00 2001 From: IanM <16573496+imorland@users.noreply.github.com> Date: Sun, 3 Nov 2024 17:05:37 +0000 Subject: [PATCH] feat: open bio links in new tab, add nofollow and ugc (#61) --- js/src/forum/components/UserBio.js | 4 +++- src/Formatter/UserBioFormatter.php | 12 ++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/js/src/forum/components/UserBio.js b/js/src/forum/components/UserBio.js index 39db53e..40027b2 100644 --- a/js/src/forum/components/UserBio.js +++ b/js/src/forum/components/UserBio.js @@ -113,7 +113,9 @@ export default class UserBio extends Component { if (bioHtml) { subContent = m.trust(bioHtml); } else if (user.bio()) { - subContent = m.trust('
' + $('
').text(user.bio()).html().replace(/\n/g, '' + $('
').text(user.bio()).html().replace(/\n/g, '{this.bioPlaceholder}
; } diff --git a/src/Formatter/UserBioFormatter.php b/src/Formatter/UserBioFormatter.php index f0f373e..03f858b 100644 --- a/src/Formatter/UserBioFormatter.php +++ b/src/Formatter/UserBioFormatter.php @@ -71,6 +71,18 @@ protected function getConfigurator() (new \Flarum\BBCode\Configure())($configurator); } + // Add target="_blank" and rel="noopener ugc" to all URL tags on the UserBioFormatter + $dom = $configurator->tags['URL']->template->asDOM(); + + foreach ($dom->getElementsByTagName('a') as $a) { + $a->setAttribute('target', '_blank'); + + $rel = $a->getAttribute('rel'); + $a->setAttribute('rel', "$rel noopener ugc"); + } + + $dom->saveChanges(); + return $configurator; }