summaryrefslogtreecommitdiffstats
path: root/lib/class/album.class.php
diff options
context:
space:
mode:
authorPaul 'flowerysong' Arthur <flowerysong00@yahoo.com>2010-05-09 19:50:35 +0000
committerPaul 'flowerysong' Arthur <flowerysong00@yahoo.com>2010-05-09 19:50:35 +0000
commit3a5a8dad2e8ddc0162496baa3f839651c05b2843 (patch)
treee974f8ea0c9e60435a80092ab7537fbd6cba0339 /lib/class/album.class.php
parent5e4162cd0ada44796008c6d1cafb98ecf62226c1 (diff)
downloadampache-3a5a8dad2e8ddc0162496baa3f839651c05b2843.tar.gz
ampache-3a5a8dad2e8ddc0162496baa3f839651c05b2843.tar.bz2
ampache-3a5a8dad2e8ddc0162496baa3f839651c05b2843.zip
Some more Art-related cleanup. Removing references to album_data, removing old
art methods from Album, etc. Should fix FS#76
Diffstat (limited to 'lib/class/album.class.php')
-rw-r--r--lib/class/album.class.php245
1 files changed, 21 insertions, 224 deletions
diff --git a/lib/class/album.class.php b/lib/class/album.class.php
index ebc3a7f0..3e56151e 100644
--- a/lib/class/album.class.php
+++ b/lib/class/album.class.php
@@ -36,12 +36,6 @@ class Album extends database_object {
public $prefix;
public $mbid; // MusicBrainz ID
- /* Art Related Fields */
- public $art;
- public $art_mime;
- public $thumb;
- public $thumb_mime;
-
// cached information
public $_songs=array();
@@ -111,18 +105,22 @@ class Album extends database_object {
// If we're extra'ing cache the extra info as well
if ($extra) {
- $sql = "SELECT COUNT(DISTINCT(song.artist)) as artist_count,COUNT(song.id) AS song_count,artist.name AS artist_name" .
- ",artist.prefix AS artist_prefix,album_data.art AS has_art,album_data.thumb AS has_thumb, artist.id AS artist_id,`song`.`album`".
+ $sql = "SELECT COUNT(DISTINCT(`song`.`artist`)) AS `artist_count`, " .
+ "COUNT(`song`.`id`) AS `song_count`, " .
+ "`artist`.`name` AS `artist_name`, " .
+ "`artist`.`prefix` AS `artist_prefix`, " .
+ "`artist`.`id` AS `artist_id`, `song`.`album`" .
"FROM `song` " .
"INNER JOIN `artist` ON `artist`.`id`=`song`.`artist` " .
- "LEFT JOIN `album_data` ON `album_data`.`album_id` = `song`.`album` " .
"WHERE `song`.`album` IN $idlist GROUP BY `song`.`album`";
$db_results = Dba::read($sql);
while ($row = Dba::fetch_assoc($db_results)) {
- $row['has_art'] = make_bool($row['has_art']);
- $row['has_thumb'] = make_bool($row['has_thumb']);
+ $art = new Art($row['album'], 'album');
+ $art->get_db();
+ $row['has_art'] = make_bool($art->raw);
+ $row['has_thumb'] = make_bool($art->thumb);
parent::add_to_cache('album_extra',$row['album'],$row);
} // while rows
} // if extra
@@ -143,17 +141,18 @@ class Album extends database_object {
}
$sql = "SELECT COUNT(DISTINCT(song.artist)) as artist_count,COUNT(song.id) AS song_count,artist.name AS artist_name" .
- ",artist.prefix AS artist_prefix,album_data.art AS has_art,album_data.thumb AS has_thumb, artist.id AS artist_id ".
+ ",artist.prefix AS artist_prefix, artist.id AS artist_id ".
"FROM `song` " .
"INNER JOIN `artist` ON `artist`.`id`=`song`.`artist` " .
- "LEFT JOIN `album_data` ON `album_data`.`album_id` = `song`.`album` " .
"WHERE `song`.`album`='$this->id' GROUP BY `song`.`album`";
$db_results = Dba::read($sql);
$results = Dba::fetch_assoc($db_results);
- if ($results['has_art']) { $results['has_art'] = 1; }
- if ($results['has_thumb']) { $results['has_thumb'] = 1; }
+ $art = new Art($this->id, 'album');
+ $art->get_db();
+ $results['has_art'] = make_bool($art->raw);
+ $results['has_thumb'] = make_bool($art->thumb);
parent::add_to_cache('album_extra',$this->id,$results);
@@ -188,25 +187,6 @@ class Album extends database_object {
} // get_songs
/**
- * has_art
- * This returns true or false depending on if we find any art for this
- * album.
- */
- public function has_art() {
-
- $sql = "SELECT `album_id` FROM `album_data` WHERE `album_id`='" . $this->id . "' AND art IS NOT NULL";
- $db_results = Dba::read($sql);
-
- if (Dba::fetch_assoc($db_results)) {
- $this->has_art = true;
- return true;
- }
-
- return false;
-
- } // has_art
-
- /**
* has_track
* This checks to see if this album has a track of the specified title
*/
@@ -343,74 +323,6 @@ class Album extends database_object {
} // update
/**
- * clear_art
- * clears the album art from the DB
- */
- public function clear_art() {
-
- $sql = "UPDATE `album_data` SET `art`=NULL, `art_mime`=NULL, `thumb`=NULL, `thumb_mime`=NULL WHERE `album_id`='$this->id'";
- $db_results = Dba::write($sql);
-
- } // clear_art
-
- /**
- * insert_art
- * this takes a string representation of an image
- * and inserts it into the database. You must pass the mime type as well
- */
- public function insert_art($image, $mime) {
-
- /* Have to disable this for Demo because people suck and try to
- * insert PORN :(
- */
- if (Config::get('demo_mode')) { return false; }
-
- // Check for PHP:GD and if we have it make sure this image is of some size
- if (function_exists('ImageCreateFromString')) {
- $im = ImageCreateFromString($image);
- if (imagesx($im) <= 5 || imagesy($im) <= 5 || !$im) {
- return false;
- }
- } // if we have PHP:GD
- elseif (strlen($image) < 5) {
- return false;
- }
-
- // Default to image/jpeg as a guess if there is no passed mime type
- $mime = $mime ? $mime : 'image/jpeg';
-
- // Push the image into the database
- $sql = "REPLACE INTO `album_data` SET `art` = '" . Dba::escape($image) . "'," .
- " `art_mime` = '" . Dba::escape($mime) . "'" .
- ", `album_id` = '$this->id'," .
- "`thumb` = NULL, `thumb_mime`=NULL";
- $db_results = Dba::write($sql);
-
- return true;
-
- } // insert_art
-
- /**
- * save_resized_art
- * This takes data from a gd resize operation and saves
- * it back into the database as a thumbnail
- */
- public static function save_resized_art($data,$mime,$album) {
-
- // Make sure there's actually something to save
- if (strlen($data) < '5') { return false; }
-
- $data = Dba::escape($data);
- $mime = Dba::escape($mime);
- $album = Dba::escape($album);
-
- $sql = "UPDATE `album_data` SET `thumb`='$data',`thumb_mime`='$mime' " .
- "WHERE `album_data`.`album_id`='$album'";
- $db_results = Dba::write($sql);
-
- } // save_resized_art
-
- /**
* get_random_albums
* This returns a random number of albums from the catalogs
* this is used by the index to return some 'potential' albums to play
@@ -420,137 +332,22 @@ class Album extends database_object {
$sql = 'SELECT `id` FROM `album` ORDER BY RAND() LIMIT ' . ($count*2);
$db_results = Dba::read($sql);
- $in_sql = '`album_id` IN (';
-
while ($row = Dba::fetch_assoc($db_results)) {
- $in_sql .= "'" . $row['id'] . "',";
- $total++;
+ $art = new Art($row['id'], 'album');
+ $art->get_db();
+ if ($art->raw) {
+ $results[] = $row['id'];
+ }
}
- if ($total < $count) { return false; }
+ if (count($results) < $count) { return false; }
- $in_sql = rtrim($in_sql,',') . ')';
-
- $sql = "SELECT `album_id`,ISNULL(`art`) AS `no_art` FROM `album_data` WHERE $in_sql";
- $db_results = Dba::read($sql);
- $results = array();
-
- while ($row = Dba::fetch_assoc($db_results)) {
- $results[$row['album_id']] = $row['no_art'];
- } // end for
-
- asort($results);
- $albums = array_keys($results);
- $results = array_slice($albums,0,$count);
+ $results = array_slice($results, 0, $count);
return $results;
} // get_random_albums
- /**
- * get_image_from_source
- * This gets an image for the album art from a source as
- * defined in the passed array. Because we don't know where
- * its comming from we are a passed an array that can look like
- * ['url'] = URL *** OPTIONAL ***
- * ['file'] = FILENAME *** OPTIONAL ***
- * ['raw'] = Actual Image data, already captured
- */
- public static function get_image_from_source($data) {
-
- // Already have the data, this often comes from id3tags
- if (isset($data['raw'])) {
- return $data['raw'];
- }
-
- // If it came from the database
- if (isset($data['db'])) {
- // Repull it
- $album_id = Dba::escape($data['db']);
- $sql = "SELECT * FROM `album_data` WHERE `album_id`='$album_id'";
- $db_results = Dba::read($sql);
- $row = Dba::fetch_assoc($db_results);
- return $row['art'];
- } // came from the db
-
- // Check to see if it's a URL
- if (isset($data['url'])) {
- $snoopy = new Snoopy();
- if(Config::get('proxy_host') AND Config::get('proxy_port')) {
- $snoopy->proxy_user = Config::get('proxy_host');
- $snoopy->proxy_port = Config::get('proxy_port');
- $snoopy->proxy_user = Config::get('proxy_user');
- $snoopy->proxy_pass = Config::get('proxy_pass');
- }
- $snoopy->fetch($data['url']);
- return $snoopy->results;
- }
-
- // Check to see if it's a FILE
- if (isset($data['file'])) {
- $handle = fopen($data['file'],'rb');
- $image_data = fread($handle,filesize($data['file']));
- fclose($handle);
- return $image_data;
- }
-
- // Check to see if it is embedded in id3 of a song
- if (isset($data['song'])) {
- // If we find a good one, stop looking
- $getID3 = new getID3();
- $id3 = $getID3->analyze($data['song']);
-
- if ($id3['format_name'] == "WMA") {
- return $id3['asf']['extended_content_description_object']['content_descriptors']['13']['data'];
- }
- elseif (isset($id3['id3v2']['APIC'])) {
- // Foreach incase they have more then one
- foreach ($id3['id3v2']['APIC'] as $image) {
- return $image['data'];
- }
- }
- } // if data song
-
- return false;
-
- } // get_image_from_source
-
- /**
- * get_art_url
- * This returns the art URL for the album
- */
- public static function get_art_url($album_id,$sid=false) {
-
- $sid = $sid ? scrub_out($sid) : session_id();
-
- $sql = "SELECT `art_mime`,`thumb_mime` FROM `album_data` WHERE `album_id`='" . Dba::escape($album_id) . "'";
- $db_results = Dba::read($sql);
-
- $row = Dba::fetch_assoc($db_results);
-
- $mime = $row['thumb_mime'] ? $row['thumb_mime'] : $row['art_mime'];
-
- switch ($type) {
- case 'image/gif':
- $type = 'gif';
- break;
- case 'image/png':
- $type = 'png';
- break;
- default:
- case 'image/jpeg':
- $type = 'jpg';
- break;
- } // end type translation
-
- $name = 'art.' . $type;
-
- $url = Config::get('web_path') . '/image.php?id=' . scrub_out($album_id) . '&auth=' . $sid . '&name=' . $name;
-
- return $url;
-
- } // get_art_url
-
} //end of album class
?>