git-svn-id: file:///svn/phpbb/trunk@7588 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
Meik Sievertsen 2007-05-15 15:46:11 +00:00
parent b6f59604b8
commit 51061920d6

View file

@ -2606,16 +2606,36 @@ function generate_text_for_edit($text, $uid, $flags)
*/ */
function make_clickable_callback($type, $whitespace, $url, $relative_url, $class) function make_clickable_callback($type, $whitespace, $url, $relative_url, $class)
{ {
$append = ''; $append = '';
$url = htmlspecialchars_decode($url); $url = htmlspecialchars_decode($url);
$relative_url = htmlspecialchars_decode($relative_url); $relative_url = htmlspecialchars_decode($relative_url);
// make sure no HTML entities were matched // make sure no HTML entities were matched
$chars = array('<', '>', '"'); $chars = array('<', '>', '"');
$split = false;
foreach ($chars as $char)
{
$next_split = strpos($url, $char);
if ($next_split !== false)
{
$split = ($split !== false) ? min($split, $next_split) : $next_split;
}
}
if ($split !== false)
{
// an HTML entity was found, so the URL has to end before it
$append = substr($url, $split) . $relative_url;
$url = substr($url, 0, $split);
$relative_url = '';
}
else if ($relative_url)
{
// same for $relative_url
$split = false; $split = false;
foreach ($chars as $char) foreach ($chars as $char)
{ {
$next_split = strpos($url, $char); $next_split = strpos($relative_url, $char);
if ($next_split !== false) if ($next_split !== false)
{ {
$split = ($split !== false) ? min($split, $next_split) : $next_split; $split = ($split !== false) ? min($split, $next_split) : $next_split;
@ -2624,86 +2644,66 @@ function make_clickable_callback($type, $whitespace, $url, $relative_url, $class
if ($split !== false) if ($split !== false)
{ {
// an HTML entity was found, so the URL has to end before it $append = substr($relative_url, $split);
$append = substr($url, $split) . $relative_url; $relative_url = substr($relative_url, 0, $split);
$url = substr($url, 0, $split);
$relative_url = '';
} }
else if ($relative_url) }
{
// same for $relative_url // if the last character of the url is a punctuation mark, exclude it from the url
$split = false; $last_char = ($relative_url) ? $relative_url[strlen($relative_url) - 1] : $url[strlen($url) - 1];
foreach ($chars as $char)
switch ($last_char)
{
case '.':
case '?':
case '!':
case ':':
case ',':
$append = $last_char;
if ($relative_url)
{ {
$next_split = strpos($relative_url, $char); $relative_url = substr($relative_url, 0, -1);
if ($next_split !== false)
{
$split = ($split !== false) ? min($split, $next_split) : $next_split;
}
} }
else
if ($split !== false)
{ {
$append = substr($relative_url, $split); $url = substr($url, 0, -1);
$relative_url = substr($relative_url, 0, $split);
} }
} }
// if the last character of the url is a punctuation mark, exclude it from the url switch ($type)
$last_char = ($relative_url) ? $relative_url[strlen($relative_url) - 1] : $url[strlen($url) - 1]; {
case MAGIC_URL_LOCAL:
$tag = 'l';
$relative_url = preg_replace('/[&?]sid=[0-9a-f]{32}$/', '', preg_replace('/([&?])sid=[0-9a-f]{32}&/', '$1', $relative_url));
$url = $url . '/' . $relative_url;
$text = ($relative_url) ? $relative_url : $url . '/';
break;
switch ($last_char) case MAGIC_URL_FULL:
{ $tag = 'm';
case '.': $text = (strlen($url) > 55) ? substr($url, 0, 39) . ' ... ' . substr($url, -10) : $url;
case '?': break;
case '!':
case ':':
case ',':
$append = $last_char;
if ($relative_url)
{
$relative_url = substr($relative_url, 0, -1);
}
else
{
$url = substr($url, 0, -1);
}
}
switch ($type) case MAGIC_URL_WWW:
{ $tag = 'w';
case MAGIC_URL_LOCAL: $url = 'http://' . $url;
$tag = 'l'; $text = (strlen($url) > 55) ? substr($url, 0, 39) . ' ... ' . substr($url, -10) : $url;
$relative_url = preg_replace('/[&?]sid=[0-9a-f]{32}$/', '', preg_replace('/([&?])sid=[0-9a-f]{32}&/', '$1', $relative_url)); break;
$url = $url . '/' . $relative_url;
$text = ($relative_url) ? $relative_url : $url . '/';
break;
case MAGIC_URL_FULL: case MAGIC_URL_EMAIL:
$tag = 'm'; $tag = 'e';
$text = (strlen($url) > 55) ? substr($url, 0, 39) . ' ... ' . substr($url, -10) : $url; $url = 'mailto:' . $url;
break; $text = (strlen($url) > 55) ? substr($url, 0, 39) . ' ... ' . substr($url, -10) : $url;
break;
}
case MAGIC_URL_WWW: $url = htmlspecialchars($url);
$tag = 'w'; $text = htmlspecialchars($text);
$url = 'http://' . $url; $append = htmlspecialchars($append);
$text = (strlen($url) > 55) ? substr($url, 0, 39) . ' ... ' . substr($url, -10) : $url;
break;
case MAGIC_URL_EMAIL: $html = "$whitespace<!-- $tag --><a$class href=\"$url\">$text</a><!-- $tag -->$append";
$tag = 'e';
$url = 'mailto:' . $url;
$text = (strlen($url) > 55) ? substr($url, 0, 39) . ' ... ' . substr($url, -10) : $url;
break;
}
$url = htmlspecialchars($url); return $html;
$text = htmlspecialchars($text);
$append = htmlspecialchars($append);
$html = "$whitespace<!-- $tag --><a$class href=\"$url\">$text</a><!-- $tag -->$append";
return $html;
} }
/** /**