<?php
### convert.php ###
// a simple script to convert Brunhilde v2.0 and earlier playlists
// to the new 2.1 format
include("global.php");
// this is where the script decides what to do
if(isset($playlist)) { convert_playlist(); }
else { query_playlist(); }
exit;
// generates a web form that asks the user which playlist to convert
// and in which $base variable each song is located
function query_playlist() {
global $Brunhilde;
global $TITLE;
global $BORDER;
global $BODY;
global $STYLESHEET;
global $TEXT;
global $BACKGROUND;
global $LOGO;
global $MEDIA_DIR;
$cdir = "blah"; // makes the "back to root directory" link appear
// Begin HTML
// imports the logo and standard links at the top of the page
include("header.php");
// to make this script look pretty
echo "<p>";
echo "<TABLE border=0 CELLPADDING=0 CELLSPACING=2 WIDTH=100% $BORDER>\n";
// Form Submission Elements
echo "<FORM NAME=\"convert\" METHOD=\"post\" ACTION=\"convert.php\">\n";
echo "<TBODY>\n<TR>\n<TD>\n";
echo "<TABLE border=0 CELLPADDING=1 CELLSPACING=1 WIDTH=100% $BODY>\n";
echo "<TBODY>\n<TR $TITLE>\n<TH>Playlist Conversion:</TH>\n</TR>\n";
echo "<TR>\n<TD ALIGN=CENTER>\n";
echo "<B>Select the Playlist that you Wish to Convert: </B>\n";
// drop menu with playlist names
echo "<SELECT NAME=\"playlist\">\n";
// generates a list of playlists for the menu
if(isset($Brunhilde)) {
while(list($name) = each($Brunhilde)) {
$name = stripslashes($name);
$playlist_url = rawurlencode(stripslashes($name));
echo "\t<OPTION VALUE=$playlist_url>$name</option>\n";
}
}
echo "</SELECT>\n";
echo "</TD>\n</TR>\n";
echo "<TR>\n<TD ALIGN=\"CENTER\">\n";
echo "<B>Select The Source Containing the Files in Your Playlist </B>\n";
// drop menu with existing base directories
echo "<SELECT NAME=\"base\">\n";
// generates a list of $base directories for the menu
for($i=0; $i < count($MEDIA_DIR); $i++) {
echo "\t<OPTION VALUE=$i>".$MEDIA_DIR[$i][0]."</option>\n";
}
echo "</SELECT>\n";
echo "</TD>\n</TR>\n";
echo "<TR>\n<TD ALIGN=\"CENTER\">\n";
echo "<INPUT TYPE=\"SUBMIT\" VALUE=\"Convert Playlist\">\n";
echo "</form>\n";
echo "</TD>\n</TR>\n</TBODY>\n</TABLE>\n";
echo "</TD>\n</TR>\n</TBODY>\n</TABLE>\n";
// displays the footer at the bottom
include("footer.php");
echo "</body></html>";
}
// adds the selected $base variable to each playlist entry
// converting it to the new v2.1 format
function convert_playlist() {
global $Brunhilde;
global $playlist;
global $base;
$playlist = stripslashes(rawurldecode($playlist));
$playlist_url = rawurlencode($playlist);
$playlist_contents = stripslashes($Brunhilde[$playlist]);
$playlist_array = explode("\n", $playlist_contents);
// tests to make sure the playlist hasn't already been converted
if(eregi("base=", $playlist_array[1])) {
already_converted();
}
// will hold the contents of the new/converted playlist
$playlist_contents = "";
for($i=0; $i<sizeof($playlist_array); $i++) {
$playlist_contents = $playlist_contents.$playlist_array[$i]."\n";
// keeps "\n" from being appended to the last line
if($i == count($playlist_array) -1) {
$playlist_contents = $playlist_contents."&base=$base";
}
else { $playlist_contents = $playlist_contents."&base=$base\n"; }
}
// makes the cookie last until this script is obsolete
$cookie_time = mktime(0, 0, 0, 12, 30, 2032);
// writes the playlists contents to the cookie
setcookie("Brunhilde[$playlist_url]", $playlist_contents, $cookie_time);
// take a look at the new playlist
header("Content-Type: text/html");
header("location: edit.php?playlist=$playlist");
}
function already_converted() {
global $playlist;
echo "<B>The Playlist '".stripslashes(rawurldecode($playlist))."' Has Already Been Converted to the New v2.1 Playlist Format.</B>";
exit;
}