1 package Onis::Plugins::Userdetails;
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(get_main_nick register_plugin nick_to_name));
10 use Onis::Users (qw(ident_to_name get_link get_image));
12 use Onis::Plugins::Core (qw(get_core_nick_counters get_sorted_nicklist));
13 use Onis::Plugins::Conversations (qw(get_conversations));
14 use Onis::Plugins::Bignumbers (qw(get_bignumbers));
15 use Onis::Plugins::Interestingnumbers (qw(get_interestingnumbers));
17 our $DISPLAY_IMAGES = 0;
18 our $DEFAULT_IMAGE = '';
20 register_plugin ('OUTPUT', \&output);
22 our $SORT_BY = 'lines';
23 if (get_config ('sort_by'))
25 my $tmp = get_config ('sort_by');
28 if (($tmp eq 'lines') or ($tmp eq 'words') or ($tmp eq 'chars'))
34 # The Core plugin already complained about this..
38 if (get_config ('plugin_max'))
40 my $tmp = get_config ('plugin_max');
42 $PLUGIN_MAX = $tmp if ($tmp);
44 if (get_config ('display_images'))
46 my $tmp = get_config ('display_images');
48 if ($tmp =~ m/true|on|yes/i)
52 elsif ($tmp =~ m/false|off|no/i)
58 print STDERR $/, __FILE__, ": ``display_times'' has been set to the invalid value ``$tmp''. ",
59 $/, __FILE__, ": Valid values are ``true'' and ``false''. Using default value ``false''.";
62 if (get_config ('default_image'))
64 $DEFAULT_IMAGE = get_config ('default_image');
67 our @H_IMAGES = qw#dark-theme/h-red.png dark-theme/h-blue.png dark-theme/h-yellow.png dark-theme/h-green.png#;
68 if (get_config ('horizontal_images'))
70 my @tmp = get_config ('horizontal_images');
73 if (scalar (@tmp) != 4)
76 # The core-pligin already complained about this..
79 for ($i = 0; $i < 4; $i++)
81 if (!defined ($tmp[$i]))
86 $H_IMAGES[$i] = $tmp[$i];
90 our @V_IMAGES = qw#images/ver0n.png images/ver1n.png images/ver2n.png images/ver3n.png#;
91 if (get_config ('vertical_images'))
93 my @tmp = get_config ('vertical_images');
96 if (scalar (@tmp) != 4)
99 # Hopefully someone complained by now..
102 for ($i = 0; $i < 4; $i++)
104 if (!defined ($tmp[$i]))
109 $V_IMAGES[$i] = $tmp[$i];
113 our $BAR_HEIGHT = 130;
114 if (get_config ('bar_height'))
116 my $tmp = get_config ('bar_height');
118 $BAR_HEIGHT = $tmp if ($tmp >= 10);
120 #$BAR_HEIGHT = int ($BAR_HEIGHT / 2);
122 our $BAR_WIDTH = 100;
123 if (get_config ('bar_width'))
125 my $tmp = get_config ('bar_width');
127 $BAR_WIDTH = $tmp if ($tmp >= 10);
130 my $VERSION = '$Id: Userdetails.pm,v 1.5 2005/03/14 18:40:25 octo Exp $';
131 print STDERR $/, __FILE__, ": $VERSION" if ($::DEBUG);
137 my $nicks_ref = get_sorted_nicklist ();
139 my $max = $PLUGIN_MAX;
141 my $fh = get_filehandle ();
143 my $trans = translate ('Detailed nick stats');
149 my @nicks = @$nicks_ref;
152 splice (@nicks, $max) if (scalar (@nicks) > $max);
158 $nick_data->{$nick} = get_core_nick_counters ($nick);
159 $nick_data->{$nick}{'conversations'} = get_conversations ($nick);
160 $nick_data->{$nick}{'bignumbers'} = get_bignumbers ($nick);
161 $nick_data->{$nick}{'interestingnumbers'} = get_interestingnumbers ($nick);
163 for (my $i = 0; $i < 24; $i++)
165 $num = $nick_data->{$nick}{'chars'}[$i];
166 $max_time = $num if ($max_time < $num);
169 for (keys %{$nick_data->{$nick}{'conversations'}})
172 my $ptr = $nick_data->{$nick}{'conversations'}{$other}{'nicks'}{$nick};
173 $num = $ptr->[0] + $ptr->[1] + $ptr->[2] + $ptr->[3];
174 $max_conv = $num if ($max_conv < $num);
183 $time_factor = $BAR_HEIGHT / $max_time;
188 $conv_factor = $BAR_WIDTH / $max_conv;
191 print $fh qq#<table class="plugin userdetails">\n#,
193 qq# <th colspan="#, $DISPLAY_IMAGES ? 3 : 2, qq#">$trans</th>\n#,
199 my $name = nick_to_name ($nick);
200 my $print = $name ? $name : $nick;
201 my $ptr = $nick_data->{$nick};
203 print $fh qq# <tr>\n#,
204 qq# <th colspan="#, $DISPLAY_IMAGES ? 3 : 2, qq#" class="nick">$print</th>\n#,
210 my $link = get_link ($name);
211 my $image = get_image ($name);
213 if ($DEFAULT_IMAGE and !$image)
215 $image = $DEFAULT_IMAGE;
218 print $fh qq# <td class="image" rowspan="2">#;
223 print $fh qq#<a href="$link">#;
225 print $fh qq#<img src="$image" alt="$print" />#;
238 print $fh qq# <td class="counters">\n#;
245 $lines = $ptr->{'lines_total'};
246 $trans = translate ('Has written %u lines');
247 printf $fh (" $trans<br />\n", $lines);
249 $words = $ptr->{'words_total'};
250 $trans = translate ('Has written %u words');
251 printf $fh (" $trans<br />\n", $words);
253 $chars = $ptr->{'chars_total'};
254 $trans = translate ('Has written %u chars');
255 printf $fh (" $trans<br />\n", $chars);
259 $num = $words / $lines;
260 $trans = translate ('Has written %.1f words per line');
261 printf $fh (" $trans<br />\n", $num);
263 $num = $chars / $lines;
264 $trans = translate ('Has written %.1f characters per line');
265 printf $fh (" $trans<br />\n", $num);
268 print $fh qq# </td>\n <td class="numbers">\n#;
270 if (%{$ptr->{'interestingnumbers'}})
272 $trans = translate ('Has given %u ops');
273 printf $fh (" $trans<br />\n", $ptr->{'interestingnumbers'}{'op_given'});
275 $trans = translate ('Has taken %u ops');
276 printf $fh (" $trans<br />\n", $ptr->{'interestingnumbers'}{'op_taken'});
278 $trans = translate ('Has kicked out %u people');
279 printf $fh (" $trans<br />\n", $ptr->{'interestingnumbers'}{'kick_given'});
281 $trans = translate ('Has been kicked out %u times');
282 printf $fh (" $trans<br />\n", $ptr->{'interestingnumbers'}{'kick_received'});
284 $trans = translate ('Has performed %u actions');
285 printf $fh (" $trans<br />\n", $ptr->{'interestingnumbers'}{'actions'});
288 if (%{$ptr->{'bignumbers'}})
290 $num = 100 * $ptr->{'bignumbers'}{'questions'} / $ptr->{'lines_total'};
291 $trans = translate ("Question ratio: %.1f%%");
292 printf $fh (" $trans<br />\n", $num);
294 $num = 100 * $ptr->{'bignumbers'}{'uppercase'} / $ptr->{'lines_total'};
295 $trans = translate ("Uppercase ratio: %.1f%%");
296 printf $fh (" $trans<br />\n", $num);
298 $num = 100 * $ptr->{'bignumbers'}{'smiley_happy'} / $ptr->{'lines_total'};
299 $trans = translate ("Happy smiley ratio: %.1f%%");
300 printf $fh (" $trans<br />\n", $num);
302 $num = 100 * $ptr->{'bignumbers'}{'smiley_sad'} / $ptr->{'lines_total'};
303 $trans = translate ("Sad smiley ratio: %.1f%%");
304 printf $fh (" $trans<br />\n", $num);
308 # exclamation ratio # TODO
314 print $fh qq# </td>\n </tr>\n <tr>\n <td class="houractivity">\n#;
316 if (defined ($ptr->{'chars'}))
318 print $fh qq# <table class="hours">\n <tr class="bars">\n#;
320 for (my $i = 0; $i < 24; $i++)
324 my $img = $V_IMAGES[int ($i / 6)];
327 $num = $ptr->{'chars'}[$i];
329 $height = sprintf ("%.2f", 95 * $num / $max_time);
331 print $fh qq# <td class="bar vertical"><img src="$img" alt="$num chars" #,
332 qq#class="first last" style="height: $height\%;" /></td>\n#;
337 <tr class="numeration">
338 <td colspan="6" class="numeration">0-5</td>
339 <td colspan="6" class="numeration">6-11</td>
340 <td colspan="6" class="numeration">12-17</td>
341 <td colspan="6" class="numeration">18-23</td>
351 print $fh qq# </td>\n <td class="convpartners">\n#;
353 if (%{$ptr->{'conversations'}})
358 ($ptr->{'conversations'}{$b}{'nicks'}{$nick}[0]
359 + $ptr->{'conversations'}{$b}{'nicks'}{$nick}[1]
360 + $ptr->{'conversations'}{$b}{'nicks'}{$nick}[2]
361 + $ptr->{'conversations'}{$b}{'nicks'}{$nick}[3])
363 ($ptr->{'conversations'}{$a}{'nicks'}{$nick}[0]
364 + $ptr->{'conversations'}{$a}{'nicks'}{$nick}[1]
365 + $ptr->{'conversations'}{$a}{'nicks'}{$nick}[2]
366 + $ptr->{'conversations'}{$a}{'nicks'}{$nick}[3])
368 (keys %{$ptr->{'conversations'}});
370 $trans = translate ('Talks to');
375 <td colspan="2">$trans:</td>
379 for (my $i = 0; $i < $PLUGIN_MAX and $i < scalar (@others); $i++)
381 my $other = $others[$i];
382 my $other_name = nick_to_name ($other) || $other;
386 qq# <td class="nick">$other_name</td>\n#,
387 qq# <td class="bar">#;
389 for (my $k = 0; $k < 4; $k++)
391 my $img = $H_IMAGES[$k];
392 my $width = int (0.5 + ($conv_factor * $ptr->{'conversations'}{$other}{'nicks'}{$nick}[$k])) || 1;
394 print $fh qq#<img src="$img" alt="" #;
397 print $fh qq#class="first" #;
401 print $fh qq#class="last" #;
403 print $fh qq#style="width: ${width}px;" />#;
406 print $fh "</td>\n </tr>\n";
409 print $fh " </table>\n";
417 print $fh "</table>\n\n";