Labyrinth/Plugin/Base.pm

filter: Statementstmt 31.7% 40 / 126 Branchbran 0.0% 0 / 58 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 30.7% 8 / 26 Podpod 100% 18 / 18 totaltotal 28.9% 66 / 228 CC 36 SCAR 37.1
CC
36
Cov
22%
Save
132.0
Admin
56.0
Promote
42.0
CRAP 40.8
« Labyrinth/Support.pm ↑ Summary Labyrinth/Request.pm »
1 package Labyrinth::Plugin::Base;
2  
3 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 4 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 $VERSION = '5.32';
8  
9 =head1 NAME
10  
11 Labyrinth::Plugin::Base - Base Plugin Handler for Labyrinth
12  
13 =head1 DESCRIPTION
14  
15 Contains all the admin handling functionality for a simple plugin.
16  
17 =cut
18  
19 # -------------------------------------
20 # Library Modules
21  
22 4 ▶use Labyrinth::Globals;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 4 ▶use Labyrinth::DBUtils;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 4 ▶use Labyrinth::Session;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 4 ▶use Labyrinth::Support;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 4 ▶use Labyrinth::Variables;
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 # -------------------------------------
29 # Variables
30  
31 4 my @mandatory;
32 my @allfields;
33 4 my @savefields;
34 4 my @addfields;
35 4 my $INDEXKEY = 'id';
36 4 my $ALLSQL = 'AllRecords';
37 4 my $SAVESQL = 'SaveRecord';
38 4 my $ADDSQL = 'AddRecord';
39 4 my $GETSQL = 'GetRecordByID';
40 4 my $DELETESQL = 'DeleteRecords';
41 4 my $PROMOTESQL = 'PromoteRecord';
42 4 my $IMAGEKEY = 'NoImageCheck';
43 4 my $LEVEL = EDITOR;
44 4 my $NEXTCOMMAND = 'home-main';
45  
46 4 my %adddata;
47 my %fields;
48  
49 # -------------------------------------
50 # The Subs
51  
52 =head1 FUNCTIONS
53  
54 =head2 Constructor
55  
56 =over 4
57  
58 =item new()
59  
60 Creates the Plugin object.
61  
62 =back
63  
64 =cut
65  
66 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
67 0 my $self = shift;
68  
69 # create an attributes hash
70 0 my $atts = {
71 'mandatory' => \@mandatory,
72 'allfields' => \@allfields,
73 'savefields' => \@savefields,
74 'addfields' => \@addfields,
75 'INDEXKEY' => $INDEXKEY,
76 'ALLSQL' => $ALLSQL,
77 'SAVESQL' => $SAVESQL,
78 'ADDSQL' => $ADDSQL,
79 'GETSQL' => $GETSQL,
80 'DELETESQL' => $DELETESQL,
81 'PROMOTESQL' => $PROMOTESQL,
82 'IMAGEKEY' => $IMAGEKEY,
83 'LEVEL' => $LEVEL,
84 'NEXTCOMMAND' => $NEXTCOMMAND,
85 'adddata' => \%adddata,
86 'fields' => \%fields,
87 };
88  
89 # create the object
90 0 bless $atts, $self;
91 0 return $atts;
92 }
93  
94 =head1 PUBLIC INTERFACE METHODS
95  
96 None by default.
97  
98 =head1 ADMIN INTERFACE METHODS
99  
100 =over 4
101  
102 =item Access
103  
104 Determines the minimum level of access required. Primarily used to build the
105 administration navigation panel.
106  
107 =cut
108  
109 0 ▶sub Access { my $self = shift; Authorised($self->{LEVEL}) }
Subroutine Access: not called CC=1 SCAR=6.9
Pod documented
110  
111 =item ImageCheck
112  
113 Used when deleting images, to sure the plugin doesn't still reference them.
114 Otherwise missing images could result.
115  
116 =cut
117  
118 0 ▶sub ImageCheck { return 0 }
Subroutine ImageCheck: not called CC=1 SCAR=6.9
Pod documented
119  
120 =item Admin
121  
122 Full Admin list for the current plugin. Enables the 'Delete' and 'Copy'
123 features if they have been selected. Calls the SearchSQL function to generate
124 the 'WHERE' clause, and stores the result output.
125  
126 =item SearchSQL
127  
128 Generates the 'WHERE' clause to refine a list.
129  
130 =item AdminAmendments
131  
132 Some plugins need to add or amend field values, or perform additonal
133 functionality before displaying the list of records.
134  
135 =cut
136  
137 0 ▶sub Admin {
Subroutine Admin: not called CC=7 SCAR=40.3
Pod documented
138 0 my $self = shift;
139 0 ▶ return unless(AccessUser($self->{LEVEL}));
Branch: 1 branch
BranchTrueFalseTotal
unless AccessUser($self->{"LEVEL"}) 0 0 0
140  
141 0 ▶ if($cgiparams{doaction}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Labyrinth::Plugin::Base::cgiparams{"doaction"}) 0 0 0
142 0 ▶ if($cgiparams{doaction} eq 'Delete') { Delete() }
Branch: 3 branches
BranchTrueFalseTotal
if ($Labyrinth::Plugin::Base::cgiparams{'doaction'} eq 'Delete') { } 0 0 0
elsif ($Labyrinth::Plugin::Base::cgiparams{'doaction'} eq 'Copy') { } 0 0 0
elsif ($Labyrinth::Plugin::Base::cgiparams{'doaction'} eq 'Promote') { } 0 0 0
143 0 elsif($cgiparams{doaction} eq 'Copy') { Copy() }
144 0 elsif($cgiparams{doaction} eq 'Promote') { Promote() }
145 }
146  
147 0 my $where = SearchSQL();
148  
149 0 my @rows = $dbi->GetQuery('hash',$self->{ALLSQL},{where=>$where});
150 0 ▶ $tvars{data} = \@rows if(@rows);
Branch: 1 branch
BranchTrueFalseTotal
if @rows 0 0 0
151  
152 0 AdminAmendments();
153 }
154  
155 0 ▶sub SearchSQL { return '' }
Subroutine SearchSQL: not called CC=1 SCAR=6.9
Pod documented
156  
157 0 ▶sub AdminAmendments {}
Subroutine AdminAmendments: not called CC=1 SCAR=0.0
Pod documented
158  
159 =item Add
160  
161 Primes the edit page for adding a record.
162  
163 =item AddAmendments
164  
165 Some plugins need to add or amend field values, or perform additonal
166 functionality before displaying the new record for edit.
167  
168 =cut
169  
170 0 ▶sub Add {
Subroutine Add: not called CC=2 SCAR=17.9
Pod documented
171 0 my $self = shift;
172 0 ▶ return unless AccessUser($self->{LEVEL});
Branch: 1 branch
BranchTrueFalseTotal
unless AccessUser($self->{"LEVEL"}) 0 0 0
173  
174 0 AddAmendments();
175  
176 0 $tvars{data} = $self->{adddata};
177 }
178  
179 0 ▶sub AddAmendments {}
Subroutine AddAmendments: not called CC=1 SCAR=0.0
Pod documented
180  
181 =item Promote
182  
183 Promotes the reference item through to the next stage of the workflow.
184  
185 =cut
186  
187 0 ▶sub Promote {
Subroutine Promote: not called CC=6 SCAR=37.4
Pod documented
188 0 my $self = shift;
189 0 ▶ return unless AccessUser($self->{LEVEL});
Branch: 1 branch
BranchTrueFalseTotal
unless AccessUser($self->{"LEVEL"}) 0 0 0
190 0 my @ids = CGIArray('LISTED');
191 0 ▶ return unless @ids;
Branch: 1 branch
BranchTrueFalseTotal
unless @ids 0 0 0
192  
193 0 for my $id (@ids) {
194 0 $cgiparams{$self->{INDEXKEY}} = $id;
195 0 ▶ next unless AuthorCheck($self->{GETSQL},$self->{INDEXKEY},$self->{LEVEL});
Branch: 1 branch
BranchTrueFalseTotal
unless AuthorCheck($self->{"GETSQL"}, $self->{"INDEXKEY"}, $self->{"LEVEL"}) 0 0 0
196  
197 0 my $publish = $tvars{data}->{publish} + 1;
198 0 ▶ next unless($publish < 5);
Branch: 1 branch
BranchTrueFalseTotal
unless $publish < 5 0 0 0
199 0 $dbi->DoQuery($self->{PROMOTESQL},$publish,$cgiparams{$self->{INDEXKEY}});
200 }
201 }
202  
203 =item Copy
204  
205 Performs any copy functionality required.
206  
207 =item CopyAmendments
208  
209 Some plugins need to add or amend field values, or perform additonal
210 functionality before saving and displaying the copied record for edit.
211  
212 =cut
213  
214 0 ▶sub Copy {
Subroutine Copy: not called CC=4 SCAR=30.0
Pod documented
215 0 my $self = shift;
216 0 ▶ return unless(AccessUser($self->{LEVEL}));
Branch: 1 branch
BranchTrueFalseTotal
unless AccessUser($self->{"LEVEL"}) 0 0 0
217 0 $cgiparams{$self->{INDEXKEY}} = $cgiparams{'LISTED'};
218 0 ▶ return unless AuthorCheck($self->{GETSQL},$self->{INDEXKEY},$self->{LEVEL});
Branch: 1 branch
BranchTrueFalseTotal
unless AuthorCheck($self->{"GETSQL"}, $self->{"INDEXKEY"}, $self->{"LEVEL"}) 0 0 0
219  
220 0 CopyAmendments();
221  
222 0 my @fields;
223 0 push @fields, $tvars{data}->{$_} for(@{$self->{addfields}});
224  
225 0 $cgiparams{$self->{INDEXKEY}} = $dbi->IDQuery($self->{ADDSQL},@fields);
226  
227 0 SetCommand($self->{NEXTCOMMAND});
228 }
229  
230 0 ▶sub CopyAmendments {}
Subroutine CopyAmendments: not called CC=1 SCAR=0.0
Pod documented
231  
232 =item Edit
233  
234 Primes the edit page for editing a record.
235  
236 =cut
237  
238 0 ▶sub Edit {
Subroutine Edit: not called CC=4 SCAR=30.0
Pod documented
239 0 my $self = shift;
240 0 ▶ return unless $cgiparams{$self->{INDEXKEY}};
Branch: 1 branch
BranchTrueFalseTotal
unless $Labyrinth::Plugin::Base::cgiparams{$self->{"INDEXKEY"}} 0 0 0
241 0 ▶ return unless AccessUser($self->{LEVEL});
Branch: 1 branch
BranchTrueFalseTotal
unless AccessUser($self->{"LEVEL"}) 0 0 0
242 0 ▶ return unless AuthorCheck($self->{GETSQL},$self->{INDEXKEY});
Branch: 1 branch
BranchTrueFalseTotal
unless AuthorCheck($self->{"GETSQL"}, $self->{"INDEXKEY"}) 0 0 0
243 0 EditAmendments();
244 }
245  
246 =item EditAmendments
247  
248 Some plugins need to add or amend field values, or perform additonal
249 functionality before displaying the record for edit.
250  
251 =cut
252  
253 0 ▶sub EditAmendments {}
Subroutine EditAmendments: not called CC=1 SCAR=0.0
Pod documented
254  
255 =item Save
256  
257 Validates the fields returned from the edit page, and either saves or inserts
258 the record into the database.
259  
260 =cut
261  
262 0 ▶sub Save {
Subroutine Save: not called CC=11 SCAR=48.8
Pod documented
263 0 my $self = shift;
264 0 ▶ return unless(AccessUser($self->{LEVEL}));
Branch: 1 branch
BranchTrueFalseTotal
unless AccessUser($self->{"LEVEL"}) 0 0 0
265 0 ▶ return unless AuthorCheck($self->{GETSQL},$self->{INDEXKEY},$self->{LEVEL});
Branch: 1 branch
BranchTrueFalseTotal
unless AuthorCheck($self->{"GETSQL"}, $self->{"INDEXKEY"}, $self->{"LEVEL"}) 0 0 0
266 0 EditAmendments();
267  
268 0 for(keys %{$self->{fields}}) {
269 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
270 0 elsif($fields{$_}->{html} == 2) { $cgiparams{$_} = CleanTags($cgiparams{$_}) }
271 0 elsif($fields{$_}->{html} == 3) { $cgiparams{$_} = CleanLink($cgiparams{$_}) }
272 }
273  
274 0 ▶ return if FieldCheck($self->{allfields},$self->{mandatory});
Branch: 1 branch
BranchTrueFalseTotal
if FieldCheck($self->{"allfields"}, $self->{"mandatory"}) 0 0 0
275 0 SaveAmendments();
276  
277 0 my @fields;
278 0 ▶ if($cgiparams{$self->{INDEXKEY}}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Labyrinth::Plugin::Base::cgiparams{$self->{'INDEXKEY'}}) { } 0 0 0
279 0 push @fields, $tvars{data}->{$_} for(@{$self->{savefields}});
280 0 $dbi->DoQuery($self->{SAVESQL},@fields,$cgiparams{$self->{INDEXKEY}});
281 } else {
282 0 push @fields, $tvars{data}->{$_} for(@{$self->{addfields}});
283 0 $cgiparams{$self->{INDEXKEY}} = $dbi->IDQuery($self->{ADDSQL},@fields);
284 }
285  
286 0 $tvars{thanks} = 1;
287 }
288  
289 =item SaveAmendments
290  
291 Some plugins need to amend fields, or perform additonal functionality before
292 saving the record.
293  
294 =cut
295  
296 0 ▶sub SaveAmendments {}
Subroutine SaveAmendments: not called CC=1 SCAR=0.0
Pod documented
297  
298 =item Delete
299  
300 Deletes the requested records from the database.
301  
302 =item DeleteItem
303  
304 =item DeleteVerify
305  
306 =cut
307  
308 0 ▶sub Delete {
Subroutine Delete: not called CC=3 SCAR=24.8
Pod documented
309 0 my $self = shift;
310 0 ▶ return unless AccessUser($self->{LEVEL});
Branch: 1 branch
BranchTrueFalseTotal
unless AccessUser($self->{"LEVEL"}) 0 0 0
311 0 my @ids = CGIArray('LISTED');
312 0 ▶ return unless @ids;
Branch: 1 branch
BranchTrueFalseTotal
unless @ids 0 0 0
313 0 my $ids = join(",",@ids);
314  
315 0 $dbi->DoQuery($self->{DELETESQL},{ids=>$ids});
316 }
317  
318 0 ▶sub DeleteVerify {
Subroutine DeleteVerify: not called CC=5 SCAR=34.0
Pod documented
319 0 my $self = shift;
320 0 ▶ return unless AccessUser($self->{LEVEL});
Branch: 1 branch
BranchTrueFalseTotal
unless AccessUser($self->{"LEVEL"}) 0 0 0
321 0 my @ids = CGIArray('LISTED');
322 0 ▶ return unless @ids;
Branch: 1 branch
BranchTrueFalseTotal
unless @ids 0 0 0
323  
324 0 for my $id (@ids) {
325 0 $cgiparams{$self->{INDEXKEY}} = $id;
326 0 ▶ next unless AuthorCheck($self->{GETSQL},$self->{INDEXKEY},$self->{LEVEL});
Branch: 1 branch
BranchTrueFalseTotal
unless AuthorCheck($self->{"GETSQL"}, $self->{"INDEXKEY"}, $self->{"LEVEL"}) 0 0 0
327 0 $dbi->DoQuery($self->{DELETESQL},$cgiparams{$self->{INDEXKEY}});
328 }
329 }
330  
331 0 ▶sub DeleteItem {
Subroutine DeleteItem: not called CC=2 SCAR=17.9
Pod documented
332 0 my $self = shift;
333 0 ▶ return unless(AccessUser($self->{LEVEL}));
Branch: 1 branch
BranchTrueFalseTotal
unless AccessUser($self->{"LEVEL"}) 0 0 0
334 0 $dbi->DoQuery($self->{DELETESQL},{ids=>$cgiparams{$self->{INDEXKEY}}});
335 }
336  
337 4 1;
338  
339 __END__
« Labyrinth/Support.pm ↑ Summary Labyrinth/Request.pm »