1 package Onis::Plugins::Urls;
6 use Onis::Config (qw(get_config));
7 use Onis::Html (qw(html_escape get_filehandle));
8 use Onis::Language (qw(translate));
9 use Onis::Data::Core (qw(register_plugin get_main_nick nick_to_name));
10 use Onis::Data::Persistent ();
12 register_plugin ('TEXT', \&add);
13 register_plugin ('ACTION', \&add);
14 register_plugin ('TOPIC', \&add);
15 register_plugin ('OUTPUT', \&output);
17 our $URLCache = Onis::Data::Persistent->new ('URLCache', 'url', qw(counter lastusedtime lastusedby));
21 print STDERR $/, __FILE__, ": $VERSION" if ($::DEBUG);
28 my $text = $data->{'text'};
29 my $nick = $data->{'nick'};
30 my $time = $data->{'epoch'};
32 while ($text =~ m#(?:(?:ftp|https?)://|www\.)[\w\.-]+\.[A-Za-z]{2,4}(?::\d+)?(?:/[\w\d\.\%\/\-\~]*(?:\?[\+\w\&\%\=]+)?)?(?=\W|$)#ig)
36 if ($match =~ m/^www/) { $match = 'http://' . $match; }
37 if ($match !~ m#://[^/]+/#) { $match .= '/'; }
39 my ($counter) = $URLCache->get ($match);
42 $URLCache->put ($match, $counter, $time, $nick);
50 if (get_config ('plugin_max'))
52 my $tmp = get_config ('plugin_max');
55 $max = $tmp if ($tmp);
58 for ($URLCache->keys ())
61 my ($counter, $lastusedtime, $lastusedby) = $URLCache->get ($url);
62 die unless (defined ($lastusedby));
64 $lastusedby = get_main_nick ($lastusedby);
65 push (@data, [$url, $counter, $lastusedby, $lastusedtime]);
68 @$URLData = sort { $b->[1] <=> $a->[1] } (@data);
69 splice (@$URLData, $max) if (scalar (@$URLData) > $max);
76 my $fh = get_filehandle ();
78 my $url = translate ('URL');
79 my $times = translate ('Times used');
80 my $last = translate ('Last used by');
83 <table class="plugin urls">
85 <td class="invis"> </td>
95 my ($url, $count, $usedby) = @$_;
96 my $name = nick_to_name ($usedby) || $usedby;
98 $url = html_escape ($url);
101 qq# <td class="numeration">$i</td>\n#,
102 qq# <td>$url</td>\n#,
103 qq# <td>$count</td>\n#,
104 qq# <td>$usedby</td>\n#,
108 print $fh "</table>\n\n";