blib/lib/Labyrinth/Plugin/Articles/Diary.pm

filter: Statementstmt 25.1% 66 / 262 Branchbran 3.4% 4 / 116 Conditioncond 0.0% 0 / 27 MC/DCmcdc 0.0% 0 / 13 Subroutinesub 41.4% 17 / 41 Podpod 100% 22 / 22 totaltotal 22.6% 109 / 481 CC 78 SCAR 43.4
CC
78
Cov
17%
Comment
210.0
ListComment
210.0
SaveComment
110.0
CRAP 76.6
↑ Summary
1 package Labyrinth::Plugin::Articles::Diary;
2  
3 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 5 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 5 $VERSION = '1.06';
8  
9 =head1 NAME
10  
11 Labyrinth::Plugin::Articles::Diary - Diary plugin for Labyrinth framework
12  
13 =head1 DESCRIPTION
14  
15 Contains all the diary handling functionality for Labyrinth.
16  
17 =cut
18  
19 # -------------------------------------
20 # Library Modules
21  
22 5 ▶use base qw(Labyrinth::Plugin::Articles);
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 5 ▶use Clone qw(clone);
Subroutine BEGIN: called CC=1 SCAR=0.0
25 5 ▶use Time::Local;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 #use Data::Dumper;
27  
28 5 ▶use Labyrinth::Audit;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 5 ▶use Labyrinth::DBUtils;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 5 ▶use Labyrinth::DTUtils;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 5 ▶use Labyrinth::Globals;
Subroutine BEGIN: called CC=1 SCAR=0.0
32 5 ▶use Labyrinth::IPAddr;
Subroutine BEGIN: called CC=1 SCAR=0.0
33 5 ▶use Labyrinth::Metadata;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 5 ▶use Labyrinth::MLUtils;
Subroutine BEGIN: called CC=1 SCAR=0.0
35 5 ▶use Labyrinth::Session;
Subroutine BEGIN: called CC=1 SCAR=0.0
36 5 ▶use Labyrinth::Support;
Subroutine BEGIN: called CC=1 SCAR=0.0
37 5 ▶use Labyrinth::Variables;
Subroutine BEGIN: called CC=1 SCAR=0.0
38 5 ▶use Labyrinth::Writer;
Subroutine BEGIN: called CC=1 SCAR=0.0
39  
40 # -------------------------------------
41 # Variables
42  
43 # type: 0 = optional, 1 = mandatory
44 # html: 0 = none, 1 = text, 2 = textarea
45  
46 5 my %fields = (
47 articleid => { type => 0, html => 0 },
48 quickname => { type => 1, html => 0 },
49 title => { type => 1, html => 1 },
50 );
51  
52 5 my (@mandatory,@allfields);
53 5 for(keys %fields) {
54 15 ▶ push @mandatory, $_ if($fields{$_}->{type});
Branch: 1 branch
BranchTrueFalseTotal
if $fields{$_}{"type"} 10 5 15
55 15 push @allfields, $_;
56 }
57  
58 5 my $LEVEL = ADMIN;
59 5 my $SECTIONID = 6;
60  
61 5 my %cfields = (
62 articleid => { type => 0, html => 0 },
63 commentid => { type => 0, html => 0 },
64 subject => { type => 0, html => 1 },
65 body => { type => 1, html => 3 },
66 author => { type => 1, html => 1 },
67 href => { type => 0, html => 1 },
68 publish => { type => 0, html => 0 },
69 );
70  
71 5 my (@cmandatory,@callfields);
72 5 for(keys %cfields) {
73 35 ▶ push @cmandatory, $_ if($cfields{$_}->{type});
Branch: 1 branch
BranchTrueFalseTotal
if $cfields{$_}{"type"} 10 25 35
74 35 push @callfields, $_;
75 }
76  
77 5 my ($BLOCK,$ALLOW) = (1,2);
78  
79 # -------------------------------------
80 # Public Methods
81  
82 =head1 PUBLIC INTERFACE METHODS
83  
84 =over 4
85  
86 =item Archive
87  
88 Retrieves a list of archived diary entries
89  
90 =item Page
91  
92 Retrieves an set of diary entries, for a given page. Default to first page.
93  
94 =item List
95  
96 Retrieves an initial list of diary entries. Primarily used to prepare a front
97 page.
98  
99 =item Meta
100  
101 Retrieves a list of diary entries based on given meta tags.
102  
103 =item Search
104  
105 Retrieves a list of diary entries based on a given search string.
106  
107 =item Cloud
108  
109 Provides the current tag cloud.
110  
111 =item Item
112  
113 Provides a single diary entry.
114  
115 =item Comment
116  
117 Allow a user to submit a comment.
118  
119 =item LatestComments
120  
121 Retrieve the most recent comments, for use in a side panel or similar.
122  
123 =item Posted
124  
125 Number of posts posted by the given writer.
126  
127 =back
128  
129 =cut
130  
131 0 ▶sub Archive {
Subroutine Archive: not called CC=1 SCAR=6.9
Pod documented
132 0 my $oldid = $cgiparams{sectionid};
133 0 $cgiparams{sectionid} = $SECTIONID;
134 0 $cgiparams{section} = 'diary';
135  
136 0 shift->SUPER::Archive();
137 0 $tvars{articles} = undef;
138 0 $cgiparams{sectionid} = $oldid; # reset
139 }
140  
141 0 ▶sub Page {
Subroutine Page: not called CC=2 SCAR=17.9
Pod documented
142 0 ▶ return List() if($cgiparams{volume}); # volumes need to be handled by the List function
Branch: 1 branch
BranchTrueFalseTotal
if $Labyrinth::Plugin::Articles::Diary::cgiparams{"volume"} 0 0 0
143  
144 0 $cgiparams{sectionid} = $SECTIONID;
145 0 $settings{data}{article_pageset} = $settings{diary_pageset};
146  
147 0 shift->SUPER::Page();
148 0 _count_comments();
149 }
150  
151 0 ▶sub List {
Subroutine List: not called CC=8 SCAR=42.8
Pod documented
152 0 $cgiparams{sectionid} = $SECTIONID;
153 0 $settings{data}{article_limit} = $settings{diary_limit};
154 0 $settings{data}{article_stop} = $settings{diary_stop};
155  
156 0 ▶ if($cgiparams{volume}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Labyrinth::Plugin::Articles::Diary::cgiparams{"volume"}) 0 0 0
157 $settings{where} = 'createdate > ' . _vol2date($cgiparams{volume}) .
158 0 ' AND createdate < ' . _vol2date($cgiparams{volume} + 1);
159 }
160  
161 0 shift->SUPER::List();
162 0 _count_comments();
163  
164 # see if we can do next and previous
165 0 my $this = 0;
166 0 ▶ if($cgiparams{volume}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Labyrinth::Plugin::Articles::Diary::cgiparams{"volume"}) 0 0 0
167 0 for my $vol (@{$tvars{archive}{diary}}) {
168 0 ▶ if($cgiparams{volume} == $vol->{volumeid}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Labyrinth::Plugin::Articles::Diary::cgiparams{'volume'} == $vol->{'volumeid'}) { } 0 0 0
169 0 $this = 1;
170 } else {
171 0 ▶ $tvars{archive}{volumes}{prev} = $vol if(!$this);
Branch: 1 branch
BranchTrueFalseTotal
unless $this 0 0 0
172 0 ▶ $tvars{archive}{volumes}{next} ||= $vol if($this);
Branch: 1 branch
BranchTrueFalseTotal
if $this 0 0 0
Condition0%0/3
$Labyrinth::Plugin::Articles::Diary::tvars{"archive"}{"volumes"}{"next"} ||= $vol
l!l&&r!l&&!r
000
MC/DC0%0/2
$Labyrinth::Plugin::Articles::Diary::tvars{"archive"}{"volumes"}{"next"} ||= $vol
$Labyrinth::Plugin::Articles::Diary::tvars{"archive"}{"volumes"}{"next"} $vol
Truth table0%0/3
A ||= B
A= $Labyrinth::Plugin::Articles::Diary::tvars{"archive"}{"volumes"}{"next"}B= $vol
ABresult
1X1
011
000
173 }
174 }
175 }
176 }
177  
178 0 ▶sub Meta {
Subroutine Meta: not called CC=2 SCAR=17.9
Pod documented
179 0 ▶ return unless($cgiparams{data});
Branch: 1 branch
BranchTrueFalseTotal
unless $Labyrinth::Plugin::Articles::Diary::cgiparams{"data"} 0 0 0
180  
181 0 my $oldid = $cgiparams{sectionid};
182 0 $cgiparams{sectionid} = $SECTIONID;
183 0 $settings{data}{article_limit} = $settings{diary_limit};
184 0 $settings{data}{article_stop} = $settings{diary_stop};
185  
186 0 shift->SUPER::Meta();
187 0 _count_comments();
188 0 $cgiparams{sectionid} = $oldid; # reset
189 }
190  
191 0 ▶sub Cloud {
Subroutine Cloud: not called CC=1 SCAR=6.9
Pod documented
192 0 my $oldid = $cgiparams{sectionid};
193 0 $cgiparams{sectionid} = $SECTIONID;
194 0 $cgiparams{actcode} = 'diary-meta';
195 0 shift->SUPER::Cloud();
196 0 $cgiparams{sectionid} = $oldid; # reset
197 }
198  
199 0 ▶sub Search {
Subroutine Search: not called CC=2 SCAR=17.9
Pod documented
200 0 ▶ return unless($cgiparams{data});
Branch: 1 branch
BranchTrueFalseTotal
unless $Labyrinth::Plugin::Articles::Diary::cgiparams{"data"} 0 0 0
201  
202 0 my $oldid = $cgiparams{sectionid};
203 0 $cgiparams{sectionid} = $SECTIONID;
204 0 $settings{data}{article_limit} = $settings{diary_limit};
205 0 $settings{data}{article_stop} = $settings{diary_stop};
206  
207 0 shift->SUPER::Search();
208 0 _count_comments();
209 0 $cgiparams{sectionid} = $oldid; # reset
210 }
211  
212 0 ▶sub Item {
Subroutine Item: not called CC=2 SCAR=17.9
Pod documented
213 0 my $oldid = $cgiparams{sectionid};
214 0 $cgiparams{sectionid} = $SECTIONID;
215 0 shift->SUPER::Item();
216 0 $tvars{diary} = $tvars{article};
217 0 my @rows = $dbi->GetQuery('hash','GetDiaryComments',$tvars{diary}->{data}->{articleid});
218 0 for(@rows) {
219 0 $_->{postdate} = formatDate(6,$_->{createdate});
220 }
221  
222 0 $tvars{comments} = \@rows;
223 0 $cgiparams{sectionid} = $oldid; # reset
224 }
225  
226 0 ▶sub Comment {
Subroutine Comment: not called CC=14 SCAR=53.5
Pod documented
227 0 my $check = CheckIP();
228 0 ▶ if( $check == $BLOCK
Branch: 1 branch
BranchTrueFalseTotal
if ($check == $BLOCK or $Labyrinth::Plugin::Articles::Diary::cgiparams{"typekey"} or not $Labyrinth::Plugin::Articles::Diary::cgiparams{"loopback"} or $Labyrinth::Plugin::Articles::Diary::cgiparams{"loopback"} ne $Labyrinth::Plugin::Articles::Diary::settings{"ipaddr"}) 0 0 0
Condition0%0/9
$check == $BLOCK or $Labyrinth::Plugin::Articles::Diary::cgiparams{"typekey"} or not $Labyrinth::Plugin::Articles::Diary::cgiparams{"loopback"} or $Labyrinth::Plugin::Articles::Diary::cgiparams{"loopback"} ne $Labyrinth::Plugin::Articles::Diary::settings{"ipaddr"}
l!l&&r!l&&!r
000
$check == $BLOCK or $Labyrinth::Plugin::Articles::Diary::cgiparams{"typekey"} or not $Labyrinth::Plugin::Articles::Diary::cgiparams{"loopback"}
l!l&&r!l&&!r
000
$check == $BLOCK or $Labyrinth::Plugin::Articles::Diary::cgiparams{"typekey"}
l!l&&r!l&&!r
000
MC/DC0%0/4
$check == $BLOCK or $Labyrinth::Plugin::Articles::Diary::cgiparams{"typekey"} or not $Labyrinth::Plugin::Articles::Diary::cgiparams{"loopback"} or $Labyrinth::Plugin::Articles::Diary::cgiparams{"loopback"} ne $Labyrinth::Plugin::Articles::Diary::settings{"ipaddr"}
$check == $BLOCK $Labyrinth::Plugin::Articles::Diary::cgiparams{"typekey"} not $Labyrinth::Plugin::Articles::Diary::cgiparams{"loopback"} $Labyrinth::Plugin::Articles::Diary::cgiparams{"loopback"} ne $Labyrinth::Plugin::Articles::Diary::settings{"ipaddr"}
Truth table0%0/5
A or B or not(C) or D
A= $check == $BLOCKB= $Labyrinth::Plugin::Articles::Diary::cgiparams{"typekey"}C= not $Labyrinth::Plugin::Articles::Diary::cgiparams{"loopback"}D= $Labyrinth::Plugin::Articles::Diary::cgiparams{"loopback"} ne $Labyrinth::Plugin::Articles::Diary::settings{"ipaddr"}
ABCDresult
1XXX1
01XX1
001X1
00011
00000
229 || $cgiparams{typekey}
230 || !$cgiparams{loopback}
231 || $cgiparams{loopback} ne $settings{ipaddr}) {
232  
233 0 $tvars{thanks} = 3;
234 # print STDERR "COMMENT SPAM ALERT:\n" . Dumper(\%cgiparams);
235 0 return;
236 }
237  
238 0 ▶ $cgiparams{publish} = $check == $ALLOW ? 3 : 2;
Branch: 1 branch
BranchTrueFalseTotal
$check == $ALLOW ? : 0 0 0
239  
240 0 for(keys %cfields) {
241 0 ▶ next unless($cfields{$_});
Branch: 1 branch
BranchTrueFalseTotal
unless $cfields{$_} 0 0 0
242 0 ▶ if($cfields{$_}->{html} == 1) { $cgiparams{$_} = CleanHTML($cgiparams{$_}) }
Branch: 3 branches
BranchTrueFalseTotal
if ($cfields{$_}{'html'} == 1) { } 0 0 0
elsif ($cfields{$_}{'html'} == 2) { } 0 0 0
elsif ($cfields{$_}{'html'} == 3) { } 0 0 0
243 0 elsif($cfields{$_}->{html} == 2) { $cgiparams{$_} = CleanTags($cgiparams{$_}) }
244 0 elsif($cfields{$_}->{html} == 3) { $cgiparams{$_} = CleanTags($cgiparams{$_}) }
245 }
246  
247 0 ▶ return if FieldCheck(\@callfields,\@cmandatory);
Branch: 1 branch
BranchTrueFalseTotal
if FieldCheck(\@callfields, \@cmandatory) 0 0 0
248  
249 0 ▶ if($tvars{data}->{subject} eq 'ARRAY(0x84fb748)') {
Branch: 1 branch
BranchTrueFalseTotal
if ($Labyrinth::Plugin::Articles::Diary::tvars{"data"}{"subject"} eq "ARRAY(0x84fb748)") 0 0 0
250 # print STDERR "COMMENT SPAM ALERT:\n" . Dumper(\%cgiparams);
251 0 $tvars{thanks} = 3;
252 0 return;
253 }
254  
255 my @fields = ( $tvars{data}->{articleid},
256 $tvars{data}->{subject},
257 formatDate(), # create date
258 $tvars{data}->{body},
259 $tvars{data}->{author},
260 $tvars{data}->{href},
261 $tvars{data}->{publish},
262 $settings{ipaddr}
263 0 );
264  
265 0 $dbi->IDQuery('AddComment',@fields);
266 0 ▶ $tvars{thanks} = $check == $ALLOW ? 2 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$check == $ALLOW ? : 0 0 0
267 }
268  
269 0 ▶sub LatestComments {
Subroutine LatestComments: not called CC=1 SCAR=6.9
Pod documented
270 0 my @rows = $dbi->GetQuery('hash','GetCommentsLatest');
271 0 $tvars{latest}->{comments} = \@rows;
272 }
273  
274 0 ▶sub Posted {
Subroutine Posted: not called CC=3 SCAR=24.8
Pod documented
275 0 ▶ return unless($cgiparams{'userid'});
Branch: 1 branch
BranchTrueFalseTotal
unless $Labyrinth::Plugin::Articles::Diary::cgiparams{"userid"} 0 0 0
276 0 my @rows = $dbi->GetQuery('array','CountPosts',$cgiparams{'userid'});
277 0 ▶ $tvars{data}{posts} = @rows ? $rows[0]->[0] : 0;
Branch: 1 branch
BranchTrueFalseTotal
@rows ? : 0 0 0
278 }
279  
280 # -------------------------------------
281 # Admin Methods
282  
283 =head1 ADMIN INTERFACE METHODS
284  
285 =over 4
286  
287 =item Access
288  
289 Check whether user has the appropriate admin access.
290  
291 =item Admin
292  
293 Lists the current set of diary entries.
294  
295 Also provides the delete, copy and promote functionality from the main
296 administration page for the given section.
297  
298 =item Add
299  
300 Add a diary entry.
301  
302 =item Edit
303  
304 Edit a diary entry.
305  
306 =item Save
307  
308 Save a diary entry.
309  
310 =item Delete
311  
312 Delete a diary entry.
313  
314 =item ListComment
315  
316 List current unpublished comments.
317  
318 =item EditComment
319  
320 Edit a given comment.
321  
322 =item SaveComment
323  
324 Save a given comment.
325  
326 =item PromoteComment
327  
328 Promote a given comment.
329  
330 =item DeleteComment
331  
332 Delete a given comment.
333  
334 =item MarkIP
335  
336 Mark matching comments as appropriate. Actions are block and allow.
337  
338 =back
339  
340 =cut
341  
342 0 ▶sub Access { Authorised($LEVEL) }
Subroutine Access: not called CC=1 SCAR=6.9
Pod documented
343  
344 0 ▶sub Admin {
Subroutine Admin: not called CC=4 SCAR=30.0
Pod documented
345 0 ▶ return unless AccessUser($LEVEL);
Branch: 1 branch
BranchTrueFalseTotal
unless AccessUser($LEVEL) 0 0 0
346 0 $cgiparams{sectionid} = $SECTIONID;
347 0 shift->SUPER::Admin();
348  
349 0 for my $article (@{ $tvars{data} }) {
350 0 my @rows = $dbi->GetQuery('array','CountDiaryComments',{ids => $article->{articleid}});
351 0 ▶ $article->{comments} = @rows ? $rows[0]->[1] : '';
Branch: 1 branch
BranchTrueFalseTotal
@rows ? : 0 0 0
352 }
353 }
354  
355 0 ▶sub Add {
Subroutine Add: not called CC=2 SCAR=17.9
Pod documented
356 0 ▶ return unless AccessUser($LEVEL);
Branch: 1 branch
BranchTrueFalseTotal
unless AccessUser($LEVEL) 0 0 0
357 0 $cgiparams{sectionid} = $SECTIONID;
358 0 my $self = shift;
359 0 $self->SUPER::Add();
360 0 $self->SUPER::Tags();
361 }
362  
363 0 ▶sub Edit {
Subroutine Edit: not called CC=4 SCAR=30.0
Pod documented
364 0 ▶ return unless AccessUser($LEVEL);
Branch: 1 branch
BranchTrueFalseTotal
unless AccessUser($LEVEL) 0 0 0
365 0 $cgiparams{sectionid} = $SECTIONID;
366  
367 0 my $self = shift;
368 0 $self->SUPER::Edit();
369 0 $self->SUPER::Tags();
370 0 my @rows = $dbi->GetQuery('hash','GetDiaryComments',$tvars{article}->{data}->{articleid});
371 0 for(@rows) {
372 0 $_->{postdate} = formatDate(6,$_->{createdate});
373 }
374  
375 0 $tvars{articles}->{$tvars{primary}}->{data}{comments} = scalar(@rows);
376 0 ▶ $tvars{comments} = \@rows if(@rows);
Branch: 1 branch
BranchTrueFalseTotal
if @rows 0 0 0
377 }
378  
379 0 ▶sub Save {
Subroutine Save: not called CC=2 SCAR=17.9
Pod documented
380 0 ▶ return unless AccessUser($LEVEL);
Branch: 1 branch
BranchTrueFalseTotal
unless AccessUser($LEVEL) 0 0 0
381 0 $cgiparams{sectionid} = $SECTIONID;
382 0 $cgiparams{quickname} = formatDate(0);
383 0 shift->SUPER::Save();
384 }
385  
386 0 ▶sub Delete {
Subroutine Delete: not called CC=2 SCAR=17.9
Pod documented
387 0 ▶ return unless AccessUser($LEVEL);
Branch: 1 branch
BranchTrueFalseTotal
unless AccessUser($LEVEL) 0 0 0
388 0 $cgiparams{sectionid} = $SECTIONID;
389 0 shift->SUPER::Delete();
390 }
391  
392 0 ▶sub ListComment {
Subroutine ListComment: not called CC=14 SCAR=53.5
Pod documented
393 0 ▶ return unless AccessUser($LEVEL);
Branch: 1 branch
BranchTrueFalseTotal
unless AccessUser($LEVEL) 0 0 0
394  
395 0 my (@rows);
396 0 ▶ if($cgiparams{pattern}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Labyrinth::Plugin::Articles::Diary::cgiparams{"pattern"}) 0 0 0
397 0 @rows = $dbi->GetQuery('hash','GetCommentMatches','%'.$cgiparams{pattern}.'%');
398 0 for my $row (@rows) {
399 0 BlockIP($row->{author},$row->{ipaddr});
400 0 $dbi->DoQuery('DeleteComment',$row->{'commentid'});
401 }
402 }
403  
404 0 @rows = $dbi->GetQuery('hash','GetAdminCommentIDs');
405  
406 0 ▶ my $start = $cgiparams{start} || 1;
Condition0%0/2
$Labyrinth::Plugin::Articles::Diary::cgiparams{'start'} || 1
l!l
00
MC/DC0%0/1
$Labyrinth::Plugin::Articles::Diary::cgiparams{'start'} || 1
$Labyrinth::Plugin::Articles::Diary::cgiparams{'start'}
Truth table0%0/2
A
A= $Labyrinth::Plugin::Articles::Diary::cgiparams{'start'}
Aresult
11
00
407 0 ▶ my $limit = $cgiparams{limit} || $settings{comment_limit} || 100;
Condition0%0/5
$Labyrinth::Plugin::Articles::Diary::cgiparams{'limit'} || $Labyrinth::Plugin::Articles::Diary::settings{'comment_limit'} || 100
l!l
00
$Labyrinth::Plugin::Articles::Diary::cgiparams{"limit"} or $Labyrinth::Plugin::Articles::Diary::settings{"comment_limit"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$Labyrinth::Plugin::Articles::Diary::cgiparams{'limit'} || $Labyrinth::Plugin::Articles::Diary::settings{'comment_limit'} || 100
$Labyrinth::Plugin::Articles::Diary::cgiparams{"limit"} $Labyrinth::Plugin::Articles::Diary::settings{"comment_limit"}
Truth table0%0/3
A or B
A= $Labyrinth::Plugin::Articles::Diary::cgiparams{"limit"}B= $Labyrinth::Plugin::Articles::Diary::settings{"comment_limit"}
ABresult
1X1
011
000
408 0 my $last = int(scalar(@rows) / $limit);
409 0 my $max = scalar(@rows);
410  
411 0 LogDebug("start=$start, limit=$limit, last=$last, max=$max");
412  
413 0 ▶ if(@rows) {
Branch: 1 branch
BranchTrueFalseTotal
if (@rows) 0 0 0
414 0 my $count = ($start-1) * $limit;
415 0 ▶ splice(@rows,0,$count) if($count > 0);
Branch: 1 branch
BranchTrueFalseTotal
if $count > 0 0 0 0
416 0 ▶ splice(@rows,$limit) if(@rows > $limit);
Branch: 1 branch
BranchTrueFalseTotal
if @rows > $limit 0 0 0
417 0 my $ids = join(',',map {$_->{commentid}} @rows);
418  
419 0 @rows = $dbi->GetQuery('hash','GetAdminComments',{ ids => $ids });
420 0 for(@rows) {
421 0 $_->{postdate} = formatDate(17,$_->{createdate});
422 }
423  
424 0 $tvars{comments} = \@rows;
425 }
426  
427 0 my ($prev,$next) = ($start-1,$start+1);
428 0 ▶ $prev = 1 if($prev < 1);
Branch: 1 branch
BranchTrueFalseTotal
if $prev < 1 0 0 0
429 0 ▶ $next = $last if($next > $last);
Branch: 1 branch
BranchTrueFalseTotal
if $next > $last 0 0 0
430  
431 0 $tvars{page}{prev} = $prev;
432 0 $tvars{page}{start} = $start;
433 0 $tvars{page}{next} = $next;
434 0 $tvars{page}{last} = $last;
435 0 $tvars{page}{limit} = $limit;
436 0 $tvars{page}{comments} = $max;
437  
438 0 my @offenders = $dbi->GetQuery('hash','WorstOffenders');
439 0 ▶ $tvars{offenders} = \@offenders if(@offenders);
Branch: 1 branch
BranchTrueFalseTotal
if @offenders 0 0 0
440 }
441  
442 0 ▶sub EditComment {
Subroutine EditComment: not called CC=3 SCAR=24.8
Pod documented
443 0 ▶ return unless AccessUser($LEVEL);
Branch: 1 branch
BranchTrueFalseTotal
unless AccessUser($LEVEL) 0 0 0
444 0 ▶ return unless AuthorCheck('GetCommentByID','commentid',$LEVEL);
Branch: 1 branch
BranchTrueFalseTotal
unless AuthorCheck("GetCommentByID", "commentid", $LEVEL) 0 0 0
445 0 $tvars{comment} = $tvars{data};
446 0 $tvars{comment}->{postdate} = formatDate(17,$tvars{comment}->{createdate});
447 0 $tvars{comment}->{ddpublish} = PublishSelect($tvars{comment}->{publish});
448 }
449  
450 0 ▶sub SaveComment {
Subroutine SaveComment: not called CC=10 SCAR=47.0
Pod documented
451 0 ▶ return unless AccessUser($LEVEL);
Branch: 1 branch
BranchTrueFalseTotal
unless AccessUser($LEVEL) 0 0 0
452 0 ▶ return unless AuthorCheck('GetCommentByID','commentid',$LEVEL);
Branch: 1 branch
BranchTrueFalseTotal
unless AuthorCheck("GetCommentByID", "commentid", $LEVEL) 0 0 0
453 0 for(keys %cfields) {
454 0 ▶ next unless($cfields{$_});
Branch: 1 branch
BranchTrueFalseTotal
unless $cfields{$_} 0 0 0
455 0 ▶ if($cfields{$_}->{html} == 1) { $cgiparams{$_} = CleanHTML($cgiparams{$_}) }
Branch: 3 branches
BranchTrueFalseTotal
if ($cfields{$_}{'html'} == 1) { } 0 0 0
elsif ($cfields{$_}{'html'} == 2) { } 0 0 0
elsif ($cfields{$_}{'html'} == 3) { } 0 0 0
456 0 elsif($cfields{$_}->{html} == 2) { $cgiparams{$_} = CleanTags($cgiparams{$_}) }
457 0 elsif($cfields{$_}->{html} == 3) { $cgiparams{$_} = CleanTags($cgiparams{$_}) }
458 }
459  
460 0 ▶ return if FieldCheck(\@callfields,\@cmandatory);
Branch: 1 branch
BranchTrueFalseTotal
if FieldCheck(\@callfields, \@cmandatory) 0 0 0
461 0 ▶ $tvars{data}->{publish} ||= 1;
Condition0%0/2
$Labyrinth::Plugin::Articles::Diary::tvars{"data"}{"publish"} ||= 1
l!l
00
MC/DC0%0/1
$Labyrinth::Plugin::Articles::Diary::tvars{"data"}{"publish"} ||= 1
$Labyrinth::Plugin::Articles::Diary::tvars{"data"}{"publish"}
Truth table0%0/2
A
A= $Labyrinth::Plugin::Articles::Diary::tvars{"data"}{"publish"}
Aresult
11
00
462  
463 my @fields = ( $tvars{data}->{subject},
464 $tvars{data}->{body},
465 $tvars{data}->{author},
466 $tvars{data}->{href},
467 $tvars{data}->{publish},
468 $tvars{data}->{commentid}
469 0 );
470  
471 0 $dbi->IDQuery('SaveComment',@fields);
472 }
473  
474 0 ▶sub PromoteComment {
Subroutine PromoteComment: not called CC=3 SCAR=24.8
Pod documented
475 0 ▶ return unless AccessUser($LEVEL);
Branch: 1 branch
BranchTrueFalseTotal
unless AccessUser($LEVEL) 0 0 0
476 0 ▶ return unless AuthorCheck('GetCommentByID','commentid',$LEVEL);
Branch: 1 branch
BranchTrueFalseTotal
unless AuthorCheck("GetCommentByID", "commentid", $LEVEL) 0 0 0
477 0 $dbi->DoQuery('PromoteComment',$tvars{data}->{publish}+1,$cgiparams{'commentid'});
478 }
479  
480 0 ▶sub DeleteComment {
Subroutine DeleteComment: not called CC=3 SCAR=24.8
Pod documented
481 0 ▶ return unless AccessUser($LEVEL);
Branch: 1 branch
BranchTrueFalseTotal
unless AccessUser($LEVEL) 0 0 0
482 0 ▶ return unless AuthorCheck('GetCommentByID','commentid',$LEVEL);
Branch: 1 branch
BranchTrueFalseTotal
unless AuthorCheck("GetCommentByID", "commentid", $LEVEL) 0 0 0
483 0 $dbi->DoQuery('DeleteComment',$cgiparams{'commentid'});
484 }
485  
486 0 ▶sub MarkIP {
Subroutine MarkIP: not called CC=9 SCAR=45.0
Pod documented
487 0 ▶ return unless AccessUser($LEVEL);
Branch: 1 branch
BranchTrueFalseTotal
unless AccessUser($LEVEL) 0 0 0
488 0 ▶ return unless AuthorCheck('GetCommentByID','commentid',$LEVEL);
Branch: 1 branch
BranchTrueFalseTotal
unless AuthorCheck("GetCommentByID", "commentid", $LEVEL) 0 0 0
489 0 ▶ return unless $cgiparams{mark};
Branch: 1 branch
BranchTrueFalseTotal
unless $Labyrinth::Plugin::Articles::Diary::cgiparams{"mark"} 0 0 0
490 0 ▶ my $mark = $cgiparams{mark} eq 'allow' ? 2 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$Labyrinth::Plugin::Articles::Diary::cgiparams{'mark'} eq 'allow' ? : 0 0 0
491  
492 0 ▶ if($mark == 2) { AllowIP($tvars{data}->{author},$tvars{data}->{ipaddr}) }
Branch: 1 branch
BranchTrueFalseTotal
if ($mark == 2) { } 0 0 0
493 0 else { BlockIP($tvars{data}->{author},$tvars{data}->{ipaddr}) }
494  
495 0 my @rows = $dbi->GetQuery('hash','GetAdminCommentByIP',$tvars{data}->{ipaddr});
496 0 for my $row (@rows) {
497 0 ▶ next unless($row->{ipaddr} eq $tvars{data}->{ipaddr});
Branch: 1 branch
BranchTrueFalseTotal
unless $row->{"ipaddr"} eq $Labyrinth::Plugin::Articles::Diary::tvars{"data"}{"ipaddr"} 0 0 0
498 0 ▶ if($mark == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mark == 2) { } 0 0 0
499 0 $dbi->DoQuery('PromoteComment',$tvars{data}->{publish}+1,$row->{'commentid'});
500 } else {
501 0 $dbi->DoQuery('DeleteComment',$row->{'commentid'});
502 }
503 }
504 }
505  
506 # -------------------------------------
507 # Private Methods
508  
509 0 ▶sub _count_comments {
Subroutine _count_comments: not called CC=6 SCAR=37.4
510 0 ▶ my $type = shift || 'mainarts';
Condition0%0/2
shift() || 'mainarts'
l!l
00
MC/DC0%0/1
shift() || 'mainarts'
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
511 0 ▶ return unless($tvars{$type} && scalar(@{$tvars{$type}}));
Branch: 1 branch
BranchTrueFalseTotal
unless $Labyrinth::Plugin::Articles::Diary::tvars{$type} and scalar @{$Labyrinth::Plugin::Articles::Diary::tvars{$type};} 0 0 0
Condition0%0/2
$Labyrinth::Plugin::Articles::Diary::tvars{$type} and scalar @{$Labyrinth::Plugin::Articles::Diary::tvars{$type};}
!ll
00
MC/DC0%0/1
$Labyrinth::Plugin::Articles::Diary::tvars{$type} and scalar @{$Labyrinth::Plugin::Articles::Diary::tvars{$type};}
$Labyrinth::Plugin::Articles::Diary::tvars{$type}
Truth table0%0/2
A
A= $Labyrinth::Plugin::Articles::Diary::tvars{$type}
Aresult
00
11
512  
513 0 my $ids = join(',', map {$_->{data}{articleid}} @{$tvars{$type}});
514 0 my @rows = $dbi->GetQuery('array','CountDiaryComments',{ids => $ids});
515 0 my %rows = map {$_->[0] => $_->[1]} @rows;
516 0 for my $item (@{$tvars{$type}}) {
517 0 ▶ $item->{comments} = $rows{$item->{data}{articleid}} || 0;
Condition0%0/2
$rows{$item->{'data'}{'articleid'}} || 0
l!l
00
MC/DC0%0/1
$rows{$item->{'data'}{'articleid'}} || 0
$rows{$item->{'data'}{'articleid'}}
Truth table0%0/2
A
A= $rows{$item->{'data'}{'articleid'}}
Aresult
11
00
518 }
519 }
520  
521 0 ▶sub _vol2date {
Subroutine _vol2date: not called CC=2 SCAR=17.9
522 0 my ($year,$mon) = $_[0] =~ /^(\d{4})(\d{2})/;
523 0 ▶ if($mon == 13) { $year++;$mon=1; }
Branch: 1 branch
BranchTrueFalseTotal
if ($mon == 13) 0 0 0
524 0 return timegm(0,0,0,1,$mon-1,$year);
525 }
526  
527 5 1;
528  
529 __END__
↑ Summary