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

Commit 31a47deb authored by clint's avatar clint

switch more of gnukebox to adodb

parent 508cf531
<?php
/* Libre.fm -- a free network service for sharing your music listening habits
Copyright (C) 2009 Free Software Foundation, Inc
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 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 Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
if(!file_exists(dirname(__FILE__) . '/config.php')) {
die('Please run the <a href=\'install.php\'>Install</a> script to configure your installation');
}
require_once('config.php');
require_once('adodb/adodb-exceptions.inc.php');
require_once('adodb/adodb.inc.php');
try {
$adodb =& NewADOConnection($adodb_connect_string);
} catch (exception $e) {
var_dump($e);
adodb_backtrace($e->gettrace());
}
?>
......@@ -60,31 +60,30 @@ require_once('utils/human-time.php');
$req_artist = urldecode($_GET["a"]);
$req_track = urldecode($_GET["t"]);
$adodb->SetFetchMode(ADODB_FETCH_ASSOC);
if ($req_user) {
// echo "SELECT username, artist, track, time FROM Scrobbles WHERE username = '" . $mdb2->quote($req_user, 'text') . "' ORDER BY time DESC LIMIT 100";
$res = $mdb2->query("SELECT username, artist, track, time FROM Scrobbles WHERE username = " . $mdb2->quote($req_user, 'text') . " ORDER BY time DESC LIMIT 100");
// echo "SELECT username, artist, track, time FROM Scrobbles WHERE username = '" . $adodb->qstr($req_user) . "' ORDER BY time DESC LIMIT 100";
$res = $adodb->CacheGetAll(60, "SELECT username, artist, track, time FROM Scrobbles WHERE username = " . $adodb->qstr($req_user) . " ORDER BY time DESC LIMIT 100");
echo "<h2>" . $req_user . "'s most recent listening data</h2>";
} elseif ($req_artist) {
$res = $mdb2->query("SELECT username, artist, track, time FROM Scrobbles WHERE artist = '" . $mdb2->quote($req_artist, 'text') ."' ORDER BY time DESC LIMIT 100");
$res = $adodb->CacheGetAll(60, "SELECT username, artist, track, time FROM Scrobbles WHERE artist = '" . $adodb->qstr($req_artist) ."' ORDER BY time DESC LIMIT 100");
echo "<h2>Last 100 Tracks by " . $req_artist . "</h2>";
} elseif ($req_track) {
$res = $mdb2->query("SELECT username, artist, track, time FROM Scrobbles WHERE track = '" . $mdb2->quote($req_track, 'text') . "' ORDER BY time DESC LIMIT 100");
$res = $adodb->CacheGetAll(60, "SELECT username, artist, track, time FROM Scrobbles WHERE track = '" . $adodb->qstr($req_track) . "' ORDER BY time DESC LIMIT 100");
echo "<h2>Last 100 plays of " . $req_track . "</h2>";
} elseif (!$res) {
$res = $mdb2->query("SELECT username, artist, track, time FROM Scrobbles ORDER BY time DESC LIMIT 10");
$res = $adodb->CacheGetAll(60, "SELECT username, artist, track, time FROM Scrobbles ORDER BY time DESC LIMIT 10");
echo "<h2>Last 10 tracks received</h2>";
}
?>
......@@ -98,7 +97,7 @@ if ($req_user) {
die($res->getMessage());
}
$i = 0;
while($row = $res->fetchRow(MDB2_FETCHMODE_ASSOC)) {
foreach($res as &$row){
$i++;
echo ($i % 2 == 0) ? "<tr class=\"even\">" : "<tr class=\"odd\">";
foreach($row as $field => $value) {
......@@ -122,37 +121,36 @@ if ($req_user) {
<h2>Statistics</h2>
<?php
$res = $mdb2->query("SELECT COUNT(*) as total from Scrobbles");
if(PEAR::isError($res)) {
die($res->getMessage());
$adodb->SetFetchMode(ADODB_FETCH_ASSOC);
$total = $adodb->CacheGetOne(60, 'SELECT COUNT(*) as total from Scrobbles');
if(!$res) {
die("sql error");
}
$row = $res->fetchRow(MDB2_FETCHMODE_ASSOC);
echo "<p>" . stripslashes($row["total"]) . " gobbles.</p>";
echo "<p>" . stripslashes($total) . " gobbles.</p>";
$res = $mdb2->query("SELECT COUNT(*) as total from Track");
if(PEAR::isError($res)) {
die($res->getMessage());
$total = $adodb->CacheGetOne(120, 'SELECT COUNT(*) as total from Track');
if(!$res) {
die("sql error");
}
$row = $res->fetchRow(MDB2_FETCHMODE_ASSOC);
echo "<p>" . stripslashes($row["total"]) . " tracks.</p>";
echo "<p>" . stripslashes($total) . " tracks.</p>";
$res = $mdb2->query("SELECT COUNT(*) as total from Users");
if(PEAR::isError($res)) {
die($res->getMessage());
$total = $adodb->CacheGetOne(720, 'SELECT COUNT(*) as total from Users');
if(!$res) {
die("sql error");
}
$row = $res->fetchRow(MDB2_FETCHMODE_ASSOC);
echo "<p>" . stripslashes($row["total"]) . " users.</p>";
echo "<p>" . stripslashes($total) . " users.</p>";
?>
<h2>Now Playing?</h2>
<?php
$res = $mdb2->query("SELECT username, artist, track, client, ClientCodes.name, ClientCodes.url from Now_Playing LEFT OUTER JOIN Scrobble_Sessions ON Now_Playing.sessionid=Scrobble_Sessions.sessionid LEFT OUTER JOIN ClientCodes ON Scrobble_Sessions.client=ClientCodes.code ORDER BY Now_Playing.expires DESC LIMIT 10");
if(PEAR::isError($res)) {
die($res->getMessage());
$adodb->SetFetchMode(ADODB_FETCH_ASSOC);
$res = $adodb->GetAll('SELECT username, artist, track, client, ClientCodes.name, ClientCodes.url from Now_Playing LEFT OUTER JOIN Scrobble_Sessions ON Now_Playing.sessionid=Scrobble_Sessions.sessionid LEFT OUTER JOIN ClientCodes ON Scrobble_Sessions.client=ClientCodes.code ORDER BY Now_Playing.expires DESC LIMIT 10');
if(!$res) {
die("sql error");
}
while($row = $res->fetchRow(MDB2_FETCHMODE_ASSOC)) {
foreach($res as &$row){
if($row["name"] == "") {
$client = strip_tags(stripslashes($row["client"])) . "(unknown, please tell us what this is)";
} else {
......@@ -178,7 +176,7 @@ if ($req_user) {
</div>
<div class="yui-g">
<div class="yui-u first" id="links">
This site handles <em>gobble</em> and <em>now playing</em>
This site handles <em>track</em> and <em>now playing</em>
submissions from client applications and offers access to our web
services API. If you just want to use <a
href="http://libre.fm">libre.fm</a> then you probably want to
......
......@@ -19,49 +19,49 @@
*/
require_once('database.php'); // include the database connection string
require_once('database2.php'); // include the database connection string
function usernameFromSID($session_id)
{
//derive the username from a session ID
global $mdb2; // include the Database connector
global $adodb; // include the Database connector
// Delete any expired session ids
$mdb2->query("DELETE FROM Scrobble_Sessions WHERE expires < " . time());
$adodb->Execute("DELETE FROM Scrobble_Sessions WHERE expires < " . time());
$res = $mdb2->query("SELECT username FROM Scrobble_Sessions WHERE sessionid = " . $mdb2->quote($session_id, "text")); // get the username from the table
$res = $adodb->GetOne("SELECT username FROM Scrobble_Sessions WHERE sessionid = " . $adodb->qstr($session_id)); // get the username from the table
if(PEAR::isError($res)) {
die("FAILED ufs " . $res->getMessage() . "\n");
// die is there is an error, printing the error
}
if(!$res->numRows()) {
if(!$res) {
die("BADSESSION\n");
// the user has no session
}
return $res->fetchOne(0);
return $res;
// return the first user
}
function createArtistIfNew($artist) {
global $mdb2;
global $adodb;
$artist = NoSpamTracks($artist);
$res = $mdb2->query("SELECT name FROM Artist WHERE name = " . ($artist));
$res = $adodb->Execute("SELECT name FROM Artist WHERE name = " . ($artist));
if(PEAR::isError($res)) {
die("FAILED art " . $res->getMessage() . "\n");
}
if(!$res->numRows()) {
if(!$res) {
// Artist doesn't exist, so we create them
$res = $mdb2->query("INSERT INTO Artist (name) VALUES (" . ($artist) . ")");
$res = $adodb->Execute("INSERT INTO Artist (name) VALUES (" . ($artist) . ")");
if(PEAR::isError($res)) {
die("FAILED artc " . $res->getMessage() . "\n");
}
......@@ -69,25 +69,25 @@ function createArtistIfNew($artist) {
}
function createAlbumIfNew($artist, $album) {
global $mdb2;
global $adodb;
$res = $mdb2->query("SELECT name FROM Album WHERE name = " . ($album) . " AND artist_name = " . ($artist));
$res = $adodb->Execute("SELECT name FROM Album WHERE name = " . ($album) . " AND artist_name = " . ($artist));
if(PEAR::isError($res)) {
die("FAILED alb " . $res->getMessage() . "\n");
}
if(!$res->numRows()) {
if(!$res) {
// Album doesn't exist, so create it
$art = $mdb2->quote(getAlbumArt($artist, $album));
$art = $adodb->qstr(getAlbumArt($artist, $album));
if ($art !="") {
$license = $mdb2->quote("amazon");
$license = $adodb->qstr("amazon");
$res = $mdb2->query("INSERT INTO Album (name, artist_name, image, artwork_license) VALUES (" . ($album) . ", " . ($artist) . ", " . ($art) . ", " . ($license) .")");
$res = $adodb->Execute("INSERT INTO Album (name, artist_name, image, artwork_license) VALUES (" . ($album) . ", " . ($artist) . ", " . ($art) . ", " . ($license) .")");
} else {
$res = $mdb2->query("INSERT INTO Album (name, artist_name) VALUES (" . ($album) . ", " . ($artist) . ")");
$res = $adodb->Execute("INSERT INTO Album (name, artist_name) VALUES (" . ($album) . ", " . ($artist) . ")");
}
......@@ -98,15 +98,15 @@ function createAlbumIfNew($artist, $album) {
}
function getTrackCreateIfNew($artist, $album, $track, $mbid) {
global $mdb2;
global $adodb;
$track = NoSpamTracks($track);
$artist = NoSpamTracks($artist);
if($album != 'NULL') {
$res = $mdb2->query("SELECT id FROM Track WHERE lower(name) = lower(" . ($track) . ") AND lower(artist_name) = lower(" . ($artist) . ") AND lower(album_name) = lower(" . ($album) . ")");
$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 = $mdb2->query("SELECT id FROM Track WHERE lower(name) = lower(" . ($track) . ") AND lower(artist_name) = lower(" . ($artist) . ") AND album_name IS NULL");
$res = $adodb->GetOne("SELECT id FROM Track WHERE lower(name) = lower(" . ($track) . ") AND lower(artist_name) = lower(" . ($artist) . ") AND album_name IS NULL");
}
if(PEAR::isError($res)) {
die("FAILED trk " . $res->getMessage() . "\n");
......@@ -114,7 +114,7 @@ function getTrackCreateIfNew($artist, $album, $track, $mbid) {
if(!$res->numRows()) {
// Create new track
$res = $mdb2->exec("INSERT INTO Track (name, artist_name, album_name, mbid) VALUES ("
$res = $adodb->Execute("INSERT INTO Track (name, artist_name, album_name, mbid) VALUES ("
. ($track) . ", "
. ($artist) . ", "
. ($album) . ", "
......@@ -124,14 +124,14 @@ function getTrackCreateIfNew($artist, $album, $track, $mbid) {
}
return getTrackCreateIfNew($artist, $album, $track, $mbid);
} else {
return $res->fetchOne(0);
return $res;
}
}
function getScrobbleTrackCreateIfNew($artist, $album, $track, $mbid, $tid) {
global $mdb2;
global $adodb;
$res = $mdb2->query("SELECT id FROM Scrobble_Track WHERE name = lower("
$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) . ")")));
......@@ -139,14 +139,14 @@ function getScrobbleTrackCreateIfNew($artist, $album, $track, $mbid, $tid) {
die("FAILED st " . $res->getMessage() . "\n");
}
if(!$res->numRows()) {
if(!$res) {
$sql = "INSERT INTO Scrobble_Track (name, artist, album, mbid, track) VALUES ("
. "lower(" . ($track) . "), "
. "lower(" . ($artist) . "), "
. (($album == 'NULL') ? "NULL" : "lower(" . ($album) . ")") . ", "
. (($mbid == 'NULL') ? "NULL" : "lower(" . ($mbid) . ")") . ", "
. ($tid) . ")";
$res = $mdb2->exec($sql);
$res = $adodb->Execute($sql);
if(PEAR::isError($res)) {
$msg = $res->getMessage() . " - " . $res->getUserInfo();
reportError($msg, $sql);
......@@ -155,19 +155,19 @@ function getScrobbleTrackCreateIfNew($artist, $album, $track, $mbid, $tid) {
}
return getScrobbleTrackCreateIfNew($artist, $album, $track, $mbid, $tid);
} else {
return $res->fetchOne(0);
return $res;
}
}
function scrobbleExists($username, $artist, $track, $time) {
global $mdb2;
global $adodb;
$res = $mdb2->query("SELECT time FROM Scrobbles WHERE username = " . ($username) . " AND artist = " . ($artist) . " AND track = " . ($track) . " AND time = " . ($time));
$res = $adodb->GetOne("SELECT time FROM Scrobbles WHERE username = " . ($username) . " AND artist = " . ($artist) . " AND track = " . ($track) . " AND time = " . ($time));
if(PEAR::isError($res)) {
die("FAILED se " . $res->getMessage() . "\n");
}
if(!$res->numRows()) {
if(!$res) {
return false;
} else {
return true;
......
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