summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorKarl 'vollmerk' Vollmer <vollmer@ampache.org>2006-03-27 07:59:33 +0000
committerKarl 'vollmerk' Vollmer <vollmer@ampache.org>2006-03-27 07:59:33 +0000
commit664bd9a28aa10eedee3deb82cda9b99b91b51fa0 (patch)
tree7ab60c5a038ccde3aa24f9fa18fd71bc6a2b515b /lib
parentdcb93abc50ddea7da48f104ad3b861dee342d623 (diff)
downloadampache-664bd9a28aa10eedee3deb82cda9b99b91b51fa0.tar.gz
ampache-664bd9a28aa10eedee3deb82cda9b99b91b51fa0.tar.bz2
ampache-664bd9a28aa10eedee3deb82cda9b99b91b51fa0.zip
I am not proud... but it works
Diffstat (limited to 'lib')
-rw-r--r--lib/class/catalog.class.php43
-rw-r--r--lib/class/flag.class.php26
-rw-r--r--lib/class/song.class.php58
-rw-r--r--lib/general.lib.php12
4 files changed, 110 insertions, 29 deletions
diff --git a/lib/class/catalog.class.php b/lib/class/catalog.class.php
index 55630719..c2af2cda 100644
--- a/lib/class/catalog.class.php
+++ b/lib/class/catalog.class.php
@@ -18,6 +18,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
+
/**
* Catalog Class
* This class handles all actual work in regards to the catalog, it contains functions for creating/listing/updated the catalogs.
@@ -1252,6 +1253,48 @@ class Catalog {
} //clean_catalog
/**
+ * clean_single_song
+ * This function takes the elements of a single song object
+ * And checks to see if those specific elements are now orphaned
+ * this is often used in flagging, and is a faster way then calling
+ * the normal clean functions. The assumption is made that this is
+ * an old song object whoes information has already been updated in the
+ * database
+ */
+ function clean_single_song($song) {
+
+ /* A'right let's check genre first */
+ $sql = "SELECT song.genre FROM song WHERE genre='" . $song->genre . "'";
+ $db_results = mysql_query($sql, dbh());
+
+ if (!mysql_num_rows($db_results)) {
+ $sql = "DELETE FROM genre WHERE id='" . $song->genre . "'";
+ $db_results = mysql_query($sql, dbh());
+ }
+
+ /* Now for the artist */
+ $sql = "SELECT song.artist FROM song WHERE artist='" . $song->artist . "'";
+ $db_results = mysql_query($sql, dbh());
+
+ if (!mysql_num_rows($db_results)) {
+ $sql = "DELETE FROM artist WHERE id='" . $song->artist . "'";
+ $db_results = mysql_query($sql, dbh());
+ }
+
+ /* Now for the album */
+ $sql = "SELECT song.album FROM song WHERE album='" . $song->album . "'";
+ $db_results = mysql_query($sql, dbh());
+
+ if (!mysql_num_rows($db_results)) {
+ $sql = "DELETE FROM album WHERE id='" . $song->album . "'";
+ $db_results = mysql_query($sql, dbh());
+ }
+
+ return true;
+
+ } // clean_single_song
+
+ /**
* clean_genres
* This functions cleans up unused genres
* @package Catalog
diff --git a/lib/class/flag.class.php b/lib/class/flag.class.php
index dc6f44a3..a95e73c8 100644
--- a/lib/class/flag.class.php
+++ b/lib/class/flag.class.php
@@ -36,6 +36,10 @@ class Flag {
var $date;
var $approved=0;
+ /* Generated Values */
+ var $name; // Blank
+ var $title; // Blank
+
/**
* Constructor
* This takes a flagged.id and then pulls in the information for said flag entry
@@ -190,11 +194,10 @@ class Flag {
} // approve
/**
- * print_name
- * This function formats and prints out a userfriendly name of the flagged
- * object
+ * format_name
+ * This function formats and sets the $this->name variable and $this->title
*/
- function print_name() {
+ function format_name() {
switch ($this->object_type) {
case 'song':
@@ -208,7 +211,20 @@ class Flag {
break;
} // end switch on object type
- echo "<span title=\"$title\">$name</span>";
+ $this->title = $title;
+ $this->name = $name;
+
+ } // format_name()
+
+ /**
+ * print_name
+ * This function formats and prints out a userfriendly name of the flagged
+ * object
+ */
+ function print_name() {
+
+ $this->format_name();
+ echo "<span title=\"" . $this->title . "\">" . $this->name . "</span>";
} // print_name
diff --git a/lib/class/song.class.php b/lib/class/song.class.php
index 44ce9602..a68a96dc 100644
--- a/lib/class/song.class.php
+++ b/lib/class/song.class.php
@@ -29,8 +29,8 @@ class Song {
/* Variables from DB */
var $id;
var $file;
- var $album;
- var $artist;
+ var $album; // album.id (Int)
+ var $artist; // artist.id (Int)
var $title;
var $year;
var $comment;
@@ -40,7 +40,7 @@ class Song {
var $size;
var $time;
var $track;
- var $genre;
+ var $genre; // genre.id (Int)
var $type;
var $mime;
var $played;
@@ -178,16 +178,18 @@ class Song {
} // get_album_songs
- /*!
- @function get_album_name
- @discussion gets the name of $this->album
- */
- function get_album_name() {
+ /**
+ * get_album_name
+ * gets the name of $this->album, allows passing of id
+ */
+ function get_album_name($album_id=0) {
- $sql = "SELECT name,prefix FROM album WHERE id='$this->album'";
+ if (!$album_id) { $album_id = $this->album; }
+
+ $sql = "SELECT name,prefix FROM album WHERE id='" . sql_escape($album_id) . "'";
$db_results = mysql_query($sql, dbh());
- $results = mysql_fetch_array($db_results);
+ $results = mysql_fetch_assoc($db_results);
if ($results['prefix']) {
return $results['prefix'] . " " .$results['name'];
@@ -198,16 +200,18 @@ class Song {
} // get_album_name
- /*!
- @function get_artist_name
- @discussion gets the name of $this->artist
- */
- function get_artist_name() {
+ /**
+ * get_artist_name
+ * gets the name of $this->artist, allows passing of id
+ */
+ function get_artist_name($artist_id=0) {
+
+ if (!$artist_id) { $artist_id = $this->artist; }
- $sql = "SELECT name,prefix FROM artist WHERE id='$this->artist'";
+ $sql = "SELECT name,prefix FROM artist WHERE id='" . sql_escape($artist_id) . "'";
$db_results = mysql_query($sql, dbh());
- $results = mysql_fetch_array($db_results);
+ $results = mysql_fetch_assoc($db_results);
if ($results['prefix']) {
return $results['prefix'] . " " . $results['name'];
@@ -218,16 +222,19 @@ class Song {
} // get_album_name
- /*!
- @function get_genre_name
- @discussion gets the name of the genre
- */
- function get_genre_name() {
+ /**
+ * get_genre_name
+ * gets the name of the genre, allow passing of a specified
+ * id
+ */
+ function get_genre_name($genre_id=0) {
- $sql = "SELECT name FROM genre WHERE id='$this->genre'";
+ if (!$genre_id) { $genre_id = $this->genre; }
+
+ $sql = "SELECT name FROM genre WHERE id='" . sql_escape($genre_id) . "'";
$db_results = mysql_query($sql, dbh());
- $results = mysql_fetch_array($db_results);
+ $results = mysql_fetch_assoc($db_results);
return $results['name'];
@@ -557,6 +564,9 @@ class Song {
if (!$song_id) { $song_id = $this->id; }
+ /* Can't update to blank */
+ if (!strlen(trim($value)) && $field != 'comment') { return false; }
+
$value = sql_escape($value);
$sql = "UPDATE song SET $field='$value' WHERE id='$song_id'";
diff --git a/lib/general.lib.php b/lib/general.lib.php
index fde2f01c..c8df6183 100644
--- a/lib/general.lib.php
+++ b/lib/general.lib.php
@@ -808,6 +808,18 @@ function scrub_out($str) {
} // scrub_out
/**
+ * revert_string
+ * This returns a scrubed string to it's most normal state
+ * Uhh yea better way to do this please?
+ */
+function revert_string($string) {
+
+ $string = unhtmlentities($string,ENT_QUOTES,conf('site_charset'));
+ return $string;
+
+} // revert_string
+
+/**
* make_bool
* This takes a value and returns what I consider to be the correct boolean value
* This is used instead of settype alone because settype considers 0 and "false" to