Selaa lähdekoodia

Filter URLs with ampersands, and add a pagefooter()

Morten Brix Pedersen 24 vuotta sitten
vanhempi
commit
f8df58585d
3 muutettua tiedostoa jossa 25 lisäystä ja 10 poistoa
  1. 1 0
      modules/Pisg.pm
  2. 19 6
      modules/Pisg/HTMLGenerator.pm
  3. 5 4
      modules/Pisg/Parser/Logfile.pm

+ 1 - 0
modules/Pisg.pm

@@ -92,6 +92,7 @@ sub get_default_config_settings
         outputfile => 'index.html',
         outputfile => 'index.html',
         maintainer => 'MAINTAINER',
         maintainer => 'MAINTAINER',
         pagehead => 'none',
         pagehead => 'none',
+        pagefoot => 'none',
         configfile => 'pisg.cfg',
         configfile => 'pisg.cfg',
         imagepath => '',
         imagepath => '',
         default_pic => '',
         default_pic => '',

+ 19 - 6
modules/Pisg/HTMLGenerator.pm

@@ -54,7 +54,9 @@ sub create_html
     }
     }
     $self->{cfg}->{headwidth} = $self->{cfg}->{tablewidth} - 4;
     $self->{cfg}->{headwidth} = $self->{cfg}->{tablewidth} - 4;
     $self->_htmlheader();
     $self->_htmlheader();
-    $self->_pageheader();
+    $self->_pageheader()
+        if ($self->{cfg}->{pagehead} ne 'none');
+
     if ($self->{cfg}->{show_activetimes}) {
     if ($self->{cfg}->{show_activetimes}) {
         $self->_activetimes();
         $self->_activetimes();
     }
     }
@@ -109,6 +111,9 @@ sub create_html
     my %hash = ( lines => $self->{stats}->{totallines} );
     my %hash = ( lines => $self->{stats}->{totallines} );
     _html($self->_template_text('totallines', %hash) . "<br /><br />");
     _html($self->_template_text('totallines', %hash) . "<br /><br />");
 
 
+    $self->_pagefooter()
+        if ($self->{cfg}->{pagefoot} ne 'none');
+
     $self->_htmlfooter();
     $self->_htmlfooter();
 
 
     close(OUTPUT);
     close(OUTPUT);
@@ -270,11 +275,18 @@ HTML
 sub _pageheader
 sub _pageheader
 {
 {
     my $self = shift;
     my $self = shift;
-    if ($self->{cfg}->{pagehead} ne 'none') {
-        open(PAGEHEAD, $self->{cfg}->{pagehead}) or die("$0: Unable to open $self->{cfg}->{pagehead} for reading: $!\n");
-        while (<PAGEHEAD>) {
-            _html($_);
-        }
+    open(PAGEHEAD, $self->{cfg}->{pagehead}) or die("$0: Unable to open $self->{cfg}->{pagehead} for reading: $!\n");
+    while (<PAGEHEAD>) {
+        _html($_);
+    }
+}
+
+sub _pagefooter
+{
+    my $self = shift;
+    open(PAGEFOOT, $self->{cfg}->{pagefoot}) or die("$0: Unable to open $self->{cfg}->{pagefoot} for reading: $!\n");
+    while (<PAGEFOOT>) {
+        _html($_);
     }
     }
 }
 }
 
 
@@ -1570,6 +1582,7 @@ sub _replace_links
         $str =~ s/(http|https|ftp|telnet|news)(:\/\/[-a-zA-Z0-9_\/~]+\.[-a-zA-Z0-9.,_~=:&amp;@%?#\/+]+)/<a href="$1$2" target="_blank" title="Open in new window: $1$2">$1$2<\/a>/g;
         $str =~ s/(http|https|ftp|telnet|news)(:\/\/[-a-zA-Z0-9_\/~]+\.[-a-zA-Z0-9.,_~=:&amp;@%?#\/+]+)/<a href="$1$2" target="_blank" title="Open in new window: $1$2">$1$2<\/a>/g;
         $str =~ s/([-a-zA-Z0-9._]+@[-a-zA-Z0-9_]+\.[-a-zA-Z0-9._]+)/<a href="mailto:$1" title="Mail to $1">$1<\/a>/g;
         $str =~ s/([-a-zA-Z0-9._]+@[-a-zA-Z0-9_]+\.[-a-zA-Z0-9._]+)/<a href="mailto:$1" title="Mail to $1">$1<\/a>/g;
     }
     }
+    $str =~ s/&/&amp;/g
     return $str;
     return $str;
 }
 }
 
 

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

@@ -279,10 +279,11 @@ sub _parse_file
 
 
                     # Find URLs
                     # Find URLs
                     if (my @urls = match_urls($saying)) {
                     if (my @urls = match_urls($saying)) {
-                        foreach (@urls) {
-                            if(!url_is_ignored($_)) {
-                                $stats->{urlcounts}{$_}++;
-                                $stats->{urlnicks}{$_} = $nick;
+                        foreach my $url (@urls) {
+                            if(!url_is_ignored($url)) {
+                                $url =~ s/&/&amp;/g;
+                                $stats->{urlcounts}{$url}++;
+                                $stats->{urlnicks}{$url} = $nick;
                             }
                             }
                         }
                         }
                     }
                     }