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));
10 use Onis::Users (qw(ident_to_name get_link get_image));
12 use Onis::Plugin::Core (qw(get_core_nick_counters));
13 use Onis::Plugin::Conversations (qw(get_conversations));
14 use Onis::Plugin::Bignumbers (qw(get_bignumbers));
16 our $DISPLAY_IMAGES = 0;
17 our $DEFAULT_IMAGE = '';
19 register_plugin ('OUTPUT', \&output);
21 our $SORT_BY = 'lines';
22 if (get_config ('sort_by'))
24 my $tmp = get_config ('sort_by');
27 if (($tmp eq 'lines') or ($tmp eq 'words') or ($tmp eq 'chars'))
33 # The Core plugin already complained about this..
37 if (get_config ('plugin_max'))
39 my $tmp = get_config ('plugin_max');
41 $PLUGIN_MAX = $tmp if ($tmp);
43 if (get_config ('display_images'))
45 my $tmp = get_config ('display_images');
47 if ($tmp =~ m/true|on|yes/i)
51 elsif ($tmp =~ m/false|off|no/i)
57 print STDERR $/, __FILE__, ": ``display_times'' has been set to the invalid value ``$tmp''. ",
58 $/, __FILE__, ": Valid values are ``true'' and ``false''. Using default value ``false''.";
61 if (get_config ('default_image'))
63 $DEFAULT_IMAGE = get_config ('default_image');
66 our @H_IMAGES = qw#dark-theme/h-red.png dark-theme/h-blue.png dark-theme/h-yellow.png dark-theme/h-green.png#;
67 if (get_config ('horizontal_images'))
69 my @tmp = get_config ('horizontal_images');
72 if (scalar (@tmp) != 4)
75 # The core-pligin already complained about this..
78 for ($i = 0; $i < 4; $i++)
80 if (!defined ($tmp[$i]))
85 $H_IMAGES[$i] = $tmp[$i];
89 our @V_IMAGES = qw#images/ver0n.png images/ver1n.png images/ver2n.png images/ver3n.png#;
90 if (get_config ('vertical_images'))
92 my @tmp = get_config ('vertical_images');
95 if (scalar (@tmp) != 4)
98 # Hopefully someone complained by now..
101 for ($i = 0; $i < 4; $i++)
103 if (!defined ($tmp[$i]))
108 $V_IMAGES[$i] = $tmp[$i];
112 our $BAR_HEIGHT = 130;
113 if (get_config ('bar_height'))
115 my $tmp = get_config ('bar_height');
117 $BAR_HEIGHT = $tmp if ($tmp >= 10);
119 #$BAR_HEIGHT = int ($BAR_HEIGHT / 2);
121 our $BAR_WIDTH = 100;
122 if (get_config ('bar_width'))
124 my $tmp = get_config ('bar_width');
126 $BAR_WIDTH = $tmp if ($tmp >= 10);
129 my $VERSION = '$Id: Userdetails.pm,v 1.5 2005/03/14 18:40:25 octo Exp $';
130 print STDERR $/, __FILE__, ": $VERSION" if ($::DEBUG);
136 my $nicks_ref = get_sorted_nicklist ();
138 my $max = $PLUGIN_MAX;
140 my $fh = get_filehandle ();
142 my $trans = translate ('Detailed nick stats');
148 my @nicks = $nicks_ref->[0 .. ($max - 1)];
155 $nick_data->{$nick} = get_core_nick_counters ($nick);
156 $nick_data->{$nick}{'conversations'} = get_conversations ($nick);
157 $nick_data->{$nick}{'bignumbers'} = get_bignumbers ($nick);
159 for (my $i = 0; $i < 12; $i++)
161 $num = $nick_data->{$nick}{'lines'}[$i] + $nick_data->{$nick}{'lines'}[$i + 1];
162 $max_time = $num if ($max_time < $num);
165 for (keys %{$nick_data->{$nick}{'conversations'}})
168 my $ptr = $nick_data->{$nick}{'conversations'}{'nicks'}{$other};
169 $num = $ptr->[0] + $ptr->[1] + $ptr->[2] + $ptr->[3];
170 $max_conv = $num if ($max_conv < $num);
179 $time_factor = $BAR_HEIGHT / $max_time;
184 $conv_factor = $BAR_WIDTH / $max_conv;
187 print $fh qq#<table class="plugin userdetails">\n#,
189 qq# <th colspan="#, $DISPLAY_IMAGES ? 3 : 2, qq#">$trans</th>\n#,
195 my $name = nick_to_name ($nick);
196 my $print = $name ? $name : $nick;
197 my $ptr = $nick_data->{$nick};
199 print $fh qq# <tr>\n#,
200 qq# <th colspan="#, $DISPLAY_IMAGES ? 3 : 2, qq#" class="nick">$print</th>\n#,
206 my $link = get_link ($name);
207 my $image = get_image ($name);
209 if ($DEFAULT_IMAGE and !$image)
211 $image = $DEFAULT_IMAGE;
214 print $fh qq# <td class="image" rowspan="2">#;
219 print $fh qq#<a href="$link">#;
221 print $fh qq#<img src="$image" alt="$print" />#;
234 print $fh qq# <td class="counters">\n#;
241 $lines = $ptr->{'lines_total'};
242 $trans = translate ('Has written %u lines');
243 printf $fh (" $trans<br />\n", $lines);
245 $words = $ptr->{'words_total'};
246 $trans = translate ('Has written %u words');
247 printf $fh (" $trans<br />\n", $words);
249 $chars = $ptr->{'chars_total'};
250 $trans = translate ('Has written %u chars');
251 printf $fh (" $trans<br />\n", $chars);
253 $num = $words / $lines;
254 $trans = translate ('Has written %.1f words per line');
255 printf $fh (" $trans<br />\n", $num);
257 $num = $chars / $lines;
258 $trans = translate ('Has written %.1f characters per line');
259 printf $fh (" $trans<br />\n", $num);
262 print $fh qq# </td>\n <td class="numbers">\n#;
266 if (defined ($DATA->{'byname'}{$name}{'op_given'}))
268 $num = $DATA->{'byname'}{$name}{'op_given'};
269 $trans = translate ('Has given %u ops');
271 printf $fh (" $trans<br />\n", $num);
274 if (defined ($DATA->{'byname'}{$name}{'op_taken'}))
276 $num = $DATA->{'byname'}{$name}{'op_taken'};
277 $trans = translate ('Has taken %u ops');
279 printf $fh (" $trans<br />\n", $num);
282 if (defined ($DATA->{'byname'}{$name}{'kick_given'}))
284 $num = $DATA->{'byname'}{$name}{'kick_given'};
285 $trans = translate ('Has kicked out %u people');
287 printf $fh (" $trans<br />\n", $num);
290 if (defined ($DATA->{'byname'}{$name}{'kick_received'}))
292 $num = $DATA->{'byname'}{$name}{'kick_received'};
293 $trans = translate ('Has been kicked out %u times');
295 printf $fh (" $trans<br />\n", $num);
298 if (defined ($DATA->{'byname'}{$name}{'questions'}))
300 $num = 100 * $DATA->{'byname'}{$name}{'questions'} / $DATA->{'byname'}{$name}{'lines'};
301 $trans = translate ("Question ratio: %.1f%%");
303 printf $fh (" $trans<br />\n", $num);
306 if (defined ($DATA->{'byname'}{$name}{'topics'}))
308 $num = $DATA->{'byname'}{$name}{'topics'};
309 $trans = translate ('Has set %u topics');
311 printf $fh (" $trans<br />\n", $num);
314 if (defined ($DATA->{'byname'}{$name}{'actions'}))
316 $num = $DATA->{'byname'}{$name}{'actions'};
317 $trans = translate ('Has performed %u actions');
319 printf $fh (" $trans<br />\n", $num);
323 # exclamation ratio # TODO
329 print $fh qq# </td>\n </tr>\n <tr>\n <td class="houractivity">\n#;
331 if (defined ($DATA->{'byname'}{$name}{'chars_time'}))
333 print $fh qq# <table class="hours_of_day">\n <tr>\n#;
340 my $img = $V_IMAGES[int ($hour / 6)];
343 if (defined ($DATA->{'byname'}{$name}{'chars_time'}{$hour}))
345 $num = $DATA->{'byname'}{$name}{'chars_time'}{$hour};
347 if (defined ($DATA->{'byname'}{$name}{'chars_time'}{1 + $hour}))
349 $num = $DATA->{'byname'}{$name}{'chars_time'}{1 + $hour};
352 $height = int (0.5 + ($time_factor * $num));
358 print $fh qq# <td><img src="$img" alt="$num chars" #,
359 qq#style="height: ${height}px;" /></td>\n#;
364 <tr class="hour_row">
365 <td colspan="3">0-5</td>
366 <td colspan="3">6-11</td>
367 <td colspan="3">12-17</td>
368 <td colspan="3">18-23</td>
378 print $fh qq# </td>\n <td class="convpartners">\n#;
380 if (defined ($DATA->{'byname'}{$name}{'conversations'}))
383 my $data = $DATA->{'byname'}{$name}{'conversations'};
386 ($data->{$b}[0] + $data->{$b}[1] + $data->{$b}[2] + $data->{$b}[3])
388 ($data->{$a}[0] + $data->{$a}[1] + $data->{$a}[2] + $data->{$a}[3])
392 $trans = translate ('Talks to');
397 <td colspan="2">$trans:</td>
408 qq# <td class="nick">$this_name</td>\n#,
409 qq# <td class="bar">#;
415 my $img = $H_IMAGES[$k];
416 my $width = int (0.5 + ($conv_factor * $data->{$this_name}[$_]));
422 print $fh qq#<img src="$img" alt="" #;
425 print $fh qq#class="first" #;
429 print $fh qq#class="last" #;
431 print $fh qq#style="width: ${width}px;" />#;
434 print $fh "</td>\n </tr>\n";
438 if ($i >= $PLUGIN_MAX)
444 print $fh " </table>\n";
458 print $fh "</table>\n\n";