1 rizwank 1.1 #!/usr/bin/perl
2 #-----------------------------------------------------------------------------
3 # UrlAlias AWStats plugin
4 # This plugin allow you to report all URL links with a text title instead of
5 # URL value.
6 # You must create a file called urlalias.cnfigvalue.txt and store it in
7 # plugin directory that contains 2 columns separated by a tab char.
8 # First column is URL value and second column is text title to use instead of.
9 #-----------------------------------------------------------------------------
10 # Perl Required Modules: None
11 #-----------------------------------------------------------------------------
12 # $Revision: 1.17 $ - $Author: eldy $ - $Date: 2004/05/21 21:22:52 $
13
14
15 # <-----
16 # ENTER HERE THE USE COMMAND FOR ALL REQUIRED PERL MODULES
17 #if (!eval ('require "TheModule.pm";')) { return $@?"Error: $@":"Error: Need Perl module TheModule"; }
18 # ----->
19 use strict;no strict "refs";
20
21
22 rizwank 1.1
23 #-----------------------------------------------------------------------------
24 # PLUGIN VARIABLES
25 #-----------------------------------------------------------------------------
26 # <-----
27 # ENTER HERE THE MINIMUM AWSTATS VERSION REQUIRED BY YOUR PLUGIN
28 # AND THE NAME OF ALL FUNCTIONS THE PLUGIN MANAGE.
29 my $PluginNeedAWStatsVersion="5.5";
30 my $PluginHooksFunctions="ShowInfoURL";
31 # ----->
32
33 # <-----
34 # IF YOUR PLUGIN NEED GLOBAL VARIABLES, THEY MUST BE DECLARED HERE.
35 use vars qw/
36 $urlinfoloaded
37 %UrlAlias
38 @UrlMatch
39 /;
40 # ----->
41
42
43 rizwank 1.1
44 #-----------------------------------------------------------------------------
45 # PLUGIN FUNCTION: Init_pluginname
46 #-----------------------------------------------------------------------------
47 sub Init_urlalias {
48 my $InitParams=shift;
49 my $checkversion=&Check_Plugin_Version($PluginNeedAWStatsVersion);
50
51 # <-----
52 # ENTER HERE CODE TO DO INIT PLUGIN ACTIONS
53 debug(" Plugin urlalias: InitParams=$InitParams",1);
54 $urlinfoloaded=0;
55 %UrlAlias=();
56 @UrlMatch=();
57 # ----->
58
59 return ($checkversion?$checkversion:"$PluginHooksFunctions");
60 }
61
62
63
64 rizwank 1.1 #-----------------------------------------------------------------------------
65 # PLUGIN FUNCTION: ShowInfoURL_pluginname
66 # UNIQUE: NO (Several plugins using this function can be loaded)
67 # Function called to add additionnal information for URLs in URLs' report.
68 # This function is called after writing the URL value in the URL cell of the
69 # Top Pages-URL report.
70 # Parameters: URL
71 #-----------------------------------------------------------------------------
72 sub ShowInfoURL_urlalias {
73 my $param="$_[0]";
74 # <-----
75 my $found = 0; # flag for testing for whether a match occurs. unused at present
76 my $filetoload='';
77 my $filetoload2='';
78 if ($param && ! $urlinfoloaded) {
79 # Load urlalias and match files
80 if ($SiteConfig && open(URLALIASFILE,"$DirData/urlalias.$SiteConfig.txt")) { $filetoload2="$DirData/urlalias.$SiteConfig.txt"; }
81 elsif (open(URLALIASFILE,"$DirData/urlalias.txt")) { $filetoload2="$DirData/urlalias.txt"; }
82 else { error("Couldn't open UrlAlias file \"$DirData/urlalias.txt\": $!"); }
83 if ($SiteConfig && open(URLMATCHFILE,"$DirData/urlmatch.$SiteConfig.txt")) { $filetoload="$DirData/urlmatch.$SiteConfig.txt"; }
84 elsif (open(URLMATCHFILE,"$DirData/urlmatch.txt")) { $filetoload="$DirData/urlmatch.txt"; }
85 rizwank 1.1 # Load UrlAlias
86 %UrlAlias = map(/^([^\t]+)\t+([^\t]+)/o,<URLALIASFILE>);
87 # Load UrlMatch
88 my $iter = 0;
89 foreach my $key (<URLMATCHFILE>) {
90 $key =~ /^([^\t]+)\t+([^\t]+)/o;
91 $UrlMatch[$iter][0] = $1;
92 $UrlMatch[$iter][1] = $2;
93 $iter++;
94 }
95 close URLALIASFILE;
96 close URLMATCHFILE;
97 debug(" Plugin urlalias: UrlAlias file loaded: ".(scalar keys %UrlAlias)." entries found.");
98 debug(" Plugin urlalias: UrlMatch file loaded: ".(scalar @UrlMatch)." entries found.");
99 $urlinfoloaded=1;
100 }
101 if ($param) {
102 if ($UrlAlias{$param}) {
103 print "<font style=\"color: $color_link; font-weight: bold\">$UrlAlias{$param}</font><br />";
104 $found=1;
105 }
106 rizwank 1.1 else {
107 foreach my $iter (0..@UrlMatch-1) {
108 my $key = $UrlMatch[$iter][0];
109 if ( $param =~ /$key/ ) {
110 print "<font style=\"color: #$color_link; font-weight: bold\">$UrlMatch[$iter][1]</font><br />";
111 $found = 1;
112 # $UrlAlias{$param} = $UrlMatch[$iter][1];
113 # if ($SiteConfig && open(URLALIASFILE,">> $DirData/urlalias.$SiteConfig.txt")) {
114 # $filetoload="$DirData/urlalias.$SiteConfig.txt";
115 # }
116 # elsif (open(URLALIASFILE,">> $DirData/urlalias.txt")) {
117 # $filetoload="$DirData/urlalias.txt";
118 # }
119 # else {
120 # error("Couldn't open UrlAlias file \"$DirData/urlalias.txt\": $!");
121 # }
122 # print URLALIASFILE "$param\t$UrlAlias{$param}";
123 # close URLALIASFILE;
124 last;
125 }
126 }
127 rizwank 1.1 }
128 if (!$found) { # does nothing right now
129 print "";
130 }
131 }
132 else { print ""; } # Url info title
133 return 1;
134 # ----->
135 }
136
137
138 1; # Do not remove this line
|