mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-08 04:18:52 +00:00
[ticket/14323] Added should_shorten()
Explicitly tests a tag's markup to determine whether a link should be shortened PHPBB3-14323
This commit is contained in:
parent
bcd5d8b512
commit
bc5d976786
2 changed files with 20 additions and 1 deletions
|
@ -47,7 +47,7 @@ class link_helper
|
||||||
// Only create a LINK_TEXT tag if the start tag is paired with an end
|
// 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
|
// tag, which is the case with tags from the Autolink plugins and with
|
||||||
// the [url] BBCode when its content is used for the URL
|
// 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;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -64,6 +64,21 @@ class link_helper
|
||||||
return true;
|
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
|
* Remove the board's root URL from a the start of a string
|
||||||
*
|
*
|
||||||
|
|
|
@ -247,6 +247,10 @@ class phpbb_textformatter_s9e_default_formatting_test extends phpbb_test_case
|
||||||
'[url]http://example.org/0xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx0[/url]',
|
'[url]http://example.org/0xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx0[/url]',
|
||||||
'<a href="http://example.org/0xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx0" class="postlink">http://example.org/0xxxxxxxxxxxxxxxxxxx ... xxxxxxxxx0</a>'
|
'<a href="http://example.org/0xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx0" class="postlink">http://example.org/0xxxxxxxxxxxxxxxxxxx ... xxxxxxxxx0</a>'
|
||||||
),
|
),
|
||||||
|
array(
|
||||||
|
'[URL]http://example.org/0xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx0[/url]',
|
||||||
|
'<a href="http://example.org/0xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx0" class="postlink">http://example.org/0xxxxxxxxxxxxxxxxxxx ... xxxxxxxxx0</a>'
|
||||||
|
),
|
||||||
array(
|
array(
|
||||||
'[url=http://example.org/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx]xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx[/url]',
|
'[url=http://example.org/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx]xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx[/url]',
|
||||||
'<a href="http://example.org/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" class="postlink">xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</a>'
|
'<a href="http://example.org/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" class="postlink">xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</a>'
|
||||||
|
|
Loading…
Add table
Reference in a new issue