[Phpfreechat-svn] SF.net SVN: phpfreechat: [1133] trunk
Status: Beta
Brought to you by:
kerphi
From: <gpi...@us...> - 2007-08-20 17:49:22
|
Revision: 1133 http://phpfreechat.svn.sourceforge.net/phpfreechat/?rev=1133&view=rev Author: gpinzone Date: 2007-08-20 10:41:46 -0700 (Mon, 20 Aug 2007) Log Message: ----------- Moved autolink feature out of JavaScript and put it into PHP. Removed email bbcode and button since it's not needed. Modified Paths: -------------- trunk/data/public/js/pfcclient.js trunk/src/pfccontainer.class.php trunk/themes/default/chat.html.tpl.php Added Paths: ----------- trunk/src/urlprocessing.php Modified: trunk/data/public/js/pfcclient.js =================================================================== --- trunk/data/public/js/pfcclient.js 2007-08-20 02:19:47 UTC (rev 1132) +++ trunk/data/public/js/pfcclient.js 2007-08-20 17:41:46 UTC (rev 1133) @@ -1387,7 +1387,7 @@ parseMessage: function(msg) { var rx = null; - +/* // parse urls var rx_url = new RegExp('(^|[^\\"])([a-z]+\:\/\/[a-z0-9.\\~\\/\\?\\=\\&\\-\\_\\#:;%,@]*[a-z0-9\\/\\?\\=\\&\\-\\_\\#])([^\\"]|$)','ig'); var ttt = msg.split(rx_url); @@ -1428,7 +1428,7 @@ // replace double spaces by entity rx = new RegExp(' ','g'); msg = msg.replace(rx, ' '); - +*/ // try to parse bbcode rx = new RegExp('\\[b\\](.+?)\\[\/b\\]','ig'); msg = msg.replace(rx, '<span style="font-weight: bold">$1</span>'); @@ -1440,10 +1440,12 @@ msg = msg.replace(rx, '<span style="text-decoration: line-through">$1</span>'); // rx = new RegExp('\\[pre\\](.+?)\\[\/pre\\]','ig'); // msg = msg.replace(rx, '<pre>$1</pre>'); +/* rx = new RegExp('\\[email\\]([A-z0-9][\\w.-]*@[A-z0-9][\\w\\-\\.]+\\.[A-z0-9]{2,6})\\[\/email\\]','ig'); msg = msg.replace(rx, '<a href="mailto: $1">$1</a>'); rx = new RegExp('\\[email=([A-z0-9][\\w.-]*@[A-z0-9][\\w\\-\\.]+\\.[A-z0-9]{2,6})\\](.+?)\\[\/email\\]','ig'); msg = msg.replace(rx, '<a href="mailto: $1">$2</a>'); +*/ rx = new RegExp('\\[color=([a-zA-Z]+|\\#?[0-9a-fA-F]{6}|\\#?[0-9a-fA-F]{3})](.+?)\\[\/color\\]','ig'); msg = msg.replace(rx, '<span style="color: $1">$2</span>'); // parse bbcode colors twice because the current_text_color is a bbcolor Modified: trunk/src/pfccontainer.class.php =================================================================== --- trunk/src/pfccontainer.class.php 2007-08-20 02:19:47 UTC (rev 1132) +++ trunk/src/pfccontainer.class.php 2007-08-20 17:41:46 UTC (rev 1133) @@ -21,6 +21,7 @@ */ require_once dirname(__FILE__)."/pfccontainerinterface.class.php"; + require_once dirname(__FILE__)."/urlprocessing.php"; /** * pfcContainer is an abstract class which define interface @@ -381,6 +382,9 @@ $msgid = $this->_requestMsgId($chan); + // convert URLs to html + $param = make_clickable($param); + // format message $data = "\n"; $data .= $msgid."\t"; Added: trunk/src/urlprocessing.php =================================================================== --- trunk/src/urlprocessing.php (rev 0) +++ trunk/src/urlprocessing.php 2007-08-20 17:41:46 UTC (rev 1133) @@ -0,0 +1,62 @@ +<?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 + * - Goes through the given string, and replaces www.xxxx.yyyy[zzzz] with an HTML <a> tag linking + * 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 + * - 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 + * have it require something like xxxx@yyyy.zzzz or such. We'll see. + */ +function make_clickable($text) +{ + $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; + + // 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\#$%&~/.\-;:=,?@+]*)#is", "\\1<a href=\"\\2\" target=\"_blank\">\\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); + + // 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); + + // Remove our padding.. + $ret = substr($ret, 1); + + return($ret); +} + +/** + * Nathan Codding - Feb 6, 2001 + * Reverses the effects of make_clickable(), for use in editpost. + * - Does not distinguish between "www.xxxx.yyyy" and "http://aaaa.bbbb" type URLs. + * + */ +function undo_make_clickable($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; + +} + +?> Modified: trunk/themes/default/chat.html.tpl.php =================================================================== --- trunk/themes/default/chat.html.tpl.php 2007-08-20 02:19:47 UTC (rev 1132) +++ trunk/themes/default/chat.html.tpl.php 2007-08-20 17:41:46 UTC (rev 1133) @@ -127,6 +127,7 @@ class="pfc_bt_delete" onclick="pfc.insert_text('[s]','[/s]',true)" /> </div> +<!-- <div id="pfc_bt_mail_btn" class="pfc_btn"> <img src="<?php echo $c->getFileUrlFromTheme('images/bt_mail.gif'); ?>" id="pfc_bt_mail" @@ -135,6 +136,7 @@ class="pfc_bt_mail" onclick="pfc.insert_text('[email]','[/email]',true)" /> </div> +--> <div id="pfc_bt_color_btn" class="pfc_btn"> <img src="<?php echo $c->getFileUrlFromTheme('images/bt_color.gif'); ?>" alt="<?php echo _pfc("Color"); ?>" This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |