1085a1086,1101
> //The following tags may contain text with a URL that should be converted to a link
> //List also contains standalone/empty tags like img and br
> $tags_begin = 'caption|td|th|div|dd|dt|li|blockquote|address|p|h[1-6]|i|b|u|tt|big|small|strike|s|em|strong|font|dfn|samp|kbd|var|cite|abbr|acronym|sub|sup|q|ins|del|img|br|object|applet';
>
>
> //transform each tagname from 'p' to '<\/?p[^>]*>'
> //this pattern will match
,
, and
> //the last one is significant for xhtml standalone tags like
and
> //note:
and
, won't work. While valid xhtml their use is discouraged anyway
> //note: the pattern will obviously match many invalid tags too like
> $arr_tags_begin = explode( "|", $tags_begin );
> for ( $i = 0; $i < count( $arr_tags_begin ); $i++ ){
> $arr_tags_begin[$i] = '<\/?' . $arr_tags_begin[$i] . '[^>]*>';
> }
> $tags_begin = implode( "|", $arr_tags_begin );
>
1091,1093c1107,1124
< // Match absolute URLs.
< $text = preg_replace_callback("`(
|
|
|[ \n\r\t\(])((http://|https://|ftp://|mailto:|smb://|afp://|file://|gopher://|news://|ssl://|sslv2://|sslv3://|tls://|tcp://|udp://)([a-zA-Z0-9@:%_+*~#?&=.,/;-]*[a-zA-Z0-9@:%_+*~#&=/;-]))([.,?!]*?)(?=(||
|[ \n\r\t\)]))`i", '_filter_url_parse_full_links', $text);
<
---
> //The structure of each three matches below is
> // 1. a tag from the list above or newline or
> // 2. any characters except "<"
> // 3. the url to match
> // 4. possible period or other marks at end of url are considered separate (end of sentence)
> // 5. end url in space, newline or tag ("<" character)
>
> //In many cases the patterns below only match the first url if there are many in the same paragraph.
> //Therefore the preg_replace are encapsulate in loops that will re-run the replace as many times as needed.
>
> // Match absolute URLs.
> $protocols = 'http://|https://|ftp://|mailto:|smb://|afp://|file://|gopher://|news://|ssl://|sslv2://|sslv3://|tls://|tcp://|udp://';
> $urlpattern = "($protocols)([a-zA-Z0-9@:%_+*~#?&=.,/;-]*[a-zA-Z0-9@:%_+*~#&=/;-])";
> $re = "`(($tags_begin|\n|\r|)([^<])*?)($urlpattern)(([\.\,\?\!]*?)[\<\s\n\r])`i";
> while(preg_match($re, $text)) {
> $text = preg_replace_callback($re, '_filter_url_parse_full_links', $text);
> }
>
1095,1096c1126,1131
< $text = preg_replace("`(|
|
|[ \n\r\t\(])([A-Za-z0-9._-]+@[A-Za-z0-9._+-]+\.[A-Za-z]{2,4})([.,?!]*?)(?=(||
|[ \n\r\t\)]))`i", '\1\2\3', $text);
<
---
> $urlpattern = '[A-Za-z0-9._-]+@[A-Za-z0-9._+-]+\.[A-Za-z]{2,4}';
> $re = "`(($tags_begin|\n|\r|)([^<])*?)($urlpattern)(([\.\,\?\!]*?)[\<\s\n\r])`i";
> while(preg_match($re, $text)) {
> $text = preg_replace($re, '\1\4\5', $text);
> }
>
1098c1133,1138
< $text = preg_replace_callback("`(|
|[ \n\r\t\(])(www\.[a-zA-Z0-9@:%_+*~#?&=.,/;-]*[a-zA-Z0-9@:%_+~#\&=/;-])([.,?!]*?)(?=(||
|[ \n\r\t\)]))`i", '_filter_url_parse_partial_links', $text);
---
> $urlpattern = 'www\.[a-zA-Z0-9@:%_+*~#?&=.,/;-]*[a-zA-Z0-9@:%_+~#\&=/;-]';
> $re = "`(($tags_begin|\n|\r|)([^<])*?)($urlpattern)(([\.\,\?\!]*?)[\<\s\n\r])`i";
> while(preg_match($re, $text)) {
> $text = preg_replace_callback($re, '_filter_url_parse_partial_links', $text);
> }
>
1100d1139
<
1182,1185c1221,1226
< $match[2] = decode_entities($match[2]);
< $caption = check_plain(_filter_url_trim($match[2]));
< $match[2] = check_url($match[2]);
< return $match[1] . ''. $caption .''. $match[5];
---
> //which parenthesis in the regexp contains the url?
> $i = 4;
> $match[$i] = decode_entities($match[$i]);
> $caption = check_plain(_filter_url_trim($match[$i]));
> $match[$i] = check_url($match[$i]);
> return $match[1] . ''. $caption .''. $match[$i+3];
1192,1195c1233,1238
< $match[2] = decode_entities($match[2]);
< $caption = check_plain(_filter_url_trim($match[2]));
< $match[2] = check_plain($match[2]);
< return $match[1] . ''. $caption .''. $match[3];
---
> //which parenthesis in the regexp contains the url?
> $i = 4;
> $match[$i] = decode_entities($match[$i]);
> $caption = check_plain(_filter_url_trim($match[$i]));
> $match[$i] = check_plain($match[$i]);
> return $match[1] . ''. $caption .''. $match[$i+1];
1196a1240
>