]> git.ipfire.org Git - thirdparty/AWStats.git/commitdiff
New: Add graphgooglechartapi plugin
authoreldy <>
Tue, 29 Dec 2009 23:14:13 +0000 (23:14 +0000)
committereldy <>
Tue, 29 Dec 2009 23:14:13 +0000 (23:14 +0000)
wwwroot/cgi-bin/awstats.pl
wwwroot/cgi-bin/plugins/graphgooglechartapi.pm [new file with mode: 0644]

index a3d758b06acfbd07db5f2588962b7927de8dcd95..060ca23e49a1e870032b18ec700473b47a872782 100644 (file)
@@ -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 "<table>\n";
                                print "<tr valign=\"bottom\">";
                                print "<td>&nbsp;</td>\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 "<table>\n";
                                print "<tr valign=\"bottom\">\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 "<table>\n";
                                print "<tr valign=\"bottom\">\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 "<table>\n";
                                print "<tr valign=\"bottom\">\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 (file)
index 0000000..193971c
--- /dev/null
@@ -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 "<img src = \"http://chart.apis.google.com/chart?cht=bvg&chd=t:";
+       $s = "";
+
+       # initialise array for 2 data series
+    @max = (0,0);
+
+       # display only x series
+       $x=1;
+       for ($serie = 0; $serie <= $x; $serie++) {
+               foreach my $j (1..(scalar @$blocklabel)) {
+                       if ($j > 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=\"\" /><br />\n";
+
+       return 0;
+}
+
+
+
+1;     # Do not remove this line