summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul 'flowerysong' Arthur <flowerysong00@yahoo.com>2010-05-05 01:43:51 +0000
committerPaul 'flowerysong' Arthur <flowerysong00@yahoo.com>2010-05-05 01:43:51 +0000
commite3e4c7246686ff44b84f7d4d48b205c6f780dde4 (patch)
treeca880eef0f820cd04385dc6cf92512d98d1b26ee
parenta7e1258587ecdc51923a5acb48887b9b4b96efcd (diff)
downloadampache-e3e4c7246686ff44b84f7d4d48b205c6f780dde4.tar.gz
ampache-e3e4c7246686ff44b84f7d4d48b205c6f780dde4.tar.bz2
ampache-e3e4c7246686ff44b84f7d4d48b205c6f780dde4.zip
Art work. Rationalise DB schema, support multiple thumbnail sizes and
caching thereof, call Catalog->gather_art instead of Catalog->gather_album_art, unbreak (hopefully) gather_musicbrainz.
-rw-r--r--admin/catalog.php2
-rw-r--r--bin/catalog_update.inc2
-rwxr-xr-xdocs/CHANGELOG1
-rw-r--r--image.php12
-rw-r--r--lib/class/art.class.php150
-rw-r--r--lib/class/catalog.class.php4
-rw-r--r--lib/class/update.class.php61
7 files changed, 174 insertions, 58 deletions
diff --git a/admin/catalog.php b/admin/catalog.php
index 9dee29eb..4239aa51 100644
--- a/admin/catalog.php
+++ b/admin/catalog.php
@@ -305,7 +305,7 @@ switch ($_REQUEST['action']) {
$catalog = new Catalog($catalog_id);
require Config::get('prefix') . '/templates/show_gather_art.inc.php';
flush();
- $catalog->get_album_art('',1);
+ $catalog->get_art('',1);
}
$url = Config::get('web_path') . '/admin/catalog.php';
$title = _('Album Art Search Finished');
diff --git a/bin/catalog_update.inc b/bin/catalog_update.inc
index 9d7b6277..a97ddf5f 100644
--- a/bin/catalog_update.inc
+++ b/bin/catalog_update.inc
@@ -125,7 +125,7 @@ while ($row = Dba::fetch_row($db_results)) {
// Look for album art
echo _('Starting Album Art Search');
echo "\n";
- $catalog->get_album_art('',1);
+ $catalog->get_art('',1);
echo "----------------\n\n";
}
diff --git a/docs/CHANGELOG b/docs/CHANGELOG
index 52a63525..228f5124 100755
--- a/docs/CHANGELOG
+++ b/docs/CHANGELOG
@@ -4,6 +4,7 @@
--------------------------------------------------------------------------
v.3.6-Alpha1
+ - Fixed support for requesting different thumbnail sizes
- Added ability to rate Albums of the Moment
- Added ability to edit/delete playlists while they are displayed
- Fix track numbers not being 0 padded when downloading or renaming.
diff --git a/image.php b/image.php
index ac91ad79..267e6f14 100644
--- a/image.php
+++ b/image.php
@@ -102,11 +102,13 @@ switch ($_GET['type']) {
readfile(Config::get('prefix') . Config::get('theme_path') . '/images/blankalbum.jpg');
break;
} // else no image
-
- if (!$art->thumb_mime) { unset($_GET['thumb']); }
-
- $mime = $_GET['thumb'] ? $art->thumb_mime : $art->raw_mime;
- $source = $_GET['thumb'] ? $art->thumb : $art->raw;
+
+ if ($_GET['thumb']) {
+ $thumb_data = $art->get_thumb($size);
+ }
+
+ $mime = $thumb_data ? $thumb_data['thumb_mime'] : $art->raw_mime;
+ $source = $thumb_data ? $thumb_data['thumb'] : $art->raw;
$extension = Art::extension($mime);
// Send the headers and output the image
diff --git a/lib/class/art.class.php b/lib/class/art.class.php
index 10d1abaa..6d1a22e9 100644
--- a/lib/class/art.class.php
+++ b/lib/class/art.class.php
@@ -42,7 +42,7 @@ class Art extends database_object {
* Art constructor, takes the UID of the object and the
* object type.
*/
- public function __construct($uid,$type) {
+ public function __construct($uid, $type) {
$this->type = Art::validate_type($type);
$this->uid = $uid;
@@ -74,7 +74,7 @@ class Art extends database_object {
*/
public static function extension($mime) {
- $data = explode("/",$mime);
+ $data = explode("/", $mime);
$extension = $data['1'];
if ($extension == 'jpeg') { $extension = 'jpg'; }
@@ -118,43 +118,47 @@ class Art extends database_object {
$type = Dba::escape($this->type);
$id = Dba::escape($this->uid);
- $sql = "SELECT `thumb`,`thumb_mime`,`art`,`art_mime` FROM `" . $type . "_data` WHERE `" . $type . "_id`='$id'";
+ $sql = "SELECT `image`, `mime`, `size` FROM `image` WHERE `object_type`='$type' AND `object_id`='$id'";
$db_results = Dba::read($sql);
- $results = Dba::fetch_assoc($db_results);
-
- // If we get nothing or there is non mime type return false
- if (!count($results) OR !strlen($results['art_mime'])) { return false; }
+ while ($results = Dba::fetch_assoc($db_results)) {
+ if ($results['size'] == 'original') {
+ $this->raw = $results['image'];
+ $this->raw_mime = $results['mime'];
+ }
+ else if (Config::get('resize_images') &&
+ $results['size'] == '275x275') {
+ $this->thumb = $results['image'];
+ $this->raw_mime = $results['mime'];
+ }
+ }
+ // If we get nothing return false
+ if (!$this->raw) { return false; }
- // If there is no thumb, and we want thumbs
- if (!strlen($results['thumb_mime']) AND Config::get('resize_images')) {
- $data = $this->generate_thumb($results['art'],array('width'=>275,'height'=>275),$results['art_mime']);
+ // If there is no thumb and we want thumbs
+ if (!$this->thumb && Config::get('resize_images')) {
+ $data = $this->generate_thumb($this->raw, array('width' => 275, 'height' => 275), $this->raw_mime);
// If it works save it!
if ($data) {
- $this->save_thumb($data['thumb'],$data['thumb_mime']);
- $results['thumb'] = $data['thumb'];
- $results['thumb_mime'] = $data['thumb_mime'];
+ $this->save_thumb($data['thumb'], $data['thumb_mime'], '275x275');
+ $this->thumb = $data['thumb'];
+ $this->thumb_mime = $data['thumb_mime'];
}
else {
- debug_event('Art','Unable to retrieve/generate thumbnail for ' . $type . '::' . $id,1);
+ debug_event('Art','Unable to retrieve or generate thumbnail for ' . $type . '::' . $id,1);
}
} // if no thumb, but art and we want to resize
- $this->raw = $results['art'];
- $this->raw_mime = $results['art_mime'];
- $this->thumb = $results['thumb'];
- $this->thumb_mime = $results['thumb_mime'];
-
return true;
} // get_db
/**
* insert
- * This takes the string representation of an image and inserts it into the database. You
- * must also pass the mime type
+ * This takes the string representation of an image and inserts it into
+ * the database. You must also pass the mime type.
*/
- public function insert($source,$mime) {
+ public function insert($source, $mime) {
// Disabled in demo mode cause people suck and upload porn
if (Config::get('demo_mode')) { return false; }
@@ -183,9 +187,11 @@ class Art extends database_object {
$uid = Dba::escape($this->uid);
$type = Dba::escape($this->type);
+ // Blow it away!
+ $this->reset();
+
// Insert it!
- $sql = "REPLACE INTO `" . $type . "_data` SET `art`='$image',`art_mime`='$mime', `" . $type . "_id`='$uid', " .
- "`thumb`=NULL, `thumb_mime`=NULL";
+ $sql = "INSERT INTO `image` (`image`, `mime`, `size`, `object_type`, `object_id`) VALUES('$image', '$mime', 'original', '$type', '$uid')";
$db_results = Dba::write($sql);
return true;
@@ -193,7 +199,7 @@ class Art extends database_object {
} // insert
/**
- * clear
+ * reset
* This resets the art in the database
*/
public function reset() {
@@ -201,17 +207,16 @@ class Art extends database_object {
$type = Dba::escape($this->type);
$uid = Dba::escape($this->uid);
- $sql = "UPDATE `" . $type . "_data` SET `art`=NULL, `art_mime`=NULL, `thumb`=NULL, `thumb_mime`=NULL " .
- "WHERE `" . $type . "_id`='$uid'";
+ $sql = "DELETE FROM `image` WHERE `object_id`='$uid' AND `object_type`='$type'";
$db_results = Dba::write($sql);
- } // clear
+ } // reset
/**
* save_thumb
- * This saves the thumbnail that we're passing
+ * This saves the thumbnail that we're passed
*/
- public function save_thumb($source,$mime) {
+ public function save_thumb($source, $mime, $size) {
// Quick sanity check
if (strlen($source) < 5 OR !strlen($mime)) {
@@ -221,16 +226,48 @@ class Art extends database_object {
$source = Dba::escape($source);
$mime = Dba::escape($mime);
+ $size = Dba::escape($size);
$uid = Dba::escape($this->uid);
$type = Dba::escape($this->type);
- $sql = "UPDATE `" . $type . "_data` SET `thumb`='$source', `thumb_mime`='$mime' " .
- "WHERE `" . $type . "_id`='$uid'";
+ $sql = "DELETE FROM `image` WHERE `object_id`='$uid' AND `object_type`='$type' AND `size`='$size'";
+ $db_results = Dba::write($sql);
+
+ $sql = "INSERT INTO `image` (`image`, `mime`, `size`, `object_type`, `object_id`) VALUES('$source', '$mime', '$size', '$type', '$uid')";
$db_results = Dba::write($sql);
} // save_thumb
/**
+ * get_thumb
+ * Returns the specified resized image. If the requested size doesn't
+ * already exist, create and cache it.
+ */
+ public function get_thumb($size) {
+ $sizetext = $size['width'] . 'x' . $size['height'];
+ $sizetext = Dba::escape($sizetext);
+ $type = Dba::escape($this->type);
+ $uid = Dba::escape($this->uid);
+
+ $sql = "SELECT `image`, `mime` FROM `image` WHERE `size`='$sizetext' AND `object_type`='$type' AND `object_id`='$uid'";
+ $db_results = Dba::read($sql);
+
+ $results = Dba::fetch_assoc($db_results);
+ if (count($results)) {
+ return array('thumb' => $results['image'],
+ 'thumb_mime' => $results['mime']);
+ }
+
+ // If we didn't get a result
+ $results = $this->generate_thumb($this->raw, $size, $this->raw_mime);
+ if ($results) {
+ $this->save_thumb($results['thumb'], $results['thumb_mime'], $sizetext);
+ }
+
+ return $results;
+ } // get_thumb
+
+ /**
* generate_thumb
* Automatically resizes the image for thumbnail viewing.
* Only works on gif/jpg/png/bmp. Fails if PHP-GD isn't available
@@ -271,12 +308,12 @@ class Art extends database_object {
return false;
}
- $source_size = array('height'=>imagesy($source),'width'=>imagesx($source));
+ $source_size = array('height' => imagesy($source), 'width' => imagesx($source));
// Create a new blank image of the correct size
- $thumbnail = imagecreatetruecolor($size['width'],$size['height']);
+ $thumbnail = imagecreatetruecolor($size['width'], $size['height']);
- if (!imagecopyresampled($thumbnail,$source,0,0,0,0,$size['width'],$size['height'],$source_size['width'],$source_size['height'])) {
+ if (!imagecopyresampled($thumbnail, $source, 0, 0, 0, 0, $size['width'], $size['height'], $source_size['width'], $source_size['height'])) {
debug_event('Art','Unable to create resized image',1);
return false;
}
@@ -288,7 +325,7 @@ class Art extends database_object {
switch ($type) {
case 'jpg':
case 'jpeg':
- imagejpeg($thumbnail,null,75);
+ imagejpeg($thumbnail, null, 75);
$mime_type = image_type_to_mime_type(IMAGETYPE_JPEG);
break;
case 'gif':
@@ -308,11 +345,11 @@ class Art extends database_object {
ob_end_clean();
if (!strlen($data)) {
- debug_event('Art','Unknown Error resizing art',1);
+ debug_event('Art', 'Unknown Error resizing art', 1);
return false;
}
- return array('thumb'=>$data,'thumb_mime'=>$mime_type);
+ return array('thumb' => $data, 'thumb_mime' => $mime_type);
} // generate_thumb
@@ -338,7 +375,7 @@ class Art extends database_object {
$uid = Dba::escape($data['db']);
$type = Dba::escape($this->type);
- $sql = "SELECT * FROM `" . $type . "_data` WHERE `" . $type . "_id`='$uid'";
+ $sql = "SELECT * FROM `image` WHERE `object_type`='$type' AND `object_id`='$uid' AND `size`='original'";
$db_results = Dba::read($sql);
$row = Dba::fetch_assoc($db_results);
return $row['art'];
@@ -398,17 +435,24 @@ class Art extends database_object {
$type = Dba::escape($type);
$uid = Dba::escape($uid);
- $sql = "SELECT `art_mime`,`thumb_mime` FROM `" . $type . "_data` WHERE `" . $type . "_id`='$uid'";
+ $sql = "SELECT `mime`,`size` FROM `image` WHERE `object_type`='$type' AND `object_id`='$uid'";
$db_results = Dba::read($sql);
- $row = Dba::fetch_assoc($db_results);
+ while ($row = Dba::fetch_assoc($db_results)) {
+ if ($row['size'] == 'original') {
+ $mime = $row['mime'];
+ }
+ else if ($row['size'] == '275x275' && Config::get('resize_images')) {
+ $thumb_mime = $row['mime'];
+ }
+ }
- $mime = $row['thumb_mime'] ? $row['thumb_mime'] : $row['art_mime'];
+ $mime = $thumb_mime ? $thumb_mime : $mime;
$extension = self::extension($mime);
-
+
$name = 'art.' . $extension;
$url = Config::get('web_path') . '/image.php?id=' . scrub_out($uid) . 'object_type=' . scrub_out($type) . '&auth=' . $sid . '&name=' . $name;
-
+
return $url;
} // url
@@ -491,20 +535,28 @@ class Art extends database_object {
/**
* gather_musicbrainz
- * This function retrives art based on MusicBrainz' Advanced Relationships
+ * This function retrieves art based on MusicBrainz' Advanced
+ * Relationships
*/
public function gather_musicbrainz($limit=0) {
- $images = array();
- $num_found = 0;
- $mbquery = new MusicBrainzQuery();
+ $images = array();
+ $num_found = 0;
+
+ if ($this->type == 'album') {
+ $album = new Album($this->uid);
+ }
+ else {
+ return $images;
+ }
- if ($this->mbid) {
+ if ($album->mbid) {
debug_event('mbz-gatherart', "Album MBID: " . $this->mbid, '5');
}
else {
return $images;
}
+ $mbquery = new MusicBrainzQuery();
$includes = new mbReleaseIncludes();
try {
$release = $mbquery->getReleaseByID($this->mbid, $includes->urlRelations());
diff --git a/lib/class/catalog.class.php b/lib/class/catalog.class.php
index 2bce9b51..03166b5d 100644
--- a/lib/class/catalog.class.php
+++ b/lib/class/catalog.class.php
@@ -709,7 +709,7 @@ class Catalog extends database_object {
// If they've enabled resizing of images generate the thumbnail now
if (Config::get('resize_images')) {
$thumb = $art->generate_thumb($image,array('width'=>275,'height'=>275),$results['0']['mime']);
- if (is_array($thumb)) { $art->save_thumb($thumb['thumb'],$thumb['thumb_mime']); }
+ if (is_array($thumb)) { $art->save_thumb($thumb['thumb'], $thumb['thumb_mime'], '275x275'); }
}
}
@@ -768,7 +768,7 @@ class Catalog extends database_object {
while ($row = Dba::fetch_assoc($db_results)) {
$art = new Art($row['album_id'],'album');
$data = $art->generate_thumb($row['art'],array('width'=>275,'height'=>275),$row['art_mime']);
- $art->save_thumb($data['thumb'],$data['thumb_mime']);
+ $art->save_thumb($data['thumb'], $data['thumb_mime'], '275x275');
/* Stupid little cutesie thing */
$thumb_count++;
diff --git a/lib/class/update.class.php b/lib/class/update.class.php
index 2fa2bb30..b54def3e 100644
--- a/lib/class/update.class.php
+++ b/lib/class/update.class.php
@@ -337,6 +337,9 @@ class Update {
$version[] = array('version'=>'360002','description'=>$update_string);
+ $update_string = '- Add image table to store images.<br />' .
+ '- Drop album_data and artist_data.<br />';
+ $version[] = array('version'=>'360003','description'=>$update_string);
return $version;
@@ -1871,6 +1874,64 @@ class Update {
} // update_360002
+ /**
+ * update_360003
+ * This update moves the image data to its own table.
+ */
+ public static function update_360003() {
+ $sql = "CREATE TABLE `image` (" .
+ "`id` int(11) unsigned NOT NULL auto_increment," .
+ "`image` mediumblob NOT NULL," .
+ "`mime` varchar(64) collate utf8_unicode_ci NOT NULL," .
+ "`size` varchar(64) collate utf8_unicode_ci NOT NULL," .
+ "`object_type` varchar(64) collate utf8_unicode_ci NOT NULL," .
+ "`object_id` int(11) unsigned NOT NULL," .
+ "PRIMARY KEY (`id`)," .
+ "KEY `object_type` (`object_type`)," .
+ "KEY `object_id` (`object_id`)" .
+ ") ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
+ $db_results = Dba::write($sql);
+
+ foreach (array('album', 'artist') as $type) {
+ $sql = "SELECT `" . $type . "_id` AS `object_id`, " .
+ "`art`, `art_mime` FROM `" . $type .
+ "_data` WHERE `art` IS NOT NULL";
+ $db_results = Dba::read($sql);
+ while ($row = Dba::fetch_assoc($db_results)) {
+ $sql = "INSERT INTO `image` " .
+ "(`image`, `mime`, `size`, " .
+ "`object_type`, `object_id`) " .
+ "VALUES('" . Dba::escape($row['art']) .
+ "', '" . $row['art_mime'] .
+ "', 'original', '" . $type . "', '" .
+ $row['object_id'] . "')";
+ $db_other_results = Dba::write($sql);
+ }
+ $sql = "DROP TABLE `" . $type . "_data`";
+ // $db_results = Dba::write($sql);
+ }
+
+ self::set_version('db_version','360003');
+
+ } // update_360003
+
+ /**
+ * update_360003
+ * This update adds the search table
+ */
+ public static function update_360003_b() {
+ $sql = "CREATE TABLE `search` (" .
+ "`id` INT( 11 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ," .
+ "`user` INT( 11 ) NOT NULL ," .
+ "`type` ENUM('private','public') DEFAULT NULL ," .
+ "`rules` VARCHAR( 65535 ) NOT NULL ," .
+ "`name` VARCHAR( 255 ) NOT NULL ," .
+ "`logic_operator` VARCHAR(3) NOT NULL " .
+ ") ENGINE = MYISAM ";
+ $db_results = Dba::write($sql);
+ self::set_version('db_version','360003');
+ } // update_360003
+
} // end update class
?>