Changeset 1698

Show
Ignore:
Timestamp:
03/26/07 09:26:54 (19 months ago)
Author:
mbonetti
Message:

fix for yet another url wrongly handled

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/gregarius/plugins/urlfilter.php

    r1540 r1698  
    3131/// Author: Marco Bonetti 
    3232/// Description: This plugin will try to make ugly URL links look better 
    33 /// Version: 1.8 
     33/// Version: 1.9 
    3434 
    3535/** 
     
    3737 * with a nicer <a href="http://www.test.com/a/b/c.html">[test.com]</a> 
    3838 */ 
    39 function __urlfilter_filter($in) { 
    40     $match = '#<a[^>]+?href="(.*?)">\\1</a>#im'; 
    41     // matches non-linkified URLs 
    42     $match2 = '#[^>"\'/=\?](http[^\s$]+)[\s$]?#im'; 
    43     $ret= preg_replace_callback($match, '__filter_callback', $in); 
    44     $ret2= preg_replace_callback($match2,'__filter_callback', $ret); 
    45     return $ret2; 
    46 } 
    4739 
    48 /** 
    49  * We need a callback because for some obscure reason the /ie modifier wouldnt work  
    50  * in preg_replace alone. This basically formats the output 
    51  */ 
    52 function __filter_callback($matches) { 
    53     $ret = preg_match("/^(http:\/\/)?([^\/]+)/i", $matches[1], $outmatches); 
    54     if ($outmatches && isset ($outmatches[2])) { 
    55         return " <a href=\"". $matches[1]."\">[" . $outmatches[2] . "]</a> "; 
    56     } 
    57     return " <a href=\"". $matches[1]."\">[" . $matches[1] . "]</a> "; 
    58 }  
     40 function __urlfilter_filter($in) { 
     41     $match = '#<a[^>]+?href="(.*?)">\\1</a>#im'; 
     42     // matches non-linkified URLs 
     43     $match2 = '#[^>"\'/=\?](http[^\s<$]+)[\s$]?#im'; 
     44     $ret= preg_replace_callback($match, '__filter_callback', $in); 
     45     $ret2= preg_replace_callback($match2,'__filter_callback', $ret); 
     46     return $ret2; 
     47 } 
     48 
     49 /** 
     50  * We need a callback because for some obscure reason the /ie modifier wouldnt work  
     51  * in preg_replace alone. This basically formats the output 
     52  */ 
     53 function __filter_callback($matches) { 
     54     $ret = preg_match("/^(http:\/\/)?([^\/<]+)/i", $matches[1], $outmatches); 
     55     if ($outmatches && isset ($outmatches[2])) { 
     56         return " <a href=\"". $matches[1]."\">[" . $outmatches[2] . "]</a> "; 
     57     } 
     58     return " <a href=\"". $matches[1]."\">[" . $matches[1] . "]</a> "; 
     59 }  
    5960 
    6061