diff options
Diffstat (limited to 'lib/util.php')
-rw-r--r-- | lib/util.php | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/lib/util.php b/lib/util.php index ee1a149a7..bdc798314 100644 --- a/lib/util.php +++ b/lib/util.php @@ -744,14 +744,28 @@ function common_render_uri_thingy($matches) { $trailer = $final . $trailer; } } - return '<a href="' . $uri . '" class="extlink">' . $uri . '</a>' . $trailer; + if ($longurl = common_longurl($uri)) { + $longurl = htmlentities($longurl, ENT_QUOTES, 'UTF-8'); + $title = " title=$longurl"; + } + else $title = ''; + + return '<a href="' . $uri . '"' . $title . ' class="extlink">' . $uri . '</a>' . $trailer; +} + +function common_longurl($uri) { + $uri_e = urlencode($uri); + $longurl = unserialize(file_get_contents("http://api.longurl.org/v1/expand?format=php&url=$uri_e")); + if (empty($longurl['long_url']) || $uri === $longurl['long_url']) return false; + return $longurl['long_url']; } function common_shorten_links($text) { $r = htmlspecialchars($text); // \s = not a horizontal whitespace character (since PHP 5.2.4) - $r = preg_replace('@[^*]https?://[^)\]>\s]+@e', "common_shorten_link('\\0')", $r); -// $r = preg_replace('@https?://[^)\]>\s]+@e', "common_shorten_link('\\0')", $r); + // RYM this should prevent * preceded URLs from being processed but it its a char +// $r = preg_replace('@[^*](https?://[^)\]>\s]+)@e', "common_shorten_link('\\1')", $r); + $r = preg_replace('@https?://[^)\]>\s]+@e', "common_shorten_link('\\0')", $r); return $r; } |