function handle_url_tag($url, $link = '', $bbcode = false) { $url = pun_trim($url); // Deal with [url][img]http://example.com/test.png[/img][/url] if (preg_match('%<img src=\\"(.*?)\\"%', $url, $matches)) { return handle_url_tag($matches[1], $url, $bbcode); } $full_url = str_replace(array(' ', '\'', '`', '"'), array('%20', '', '', ''), $url); if (strpos($url, 'www.') === 0) { // If it starts with www, we add http:// $full_url = 'http://' . $full_url; } else { if (strpos($url, 'ftp.') === 0) { // Else if it starts with ftp, we add ftp:// $full_url = 'ftp://' . $full_url; } else { if (strpos($url, '/') === 0) { // Allow for relative URLs that start with a slash $full_url = get_base_url(true) . $full_url; } else { if (!preg_match('#^([a-z0-9]{3,6})://#', $url)) { // Else if it doesn't start with abcdef://, we add http:// $full_url = 'http://' . $full_url; } } } } // Ok, not very pretty :-) if ($bbcode) { if ($full_url == $link) { return '[url]' . $link . '[/url]'; } else { return '[url=' . $full_url . ']' . $link . '[/url]'; } } else { if ($link == '' || $link == $url) { $url = pun_htmlspecialchars_decode($url); $link = utf8_strlen($url) > 55 ? utf8_substr($url, 0, 39) . ' … ' . utf8_substr($url, -10) : $url; $link = pun_htmlspecialchars($link); } else { $link = stripslashes($link); } return '<a href="' . $full_url . '" rel="nofollow">' . $link . '</a>'; } }
function handle_url_tag($url, $link = '', $bbcode = false) { $url = pun_trim($url); $full_url = str_replace(array(' ', '\'', '`', '"'), array('%20', '', '', ''), $url); if (strpos($url, 'www.') === 0) { // If it starts with www, we add http:// $full_url = 'http://' . $full_url; } else { if (strpos($url, 'ftp.') === 0) { // Else if it starts with ftp, we add ftp:// $full_url = 'ftp://' . $full_url; } else { if (!preg_match('#^([a-z0-9]{3,6})://#', $url)) { // Else if it doesn't start with abcdef://, we add http:// $full_url = 'http://' . $full_url; } } } // Ok, not very pretty :-) if ($bbcode) { if ($full_url == $link) { return '[url]' . $link . '[/url]'; } else { return '[url=' . $full_url . ']' . $link . '[/url]'; } } else { if ($link == '' || $link == $url) { $url = pun_htmlspecialchars_decode($url); $link = utf8_strlen($url) > 55 ? utf8_substr($url, 0, 39) . ' … ' . utf8_substr($url, -10) : $url; $link = pun_htmlspecialchars($link); } else { $link = stripslashes($link); } return '<a href="' . $full_url . '">' . $link . '</a>'; } }