From bc5d976786d60d8d33cf77fccf81ce351b59fcdc Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Mon, 28 Dec 2015 04:19:21 +0100 Subject: [ticket/14323] Added should_shorten() Explicitly tests a tag's markup to determine whether a link should be shortened PHPBB3-14323 --- phpBB/phpbb/textformatter/s9e/link_helper.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'phpBB/phpbb') diff --git a/phpBB/phpbb/textformatter/s9e/link_helper.php b/phpBB/phpbb/textformatter/s9e/link_helper.php index 76948159ba..0f44603dec 100644 --- a/phpBB/phpbb/textformatter/s9e/link_helper.php +++ b/phpBB/phpbb/textformatter/s9e/link_helper.php @@ -47,7 +47,7 @@ class link_helper // Only create a LINK_TEXT tag if the start tag is paired with an end // tag, which is the case with tags from the Autolink plugins and with // the [url] BBCode when its content is used for the URL - if (!$tag->getEndTag()) + if (!$tag->getEndTag() || !$this->should_shorten($tag, $parser->getText())) { return true; } @@ -64,6 +64,21 @@ class link_helper return true; } + /** + * Test whether we should shorten this tag's text + * + * Will test whether the tag either does not use any markup or uses a single + * [url] BBCode + * + * @param \s9e\TextFormatter\Parser\Tag $tag URL tag + * @param string $text Original text + * @return bool + */ + protected function should_shorten(\s9e\TextFormatter\Parser\Tag $tag, $text) + { + return ($tag->getLen() === 0 || strtolower(substr($text, $tag->getPos(), $tag->getLen())) === '[url]'); + } + /** * Remove the board's root URL from a the start of a string * -- cgit v1.2.1