diff options
-rw-r--r-- | albums.php | 12 | ||||
-rw-r--r-- | artists.php | 29 | ||||
-rw-r--r-- | browse.php | 26 | ||||
-rwxr-xr-x | docs/CHANGELOG | 6 | ||||
-rw-r--r-- | lib/class/catalog.class.php | 35 | ||||
-rw-r--r-- | lib/class/genre.class.php | 106 | ||||
-rw-r--r-- | lib/ui.lib.php | 37 | ||||
-rw-r--r-- | song.php | 12 | ||||
-rw-r--r-- | templates/show_alphabet_form.inc.php | 38 | ||||
-rw-r--r-- | templates/show_browse_menu.inc | 4 | ||||
-rw-r--r-- | templates/show_genres.inc.php | 13 |
11 files changed, 271 insertions, 47 deletions
@@ -123,32 +123,30 @@ else { switch($match) { case 'Show_all': show_alphabet_list('albums','albums.php','show_all'); - echo "<form name=\"f\" method=\"get\" action=\"".$_SERVER['PHP_SELF']."\"><label for=\"match\" accesskey=\"S\">" . _("<u>S</u>how all albums") ."</label> <input type=\"text\" size=\"3\" id=\"match\" name=\"match\" value=\"\"></input><input type=\"hidden\" name=\"action\" value=\"match\"></input></form>\n"; + show_alphabet_form('',_("Show Albums starting with"),"albums.php?action=match"); $offset_limit = 99999; $sql = "SELECT id FROM album"; break; case 'Show_missing_art': show_alphabet_list('albums','albums.php','show_missing_art'); - echo "<form name=\"f\" method=\"get\" action=\"".$_SERVER['PHP_SELF']."\"><label for=\"match\" accesskey=\"S\">" . _("<u>S</u>how all albums") ."</label> <input type=\"text\" size=\"3\" id=\"match\" name=\"match\" value=\"\"></input><input type=\"hidden\" name=\"action\" value=\"match\"></input></form>\n"; + show_alphabet_form('',_("Show Albums starting with"),"albums.php?action=match"); $offset_limit = 99999; $sql = "SELECT id FROM album where art is null"; break; case 'Browse': case 'show_albums': show_alphabet_list('albums','albums.php','browse'); - echo "<form name=\"f\" method=\"get\" action=\"".$_SERVER['PHP_SELF']."\"><label for=\"match\" accesskey=\"S\">" . _("<u>S</u>how only albums starting with") . "</label> <input type=\"text\" size=\"3\" id=\"match\" name=\"match\" value=\"\"></input><input type=\"hidden\" name=\"action\" value=\"match\"></input></form>\n"; + show_alphabet_form('',_("Show Albums starting with"),"albums.php?action=match"); $sql = "SELECT id FROM album"; break; case 'none': show_alphabet_list('albums','albums.php','a'); - echo "<p style=\"font: 10pt bold;\">". - _("Select a starting letter or Show all") . "</p>"; - echo "<form name=\"f\" method=\"get\" action=\"".$_SERVER['PHP_SELF']."\"><label for=\"match\" accesskey=\"S\">" . _("<u>S</u>how only albums starting with") . "</label> <input type=\"text\" size=\"3\" id=\"match\" name=\"match\" value=\"\"></input><input type=\"hidden\" name=\"action\" value=\"match\"></input></form>\n"; + show_alphabet_form('',_("Show Albums starting with"),"albums.php?action=match"); $sql = "SELECT id FROM album WHERE name LIKE 'a%'"; break; default: show_alphabet_list('albums','albums.php',$match); - echo "<form name=\"f\" method=\"get\" action=\"".$_SERVER['PHP_SELF']."\"><label for=\"match\" accesskey=\"S\">" . _("<u>S</u>how only albums starting with") . "<input type=\"text\" size=\"3\" id=\"match\" name=\"match\" value=\"$match\"></input><input type=\"hidden\" name=\"action\" value=\"match\"></input></p></form>\n"; + show_alphabet_form($match,_("Show Albums starting with"),"albums.php?action=match"); echo "<br /><br />"; $sql = "SELECT id FROM album WHERE name LIKE '$match%'"; } // end switch diff --git a/artists.php b/artists.php index 3511c1f9..19a8836c 100644 --- a/artists.php +++ b/artists.php @@ -68,33 +68,17 @@ switch($action) { preg_match("/^(\w*)/", $match, $matches); show_alphabet_list('artists','artists.php',$match); if ($match === "Browse") { - echo "<form name=\"f\" method=\"get\" action=\"".$_SERVER['PHP_SELF']."\">\n"; - echo "<label for=\"match\" accesskey=\"S\">"; - echo _("<u>S</u>how artists starting with") . "</label> \n"; - echo "<input type=\"text\" size=\"3\" id=\"match\" name=\"match\" value=\"\" />\n"; - echo "<input type=\"hidden\" name=\"action\" value=\"match\" />\n"; - echo "</form>\n"; + show_alphabet_form('',_("Show Artists starting with"),"albums.php?action=match"); show_artists(); } elseif ($match === "Show_all") { - echo "<form name=\"f\" method=\"get\" action=\"".$_SERVER['PHP_SELF']."\">\n"; - echo "<label for=\"match\" accesskey=\"S\">"; - echo _("<u>S</u>how artists starting with") . "</label> "; - echo "<input type=\"text\" size=\"3\" id=\"match\" name=\"match\" value=\"\" />\n"; - echo "<input type=\"hidden\" name=\"action\" value=\"match\" />\n"; - echo "</form>\n"; + show_alphabet_form('',_("Show Artists starting with"),"albums.php?action=match"); $_SESSION['view_offset_limit'] = 999999; show_artists(); } else { $chr = preg_replace("/[^a-zA-Z0-9]/", "", $matches[1]); - - echo "<form name=\"f\" method=\"get\" action=\"".$_SERVER['PHP_SELF']."\">\n"; - echo "<label for=\"match\" accesskey=\"S\">"; - echo _("<u>S</u>how artists starting with") . "</label> \n"; - echo "<input type=\"text\" size=\"3\" id=\"match\" name=\"match\" value=\"$chr\" />\n"; - echo "<input type=\"hidden\" name=\"action\" value=\"match\" />\n"; - echo "</p></form>\n"; + show_alphabet_form($chr,_("Show Artists starting with"),"albums.php?action=match"); if ($chr == '') { show_artists('A'); @@ -106,13 +90,8 @@ switch($action) { break; default: - echo "<form name=\"f\" method=\"get\" action=\"".$_SERVER['PHP_SELF']."\">\n"; - echo "<label for=\"match\" accesskey=\"S\">"; - echo _("<u>S</u>how artists starting with") . "</label> \n"; - echo "<input type=\"text\" size=\"3\" id=\"match\" name=\"match\" value=\"\" />\n"; - echo "<input type=\"hidden\" name=\"action\" value=\"match\" />\n"; - echo "</p></form>\n"; show_alphabet_list('artists','artists.php'); + show_alphabet_form('',_("Show Artists starting with"),"albums.php?action=match"); show_artists('A'); break; @@ -48,7 +48,31 @@ switch($action) { case 'album': case 'artist': 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 = $_SESSION['userdata']['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); + } + break; case 'catalog': diff --git a/docs/CHANGELOG b/docs/CHANGELOG index 087e3520..1b7c1018 100755 --- a/docs/CHANGELOG +++ b/docs/CHANGELOG @@ -26,6 +26,10 @@ - Added optional automatic resizing of thumbnails using php-gd - Improved Upload System (Thx Rosensama) - Added Download Selected Option if Zip Downloads are allowed + - Added initial Genre Browsing + - Fixed problem where catalog wouldn't clean unused genre + entries + - Fixed a security problem with Albums & Artists browse pages -------------------------------------------------------------------------- @@ -44,7 +48,7 @@ - Updated Getid3() library to 1.7.4 - Added code to streaming that requires you to play at least half the song before it's counted in the stats (Thx SH) - - Added Norwegian translation (Thx Ruudboy) + - Added Dutch translation (Thx Ruudboy) - Added a clean_catalog() to the /bin/catalog_update.php.inc script - Removed all instances of $user->id - Improved XMLRPC client and server functions, no longer attempts diff --git a/lib/class/catalog.class.php b/lib/class/catalog.class.php index 4649ae44..bade7811 100644 --- a/lib/class/catalog.class.php +++ b/lib/class/catalog.class.php @@ -1066,6 +1066,7 @@ class Catalog { $this->clean_albums(); $this->clean_stats(); $this->clean_artists(); + $this->clean_genres(); $this->clean_flagged(); } // update_remote_catalog @@ -1156,6 +1157,7 @@ class Catalog { $this->clean_stats(); $this->clean_playlists(); $this->clean_flagged(); + $this->clean_genres(); /* Return dead files, so they can be listed */ echo "<b>" . _("Catalog Clean Done") . " [" . count($dead_files) . "] " . _("files removed") . "</b><br />\n"; @@ -1164,6 +1166,39 @@ class Catalog { } //clean_catalog + /** + * clean_genres + * This functions cleans up unused genres + * @package Catalog + * @catagory Clean + */ + function clean_genres() { + + /* Mysql 3.23 doesn't support our cool query so we have to do it a different way */ + if (preg_match("/^3\./",mysql_get_server_info())) { + $sql = "SELECT genre.id FROM genre LEFT JOIN song ON song.genre = genre.id WHERE song.id IS NULL"; + $db_results = mysql_query($sql, dbh()); + + $results = array(); + + while ($r = mysql_fetch_row($db_results)) { + $results[] = $r; + } + + foreach ($results as $dead) { + + $sql = "DELETE FROM genre WHERE id='$dead[0]'"; + $db_results = mysql_query($sql,dbh()); + } + return true; + } + + /* Do a complex delete to get albums where there are no songs */ + $sql = "DELETE FROM genre USING genre LEFT JOIN song ON song.genre = genre.id WHERE song.id IS NULL"; + $db_results = mysql_query($sql, dbh()); + + } // clean_genres + /*! @function clean_albums diff --git a/lib/class/genre.class.php b/lib/class/genre.class.php index 0b57a473..d5165dcb 100644 --- a/lib/class/genre.class.php +++ b/lib/class/genre.class.php @@ -71,8 +71,11 @@ class Genre { */ function format_genre() { - - + $this->link = $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; + } // format_genre /** @@ -83,7 +86,12 @@ class Genre { */ 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); + return $total_items[0]; } // get_song_count @@ -95,11 +103,44 @@ class Genre { */ function get_songs() { + $sql = "SELECT song.id FROM song WHERE genre='" . $this->id . "'"; + $db_results = mysql_query($sql, dbh()); + $results = array(); + + while ($r = mysql_fetch_assoc($db_results)) { + $results[] = $r['id']; + } + + return $results; } // get_songs /** + * get_random_songs + * This is the same as get_songs except it returns a random assortment of songs from this + * genre + * @package Genre + * @catagory Class + */ + function get_random_songs() { + + $limit = rand(1,$this->get_song_count()); + + $sql = "SELECT song.id FROM song WHERE genre='" . $this->id . "' ORDER BY RAND() LIMIT $limit"; + $db_results = mysql_query($sql, dbh()); + + $results = array(); + + while ($r = mysql_fetch_assoc($db_results)) { + $results[] = $r['id']; + } + + return $results; + + } // get_random_songs + + /** * get_albums * This gets all of the albums that have at least one song in this genre * @package Genre @@ -123,6 +164,67 @@ class Genre { } // get_artists + /** + * get_genres + * this returns an array of genres based on a sql statement that's passed + * @package Genre + * @catagory Class + */ + function get_genres($sql) { + + $db_results = mysql_query($sql, dbh()); + + $results = array(); + + while ($r = mysql_fetch_assoc($db_results)) { + $results[] = new Genre($r['id']); + } + + return $results; + + } // get_genres + + /** + * get_sql_from_match + * This is specificly for browsing it takes the match and returns the sql call that we want to use + * @package Genre + * @catagory Class + */ + function get_sql_from_match($match) { + + switch ($match) { + case 'Show_All': + case 'show_all': + $sql = "SELECT id FROM genre"; + break; + case 'Browse': + case 'show_genres': + $sql = "SELECT id FROM genre"; + break; + default: + $sql = "SELECT id FROM genre WHERE name LIKE '" . sql_escape($match) . "%'"; + break; + } // end switch on match + + return $sql; + + } // 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) { + + show_alphabet_list('genre','browse.php',$match,'genre'); + show_alphabet_form($match,_("Show Genres starting with"),"browse.php?action=genre&match=$match"); + + } // show_match_list + } //end of genre class ?> diff --git a/lib/ui.lib.php b/lib/ui.lib.php index 85bae998..3b1abb19 100644 --- a/lib/ui.lib.php +++ b/lib/ui.lib.php @@ -171,6 +171,8 @@ function show_menu_items ($high) { */ function show_browse_menu($highlight) { + $highlight = ucfirst($highlight); + include(conf('prefix'). "/templates/show_browse_menu.inc"); } // show_browse_menu @@ -283,7 +285,7 @@ function return_referer() { * shows the A-Z,0-9 lists for * albums and artist pages */ -function show_alphabet_list ($type,$script="artist.php",$selected="false") { +function show_alphabet_list ($type,$script="artist.php",$selected="false",$action='match') { $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"); @@ -293,20 +295,33 @@ function show_alphabet_list ($type,$script="artist.php",$selected="false") { echo "<div class=\"alphabet\">"; foreach ($list as $l) { $style_name = "style_" . strtolower($l); - echo "<a href=\"". conf('web_path') ."/$script?action=match&match=$l\" " . ${$style_name} . ">$l</a> | \n"; + echo "<a href=\"". conf('web_path') ."/$script?action=$action&match=$l\" " . ${$style_name} . ">$l</a> | \n"; } - echo " <a href=\"". conf('web_path') ."/$script?action=match&match=Browse\" $style_browse>" . _("Browse") . "</a> | \n"; + echo " <a href=\"". conf('web_path') ."/$script?action=$action&match=Browse\" $style_browse>" . _("Browse") . "</a> | \n"; if ($script == "albums.php") { - echo " <a href=\"". conf('web_path') ."/$script?action=match&match=Show_missing_art\" $style_show_missing_art>" . _("Show w/o art") . "</a> | \n"; + echo " <a href=\"". conf('web_path') ."/$script?action=$action&match=Show_missing_art\" $style_show_missing_art>" . _("Show w/o art") . "</a> | \n"; } // if we are on the albums page - echo " <a href=\"". conf('web_path') ."/$script?action=match&match=Show_all\" $style_show_all>" . _("Show all") . "</a>"; + echo " <a href=\"". conf('web_path') ."/$script?action=$action&match=Show_all\" $style_show_all>" . _("Show all") . "</a>"; echo "</div>\n"; } // show_alphabet_list /** + * show_alphabet_form + * this shows the spiffy little form that acts as a "quick search" when browsing + * @package General + * @catagory Display + */ +function show_alphabet_form($match, $text, $action) { + + require (conf('prefix') . '/templates/show_alphabet_form.inc.php'); + +} // show_alphabet_form + + +/** * show_local_control * shows the controls * for localplay @@ -676,5 +691,17 @@ function img_resize($image,$size,$type){ } // img_resize +/** + * show_genres + * this shows the 'many' genre form, it takes an array of genre objects and the view object + * @package Genre + * @catagory Display + */ +function show_genres($genres,$view) { + + require (conf('prefix') . '/templates/show_genres.inc.php'); + +} // show_genres + ?> @@ -52,7 +52,17 @@ switch ($action) { else { $song_ids = $_POST['song']; } - $_REQUEST['action'] = "m3u"; + $_REQUEST['action'] = 'm3u'; + break; + case 'genre': + $genre = new Genre($_REQUEST['genre']); + $song_ids = $genre->get_songs(); + $_REQUEST['action'] = 'm3u'; + break; + case 'random_genre': + $genre = new Genre($_REQUEST['genre']); + $song_ids = $genre->get_random_songs(); + $_REQUEST['action'] = 'm3u'; break; default: break; diff --git a/templates/show_alphabet_form.inc.php b/templates/show_alphabet_form.inc.php new file mode 100644 index 00000000..383683b6 --- /dev/null +++ b/templates/show_alphabet_form.inc.php @@ -0,0 +1,38 @@ +<?php +/* + + Copyright (c) 2001 - 2005 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. + +*/ +/*! + @header + A template file + +*/ + +?> + +<form name="f" method="get" action="<?php echo conf('web_path') . "/$action"; ?>" enctype="multipart/form-data"> + <label for="match" accesskey="S"><?php echo $text; ?> + <input type="text" size="3" id="match" name="match" value="<?php echo $match; ?>" /> + <input type="hidden" name="action" value="match" /> +</form> +<br /> + + + diff --git a/templates/show_browse_menu.inc b/templates/show_browse_menu.inc index 63b7b4fb..6edafcfe 100644 --- a/templates/show_browse_menu.inc +++ b/templates/show_browse_menu.inc @@ -34,7 +34,7 @@ $web_path = conf('web_path'); $items = array( _("Artist") => "$web_path/artists.php", _("Albums") => "$web_path/albums.php", - _("Genre") => "$web_path/genres.php", + _("Genre") => "$web_path/browse.php?action=genre", ); ?> @@ -42,7 +42,7 @@ $items = array( <?php foreach ( array_keys($items) as $item ) { - if ( $admin_highlight == $item ) { + if ( _($highlight) == $item ) { echo "<li class=\"active\"><a class=\"active\" href=\"$items[$item]\">" . $item . "</a></li>\n"; } else { diff --git a/templates/show_genres.inc.php b/templates/show_genres.inc.php index cf9faf72..a263e630 100644 --- a/templates/show_genres.inc.php +++ b/templates/show_genres.inc.php @@ -39,12 +39,19 @@ $total_items = $view->total_items; </tr> <?php foreach ($genres as $genre) { - + $genre->format_genre(); ?> -<tr> +<tr class="<?php echo flip_class(); ?>"> <td><?php echo $genre->link; ?></td> <td><?php echo $genre->get_song_count(); ?></td> - <td>Play | Download</td> + <td> + <?php echo _("Play"); ?>: + <a href="<?php echo $genre->play_link; ?>">All</a> + | + <a href="<?php echo $genre->random_link; ?>">Random</a> + | + Download + </td> </tr> <? } // end foreach genres ?> <tr class="even" align="center"> |