diff options
author | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2006-12-28 22:56:55 +0000 |
---|---|---|
committer | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2006-12-28 22:56:55 +0000 |
commit | d6e28b752f3f04e418a4c27f37fa67b76596d5ec (patch) | |
tree | 7425e8a886db303672c97ccebc3d145bf5fa8b5d /albums.php | |
parent | 223143ed3a95ad59ff2945f6746da73992012354 (diff) | |
download | ampache-d6e28b752f3f04e418a4c27f37fa67b76596d5ec.tar.gz ampache-d6e28b752f3f04e418a4c27f37fa67b76596d5ec.tar.bz2 ampache-d6e28b752f3f04e418a4c27f37fa67b76596d5ec.zip |
* Added new Snoopy, fixes some minor bugs
* Rewrote Album Art collection, fixing tons of logic flaws, single album art find is currently broken
might even be a little faster now when using folder and id3 methods at the same time
* Fixed some issues with FastCGI installs
* Removed another upload file that wasn't used anymore
* Tweaked Recently Played to show 'played XXX ago'
Diffstat (limited to 'albums.php')
-rw-r--r-- | albums.php | 384 |
1 files changed, 185 insertions, 199 deletions
@@ -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&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&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&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> "; - echo "<a href=\"" . conf('web_path') . "/albums.php?action=show&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> "; + echo "<a href=\"" . conf('web_path') . "/albums.php?action=show&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(); ?> |