line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Labyrinth::Plugin::MP3s; |
2
|
|
|
|
|
|
|
|
3
|
5
|
|
|
5
|
|
76394
|
use warnings; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
179
|
|
4
|
5
|
|
|
5
|
|
52
|
use strict; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
179
|
|
5
|
|
|
|
|
|
|
|
6
|
5
|
|
|
5
|
|
22
|
use vars qw($VERSION); |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
316
|
|
7
|
|
|
|
|
|
|
$VERSION = '1.01'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 NAME |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
Labyrinth::Plugin::MP3s - MP3 plugin handler for Labyrinth |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 DESCRIPTION |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
Contains all the MP3 management handling functionality for the Labyrinth Web |
16
|
|
|
|
|
|
|
Framework. |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=cut |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# ------------------------------------- |
21
|
|
|
|
|
|
|
# Library Modules |
22
|
|
|
|
|
|
|
|
23
|
5
|
|
|
5
|
|
25
|
use base qw(Labyrinth::Plugin::Base); |
|
5
|
|
|
|
|
21
|
|
|
5
|
|
|
|
|
4962
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
use Labyrinth::DBUtils; |
26
|
|
|
|
|
|
|
use Labyrinth::MLUtils; |
27
|
|
|
|
|
|
|
use Labyrinth::Support; |
28
|
|
|
|
|
|
|
use Labyrinth::Variables; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# ------------------------------------- |
31
|
|
|
|
|
|
|
# Variables |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# type: 0 = optional, 1 = mandatory |
34
|
|
|
|
|
|
|
# html: 0 = none, 1 = text, 2 = textarea |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
my %cat_fields = ( |
37
|
|
|
|
|
|
|
mp3catid => { type => 0, html => 0 }, |
38
|
|
|
|
|
|
|
category => { type => 1, html => 1 }, |
39
|
|
|
|
|
|
|
); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
my (@cat_mandatory,@cat_allfields); |
42
|
|
|
|
|
|
|
for(keys %cat_fields) { |
43
|
|
|
|
|
|
|
push @cat_mandatory, $_ if($cat_fields{$_}->{type}); |
44
|
|
|
|
|
|
|
push @cat_allfields, $_; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
my %fields = ( |
48
|
|
|
|
|
|
|
mp3id => { type => 0, html => 0 }, |
49
|
|
|
|
|
|
|
mp3catid => { type => 1, html => 1 }, |
50
|
|
|
|
|
|
|
orderno => { type => 1, html => 1 }, |
51
|
|
|
|
|
|
|
source => { type => 1, html => 1 }, |
52
|
|
|
|
|
|
|
tracks => { type => 0, html => 2 }, |
53
|
|
|
|
|
|
|
notes => { type => 0, html => 2 }, |
54
|
|
|
|
|
|
|
publish => { type => 1, html => 1 }, |
55
|
|
|
|
|
|
|
); |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
my (@mandatory,@allfields); |
58
|
|
|
|
|
|
|
for(keys %fields) { |
59
|
|
|
|
|
|
|
push @mandatory, $_ if($fields{$_}->{type}); |
60
|
|
|
|
|
|
|
push @allfields, $_; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
my @savefields = qw(mp3catid orderno source tracks notes publish); |
64
|
|
|
|
|
|
|
my $INDEXKEY = 'mp3id'; |
65
|
|
|
|
|
|
|
my $ALLSQL = 'AllMP3s'; |
66
|
|
|
|
|
|
|
my $SAVESQL = 'SaveMP3'; |
67
|
|
|
|
|
|
|
my $ADDSQL = 'AddMP3'; |
68
|
|
|
|
|
|
|
my $GETSQL = 'GetMP3ByID'; |
69
|
|
|
|
|
|
|
my $LEVEL = ADMIN; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
my %adddata = ( |
72
|
|
|
|
|
|
|
mp3id => 0, |
73
|
|
|
|
|
|
|
mp3catid => 1, |
74
|
|
|
|
|
|
|
orderno => 999, |
75
|
|
|
|
|
|
|
source => '', |
76
|
|
|
|
|
|
|
tracks => '', |
77
|
|
|
|
|
|
|
notes => '', |
78
|
|
|
|
|
|
|
publish => 1, |
79
|
|
|
|
|
|
|
); |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
# ------------------------------------- |
82
|
|
|
|
|
|
|
# The Subs |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head1 PUBLIC INTERFACE METHODS |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=over 4 |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=item * List |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
Lists all the publicly visable categories and MP3s. |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=back |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=cut |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub List { |
97
|
|
|
|
|
|
|
# get list for current realm |
98
|
|
|
|
|
|
|
my @cats = $dbi->GetQuery('hash','GetMP3Cats'); |
99
|
|
|
|
|
|
|
$tvars{cats} = \@cats; |
100
|
|
|
|
|
|
|
my @rows = $dbi->GetQuery('hash','GetMP3s'); |
101
|
|
|
|
|
|
|
$tvars{mp3s} = \@rows; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head1 ADMIN INTERFACE METHODS |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head2 MP3s Methods |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=over 4 |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=item * Admin |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
List, and manages, all the MP3s available within the system. |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=item * Add |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
Add a new MP3. |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=item * Edit |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Edit details of an existing MP3. |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=item * ReOrder |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
Re-order MP3s within a category. |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=item * Promote |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
Publish, Archive, etc MP3s. |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=item * Delete |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
Delete an MP3 from the system. |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=item * Save |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
Validates the fields returned from the edit page, and either saves or inserts |
137
|
|
|
|
|
|
|
the record into the database. |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
It should be noted that the actual media file upload data is saved in the |
140
|
|
|
|
|
|
|
'images' table. This is for legacy reasons and the table *should* have been |
141
|
|
|
|
|
|
|
renamed, perhaps to 'media', but I've never gotten around to it. |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=back |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=cut |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
sub Admin { |
148
|
|
|
|
|
|
|
return unless(AccessUser($LEVEL)); |
149
|
|
|
|
|
|
|
if($cgiparams{doaction}) { |
150
|
|
|
|
|
|
|
if($cgiparams{doaction} eq 'ReOrder' ) { ReOrder(); } |
151
|
|
|
|
|
|
|
if($cgiparams{doaction} eq 'Promote' ) { Promote(); } |
152
|
|
|
|
|
|
|
if($cgiparams{doaction} eq 'Delete' ) { Delete(); } |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
my @rows = $dbi->GetQuery('hash','AllMP3s'); |
155
|
|
|
|
|
|
|
for my $row (@rows) { |
156
|
|
|
|
|
|
|
$row->{publish} = PublishState($row->{publish}); |
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
$tvars{data} = \@rows if(@rows); |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
sub Add { |
162
|
|
|
|
|
|
|
return unless AccessUser($LEVEL); |
163
|
|
|
|
|
|
|
$tvars{data}{ddcats} = CatSelect(); |
164
|
|
|
|
|
|
|
$tvars{data}{ddpublish} = PublishSelect($tvars{data}{publish},1); |
165
|
|
|
|
|
|
|
} |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
sub Edit { |
168
|
|
|
|
|
|
|
return unless AccessUser($LEVEL); |
169
|
|
|
|
|
|
|
return unless AuthorCheck($GETSQL,$INDEXKEY,$LEVEL); |
170
|
|
|
|
|
|
|
$tvars{data}{ddcats} = CatSelect($tvars{data}{mp3catid}); |
171
|
|
|
|
|
|
|
$tvars{data}{ddpublish} = PublishSelect($tvars{data}{publish},1); |
172
|
|
|
|
|
|
|
} |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
sub ReOrder { |
175
|
|
|
|
|
|
|
my @rows = $dbi->GetQuery('hash',$ALLSQL); |
176
|
|
|
|
|
|
|
for my $row (@rows) { |
177
|
|
|
|
|
|
|
next if($cgiparams{"ORDER$row->{mp3id}"} == $row->{orderno}); |
178
|
|
|
|
|
|
|
$dbi->DoQuery('ReOrderMP3s',$cgiparams{"ORDER$row->{mp3id}"},$row->{mp3id}); |
179
|
|
|
|
|
|
|
} |
180
|
|
|
|
|
|
|
} |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
sub Promote { |
183
|
|
|
|
|
|
|
my @ids = CGIArray('LISTED'); |
184
|
|
|
|
|
|
|
next unless(@ids); |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
my @rows = $dbi->GetQuery('hash',$ALLSQL); |
187
|
|
|
|
|
|
|
my %ids = map {$_->{mp3id} => $_->{publish}} @rows; |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
for my $id (@ids) { |
190
|
|
|
|
|
|
|
next unless(defined $ids{$id} && $ids{$id} < 4); |
191
|
|
|
|
|
|
|
$dbi->DoQuery('PromoteMP3s',($ids{$id} + 1),$id); |
192
|
|
|
|
|
|
|
} |
193
|
|
|
|
|
|
|
} |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
sub Delete { |
196
|
|
|
|
|
|
|
my @ids = CGIArray('LISTED'); |
197
|
|
|
|
|
|
|
return unless @ids; |
198
|
|
|
|
|
|
|
$dbi->DoQuery('DeleteMP3s',{ids=>join(",",@ids)}); |
199
|
|
|
|
|
|
|
} |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
sub Save { |
202
|
|
|
|
|
|
|
return unless AccessUser($LEVEL); |
203
|
|
|
|
|
|
|
return unless AuthorCheck($GETSQL,$INDEXKEY,$LEVEL); |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
for(keys %fields) { |
206
|
|
|
|
|
|
|
if($fields{$_}->{html} == 1) { $cgiparams{$_} = CleanHTML($cgiparams{$_}) } |
207
|
|
|
|
|
|
|
elsif($fields{$_}->{html} == 2) { $cgiparams{$_} = CleanTags($cgiparams{$_}) } |
208
|
|
|
|
|
|
|
elsif($fields{$_}->{html} == 3) { $cgiparams{$_} = CleanMP3s($cgiparams{$_}) } |
209
|
|
|
|
|
|
|
} |
210
|
|
|
|
|
|
|
return if FieldCheck(\@allfields,\@mandatory); |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
# TODO upload Media file |
213
|
|
|
|
|
|
|
if($cgiparams{mp3file}) { |
214
|
|
|
|
|
|
|
my ($imageid,$imagelink) = SaveImageFile( |
215
|
|
|
|
|
|
|
param => "FILEUPLOAD", |
216
|
|
|
|
|
|
|
stock => 'mp3s' |
217
|
|
|
|
|
|
|
); |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
# TODO |
220
|
|
|
|
|
|
|
} |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
my @fields = map {$tvars{data}->{$_}} @savefields; |
223
|
|
|
|
|
|
|
if( $cgiparams{$INDEXKEY}) { $dbi->DoQuery($SAVESQL,@fields,$cgiparams{$INDEXKEY}); } |
224
|
|
|
|
|
|
|
else { $cgiparams{$INDEXKEY} = $dbi->IDQuery( $ADDSQL,@fields); } |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
$tvars{thanks} = 1; |
227
|
|
|
|
|
|
|
} |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
=head2 Category Admin |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
=over 4 |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
=item * CatAdmin |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
List, and manages, all the MP3 categories within the system. |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
=item * CatEdit |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
Edit details of an existing MP3 category. |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
=item * CatDelete |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
Delete an MP3 category from the system. |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
=item * CatSave |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
Validates the fields returned from the edit page, and either saves or inserts |
248
|
|
|
|
|
|
|
the record into the database. |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
Note that there is no CatAdd, as this is purely a blank form, submitted to |
251
|
|
|
|
|
|
|
CatSave method. |
252
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
=item * CatSelect |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
Provides a drop down list of the currently available MP3 categories. |
256
|
|
|
|
|
|
|
=back |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
=cut |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
sub CatAdmin { |
261
|
|
|
|
|
|
|
return unless(AccessUser($LEVEL)); |
262
|
|
|
|
|
|
|
if($cgiparams{doaction}) { |
263
|
|
|
|
|
|
|
if($cgiparams{doaction} eq 'Delete' ) { CatDelete(); } |
264
|
|
|
|
|
|
|
} |
265
|
|
|
|
|
|
|
my @rows = $dbi->GetQuery('hash','GetAllMP3Cats'); |
266
|
|
|
|
|
|
|
$tvars{data} = \@rows if(@rows); |
267
|
|
|
|
|
|
|
} |
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
sub CatEdit { |
270
|
|
|
|
|
|
|
return unless AccessUser($LEVEL); |
271
|
|
|
|
|
|
|
return unless AuthorCheck('GetMP3CatByID','mp3catid',$LEVEL); |
272
|
|
|
|
|
|
|
} |
273
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
sub CatDelete { |
275
|
|
|
|
|
|
|
return unless AccessUser($LEVEL); |
276
|
|
|
|
|
|
|
my @ids = CGIArray('LISTED'); |
277
|
|
|
|
|
|
|
return unless @ids; |
278
|
|
|
|
|
|
|
$dbi->DoQuery('DeleteMP3Cats',{ids=>join(",",@ids)}); |
279
|
|
|
|
|
|
|
$dbi->DoQuery('DeleteMP3Categories',{ids=>join(",",@ids)}); |
280
|
|
|
|
|
|
|
} |
281
|
|
|
|
|
|
|
|
282
|
|
|
|
|
|
|
sub CatSave { |
283
|
|
|
|
|
|
|
return unless AccessUser($LEVEL); |
284
|
|
|
|
|
|
|
return unless AuthorCheck('GetMP3CatByID','mp3catid',$LEVEL); |
285
|
|
|
|
|
|
|
for(keys %cat_fields) { |
286
|
|
|
|
|
|
|
if($cat_fields{$_}->{html} == 1) { $cgiparams{$_} = CleanHTML($cgiparams{$_}) } |
287
|
|
|
|
|
|
|
elsif($cat_fields{$_}->{html} == 2) { $cgiparams{$_} = CleanTags($cgiparams{$_}) } |
288
|
|
|
|
|
|
|
elsif($cat_fields{$_}->{html} == 3) { $cgiparams{$_} = CleanMP3s($cgiparams{$_}) } |
289
|
|
|
|
|
|
|
} |
290
|
|
|
|
|
|
|
return if FieldCheck(\@cat_allfields,\@cat_mandatory); |
291
|
|
|
|
|
|
|
if($cgiparams{mp3catid}) { $dbi->DoQuery('SaveMP3Category',$tvars{data}->{category},$cgiparams{mp3catid}); } |
292
|
|
|
|
|
|
|
else { $cgiparams{mp3catid} = $dbi->IDQuery('AddMP3Category',$tvars{data}->{category}); } |
293
|
|
|
|
|
|
|
$tvars{thanks} = 1; |
294
|
|
|
|
|
|
|
} |
295
|
|
|
|
|
|
|
|
296
|
|
|
|
|
|
|
sub CatSelect { |
297
|
|
|
|
|
|
|
my $opt = shift; |
298
|
|
|
|
|
|
|
my @rows = $dbi->GetQuery('hash','GetAllMP3Cats'); |
299
|
|
|
|
|
|
|
DropDownRows($opt,'mp3catid','mp3catid','category',@rows); |
300
|
|
|
|
|
|
|
} |
301
|
|
|
|
|
|
|
|
302
|
|
|
|
|
|
|
1; |
303
|
|
|
|
|
|
|
|
304
|
|
|
|
|
|
|
__END__ |