diff options
author | JoshyPHP <s9e.dev@gmail.com> | 2015-12-05 19:48:01 +0100 |
---|---|---|
committer | JoshyPHP <s9e.dev@gmail.com> | 2015-12-26 14:19:22 +0100 |
commit | 8fe94a19b46c4e33a117c1a040415f2b1c397e7c (patch) | |
tree | 97a3279742d78a2cc30cfbf1dfc4d889c7b190d5 /phpBB | |
parent | eb6ceb963ea7b32ef852b53d3da3a7e795291359 (diff) | |
download | forums-8fe94a19b46c4e33a117c1a040415f2b1c397e7c.tar forums-8fe94a19b46c4e33a117c1a040415f2b1c397e7c.tar.gz forums-8fe94a19b46c4e33a117c1a040415f2b1c397e7c.tar.bz2 forums-8fe94a19b46c4e33a117c1a040415f2b1c397e7c.tar.xz forums-8fe94a19b46c4e33a117c1a040415f2b1c397e7c.zip |
[ticket/14323] Added support for truncating local URLs
PHPBB3-14323
Diffstat (limited to 'phpBB')
-rw-r--r-- | phpBB/phpbb/textformatter/s9e/factory.php | 3 | ||||
-rw-r--r-- | phpBB/phpbb/textformatter/s9e/parser.php | 25 |
2 files changed, 17 insertions, 11 deletions
diff --git a/phpBB/phpbb/textformatter/s9e/factory.php b/phpBB/phpbb/textformatter/s9e/factory.php index dd3102d4de..63e49b6dd4 100644 --- a/phpBB/phpbb/textformatter/s9e/factory.php +++ b/phpBB/phpbb/textformatter/s9e/factory.php @@ -415,7 +415,8 @@ class factory implements \phpbb\textformatter\cache_interface ->add(__NAMESPACE__ . '\\parser::generate_autolink_text') ->resetParameters() ->addParameterByName('tag') - ->addParameterByName('parser'); + ->addParameterByName('parser') + ->addParameterByValue(generate_board_url() . '/'); } /** diff --git a/phpBB/phpbb/textformatter/s9e/parser.php b/phpBB/phpbb/textformatter/s9e/parser.php index faddc806cd..d8a2b8d62c 100644 --- a/phpBB/phpbb/textformatter/s9e/parser.php +++ b/phpBB/phpbb/textformatter/s9e/parser.php @@ -400,11 +400,12 @@ class parser implements \phpbb\textformatter\parser_interface * Will only apply to URL tags that do not use any markup (e.g. not "[url]") on the assumption * that those tags were created by the Autolink plugin to linkify URLs found in plain text * - * @param \s9e\TextFormatter\Parser\Tag $url_tag URL tag (start tag) - * @param \s9e\TextFormatter\Parser $parser Parser - * @return bool Always TRUE to indicate that the tag is valid + * @param \s9e\TextFormatter\Parser\Tag $url_tag URL tag (start tag) + * @param \s9e\TextFormatter\Parser $parser Parser + * @param string $board_url Forum's root URL (with trailing slash) + * @return bool Always TRUE to indicate that the tag is valid */ - public static function generate_autolink_text(\s9e\TextFormatter\Parser\Tag $url_tag, \s9e\TextFormatter\Parser $parser) + public static function generate_autolink_text(\s9e\TextFormatter\Parser\Tag $url_tag, \s9e\TextFormatter\Parser $parser, $board_url) { // If the tag consumes any text then we ignore it because it's not a linkified URL. Same if // it's not paired with an end tag that doesn't consume any text either @@ -419,16 +420,20 @@ class parser implements \phpbb\textformatter\parser_interface $length = $end - $start; $text = substr($parser->getText(), $start, $length); - if ($length <= 55 || utf8_strlen($text) <= 55) + // Remove the board's root URL from the link if applicable + if (stripos($text, $board_url) === 0 && strlen($text) > strlen($board_url)) { - // Do not do anything if the text is not longer than 55 characters - return true; + $text = substr($text, strlen($board_url)); } - $tag = $parser->addSelfClosingTag('AUTOLINK_TEXT', $start, $length); - $url_tag->cascadeInvalidationTo($tag); + // Truncate the text if it's longer than 55 characters + if (utf8_strlen($text) > 55) + { + $text = utf8_substr($text, 0, 39) . ' ... ' . utf8_substr($text, -10); + } - $text = utf8_substr($text, 0, 39) . ' ... ' . utf8_substr($text, -10); + // Create a tag that consumes the link's text + $tag = $parser->addSelfClosingTag('AUTOLINK_TEXT', $start, $length); $tag->setAttribute('text', $text); return true; |