1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-08-01 14:30:32 +02:00

[ticket/16512] Fix make_clickable() to make use of custom link classes

PHPBB3-16512
This commit is contained in:
rxu
2020-06-04 15:08:06 +07:00
parent d7ccd22383
commit da4b446ac6
2 changed files with 156 additions and 85 deletions

View File

@@ -927,7 +927,7 @@ function make_clickable_callback($type, $whitespace, $url, $relative_url, $class
* Cuts down displayed size of link if over 50 chars, turns absolute links
* into relative versions when the server/script path matches the link
*/
function make_clickable($text, $server_url = false, $class = 'postlink')
function make_clickable($text, $server_url = false, string $class = 'postlink')
{
if ($server_url === false)
{
@@ -948,29 +948,51 @@ function make_clickable($text, $server_url = false, $class = 'postlink')
$magic_url_match_args = array();
}
// relative urls for this board
$magic_url_match_args[$server_url][] = array(
'#(^|[\n\t (>.])(' . preg_quote($server_url, '#') . ')/(' . get_preg_expression('relative_url_inline') . ')#iu',
MAGIC_URL_LOCAL,
$local_class,
);
// Check if tne match for this $server_url and $class already exists
$element_exists = false;
if (isset($magic_url_match_args[$server_url]))
{
array_walk_recursive($magic_url_match_args[$server_url], function($value, $key) use (&$element_exists, $static_class)
{
if ($value == $static_class)
{
$element_exists = true;
return;
}
}
);
}
// matches a xxxx://aaaaa.bbb.cccc. ...
$magic_url_match_args[$server_url][] = array(
'#(^|[\n\t (>.])(' . get_preg_expression('url_inline') . ')#iu',
MAGIC_URL_FULL,
$class,
);
// Only add new $server_url and $class matches if not exist
if (!$element_exists)
{
// relative urls for this board
$magic_url_match_args[$server_url][] = array(
'#(^|[\n\t (>.])(' . preg_quote($server_url, '#') . ')/(' . get_preg_expression('relative_url_inline') . ')#iu',
MAGIC_URL_LOCAL,
$local_class,
$static_class,
);
// matches a "www.xxxx.yyyy[/zzzz]" kinda lazy URL thing
$magic_url_match_args[$server_url][] = array(
'#(^|[\n\t (>])(' . get_preg_expression('www_url_inline') . ')#iu',
MAGIC_URL_WWW,
$class,
);
// matches a xxxx://aaaaa.bbb.cccc. ...
$magic_url_match_args[$server_url][] = array(
'#(^|[\n\t (>.])(' . get_preg_expression('url_inline') . ')#iu',
MAGIC_URL_FULL,
$class,
$static_class,
);
// matches a "www.xxxx.yyyy[/zzzz]" kinda lazy URL thing
$magic_url_match_args[$server_url][] = array(
'#(^|[\n\t (>])(' . get_preg_expression('www_url_inline') . ')#iu',
MAGIC_URL_WWW,
$class,
$static_class,
);
}
// matches an email@domain type address at the start of a line, or after a space or after what might be a BBCode.
$magic_url_match_args[$server_url][] = array(
$magic_url_match_args[$server_url]['email'] = array(
'/(^|[\n\t (>])(' . get_preg_expression('email') . ')/iu',
MAGIC_URL_EMAIL,
'',
@@ -981,6 +1003,12 @@ function make_clickable($text, $server_url = false, $class = 'postlink')
{
if (preg_match($magic_args[0], $text, $matches))
{
// Only apply $class from the correcponding function call argument (excepting emails which never has a class)
if ($magic_args[3] != $static_class && $magic_args[1] != MAGIC_URL_EMAIL)
{
continue;
}
$text = preg_replace_callback($magic_args[0], function($matches) use ($magic_args)
{
$relative_url = isset($matches[3]) ? $matches[3] : '';