summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--albumart.php4
-rw-r--r--albums.php384
-rwxr-xr-xdocs/CHANGELOG3
-rw-r--r--lib/album.lib.php33
-rw-r--r--lib/class/album.class.php345
-rw-r--r--lib/class/catalog.class.php60
-rw-r--r--lib/init.php1
-rw-r--r--lib/upload.php264
-rw-r--r--modules/infotools/Snoopy.class.php2
-rw-r--r--templates/list_header.inc10
-rw-r--r--templates/show_album_art.inc.php5
-rw-r--r--templates/show_recently_played.inc.php2
12 files changed, 432 insertions, 681 deletions
diff --git a/albumart.php b/albumart.php
index 6905a3f2..aad36616 100644
--- a/albumart.php
+++ b/albumart.php
@@ -58,8 +58,8 @@ switch ($_REQUEST['type']) {
default:
$album = new Album($_REQUEST['id']);
- // Check db first
- $r = $album->get_art($_REQUEST['fast']);
+ // Attempt to pull art from the database
+ $r = $album->get_art();
if (isset($r->art)) {
$art = $r->art;
diff --git a/albums.php b/albums.php
index d7e21e5f..8eb91f1b 100644
--- a/albums.php
+++ b/albums.php
@@ -5,9 +5,8 @@
All Rights Reserved.
This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License
- as published by the Free Software Foundation; either version 2
- of the License, or (at your option) any later version.
+ modify it under the terms of the GNU General Public License v2
+ as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -20,10 +19,12 @@
*/
+
require_once('lib/init.php');
show_template('header');
+
// We'll set any input parameters here
if(!isset($_REQUEST['match'])) { $_REQUEST['match'] = "Browse"; }
if(isset($_REQUEST['match'])) $match = scrub_in($_REQUEST['match']);
@@ -35,236 +36,221 @@ if ($min_album_size == '') {
$min_album_size = '0';
}
-if ($_REQUEST['action'] === 'clear_art') {
- if (!$GLOBALS['user']->has_access('75')) { access_denied(); }
- $album = new Album($_REQUEST['album_id']);
- $album->clear_art();
- show_confirmation(_('Album Art Cleared'),_('Album Art information has been removed from the database'),"/albums.php?action=show&album=" . $album->id);
+$action = scrub_in($_REQUEST['action']);
-} // clear_art
-// if we have album
-elseif (isset($album)) {
- $album = new Album($_REQUEST['album']);
- $album->format_album();
- require (conf('prefix') . "/templates/show_album.inc");
-
- /* Get the song ids for this album */
- $song_ids = $album->get_song_ids($_REQUEST['artist']);
+/* Switch on Action */
+switch ($action) {
+ case 'clear_art':
+ if (!$GLOBALS['user']->has_access('75')) { access_denied(); }
+ $album = new Album($_REQUEST['album_id']);
+ $album->clear_art();
+ show_confirmation(_('Album Art Cleared'),_('Album Art information has been removed from the database'),"/albums.php?action=show&album=" . $album->id);
+ break;
+ case 'show':
+ $album = new Album($_REQUEST['album']);
+ $album->format();
+
+ require (conf('prefix') . '/templates/show_album.inc');
- show_songs($song_ids,0,$album);
+ /* Get the song ids for this album */
+ $song_ids = $album->get_song_ids($_REQUEST['artist']);
-} // isset(album)
-
-// Finds the Album art from amazon
-elseif ($_REQUEST['action'] === 'find_art') {
+ show_songs($song_ids,0,$album);
+ break;
+ // Upload album art
+ case 'upload_art':
+
+ // we didn't find anything
+ if (empty($_FILES['file']['tmp_name'])) {
+ show_confirmation(_('Album Art Not Located'),_('Album Art could not be located at this time. This may be due to write access error, or the file is not received corectly.'),"/albums.php?action=show&album=" . $album->id);
+ break;
+ }
- if (!$GLOBALS['user']->has_access('25')) { access_denied(); }
+ $album = new Album($_REQUEST['album_id']);
+
+ // Pull the image information
+ $data = array('file'=>$_FILES['file']['tmp_name']);
+ $image_data = get_image_from_source($data);
+
+ // If we got something back insert it
+ if ($image_data) {
+ $album->insert_art($image_data,$_FILES['file']['type']);
+ show_confirmation(_('Album Art Inserted'),'',"/albums.php?action=show&album=" . $album->id);
+ }
+ // Else it failed
+ else {
+ show_confirmation(_('Album Art Not Located'),_('Album Art could not be located at this time. This may be due to write access error, or the file is not received corectly.'),"/albums.php?action=show&album=" . $album->id);
+ }
+
+ break;
+ case 'find_art':
+
+ if (!$GLOBALS['user']->has_access('25')) { access_denied(); exit; }
- // csammis: In response to https://ampache.bountysource.com/Task.View?task_id=86,
- // adding retry to album art searching. I hope my PHP style doesn't make vollmer cry,
- // because that would make me cry...then my girlfriend would cry...then my cat would laugh.
- // She's such a little trouper!
- // *NOTE* I knocked it up a notch with some more horrible code :S - Vollmer
-
- if (!conf('amazon_developer_key')) {
- echo "<br /><div class=\"fatalerror\">" . _("Error") . ": " . _("No Amazon Developer Key set, amazon album art searching will not work") . "</div>";
- }
-
- // get the Album information
- $album = new Album($_REQUEST['album_id']);
+ // get the Album information
+ $album = new Album($_REQUEST['album_id']);
+
+ // Build the options for our search
+ if (isset($_REQUEST['artist_name'])) {
+ $artist = scrub_in($_REQUEST['artist_name']);
+ }
+ elseif ($album->artist_count == '1') {
+ $artist = $album->artist;
+ }
+ if (isset($_REQUEST['album_name'])) {
+ $album_name = scrub_in($_REQUEST['album_name']);
+ }
+ else {
+ $album_name = $album->name;
+ }
- if (isset($_REQUEST['artist_name'])) {
- $artist = scrub_in($_REQUEST['artist_name']);
- }
- elseif ($album->artist_count == '1') {
- $artist = $album->artist;
- }
-
- if (isset($_REQUEST['album_name'])) {
- $album_name = scrub_in($_REQUEST['album_name']);
- }
- else {
- $album_name = $album->name;
- }
+ $options['artist'] = $artist;
+ $options['album_name'] = $album_name;
+ $options['keyword'] = $artist . " " . $album_name;
+ $options['url'] = $_REQUEST['cover'];
- $search = $artist . " " . $album_name;
-
- //Find out if the cover url is a local filename or an url
- if (empty($_FILES['file']['tmp_name'])){
- $coverurl = $_REQUEST['cover'];
+ // Attempt to find the art.
+ $images = $album->find_art($options);
- // Attempt to find the art with what we've got
- $images = $album->find_art($_REQUEST['cover'], $search);
+ // Store the results for further use
$_SESSION['form']['images'] = $images;
-
+
if (count($images)) {
- include(conf('prefix') . '/templates/show_album_art.inc.php');
+ require_once(conf('prefix') . '/templates/show_album_art.inc.php');
}
else {
- show_confirmation(_('Album Art Not Located'),_('Album Art could not be located at this time. This may be due to Amazon being busy, or the album not being present in their collection.'),"/albums.php?action=show&amp;album=" . $album->id);
- }
-
+ show_confirmation(_('Album Art Not Located'),_('Album Art could not be located at this time. This may be due to write access error, or the file is not received corectly.'),"/albums.php?action=show&amp;album=" . $album->id);
+ }
+
$albumname = $album->name;
$artistname = $artist;
-
+
// Remember the last typed entry, if there was one
if (isset($_REQUEST['album_name'])) { $albumname = scrub_in($_REQUEST['album_name']); }
if (isset($_REQUEST['artist_name'])) { $artistname = scrub_in($_REQUEST['artist_name']); }
-
- include(conf('prefix') . '/templates/show_get_albumart.inc.php');
-
- }
- elseif (isset($_FILES['file']['tmp_name'])){
- $album_id = $_REQUEST['album_id'];
-
- $album = new Album($album_id);
-
- $dir = dirname($_FILES['file']['tmp_name']) . "/";
- $filename = $dir . basename($_FILES['file']['tmp_name']);
- $handle = fopen($filename, "rb");
- $mime = $_FILES['file']['type'];
- $art = '';
- while(!feof($handle)) {
- $art .= fread($handle, 1024);
- }
- fclose($handle);
- if (!empty($art)){
- $album->insert_art($art,$mime);
- show_confirmation(_('Album Art Inserted'),'',"/albums.php?action=show&album=$album_id");
- }
- else {
- show_confirmation(_('Album Art Not Located'),_('Album Art could not be located at this time. This may be due to write acces error, or the file is not received corectly.'),"/albums.php?action=show&amp;album=" . $album->id);
- }
+ require_once(conf('prefix') . '/templates/show_get_albumart.inc.php');
- }
+ break;
+ case 'select_art':
-
-} // find_art
-
-// Selecting image from find_art
-elseif ($_REQUEST['action'] === 'select_art') {
-
- /* Check to see if we have the image url still */
- $image_id = $_REQUEST['image'];
- $album_id = $_REQUEST['album_id'];
-
- $url = $_SESSION['form']['images'][$image_id]['url'];
- $mime = $_SESSION['form']['images'][$image_id]['mime'];
- $snoopy = new Snoopy();
- $snoopy->fetch($url);
+ /* Check to see if we have the image url still */
+ $image_id = $_REQUEST['image'];
+ $album_id = $_REQUEST['album_id'];
- $image_data = $snoopy->results;
+ $url = $_SESSION['form']['images'][$image_id]['url'];
+ $mime = $_SESSION['form']['images'][$image_id]['mime'];
+ $snoopy = new Snoopy();
+ $snoopy->fetch($url);
+
+ $image_data = $snoopy->results;
- $album = new Album($album_id);
- $album->insert_art($image_data,$mime);
-
- show_confirmation(_('Album Art Inserted'),'',"/albums.php?action=show&album=$album_id");
-
-
-} // end select art
-
-// Updates Album from tags
-elseif ($_REQUEST['action'] === 'update_from_tags') {
-
- $album = new Album($_REQUEST['album_id']);
-
- echo "<br /><b>" . _("Starting Update from Tags") . ". . .</b><br />\n";
-
- $catalog = new Catalog();
- $catalog->update_single_item('album',$_REQUEST['album_id']);
+ $album = new Album($album_id);
+ $album->insert_art($image_data,$mime);
- echo "<br /><b>" . _("Update From Tags Complete") . "</b> &nbsp;&nbsp;";
- echo "<a href=\"" . conf('web_path') . "/albums.php?action=show&amp;album=" . $_REQUEST['album_id'] . "\">[" . _("Return") . "]</a>";
+ show_confirmation(_('Album Art Inserted'),'',"/albums.php?action=show&album=$album_id");
-} // update_from_tags
+ break;
+ case 'update_from_tags':
+
+ $album = new Album($_REQUEST['album_id']);
-else {
+ show_box_top(_('Starting Update from Tags'));
- if (strlen($_REQUEST['match']) < '1') { $match = 'a'; }
+ $catalog = new Catalog();
+ $catalog->update_single_item('album',$_REQUEST['album_id']);
- // Setup the View Ojbect
- $view = new View();
- $view->import_session_view();
+ echo "<br /><b>" . _('Update From Tags Complete') . "</b> &nbsp;&nbsp;";
+ echo "<a href=\"" . conf('web_path') . "/albums.php?action=show&amp;album=" . scrub_out($_REQUEST['album_id']) . "\">[" . _('Return') . "]</a>";
+ show_box_bottom();
+ break;
+ // Browse by Album
+ default:
+ if (strlen($_REQUEST['match']) < '1') { $match = 'a'; }
- if ($match == 'Show_all' || $match == 'Show_missing_art' || $match == 'Browse') { $chr = ''; }
- else { $chr = $match; }
+ // Setup the View Ojbect
+ $view = new View();
+ $view->import_session_view();
- require (conf('prefix') . '/templates/show_box_top.inc.php');
- show_alphabet_list('albums','albums.php',$match);
- show_alphabet_form($chr,_('Show Albums starting with'),"albums.php?action=match");
- require (conf('prefix') . '/templates/show_box_bottom.inc.php');
+ if ($match == 'Show_all' || $match == 'Show_missing_art' || $match == 'Browse') { $chr = ''; }
+ else { $chr = $match; }
- switch($match) {
- case 'Show_all':
- $offset_limit = 99999;
- $sql = "SELECT album.id FROM song,album ".
- " WHERE song.album=album.id ".
- "GROUP BY song.album ".
- " HAVING COUNT(song.id) > $min_album_size ";
+ require (conf('prefix') . '/templates/show_box_top.inc.php');
+ show_alphabet_list('albums','albums.php',$match);
+ show_alphabet_form($chr,_('Show Albums starting with'),"albums.php?action=match");
+ require (conf('prefix') . '/templates/show_box_bottom.inc.php');
+
+ switch($match) {
+ case 'Show_all':
+ $offset_limit = 99999;
+ $sql = "SELECT album.id FROM song,album ".
+ " WHERE song.album=album.id ".
+ "GROUP BY song.album ".
+ " HAVING COUNT(song.id) > $min_album_size ";
break;
- case 'Show_missing_art':
- $offset_limit = 99999;
- $sql = "SELECT album.id FROM song,album ".
- " WHERE song.album=album.id ".
- " AND album.art is null ".
- "GROUP BY song.album ".
- " HAVING COUNT(song.id) > $min_album_size ";
+ case 'Show_missing_art':
+ $offset_limit = 99999;
+ $sql = "SELECT album.id FROM song,album ".
+ " WHERE song.album=album.id ".
+ " AND album.art is null ".
+ "GROUP BY song.album ".
+ " HAVING COUNT(song.id) > $min_album_size ";
break;
- case 'Browse':
- case 'show_albums':
- $sql = "SELECT album.id FROM song,album ".
- " WHERE song.album=album.id ".
- "GROUP BY song.album ".
- " HAVING COUNT(song.id) > $min_album_size ";
+ case 'Browse':
+ case 'show_albums':
+ $sql = "SELECT album.id FROM song,album ".
+ " WHERE song.album=album.id ".
+ "GROUP BY song.album ".
+ " HAVING COUNT(song.id) > $min_album_size ";
+ break;
+ default:
+ $sql = "SELECT album.id FROM song,album ".
+ " WHERE song.album=album.id ".
+ " AND album.name LIKE '$match%'".
+ "GROUP BY song.album ".
+ " HAVING COUNT(song.id) > $min_album_size ";
+ } // end switch
+
+ switch ($_REQUEST['type']) {
+ case 'album_sort':
+ if ($match != 'Browse' && $match != 'Show_missing_art' && $match != 'Show_all') {
+ $match_string = " AND album.name LIKE '$match%'";
+ }
+ $sort_sql = "SELECT album.id, IF(COUNT(DISTINCT(song.artist)) > 1,'Various', artist.name) AS artist_name " .
+ "FROM song,artist,album WHERE song.album=album.id AND song.artist=artist.id $match_string" .
+ "GROUP BY album.name,album.year ".
+ "HAVING COUNT(song.id) > $min_album_size ";
+ $sort_order = 'artist.name';
break;
- default:
- $sql = "SELECT album.id FROM song,album ".
- " WHERE song.album=album.id ".
- " AND album.name LIKE '$match%'".
- "GROUP BY song.album ".
- " HAVING COUNT(song.id) > $min_album_size ";
- } // end switch
-
- switch ($_REQUEST['type']) {
- case 'album_sort':
- if ($match != 'Browse' && $match != 'Show_missing_art' && $match != 'Show_all') {
- $match_string = " AND album.name LIKE '$match%'";
- }
- $sort_sql = "SELECT album.id, IF(COUNT(DISTINCT(song.artist)) > 1,'Various', artist.name) AS artist_name " .
- "FROM song,artist,album WHERE song.album=album.id AND song.artist=artist.id $match_string" .
- "GROUP BY album.name,album.year ".
- "HAVING COUNT(song.id) > $min_album_size ";
- $sort_order = 'artist.name';
- break;
- default:
-
- break;
- } // switch on special sort types
-
- // if we are returning
- if ($_REQUEST['keep_view']) {
- $view->initialize($sort_sql);
- }
-
- // If we aren't keeping the view then initlize it
- elseif ($sql) {
- if (!$sort_order) { $sort_order = 'name'; }
- $db_results = mysql_query($sql, dbh());
- $total_items = mysql_num_rows($db_results);
- if ($match != "Show_all") { $offset_limit = $_SESSION['userdata']['offset_limit']; }
- $view = new View($sql, 'albums.php',$sort_order,$total_items,$offset_limit);
- }
-
- else { $view = false; }
-
- if ($view->base_sql) {
- $albums = get_albums($view->sql);
- show_albums($albums,$view);
- }
-
-} // else no album
+ default:
+
+ break;
+ } // switch on special sort types
+
+ // if we are returning
+ if ($_REQUEST['keep_view']) {
+ $view->initialize($sort_sql);
+ }
+
+ // If we aren't keeping the view then initlize it
+ elseif ($sql) {
+ if (!$sort_order) { $sort_order = 'name'; }
+ $db_results = mysql_query($sql, dbh());
+ $total_items = mysql_num_rows($db_results);
+ if ($match != "Show_all") { $offset_limit = $_SESSION['userdata']['offset_limit']; }
+ $view = new View($sql, 'albums.php',$sort_order,$total_items,$offset_limit);
+ }
+
+ else { $view = false; }
+
+ if ($view->base_sql) {
+ $albums = get_albums($view->sql);
+ show_albums($albums,$view);
+ }
+
+ break;
+} // end switch on action
show_footer();
?>
diff --git a/docs/CHANGELOG b/docs/CHANGELOG
index c5ecdc7f..e19a937e 100755
--- a/docs/CHANGELOG
+++ b/docs/CHANGELOG
@@ -4,6 +4,9 @@
--------------------------------------------------------------------------
v.3.3.3-Beta3
+ - Rewrote Album Art collection to correct some seriou logic flaws
+ - Added potential fix for FastCGI installations
+ - Updated Snoopy to 1.2.3 (from manually patched 1.2.1)
- Fixed sorting of Themes, now sorted by Alpha of theme name
- Fixed long standing Now Playing display in Classic Theme
- Fixed Now Playing to account for Windows Media Player 11s
diff --git a/lib/album.lib.php b/lib/album.lib.php
index fc030163..891c1b24 100644
--- a/lib/album.lib.php
+++ b/lib/album.lib.php
@@ -24,6 +24,39 @@ function get_albums($sql, $action=0) {
} // get_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
+ */
+function get_image_from_source($data) {
+
+ // Already have the data, this often comes from id3tags
+ if (isset($data['raw'])) {
+ return $data['raw'];
+ }
+
+ // Check to see if it's a URL
+ if (isset($data['url'])) {
+ $snoopy = new Snoopy();
+ $snoopy->fetch($results['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;
+ }
+
+ return false;
+} // get_image_from_source
?>
diff --git a/lib/class/album.class.php b/lib/class/album.class.php
index 0279bb62..be13d7c8 100644
--- a/lib/class/album.class.php
+++ b/lib/class/album.class.php
@@ -36,6 +36,9 @@ class Album {
var $art;
var $art_mime;
+ // cached information
+ var $_songs=array();
+
/*!
@function Album
@discussion Album class, for modifing a song.
@@ -178,24 +181,29 @@ class Album {
/**
* get_art
- * This function should be called for gathering and returning Album Art
- * By default it ignores the DB and looks at the current gathering preferences
- * as defined by the config file and attempts to find the album art. If the
- * param FAST is passed then it will only check the database, if no art is
- * found it return false. This only return the first art found and should
- * not be used for the advanced album art finding functions, but for the
- * catalog
+ * This function only pulls art from the database, nothing else
+ * It should not be called when trying to find new art
*/
- function get_art($fast = 0) {
+ function get_art() {
- // If we are doing fast then only return
- // what's in the database
- if ($fast) {
- return $this->get_db_art();
- }
+ return $this->get_db_art();
+
+ } // get_art
+
+ /**
+ * find_art
+ * This function searches for album art using all configured methods
+ * for the current album. There is an optional 'limit' passed that will
+ * gather up to the specified number of possible album covers.
+ * There is also an optional array of options the possible options are
+ * ['keyword'] = STRING
+ * ['artist'] = STRING
+ * ['album_name'] = STRING
+ */
+ function find_art($options=array(),$limit=null) {
/* Create Base Vars */
- $album_art_order = array();
+ $results = array();
/* Attempt to retrive the album art order */
$config_value = conf('album_art_order');
@@ -203,80 +211,106 @@ class Album {
/* If it's not set */
if (empty($config_value)) {
- $album_art_order = array('id3','folder','amazon');
+ // They don't want art!
+ return false;
}
elseif (!is_array($config_value)) {
- array_push($album_art_order,$config_value);
- }
- else {
- $album_art_order = array_merge($album_art_order, conf('album_art_order'));
+ $config_value = array($config_value);
}
- foreach ($album_art_order AS $method) {
+ foreach ($config_value AS $method) {
$method_name = "get_" . $method . "_art";
if (in_array($method_name,$class_methods)) {
- if ($this->{$method_name}()) {
- return $this->get_db_art();
- } // if method finds the art
+ // Some of these take options!
+ switch ($method_name) {
+ case 'get_amazon_art':
+ $data = $this->{$method_name}($options['keyword']);
+ break;
+ case 'get_id3_art':
+ $data = $this->{$method_name}($limit);
+ break;
+ default:
+ $data = $this->{$method_name}();
+ break;
+ }
+
+ // Add the results we got to the current set
+ $total_results += count($data);
+ $results = array_merge($results,$data);
+
+ if ($total_results > $limit) {
+ return $results;
+ }
+
} // if the method exists
} // end foreach
- return false;
+ return $results;
- } // get_art
+ } // find_art
/*!
@function get_id3_art
@discussion looks for art from the id3 tags
*/
- function get_id3_art() {
+ function get_id3_art($limit='') {
- $songs = $this->get_songs();
+ // grab the songs and define our results
+ if (!count($this->_songs)) {
+ $this->_songs = $this->get_songs();
+ }
+ $data = array();
// Foreach songs in this album
- foreach ($songs as $song) {
+ foreach ($this->_songs as $song) {
+
// If we find a good one, stop looking
$getID3 = new getID3();
$id3 = $getID3->analyze($song->file);
if ($id3['format_name'] == "WMA") {
$image = $id3['asf']['extended_content_description_object']['content_descriptors']['13'];
+ $data[] = array('raw'=>$image['data'],'mime'=>$image['mime']);
}
- else {
- $image = $id3['id3v2']['APIC']['0'];
+ elseif (isset($id3['id3v2']['APIC'])) {
+ // Foreach incase they have more then one
+ foreach ($id3['id3v2']['APIC'] as $image) {
+ $data[] = array('raw'=>$image['data'],'mime'=>$image['mime']);
+ }
}
- if ($image) {
- $art = $image['data'];
- $mime = $image['mime'];
- // Stick it in the db for next time
- $this->insert_art($art,$mime);
-
- return true;
- } // end if image
+ if (!empty($limit) && $limit < count($data)) {
+ return $data;
+ }
+
} // end foreach
- return false;
+ return $data;
} // get_id3_art
- /*!
- @function get_folder_art()
- @discussion returns the album art from the folder of the mp3s
- */
- function get_folder_art() {
+ /**
+ * get_folder_art()
+ * returns the album art from the folder of the audio files
+ * If a limit is passed or the preferred filename is found the current results set
+ * is returned
+ */
+ function get_folder_art($limit='') {
- $songs = $this->get_songs();
+ if (!count($this->_songs)) {
+ $this->_songs = $this->get_songs();
+ }
+ $data = array();
/* See if we are looking for a specific filename */
$preferred_filename = conf('album_art_preferred_filename');
/* Thanks to dromio for origional code */
/* Added search for any .jpg, png or .gif - Vollmer */
- foreach($songs as $song) {
+ foreach($this->_songs as $song) {
$dir = dirname($song->file);
/* Open up the directory */
@@ -295,46 +329,33 @@ class Album {
if ($extension == "jpg" || $extension == "gif" || $extension == "png" || $extension == "jp2") {
if ($file == $preferred_filename) {
- $found = 1;
- $album_art_filename = array('file' => $file, 'ext' => $extension);
- break;
- }
- elseif (!$preferred_filename) {
- $found = 1;
- $album_art_filename = array('file' => $file, 'ext' => $extension);
- break;
+ // If we found the preferred filename we're done, wipe out previous results
+ $data = array(array('file' => $file, 'mime' => 'image/' . $extension));
+ return $data;
}
else {
- $found = 1;
- $album_art_filename = array('file' => $file, 'ext' => $extension);
+ $data[] = array('file' => $file, 'mime' => 'image/' . $extension);
}
} // end if it's an image
} // end while reading dir
@closedir($handle);
+
+ if (!empty($limit) && $limit < count($data)) {
+ return $data;
+ }
- if ($found) {
- $handle = fopen($dir."/".$album_art_filename['file'], "rb");
- $mime = "image/" . $album_art_filename['ext'];
- $art = '';
- while(!feof($handle)) {
- $art .= fread($handle, 1024);
- }
- fclose($handle);
- $this->insert_art($art,$mime);
- return true;
- } // if found
} // end foreach songs
- return false;
+ return $data;
} // get_folder_art()
- /*!
- @function get_db_art()
- @discussion returns the album art from the db
- */
+ /**
+ * get_db_art()
+ * returns the album art from the db along with the mime type
+ */
function get_db_art() {
$sql = "SELECT art,art_mime FROM album WHERE id='$this->id' AND art_mime IS NOT NULL";
@@ -345,100 +366,13 @@ class Album {
return $results;
} // get_db_art
-
-
- /*!
- @function get_amazon_art
- @discussion searches amazon for the
- album art
- */
- function get_amazon_art() {
-
- $results = $this->find_art();
-
- if (count($results) < 1) { return false; }
-
- $snoopy = new Snoopy();
- $snoopy->fetch($results['0']['url']);
- $data = $snoopy->results;
-
- $this->insert_art($data,$results['0']['mime']);
-
- return true;
-
- } // get_amazon_art
-
- /*!
- @function get_random_songs
- @discussion gets a random number, and
- a random assortment of songs from this
- album
- */
- function get_random_songs() {
-
- $results = array();
-
- $sql = "SELECT id FROM song WHERE album='$this->id' ORDER BY RAND()";
- $db_results = mysql_query($sql, dbh());
-
- while ($r = mysql_fetch_array($db_results)) {
- $results[] = $r[0];
- }
-
- return $results;
-
- } // get_random_songs
-
- /*!
- @function clear_art
- @discussion clears the album art from the DB
- */
- function clear_art() {
-
- $sql = "UPDATE album SET art=NULL, art_mime=NULL WHERE id='$this->id'";
- $db_results = mysql_query($sql, dbh());
-
- } // clear_art
-
- /*!
- @function insert_art
- @discussion this takes a string representation of an image
- and inserts it into the database. You must pass the
- mime type as well
- */
- function insert_art($image, $mime) {
-
- /* Have to disable this for Demo because people suck and try to
- * insert PORN :(
- */
- if (conf('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) == 1 || @imagesy($im) == 1 && $im) {
- return false;
- }
- } // if we have PHP:GD
-
- // Push the image into the database
- $sql = "UPDATE album SET art = '" . sql_escape($image) . "'," .
- " art_mime = '" . sql_escape($mime) . "'" .
- " WHERE id = '$this->id'";
- $db_results = mysql_query($sql, dbh());
- return true;
-
- } // insert_art
-
- /*!
- @function find_art
- @discussion searches amazon or a url
- for the album art
- @patch Added Keyword Support (csammis)
- @patch Added Variable Root Amazon Search (nhorloc)
- */
- function find_art($coverurl = '', $keywords = '') {
+ /**
+ * get_amazon_art
+ * This takes keywords and performs a search of the Amazon website
+ * for album art. It returns an array of found objects with mime/url keys
+ */
+ function get_amazon_art($keywords = '') {
$images = array();
$final_results = array();
@@ -447,9 +381,6 @@ class Album {
// Prevent the script from timing out
set_time_limit(0);
- // No coverurl specified search amazon
- if (empty($coverurl)) {
-
if (empty($keywords)) {
$keywords = $this->name;
/* If this isn't a various album combine with artist name */
@@ -498,13 +429,7 @@ class Album {
/* Log this if we're doin debug */
debug_event('amazon-xml',"Searched using $keywords with " . conf('amazon_developer_key') . " as key " . count($final_results) . " results found",'5');
} // end foreach
- } // if no cover
-
- // If we've specified a coverurl, create a fake Amazon array with it
- else {
- $final_results = array_merge($final_results, array(array('LargeImage' => $coverurl)));
- }
-
+
/* Foreach through what we've found */
foreach ($final_results as $result) {
@@ -533,11 +458,75 @@ class Album {
$images[] = $data;
} // if we've got something
-
- /* Default to false */
+
return $images;
- } // find_art
+ } // get_amazon_art()
+
+
+ /*!
+ @function get_random_songs
+ @discussion gets a random number, and
+ a random assortment of songs from this
+ album
+ */
+ function get_random_songs() {
+
+ $results = array();
+
+ $sql = "SELECT id FROM song WHERE album='$this->id' ORDER BY RAND()";
+ $db_results = mysql_query($sql, dbh());
+
+ while ($r = mysql_fetch_array($db_results)) {
+ $results[] = $r[0];
+ }
+
+ return $results;
+
+ } // get_random_songs
+
+ /*!
+ @function clear_art
+ @discussion clears the album art from the DB
+ */
+ function clear_art() {
+
+ $sql = "UPDATE album SET art=NULL, art_mime=NULL WHERE id='$this->id'";
+ $db_results = mysql_query($sql, dbh());
+
+ } // clear_art
+
+ /*!
+ @function insert_art
+ @discussion this takes a string representation of an image
+ and inserts it into the database. You must pass the
+ mime type as well
+ */
+ function insert_art($image, $mime) {
+
+ /* Have to disable this for Demo because people suck and try to
+ * insert PORN :(
+ */
+ if (conf('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) == 1 || @imagesy($im) == 1 && $im) {
+ return false;
+ }
+ } // if we have PHP:GD
+
+ // Push the image into the database
+ $sql = "UPDATE album SET art = '" . sql_escape($image) . "'," .
+ " art_mime = '" . sql_escape($mime) . "'" .
+ " WHERE id = '$this->id'";
+ $db_results = mysql_query($sql, dbh());
+
+ return true;
+
+ } // insert_art
+
} //end of album class
diff --git a/lib/class/catalog.class.php b/lib/class/catalog.class.php
index 347d6ef3..75702add 100644
--- a/lib/class/catalog.class.php
+++ b/lib/class/catalog.class.php
@@ -461,29 +461,25 @@ class Catalog {
// Run through them an get the art!
foreach ($albums as $album) {
flush();
- if ($debug) { echo "&nbsp;&nbsp;&nbsp;&nbsp;" . $album->name . " -- "; }
-
- if ($methods['id3']) {
- $found = $album->get_id3_art();
- if ($found && $debug) { echo _("Found in ID3") . "<br />\n"; }
- }
- if ($methods['amazon'] && !$found) {
- $found = $album->get_amazon_art();
- if ($found && $debug) { echo _("Found on Amazon") . "<br />\n"; }
- }
- if ($methods['folder'] && !$found) {
- $found = $album->get_folder_art();
- if ($found && $debug) { echo _("Found in Folder") . "<br />\n"; }
+ if (conf('debug')) {
+ debug_event('gather_art','Gathering art for ' . $album->name,'5');
}
- if (count($methods) == '0' && !$found) {
- $found = $album->get_art();
- if ($found && $debug) { echo _("Found") . "<br />\n"; }
- }
-
- if (!$found && $debug) { echo "<font class=\"error\">" . _("Not Found") . "</font><br />\n"; }
+ // Define the options we want to use for the find art function
+ $options = array(
+ 'album_name' => $album->name,
+ 'artist' => $album->artist,
+ 'keyword' => $album->artist . ' ' . $album->name
+ );
+
+ // Return results
+ $results = $album->find_art($options,1);
+
+ // Pull the string representation from the source
+ $image = get_image_from_source($results['0']);
+ $album->insert_art($image,$results['0']['mime']);
+
if ($found) { $art_found++; }
-
/* Stupid little cutesie thing */
$search_count++;
@@ -1635,21 +1631,23 @@ class Catalog {
$album_id = $song->album;
if ($info['change']) {
echo "<dl style=\"list-style-type:none;\">\n\t<li>";
- echo "<b>$song->file " . _("Updated") . "</b>\n";
+ echo "<b>$song->file " . _('Updated') . "</b>\n";
echo $info['text'];
- /* If we aren't doing a fast update re-gather album art */
- if ($gather_type != 'fast_update' AND !isset($searched_albums[$album_id])) {
- $album = new Album($song->album);
- $searched_albums[$album_id] = 1;
- $found = $album->get_art();
- unset($album);
- if ($found) { $is_found = _(" FOUND"); }
+ $album = new Album($song->album);
+
+ if (!$album->has_art) {
+ $found = $album->find_art($options,1);
+ if (count($found)) {
+ $image = get_image_from_source($found['0']);
+ $album->insert_art($image,$found['mime']);
+ $is_found = _(' FOUND');
+ }
echo "<br /><b>" . _('Searching for new Album Art') . ". . .$is_found</b><br />\n";
unset($found,$is_found);
- }
- elseif (isset($searched_albums[$album_id])) {
+ }
+ else {
echo "<br /><b>" . _('Album Art Already Found') . ". . .</b><br />\n";
- }
+ }
echo "\t</li>\n</dl>\n<hr align=\"left\" width=\"50%\" />\n";
flush();
$total_updated++;
diff --git a/lib/init.php b/lib/init.php
index a3c9e98d..b7fbdac1 100644
--- a/lib/init.php
+++ b/lib/init.php
@@ -154,7 +154,6 @@ require_once(conf('prefix') . '/lib/batch.lib.php');
require_once(conf('prefix') . '/lib/themes.php');
require_once(conf('prefix') . '/lib/stream.lib.php');
require_once(conf('prefix') . '/lib/playlist.lib.php');
-require_once(conf('prefix') . '/lib/upload.php');
require_once(conf('prefix') . '/lib/democratic.lib.php');
require_once(conf('prefix') . '/modules/lib.php');
require_once(conf('prefix') . '/modules/catalog.php');
diff --git a/lib/upload.php b/lib/upload.php
deleted file mode 100644
index 9390d519..00000000
--- a/lib/upload.php
+++ /dev/null
@@ -1,264 +0,0 @@
-<?php
-/*
-
- Copyright (c) 2001 - 2006 Ampache.org
- All Rights Reserved
-
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License
- as published by the Free Software Foundation; either version 2
- of the License, or (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-
-*/
-
-/*!
- @function check_upload_extension
- @discussion checks the extension against the allow list
-*/
-function check_upload_extension($name='file') {
-
-
- $filename = $_FILES[$name]['name'];
-
- $path_parts = pathinfo($filename);
-
- $extension = $path_parts['extension'];
-
- $allowed_extensions = "/" . conf('catalog_file_pattern') . "/";
- if (preg_match($allowed_extensions,$extension)) {
- return true;
- }
-
- debug_event('upload',"Error: Invalid Extension $extension",'2');
-
- return false;
-
-} // check_upload_extension
-
-/*!
- @function check_upload_size
- @discussion checks the filesize of the upload
-*/
-function check_upload_size($name='file') {
- static $total_size;
-
- $size = $_FILES[$name]['size'];
-
- $total_size = $total_size + $size;
-
- if ($size > conf('max_upload_size')) {
- debug_event('upload',"Error: Upload to large, $size",'2');
- return false;
- }
-
- if ($total_size > conf('max_upload_size')) {
- debug_event('upload',"Error: Total Upload to large, $total_size",'2');
- return false;
- }
-
- return true;
-
-} // check_upload_size
-
-/*!
- @function check_upload_directory
- @discussion this functions checks to make sure that you can actually write to the upload directory
-*/
-function check_upload_directory($directory) {
-
- /* We need to make sure we can write to said dir */
- if (@is_writable($directory)) {
- return true;
- }
-
- return false;
-
-} // check_upload_directory
-
-/*!
- @function find_upload_catalog
- @dicussion all upload directories must be contained within another catalog, this checks
- to make sure that is true. returns id of catalog found or false
-*/
-function find_upload_catalog($directory) {
-
- $sql = "SELECT id, path FROM catalog";
- $db_results = mysql_query($sql, dbh());
-
- while( $results = mysql_fetch_assoc($db_results)) {
-
- $catalog_path = str_replace("\\","/",$results['path']);
-
- $directory = str_replace("\\","/",$directory);
- if (strncmp($directory,$catalog_path,strlen($catalog_path)) == '0') {
- return $results['id'];
- }
-
- } // end while loop through catalog records
-
- return false;
-
-} // find_upload_catalog
-
-/*!
- @function upload_file
- @discussion this uploads a file to ampache
-*/
-function upload_file($file,$target_directory) {
-
- /* Build target file names */
- $full_filename = $target_directory . "/" . $_FILES[$file]['name'];
-
- /* Check to make sure the file doesn't exist already */
- if (file_exists($full_filename)) {
- $GLOBALS['error']->add_error($file,"Error: $full_filename already exists");
- return false;
- }
-
- /* Attempt to move the file */
- if (!$upload_code = @move_uploaded_file($_FILES[$file]['tmp_name'],$full_filename)) {
- $GLOBALS['error']->add_error($file,"Error: Unable to move $full_filename");
- return false;
- }
-
- return $full_filename;
-
-} // upload_file
-
-/*!
- @function insert_quarantine_record
- @discussion this inserts the record that a file has been added
-*/
-function insert_quarantine_record($username,$action,$filename) {
-
- /* First make sure this file isn't listed already */
- $sql = "SELECT id FROM " . tbl_name('upload') . " WHERE file='" . sql_escape($filename) . "'";
- $db_results = mysql_query($sql, dbh());
-
- /* If no rows, insert using ugly sql statement */
- if (!mysql_num_rows($db_results)) {
- $sql = "INSERT INTO " . tbl_name('upload') . " (`user`,`file`,`action`,`addition_time`)" .
- " VALUES ('$username','" . sql_escape($filename) . "','$action','" . time() . "')";
- $db_results = mysql_query($sql, dbh());
- }
-
- else {
- $sql = "UPDATE " . tbl_name('upload') . " SET action='$action' WHERE file='" . sql_escape($filename) . "'";
- $db_results = mysql_query($sql, dbh());
- }
-
-} // insert_quarantine_record
-
-/*!
- @function update_quarantine_record
- @discusison this updates an existing quarantine record
-*/
-function update_quarantine_record($id, $new_action) {
-
- $sql = "UPDATE " . tbl_name('upload') . " SET action='$new_action' WHERE id='" . sql_escape($id) . "'";
- $db_results = mysql_query($sql, dbh());
-
- return true;
-
-} // update_quarantine_record
-
-/*!
- @function get_uploads
- @discussion gets uploads and returns an array of em
-*/
-function get_uploads() {
-
- $sql = "SELECT * FROM " . tbl_name('upload');
- $db_results = mysql_query($sql, dbh());
-
- $results = array();
-
- while ($r = mysql_fetch_assoc($db_results)) {
-
- /* Create the vainfo object and get info */
- $vainfo = new vainfo($r['file']);
- $vainfo->get_info();
- $data = $vainfo->tags;
-
- $key = get_tag_type($vainfo->tags);
-
- /* Fill Empty info from filename/path */
- $data = clean_tag_info($vainfo->tags,$key,$r['file']);
-
- $data['id'] = $r['id'];
- $data['user'] = $r['user'];
- $data['action'] = $r['action'];
- $data['addition_time'] = $r['addition_time'];
-
- $results[] = $data;
-
- } // end while
-
- return $results;
-
-} // get_uploads
-
-/*!
- @function show_upload
- @discussion This shows the upload templates
-*/
-function show_upload() {
-
- require_once( "templates/show_upload.inc" );
- echo( "\n<br /><br />\n" );
- require_once( "templates/show_uploads.inc" );
-
-} // show_upload
-
-/*!
- @function report_file_error
- @discussion use with $_FILES and move_uploaded_file
- if move_uploaded_file returns false (error), pass
- $file['error'] here for interpretation
-*/
-function report_file_error( $error_code ) {
-
- $codes = array(
- 0 => _( "The file uploaded successfully" ),
- 1 => _( "The uploaded file exceeds the upload_max_filesize directive in php.ini" ),
- 2 => _( "The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form" ),
- 3 => _( "The uploaded file was only partially uploaded" ),
- 4 => _( "No file was uploaded" ),
- 6 => _( "Missing a temporary folder" )
- );
-
- return $codes[$error_code];
-
-} // report_file_error
-
-
-/**
- * show_upload_status_style
- * Pure fluf, it shows Grey for 'unknown' Green for Add and Red for delete
- */
-function show_upload_status_style($action) {
-
- switch ($action) {
- case 'add':
- return 'width:10px;background:green;';
- break;
- case 'delete':
- return 'width:10px;background:red;';
- break;
- default:
- return 'width:10px;';
- break;
- } // end switch
-
-} // show_upload_status_style
-
-?>
diff --git a/modules/infotools/Snoopy.class.php b/modules/infotools/Snoopy.class.php
index f625f67a..77e5b731 100644
--- a/modules/infotools/Snoopy.class.php
+++ b/modules/infotools/Snoopy.class.php
@@ -1013,7 +1013,7 @@ class Snoopy
$headerfile = tempnam($temp_dir, "sno");
$safer_URI = strtr( $URI, "\"", " " ); // strip quotes from the URI to avoid shell access
- exec(escapeshellcmd($this->curl_path." -D \"$headerfile\"".$cmdline_params." \"".$safer_URI."\""),$results,$return);
+ exec($this->curl_path." -D \"$headerfile\"".$cmdline_params." \"".$safer_URI."\"",$results,$return);
if($return)
{
diff --git a/templates/list_header.inc b/templates/list_header.inc
index 58c7fa61..257c5220 100644
--- a/templates/list_header.inc
+++ b/templates/list_header.inc
@@ -88,8 +88,16 @@ while ($page <= $pages) {
ksort($page_data['up']);
ksort($page_data['down']);
-/* Take the script name and passed action and setup the next action */
+/* Detect the current script, this take a little work because we have to
+ * account for FastCGI
+ */
preg_match("/.*\/(.+\.php)$/", $_SERVER['SCRIPT_NAME'], $matches);
+// Must be running Fast CGI or something similar
+if (!isset($matches['1'])) {
+ // Try PHP_SELF
+ preg_match("/.*\/(.+\.php)$/",$_SERVER['PHP_SELF'],$matches);
+}
+
$action = "action=" . scrub_in($_REQUEST['action']);
$script = conf('web_path') . "/" . $admin_menu . $matches[1];
diff --git a/templates/show_album_art.inc.php b/templates/show_album_art.inc.php
index a386b353..102a2698 100644
--- a/templates/show_album_art.inc.php
+++ b/templates/show_album_art.inc.php
@@ -5,9 +5,8 @@
All rights reserved.
This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License
- as published by the Free Software Foundation; either version 2
- of the License, or (at your option) any later version.
+ modify it under the terms of the GNU General Public License v2
+ as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
diff --git a/templates/show_recently_played.inc.php b/templates/show_recently_played.inc.php
index 3693dc27..e30ee53e 100644
--- a/templates/show_recently_played.inc.php
+++ b/templates/show_recently_played.inc.php
@@ -35,7 +35,7 @@ $time_unit = array('',_('seconds ago'),_('minutes ago'),_('hours ago'),_('days a
<?php foreach ($data as $row) {
$row_user = new User($row['user']);
$song = new Song($row['object_id']);
- $amount = intval(time() - $row['date']);
+ $amount = intval(time() - $row['date']+2);
$time_place = '0';
while ($amount >= 1) {