line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Labyrinth::Plugin::Base; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
5558
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
68
|
|
4
|
2
|
|
|
2
|
|
10
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
52
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
7
|
use vars qw($VERSION); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
83
|
|
7
|
|
|
|
|
|
|
$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
|
2
|
|
|
2
|
|
65
|
use Labyrinth::Globals; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
use Labyrinth::DBUtils; |
24
|
|
|
|
|
|
|
use Labyrinth::Session; |
25
|
|
|
|
|
|
|
use Labyrinth::Support; |
26
|
|
|
|
|
|
|
use Labyrinth::Variables; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# ------------------------------------- |
29
|
|
|
|
|
|
|
# Variables |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
my @mandatory; |
32
|
|
|
|
|
|
|
my @allfields; |
33
|
|
|
|
|
|
|
my @savefields; |
34
|
|
|
|
|
|
|
my @addfields; |
35
|
|
|
|
|
|
|
my $INDEXKEY = 'id'; |
36
|
|
|
|
|
|
|
my $ALLSQL = 'AllRecords'; |
37
|
|
|
|
|
|
|
my $SAVESQL = 'SaveRecord'; |
38
|
|
|
|
|
|
|
my $ADDSQL = 'AddRecord'; |
39
|
|
|
|
|
|
|
my $GETSQL = 'GetRecordByID'; |
40
|
|
|
|
|
|
|
my $DELETESQL = 'DeleteRecords'; |
41
|
|
|
|
|
|
|
my $PROMOTESQL = 'PromoteRecord'; |
42
|
|
|
|
|
|
|
my $IMAGEKEY = 'NoImageCheck'; |
43
|
|
|
|
|
|
|
my $LEVEL = EDITOR; |
44
|
|
|
|
|
|
|
my $NEXTCOMMAND = 'home-main'; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
sub new { |
67
|
|
|
|
|
|
|
my $self = shift; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
# create an attributes hash |
70
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
bless $atts, $self; |
91
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
sub Access { my $self = shift; Authorised($self->{LEVEL}) } |
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
|
|
|
|
|
|
|
sub ImageCheck { return 0 } |
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
|
|
|
|
|
|
|
sub Admin { |
138
|
|
|
|
|
|
|
my $self = shift; |
139
|
|
|
|
|
|
|
return unless(AccessUser($self->{LEVEL})); |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
if($cgiparams{doaction}) { |
142
|
|
|
|
|
|
|
if($cgiparams{doaction} eq 'Delete') { Delete() } |
143
|
|
|
|
|
|
|
elsif($cgiparams{doaction} eq 'Copy') { Copy() } |
144
|
|
|
|
|
|
|
elsif($cgiparams{doaction} eq 'Promote') { Promote() } |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
my $where = SearchSQL(); |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
my @rows = $dbi->GetQuery('hash',$self->{ALLSQL},{where=>$where}); |
150
|
|
|
|
|
|
|
$tvars{data} = \@rows if(@rows); |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
AdminAmendments(); |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
sub SearchSQL { return '' } |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
sub AdminAmendments {} |
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
|
|
|
|
|
|
|
sub Add { |
171
|
|
|
|
|
|
|
my $self = shift; |
172
|
|
|
|
|
|
|
return unless AccessUser($self->{LEVEL}); |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
AddAmendments(); |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
$tvars{data} = $self->{adddata}; |
177
|
|
|
|
|
|
|
} |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
sub AddAmendments {} |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=item Promote |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
Promotes the reference item through to the next stage of the workflow. |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=cut |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
sub Promote { |
188
|
|
|
|
|
|
|
my $self = shift; |
189
|
|
|
|
|
|
|
return unless AccessUser($self->{LEVEL}); |
190
|
|
|
|
|
|
|
my @ids = CGIArray('LISTED'); |
191
|
|
|
|
|
|
|
return unless @ids; |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
for my $id (@ids) { |
194
|
|
|
|
|
|
|
$cgiparams{$self->{INDEXKEY}} = $id; |
195
|
|
|
|
|
|
|
next unless AuthorCheck($self->{GETSQL},$self->{INDEXKEY},$self->{LEVEL}); |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
my $publish = $tvars{data}->{publish} + 1; |
198
|
|
|
|
|
|
|
next unless($publish < 5); |
199
|
|
|
|
|
|
|
$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
|
|
|
|
|
|
|
sub Copy { |
215
|
|
|
|
|
|
|
my $self = shift; |
216
|
|
|
|
|
|
|
return unless(AccessUser($self->{LEVEL})); |
217
|
|
|
|
|
|
|
$cgiparams{$self->{INDEXKEY}} = $cgiparams{'LISTED'}; |
218
|
|
|
|
|
|
|
return unless AuthorCheck($self->{GETSQL},$self->{INDEXKEY},$self->{LEVEL}); |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
CopyAmendments(); |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
my @fields; |
223
|
|
|
|
|
|
|
push @fields, $tvars{data}->{$_} for(@{$self->{addfields}}); |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
$cgiparams{$self->{INDEXKEY}} = $dbi->IDQuery($self->{ADDSQL},@fields); |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
SetCommand($self->{NEXTCOMMAND}); |
228
|
|
|
|
|
|
|
} |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
sub CopyAmendments {} |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
=item Edit |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
Primes the edit page for editing a record. |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
=cut |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
sub Edit { |
239
|
|
|
|
|
|
|
my $self = shift; |
240
|
|
|
|
|
|
|
return unless $cgiparams{$self->{INDEXKEY}}; |
241
|
|
|
|
|
|
|
return unless AccessUser($self->{LEVEL}); |
242
|
|
|
|
|
|
|
return unless AuthorCheck($self->{GETSQL},$self->{INDEXKEY}); |
243
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
sub EditAmendments {} |
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
|
|
|
|
|
|
|
sub Save { |
263
|
|
|
|
|
|
|
my $self = shift; |
264
|
|
|
|
|
|
|
return unless(AccessUser($self->{LEVEL})); |
265
|
|
|
|
|
|
|
return unless AuthorCheck($self->{GETSQL},$self->{INDEXKEY},$self->{LEVEL}); |
266
|
|
|
|
|
|
|
EditAmendments(); |
267
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
for(keys %{$self->{fields}}) { |
269
|
|
|
|
|
|
|
if($fields{$_}->{html} == 1) { $cgiparams{$_} = CleanHTML($cgiparams{$_}) } |
270
|
|
|
|
|
|
|
elsif($fields{$_}->{html} == 2) { $cgiparams{$_} = CleanTags($cgiparams{$_}) } |
271
|
|
|
|
|
|
|
elsif($fields{$_}->{html} == 3) { $cgiparams{$_} = CleanLink($cgiparams{$_}) } |
272
|
|
|
|
|
|
|
} |
273
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
return if FieldCheck($self->{allfields},$self->{mandatory}); |
275
|
|
|
|
|
|
|
SaveAmendments(); |
276
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
my @fields; |
278
|
|
|
|
|
|
|
if($cgiparams{$self->{INDEXKEY}}) { |
279
|
|
|
|
|
|
|
push @fields, $tvars{data}->{$_} for(@{$self->{savefields}}); |
280
|
|
|
|
|
|
|
$dbi->DoQuery($self->{SAVESQL},@fields,$cgiparams{$self->{INDEXKEY}}); |
281
|
|
|
|
|
|
|
} else { |
282
|
|
|
|
|
|
|
push @fields, $tvars{data}->{$_} for(@{$self->{addfields}}); |
283
|
|
|
|
|
|
|
$cgiparams{$self->{INDEXKEY}} = $dbi->IDQuery($self->{ADDSQL},@fields); |
284
|
|
|
|
|
|
|
} |
285
|
|
|
|
|
|
|
|
286
|
|
|
|
|
|
|
$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
|
|
|
|
|
|
|
sub SaveAmendments {} |
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
|
|
|
|
|
|
|
sub Delete { |
309
|
|
|
|
|
|
|
my $self = shift; |
310
|
|
|
|
|
|
|
return unless AccessUser($self->{LEVEL}); |
311
|
|
|
|
|
|
|
my @ids = CGIArray('LISTED'); |
312
|
|
|
|
|
|
|
return unless @ids; |
313
|
|
|
|
|
|
|
my $ids = join(",",@ids); |
314
|
|
|
|
|
|
|
|
315
|
|
|
|
|
|
|
$dbi->DoQuery($self->{DELETESQL},{ids=>$ids}); |
316
|
|
|
|
|
|
|
} |
317
|
|
|
|
|
|
|
|
318
|
|
|
|
|
|
|
sub DeleteVerify { |
319
|
|
|
|
|
|
|
my $self = shift; |
320
|
|
|
|
|
|
|
return unless AccessUser($self->{LEVEL}); |
321
|
|
|
|
|
|
|
my @ids = CGIArray('LISTED'); |
322
|
|
|
|
|
|
|
return unless @ids; |
323
|
|
|
|
|
|
|
|
324
|
|
|
|
|
|
|
for my $id (@ids) { |
325
|
|
|
|
|
|
|
$cgiparams{$self->{INDEXKEY}} = $id; |
326
|
|
|
|
|
|
|
next unless AuthorCheck($self->{GETSQL},$self->{INDEXKEY},$self->{LEVEL}); |
327
|
|
|
|
|
|
|
$dbi->DoQuery($self->{DELETESQL},$cgiparams{$self->{INDEXKEY}}); |
328
|
|
|
|
|
|
|
} |
329
|
|
|
|
|
|
|
} |
330
|
|
|
|
|
|
|
|
331
|
|
|
|
|
|
|
sub DeleteItem { |
332
|
|
|
|
|
|
|
my $self = shift; |
333
|
|
|
|
|
|
|
return unless(AccessUser($self->{LEVEL})); |
334
|
|
|
|
|
|
|
$dbi->DoQuery($self->{DELETESQL},{ids=>$cgiparams{$self->{INDEXKEY}}}); |
335
|
|
|
|
|
|
|
} |
336
|
|
|
|
|
|
|
|
337
|
|
|
|
|
|
|
1; |
338
|
|
|
|
|
|
|
|
339
|
|
|
|
|
|
|
__END__ |