We are no longer offering accounts on this server. Consider https://gitlab.freedesktop.org/ as a place to host projects.

Commit 8009b7ac authored by Mike Sheldon's avatar Mike Sheldon

Make some more of the old gnukebox code more compliant with the coding standards

parent 63ea71c5
......@@ -24,10 +24,8 @@ require_once('temp-utils.php');
function useridFromSID($session_id)
{
//derive the username from a session ID
global $adodb; // include the Database connector
//derive the username from a session ID
global $adodb; // include the Database connector
// Delete any expired session ids
$adodb->Execute('DELETE FROM Scrobble_Sessions WHERE expires < ' . time());
......@@ -42,13 +40,11 @@ function useridFromSID($session_id)
if(!$res) {
die("BADSESSION\n");
// the user has no session
}
return $res;
// return the first user
// return the first user
}
function createArtistIfNew($artist) {
......@@ -66,7 +62,7 @@ function createArtistIfNew($artist) {
if(!$res) {
// Artist doesn't exist, so we create them
try {
$artist = substr($artist,0,255);
$artist = substr($artist,0,255);
$res = $adodb->Execute('INSERT INTO Artist (name) VALUES (' . ($artist) . ')');
}
catch (exception $e) {
......@@ -79,8 +75,8 @@ function createAlbumIfNew($artist, $album) {
global $adodb;
try {
$artist = substr($artist,0,255);
$album = substr($album,0,255);
$artist = substr($artist,0,255);
$album = substr($album,0,255);
$name = $adodb->GetOne('SELECT name FROM Album WHERE lower(name) = lower(' . ($album) . ') AND lower(artist_name) = lower(' . ($artist) . ')');
}
catch (exception $e) {
......@@ -96,16 +92,13 @@ function createAlbumIfNew($artist, $album) {
if ($art !="") {
$license = $adodb->qstr('amazon');
$sql = 'INSERT INTO Album (name, artist_name, image, artwork_license) VALUES (' . ($album) . ', ' . ($artist) . ', ' . ($art) . ', ' . ($license) .')';
} else {
$sql = 'INSERT INTO Album (name, artist_name) VALUES (' . ($album) . ', ' . ($artist) . ')';
}
try {
$adodb->Execute($sql);
}
catch (exception $e) {
} catch (exception $e) {
die('FAILED albc ' . $e->getMessage() . '\n');
}
}
......@@ -118,11 +111,11 @@ function getTrackCreateIfNew($artist, $album, $track, $mbid) {
$artist = NoSpamTracks($artist);
try {
if($album != 'NULL') {
$res = $adodb->GetOne('SELECT id FROM Track WHERE lower(name) = lower(' . ($track) . ') AND lower(artist_name) = lower(' . ($artist) . ') AND lower(album_name) = lower(' . ($album) . ')');
} else {
$res = $adodb->GetOne('SELECT id FROM Track WHERE lower(name) = lower(' . ($track) . ') AND lower(artist_name) = lower(' . ($artist) . ') AND album_name IS NULL');
}
if($album != 'NULL') {
$res = $adodb->GetOne('SELECT id FROM Track WHERE lower(name) = lower(' . ($track) . ') AND lower(artist_name) = lower(' . ($artist) . ') AND lower(album_name) = lower(' . ($album) . ')');
} else {
$res = $adodb->GetOne('SELECT id FROM Track WHERE lower(name) = lower(' . ($track) . ') AND lower(artist_name) = lower(' . ($artist) . ') AND album_name IS NULL');
}
}
catch (exception $e) {
die('FAILED trk ' . $e->getMessage() . '\n');
......@@ -131,16 +124,15 @@ function getTrackCreateIfNew($artist, $album, $track, $mbid) {
if(!$res) {
// Create new track
try {
$track = substr($track,0,255);
$artist = substr($artist,0,255);
$album = substr($album,0,255);
$res = $adodb->Execute('INSERT INTO Track (name, artist_name, album_name, mbid) VALUES ('
. ($track) . ', '
. ($artist) . ', '
. ($album) . ', '
. ($mbid) . ')');
}
catch (exception $e) {
$track = substr($track,0,255);
$artist = substr($artist,0,255);
$album = substr($album,0,255);
$res = $adodb->Execute('INSERT INTO Track (name, artist_name, album_name, mbid) VALUES ('
. ($track) . ', '
. ($artist) . ', '
. ($album) . ', '
. ($mbid) . ')');
} catch (exception $e) {
die('FAILED trkc ' . $e->getMessage() . '\n');
}
return getTrackCreateIfNew($artist, $album, $track, $mbid);
......@@ -153,12 +145,11 @@ function getScrobbleTrackCreateIfNew($artist, $album, $track, $mbid, $tid) {
global $adodb;
try {
$res = $adodb->GetOne('SELECT id FROM Scrobble_Track WHERE name = lower('
. ($track) . ') AND artist = lower(' . ($artist) . ') AND album '
. (($album == 'NULL') ? 'IS NULL' : ('= lower(' . ($album) . ')')) . ' AND mbid '
. (($mbid == 'NULL') ? 'IS NULL' : ('= lower(' . ($mbid) . ')')));
}
catch (exception $e) {
$res = $adodb->GetOne('SELECT id FROM Scrobble_Track WHERE name = lower('
. ($track) . ') AND artist = lower(' . ($artist) . ') AND album '
. (($album == 'NULL') ? 'IS NULL' : ('= lower(' . ($album) . ')')) . ' AND mbid '
. (($mbid == 'NULL') ? 'IS NULL' : ('= lower(' . ($mbid) . ')')));
} catch (exception $e) {
die('FAILED st ' . $e->getMessage() . '\n');
}
......@@ -175,7 +166,6 @@ function getScrobbleTrackCreateIfNew($artist, $album, $track, $mbid, $tid) {
catch (exception $e) {
$msg = $e->getMessage();
reportError($msg, $sql);
die('FAILED stc ' . $res->getMessage() . '\n');
}
return getScrobbleTrackCreateIfNew($artist, $album, $track, $mbid, $tid);
......@@ -188,9 +178,8 @@ function scrobbleExists($userid, $artist, $track, $time) {
global $adodb;
try {
$res = $adodb->GetOne('SELECT time FROM Scrobbles WHERE userid = ' . ($userid) . ' AND artist = ' . ($artist) . ' AND track = ' . ($track) . ' AND time = ' . ($time));
}
catch (exception $e) {
$res = $adodb->GetOne('SELECT time FROM Scrobbles WHERE userid = ' . ($userid) . ' AND artist = ' . ($artist) . ' AND track = ' . ($track) . ' AND time = ' . ($time));
} catch (exception $e) {
die('FAILED se ' . $e->getMessage() . '\n');
}
......@@ -200,41 +189,39 @@ function scrobbleExists($userid, $artist, $track, $time) {
return true;
}
}
function NoSpamTracks ($track) {
// This function exists to remove things like '(PREVIEW: buy it at www.magnatune.com)' from track names.
$track = str_replace(' (PREVIEW: buy it at www.magnatune.com)', "", $track);
function NoSpamTracks ($track) {
return $track;
// This function exists to remove things like '(PREVIEW: buy it at www.magnatune.com)' from track names.
$track = str_replace(' (PREVIEW: buy it at www.magnatune.com)', "", $track);
return $track;
}
function getAlbumArt($artist, $album) {
$Access_Key_ID = '1EST86JB355JBS3DFE82'; // this is mattl's personal key :)
$SearchIndex='Music';
$Keywords=urlencode($artist.' '.$album);
$Operation = 'ItemSearch';
$Version = '2007-07-16';
$ResponseGroup = 'ItemAttributes,Images';
$request=
'http://ecs.amazonaws.com/onca/xml'
. '?Service=AWSECommerceService'
. '&AssociateTag=' . $Associate_tag
. '&AWSAccessKeyId=' . $Access_Key_ID
. '&Operation=' . $Operation
. '&Version=' . $Version
. '&SearchIndex=' . $SearchIndex
. '&Keywords=' . $Keywords
. '&ResponseGroup=' . $ResponseGroup;
$aws_xml = simplexml_load_file($request) or die('xml response not loading\n');
$image = $aws_xml->Items->Item->MediumImage->URL;
$URI = $aws_xml->Items->Item->DetailPageURL;
return $image;
$Access_Key_ID = '1EST86JB355JBS3DFE82'; // this is mattl's personal key :)
$SearchIndex='Music';
$Keywords=urlencode($artist.' '.$album);
$Operation = 'ItemSearch';
$Version = '2007-07-16';
$ResponseGroup = 'ItemAttributes,Images';
$request='http://ecs.amazonaws.com/onca/xml'
. '?Service=AWSECommerceService'
. '&AssociateTag=' . $Associate_tag
. '&AWSAccessKeyId=' . $Access_Key_ID
. '&Operation=' . $Operation
. '&Version=' . $Version
. '&SearchIndex=' . $SearchIndex
. '&Keywords=' . $Keywords
. '&ResponseGroup=' . $ResponseGroup;
$aws_xml = simplexml_load_file($request) or die('xml response not loading\n');
$image = $aws_xml->Items->Item->MediumImage->URL;
$URI = $aws_xml->Items->Item->DetailPageURL;
return $image;
}
function validateMBID ($input) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment