<?php
session_start();
//The config file may not exist yet.
@include_once( getcwd()."/includes/configuration.php" );
//all of these files should exist
include_once( getcwd()."/includes/misc.php" );
include_once( getcwd()."/includes/login.php" );
include_once( getcwd()."/layout/header.php" );
include_once( getcwd()."/art/amazon.php" );
require_once( getcwd()."/id3/getid3.php");
//this is likely because of no config file. It'll kick you to the admin page
if(!isset($backend))
{
$self = $_SERVER["PHP_SELF"];
$selfArray = explode("/", $self);
$numSelf = count($selfArray);
$numSelf--;
for($i = 0; $i < $numSelf; $i++)
{
$phpSelf .= $selfArray[$i]."/";
}
echo( "
<script>
location=\"http://".$_SERVER["SERVER_NAME"].$phpSelf."admin.php\";
</script>
");
}
elseif($backend == "mysql")
{
connect_to($dbhost, $dbuser, $dbpass, $dbname);
}
//checking for the ffmpeg extension
$extension = "ffmpeg";
$extension_soname = $extension . "." . PHP_SHLIB_SUFFIX;
$extension_fullname = PHP_EXTENSION_DIR . "/" . $extension_soname;
// load extension
if(!extension_loaded($extension)) {
@dl($extension_soname) or ($noFFMPEG = true);
}
//a little cleaning up/security
if(isset($_GET["dir"]))
{
$displayDir = $_GET["dir"];
$displayDir = str_replace("..", "", $displayDir);
$displayDir = str_replace("//", "/", $displayDir);
$displayDir = str_replace("\\", "", $displayDir);
}
else
{
$displayDir = "";
}
//setup our variables
$musicDir = $musicDir.$displayDir."/";
$displayDirEncoded = customEncodeURL($displayDir);
//do the scan
@$dirArray = scandir($musicDir, 0);
killcifs($musicDir);
//setup more variables
$filei = 0;
$diri = 0;
$imagei = 0;
//parse the scan
foreach($dirArray as $single)
{
if(is_file($musicDir.$single) && !bannedFiles($single))
{
$fnamearray = explode(".", $single);
$num = count($fnamearray);
$ftype = strtolower($fnamearray[$num-1]);
//images
if($ftype == "jpg" || $ftype == "gif" || $ftype == "png" || $ftype == "bmp")
{
$imageList[$imagei] = $single;
$imagei++;
}
elseif($ftype == "m3u" || $ftype == "sfv" || $ftype == "cue")
{
//do nothing
}
else
{
$fileList[$filei] = $single;
$filei++;
}
}
elseif(is_dir($musicDir.$single) && $single != "." && $single != "..")
{
$dirList[$diri] = $single;
$diri++;
}
elseif(is_link($musicDir.$single))
{
$dirList[$diri] = $single;
$diri++;
}
}
echo( "<center>[ " );
$displayArray = explode("/", $displayDir);
if($_GET["bytag"] == "1")
{
$contentString = "Contents of <a href=\"index.php?dir=/&bytag=1\">/</a>";
}
else
{
$contentString = "Contents of <a href=\"index.php?dir=/\">/</a>";
}
foreach( $displayArray as $singleDisplay)
{
if($singleDisplay != "")
{
$accumString .= customEncodeURL($singleDisplay);
if($_GET["bytag"] == "1")
{
$contentString .= " · <a href=\"index.php?dir=/$accumString&bytag=1\">$singleDisplay</a>";
}
else
{
$contentString .= " · <a href=\"index.php?dir=/$accumString\">$singleDisplay</a>";
}
$accumString .= "/";
}
}
if($displayDir != "" || $musicDir != "/")
{
echo( $contentString );
}
else
{
echo( "Contents of <a href=\"index.php?dir=/\">/</a>" );
}
echo(" | <a href=\"recurse.php?dir=$displayDirEncoded\">Play</a> · <a href=\"embedRecurse.php?dir=$displayDirEncoded\">Embedded</a>" );
if(!$noFFMPEG)
{
echo (" · <a href=\"operations/convertRecurse.php?dir=$displayDirEncoded\">Convert</a>" );
}
if($backend == "mysql")
{
echo( " · <a href=\"operations/crawl.php?dir=$displayDirEncoded\">Crawl</a>" );
}
if(file_exists("/usr/bin/detox"))
{
echo( " · <a href=\"operations/detox.php?dir=$displayDirEncoded\">Detox</a>" );
}
echo( "]</center>" );
echo( "Showing $filei files and $diri directories<br>" );
if(isset($dirList))
{
echo( "<table cellpadding=\"0\" cellspacing=\"5\" width=\"100%\" class=\"tableborder\">
<tr><td>
<table cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">
<tr class=\"tableheader\"><td colspan=\"7\"><center><h3>Subdirectories</h3></center></td></tr>" );
foreach($dirList as $single)
{
$numDirs = numDirs($musicDir.$single);
$numFiles = numFiles($musicDir.$single);
if($numDirs > 0)
{
$numDirs = $numDirs." subdirectories";
}
else
{
$numDirs = "";
}
if($numFiles > 0)
{
$numFiles = $numFiles." songs";
}
else
{
$numFiles = "";
}
$singleEncoded = customEncodeURL($single);
$mkTime = mktime();
$mkTime = $mkTime - (7*24*60*60);
$aWeekAgo = date("Y-m-d H:m:s", $mkTime);
if($aWeekAgo < date("Y-m-d H:m:s", @filectime($musicDir.$single)))
{
$new = " <font color=\"red\"><b>New!</b></font>";
}
else
{
$new = "";
}
if($_GET["bytag"] == "1")
{
if($displayDir == "/")
{
echo( "<tr class=\"hovertr\"><td width=\"10%\"> </td><td><a href=\"index.php?dir=$displayDirEncoded$singleEncoded&bytag=1\">$single$new</a> </td><td colspan=\"2\"><b>$numFiles</b></td><td colspan=\"3\"><b>$numDirs</b></td></tr>" );
}
else
{
echo( "<tr class=\"hovertr\"><td width=\"10%\"> </td><td><a href=\"index.php?dir=$displayDirEncoded/$singleEncoded&bytag=1\">$single$new</a> </td><td colspan=\"2\"><b>$numFiles</b></td><td colspan=\"3\"><b>$numDirs</b></td></tr>" );
}
}
else
{
if($displayDir == "/")
{
echo( "<tr class=\"hovertr\"><td width=\"10%\"> </td><td><a href=\"index.php?dir=$displayDirEncoded$singleEncoded\">$single$new</a> </td><td colspan=\"2\"><b>$numFiles</b></td><td colspan=\"3\"><b>$numDirs</b></td></tr>" );
}
else
{
echo( "<tr class=\"hovertr\"><td width=\"10%\"> </td><td><a href=\"index.php?dir=$displayDirEncoded/$singleEncoded\">$single$new</a> </td><td colspan=\"2\"><b>$numFiles</b></td><td colspan=\"3\"><b>$numDirs</b></td></tr>" );
}
}
}
echo( "
</table>
</td></tr>
</table><p> </p>" );
}
if(isset($fileList))
{
if($backend == "mysql")
{
$sql0 = "DELETE FROM `files` WHERE `Directory` = '$musicDir'";
@mysql_query($sql0);
}
echo( "<table cellpadding=\"0\" cellspacing=\"5\" width=\"100%\" class=\"tableborder\">
<tr><td>
<table cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">
<tr class=\"tableheader\"><td colspan=\"3\"><center><h3>Songs</h3></center></td></tr>" );
foreach($fileList as $single)
{
if($backend == "mysql")
{
$sql1 = "INSERT INTO `files` (`Directory`, `File`) VALUES ('$musicDir', '$single')";
@mysql_query($sql1);
}
$singleEncoded = customEncodeURL($single);
$fnamearray = explode(".", $single);
$num = count($fnamearray);
$ftype = strtolower($fnamearray[$num-1]);
if($ftype != "flv" && $ftype != "mov")
{
$getID3 = new getID3;
$ThisFileInfo = $getID3->analyze($musicDir.$single);
getid3_lib::CopyTagsToComments($ThisFileInfo);
}
$track = "".$ThisFileInfo['id3v2']['comments']['title'][0]."";
$trackNum = "".$ThisFileInfo['id3v2']['comments']['track_number'][0]."";
$album = "".$ThisFileInfo['id3v2']['comments']['album'][0]."";
$artist = "".$ThisFileInfo['id3v2']['comments']['artist'][0]."";
if($track != "")
{
//do nothing
}
else
{
$track = $single;
}
if($_GET["bytag"] == "1")
{
$single = $trackNum." ".$track;
}
echo( "<tr class=\"hovertr\"><td width=\"10%\"> </td><td><a href=\"play.php?dir=$displayDirEncoded&file=$singleEncoded\">$single</a>" );
$mkTime = mktime();
$mkTime = $mkTime - (7*24*60*60);
$aWeekAgo = date("Y-m-d H:m:s", $mkTime);
if($aWeekAgo < date("Y-m-d H:m:s", @filectime($musicDir.$single)))
{
echo( " <font color=\"red\"><b>New!</b></font>" );
}
echo( "</td><td align=\"right\">[<a href=\"info.php?dir=$displayDirEncoded&file=$singleEncoded\">Info</a>] [<a href=\"download.php?dir=$displayDirEncoded&file=$singleEncoded\">Download</a>]");
if($ftype == "mp3" || $ftype == "flv" || $ftype == "mp4" || $ftype == "ogg" || $ftype == "jpg" || $ftype == "gif" || $ftype == "png" || $ftype == "bmp" || $ftype == "nfo" || $ftype == "txt" || $ftype == "log")
{
echo( " [<a href=\"embed.php?dir=$displayDirEncoded&file=$singleEncoded\">Embedded</a>]" );
}
else
{
echo( " [Embedded]" );
}
echo( " [<a href=\"operations/index.php?dir=$displayDirEncoded&file=$singleEncoded\">Operations</a>]</td></tr>" );
}
echo( "</table>
</td></tr>
</table><p> </p>" );
}
//display any images we find
if(isset($imageList))
{
echo( "<table cellpadding=\"0\" cellspacing=\"5\" width=\"100%\">
<tr><td>
<table cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">
<tr class=\"tableheader\"><td colspan=\"3\"><center><h3>Images</h3></center></td></tr>" );
$i = 1;
foreach($imageList as $single)
{
$singleEncoded = customEncodeURL($single);
if($i == 1)
{
echo( "<tr>" );
}
echo( "<td><a href=\"embed.php?dir=$displayDirEncoded&file=$singleEncoded\"><img src=\"$baseURL"."music$displayDir/$single\" width=\"150\" height=\"150\"></a></td>" );
if($i == 3)
{
echo( "</tr>" );
$i = 0;
}
$i++;
}
echo( "</table>
</td></tr>
</table><p> </p>" );
}
//if Amazon Art is enabled, this is where it will be displayed
if($pullAmazonArt == "true" && $album != "" && $artist != "" && !isset($imageList))
{
echo( "<table cellpadding=\"0\" cellspacing=\"5\" width=\"100%\">
<tr><td>
<table cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">
<tr class=\"tableheader\"><td colspan=\"3\"><center><h3>Images From Amazon</h3></center></td></tr>" );
echo( "<tr><td>".checkAmazon($artist." ".$album)."</td></tr></table>
</td></tr>
</table><p> </p>" );
}
?>