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));
10 use Onis::Data::Persistent ();
11 use Onis::Users (qw(nick_to_name));
13 register_plugin ('TEXT', \&add);
14 register_plugin ('ACTION', \&add);
15 register_plugin ('TOPIC', \&add);
16 register_plugin ('OUTPUT', \&output);
18 our $URLCache = Onis::Data::Persistent->new ('URLCache', 'url', qw(counter lastusedtime lastusedby));
22 print STDERR $/, __FILE__, ": $VERSION" if ($::DEBUG);
29 my $text = $data->{'text'};
30 my $nick = $data->{'nick'};
31 my $time = $data->{'epoch'};
33 while ($text =~ m#(?:(?:ftp|https?)://|www\.)[\w\.-]+\.[A-Za-z]{2,4}(?::\d+)?(?:/[\w\d\.\%\/\-\~]*(?:\?[\+\w\&\%\=]+)?)?(?=\W|$)#ig)
37 if ($match =~ m/^www/) { $match = 'http://' . $match; }
38 if ($match !~ m#://[^/]+/#) { $match .= '/'; }
40 my ($counter) = $URLCache->get ($match);
43 $URLCache->put ($match, $counter, $time, $nick);
51 if (get_config ('plugin_max'))
53 my $tmp = get_config ('plugin_max');
56 $max = $tmp if ($tmp);
59 for ($URLCache->keys ())
62 my ($counter, $lastusedtime, $lastusedby) = $URLCache->get ($url);
63 die unless (defined ($lastusedby));
65 $lastusedby = get_main_nick ($lastusedby);
66 push (@data, [$url, $counter, $lastusedby, $lastusedtime]);
69 @$URLData = sort { $b->[1] <=> $a->[1] } (@data);
70 splice (@$URLData, $max);
77 my $fh = get_filehandle ();
79 my $url = translate ('URL');
80 my $times = translate ('Times used');
81 my $last = translate ('Last used by');
84 <table class="plugin urls">
86 <td class="invis"> </td>
96 my ($url, $count, $usedby) = @$_;
97 my $name = nick_to_name ($usedby) || $usedby;
99 $url = html_escape ($url);
102 qq# <td class="numeration">$i</td>\n#,
103 qq# <td>$url</td>\n#,
104 qq# <td>$count</td>\n#,
105 qq# <td>$usedby</td>\n#,
109 print $fh "</table>\n\n";