blib/lib/Labyrinth/Plugin/Links.pm

filter: Statementstmt 39.6% 42 / 106 Branchbran 5.7% 4 / 70 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 36.8% 7 / 19 Podpod 100% 12 / 12 totaltotal 30.2% 65 / 215 CC 38 SCAR 37.7
CC
38
Cov
25%
CatSave
110.0
Save
90.0
Admin
30.0
CRAP 43.3
↑ Summary
1 package Labyrinth::Plugin::Links;
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 our $VERSION = '1.07';
7  
8 =head1 NAME
9  
10 Labyrinth::Plugin::Links - Links plugin handler for Labyrinth
11  
12 =head1 DESCRIPTION
13  
14 Contains all the link handling functionality for the Labyrinth
15 framework.
16  
17 =cut
18  
19 # -------------------------------------
20 # Library Modules
21  
22 5 ▶use base qw(Labyrinth::Plugin::Base);
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 5 ▶use Labyrinth::DBUtils;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 5 ▶use Labyrinth::MLUtils;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 5 ▶use Labyrinth::Support;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 5 ▶use Labyrinth::Variables;
Subroutine BEGIN: called CC=1 SCAR=0.0
28  
29 # -------------------------------------
30 # Variables
31  
32 # type: 0 = optional, 1 = mandatory
33 # html: 0 = none, 1 = text, 2 = textarea
34  
35 5 my %cat_fields = (
36 catid => { type => 0, html => 0 },
37 orderno => { type => 0, html => 1 },
38 category => { type => 1, html => 1 },
39 );
40  
41 5 my (@cat_mandatory,@cat_allfields);
42 5 for(keys %cat_fields) {
43 15 ▶ push @cat_mandatory, $_ if($cat_fields{$_}->{type});
Branch: 1 branch
BranchTrueFalseTotal
if $cat_fields{$_}{"type"} 5 10 15
44 15 push @cat_allfields, $_;
45 }
46  
47 5 my %fields = (
48 linkid => { type => 0, html => 0 },
49 catid => { type => 0, html => 0 },
50 href => { type => 1, html => 1 },
51 title => { type => 1, html => 3 },
52 body => { type => 0, html => 2 },
53 );
54  
55 5 my (@mandatory,@allfields);
56 5 for(keys %fields) {
57 25 ▶ push @mandatory, $_ if($fields{$_}->{type});
Branch: 1 branch
BranchTrueFalseTotal
if $fields{$_}{"type"} 10 15 25
58 25 push @allfields, $_;
59 }
60  
61 5 my @savefields = qw(title href body catid);
62 5 my $INDEXKEY = 'linkid';
63 5 my $ALLSQL = 'GetLinks';
64 5 my $SAVESQL = 'SaveLink';
65 5 my $ADDSQL = 'AddLink';
66 5 my $GETSQL = 'GetLinkByID';
67 5 my $DELETESQL = 'DeleteLink';
68  
69 5 my %adddata = (
70 linkid => 0,
71 href => '',
72 title => '',
73 body => '',
74 );
75  
76 5 my $protocol = qr{(?:http|https|ftp|afs|news|nntp|mid|cid|mailto|wais|prospero|telnet|gopher|git)://};
77  
78 # -------------------------------------
79 # The Subs
80  
81 =head1 PUBLIC INTERFACE METHODS
82  
83 =head2 Default Methods
84  
85 =over 4
86  
87 =item List
88  
89 Provides a list of all the current links.
90  
91 =back
92  
93 =cut
94  
95 sub List {
96 # get link list for current realm
97 0 ▶ my @rows = $dbi->GetQuery('hash','GetLinks');
Subroutine List: not called CC=2 SCAR=17.9
Pod documented
98 0 ▶ $tvars{links} = \@rows if(@rows);
Branch: 1 branch
BranchTrueFalseTotal
if @rows 0 0 0
99 }
100  
101 =head1 ADMIN INTERFACE METHODS
102  
103 =head2 Link Methods
104  
105 =over 4
106  
107 =item Admin
108  
109 Provides a list of all the current links, with additional administrator
110 functions.
111  
112 =item Add
113  
114 Add a link.
115  
116 =item Edit
117  
118 Edit an existing link.
119  
120 =item Save
121  
122 Validates the given fields and saves to the database.
123  
124 =item Delete
125  
126 Delete a link
127  
128 =item CheckLink
129  
130 Checks whether a link begins with an accepted protocol (http, https, ftp), and
131 if missing adds 'http://'.
132  
133 =back
134  
135 =cut
136  
137 sub Admin {
138 0 ▶ return unless(AccessUser(EDITOR));
Subroutine Admin: not called CC=5 SCAR=34.0
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
unless AccessUser(2) 0 0 0
139 0 ▶ if($cgiparams{doaction}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Labyrinth::Plugin::Links::cgiparams{"doaction"}) 0 0 0
140 0 ▶ if($cgiparams{doaction} eq 'Delete' ) { Delete(); }
Branch: 1 branch
BranchTrueFalseTotal
if ($Labyrinth::Plugin::Links::cgiparams{"doaction"} eq "Delete") 0 0 0
141 }
142 0 my @rows = $dbi->GetQuery('hash',$ALLSQL);
143 0 ▶ $tvars{data} = \@rows if(@rows);
Branch: 1 branch
BranchTrueFalseTotal
if @rows 0 0 0
144 }
145  
146 sub Add {
147 0 ▶ return unless AccessUser(EDITOR);
Subroutine Add: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
unless AccessUser(2) 0 0 0
148 0 $tvars{data}{ddcats} = CatSelect();
149 }
150  
151 sub Edit {
152 0 ▶ return unless AccessUser(EDITOR);
Subroutine Edit: not called CC=3 SCAR=24.8
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
unless AccessUser(2) 0 0 0
153 0 ▶ return unless AuthorCheck($GETSQL,$INDEXKEY,EDITOR);
Branch: 1 branch
BranchTrueFalseTotal
unless AuthorCheck($GETSQL, $INDEXKEY, 2) 0 0 0
154 0 $tvars{data}{ddcats} = CatSelect($tvars{data}{catid});
155 0 $tvars{data}{ddpublish} = PublishSelect($tvars{data}{publish},1);
156 }
157  
158 sub Save {
159 0 ▶ return unless AccessUser(EDITOR);
Subroutine Save: not called CC=9 SCAR=45.0
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
unless AccessUser(2) 0 0 0
160 0 ▶ return unless AuthorCheck($GETSQL,$INDEXKEY,EDITOR);
Branch: 1 branch
BranchTrueFalseTotal
unless AuthorCheck($GETSQL, $INDEXKEY, 2) 0 0 0
161 0 for(keys %fields) {
162 0 ▶ if($fields{$_}->{html} == 1) { $cgiparams{$_} = CleanHTML($cgiparams{$_}) }
Branch: 3 branches
BranchTrueFalseTotal
if ($fields{$_}{'html'} == 1) { } 0 0 0
elsif ($fields{$_}{'html'} == 2) { } 0 0 0
elsif ($fields{$_}{'html'} == 3) { } 0 0 0
163 0 elsif($fields{$_}->{html} == 2) { $cgiparams{$_} = CleanTags($cgiparams{$_}) }
164 0 elsif($fields{$_}->{html} == 3) { $cgiparams{$_} = CleanLink($cgiparams{$_}) }
165 }
166 0 ▶ return if FieldCheck(\@allfields,\@mandatory);
Branch: 1 branch
BranchTrueFalseTotal
if FieldCheck(\@allfields, \@mandatory) 0 0 0
167 0 my @fields = map {$tvars{data}->{$_}} @savefields;
168 0 ▶ if($cgiparams{$INDEXKEY}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Labyrinth::Plugin::Links::cgiparams{$INDEXKEY}) { } 0 0 0
169 0 $dbi->DoQuery($SAVESQL,@fields,$cgiparams{$INDEXKEY});
170 } else {
171 0 $cgiparams{$INDEXKEY} = $dbi->IDQuery($ADDSQL,@fields);
172 }
173 0 $tvars{thanks} = 1;
174 }
175  
176 sub Delete {
177 0 ▶ return unless AccessUser(ADMIN);
Subroutine Delete: not called CC=3 SCAR=24.8
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
unless AccessUser(4) 0 0 0
178 0 my @ids = CGIArray('LISTED');
179 0 ▶ return unless @ids;
Branch: 1 branch
BranchTrueFalseTotal
unless @ids 0 0 0
180  
181 0 $dbi->DoQuery($DELETESQL,{ids=>join(",",@ids)});
182 }
183  
184 sub CheckLink {
185 0 ▶ if($cgiparams{href} && $cgiparams{href} !~ m!^(/|$protocol)!) {
Subroutine CheckLink: not called CC=3 SCAR=24.8
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if ($Labyrinth::Plugin::Links::cgiparams{"href"} and not $Labyrinth::Plugin::Links::cgiparams{"href"} =~ m[^(/|$protocol)]) 0 0 0
Condition0%0/3
$Labyrinth::Plugin::Links::cgiparams{"href"} and not $Labyrinth::Plugin::Links::cgiparams{"href"} =~ m[^(/|$protocol)]
!ll&&!rl&&r
000
MC/DC0%0/2
$Labyrinth::Plugin::Links::cgiparams{"href"} and not $Labyrinth::Plugin::Links::cgiparams{"href"} =~ m[^(/|$protocol)]
$Labyrinth::Plugin::Links::cgiparams{"href"} not $Labyrinth::Plugin::Links::cgiparams{"href"} =~ m[^(/|$protocol)]
Truth table0%0/3
A and not(B)
A= $Labyrinth::Plugin::Links::cgiparams{"href"}B= not $Labyrinth::Plugin::Links::cgiparams{"href"} =~ m[^(/|$protocol)]
ABresult
0X0
100
111
186 0 $cgiparams{href} = 'http://' . $cgiparams{href};
187 }
188 }
189  
190 =head2 Category Admin
191  
192 =over 4
193  
194 =item CatAdmin
195  
196 Provides a list of the link categories.
197  
198 =item CatEdit
199  
200 Edit a link category.
201  
202 =item CatSave
203  
204 Validates the fields returned from the edit page, and either saves or inserts
205 the record into the database.
206  
207 =item CatDelete
208  
209 Delete a link category.
210  
211 =item CatSelect
212  
213 Returns a HTML drop-down list of link categories.
214  
215 =cut
216  
217 sub CatAdmin {
218 0 ▶ return unless(AccessUser(EDITOR));
Subroutine CatAdmin: not called CC=5 SCAR=34.0
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
unless AccessUser(2) 0 0 0
219 0 ▶ if($cgiparams{doaction}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Labyrinth::Plugin::Links::cgiparams{"doaction"}) 0 0 0
220 0 ▶ if($cgiparams{doaction} eq 'Delete' ) { CatDelete(); }
Branch: 1 branch
BranchTrueFalseTotal
if ($Labyrinth::Plugin::Links::cgiparams{"doaction"} eq "Delete") 0 0 0
221 }
222 0 my @rows = $dbi->GetQuery('hash','GetCategories');
223 0 ▶ $tvars{data} = \@rows if(@rows);
Branch: 1 branch
BranchTrueFalseTotal
if @rows 0 0 0
224 }
225  
226 sub CatEdit {
227 0 ▶ return unless AccessUser(EDITOR);
Subroutine CatEdit: not called CC=3 SCAR=24.8
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
unless AccessUser(2) 0 0 0
228 0 ▶ return unless AuthorCheck('GetCategoryByID','catid',EDITOR);
Branch: 1 branch
BranchTrueFalseTotal
unless AuthorCheck("GetCategoryByID", "catid", 2) 0 0 0
229 }
230  
231 sub CatSave {
232 0 ▶ return unless AccessUser(EDITOR);
Subroutine CatSave: not called CC=10 SCAR=47.0
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
unless AccessUser(2) 0 0 0
233 0 ▶ return unless AuthorCheck('GetCategoryByID','catid',EDITOR);
Branch: 1 branch
BranchTrueFalseTotal
unless AuthorCheck("GetCategoryByID", "catid", 2) 0 0 0
234  
235 0 for(keys %cat_fields) {
236 0 ▶ if($cat_fields{$_}->{html} == 1) { $cgiparams{$_} = CleanHTML($cgiparams{$_}) }
Branch: 3 branches
BranchTrueFalseTotal
if ($cat_fields{$_}{'html'} == 1) { } 0 0 0
elsif ($cat_fields{$_}{'html'} == 2) { } 0 0 0
elsif ($cat_fields{$_}{'html'} == 3) { } 0 0 0
237 0 elsif($cat_fields{$_}->{html} == 2) { $cgiparams{$_} = CleanTags($cgiparams{$_}) }
238 0 elsif($cat_fields{$_}->{html} == 3) { $cgiparams{$_} = CleanLink($cgiparams{$_}) }
239 }
240 0 ▶ return if FieldCheck(\@cat_allfields,\@cat_mandatory);
Branch: 1 branch
BranchTrueFalseTotal
if FieldCheck(\@cat_allfields, \@cat_mandatory) 0 0 0
241  
242 0 ▶ $tvars{data}->{orderno} ||= 1;
Condition0%0/2
$Labyrinth::Plugin::Links::tvars{"data"}{"orderno"} ||= 1
l!l
00
MC/DC0%0/1
$Labyrinth::Plugin::Links::tvars{"data"}{"orderno"} ||= 1
$Labyrinth::Plugin::Links::tvars{"data"}{"orderno"}
Truth table0%0/2
A
A= $Labyrinth::Plugin::Links::tvars{"data"}{"orderno"}
Aresult
11
00
243 0 my @fields = ($tvars{data}->{orderno},$tvars{data}->{category});
244 0 ▶ if($cgiparams{catid}) { $dbi->DoQuery('SaveCategory',@fields,$cgiparams{catid}); }
Branch: 1 branch
BranchTrueFalseTotal
if ($Labyrinth::Plugin::Links::cgiparams{'catid'}) { } 0 0 0
245 0 else { $cgiparams{catid} = $dbi->IDQuery('NewCategory',@fields); }
246 0 $tvars{thanks} = 1;
247 }
248  
249 sub CatDelete {
250 0 ▶ return unless AccessUser(ADMIN);
Subroutine CatDelete: not called CC=3 SCAR=24.8
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
unless AccessUser(4) 0 0 0
251 0 my @ids = CGIArray('LISTED');
252 0 ▶ return unless @ids;
Branch: 1 branch
BranchTrueFalseTotal
unless @ids 0 0 0
253 0 $dbi->DoQuery('DeleteCategory',{ids=>join(",",@ids)});
254 0 $dbi->DoQuery('DeleteCatLinks',{ids=>join(",",@ids)});
255 }
256  
257 sub CatSelect {
258 0 ▶ my $opt = shift;
Subroutine CatSelect: not called CC=1 SCAR=6.9
Pod documented
259 0 my @rows = $dbi->GetQuery('hash','GetCategories');
260 0 DropDownRows($opt,'catid','catid','category',@rows);
261 }
262  
263 5 1;
264  
265 __END__
266  
267 =back
268  
269 =head1 SEE ALSO
270  
271 Labyrinth
272  
273 =head1 AUTHOR
274  
275 Barbie, <barbie@missbarbell.co.uk> for
276 Miss Barbell Productions, L<http://www.missbarbell.co.uk/>
277  
278 =head1 COPYRIGHT & LICENSE
279  
280 Copyright (C) 2002-2014 Barbie for Miss Barbell Productions
281 All Rights Reserved.
282  
283 This module is free software; you can redistribute it and/or
284 modify it under the Artistic License 2.0.
285  
286 =cut
↑ Summary