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->[0 .. ($max - 1)];
156 $nick_data->{$nick} = get_core_nick_counters ($nick);
157 $nick_data->{$nick}{'conversations'} = get_conversations ($nick);
158 $nick_data->{$nick}{'bignumbers'} = get_bignumbers ($nick);
159 $nick_data->{$nick}{'interestingnumbers'} = get_interestingnumbers ($nick);
161 for (my $i = 0; $i < 12; $i++)
163 $num = $nick_data->{$nick}{'lines'}[2 * $i] + $nick_data->{$nick}{'lines'}[(2 * $i) + 1];
164 $max_time = $num if ($max_time < $num);
167 for (keys %{$nick_data->{$nick}{'conversations'}})
170 my $ptr = $nick_data->{$nick}{'conversations'}{'nicks'}{$other};
171 $num = $ptr->[0] + $ptr->[1] + $ptr->[2] + $ptr->[3];
172 $max_conv = $num if ($max_conv < $num);
181 $time_factor = $BAR_HEIGHT / $max_time;
186 $conv_factor = $BAR_WIDTH / $max_conv;
189 print $fh qq#<table class="plugin userdetails">\n#,
191 qq# <th colspan="#, $DISPLAY_IMAGES ? 3 : 2, qq#">$trans</th>\n#,
197 my $name = nick_to_name ($nick);
198 my $print = $name ? $name : $nick;
199 my $ptr = $nick_data->{$nick};
201 print $fh qq# <tr>\n#,
202 qq# <th colspan="#, $DISPLAY_IMAGES ? 3 : 2, qq#" class="nick">$print</th>\n#,
208 my $link = get_link ($name);
209 my $image = get_image ($name);
211 if ($DEFAULT_IMAGE and !$image)
213 $image = $DEFAULT_IMAGE;
216 print $fh qq# <td class="image" rowspan="2">#;
221 print $fh qq#<a href="$link">#;
223 print $fh qq#<img src="$image" alt="$print" />#;
236 print $fh qq# <td class="counters">\n#;
243 $lines = $ptr->{'lines_total'};
244 $trans = translate ('Has written %u lines');
245 printf $fh (" $trans<br />\n", $lines);
247 $words = $ptr->{'words_total'};
248 $trans = translate ('Has written %u words');
249 printf $fh (" $trans<br />\n", $words);
251 $chars = $ptr->{'chars_total'};
252 $trans = translate ('Has written %u chars');
253 printf $fh (" $trans<br />\n", $chars);
255 $num = $words / $lines;
256 $trans = translate ('Has written %.1f words per line');
257 printf $fh (" $trans<br />\n", $num);
259 $num = $chars / $lines;
260 $trans = translate ('Has written %.1f characters per line');
261 printf $fh (" $trans<br />\n", $num);
264 print $fh qq# </td>\n <td class="numbers">\n#;
266 if (%{$ptr->{'interestingnumbers'}})
268 $trans = translate ('Has given %u ops');
269 printf $fh (" $trans<br />\n", $ptr->{'interestingnumbers'}{'ops_given'});
271 $trans = translate ('Has taken %u ops');
272 printf $fh (" $trans<br />\n", $ptr->{'interestingnumbers'}{'ops_taken'});
274 $trans = translate ('Has kicked out %u people');
275 printf $fh (" $trans<br />\n", $ptr->{'interestingnumbers'}{'kicks_given'});
277 $trans = translate ('Has been kicked out %u times');
278 printf $fh (" $trans<br />\n", $ptr->{'interestingnumbers'}{'kicks_received'});
280 $trans = translate ('Has performed %u actions');
281 printf $fh (" $trans<br />\n", $ptr->{'interestingnumbers'}{'actions'});
284 if (%{$ptr->{'bignumbers'}})
286 $num = 100 * $ptr->{'bignumbers'}{'questions'} / $ptr->{'lines_total'};
287 $trans = translate ("Question ratio: %.1f%%");
288 printf $fh (" $trans<br />\n", $num);
290 $num = 100 * $ptr->{'bignumbers'}{'uppercase'} / $ptr->{'lines_total'};
291 $trans = translate ("Uppercase ratio: %.1f%%");
292 printf $fh (" $trans<br />\n", $num);
294 $num = 100 * $ptr->{'bignumbers'}{'smiley_happy'} / $ptr->{'lines_total'};
295 $trans = translate ("Happy smiley ratio: %.1f%%");
296 printf $fh (" $trans<br />\n", $num);
298 $num = 100 * $ptr->{'bignumbers'}{'smiley_sad'} / $ptr->{'lines_total'};
299 $trans = translate ("Sad smiley ratio: %.1f%%");
300 printf $fh (" $trans<br />\n", $num);
304 # exclamation ratio # TODO
310 print $fh qq# </td>\n </tr>\n <tr>\n <td class="houractivity">\n#;
312 if (defined ($ptr->{'chars'}))
314 print $fh qq# <table class="hours_of_day">\n <tr>\n#;
316 for (my $i = 0; $i < 12; $i++)
321 my $img = $V_IMAGES[int ($hour / 6)];
324 $num = $ptr->{'chars'}[$hour];
325 $num += $ptr->{'chars'}[$hour + 1];
327 $height = int (0.5 + ($time_factor * $num)) || 1;
329 print $fh qq# <td><img src="$img" alt="$num chars" #,
330 qq#style="height: ${height}px;" /></td>\n#;
335 <tr class="hour_row">
336 <td colspan="3">0-5</td>
337 <td colspan="3">6-11</td>
338 <td colspan="3">12-17</td>
339 <td colspan="3">18-23</td>
349 print $fh qq# </td>\n <td class="convpartners">\n#;
351 if (%{$ptr->{'conversations'}})
356 ($ptr->{'conversations'}{$b}{'nicks'}{$nick}[0]
357 + $ptr->{'conversations'}{$b}{'nicks'}{$nick}[1]
358 + $ptr->{'conversations'}{$b}{'nicks'}{$nick}[2]
359 + $ptr->{'conversations'}{$b}{'nicks'}{$nick}[3])
361 ($ptr->{'conversations'}{$a}{'nicks'}{$nick}[0]
362 + $ptr->{'conversations'}{$a}{'nicks'}{$nick}[1]
363 + $ptr->{'conversations'}{$a}{'nicks'}{$nick}[2]
364 + $ptr->{'conversations'}{$a}{'nicks'}{$nick}[3])
366 (keys %{$ptr->{'conversations'}});
368 $trans = translate ('Talks to');
373 <td colspan="2">$trans:</td>
377 for (my $i = 0; $i < $PLUGIN_MAX and $i < scalar (@others); $i++)
379 my $other = $others[$i];
380 my $other_name = nick_to_name ($other) || $other;
384 qq# <td class="nick">$other_name</td>\n#,
385 qq# <td class="bar">#;
387 for (my $k = 0; $k < 4; $k++)
389 my $img = $H_IMAGES[$k];
390 my $width = int (0.5 + ($conv_factor * $ptr->{'conversations'}{$other}{'nicks'}{$nick}[$k])) || 1;
392 print $fh qq#<img src="$img" alt="" #;
395 print $fh qq#class="first" #;
399 print $fh qq#class="last" #;
401 print $fh qq#style="width: ${width}px;" />#;
404 print $fh "</td>\n </tr>\n";
407 print $fh " </table>\n";
415 print $fh "</table>\n\n";