[Phpfreechat-svn] SF.net SVN: phpfreechat: [1135] trunk/src/urlprocessing.php
Status: Beta
Brought to you by:
kerphi
From: <gpi...@us...> - 2007-08-20 20:40:45
|
Revision: 1135 http://phpfreechat.svn.sourceforge.net/phpfreechat/?rev=1135&view=rev Author: gpinzone Date: 2007-08-20 13:40:46 -0700 (Mon, 20 Aug 2007) Log Message: ----------- Added URL shortening to URL linking. Now all browsers work the same. Modified Paths: -------------- trunk/src/urlprocessing.php Modified: trunk/src/urlprocessing.php =================================================================== --- trunk/src/urlprocessing.php 2007-08-20 19:36:14 UTC (rev 1134) +++ trunk/src/urlprocessing.php 2007-08-20 20:40:46 UTC (rev 1135) @@ -24,19 +24,19 @@ // xxxx can only be alpha characters. // yyyy is anything up to the first space, newline, comma, double quote or < //$ret = preg_replace("#(^|[\n ])([\w]+?://[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "\\1<a href=\"\\2\" target=\"_blank\">\\2</a>", $ret); - $ret = preg_replace("#(^|[\n \]])([\w]+?://[\w\#$%&~/.\-;:=,?@+]*)#is", "\\1<a href=\"\\2\" target=\"_blank\">\\2</a>", $ret); + $ret = preg_replace("#(^|[\n \]])([\w]+?://[\w\#$%&~/.\-;:=,?@+]*)#ise", "'\\1<a href=\"\\2\" target=\"_blank\">' . shorten_url('\\2') . '</a>'", $ret); // matches a "www|ftp.xxxx.yyyy[/zzzz]" kinda lazy URL thing // Must contain at least 2 dots. xxxx contains either alphanum, or "-" // zzzz is optional.. will contain everything up to the first space, newline, // comma, double quote or <. //$ret = preg_replace("#(^|[\n ])((www|ftp)\.[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "\\1<a href=\"http://\\2\" target=\"_blank\">\\2</a>", $ret); - $ret = preg_replace("#(^|[\n \]])((www|ftp)\.[\w\#$%&~/.\-;:=,?@+]*)#is", "\\1<a href=\"http://\\2\" target=\"_blank\">\\2</a>", $ret); + $ret = preg_replace("#(^|[\n \]])((www|ftp)\.[\w\#$%&~/.\-;:=,?@+]*)#ise", "'\\1<a href=\"http://\\2\" target=\"_blank\">' . shorten_url('\\2') . '</a>'", $ret); // matches an email@domain type address at the start of a line, or after a space. // Note: Only the followed chars are valid; alphanums, "-", "_" and or ".". //$ret = preg_replace("#(^|[\n ])([a-z0-9&\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#i", "\\1<a href=\"mailto:\\2@\\3\">\\2@\\3</a>", $ret); - $ret = preg_replace("#(^|[\n \]])([a-z0-9&\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#i", "\\1<a href=\"mailto:\\2@\\3\">\\2@\\3</a>", $ret); + $ret = preg_replace("#(^|[\n \]])([a-z0-9&\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#ie", "'\\1<a href=\"mailto:\\2@\\3\">' . shorten_url('\\2@\\3') . '</a>'", $ret); // Remove our padding.. $ret = substr($ret, 1); @@ -59,4 +59,12 @@ } +function shorten_url($url) +{ + $len = strlen($url); + $short_url = ($len > 40) ? substr($url, 0, 30) . "..." . substr($url, -7) : $url; + + return $short_url; +} + ?> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |