Changeset 2100


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

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

File:
1 edited

Legend:

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

    r1954 r2100  
    10491049                        return $body; 
    10501050 
    1051                 /* Replace links tags <a href="" ></a> to links with target=_blank */ 
    1052                 $pattern = '/<a[^>]+href="([^>"]+)"[^>]*>(.*)<\/a>/im'; 
    1053                 $replacement = '<a href="$1" target="_blank">$2</a>'; 
    1054                 $body = preg_replace($pattern, $replacement, $body); 
    1055  
    1056                 /*Replace websites that does NOT begin with href=" to links */ 
    1057                 $pattern = '/([^h][^r][^e][^f][^=][^"])((https?:\/\/)[A-Za-z0-9\.~?\/_=&#;\-:]*)/m'; 
    1058                 $replacement = '$1<a href="$2" target="_blank">$2</a>'; 
    1059                 $body = preg_replace($pattern, $replacement, $body); 
    1060  
    1061                 /*Transform email address in new_message_to*/ 
    1062                 $pattern = '/([A-Za-z0-9\.~?\/_=#\-]*@[A-Za-z0-9\.~?\/_=#\-]*)/im'; 
    1063                 $replacement = '<a href="javascript:new_message_to(\'$1\')">$1</a>'; 
    1064                 $body = preg_replace($pattern, $replacement, $body); 
    1065  
    1066                 /*Subs. email links to expresso*/ 
    1067                 $body = mb_ereg_replace("<a[^>]*href=[\'\"]mailto:([^\"\']+)[\'\"]>([^<]+)</a>", 
    1068                         "<a href=\"javascript:new_message_to('\\1')\">\\2</a>",$body); 
     1051                // All links should be moderated and they should only have the attribute 'target="blank"'. 
     1052                $pattern = '/<a[^>]+href="([^>"]+)"[^>]*>(.*)<\/a>/im'; 
     1053                $replacement = '<a href="$1" target="_blank">$2</a>'; 
     1054                $body = preg_replace( $pattern, $replacement, $body ); 
     1055 
     1056 
     1057                // Domains and IPs addresses found in the text and which is not a link yet should be replaced by one. 
     1058                // See more informations in www.iana.org 
     1059                $octets = array( 
     1060                        'first' => '(2[0-3][0-9]|1[0-9]{2}|[1-9][0-9]?)', 
     1061                        'middle' => '(25[0-5]|2[0-4][0-9]|1?[0-9]{1,2})', 
     1062                        'last' => '(25[0-4]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]?)' 
     1063                ); 
     1064 
     1065                $ip = "\b{$octets[ 'first' ]}\.({$octets[ 'middle' ]}\.){2}{$octets[ 'last' ]}\b"; 
     1066 
     1067                $top_level_domains = '(\.(ac|ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|as|asia|at|au|aw|ax|az|' 
     1068                        . 'ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bl|bm|bn|bo|br|bs|bt|bv|bw|by|bz|' 
     1069                        . 'ca|cat|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cu|cv|cx|cy|cz|' 
     1070                        . 'de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|' 
     1071                        . 'ga|gb|gd|ge|gf|gg|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|' 
     1072                        . 'hk|hm|hn|hr|ht|hu|id|ie|il|im|in|info|int|io|iq|ir|is|it|je|jm|jo|jobs|jp|' 
     1073                        . 'ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|' 
     1074                        . 'ma|mc|md|me|mf|mg|mh|mil|mk|ml|mm|mn|mo|mobi|mp|mq|mr|ms|mt|mu|museum|' 
     1075                        . 'mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nu|nz|om|org|' 
     1076                        . 'pa|pe|pf|pg|ph|pk|pl|pm|pn|pro|ps|pt|pw|py|qa|re|ro|rs|ru|rw|' 
     1077                        . 'sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|' 
     1078                        . 'tc|td|tel|tf|tg|th|tj|tk|tl|tm|tn|to|tp|tr|travel|tt|tv|tw|tz|' 
     1079                        . 'ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw))+\b'; 
     1080                 
     1081                $path = '(?>\/[\w\d~?\/_=&#;\.!*\'\(\),\-\+:@$%]+)?'; 
     1082                $port = '(?>:\d{2,5})?'; 
     1083                $domain = '(?>[\w\d_\-]+)'; 
     1084                $subdomain = "(?>{$domain}\.)*"; 
     1085                $protocol = '(?>(http|ftp)(s)?:\/\/)?'; 
     1086                $url = "(?>{$protocol}((?>{$subdomain}{$domain}{$top_level_domains}|{$ip}){$port}{$path}))"; 
     1087 
     1088                $pattern = "/(url\( *['\"]?|['\"@=])?{$url}/"; 
     1089 
     1090                /* 
     1091                // PHP 5.3 
     1092                $replace = function( $matches ) 
     1093                { 
     1094                        if ( $matches[ 1 ] ) 
     1095                                return $matches[ 0 ]; 
     1096 
     1097                        $url = ( $matches[ 2 ] ) ? $matches[ 2 ] : 'http'; 
     1098                        $url .= "{$matches[ 3 ]}://{$matches[ 4 ]}"; 
     1099                        return "<a href=\"{$url}\" target=\"_blank\">{$matches[ 4 ]}</a>"; 
     1100                }; 
     1101                $body = preg_replace_callback( $pattern, $replace, $body ); 
     1102                */ 
     1103 
     1104                // PHP 5.2.x - Remover assim que possível 
     1105                $body = preg_replace_callback( $pattern, 
     1106                        create_function( 
     1107                                '$matches', 
     1108                                'if ( $matches[ 1 ] ) return $matches[ 0 ];' 
     1109                                        . '$url = ( $matches[ 2 ] ) ? $matches[ 2 ] : "http";' 
     1110                                        . '$url .= "{$matches[ 3 ]}://{$matches[ 4 ]}";' 
     1111                                        . 'return "<a href=\"{$url}\" target=\"_blank\">{$matches[ 4 ]}</a>";' 
     1112                        ), $body 
     1113                ); 
     1114 
     1115                // E-mail address in the text should create a new e-mail on ExpressoMail 
     1116                $pattern = '/( |<|&lt;|>)([A-Za-z0-9\.~?\/_=#\-]*@[A-Za-z0-9\.~?\/_=#\-]*)( |>|&gt;|<)/im'; 
     1117                $replacement = '$1<a href="javascript:new_message_to(\'$2\')">$2</a>$3'; 
     1118                $body = preg_replace( $pattern, $replacement, $body ); 
     1119 
     1120                // If there is an link with a "mailto:" in href attribute, it will changed to create a new e-mail on ExpressoMail. 
     1121                $pattern = '/<a[^>]+href=["\']mailto:([^"]+)["\'][^>]*>([^<]+)<\/a>/im'; 
     1122                $replacement = '<a href="javascript:new_message_to(\'$1\')">$2</a>'; 
     1123                $body = preg_replace( $pattern, $replacement, $body ); 
    10691124 
    10701125 
Note: See TracChangeset for help on using the changeset viewer.