summaryrefslogtreecommitdiffstats
path: root/lib/class
diff options
context:
space:
mode:
Diffstat (limited to 'lib/class')
-rw-r--r--lib/class/album.class.php47
-rw-r--r--lib/class/artist.class.php21
-rw-r--r--lib/class/catalog.class.php22
-rw-r--r--lib/class/playlist.class.php4
-rw-r--r--lib/class/rating.class.php4
5 files changed, 67 insertions, 31 deletions
diff --git a/lib/class/album.class.php b/lib/class/album.class.php
index df9d06b3..86ef3af4 100644
--- a/lib/class/album.class.php
+++ b/lib/class/album.class.php
@@ -105,6 +105,30 @@ class Album {
} // get_songs
+ /**
+ * get_song_ids
+ * This returns an array of the song id's that are on this album. This is used by the
+ * show_songs function and can be pased and artist if you so desire to limit it to that
+ */
+ function get_song_ids($artist='') {
+
+ /* If they pass an artist then constrain it based on the artist as well */
+ if ($artist) {
+ $artist_sql = " AND artist='" . sql_escape($artist) . "'";
+ }
+
+ $sql = "SELECT id FROM song WHERE album='" . sql_escape($this->id) . "' $artist_sql ORDER BY track";
+ $db_results = mysql_query($sql, dbh());
+
+ $results = array();
+
+ while ($r = mysql_fetch_assoc($db_results)) {
+ $results[] = $r['id'];
+ }
+
+ return $results;
+
+ } // get_song_ids
/*!
@function format_album
@@ -466,29 +490,6 @@ class Album {
} // find_art
- /*!
- @function get_song_ids
- @discussion returns a list of song_ids on the album
- get_songs returns a list of song objects
- */
- // it seems get_songs really should call this,
- // but I don't feel comfortable imposing that - RCR
- function get_song_ids( $limit = 0 ) {
-
- $results = array();
- $sql = "SELECT id FROM song WHERE album='$this->id' ORDER BY track, title";
-
- if ($limit) { $sql .= " LIMIT $limit"; }
-
- $db_results = mysql_query($sql, dbh());
-
- while ($r = mysql_fetch_object($db_results)) {
- $results[] = $r->id;
- }
-
- return $results;
- } // get_song_ids
-
} //end of album class
?>
diff --git a/lib/class/artist.class.php b/lib/class/artist.class.php
index 961b5991..173fe884 100644
--- a/lib/class/artist.class.php
+++ b/lib/class/artist.class.php
@@ -67,7 +67,7 @@ class Artist {
function get_info() {
/* Grab the basic information from the catalog and return it */
- $sql = "SELECT * FROM artist WHERE id='$this->id'";
+ $sql = "SELECT * FROM artist WHERE id='" . sql_escape($this->id) . "'";
$db_results = mysql_query($sql, dbh());
$results = mysql_fetch_object($db_results);
@@ -112,6 +112,24 @@ class Artist {
} // get_songs
+ /**
+ * get_song_ids
+ * This gets an array of song ids that are assoicated with this artist. This is great for using
+ * with the show_songs function
+ */
+ function get_song_ids() {
+
+ $sql = "SELECT id FROM song WHERE artist='" . sql_escape($this->id) . "' ORDER BY album, track";
+ $db_results = mysql_query($sql, dbh());
+
+ while ($r = mysql_fetch_assoc($db_results)) {
+ $results[] = $r['id'];
+ }
+
+ return $results;
+
+ } // get_song_ids
+
/*!
@function get_random_songs
@discussion gets a random number, and
@@ -265,7 +283,6 @@ class Artist {
/* Set Vars */
$web_path = conf('web_path');
-
$albums = $this->get_albums();
$this->format_artist();
$artist = $this;
diff --git a/lib/class/catalog.class.php b/lib/class/catalog.class.php
index dcbf074e..19cfd0ba 100644
--- a/lib/class/catalog.class.php
+++ b/lib/class/catalog.class.php
@@ -1668,7 +1668,13 @@ class Catalog {
/* If not found create */
else {
- $sql = "INSERT INTO artist (name, prefix) VALUES ('$artist', '$prefix')";
+ $prefix_txt = 'NULL';
+
+ if ($prefix) {
+ $prefix_txt = "'$prefix'";
+ }
+
+ $sql = "INSERT INTO artist (name, prefix) VALUES ('$artist', $prefix_txt)";
$db_results = mysql_query($sql, dbh());
$artist_id = mysql_insert_id(dbh());
@@ -1744,8 +1750,13 @@ class Catalog {
/* If not found create */
else {
+ $prefix_txt = 'NULL';
+
+ if ($prefix) {
+ $prefix_txt = "'$prefix'";
+ }
- $sql = "INSERT INTO album (name, prefix,year) VALUES ('$album', '$prefix','$album_year')";
+ $sql = "INSERT INTO album (name, prefix,year) VALUES ('$album',$prefix_txt,'$album_year')";
$db_results = mysql_query($sql, dbh());
$album_id = mysql_insert_id(dbh());
@@ -1780,9 +1791,10 @@ class Catalog {
@param $genre The name of the genre
*/
function check_genre($genre) {
-
- if (!$genre) {
- return false;
+
+ /* If a genre isn't specified force one */
+ if (strlen($genre) < 1) {
+ $genre = "Unknown (Orphaned)";
}
if ($this->genres[$genre]) {
diff --git a/lib/class/playlist.class.php b/lib/class/playlist.class.php
index a3455d7f..0ab165cd 100644
--- a/lib/class/playlist.class.php
+++ b/lib/class/playlist.class.php
@@ -76,8 +76,12 @@ class Playlist {
*/
function get_track($id) {
+ $sql = "SELECT track FROM playlist_data WHERE id='" . sql_escape($id) . "'";
+ $db_results = mysql_query($sql, dbh());
+ $result = mysql_fetch_assoc($db_results);
+ return $result['track'];
} // get_track
diff --git a/lib/class/rating.class.php b/lib/class/rating.class.php
index f9dd0794..136d212e 100644
--- a/lib/class/rating.class.php
+++ b/lib/class/rating.class.php
@@ -44,10 +44,12 @@ class Rating {
$this->id = $id;
$this->type = $type;
-
if (intval($id) > 1) {
$this->get_average();
}
+ else {
+ $this->rating='0';
+ }
} // Rating