|
From: Lo?c C. <lo...@us...> - 2001-04-24 19:07:53
|
Update of /cvsroot/phpmychat/phpMyChat-0.15/chat/lib
In directory usw-pr-cvs1:/tmp/cvs-serv31935/chat/lib
Modified Files:
format_messages.lib.php3
Log Message:
First draft of an improved url detection
Index: format_messages.lib.php3
===================================================================
RCS file: /cvsroot/phpmychat/phpMyChat-0.15/chat/lib/format_messages.lib.php3,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -r1.6 -r1.7
*** format_messages.lib.php3 2001/04/19 21:05:04 1.6
--- format_messages.lib.php3 2001/04/24 19:07:50 1.7
***************
*** 33,38 ****
*
* @global array the session data
*/
! function checkColor(&$theColor)
{
global $dbSessionVars;
--- 33,40 ----
*
* @global array the session data
+ *
+ * @access private
*/
! function pmcCheckColor(&$theColor)
{
global $dbSessionVars;
***************
*** 42,46 ****
&& !($dbSessionVars['status'] == 'a' || $dbSessionVars['status'] == 'm'))
$theColor = '#000000';
! } // end of the 'checkColor()' function
--- 44,91 ----
&& !($dbSessionVars['status'] == 'a' || $dbSessionVars['status'] == 'm'))
$theColor = '#000000';
! } // end of the 'pmcCheckColor()' function
!
!
! /**
! * Check messages parts that should be transformed to html links (links must be
! * stricly compliant with the RFC 2396)
! *
! * @param string the message
! *
! * @access private
! */
! function pmcCheckLinks(&$str)
! {
! // Defines the regular expressions to search for
! $reserved = '[;/?:@&=+$,]';
! $unreserved = '[a-z0-9\-_\.!~*\'()]';
! $escaped = '%[a-z0-9]{2}';
! $uric = "($reserved)|($unreserved)|($escaped)";
!
! // urls except 'news:'
! $scheme = '(http|https|ftp|telnet|gopher|file|wais)://';
! $user = "(($unreserved)|($escaped)|[;:&=+$,])+@";
! $host = "[a-z0-9]([a-z0-9]|$escaped|[\-\.])*[a-z0-9]";
! $port = ':([0-9]+)';
! $path = "/(($unreserved)|($escaped)|[:@&=+$,]|[/;])*";
! $query = "\?($uric)*";
! $fragment = "#($uric)*";
! $urlPattern = "$scheme(($user)?$host($port)?($path)?($query)?($fragment)?)";
!
! // 'news:' urls
! $scheme = 'news:';
! $host = "[a-z0-9]([a-z0-9]|$escaped|[\-\.])*[a-z0-9]";
! $newsPattern = "$scheme($host)";
!
! // e-mails
! $scheme = 'mailto:';
! $host = '[0-9a-z]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.[a-wyz][a-z](fo|g|l|m|mes|o|op|pa|ro|seum|t|u|v|z)?';
! $mailPattern = "($scheme)?($host)";
!
! // Do the work
! $str = eregi_replace($urlPattern, '<a href="\\1://\\2" target="_blank">\\1://\\2</a>', $str);
! $str = eregi_replace($newsPattern, '<a href="news:\\1" target="_blank">\\1</a>', $str);
! $str = eregi_replace($mailPattern, '<a href="mailto:\\2" target="_blank">\\2</a>', $str);
! } // end of the 'pmcCheckLinks()' function
***************
*** 57,60 ****
--- 102,107 ----
*
* @global boolean whether the current character set is 'iso-8859-1' or not
+ *
+ * @access private
*/
function formatMessage($theMessage)
***************
*** 63,67 ****
// Ensure color is valid
! checkColor($GLOBALS['color']);
// Remove swearings
--- 110,114 ----
// Ensure color is valid
! pmcCheckColor($GLOBALS['color']);
// Remove swearings
***************
*** 105,119 ****
}
}
-
- // URLs
- // no prefix (www.myurl.ext) -> add 'http://'
- $theMessage = eregi_replace('([[:space:]]|^)(www)', '\\1http://\\2', $theMessage);
- // creates html link
- $prefix = '(http|https|ftp|telnet|news|gopher|file|wais)://';
- $pureUrl = '([[:alnum:]/\n+-=%&:_.~?]+[#[:alnum:]+]*)';
- $theMessage = eregi_replace($prefix . $pureUrl, '<a href="\\1://\\2" target="_blank">\\1://\\2</a>', $theMessage);
! // e-mail addresses
! $theMessage = eregi_replace('([0-9a-z]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.[a-wyz][a-z](fo|g|l|m|mes|o|op|pa|ro|seum|t|u|v|z)?)', '<a href="mailto:\\1">\\1</a>', $theMessage);
// transform ISO-8859-1 special characters
--- 152,158 ----
}
}
! // Build html links from the message
! pmcCheckLinks($theMessage);
// transform ISO-8859-1 special characters
|