From 691c838e90e759a7461cec657d95a4f1af9f46c6 Mon Sep 17 00:00:00 2001 From: Karl 'vollmerk' Vollmer Date: Sun, 6 May 2007 21:07:03 +0000 Subject: basic browse concept added to sidebar and start of the browse logic --- browse.php | 6 +- lib/class/album.class.php | 113 +++++++++++++++++++++-------------- lib/class/browse.class.php | 90 ++++++++++++++++++++++++++++ lib/class/update.class.php | 8 +++ lib/init.php | 5 +- lib/ui.lib.php | 22 +++---- server/ajax.server.php | 27 ++++----- templates/sidebar_browse.inc.php | 19 +++++- themes/classic/templates/default.css | 5 ++ 9 files changed, 212 insertions(+), 83 deletions(-) create mode 100644 lib/class/browse.class.php diff --git a/browse.php b/browse.php index 91bc204f..220a0f9b 100644 --- a/browse.php +++ b/browse.php @@ -102,10 +102,8 @@ switch($_REQUEST['action']) { } break; - case 'song_title': - /* Create the Needed Object */ - $song = new Song(); - + case 'song': + Browse::set_type('song'); /* Setup the View Object */ $view = new View(); diff --git a/lib/class/album.class.php b/lib/class/album.class.php index 72abfab4..fbd55255 100644 --- a/lib/class/album.class.php +++ b/lib/class/album.class.php @@ -27,33 +27,48 @@ class Album { /* Variables from DB */ - var $id; - var $name; - var $year; - var $prefix; + public $id; + public $name; + public $year; + public $prefix; /* Art Related Fields */ - var $art; - var $art_mime; + public $art; + public $art_mime; + public $thumb; + public $thumb_mime; // cached information - var $_songs=array(); + public $_songs=array(); - /*! - @function Album - @discussion Album class, for modifing a song. - @param $album_id The ID of the song + /** + * __construct + * Album constructor it loads everything relating + * to this album from the database it does not + * pull the album or thumb art by default or + * get any of the counts. */ - function Album($album_id = 0) { + function __construct($album_id = 0) { if (!$album_id) { return false; } /* Assign id for use in get_info() */ - $this->id = $album_id; + $this->id = intval($album_id); /* Get the information from the db */ - if ($info = $this->_get_info()) { - $this->name = trim($info['prefix'] . " " . $info['album_name']); + $info = $this->_get_info(); + + // Foreach what we've got + foreach ($info as $key=>$value) { + $this->$key = $value; + } + + // Little bit of formating here + $this->f_name = trim($info['prefix'] . ' ' . $info['name']); + + // Additional data that we are going to need + + /* $this->songs = $info['song_count']; $this->artist_count = $info['artist_count']; $this->year = $info['year']; @@ -62,40 +77,40 @@ class Album { $this->album = $info['album_name']; $this->has_art = $info['has_art']; $this->prefix = $info['prefix']; - } // if info + */ return true; } //constructor - /*! - @function get_info - @discussion get's the vars for $this out of the database - @param $this->id Taken from the object - */ + /** + * _get_info + * This is a private function that pulls the album + * from the database + */ private function _get_info() { - $this->id = intval($this->id); - - /* Grab the basic information from the catalog and return it */ + // Just get the album information + $sql = "SELECT * FROM `album` WHERE `id`='" . $this->id . "'"; + + /* Grab the basic information from the catalog and return it $sql = "SELECT COUNT(DISTINCT(song.artist)) as artist_count,album.prefix,album.year,album.name AS album_name,COUNT(song.id) AS song_count," . "artist.name AS artist_name,artist.id AS art_id,artist.prefix AS artist_prefix,album.art AS has_art ". "FROM song,artist,album WHERE album.id='$this->id' AND song.album=album.id AND song.artist=artist.id GROUP BY song.album"; + */ $db_results = Dba::query($sql); $results = Dba::fetch_assoc($db_results); - // If there is art then set it to 1, if not set it to 0, we don't want to cary - // around the full blob with every object because it can be pretty big - $results['has_art'] = strlen($results['has_art']) ? '1' : '0'; - return $results; } // _get_info /** * get_songs - * gets the songs for this album + * gets the songs for this album takes an optional limit + * and an optional artist, if artist is passed it only gets + * songs with this album + specified artist */ public function get_songs($limit = 0,$artist='') { @@ -117,13 +132,32 @@ class Album { } // 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::query($sql); + + if (Dba::fetch_assoc($db_results)) { + $this->has_art = true; + return true; + } + + return false; + + } // has_art + /** * format * This is the format function for this object. It sets cleaned up * albumĀ information with the base required * f_link, f_name */ - function format() { + public function format() { $web_path = Config::get('web_path'); @@ -147,24 +181,13 @@ class Album { } // format - /** - * format_album - * DEPRECIATED DO NOT USE! - */ - function format_album() { - - // Call the real function - $this->format(); - - } // format_album - /** * get_art * This function only pulls art from the database, if thumb is passed * it trys to pull the resized art instead, if resized art is found then * it returns an additional resized=true in the array */ - function get_art() { + public function get_art() { // Attempt to get the resized art first $art = $this->get_resized_db_art(); @@ -187,7 +210,7 @@ class Album { * ['artist'] = STRING * ['album_name'] = STRING */ - function find_art($options=array(),$limit='') { + public function find_art($options=array(),$limit='') { /* Create Base Vars */ $results = array(); @@ -365,7 +388,7 @@ class Album { $id = Dba::escape($this->id); - $sql = "SELECT `thumb` AS `art`,`thumb_mime` AS `art_mime` FROM `album` WHERE `id`='$id'"; + $sql = "SELECT `thumb` AS `art`,`thumb_mime` AS `art_mime` FROM `album_data` WHERE `album_id`='$id'"; $db_results = Dba::query($sql); $results = Dba::fetch_assoc($db_results); @@ -384,7 +407,7 @@ class Album { */ public function get_db_art() { - $sql = "SELECT `art`,`art_mime` FROM `album` WHERE `id`='$this->id'"; + $sql = "SELECT `art`,`art_mime` FROM `album_data` WHERE `album_id`='$this->id'"; $db_results = Dba::query($sql); $results = Dba::fetch_assoc($db_results); diff --git a/lib/class/browse.class.php b/lib/class/browse.class.php new file mode 100644 index 00000000..eaa540bb --- /dev/null +++ b/lib/class/browse.class.php @@ -0,0 +1,90 @@ +id; -Config::set_by_array($ajax_info); -unset($ajax_info); +Config::set('ajax_url',Config::get('web_path') . '/server/ajax.server.php',1); // Load gettext mojo load_gettext(); diff --git a/lib/ui.lib.php b/lib/ui.lib.php index af88b29e..6746226a 100644 --- a/lib/ui.lib.php +++ b/lib/ui.lib.php @@ -141,29 +141,25 @@ function return_referer() { /** * show_alphabet_list - * shows the A-Z,0-9 lists for - * albums and artist pages + * shows the A-Z,0-9 lists for albums and artist page + * It takes a selected and an action */ -function show_alphabet_list ($type,$script="artist.php",$selected="false",$action='match') { +function show_alphabet_list () { $list = array(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,1,2,3,4,5,6,7,8,9,"0"); $style_name = "style_" . strtolower($selected); ${$style_name} = "style=\"font-weight:bold;\""; - unset($title); + echo "
"; foreach ($list as $l) { $style_name = "style_" . strtolower($l); - echo "$l | \n"; + echo "" . + $l . "\n"; + $i++; + if ($i/11 == intval($i/11)) { echo "
"; } } - - echo " " . _("Browse") . " | \n"; - if ($script == "albums.php") { - echo " " . _("Show w/o art") . " | \n"; - } // if we are on the albums page - - echo " " . _("Show all") . ""; - echo "
\n"; + echo ""; } // show_alphabet_list diff --git a/server/ajax.server.php b/server/ajax.server.php index 591e7037..5afb6b61 100644 --- a/server/ajax.server.php +++ b/server/ajax.server.php @@ -193,23 +193,20 @@ switch ($action) { $xml_doc = xml_from_array($results); echo $xml_doc; break; - case 'browse_type': - // Clean up the types - switch ($_REQUEST['type']) { - case 'song': - case 'album': - case 'artist': - case 'genre': - $type = $_REQUEST['type']; - break; - default: - $type = 'song'; - break; - } // types - - + // Used to change filter/settings on browse + case 'browse': + // Set any new filters we've just added + Browse::set_filter($_REQUEST['key'],$_REQUEST['value']); + // Refresh the browse div with our new filter options + $object_ids = Browse::get_objects(); + ob_start(); + Browse::show_objects($object_ids); + $results['browse_content'] = ob_get_contents(); + ob_end_clean(); + $xml_doc = xml_from_array($results); + echo $xml_doc; break; case 'sidebar': switch ($_REQUEST['button']) { diff --git a/templates/sidebar_browse.inc.php b/templates/sidebar_browse.inc.php index 1b6a02ee..949d174e 100644 --- a/templates/sidebar_browse.inc.php +++ b/templates/sidebar_browse.inc.php @@ -1,9 +1,24 @@ +

-
- + +
+
+ +
+

+ +
+ +
+ +
+ +

diff --git a/themes/classic/templates/default.css b/themes/classic/templates/default.css index 5c1b8308..1fd7391e 100644 --- a/themes/classic/templates/default.css +++ b/themes/classic/templates/default.css @@ -619,6 +619,11 @@ td.user_disabled { font-size:10px; font-weight:normal; } +.alphabet span { + cursor: pointer; + color: #003399; +} + #mpdpl td { padding:0 2px 0 2px; text-align:left; -- cgit