From 2f126626cbd951e97220d7c9ab1f2791f614f401 Mon Sep 17 00:00:00 2001 From: Karl 'vollmerk' Vollmer Date: Fri, 31 Mar 2006 08:07:54 +0000 Subject: added download for size, and seriously cleaned up the /song.php file it actually is not ugly anymore.. yeah! --- lib/flag.php | 5 ----- lib/general.lib.php | 42 +++++++++++++++++++++++++++++++----------- lib/gettext.php | 2 +- 3 files changed, 32 insertions(+), 17 deletions(-) (limited to 'lib') diff --git a/lib/flag.php b/lib/flag.php index 5e16faeb..8f3d0dff 100644 --- a/lib/flag.php +++ b/lib/flag.php @@ -132,11 +132,6 @@ function get_flagged_songs($user = 0) return $arr; } -function show_flagged_songs($flags) -{ - require_once(conf('prefix').'/templates/list_flagged.inc'); -} - function accept_new_tags($flags) { if(!is_array($flags)) $flags = array($flags); diff --git a/lib/general.lib.php b/lib/general.lib.php index c8df6183..ad4d7519 100644 --- a/lib/general.lib.php +++ b/lib/general.lib.php @@ -490,8 +490,9 @@ function set_memory_limit($new_limit) { function get_random_songs( $options, $matchlist) { $dbh = dbh(); + /* Define the options */ - $limit = $options['limit']; + $limit = intval($options['limit']); /* If they've passed -1 as limit then don't get everything */ if ($options['limit'] == "-1") { unset($options['limit']); } @@ -524,7 +525,7 @@ function get_random_songs( $options, $matchlist) { $albums_where .= " OR song.album=" . $data[0]; } $albums_where = ltrim($albums_where," OR"); - $query = "SELECT song.id FROM song WHERE $albums_where ORDER BY song.track ASC"; + $query = "SELECT song.id,song.size FROM song WHERE $albums_where ORDER BY song.track ASC"; } elseif ($options['random_type'] == 'full_artist') { $query = "SELECT artist.id FROM song,artist WHERE song.artist=artist.id AND $where GROUP BY song.artist ORDER BY RAND() " . $options['limit']; @@ -533,17 +534,17 @@ function get_random_songs( $options, $matchlist) { $artists_where .= " OR song.artist=" . $data[0]; } $artists_where = ltrim($artists_where," OR"); - $query = "SELECT song.id FROM song WHERE $artists_where ORDER BY RAND()"; + $query = "SELECT song.id,song.size FROM song WHERE $artists_where ORDER BY RAND()"; } elseif ($options['random_type'] == 'unplayed') { - $uid = $_SESSION['userdata']['username']; - $query = "SELECT song.id FROM song LEFT JOIN object_count ON song.id = object_count.object_id " . + $uid = $GLOBALS['user']->id; + $query = "SELECT song.id,song.size FROM song LEFT JOIN object_count ON song.id = object_count.object_id " . "WHERE ($where) AND ((object_count.object_type='song' AND userid = '$uid') OR object_count.count IS NULL ) " . "ORDER BY CASE WHEN object_count.count IS NULL THEN RAND() WHEN object_count.count > 4 THEN RAND()*RAND()*object_count.count " . "ELSE RAND()*object_count.count END " . $options['limit']; } // If unplayed else { - $query = "SELECT id FROM song WHERE $where ORDER BY RAND() " . $options['limit']; + $query = "SELECT id,size FROM song WHERE $where ORDER BY RAND() " . $options['limit']; } $db_result = mysql_query($query, $dbh); @@ -551,10 +552,29 @@ function get_random_songs( $options, $matchlist) { $songs = array(); while ( $r = mysql_fetch_array($db_result) ) { - $songs[] = $r[0]; - } + /* If they've specified a filesize limit */ + if ($options['size_limit']) { + /* Turn it into MB */ + $new_size = ($r['1'] / 1024) / 1024; + + /* If we would go over the allowed size skip to the next song */ + if (($total + $new_size) > $options['size_limit']) { continue; } + + $total = $total + $new_size; + $songs[] = $r[0]; + + /* If we are within 4mb then that's good enough for Vollmer work */ + if (($options['size_limit'] - floor($total)) < 4) { return $songs; } + + } // end if we are defining a size limit + + /* If we aren't using a limit */ + else { + $songs[] = $r[0]; + } + } // while we fetch results - return ($songs); + return $songs; } // get_random_songs @@ -690,10 +710,10 @@ function show_info_box ($title, $type, $items) { if ($type == 'your_song') { - echo "$title - Play\n"; + echo "$title - " . _('Play') . "\n"; } elseif ($type == 'song') { - echo "$title - Play\n"; + echo "$title - " . _('Play') . "\n"; } else { echo "$title\n"; diff --git a/lib/gettext.php b/lib/gettext.php index 6db831ac..56e175e9 100644 --- a/lib/gettext.php +++ b/lib/gettext.php @@ -32,7 +32,7 @@ function load_gettext() { $lang = conf('lang'); putenv("LANG=" . $lang); /* Try lang, lang + charset and lang + utf-8 */ - setlocale(LC_ALL, $lang,$lang . '_'. conf('site_charset'),$lang . '_UTF-8'); + setlocale(LC_ALL, $lang,$lang . '.'. conf('site_charset'),$lang . '.UTF-8',$lang . '.' . conf('lc_charset')); } } // load_gettext -- cgit