1 package Onis::Plugins::Words;
6 use Onis::Config (qw(get_config));
7 use Onis::Html (qw(get_filehandle));
8 use Onis::Language (qw(translate));
9 use Onis::Data::Core (qw(register_plugin));
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 ('OUTPUT', \&output);
17 our $WordCache = Onis::Data::Persistent->new ('WordCache', 'word', qw(counter lastusedtime lastusedby));
22 if (get_config ('ignore_words'))
24 my $tmp = get_config ('ignore_words');
27 $MIN_LENGTH = $tmp if ($tmp);
31 print STDERR $/, __FILE__, ": $VERSION" if ($::DEBUG);
38 my $text = $data->{'text'};
39 my $nick = $data->{'nick'};
40 my $words = $data->{'words'};
41 my $time = $data->{'epoch'};
47 next if (length ($word) < $MIN_LENGTH);
49 my ($counter) = $WordCache->get ($word);
53 $WordCache->put ($word, $counter, $time, $nick);
61 if (get_config ('plugin_max'))
63 my $tmp = get_config ('plugin_max');
66 $max = $tmp if ($tmp);
69 for ($WordCache->keys ())
72 my $ident = nick_to_ident ($word);
76 $WordCache->del ($word);
80 my ($counter, $lastusedtime, $lastusedby) = $WordCache->get ($word);
81 die unless (defined ($lastusedby));
83 my $nick = get_main_nick ($lastusedby);
84 push (@data, [$word, $counter, $nick, $lastusedtime]);
87 @$WordData = sort { $b->[0] <=> $a->[0] } (@data);
88 splice (@$WordData, $max);
94 return (undef) unless (@$WordData);
96 my $fh = get_filehandle ();
98 my $word = translate ('Word');
99 my $times = translate ('Times used');
100 my $last = translate ('Last used by');
103 <table class="plugin">
105 <td class="invis"> </td>
117 my ($word, $count, $nick) = @$_;
118 my $name = nick_to_name ($nick) || $nick;
121 qq# <td class="numeration">$i</td>\n#,
122 qq# <td>$word</td>\n#,
123 qq# <td>$count</td>\n#,
124 qq# <td class="nick">$name</td>\n#,
127 print $fh "</table>\n\n";