/*
tracks.php
###########################################################################
Copyright (C) 2004 by Harper Reed
web: http://www.nata2.org
email: nata2info at nata2.org
###########################################################################
LICENSE
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License (GPL)
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
To read the license please visit http://www.gnu.org/copyleft/gpl.html
###########################################################################
*/
//Config
$filename = "tracks.txt";
//a simple truncate function to make sure the track length is not out of
//control
function truncate ($string,$maxlength) { if (strlen($string)<=$maxlength) {
return $string; } else { return substr($string,0,($maxlength-1))."..."; }
}
// this writes the posted info to the data file
function addHistory($track, $artist,$genre, $album){
global $filename;
$handle = fopen ($filename, "a+") or die ("$filename does not exist");;
$time = mktime();
$line= "$track\t$album\t$artist\t$genre\t$time";
fwrite($handle, $line ."\n");
fclose($handle);
}
// this gets the data from the file
function gettracks(){
global $filename;
$handle = @fopen ($filename, "a+") or die ("$filename does not exist or is not writeable" );;
while (!feof($handle)) {
$contents .= fgets($handle, 4096);
}
fclose($handle);
$tracks = preg_split('/\n/', $contents);
array_pop($tracks);
$tracks = array_reverse($tracks);
$i=0;
foreach ($tracks as $song) {
$i++;
$song = preg_split('/\t/', $song);
$track[title] = $song[0];
$track[album] = $song[1];
$track[artist] = $song[2];
$track[genre] = $song[3];
$track[playtime] = $song[4];
$songs[] = $track;
if ($i>5) break;
}
return $songs;
}
//the function that displays the track info
function dispTracks(){
$tracks = gettracks();
if ($tracks !=""){
foreach ($tracks as $song)
{
$playdate = date("F j, Y, g:i a", $song[playtime]);
print "".truncate($song[title],30)." - ".truncate($song[artist],20)."
";
}
}
else echo "Empty Tracks.txt file";
}
//fixed the bug with register globals being off
$add = $_GET["add"];
$track = $_GET["t"];
$artist = $_GET["a"];
$genre = $_GET["g"];
$album = $_GET["al"];
//checking if we should be adding or not
if ($add ==1){
addHistory($track,$artist,$genre,$album);
}else
dispTracks();
?>