home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / tsw / TSW_3.4.0.exe / Apache2 / cgi-bin / tooltips.pm < prev    next >
Encoding:
Text File  |  2004-05-20  |  8.2 KB  |  207 lines

  1. #!/usr/bin/perl
  2. #-----------------------------------------------------------------------------
  3. # Tooltips AWStats plugin
  4. # This plugin allow you to add some toolpus in AWStats HTML report pages.
  5. # The tooltip are in same language than the report (they are stored in the
  6. # awstats-tt-codelanguage.txt files in lang directory).
  7. #-----------------------------------------------------------------------------
  8. # Perl Required Modules: None
  9. #-----------------------------------------------------------------------------
  10. # $Revision: 1.4 $ - $Author: joker $ - $Date: 2004/05/20 20:38:42 $
  11.  
  12.  
  13. # <-----
  14. # ENTER HERE THE USE COMMAND FOR ALL REQUIRED PERL MODULES.
  15. # ----->
  16. use strict;no strict "refs";
  17.  
  18.  
  19.  
  20. #-----------------------------------------------------------------------------
  21. # PLUGIN VARIABLES
  22. #-----------------------------------------------------------------------------
  23. # <-----
  24. # ENTER HERE THE MINIMUM AWSTATS VERSION REQUIRED BY YOUR PLUGIN
  25. # AND THE NAME OF ALL FUNCTIONS THE PLUGIN MANAGE.
  26. my $PluginNeedAWStatsVersion="6.1";
  27. my $PluginHooksFunctions="AddHTMLStyles AddHTMLBodyHeader";
  28. # ----->
  29.  
  30. # <-----
  31. # IF YOUR PLUGIN NEED GLOBAL VARIABLES, THEY MUST BE DECLARED HERE.
  32. use vars qw/
  33. $TOOLTIPWIDTH
  34. /;
  35. # ----->
  36.  
  37.  
  38.  
  39. #-----------------------------------------------------------------------------
  40. # PLUGIN FUNCTION: Init_pluginname
  41. #-----------------------------------------------------------------------------
  42. sub Init_tooltips {
  43.     my $InitParams=shift;
  44.     my $checkversion=&Check_Plugin_Version($PluginNeedAWStatsVersion);
  45.  
  46.     # <-----
  47.     # ENTER HERE CODE TO DO INIT PLUGIN ACTIONS
  48.     debug(" InitParams=$InitParams",1);
  49.     $TOOLTIPON=1;
  50.     $TOOLTIPWIDTH=380;                    # Width of tooltips
  51.     # ----->
  52.  
  53.     return ($checkversion?$checkversion:"$PluginHooksFunctions");
  54. }
  55.  
  56.  
  57.  
  58. #-----------------------------------------------------------------------------
  59. # PLUGIN FUNCTION: AddHTMLStyles_pluginname
  60. # UNIQUE: NO (Several plugins using this function can be loaded)
  61. # Function called to Add HTML styles at beginning of BODY section.
  62. #-----------------------------------------------------------------------------
  63. sub AddHTMLStyles_tooltips {
  64.     # <-----
  65.     print "div { font: 12px 'Arial','Verdana','Helvetica', sans-serif; text-align: justify; }\n";
  66.     print ".CTooltip { position:absolute; top: 0px; left: 0px; z-index: 2; width: ${TOOLTIPWIDTH}px; visibility:hidden; font: 8pt 'MS Comic Sans','Arial',sans-serif; background-color: #FFFFE6; padding: 8px; border: 1px solid black; }\n";
  67.     return 1;
  68.     # ----->
  69. }
  70.  
  71.  
  72. #-----------------------------------------------------------------------------
  73. # PLUGIN FUNTION: AddHTMLBodyHeader_pluginname
  74. # UNIQUE: NO (Several plugins using this function can be loaded)
  75. # Function called to Add HTML code at beginning of BODY section.
  76. #-----------------------------------------------------------------------------
  77. sub AddHTMLBodyHeader_tooltips {
  78.     # <-----
  79.     if ($FrameName ne 'mainleft') {
  80.  
  81.         # GET AND WRITE THE TOOLTIP STRINGS
  82.         #---------------------------------------------------------------------
  83.         &_ReadAndOutputTooltipFile($Lang);
  84.  
  85.         # WRITE TOOLTIPS JAVASCRIPT CODE
  86.         #---------------------------------------------------------------------
  87.         # Position .style.pixelLeft/.pixelHeight/.pixelWidth/.pixelTop    IE OK        Opera OK
  88.         #          .style.left/.height/.width/.top                        IE456 OK                Netscape67 OK    XHTML OK
  89.         # document.getElementById                                        IE456 OK    Opera OK    Netscape67 OK    XHTML OK
  90.         # document.body.offsetWidth|document.body.style.pixelWidth        IE OK        Opera OK    Netscape OK        XHTML KO    Visible width of container
  91.         # document.body.scrollTop                                       IE OK        Opera OK    Netscape OK        XHTML KO    Visible width of container
  92.         # document.documentElement.offsetWidth                                                                    XHTML OK    Visible width of container
  93.         # document.body.scrollTop                                       IE OK        Opera OK    Netscape OK        XHTML KO    Visible width of container
  94.         # tooltipOBJ.offsetWidth|tooltipOBJ.style.pixelWidth            IE OK        Opera OK    Netscape OK                    Width of an object
  95.         # event.clientXY                                                IE OK        Opera OK    Netscape KO        XHTML KO    Return position of mouse
  96.  
  97.         my $docwidth="document.body.offsetWidth";
  98.         my $doctop="document.body.scrollTop";
  99.         if ($BuildReportFormat eq 'xhtml' || $BuildReportFormat eq 'xml') {
  100.             $docwidth="document.documentElement.offsetWidth";
  101.             $doctop="document.documentElement.scrollTop";
  102.         }
  103.  
  104.         print <<EOF;
  105.  
  106. <script language="javascript" type="text/javascript">
  107. function ShowTip(fArg)
  108. {
  109.     var tooltipOBJ = (document.getElementById) ? document.getElementById('tt' + fArg) : eval("document.all['tt" + fArg + "']");
  110.     if (tooltipOBJ != null) {
  111.         var tooltipLft = ($docwidth?$docwidth:document.body.style.pixelWidth) - (tooltipOBJ.offsetWidth?tooltipOBJ.offsetWidth:(tooltipOBJ.style.pixelWidth?tooltipOBJ.style.pixelWidth:$TOOLTIPWIDTH)) - 30;
  112.         var tooltipTop = 10;
  113.         if (navigator.appName == 'Netscape') {
  114.             tooltipTop = ($doctop>=0?$doctop+10:event.clientY+10);
  115.              tooltipOBJ.style.top = tooltipTop+"px";
  116.             tooltipOBJ.style.left = tooltipLft+"px";
  117.         }
  118.         else {
  119.             tooltipTop = ($doctop>=0?$doctop+10:event.clientY+10);
  120.             tooltipTop = (document.body.scrollTop>=0?document.body.scrollTop+10:event.clientY+10);
  121. EOF
  122.         # Seul IE en HTML a besoin de code supplΘmentaire. IE en xhtml est OK
  123.         if ($BuildReportFormat ne 'xhtml' && $BuildReportFormat ne 'xml') {
  124. print <<EOF;
  125.             if ((event.clientX > tooltipLft) && (event.clientY < (tooltipOBJ.scrollHeight?tooltipOBJ.scrollHeight:tooltipOBJ.style.pixelHeight) + 10)) {
  126.                 tooltipTop = ($doctop?$doctop:document.body.offsetTop) + event.clientY + 20;
  127.             }
  128. EOF
  129.         }
  130. print <<EOF;
  131.             tooltipOBJ.style.left = tooltipLft;
  132.             tooltipOBJ.style.top = tooltipTop;
  133.         }
  134.         tooltipOBJ.style.visibility = "visible";
  135.     }
  136. }
  137. function HideTip(fArg)
  138. {
  139.     var tooltipOBJ = (document.getElementById) ? document.getElementById('tt' + fArg) : eval("document.all['tt" + fArg + "']");
  140.     if (tooltipOBJ != null) {
  141.         tooltipOBJ.style.visibility = "hidden";
  142.     }
  143. }
  144. </script>
  145.  
  146. EOF
  147.  
  148.     }
  149.     return 1;
  150.     # ----->
  151. }
  152.  
  153.  
  154. #------------------------------------------------------------------------------
  155. # Function:     Get the tooltip texts for a specified language and write it
  156. # Parameters:    LanguageId
  157. # Input:        $DirLang $DIR
  158. # Output:        Full tooltips text
  159. # Return:        None
  160. #------------------------------------------------------------------------------
  161. sub _ReadAndOutputTooltipFile {
  162.     # Check lang files in common possible directories :
  163.     # Windows :                                   "${DIR}lang" (lang in same dir than awstats.pl)
  164.     # Debian package :                            "/usr/share/awstats/lang"
  165.     # Other possible directories :                "./lang"
  166.     my @PossibleLangDir=("$DirLang","${DIR}lang","/usr/share/awstats/lang","./lang");
  167.  
  168.     my $FileLang='';
  169.     my $logtype=lc($LogType ne 'S'?$LogType:'W');
  170.     foreach my $dir (@PossibleLangDir) {
  171.         my $searchdir=$dir;
  172.         if ($searchdir && (!($searchdir =~ /\/$/)) && (!($searchdir =~ /\\$/)) ) { $searchdir .= "/"; }
  173.         if (open(LANG,"${searchdir}tooltips_${logtype}/awstats-tt-$_[0].txt")) { $FileLang="${searchdir}tooltips_${logtype}/awstats-tt-$_[0].txt"; last; }
  174.     }
  175.     # If file not found, we try english
  176.     if (! $FileLang) {
  177.         foreach my $dir (@PossibleLangDir) {
  178.             my $searchdir=$dir;
  179.             if ($searchdir && (!($searchdir =~ /\/$/)) && (!($searchdir =~ /\\$/)) ) { $searchdir .= "/"; }
  180.             if (open(LANG,"${searchdir}tooltips_${logtype}/awstats-tt-en.txt")) { $FileLang="${searchdir}tooltips_${logtype}/awstats-tt-en.txt"; last; }
  181.         }
  182.     }
  183.     if ($Debug) { debug("Call to Read_Language_Tooltip [FileLang=\"$FileLang\"]"); }
  184.     if ($FileLang) {
  185.         my $aws_PROG=ucfirst($PROG);
  186.         my $aws_VisitTimeout = $VISITTIMEOUT/10000*60;
  187.         my $aws_NbOfRobots = scalar keys %RobotsHashIDLib;
  188.         my $aws_NbOfWorms = scalar @WormsSearchIDOrder;
  189.         my $aws_NbOfSearchEngines = scalar keys %SearchEnginesHashLib;
  190.         while (<LANG>) {
  191.             if ($_ =~ /\<!--/) { next; }    # Remove comment
  192.             # Search for replaceable parameters
  193.             s/#PROG#/$aws_PROG/;
  194.             s/#MaxNbOfRefererShown#/$MaxNbOf{'RefererShown'}/;
  195.             s/#VisitTimeOut#/$aws_VisitTimeout/;
  196.             s/#RobotArray#/$aws_NbOfRobots/;
  197.             s/#WormsArray#/$aws_NbOfWorms/;
  198.             s/#SearchEnginesArray#/$aws_NbOfSearchEngines/;
  199.             print "$_";
  200.         }
  201.     }
  202.     close(LANG);
  203. }
  204.  
  205.  
  206. 1;    # Do not remove this line
  207.