Просмотр исходного кода

Finally fix the multiple URLs in a line-thingy

Morten Brix Pedersen 24 лет назад
Родитель
Сommit
21041b50bb
3 измененных файлов с 18 добавлено и 12 удалено
  1. 1 2
      modules/Pisg/Common.pm
  2. 3 5
      modules/Pisg/HTMLGenerator.pm
  3. 14 5
      modules/Pisg/Parser/Logfile.pm

+ 1 - 2
modules/Pisg/Common.pm

@@ -109,8 +109,7 @@ sub match_url
 {
     my ($str) = @_;
 
-    #if ($str =~ /(http|https|ftp|telnet|news)(:\/\/[-a-zA-Z0-9_]+\.[-a-zA-Z0-9.,_~=:;&@%?#\/+]+)/) {
-    if ($str =~ /(http:\/\/|https:\/\/|ftp:\/\/|telnet:\/\/|news:\/\/|www.)([-a-zA-Z0-9_\/~]+\.[-a-zA-Z0-9.,_~=:&@%?#\/+]+)/) {
+    if ($str =~ /(http|https|ftp|telnet|news)(:\/\/[-a-zA-Z0-9_\/~]+\.[-a-zA-Z0-9.,_~=:&@%?#\/+]+)/) { 
         my $url = "$1$2";
         if ($url_seen{$url}) {
             return $url;

+ 3 - 5
modules/Pisg/HTMLGenerator.pm

@@ -1538,6 +1538,8 @@ sub _replace_links
     my $nick = shift;
     my ($url, $email, $replaced, $return_str);
 
+
+    $str =~ s/(http:\/\/)?www\./http:\/\/www\./ig;
     $return_str = $str;
     $replaced = 0;
      if ($nick) {
@@ -1551,11 +1553,7 @@ sub _replace_links
         while ($replaced < 1) {
             $replaced = 1;
             if ($url = match_url($str)) {
-                if ($url =~ /^www\./i) {
-                    $return_str =~ s/(\Q$url\E)/<a href="http:\/\/$1" target="_blank" title="Open in new window: $1">$1<\/a>/g;
-                } else {
-                    $return_str =~ s/(\Q$url\E)/<a href="$1" target="_blank" title="Open in new window: $1">$1<\/a>/g;
-                }
+                $return_str =~ s/(?<!(<a href="))(\Q$url\E)(?![-a-zA-Z0-9.,_~=:;&@%?#\/+]+)/<a href="$2" target="_blank" title="Open in new window: $2">$2<\/a>/g;
                 $str =~ s/(\Q$url\E)//g;
                 $replaced--;
             }

+ 14 - 5
modules/Pisg/Parser/Logfile.pm

@@ -286,11 +286,20 @@ sub _parse_file
                         $stats->{frowns}{$nick}++;
                     }
 
-                    if (my $url = match_url($saying)) {
-                        unless(url_is_ignored($url)) {
-                            $stats->{urlcounts}{$url}++;
-                            $stats->{urlnicks}{$url} = $nick;
-                        }
+                    # Find URLs
+                    my $check_str = $saying;                                                   
+                    $check_str =~ s/(http:\/\/)?www\./http:\/\/www\./ig;                       
+                    my $replaced = 0;                                                          
+                    while ($replaced < 1) {                                                    
+                        $replaced = 1;                                                         
+                        if (my $url = match_url($check_str)) {                                 
+                            unless(url_is_ignored($url)) {                                     
+                                $stats->{urlcounts}{$url}++;                                   
+                                $stats->{urlnicks}{$url} = $nick;                              
+                            }                                                                  
+                            $check_str =~ s/(\Q$url\E)//g;                                     
+                            $replaced--;                                                       
+                        }                                                                      
                     }
 
                     $self->_parse_words($stats, $saying, $nick);