mirror of
https://github.com/Yetangitu/ampache
synced 2025-10-04 18:29:40 +02:00
I am not proud... but it works
This commit is contained in:
parent
dcb93abc50
commit
664bd9a28a
6 changed files with 155 additions and 51 deletions
|
@ -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.
|
||||
|
@ -1251,6 +1252,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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
||||
$sql = "SELECT name,prefix FROM artist WHERE id='$this->artist'";
|
||||
if (!$artist_id) { $artist_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'";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue