From 1b35c20dd0a93b143d8b9542743a743e0db66386 Mon Sep 17 00:00:00 2001 From: martian Date: Tue, 9 Feb 2010 17:44:44 +0000 Subject: Adding the bandwidth option to the preferences. This changes the complexity of the UI and toggles album art. --- config/ampache.cfg.php.dist | 12 ++-- lib/class/config.class.php | 5 ++ lib/class/preference.class.php | 2 +- lib/class/song.class.php | 11 ++-- lib/class/update.class.php | 17 +++-- lib/class/user.class.php | 5 +- lib/preferences.php | 8 +++ templates/base.css | 4 +- templates/show_album_row.inc.php | 20 +++--- templates/show_albums.inc.php | 6 +- templates/show_artist.inc.php | 4 -- templates/show_index.inc.php | 116 +++++++++++++++++++++++++-------- templates/show_now_playing_row.inc.php | 9 ++- templates/show_random_albums.inc.php | 8 ++- 14 files changed, 161 insertions(+), 66 deletions(-) diff --git a/config/ampache.cfg.php.dist b/config/ampache.cfg.php.dist index d215bf1d..37c52c82 100644 --- a/config/ampache.cfg.php.dist +++ b/config/ampache.cfg.php.dist @@ -237,13 +237,11 @@ default_auth_level = "admin" ; DEFAULT: true ratings = "true" -; ShoutBox -; Enabling this will allow any user to 'tag' an item and post -; a comment about it which will then be put on the main pages -; shoutbox. Admins are allowed to create 'sticky' shoutbox items -; POSSIBLE VALUES: false true -; DEFAULT: false -;shoutbox = "false" +; Index features +; Vollmer will probably write better stuff here than I will -Vlet +; POSSIBLE VALUES: shout, played, added, now, random +; DEFAULT: hmm +features = "shout, played, added, now, random" ; This options will turn on/off Demo Mode ; If Demo mode is on you can not play songs or update your catalog diff --git a/lib/class/config.class.php b/lib/class/config.class.php index d846f225..64a45522 100644 --- a/lib/class/config.class.php +++ b/lib/class/config.class.php @@ -28,6 +28,11 @@ * config overides and/or local configs (for like dba) * The class should be a static var in the other classes */ + +define('BANDWIDTH_LOW', 0); +define('BANDWIDTH_MEDIUM', 1); +define('BANDWIDTH_HIGH', 2); + class Config { // These are the settings for this specific class diff --git a/lib/class/preference.class.php b/lib/class/preference.class.php index cfc08bf8..04d7f2f7 100644 --- a/lib/class/preference.class.php +++ b/lib/class/preference.class.php @@ -226,7 +226,7 @@ class Preference { $sql = "SELECT `preference`.`name`,`preference`.`description`,`user_preference`.`value` FROM `preference` " . " INNER JOIN `user_preference` ON `user_preference`.`preference`=`preference`.`id` " . - " WHERE `user_preference`.`user`='$user_id' AND `preference`.`catagory` != 'internal' $user_limit"; + " WHERE `user_preference`.`user`='$user_id' AND `preference`.`catagory` != 'internal' $user_limit order by `preference`.`description`"; $db_results = Dba::read($sql); $results = array(); diff --git a/lib/class/song.class.php b/lib/class/song.class.php index 7d30b116..6b68df94 100644 --- a/lib/class/song.class.php +++ b/lib/class/song.class.php @@ -918,7 +918,7 @@ class Song extends database_object implements media { * it uses the popular threshold to figure out how many to pull * it will only return unique object */ - public static function get_recently_played($user_id='') { + public static function get_recently_played($user_id='', $limit=null) { if ($user_id) { $user_limit = " AND `object_count`.`user`='" . Dba::escape($user_id) . "'"; @@ -931,12 +931,15 @@ class Song extends database_object implements media { "ORDER BY `object_count`.`date` DESC "; $db_results = Dba::read($sql); - $results = array(); + $results = array(); while ($row = Dba::fetch_assoc($db_results)) { if (isset($results[$row['object_id']])) { continue; } - $results[$row['object_id']] = $row; - if (count($results) > Config::get('popular_threshold')) { break; } + $results[$row['object_id']] = $row; + if (!is_null($limit)) + if (count($results) > $limit) { break; } + else + if (count($results) > Config::get('popular_threshold')) { break; } } return $results; diff --git a/lib/class/update.class.php b/lib/class/update.class.php index 106c3480..bda724a4 100644 --- a/lib/class/update.class.php +++ b/lib/class/update.class.php @@ -1828,12 +1828,21 @@ class Update { $sql = "ALTER TABLE `live_stream` CHANGE `url` `url` VARCHAR ( 4096 )"; $db_results = Dba::write($sql); + + // Now add in the min_object_count preference and the random_method + $sql = "INSERT INTO `preferences` (`name`,`value`,`description`,`level`,`type`,`catagory`) " . + "VALUES('bandwidth','1','Bandwidth','100','integer','interface')"; + $db_results = Dba::write($sql); + + /* Fix every users preferences */ + $sql = "SELECT `id` FROM `user`"; + $db_results = Dba::read($sql); - User::fix_preferences('-1'); + User::fix_preferences('-1'); - while ($r = Dba::fetch_assoc($db_results)) { - User::fix_preferences($r['id']); - } // while we're fixing the useres stuff + while ($r = Dba::fetch_assoc($db_results)) { + User::fix_preferences($r['id']); + } // while results } // update_360002 diff --git a/lib/class/user.class.php b/lib/class/user.class.php index 5608e025..40065922 100644 --- a/lib/class/user.class.php +++ b/lib/class/user.class.php @@ -197,7 +197,8 @@ class User extends database_object { $sql = "SELECT preference.name, preference.description, preference.catagory, preference.level, user_preference.value " . "FROM preference INNER JOIN user_preference ON user_preference.preference=preference.id " . - "WHERE user_preference.user='$user_id' " . $user_limit; + "WHERE user_preference.user='$user_id' " . $user_limit . " ORDER BY preference.catagory, preference.description"; + $db_results = Dba::read($sql); /* Ok this is crapy, need to clean this up or improve the code FIXME */ @@ -206,7 +207,7 @@ class User extends database_object { $admin = false; if ($type == 'system') { $admin = true; } $type_array[$type][$r['name']] = array('name'=>$r['name'],'level'=>$r['level'],'description'=>$r['description'],'value'=>$r['value']); - ksort($type_array[$type]); + //ksort($type_array[$type]); // sorted this via sql and added sub-category sorting - Vlet $results[$type] = array ('title'=>ucwords($type),'admin'=>$admin,'prefs'=>$type_array[$type]); } // end while diff --git a/lib/preferences.php b/lib/preferences.php index 5ea7aba4..5b496ba0 100644 --- a/lib/preferences.php +++ b/lib/preferences.php @@ -257,6 +257,14 @@ function create_preference_input($name,$value) { echo "\t\n"; echo "\n"; break; + case 'bandwidth': + ${"bandwidth_$value"} = ' selected="selected"'; + echo "\n"; + break; case 'transcode': ${$value} = ' selected="selected"'; echo "/> - - + - - - - -
- -
- -
- -
- - -
- -
- +// Various settings for the 'bandwidth' option +$feature_sets = array + ( + BANDWIDTH_LOW => array('now', 'played'), + BANDWIDTH_MEDIUM => array('now', 'random', 'played'), + BANDWIDTH_HIGH => array('now', 'random', 'shout', 'played', 'added') + ); + +$feature_limits = array ( + BANDWIDTH_LOW => array + ( + 'shout' => 7, + 'played' => 7, + 'added' => 7 + ), + BANDWIDTH_MEDIUM => array + ( + 'shout' => 10, + 'played' => 10, + 'added' => 10 + ), + BANDWIDTH_HIGH => array + ( + 'shout' => 10, + 'played' => 20, + 'added' => 20 + ) + ); + +$features = $feature_sets[Config::get('bandwidth')]; + +foreach ($features as $feature) { + switch ($feature) { + case 'shout': + ?>
diff --git a/templates/show_now_playing_row.inc.php b/templates/show_now_playing_row.inc.php index bd1f95cc..66b3639d 100644 --- a/templates/show_now_playing_row.inc.php +++ b/templates/show_now_playing_row.inc.php @@ -23,6 +23,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. $title = scrub_out(truncate_with_ellipsis($media->title)); $album = scrub_out(truncate_with_ellipsis($media->f_album_full)); $artist = scrub_out(truncate_with_ellipsis($media->f_artist_full)); + +// This should not be hard coded, but it will likely break all the themes. +//$image_size = Config::get('bandwidth') == BANDWIDTH_MEDIUM ? 75 : 128; +$image_size = 75; + ?>
@@ -72,11 +77,11 @@ $artist = scrub_out(truncate_with_ellipsis($media->f_artist_full));
- + BANDWIDTH_LOW) { ?>
diff --git a/templates/show_random_albums.inc.php b/templates/show_random_albums.inc.php index a262a4a1..2dee7f85 100644 --- a/templates/show_random_albums.inc.php +++ b/templates/show_random_albums.inc.php @@ -29,11 +29,15 @@ $button = Ajax::button('?page=index&action=random_albums','random',_('Refresh'), $album = new Album($album_id); $album->format(); $name = '[' . $album->f_artist . '] ' . scrub_out($album->full_name); + + // This should not be hard coded, but it will likely break all the themes. + //$image_size = Config::get('bandwidth') == BANDWIDTH_MEDIUM ? 75 : 128; + $image_size = 75; ?>
- - <?php echo $name; ?> + BANDWIDTH_LOW) { ?> + <?php echo $name; ?> f_artist . '] ' . $album->f_name; ?> -- cgit