X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=lib%2FOnis%2FPlugins%2FCore.pm;fp=lib%2FOnis%2FPlugins%2FCore.pm;h=ab7ae60f01ab77f80eca4d2a8837c707aaef2ba3;hb=6d3432d621c9e0c075b97629f544a262bbeecbb2;hp=0000000000000000000000000000000000000000;hpb=1dba71b203ceb19823a3c426e303969070db42d0;p=onis.git diff --git a/lib/Onis/Plugins/Core.pm b/lib/Onis/Plugins/Core.pm new file mode 100644 index 0000000..ab7ae60 --- /dev/null +++ b/lib/Onis/Plugins/Core.pm @@ -0,0 +1,760 @@ +package Onis::Plugins::Core; + +use strict; +use warnings; + +use Onis::Config qw/get_config/; +use Onis::Html qw/html_escape get_filehandle/; +use Onis::Language qw/translate/; +use Onis::Users qw/get_name get_link get_image nick_to_username/; +use Onis::Data::Core qw#all_nicks nick_to_ident ident_to_nick get_main_nick register_plugin#; +use Onis::Data::Persistent qw#init#; + +our $DATA; +our $QUOTE_CACHE = init ('$QUOTE_CACHE', 'hash'); + +our @H_IMAGES = qw#dark-theme/h-red.png dark-theme/h-blue.png dark-theme/h-yellow.png dark-theme/h-green.png#; +our $QUOTE_CACHE_SIZE = 10; +our $QUOTE_MIN = 30; +our $QUOTE_MAX = 80; +our $WORD_LENGTH = 5; +our $SORT_BY = 'LINES'; +our $DISPLAY_LINES = 'BOTH'; +our $DISPLAY_WORDS = 'NONE'; +our $DISPLAY_CHARS = 'NONE'; +our $DISPLAY_TIMES = 0; +our $DISPLAY_IMAGES = 0; +our $DEFAULT_IMAGE = ''; +our $BAR_HEIGHT = 130; +our $BAR_WIDTH = 100; +our $LONGLINES = 50; +our $SHORTLINES = 10; + +if (get_config ('quote_cache_size')) +{ + my $tmp = get_config ('quote_cache_size'); + $tmp =~ s/\D//g; + $QUOTE_CACHE_SIZE = $tmp if ($tmp); +} +if (get_config ('quote_min')) +{ + my $tmp = get_config ('quote_min'); + $tmp =~ s/\D//g; + $QUOTE_MIN = $tmp if ($tmp); +} +if (get_config ('quote_max')) +{ + my $tmp = get_config ('quote_max'); + $tmp =~ s/\D//g; + $QUOTE_MAX = $tmp if ($tmp); +} +if (get_config ('min_word_length')) +{ + my $tmp = get_config ('min_word_length'); + $tmp =~ s/\D//g; + $WORD_LENGTH = $tmp if ($tmp); +} +if (get_config ('display_lines')) +{ + my $tmp = get_config ('display_lines'); + $tmp = uc ($tmp); + + if (($tmp eq 'NONE') or ($tmp eq 'BAR') or ($tmp eq 'NUMBER') or ($tmp eq 'BOTH')) + { + $DISPLAY_LINES = $tmp; + } + else + { + $tmp = get_config ('display_lines'); + print STDERR $/, __FILE__, ": ``display_lines'' has been set to the invalid value ``$tmp''. ", + $/, __FILE__, ": Valid values are ``none'', ``bar'', ``number'' and ``both''. Using default value ``both''."; + } +} +if (get_config ('display_words')) +{ + my $tmp = get_config ('display_words'); + $tmp = uc ($tmp); + + if (($tmp eq 'NONE') or ($tmp eq 'BAR') or ($tmp eq 'NUMBER') or ($tmp eq 'BOTH')) + { + $DISPLAY_WORDS = $tmp; + } + else + { + $tmp = get_config ('display_words'); + print STDERR $/, __FILE__, ": ``display_words'' has been set to the invalid value ``$tmp''. ", + $/, __FILE__, ": Valid values are ``none'', ``bar'', ``number'' and ``both''. Using default value ``none''."; + } +} +if (get_config ('display_chars')) +{ + my $tmp = get_config ('display_chars'); + $tmp = uc ($tmp); + + if (($tmp eq 'NONE') or ($tmp eq 'BAR') or ($tmp eq 'NUMBER') or ($tmp eq 'BOTH')) + { + $DISPLAY_CHARS = $tmp; + } + else + { + $tmp = get_config ('display_chars'); + print STDERR $/, __FILE__, ": ``display_chars'' has been set to the invalid value ``$tmp''. ", + $/, __FILE__, ": Valid values are ``none'', ``bar'', ``number'' and ``both''. Using default value ``none''."; + } +} +if (get_config ('display_times')) +{ + my $tmp = get_config ('display_times'); + + if ($tmp =~ m/true|on|yes/i) + { + $DISPLAY_TIMES = 1; + } + elsif ($tmp =~ m/false|off|no/i) + { + $DISPLAY_TIMES = 0; + } + else + { + print STDERR $/, __FILE__, ": ``display_times'' has been set to the invalid value ``$tmp''. ", + $/, __FILE__, ": Valid values are ``true'' and ``false''. Using default value ``false''."; + } +} +if (get_config ('display_images')) +{ + my $tmp = get_config ('display_images'); + + if ($tmp =~ m/true|on|yes/i) + { + $DISPLAY_IMAGES = 1; + } + elsif ($tmp =~ m/false|off|no/i) + { + $DISPLAY_IMAGES = 0; + } + else + { + print STDERR $/, __FILE__, ": ``display_times'' has been set to the invalid value ``$tmp''. ", + $/, __FILE__, ": Valid values are ``true'' and ``false''. Using default value ``false''."; + } +} +if (get_config ('default_image')) +{ + $DEFAULT_IMAGE = get_config ('default_image'); +} +if (get_config ('sort_by')) +{ + my $tmp = get_config ('sort_by'); + $tmp = uc ($tmp); + + if (($tmp eq 'LINES') or ($tmp eq 'WORDS') or ($tmp eq 'CHARS')) + { + $SORT_BY = $tmp; + } + else + { + $tmp = get_config ('sort_by'); + print STDERR $/, __FILE__, ": ``sort_by'' has been set to the invalid value ``$tmp''. ", + $/, __FILE__, ": Valid values are ``lines'' and ``words''. Using default value ``lines''."; + } +} +if (get_config ('horizontal_images')) +{ + my @tmp = get_config ('horizontal_images'); + my $i; + + if (scalar (@tmp) != 4) + { + print STDERR $/, __FILE__, ": The number of horizontal images is not four. The output might look weird.", $/; + } + + for ($i = 0; $i < 4; $i++) + { + if (!defined ($tmp[$i])) + { + next; + } + + $H_IMAGES[$i] = $tmp[$i]; + } +} +if (get_config ('bar_height')) +{ + my $tmp = get_config ('bar_height'); + $tmp =~ s/\D//g; + $BAR_HEIGHT = $tmp if ($tmp >= 10); +} +if (get_config ('bar_width')) +{ + my $tmp = get_config ('bar_width'); + $tmp =~ s/\D//g; + $BAR_WIDTH = $tmp if ($tmp >= 10); +} +if (get_config ('longlines')) +{ + my $tmp = get_config ('longlines'); + $tmp =~ s/\D//g; + $LONGLINES = $tmp if ($tmp); +} +if (get_config ('shortlines')) +{ + my $tmp = get_config ('shortlines'); + $tmp =~ s/\D//g; + if ($tmp or ($tmp == 0)) + { + $SHORTLINES = $tmp; + } +} + +$DATA = register_plugin ('TEXT', \&add); +$DATA = register_plugin ('ACTION', \&add); +$DATA = register_plugin ('OUTPUT', \&output); + +if (!defined ($DATA->{'byhour'})) +{ + $DATA->{'byhour'} = []; +} + +my $VERSION = '$Id: Core.pm,v 1.12 2004/04/30 06:56:13 octo Exp $'; +print STDERR $/, __FILE__, ": $VERSION" if ($::DEBUG); + +return (1); + +sub add +{ + my $data = shift; + + my $nick = $data->{'nick'}; + my $ident = $data->{'ident'}; + my $hour = int ($data->{'hour'}); + my $host = $data->{'host'}; + my $text = $data->{'text'}; + my $type = $data->{'type'}; + + my $words = scalar (@{$data->{'words'}}); + my $chars = length ($text); + if ($type eq 'ACTION') + { + $chars -= (length ($nick) + 3); + } + + $DATA->{'byident'}{$ident}{'lines'}++; + $DATA->{'byident'}{$ident}{'words'} += $words; + $DATA->{'byident'}{$ident}{'chars'} += $chars; + $DATA->{'byident'}{$ident}{'lines_time'}{$hour}++; + $DATA->{'byident'}{$ident}{'words_time'}{$hour} += $words; + $DATA->{'byident'}{$ident}{'chars_time'}{$hour} += $chars; + + $DATA->{'byhour'}[$hour] += $chars; + + if ((length ($text) >= $QUOTE_MIN) + and (length ($text) <= $QUOTE_MAX)) + { + if (!defined ($QUOTE_CACHE->{$nick})) + { + $QUOTE_CACHE->{$nick} = []; + } + push (@{$QUOTE_CACHE->{$nick}}, $text); + } + + if (defined ($QUOTE_CACHE->{$nick})) + { + while (scalar (@{$QUOTE_CACHE->{$nick}}) > $QUOTE_CACHE_SIZE) + { + shift (@{$QUOTE_CACHE->{$nick}}); + } + } + + return (1); +} + +sub output +{ + activetimes (); + ranking (); +} + +# this subroutines doesn't take any arguments either (stupid me). It prints the +# daily usage to the file. +sub activetimes +{ + my $max = 0; # the most lines that were written in one hour.. + my $total = 0; # the total amount of lines we wrote.. + my ($i, $j); # used in for-loops + my $factor = 0; # used to find a bar's height + my $newline = ''; # buffer variable.. + + my @data = @{$DATA->{'byhour'}}; + + my @img_urls = get_config ('vertical_images'); + if (!@img_urls) + { + @img_urls = qw#images/ver0n.png images/ver1n.png images/ver2n.png images/ver3n.png#; + } + + my $fh = get_filehandle () or die; + +# this for loop looks for the most amount of lines in one hour and sets +# $most_lines + for ($i = 0; $i < 24; $i++) + { + if (!defined ($data[$i])) + { + next; + } + + $total += $data[$i]; + + if ($data[$i] > $max) + { + $max = $data[$i]; + } + } + + if (!$total) + { + $total = 1; + $max = 1; + } + + $factor = (($BAR_HEIGHT - 1) / $max); + + my $header = translate ('When do we actually talk here?'); + print $fh "
', sprintf ("%2.1f", $percent),
+ qq#% | \n#;
+ }
+ }
+
+ print $fh "
$_ | \n" } (0 .. 23); + print $fh "
($trans)
\n"; + + print $fh <$name ($total) | \n"; + + if ($row_in_this_table == $SHORTLINES and $col_in_this_table == 5) + { + print $fh "