From: eldy <> Date: Tue, 29 Dec 2009 23:14:13 +0000 (+0000) Subject: New: Add graphgooglechartapi plugin X-Git-Tag: AWSTATS_7_0_BETA2~87 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=db239f7326088799bc22d59af894f930cd93e514;p=thirdparty%2FAWStats.git New: Add graphgooglechartapi plugin --- diff --git a/wwwroot/cgi-bin/awstats.pl b/wwwroot/cgi-bin/awstats.pl index a3d758b0..060ca23e 100644 --- a/wwwroot/cgi-bin/awstats.pl +++ b/wwwroot/cgi-bin/awstats.pl @@ -15002,12 +15002,8 @@ if ( scalar keys %HTMLOutput ) { } # Call to plugins' function ShowPagesAddField - foreach my $pluginname ( - keys %{ $PluginsLoaded{'ShowPagesAddField'} } ) + foreach my $pluginname ( keys %{ $PluginsLoaded{'ShowPagesAddField'} } ) { - - # my $function="ShowPagesAddField_$pluginname('')"; - # eval("$function"); my $function = "ShowPagesAddField_$pluginname"; &$function(''); } @@ -16236,12 +16232,14 @@ if ( scalar keys %HTMLOutput ) { # TODO # Show bars for month - if ( $PluginsLoaded{'ShowGraph'}{'graphapplet'} ) { + my $graphdone=0; + foreach my $pluginname ( keys %{ $PluginsLoaded{'ShowGraph'} } ) + { my @blocklabel = (); for ( my $ix = 1 ; $ix <= 12 ; $ix++ ) { my $monthix = sprintf( "%02s", $ix ); push @blocklabel, - "$MonthNumLib{$monthix}\�$YearRequired"; + "$MonthNumLib{$monthix}\n$YearRequired"; } my @vallabel = ( "$Message[11]", "$Message[10]", @@ -16272,15 +16270,19 @@ if ( scalar keys %HTMLOutput ) { $valdata[ $xx++ ] = $MonthBytes{ $YearRequired . $monthix } || 0; } - ShowGraph_graphapplet( + + my $function = "ShowGraph_$pluginname"; + &$function( "$title", "month", $ShowMonthStats, \@blocklabel, \@vallabel, \@valcolor, \@valmax, \@valtotal, \@valaverage, \@valdata ); + $graphdone=1; } - else { + if (! $graphdone) + { print "\n"; print ""; print "\n"; @@ -16627,7 +16629,9 @@ if ( scalar keys %HTMLOutput ) { } # Show bars for day - if ( $PluginsLoaded{'ShowGraph'}{'graphapplet'} ) { + my $graphdone=0; + foreach my $pluginname ( keys %{ $PluginsLoaded{'ShowGraph'} } ) + { my @blocklabel = (); foreach my $daycursor ( $firstdaytoshowtime .. $lastdaytoshowtime ) @@ -16646,7 +16650,7 @@ if ( scalar keys %HTMLOutput ) { my $weekend = ( DayOfWeek( $day, $month, $year ) =~ /[06]/ ? '!' : '' ); push @blocklabel, - "$day�$MonthNumLib{$month}$weekend$bold"; + "$day\n$MonthNumLib{$month}$weekend$bold"; } my @vallabel = ( "$Message[10]", "$Message[56]", @@ -16685,15 +16689,17 @@ if ( scalar keys %HTMLOutput ) { $valdata[ $xx++ ] = $DayHits{ $year . $month . $day } || 0; $valdata[ $xx++ ] = $DayBytes{ $year . $month . $day } || 0; } - ShowGraph_graphapplet( + my $function = "ShowGraph_$pluginname"; + &$function( "$title", "daysofmonth", $ShowDaysOfMonthStats, \@blocklabel, \@vallabel, \@valcolor, \@valmax, \@valtotal, \@valaverage, \@valdata ); + $graphdone=1; } - else { + if (! $graphdone) { print "
 
\n"; print "\n"; foreach @@ -17055,7 +17061,9 @@ if ( scalar keys %HTMLOutput ) { } # Show bars for days of week - if ( $PluginsLoaded{'ShowGraph'}{'graphapplet'} ) { + my $graphdone=0; + foreach my $pluginname ( keys %{ $PluginsLoaded{'ShowGraph'} } ) + { my @blocklabel = (); for (@DOWIndex) { push @blocklabel, @@ -17098,15 +17106,18 @@ if ( scalar keys %HTMLOutput ) { $avg_dayofweek_h[$_] = int( $avg_dayofweek_h[$_] ); } } - ShowGraph_graphapplet( + my $function = "ShowGraph_$pluginname"; + &$function( "$title", "daysofweek", $ShowDaysOfWeekStats, \@blocklabel, \@vallabel, \@valcolor, \@valmax, \@valtotal, \@valaverage, \@valdata ); + $graphdone=1; } - else { + if (! $graphdone) + { print "
\n"; print "\n"; for (@DOWIndex) { @@ -17302,7 +17313,9 @@ if ( scalar keys %HTMLOutput ) { } # Show bars for hour - if ( $PluginsLoaded{'ShowGraph'}{'graphapplet'} ) { + my $graphdone=0; + foreach my $pluginname ( keys %{ $PluginsLoaded{'ShowGraph'} } ) + { my @blocklabel = ( 0 .. 23 ); my @vallabel = ( "$Message[56]", "$Message[57]", "$Message[75]" ); @@ -17317,15 +17330,18 @@ if ( scalar keys %HTMLOutput ) { $valdata[ $xx++ ] = $_time_h[$_] || 0; $valdata[ $xx++ ] = $_time_k[$_] || 0; } - ShowGraph_graphapplet( + my $function = "ShowGraph_$pluginname"; + &$function( "$title", "hours", $ShowHoursStats, \@blocklabel, \@vallabel, \@valcolor, \@valmax, \@valtotal, \@valaverage, \@valdata ); + $graphdone=1; } - else { + if (! $graphdone) + { print "
\n"; print "\n"; for ( my $ix = 0 ; $ix <= 23 ; $ix++ ) { diff --git a/wwwroot/cgi-bin/plugins/graphgooglechartapi.pm b/wwwroot/cgi-bin/plugins/graphgooglechartapi.pm new file mode 100644 index 00000000..193971c3 --- /dev/null +++ b/wwwroot/cgi-bin/plugins/graphgooglechartapi.pm @@ -0,0 +1,147 @@ +#!/usr/bin/perl +#----------------------------------------------------------------------------- +# GraphGoogleChartApi AWStats plugin +# Allow AWStats to replace bar graphs with a Google Graph image +#----------------------------------------------------------------------------- +# Perl Required Modules: None +#----------------------------------------------------------------------------- +# $Revision$ - $Author$ - $Date$ +# +# Changelog +# +# 1.0 - Initial release +# 1.1 - Changed scaling: making it independent of chart series + + +# <----- +# ENTER HERE THE USE COMMAND FOR ALL REQUIRED PERL MODULES +# -----> +#use strict; +no strict "refs"; + + + +#----------------------------------------------------------------------------- +# PLUGIN VARIABLES +#----------------------------------------------------------------------------- +# <----- +# ENTER HERE THE MINIMUM AWSTATS VERSION REQUIRED BY YOUR PLUGIN +# AND THE NAME OF ALL FUNCTIONS THE PLUGIN MANAGE. +my $PluginNeedAWStatsVersion = "6.0"; +my $PluginHooksFunctions = "ShowGraph"; +# -----> + +# <----- +# IF YOUR PLUGIN NEED GLOBAL VARIABLES, THEY MUST BE DECLARED HERE. +use vars qw/ +$DirClasses +/; +# -----> + + +#----------------------------------------------------------------------------- +# PLUGIN FUNCTION: Init_pluginname +#----------------------------------------------------------------------------- +sub Init_graphgooglechartapi { + my $InitParams = shift; + my $checkversion = &Check_Plugin_Version($PluginNeedAWStatsVersion); + + # <----- + # ENTER HERE CODE TO DO INIT PLUGIN ACTIONS + $DirClasses = $InitParams; + # -----> + + return ($checkversion?$checkversion:"$PluginHooksFunctions"); +} + + +#------------------------------------------------------- +# PLUGIN FUNCTION: ShowGraph_pluginname +# UNIQUE: YES (Only one plugin using this function can be loaded) +# Add the code for call to applet awgraphapplet +# Parameters: $title $type $showmonthstats \@blocklabel,\@vallabel,\@valcolor,\@valmax,\@valtotal +# Input: None +# Output: HTML code for awgraphapplet insertion +# Return: 0 OK, 1 Error +#------------------------------------------------------- +sub ShowGraph_graphgooglechartapi() { + my $title = shift; + my $type = shift; + my $showmonthstats = shift; + my $blocklabel = shift; + my $vallabel = shift; + my $valcolor = shift; + my $valmax = shift; + my $valtotal = shift; + my $valaverage = shift; + my $valdata = shift; + + my $graphwidth = 780; + my $graphheight = 400; + + my $color1 = "4477dd"; + my $color2 = "66f0ff"; + my $maxlabellen = 3; + + if ($type eq 'month') { + $graphwidth = 540; + $graphheight = 160; + $color1 = "ffb055"; + $color2 = "f8e880"; + } + elsif ($type eq 'daysofmonth') { + $graphwidth = 640; + $graphheight = 160; + $color1 = "f8e880"; + $color2 = "4477DD"; + $maxlabellen = 2; + } + elsif ($type eq 'daysofweek') { + $graphwidth = 300; + $graphheight = 160; + } + elsif ($type eq 'hours') { + $graphwidth = 600; + $graphheight = 160; + } + else { + error("Unknown type parameter in ShowGraph_graphgooglechartapi function"); + } + + print " 1) { $s .= ","; } + $val = @$valdata[($j-1)*(scalar @$vallabel)+$serie]; + $s .= "$val"; + if ($val > $max[$serie]) { + $max[$serie] = $val; + } + } + if ($serie < $x) { + $s .= "|"; + } + } + print $s."&chds=0,$max[0],0,$max[1]&chbh=a&chl="; + + # display labels + foreach my $i (1..(scalar @$blocklabel)) { + $b = "".@$blocklabel[$i-1]; + $b = substr($b,0,$maxlabellen); + print $b ."|"; + } + print "&chs=$graphwidth"; print "x$graphheight&chco=$color1,$color2\" alt=\"\" />
\n"; + + return 0; +} + + + +1; # Do not remove this line