Hits.pm

filter: Statementstmt 25.8% 39 / 151 Branchbran 0.0% 0 / 70 Conditioncond 0.0% 0 / 19 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 52.3% 11 / 21 Podpod 100% 10 / 10 totaltotal 21.5% 60 / 279 CC 59 SCAR 47.0
CC
59
Cov
16%
HitPhotos
240.0
HitAlbums
182.0
HitPages
132.0
CRAP 110.1
« News.pm ↑ Summary Groups.pm »
1 package Labyrinth::Plugin::Hits;
2  
3 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 4 our $VERSION = '5.19';
7  
8 =head1 NAME
9  
10 Labyrinth::Plugin::Hits - Handles the hit and update stats for page impressions
11  
12 =head1 DESCRIPTION
13  
14 Contains all the page hit handling functionality for the Labyrinth
15 framework.
16  
17 =cut
18  
19 #----------------------------------------------------------------------------
20 # Libraries
21  
22 4 ▶use base qw(Labyrinth::Plugin::Base);
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 4 ▶use Time::Local;
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 4 ▶use Labyrinth::Audit;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 4 ▶use Labyrinth::DBUtils;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 4 ▶use Labyrinth::DTUtils;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 4 ▶use Labyrinth::MLUtils;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 4 ▶use Labyrinth::Support;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 4 ▶use Labyrinth::Variables;
Subroutine BEGIN: called CC=1 SCAR=0.0
32  
33 4 ▶use Labyrinth::Plugin::Content;
Subroutine BEGIN: called CC=1 SCAR=0.0
34  
35 #----------------------------------------------------------------------------
36 # Variables
37  
38 # type: 0 = optional, 1 = mandatory
39 # html: 0 = none, 1 = text, 2 = textarea
40  
41 4 my %fields = (
42 title => { type => 1, html => 1 },
43 tagline => { type => 0, html => 1 },
44 query => { type => 0, html => 2 },
45 );
46  
47 4 my $WEEKS1 = 60 * 60 * 24 * 7;
48 4 my $WEEKS4 = $WEEKS1 * 4;
49 4 my $WEEKS6 = $WEEKS1 * 6;
50  
51 #----------------------------------------------------------------------------
52 # Public Interface Functions
53  
54 =head1 PUBLIC INTERFACE METHODS
55  
56 =over 4
57  
58 =item GetUpdate
59  
60 Provides the dates for the last update to the site and the requested page.
61  
62 =item SetHits
63  
64 Records the hit for the current page and photo (if applicable).
65  
66 =item HitPages
67  
68 List of hit stats for site pages.
69  
70 =item HitAlbums
71  
72 List of hit stats for galley albums.
73  
74 =item HitPhotos
75  
76 List of hit stats for galley photos.
77  
78 =item HitSelects
79  
80 Compile contents of the drop downs on hit pages.
81  
82 =back
83  
84 =cut
85  
86 0 ▶sub GetUpdate {
Subroutine GetUpdate: not called CC=6 SCAR=37.4
Pod documented
87 0 ▶ my $section = $tvars{'section'} || 'unstated';
Condition0%0/2
$Labyrinth::Plugin::Hits::tvars{'section'} || 'unstated'
l!l
00
MC/DC0%0/1
$Labyrinth::Plugin::Hits::tvars{'section'} || 'unstated'
$Labyrinth::Plugin::Hits::tvars{'section'}
Truth table0%0/2
A
A= $Labyrinth::Plugin::Hits::tvars{'section'}
Aresult
11
00
88 0 ▶ my $pageid = $cgiparams{pid} || $cgiparams{pageid} || 0;
Condition0%0/5
$Labyrinth::Plugin::Hits::cgiparams{'pid'} || $Labyrinth::Plugin::Hits::cgiparams{'pageid'} || 0
l!l
00
$Labyrinth::Plugin::Hits::cgiparams{"pid"} or $Labyrinth::Plugin::Hits::cgiparams{"pageid"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$Labyrinth::Plugin::Hits::cgiparams{'pid'} || $Labyrinth::Plugin::Hits::cgiparams{'pageid'} || 0
$Labyrinth::Plugin::Hits::cgiparams{"pid"} $Labyrinth::Plugin::Hits::cgiparams{"pageid"}
Truth table0%0/3
A or B
A= $Labyrinth::Plugin::Hits::cgiparams{"pid"}B= $Labyrinth::Plugin::Hits::cgiparams{"pageid"}
ABresult
1X1
011
000
89  
90 0 my %updates = (
91 siteupdate => ['site',0],
92 pageupdate => [$section,$pageid],
93 );
94  
95 0 foreach my $update (keys %updates) {
96 0 my @rs = $dbi->GetQuery('array','PageTimeStamp',@{$updates{$update}});
97 0 ▶ next unless(@rs);
Branch: 1 branch
BranchTrueFalseTotal
unless @rs 0 0 0
98  
99 # get expanded timestamp [2004-05-07 13:24:56]
100 0 $rs[0]->[0] =~ /(\d\d\d\d)[^\d]?(\d\d)[^\d]?(\d\d)/;
101 0 $tvars{$update} = formatDate(5,timelocal(0,0,0,int($3),$2-1,$1));
102 }
103 }
104  
105 0 ▶sub SetHits {
Subroutine SetHits: not called CC=9 SCAR=45.0
Pod documented
106 0 my $counter = 0;
107 0 ▶ my $section = $cgiparams{act} || 'unstated';
Condition0%0/2
$Labyrinth::Plugin::Hits::cgiparams{'act'} || 'unstated'
l!l
00
MC/DC0%0/1
$Labyrinth::Plugin::Hits::cgiparams{'act'} || 'unstated'
$Labyrinth::Plugin::Hits::cgiparams{'act'}
Truth table0%0/2
A
A= $Labyrinth::Plugin::Hits::cgiparams{'act'}
Aresult
11
00
108 0 ▶ my $pageid = $cgiparams{pid} || $cgiparams{pageid} || 0;
Condition0%0/5
$Labyrinth::Plugin::Hits::cgiparams{'pid'} || $Labyrinth::Plugin::Hits::cgiparams{'pageid'} || 0
l!l
00
$Labyrinth::Plugin::Hits::cgiparams{"pid"} or $Labyrinth::Plugin::Hits::cgiparams{"pageid"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$Labyrinth::Plugin::Hits::cgiparams{'pid'} || $Labyrinth::Plugin::Hits::cgiparams{'pageid'} || 0
$Labyrinth::Plugin::Hits::cgiparams{"pid"} $Labyrinth::Plugin::Hits::cgiparams{"pageid"}
Truth table0%0/3
A or B
A= $Labyrinth::Plugin::Hits::cgiparams{"pid"}B= $Labyrinth::Plugin::Hits::cgiparams{"pageid"}
ABresult
1X1
011
000
109 0 ▶ my $photoid = $cgiparams{iid} || $cgiparams{photoid} || 0;
Condition0%0/5
$Labyrinth::Plugin::Hits::cgiparams{'iid'} || $Labyrinth::Plugin::Hits::cgiparams{'photoid'} || 0
l!l
00
$Labyrinth::Plugin::Hits::cgiparams{"iid"} or $Labyrinth::Plugin::Hits::cgiparams{"photoid"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$Labyrinth::Plugin::Hits::cgiparams{'iid'} || $Labyrinth::Plugin::Hits::cgiparams{'photoid'} || 0
$Labyrinth::Plugin::Hits::cgiparams{"iid"} $Labyrinth::Plugin::Hits::cgiparams{"photoid"}
Truth table0%0/3
A or B
A= $Labyrinth::Plugin::Hits::cgiparams{"iid"}B= $Labyrinth::Plugin::Hits::cgiparams{"photoid"}
ABresult
1X1
011
000
110 0 my @keys = sort grep {/(name|id|letter|data|volume|month|year)/} keys %cgiparams;
111 0 ▶ my $query = join( '&', map {defined $cgiparams{$_} ? "$_=$cgiparams{$_}" : ''} @keys) if(@keys);
Branch: 2 branches
BranchTrueFalseTotal
if @keys 0 0 0
defined $Labyrinth::Plugin::Hits::cgiparams{$_} ? : 0 0 0
112 0 my $dt = formatDate(0);
113  
114 0 $dbi->DoQuery('AddAHit',1,$section,$pageid,$photoid,$query,$dt);
115 0 my @rs = $dbi->GetQuery('array','GetAHit',$section,$query);
116 0 ▶ $tvars{hits} = @rs ? $rs[0]->[0] : 0;
Branch: 1 branch
BranchTrueFalseTotal
@rs ? : 0 0 0
117 }
118  
119 0 ▶sub HitPages {
Subroutine HitPages: not called CC=11 SCAR=48.8
Pod documented
120 0 my $dt = time() - $WEEKS4;
121  
122 0 my @pagesall = $dbi->GetQuery('hash','PageHitsAllTime');
123 0 for my $row (@pagesall) {
124 0 for(keys %fields) {
125 0 ▶ if($fields{$_}->{html} == 1) { $row->{$_} = CleanHTML($row->{$_}); }
Branch: 2 branches
BranchTrueFalseTotal
if ($fields{$_}{'html'} == 1) { } 0 0 0
elsif ($fields{$_}{'html'} == 2) { } 0 0 0
126 0 elsif($fields{$_}->{html} == 2) { $row->{$_} = CleanTags($row->{$_}); }
127 }
128 }
129 0 ▶ $tvars{pagesall} = \@pagesall if(@pagesall);
Branch: 1 branch
BranchTrueFalseTotal
if @pagesall 0 0 0
130  
131 0 my @pagesmon = $dbi->GetQuery('hash','PageHitsLastMonth',$dt);
132 0 for my $row (@pagesmon) {
133 0 for(keys %fields) {
134 0 ▶ if($fields{$_}->{html} == 1) { $row->{$_} = CleanHTML($row->{$_}); }
Branch: 2 branches
BranchTrueFalseTotal
if ($fields{$_}{'html'} == 1) { } 0 0 0
elsif ($fields{$_}{'html'} == 2) { } 0 0 0
135 0 elsif($fields{$_}->{html} == 2) { $row->{$_} = CleanTags($row->{$_}); }
136 }
137 }
138  
139 0 $tvars{ddmonths} = MonthSelect($tvars{data}->{month},1);
140 0 $tvars{ddyears} = YearSelect($tvars{data}->{year},2,1);
141 0 $tvars{today} = formatDate(7);
142 0 ▶ $tvars{pagesmon} = \@pagesmon if(@pagesmon);
Branch: 1 branch
BranchTrueFalseTotal
if @pagesmon 0 0 0
143 }
144  
145 0 ▶sub HitAlbums {
Subroutine HitAlbums: not called CC=13 SCAR=52.0
Pod documented
146 0 my $dt = time() - $WEEKS4;
147  
148 0 my @albumsall = $dbi->GetQuery('hash','AlbumHitsAllTime');
149 0 for my $row (@albumsall) {
150 0 $row->{month} = isMonth($_->{month});
151 0 ▶ $row->{title} =~ s/'/\'/g if $row->{title};
Branch: 1 branch
BranchTrueFalseTotal
if $row->{"title"} 0 0 0
152 0 for(keys %fields) {
153 0 ▶ if($fields{$_}->{html} == 1) { $row->{$_} = CleanHTML($row->{$_}); }
Branch: 2 branches
BranchTrueFalseTotal
if ($fields{$_}{'html'} == 1) { } 0 0 0
elsif ($fields{$_}{'html'} == 2) { } 0 0 0
154 0 elsif($fields{$_}->{html} == 2) { $row->{$_} = CleanTags($row->{$_}); }
155 }
156 }
157 0 ▶ $tvars{albumsall} = \@albumsall if(@albumsall);
Branch: 1 branch
BranchTrueFalseTotal
if @albumsall 0 0 0
158  
159 0 my @albumsmon = $dbi->GetQuery('hash','AlbumHitsLastMonth',$dt);
160 0 for my $row (@albumsmon) {
161 0 $row->{month} = isMonth($_->{month});
162 0 ▶ $row->{title} =~ s/'/\'/g if $row->{title};
Branch: 1 branch
BranchTrueFalseTotal
if $row->{"title"} 0 0 0
163 0 for(keys %fields) {
164 0 ▶ if($fields{$_}->{html} == 1) { $row->{$_} = CleanHTML($row->{$_}); }
Branch: 2 branches
BranchTrueFalseTotal
if ($fields{$_}{'html'} == 1) { } 0 0 0
elsif ($fields{$_}{'html'} == 2) { } 0 0 0
165 0 elsif($fields{$_}->{html} == 2) { $row->{$_} = CleanTags($row->{$_}); }
166 }
167 }
168  
169 0 $tvars{ddmonths} = MonthSelect($tvars{data}->{month},1);
170 0 $tvars{ddyears} = YearSelect($tvars{data}->{year},2,1);
171 0 $tvars{today} = formatDate(7);
172 0 ▶ $tvars{albumsmon} = \@albumsmon if(@albumsmon);
Branch: 1 branch
BranchTrueFalseTotal
if @albumsmon 0 0 0
173 }
174  
175 0 ▶sub HitPhotos {
Subroutine HitPhotos: not called CC=15 SCAR=54.8
Pod documented
176 0 my $dt = time() - $WEEKS4;
177  
178 0 my @photosall = $dbi->GetQuery('hash','PhotoHitsAllTime');
179 0 for my $row (@photosall) {
180 0 $row->{month} = isMonth($row->{month});
181 0 ▶ $row->{tagline} =~ s/'/\'/g if $row->{tagline};
Branch: 1 branch
BranchTrueFalseTotal
if $row->{"tagline"} 0 0 0
182 0 ▶ $row->{title} =~ s/'/\'/g if $row->{title};
Branch: 1 branch
BranchTrueFalseTotal
if $row->{"title"} 0 0 0
183 0 for(keys %fields) {
184 0 ▶ if($fields{$_}->{html} == 1) { $row->{$_} = CleanHTML($row->{$_}); }
Branch: 2 branches
BranchTrueFalseTotal
if ($fields{$_}{'html'} == 1) { } 0 0 0
elsif ($fields{$_}{'html'} == 2) { } 0 0 0
185 0 elsif($fields{$_}->{html} == 2) { $row->{$_} = CleanTags($row->{$_}); }
186 }
187 }
188 0 ▶ $tvars{photosall} = \@photosall if(@photosall);
Branch: 1 branch
BranchTrueFalseTotal
if @photosall 0 0 0
189  
190 0 my @photosmon = $dbi->GetQuery('hash','PhotoHitsLastMonth',$dt);
191 0 for my $row (@photosmon) {
192 0 $row->{month} = isMonth($row->{month});
193 0 ▶ $row->{tagline} =~ s/'/\'/g if $row->{tagline};
Branch: 1 branch
BranchTrueFalseTotal
if $row->{"tagline"} 0 0 0
194 0 ▶ $row->{title} =~ s/'/\'/g if $row->{title};
Branch: 1 branch
BranchTrueFalseTotal
if $row->{"title"} 0 0 0
195 0 for(keys %fields) {
196 0 ▶ if($fields{$_}->{html} == 1) { $row->{$_} = CleanHTML($row->{$_}); }
Branch: 2 branches
BranchTrueFalseTotal
if ($fields{$_}{'html'} == 1) { } 0 0 0
elsif ($fields{$_}{'html'} == 2) { } 0 0 0
197 0 elsif($fields{$_}->{html} == 2) { $row->{$_} = CleanTags($row->{$_}); }
198 }
199 }
200 0 ▶ $tvars{photosmon} = \@photosmon if(@photosmon);
Branch: 1 branch
BranchTrueFalseTotal
if @photosmon 0 0 0
201 }
202  
203 0 ▶sub HitSelects {
Subroutine HitSelects: not called CC=1 SCAR=6.9
Pod documented
204 0 $tvars{ddmonths} = MonthSelect($tvars{data}->{month},1);
205 0 $tvars{ddyears} = YearSelect($tvars{data}->{year},2,1);
206 0 $tvars{today} = formatDate(7);
207 }
208  
209 #----------------------------------------------------------------------------
210 # Administration Interface Functions
211  
212 =head1 PUBLIC INTERFACE METHODS
213  
214 =over 4
215  
216 =item AdminUpdates
217  
218 List the last site page updates, via the 'AdminUpdates' phrasebook query.
219  
220 =item SetUpdates
221  
222 Store page and site update from current timestamp. Only called internally.
223  
224 =item AdminHits
225  
226 Shorthand method to list all the hit counters for admin use.
227  
228 =item Reset
229  
230 Original method to reset hit counters, such that individual counters older than
231 a given date, are summed and stored in one counter entry.
232  
233 This is being deprecated in favour of a new script, which will be incorporated
234 here in the future.
235  
236 =back
237  
238 =cut
239  
240 0 ▶sub AdminUpdates {
Subroutine AdminUpdates: not called CC=4 SCAR=30.0
Pod documented
241 0 ▶ return unless AccessUser(EDITOR);
Branch: 1 branch
BranchTrueFalseTotal
unless AccessUser(2) 0 0 0
242 0 my @rs = $dbi->GetQuery('hash','AdminUpdates');
243  
244 0 foreach my $rec (@rs) {
245 0 $rec->{pagets} =~ /^(\d\d\d\d)(\d\d)(\d\d)/;
246 0 LogDebug("pagets=".$rec->{pagets});
247 0 $rec->{updated} = formatDate(5,timelocal(0,0,0,int($3),$2-1,$1));
248 }
249  
250 0 ▶ $tvars{records} = \@rs if(@rs);
Branch: 1 branch
BranchTrueFalseTotal
if @rs 0 0 0
251 }
252  
253 0 ▶sub SetUpdates {
Subroutine SetUpdates: not called CC=4 SCAR=30.0
Pod documented
254 0 my $self = shift;
255 0 my $area = shift;
256 0 my $now = formatDate(0);
257  
258 0 ▶ while(@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
259 0 my $pageid = shift @_;
260 # LogDebug("SetUpdates: area=$area, pageid=$pageid");
261  
262 # check whether old or new
263 0 my @rs = $dbi->GetQuery('hash','GetUpdate',$area,$pageid);
264  
265 # store page update
266 0 ▶ my $key = (@rs ? 'SetUpdate' : 'AddUpdate');
Branch: 1 branch
BranchTrueFalseTotal
@rs ? : 0 0 0
267 0 $dbi->DoQuery($key,$now,$area,$pageid);
268 }
269  
270 # store index updates
271 0 ▶ $dbi->DoQuery('SetUpdate',$now,'site',0) if($area ne 'site');
Branch: 1 branch
BranchTrueFalseTotal
if $area ne "site" 0 0 0
272 }
273  
274 0 ▶sub AdminHits {
Subroutine AdminHits: not called CC=2 SCAR=17.9
Pod documented
275 0 ▶ return unless AccessUser(EDITOR);
Branch: 1 branch
BranchTrueFalseTotal
unless AccessUser(2) 0 0 0
276 0 HitPages();
277 0 HitAlbums();
278 0 HitPhotos();
279 0 HitSelects();
280 }
281  
282 0 ▶sub Reset {
Subroutine Reset: not called CC=3 SCAR=24.8
Pod documented
283 0 ▶ return unless AccessUser(ADMIN);
Branch: 1 branch
BranchTrueFalseTotal
unless AccessUser(4) 0 0 0
284 0 my $dt = formatDate(0) - ($WEEKS6);
285 0 my @rows = $dbi->GetQuery('hash','SumHits',$dt);
286 0 for my $row (@rows) {
287 0 $dbi->DoQuery('DelHits',$row->{area},$row->{query},$dt);
288 0 $dbi->DoQuery('AddAHit',$row->{counter},$row->{area},$row->{pageid},$row->{photoid},$row->{query},0);
289 }
290 }
291  
292 4 1;
293  
294 __END__
« News.pm ↑ Summary Groups.pm »