[Phpfreechat-svn] SF.net SVN: phpfreechat: [1145] trunk/src
Status: Beta
Brought to you by:
kerphi
From: <gpi...@us...> - 2007-08-24 15:25:12
|
Revision: 1145 http://phpfreechat.svn.sourceforge.net/phpfreechat/?rev=1145&view=rev Author: gpinzone Date: 2007-08-24 08:13:24 -0700 (Fri, 24 Aug 2007) Log Message: ----------- Added two new parameters to the globalconfigclass: $short_url and $short_url_width. Rewrote short URL algorithm to use these values and to deal with ridiculously small widths. Moved URL proceesing to read instead of write. Fixed issue with honoring target global setting from the last commit. Modified Paths: -------------- trunk/src/pfccontainer.class.php trunk/src/pfcglobalconfig.class.php trunk/src/pfcurlprocessing.php Modified: trunk/src/pfccontainer.class.php =================================================================== --- trunk/src/pfccontainer.class.php 2007-08-24 02:39:27 UTC (rev 1144) +++ trunk/src/pfccontainer.class.php 2007-08-24 15:13:24 UTC (rev 1145) @@ -382,9 +382,6 @@ $msgid = $this->_requestMsgId($chan); - // convert URLs to html - $param = pfc_make_hyperlink($param); - // format message $data = "\n"; $data .= $msgid."\t"; @@ -445,7 +442,8 @@ $data["timestamp"] = $formated_line[1]; $data["sender"] = $formated_line[2]; $data["cmd"] = $formated_line[3]; - $data["param"] = $formated_line[4]; + // convert URLs to html + $data["param"] = pfc_make_hyperlink($formated_line[4]); $datalist[$data["id"]] = $data; } } Modified: trunk/src/pfcglobalconfig.class.php =================================================================== --- trunk/src/pfcglobalconfig.class.php 2007-08-24 02:39:27 UTC (rev 1144) +++ trunk/src/pfcglobalconfig.class.php 2007-08-24 15:13:24 UTC (rev 1145) @@ -100,6 +100,8 @@ var $startwithsound = true; // start with sound enabled var $openlinknewwindow = true; // used to open the links in a new window var $notify_window = true; // true : appends a prefix to the window title with the number of new posted messages + var $short_url = true; // true : shortens long urls entered by users in the chat area + var $short_url_width = 40; // final width of the shortened url /** * Be sure that you are conform to the license page before setting this to false ! Modified: trunk/src/pfcurlprocessing.php =================================================================== --- trunk/src/pfcurlprocessing.php 2007-08-24 02:39:27 UTC (rev 1144) +++ trunk/src/pfcurlprocessing.php 2007-08-24 15:13:24 UTC (rev 1145) @@ -1,13 +1,15 @@ <?php +require_once dirname(__FILE__).'/pfcglobalconfig.class.php'; + /** * Rewritten by Nathan Codding - Feb 6, 2001. * - Goes through the given string, and replaces xxxx://yyyy with an HTML <a> tag linking - * to that URL + * to that URL * - Goes through the given string, and replaces www.xxxx.yyyy[zzzz] with an HTML <a> tag linking - * to http://www.xxxx.yyyy[/zzzz] + * to http://www.xxxx.yyyy[/zzzz] * - Goes through the given string, and replaces xxxx@yyyy with an HTML mailto: tag linking - * to that email address + * to that email address * - Only matches these 2 patterns either after a space, or at the beginning of a line * * Notes: the email one might get annoying - it's easy to make it more restrictive, though.. maybe @@ -15,38 +17,41 @@ */ function pfc_make_hyperlink($text) { + $c =& pfcGlobalConfig::Instance(); + $openlinknewwindow = $c->openlinknewwindow; + if ($openlinknewwindow) $target = " onclick=\"window.open(this.href,\\'_blank\\');return false;\""; else - $target = ''; + $target = ""; $text = preg_replace('#(script|about|applet|activex|chrome):#is', "\\1:", $text); - // pad it with a space so we can match things at the start of the 1st line. - $ret = ' ' . $text; + // pad it with a space so we can match things at the start of the 1st line. + $ret = ' ' . $text; - // matches an "xxxx://yyyy" URL at the start of a line, or after a space. - // 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\#$%&~/.\-;:=,?@+]*)#ise", "'\\1<a href=\"\\2\"" . $target . ">' . pfc_shorten_url('\\2') . '</a>'", $ret); + // matches an "xxxx://yyyy" URL at the start of a line, or after a space. + // 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\#$%&~/.\-;:=,?@+]*)#ise", "'\\1<a href=\"\\2\"" . $target . ">' . pfc_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\#$%&~/.\-;:=,?@+]*)#ise", "'\\1<a href=\"http://\\2\"" . $target . ">' . pfc_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\#$%&~/.\-;:=,?@+]*)#ise", "'\\1<a href=\"http://\\2\"" . $target . ">' . pfc_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]+)#ie", "'\\1<a href=\"mailto:\\2@\\3\">' . pfc_shorten_url('\\2@\\3') . '</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]+)#ie", "'\\1<a href=\"mailto:\\2@\\3\">' . pfc_shorten_url('\\2@\\3') . '</a>'", $ret); - // Remove our padding.. - $ret = substr($ret, 1); + // Remove our padding.. + $ret = substr($ret, 1); - return($ret); + return($ret); } /** @@ -57,19 +62,32 @@ */ function pfc_undo_make_hyperlink($text) { - $text = preg_replace("#<!-- BBCode auto-link start --><a href=\"(.*?)\" target=\"_blank\">.*?</a><!-- BBCode auto-link end -->#i", "\\1", $text); - $text = preg_replace("#<!-- BBcode auto-mailto start --><a href=\"mailto:(.*?)\">.*?</a><!-- BBCode auto-mailto end -->#i", "\\1", $text); + $text = preg_replace("#<!-- BBCode auto-link start --><a href=\"(.*?)\" target=\"_blank\">.*?</a><!-- BBCode auto-link end -->#i", "\\1", $text); + $text = preg_replace("#<!-- BBcode auto-mailto start --><a href=\"mailto:(.*?)\">.*?</a><!-- BBCode auto-mailto end -->#i", "\\1", $text); - return $text; + return $text; } function pfc_shorten_url($url) { + $c =& pfcGlobalConfig::Instance(); + + if (! $c->short_url) + return $url; + + // Short URL Width + $shurl_w = $c->short_url_width; + + $shurl_end_w = floor($shurl_w * .25) - 3; + if ($shurl_end_w < 3) $shurl_end_w = 3; + $shurl_begin_w = $shurl_w - $shurl_end_w - 3; + if ($shurl_begin_w < 3) $shurl_begin_w = 3; + $decodedurl = html_entity_decode($url, ENT_QUOTES); $len = strlen($decodedurl); - $short_url = ($len > 40) ? substr($decodedurl, 0, 30) . "..." . substr($decodedurl, -7) : $decodedurl; + $short_url = ($len > $shurl_w) ? substr($decodedurl, 0, $shurl_begin_w) . "..." . substr($decodedurl, -$shurl_end_w) : $decodedurl; return htmlentities($short_url, ENT_QUOTES); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |