Changeset 2101


Ignore:
Timestamp:
03/01/10 16:04:38 (14 years ago)
Author:
niltonneto
Message:

Ticket #859 - Corrigido problema no método replace_links.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.1/expressoMail1_2/inc/class.imap_functions.inc.php

    r1970 r2101  
    450450                $return = array(); 
    451451                $msg_number = $params['msg_number']; 
    452                 if(preg_match('(.+)(_[a-zA-Z0-9]+)',$msg_number,$matches)) { //Verifies if it comes from a tab diferent of the main one.  
     452                if(@preg_match('(.+)(_[a-zA-Z0-9]+)',$msg_number,$matches)) { //Verifies if it comes from a tab diferent of the main one.  
    453453                        $msg_number = $matches[1];  
    454454                        $plus_id = $matches[2];  
     
    11641164                $body = preg_replace( $pattern, $replacement, $body ); 
    11651165 
    1166                 // Url found in the text and which is not a link yet should be replaced by one. 
    1167                 $pattern = '/(^|\w>|[ \(\[])((http(s)?:\/\/)?([\w\d_\-@]{2,}(\.[\w\d~?\/_=&#;\-:@$]+)+))/im'; 
    1168                 $replacement = '$1<a href="http$4://$5" target="_blank">$2</a>'; 
    1169                 $body = preg_replace( $pattern, $replacement, $body ); 
     1166 
     1167                // Domains and IPs addresses found in the text and which is not a link yet should be replaced by one. 
     1168                // See more informations in www.iana.org 
     1169                $octets = array( 
     1170                        'first' => '(2[0-3][0-9]|1[0-9]{2}|[1-9][0-9]?)', 
     1171                        'middle' => '(25[0-5]|2[0-4][0-9]|1?[0-9]{1,2})', 
     1172                        'last' => '(25[0-4]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]?)' 
     1173                ); 
     1174 
     1175                $ip = "\b{$octets[ 'first' ]}\.({$octets[ 'middle' ]}\.){2}{$octets[ 'last' ]}\b"; 
     1176 
     1177                $top_level_domains = '(\.(ac|ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|as|asia|at|au|aw|ax|az|' 
     1178                        . 'ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bl|bm|bn|bo|br|bs|bt|bv|bw|by|bz|' 
     1179                        . 'ca|cat|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cu|cv|cx|cy|cz|' 
     1180                        . 'de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|' 
     1181                        . 'ga|gb|gd|ge|gf|gg|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|' 
     1182                        . 'hk|hm|hn|hr|ht|hu|id|ie|il|im|in|info|int|io|iq|ir|is|it|je|jm|jo|jobs|jp|' 
     1183                        . 'ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|' 
     1184                        . 'ma|mc|md|me|mf|mg|mh|mil|mk|ml|mm|mn|mo|mobi|mp|mq|mr|ms|mt|mu|museum|' 
     1185                        . 'mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nu|nz|om|org|' 
     1186                        . 'pa|pe|pf|pg|ph|pk|pl|pm|pn|pro|ps|pt|pw|py|qa|re|ro|rs|ru|rw|' 
     1187                        . 'sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|' 
     1188                        . 'tc|td|tel|tf|tg|th|tj|tk|tl|tm|tn|to|tp|tr|travel|tt|tv|tw|tz|' 
     1189                        . 'ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw))+\b'; 
     1190                 
     1191                $path = '(?>\/[\w\d~?\/_=&#;\.!*\'\(\),\-\+:@$%]+)?'; 
     1192                $port = '(?>:\d{2,5})?'; 
     1193                $domain = '(?>[\w\d_\-]+)'; 
     1194                $subdomain = "(?>{$domain}\.)*"; 
     1195                $protocol = '(?>(http|ftp)(s)?:\/\/)?'; 
     1196                $url = "(?>{$protocol}((?>{$subdomain}{$domain}{$top_level_domains}|{$ip}){$port}{$path}))"; 
     1197 
     1198                $pattern = "/(url\( *['\"]?|['\"@=])?{$url}/"; 
     1199 
     1200                /* 
     1201                // PHP 5.3 
     1202                $replace = function( $matches ) 
     1203                { 
     1204                        if ( $matches[ 1 ] ) 
     1205                                return $matches[ 0 ]; 
     1206 
     1207                        $url = ( $matches[ 2 ] ) ? $matches[ 2 ] : 'http'; 
     1208                        $url .= "{$matches[ 3 ]}://{$matches[ 4 ]}"; 
     1209                        return "<a href=\"{$url}\" target=\"_blank\">{$matches[ 4 ]}</a>"; 
     1210                }; 
     1211                $body = preg_replace_callback( $pattern, $replace, $body ); 
     1212                */ 
     1213 
     1214                // PHP 5.2.x - Remover assim que possível 
     1215                $body = preg_replace_callback( $pattern, 
     1216                        create_function( 
     1217                                '$matches', 
     1218                                'if ( $matches[ 1 ] ) return $matches[ 0 ];' 
     1219                                        . '$url = ( $matches[ 2 ] ) ? $matches[ 2 ] : "http";' 
     1220                                        . '$url .= "{$matches[ 3 ]}://{$matches[ 4 ]}";' 
     1221                                        . 'return "<a href=\"{$url}\" target=\"_blank\">{$matches[ 4 ]}</a>";' 
     1222                        ), $body 
     1223                ); 
    11701224 
    11711225                // E-mail address in the text should create a new e-mail on ExpressoMail 
Note: See TracChangeset for help on using the changeset viewer.