Apache-MP3-Skin
view release on metacpan or search on metacpan
if (param('Add All to Playlist')) {
my %seen;
@playlist = grep !$seen{$_}++,(@playlist,@{$self->find_mp3s});
$changed++;
}
if (param('Add to Playlist')) {
my $dir = dirname($r->uri);
my @new = param('file') or return HTTP_NO_CONTENT;
my %seen;
# The line below is the only line that's different than SUPER::process_playlist
@playlist = grep !$seen{$_}++,(@playlist,map {(m/^\//) ? "$_" : "$dir/$_" } @new);
$changed++;
}
if (param('Play Selected') and param('playlist')) {
my @uris = param('file') or return HTTP_NO_CONTENT;
return $self->send_playlist(\@uris);
}
if (param('Shuffle All') and param('playlist')) {
my $r = $self->r;
if (param('Shuffle Selected')) {
return HTTP_NO_CONTENT unless my @files = param('file');
$self->shuffle(\@files);
my $uri = dirname($r->uri);
$self->send_playlist([map { (m/^\//) ? "$_" : "$uri/$_" } @files]);
return OK;
}
return $self->SUPER::run();
}
# override the list_directory in Apache::MP3, see if there's a skin file.
# if there's a skin file, we'll handle it otherwise pass it back (SUPER)
# to Apache::MP3
sub list_directory {
my $self = shift;
my $script_tag = "<SCRIPT language=\"JavaScript\" src=\"".$self->default_dir."/apache_mp3_skin.js\"></SCRIPT>";
$page =~ s!(</HEAD[^>]*>)!$script_tag$1!oi;
$page =~ s!(<BODY[^>]*>)!$1<FORM NAME="apache_mp3_skin">!oi;
$page =~ s!(</BODY[^>]*>)!</FORM>$1!oi;
print $page;
} else {
return $self->SUPER::list_directory($dir);
}
return OK;
}
sub set_template_params {
my ($self, $template, $dir, $directories, $mp3s) = @_;
my @inner_loops;
in any JavaScript that you have.
=head1 METHODS
Apache::MP3::Skin overrides the following methods:
=over 4
=item list_directory()
Checks to see if this is a skin file, if not hands off to SUPER::list_directory().
If there is a skin files, gets it, processes it, adds in the <SCRIPT> and <FORM>
tags and the prints it.
=item run()
Looks for the "Shuffle Selected" parameter and handles the request if there is one.
Otherwise, sends to SUPER::run().
=item process_playlist()
Same as SUPER::process_playlist with only one line changed. If there is an 'Add to
Playlist' param. file param values that begin with '/' are not prepended with the
current uri and are treated as document root relative.
=back
And adds the following:
=over 4
=item set_template_params()
( run in 1.271 second using v1.01-cache-2.11-cpan-49f99fa48dc )