From 19276f57a9eeacae7829629baa35fcb28d77419f Mon Sep 17 00:00:00 2001 From: Karl 'vollmerk' Vollmer Date: Mon, 4 Jun 2007 02:45:03 +0000 Subject: fixed genre and artist view... mostly also fixed batch downloads --- batch.php | 7 ++- browse.php | 35 +++------------ lib/batch.lib.php | 2 +- lib/class/album.class.php | 3 +- lib/class/artist.class.php | 22 +++++---- lib/class/browse.class.php | 10 +++++ lib/class/catalog.class.php | 46 +++++++------------ lib/class/genre.class.php | 87 ++++++++++++------------------------ server/ajax.server.php | 20 +++++++-- stats.php | 4 +- templates/footer.inc.php | 7 +-- templates/header.inc.php | 4 +- templates/show_albums.inc.php | 2 + templates/show_artists.inc.php | 44 +++++++++--------- templates/show_genres.inc.php | 28 ++++++------ templates/show_playlist_bar.inc.php | 5 +++ templates/sidebar_home.inc.php | 4 ++ themes/classic/templates/default.css | 10 ++--- 18 files changed, 158 insertions(+), 182 deletions(-) diff --git a/batch.php b/batch.php index f64ce002..4e974cfd 100644 --- a/batch.php +++ b/batch.php @@ -33,7 +33,7 @@ set_time_limit(0); switch ($_REQUEST['action']) { case 'tmp_playlist': $tmpPlaylist = new tmpPlaylist($_REQUEST['id']); - $song_ids = $tmpPlaylist->get_objects(); + $song_ids = $tmpPlaylist->get_items(); $name = $GLOBALS['user']->username . ' - Playlist'; break; case 'playlist': @@ -46,6 +46,11 @@ switch ($_REQUEST['action']) { $song_ids = $album->get_songs(); $name = $album->name; break; + case 'artist': + $artist = new Artist($_REQUEST['id']); + $song_ids = $artist->get_songs(); + $name = $artist->name; + break; case 'genre': $id = scrub_in($_REQUEST['id']); $genre = new Genre($id); diff --git a/browse.php b/browse.php index ea594156..2e002936 100644 --- a/browse.php +++ b/browse.php @@ -47,42 +47,19 @@ switch($_REQUEST['action']) { Browse::show_objects($album_ids); break; case 'artist': - show_alphabet_list('artists','artists.php'); - show_alphabet_form('',_("Show Artists starting with"),"artists.php?action=match"); - show_artists(); + Browse::set_type('artist'); + $artist_ids = Browse::get_objects(); + Browse::show_objects($artist_ids); break; case 'genre': - /* Create the Needed Object */ - $genre = new Genre(); - - /* Setup the View object */ - $view = new View(); - $view->import_session_view(); - $genre->show_match_list($_REQUEST['match']); - $sql = $genre->get_sql_from_match($_REQUEST['match']); - - if ($_REQUEST['keep_view']) { - $view->initialize(); - } - else { - $db_results = mysql_query($sql, dbh()); - $total_items = mysql_num_rows($db_results); - $offset_limit = 999999; - if ($match != 'Show_All') { $offset_limit = $user->prefs['offset_limit']; } - $view = new View($sql, 'browse.php?action=genre','name',$total_items,$offset_limit); - } - - if ($view->base_sql) { - $genres = $genre->get_genres($view->sql); - show_genres($genres,$view); - } - + Browse::set_type('genre'); + $genre_ids = Browse::get_objects(); + Browse::show_objects($genre_ids); break; case 'song': Browse::set_type('song'); $song_ids = Browse::get_objects(); Browse::show_objects($song_ids); - break; case 'catalog': diff --git a/lib/batch.lib.php b/lib/batch.lib.php index 6666cbb1..4c83deb3 100644 --- a/lib/batch.lib.php +++ b/lib/batch.lib.php @@ -52,7 +52,7 @@ function get_song_files( $song_ids ) { function send_zip( $name, $song_files ) { /* Require needed library */ - require_once(conf('prefix') . '/modules/archive/archive.lib.php' ); + require_once Config::get('prefix') . '/modules/archive/archive.lib.php'; $arc = new zip_file( $name . ".zip" ); $options = array( 'inmemory' => 1, // create archive in memory diff --git a/lib/class/album.class.php b/lib/class/album.class.php index d801c518..513256d6 100644 --- a/lib/class/album.class.php +++ b/lib/class/album.class.php @@ -374,7 +374,8 @@ class Album { /* Thanks to dromio for origional code */ /* Added search for any .jpg, png or .gif - Vollmer */ - foreach($this->_songs as $song) { + foreach($this->_songs as $song_id) { + $song = new Song($song_id); $dir = dirname($song->file); debug_event('folder_art',"Opening $dir and checking for Album Art",'3'); diff --git a/lib/class/artist.class.php b/lib/class/artist.class.php index ee2aad62..7a07785d 100644 --- a/lib/class/artist.class.php +++ b/lib/class/artist.class.php @@ -95,7 +95,7 @@ class Artist { * get_songs * gets the songs for this artist */ - function get_songs() { + public function get_songs() { $sql = "SELECT `song`.`id` FROM `song` WHERE `song`.`artist`='" . Dba::escape($this->id) . "'"; $db_results = Dba::query($sql); @@ -126,21 +126,19 @@ class Artist { } // get_song_ids - /*! - @function get_random_songs - @discussion gets a random number, and - a random assortment of songs from this - album - */ - function get_random_songs() { + /** + * get_random_songs + * Gets the songs from this artist in a random order + */ + public function get_random_songs() { $results = array(); - $sql = "SELECT id FROM song WHERE artist='$this->id' ORDER BY RAND() LIMIT " . rand(1,$this->songs); - $db_results = mysql_query($sql, dbh()); + $sql = "SELECT `id` FROM `song` WHERE `artist`='$this->id' ORDER BY RAND()"; + $db_results = Dba::query($sql); - while ($r = mysql_fetch_array($db_results)) { - $results[] = $r[0]; + while ($r = Dba::fetch_assoc($db_results)) { + $results[] = $r['id']; } return $results; diff --git a/lib/class/browse.class.php b/lib/class/browse.class.php index 8cfb27d6..8613559f 100644 --- a/lib/class/browse.class.php +++ b/lib/class/browse.class.php @@ -303,6 +303,16 @@ class Browse { require_once Config::get('prefix') . '/templates/show_albums.inc.php'; show_box_bottom(); break; + case 'genre': + show_box_top(); + require_once Config::get('prefix') . '/templates/show_genres.inc.php'; + show_box_bottom(); + break; + case 'artist': + show_box_top(); + require_once Config::get('prefix') . '/templates/show_artists.inc.php'; + show_box_bottom(); + break; default: // Rien a faire break; diff --git a/lib/class/catalog.class.php b/lib/class/catalog.class.php index f9ed1969..06e786f7 100644 --- a/lib/class/catalog.class.php +++ b/lib/class/catalog.class.php @@ -83,7 +83,7 @@ class Catalog { /** * get_catalogs - * Pull all the current catalogs and return an array of objects + *Pull all the current catalogs */ public static function get_catalogs() { @@ -192,24 +192,11 @@ class Catalog { // Catalog Add start $start_time = time(); - // Setup the 10 sec ajax request hotness - $refresh_limit = 5; - $ajax_url = Config::get('ajax_url') . '?action=catalog&type=add_files'; - /* Can't have the & stuff in the Javascript */ - $ajax_url = str_replace("&","&",$ajax_url); - require_once Config::get('prefix') . '/templates/javascript_refresh.inc.php'; - - show_box_top(); - echo _('Starting New Song Search on') . " [$this->name] " . _('catalog') . "
"; - echo "
"; - require_once Config::get('prefix') . '/templates/show_run_add_catalog.inc.php'; - echo "
"; - echo ""; - show_box_bottom(); + require Config::get('prefix') . '/templates/show_adds_catalog.inc.php'; + flush(); // Prevent the script from timing out and flush what we've got set_time_limit(0); - flush(); $this->add_files($this->path,$options); @@ -410,13 +397,12 @@ class Catalog { /* Stupid little cutesie thing */ $this->count++; - if ( !($this->count%Config::get('catalog_echo_count'))) { - $sql = "REPLACE INTO `update_info` (`key`,`value`) " . - "VALUES('catalog_add_found','$this->count')"; - $db_results = Dba::query($sql); - $sql = "REPLACE INTO `update_info` (`key`,`value`) " . - "VALUES('catalog_add_directory','" . Dba::escape($path) . "')"; - $db_results = Dba::query($sql); + if ( !($this->count%10)) { + $file = str_replace(array('(',')','\''),'',$full_file); + echo "\n"; } // update our current state } // not found @@ -1014,13 +1000,11 @@ class Catalog { /* Do a little stats mojo here */ $current_time = time(); - - if ($verbose) { - echo "\n" . _('Starting Album Art Search') . ". . .
\n"; - echo _('Searched') . ": id . "\">" . _('None') . ""; - flush(); - } - $this->get_album_art(); + + $catalog_id = $this->id; + require Config::get('prefix') . '/templates/show_gather_art.inc.php'; + flush(); + $this->get_album_art(0,1); /* Update the Catalog last_update */ $this->update_last_add(); @@ -1036,8 +1020,10 @@ class Catalog { $this->count = 0; } + show_box_top(); echo "\n
" . _("Catalog Update Finished") . "... " . _("Total Time") . " [" . date("i:s",$time_diff) . "] " . _("Total Songs") . " [" . $this->count . "] " . _("Songs Per Seconds") . " [" . $song_per_sec . "]

"; + show_box_bottom(); } // add_to_catalog diff --git a/lib/class/genre.class.php b/lib/class/genre.class.php index 3d193be2..b2eac58a 100644 --- a/lib/class/genre.class.php +++ b/lib/class/genre.class.php @@ -1,7 +1,7 @@ 0) { - $this->id = intval($genre_id); - $info = $this->_get_info(); - $this->name = $info['name']; - } + public function __construct($genre_id=0) { + + if (!$genre_id) { return false; } + + $this->id = intval($genre_id); + $info = $this->_get_info(); + $this->name = $info['name']; } // Genre @@ -49,50 +47,44 @@ class Genre { /** * Private Get Info * This simply returns the information for this genre - * @package Genre - * @catagory Class */ - function _get_info() { + private function _get_info() { - $sql = "SELECT * FROM " . tbl_name('genre') . " WHERE id='$this->id'"; - $db_results = mysql_query($sql, dbh()); + $sql = "SELECT * FROM `genre` WHERE `id`='$this->id'"; + $db_results = Dba::query($sql); - $results = mysql_fetch_assoc($db_results); + $results = Dba::fetch_assoc($db_results); return $results; - } // _get_info() + } // _get_info /** * format_genre * this reformats the genre object so it's all purdy and creates a link var - * @package Genre - * @catagory Class */ - function format_genre() { + public function format_genre() { - $this->link = "id . "\">" . scrub_out($this->name) . ""; + $this->link = "id . "\">" . scrub_out($this->name) . ""; - $this->play_link = conf('web_path') . '/song.php?action=genre&genre=' . $this->id; - $this->random_link = conf('web_path') . '/song.php?action=random_genre&genre=' . $this->id; - $this->download_link = conf('web_path') . '/batch.php?action=genre&id=' . $this->id; + $this->play_link = Config::get('web_path') . '/song.php?action=genre&genre=' . $this->id; + $this->random_link = Config::get('web_path') . '/song.php?action=random_genre&genre=' . $this->id; + $this->download_link = Config::get('web_path') . '/batch.php?action=genre&id=' . $this->id; } // format_genre /** * get_song_count * This returns the number of songs in said genre - * @package Genre - * @catagory Class */ - function get_song_count() { + public function get_song_count() { - $sql = "SELECT count(song.id) FROM song WHERE genre='" . $this->id . "'"; - $db_results = mysql_query($sql, dbh()); - - $total_items = mysql_fetch_array($db_results); + $sql = "SELECT count(`song`.`id`) AS `total` FROM `song` WHERE `genre`='" . $this->id . "'"; + $db_results = Dba::query($sql); - return $total_items[0]; + $total_items = Dba::fetch_assoc($db_results); + + return $total_items['total']; } // get_song_count @@ -251,14 +243,14 @@ class Genre { case 'Show_All': case 'show_all': case 'Show_all': - $sql = "SELECT id FROM genre"; + $sql = "SELECT `id` FROM `genre`"; break; case 'Browse': case 'show_genres': - $sql = "SELECT id FROM genre"; + $sql = "SELECT `id` FROM `genre`"; break; default: - $sql = "SELECT id FROM genre WHERE name LIKE '" . sql_escape($match) . "%'"; + $sql = "SELECT `id` FROM `genre` WHERE `name` LIKE '" . Dba::escape($match) . "%'"; break; } // end switch on match @@ -266,27 +258,6 @@ class Genre { } // get_sql_from_match - - /** - * show_match_list - * This shows the Alphabet list and any other 'things' that genre by need at the top of every browse - * page - * @package Genre - * @catagory Class - */ - function show_match_list($match) { - - - - require (conf('prefix') . '/templates/show_box_top.inc.php'); - show_alphabet_list('genre','browse.php',$match,'genre'); - /* Detect if it's Browse, and if so don't fill it in */ - if ($match == 'Browse') { $match = ''; } - show_alphabet_form($match,_('Show Genres starting with'),"browse.php?action=genre&match=$match"); - require (conf('prefix') . '/templates/show_box_bottom.inc.php'); - - } // show_match_list - } //end of genre class ?> diff --git a/server/ajax.server.php b/server/ajax.server.php index 4f60573b..50368e9b 100644 --- a/server/ajax.server.php +++ b/server/ajax.server.php @@ -76,19 +76,31 @@ switch ($action) { case 'basket': switch ($_REQUEST['type']) { case 'album': - $album = new Album($_REQUEST['id']); - $songs = $album->get_songs(); + case 'artist': + case 'genre': + $object = new $_REQUEST['type']($_REQUEST['id']); + $songs = $object->get_songs(); foreach ($songs as $song_id) { $GLOBALS['user']->playlist->add_object($song_id); } // end foreach break; case 'album_random': - $album = new Album($_REQUEST['id']); - $songs = $album->get_random_songs(); + case 'artist_random': + case 'genre_random': + $data = explode('_',$_REQUEST['type']); + $type = $data['0']; + $object = new $type($_REQUEST['id']); + $songs = $object->get_random_songs(); foreach ($songs as $song_id) { $GLOBALS['user']->playlist->add_object($song_id); } break; + $artist = new Artist($_REQUEST['id']); + $songs = $artist->get_random_songs(); + foreach ($songs as $song_id) { + $GLOBALS['user']->playlist->add_object($song_id); + } + break; case 'clear_all': $GLOBALS['user']->playlist->clear(); break; diff --git a/stats.php b/stats.php index e4013c8d..49b486bf 100644 --- a/stats.php +++ b/stats.php @@ -26,10 +26,8 @@ require_once 'lib/init.php'; require_once Config::get('prefix') . '/templates/header.inc.php'; -$action = scrub_in($_REQUEST['action']); - /* Switch on the action to be performed */ -switch ($action) { +switch ($_REQUEST['action']) { case 'user_stats': /* Get em! */ $working_user = new User($_REQUEST['user_id']); diff --git a/templates/footer.inc.php b/templates/footer.inc.php index 5eb6075b..2b306aa5 100644 --- a/templates/footer.inc.php +++ b/templates/footer.inc.php @@ -20,12 +20,13 @@ */ ?> + - -