diff options
author | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2007-08-27 02:38:04 +0000 |
---|---|---|
committer | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2007-08-27 02:38:04 +0000 |
commit | 9d5967348fbcedc0ce5f9172e3922e0cdb0536d2 (patch) | |
tree | dd1caf093c0ee0ac2c63ca479a0fe534f77efec2 | |
parent | 185630d92c74356946a2a0fe19748b41c9ba57de (diff) | |
download | ampache-9d5967348fbcedc0ce5f9172e3922e0cdb0536d2.tar.gz ampache-9d5967348fbcedc0ce5f9172e3922e0cdb0536d2.tar.bz2 ampache-9d5967348fbcedc0ce5f9172e3922e0cdb0536d2.zip |
fixed advanced random, tweaked some css a tad and fixed a few other minor typos
-rwxr-xr-x | docs/CHANGELOG | 1 | ||||
-rw-r--r-- | lib/class/album.class.php | 2 | ||||
-rw-r--r-- | lib/class/random.class.php | 126 | ||||
-rw-r--r-- | lib/general.lib.php | 132 | ||||
-rw-r--r-- | server/random.ajax.php | 19 | ||||
-rwxr-xr-x | sql/ampache.sql | 17 | ||||
-rw-r--r-- | templates/show_album.inc.php | 2 | ||||
-rw-r--r-- | templates/show_random.inc.php | 10 | ||||
-rw-r--r-- | themes/classic/templates/default.css | 9 |
9 files changed, 182 insertions, 136 deletions
diff --git a/docs/CHANGELOG b/docs/CHANGELOG index 6faed6db..ac69e5d3 100755 --- a/docs/CHANGELOG +++ b/docs/CHANGELOG @@ -4,6 +4,7 @@ -------------------------------------------------------------------------- v.3.4-Alpha2 + - Fixed Advanced random - Fixed missing artist name on Albums of the Moment - Added simple Playlist element view, non-editable - Fixed double posting of songs on a single stream with some diff --git a/lib/class/album.class.php b/lib/class/album.class.php index f19d26cc..c351b085 100644 --- a/lib/class/album.class.php +++ b/lib/class/album.class.php @@ -219,7 +219,7 @@ class Album { $this->f_artist = $artist; } else { - $this->f_artist_link = "<div title=\"$this->artist_count " . _('Artists') . "\">" . _('Various') . "</div>"; + $this->f_artist_link = "<span title=\"$this->artist_count " . _('Artists') . "\">" . _('Various') . "</span>"; $this->f_artist = _('Various'); } diff --git a/lib/class/random.class.php b/lib/class/random.class.php index b2081539..4649ddf7 100644 --- a/lib/class/random.class.php +++ b/lib/class/random.class.php @@ -240,6 +240,132 @@ class Random { } // get_artist /** + * advanced + * This processes the results of a post from a form and returns an + * array of song items that were returned from said randomness + */ + public static function advanced($data) { + + /* Figure out our object limit */ + $limit = intval($data['random']); + + // Generate our matchlist + if ($data['catalog'] != '-1') { + $matchlist['catalog'] = $data['catalog']; + } + if ($data['genre'][0] != '-1') { + $matchlist['genre'] = $data['genre']; + } +print_r($_POST); + /* If they've passed -1 as limit then don't get everything */ + if ($data['limit'] == "-1") { unset($data['limit']); } + elseif ($data['random_type'] == 'length') { /* Rien a faire */ } + else { $limit_sql = "LIMIT " . $limit; } + + $where = "1=1 "; + if (is_array($matchlist)) { + foreach ($matchlist as $type => $value) { + if (is_array($value)) { + foreach ($value as $v) { + $v = Dba::escape($v); + if ($v != $value[0]) { $where .= " OR $type='$v' "; } + else { $where .= " AND ( $type='$v'"; } + } + $where .= " ) "; + } + elseif (strlen($value)) { + $value = Dba::escape($value); + $where .= " AND $type='$value' "; + } + } // end foreach + } // end if matchlist + + + if ($data['random_type'] == 'full_album') { + $query = "SELECT` album`.`id` FROM `song` INNER JOIN `album` ON `song`.`album`=`album`.`id` " . + "WHERE $where GROUP BY `song`.`album` ORDER BY RAND() $limit_sql"; + $db_results = Dba::query($query); + while ($row = Dba::fetch_row($db_results)) { + $albums_where .= " OR `song`.`album`=" . $row[0]; + } + $albums_where = ltrim($albums_where," OR"); + $sql = "SELECT `song`.`id`,`song`.`size`,`song`.`time` FROM `song` WHERE $albums_where ORDER BY `song`.`album`,`song`.`track` ASC"; + } + elseif ($data['random_type'] == 'full_artist') { + $query = "SELECT `artist`.`id` FROM `song` INNER JOIN `artist` ON `song`.`artist`=`artist`.`id` " . + "WHERE $where GROUP BY `song`.`artist` ORDER BY RAND() $limit_sql"; + $db_results = Dba::query($query); + while ($row = Dba::fetch_row($db_results)) { + $artists_where .= " OR song.artist=" . $row[0]; + } + $artists_where = ltrim($artists_where," OR"); + $sql = "SELECT song.id,song.size,song.time FROM song WHERE $artists_where ORDER BY RAND()"; + } +/* TEMP DISABLE */ +// elseif ($options['random_type'] == 'unplayed') { +// $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 user = '$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 " . $limit_sql; +// } // If unplayed + else { + $sql = "SELECT `id`,`size`,`time` FROM `song` WHERE $where ORDER BY RAND() $limit_sql"; + } + + // Run the query generated above so we can while it + $db_results = Dba::query($sql); + $results = array(); + + while ($row = Dba::fetch_assoc($db_results)) { + + // If size limit is specified + if ($data['size_limit']) { + // Convert + $new_size = ($row['size'] / 1024) / 1024; + + // Only fuzzy 10 times + if ($fuzzy_size > 10) { return $results; } + + // Add and check, skip if over don't return incase theres a smaller one commin round + if (($size_total + $new_size) > $data['size_limit']) { $fuzzy_size++; continue; } + + $size_total = $size_total + $new_size; + $results[] = $row['id']; + + // If we are within 4mb of target then jump ship + if (($data['size_limit'] - floor($size_total)) < 4) { return $results; } + } // if size_limit + + // If length really does matter + if ($data['random_type'] == 'length') { + // base on min, seconds are for chumps and chumpettes + $new_time = floor($row['time'] / 60); + + if ($fuzzy_time > 10) { return $results; } + + // If the new one would go voer skip! + if (($time_total + $new_time) > $data['limit']) { $fuzzy_time++; continue; } + + $time_total = $time_total + $new_time; + $results[] = $row['id']; + + if (($data['limit'] - $time_total) < 2) { return $results; } + + } // if length does matter + + if (!$data['size_limit'] AND $data['random_type'] != 'length') { + $results[] = $row['id']; + } + + } // end while results + + + return $results; + + } // advanced + + /** * get_type_name * This returns a 'purrty' name for the differnt random types */ diff --git a/lib/general.lib.php b/lib/general.lib.php index bf4b6edf..eab84a73 100644 --- a/lib/general.lib.php +++ b/lib/general.lib.php @@ -20,17 +20,10 @@ */ -/* - @header General Library - This is the general library that contains misc functions - that doesn't have a home elsewhere -*/ - -/*! - @function ip2int - @discussion turns a dotted quad ip into an - int -*/ +/** + * ip2int + * turns a dotted quad ip into an int + */ function ip2int($ip) { $a=explode(".",$ip); @@ -290,122 +283,6 @@ function set_memory_limit($new_limit) { } // set_memory_limit -/*! - @function get_random_songs - @discussion Returns a random set of songs/albums or artists - matchlist is an array of the WHERE mojo and options - defines special unplayed,album,artist,limit info -*/ -function get_random_songs( $options, $matchlist) { - - $dbh = dbh(); - - /* Define the options */ - $limit = intval($options['limit']); - - /* If they've passed -1 as limit then don't get everything */ - if ($options['limit'] == "-1") { unset($options['limit']); } - elseif ($options['random_type'] == 'length') { /* Rien a faire */ } - else { $limit_sql = "LIMIT " . $limit; } - - - $where = "1=1 "; - if(is_array($matchlist)) - foreach ($matchlist as $type => $value) { - if (is_array($value)) { - foreach ($value as $v) { - $v = sql_escape($v); - if ($v != $value[0]) { $where .= " OR $type='$v' "; } - else { $where .= " AND ( $type='$v'"; } - } - $where .= " ) "; - } - elseif (strlen($value)) { - $value = sql_escape($value); - $where .= " AND $type='$value' "; - } - } - - - - if ($options['random_type'] == 'full_album') { - $query = "SELECT album.id FROM song,album WHERE song.album=album.id AND $where GROUP BY song.album ORDER BY RAND() " . $limit_sql; - $db_results = mysql_query($query, $dbh); - while ($data = mysql_fetch_row($db_results)) { - $albums_where .= " OR song.album=" . $data[0]; - } - $albums_where = ltrim($albums_where," OR"); - $query = "SELECT song.id,song.size,song.time FROM song WHERE $albums_where ORDER BY song.album,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() " . $limit_sql; - $db_results = mysql_query($query, $dbh); - while ($data = mysql_fetch_row($db_results)) { - $artists_where .= " OR song.artist=" . $data[0]; - } - $artists_where = ltrim($artists_where," OR"); - $query = "SELECT song.id,song.size,song.time FROM song WHERE $artists_where ORDER BY RAND()"; - } -/* TEMP DISABLE */ -// elseif ($options['random_type'] == 'unplayed') { -// $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 user = '$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 " . $limit_sql; -// } // If unplayed - else { - $query = "SELECT id,size,time FROM song WHERE $where ORDER BY RAND() " . $limit_sql; - } - - $db_result = mysql_query($query, $dbh); - - $songs = array(); - - while ( $r = mysql_fetch_assoc($db_result) ) { - /* If they've specified a filesize limit */ - if ($options['size_limit']) { - /* Turn it into MB */ - $new_size = ($r['size'] / 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['id']; - - /* 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 they've specified a length */ - if ($options['random_type'] == 'length') { - /* Turn the length into min's */ - $new_time = floor($r['time'] / 60); - - if ($fuzzy_count > 10) { return $songs; } - - /* If the new one would go over skip to the next song with a limit */ - if (($total + $new_time) > $options['limit']) { $fuzzy_count++; continue; } - - $total = $total + $new_time; - $songs[] = $r['id']; - - if (($options['limit'] - $total) < 2) { return $songs; } - - } // if length - - /* If we aren't using a limit */ - else { - $songs[] = $r['id']; - } - } // while we fetch results - - return $songs; - -} // get_random_songs - /** * cleanup_and_exit * used specificly for the play/index.php file @@ -690,7 +567,6 @@ function translate_pattern_code($code) { } // translate_pattern_code - /** * print_boolean * This function takes a boolean value and then print out a friendly diff --git a/server/random.ajax.php b/server/random.ajax.php index c64e5807..70429e09 100644 --- a/server/random.ajax.php +++ b/server/random.ajax.php @@ -52,7 +52,26 @@ switch ($_REQUEST['action']) { } $results['rightbar'] = ajax_include('rightbar.inc.php'); break; + case 'advanced_random': + $object_ids = Random::advanced($_POST); + + // First add them to the active playlist + foreach ($object_ids as $object_id) { + $GLOBALS['user']->playlist->add_object($object_id,'song'); + } + $results['rightbar'] = ajax_include('rightbar.inc.php'); + + // Now setup the browse and show them below! + Browse::set_type('song'); + Browse::save_objects($object_ids); + ob_start(); + Browse::show_objects(); + $results['browse'] = ob_get_contents(); + ob_end_clean(); + + break; default: + $results['rfc3514'] = '0x1'; break; } // switch on action; diff --git a/sql/ampache.sql b/sql/ampache.sql index 9600906d..bcf1aab0 100755 --- a/sql/ampache.sql +++ b/sql/ampache.sql @@ -1,3 +1,20 @@ +-- +-- +-- Copyright (c) 2001 - 2007 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 v2 +-- as published by the Free Software Foundation. +-- +-- 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. -- MySQL dump 10.11 -- -- Host: localhost Database: ampache diff --git a/templates/show_album.inc.php b/templates/show_album.inc.php index f341c364..f2738e93 100644 --- a/templates/show_album.inc.php +++ b/templates/show_album.inc.php @@ -23,7 +23,7 @@ $web_path = Config::get('web_path'); $ajax_url = Config::get('ajax_url'); // Title for this album -$title = scrub_out($album->name) . ' (' . $album->year . ') -- ' . $album->f_artist; +$title = scrub_out($album->name) . ' (' . $album->year . ') -- ' . $album->f_artist_link; ?> <?php show_box_top($title,'info-box'); ?> <div style="float:left;margin-right:10px;"> diff --git a/templates/show_random.inc.php b/templates/show_random.inc.php index 684ced98..6e6296d0 100644 --- a/templates/show_random.inc.php +++ b/templates/show_random.inc.php @@ -18,12 +18,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - - ?> <form id="random" method="post" enctype="multipart/form-data" action="<?php echo Config::get('web_path'); ?>/random.php"> <?php show_box_top(_('Play Random Selection')); ?> -<table> +<table class="table-data" border="0" cellspacing="0" cellpadding="3"> <tr> <td><?php echo _('Item count'); ?></td> <td> @@ -42,7 +40,7 @@ </td> <td rowspan="4" valign="top"><?php echo _('From genre'); ?></td> <td rowspan="4"> - <?php show_genre_select('genre','','5'); ?> + <?php show_genre_select('genre[]','','5'); ?> </td> </tr> <tr> @@ -78,8 +76,12 @@ </tr> <tr> <td colspan="4"> + <?php echo Ajax::text("?page=random&action=advanced_random",_('Enqueue'),'advanced_random_enqueue','random','smallbutton'); ?> </td> </tr> </table> <?php show_box_bottom(); ?> </form> +<div id="browse"> + +</div> diff --git a/themes/classic/templates/default.css b/themes/classic/templates/default.css index f3450010..3d80a449 100644 --- a/themes/classic/templates/default.css +++ b/themes/classic/templates/default.css @@ -128,6 +128,12 @@ input { font-weight:bold; background: #d0d0d0; } +.smallbutton:active { + border-bottom:1px solid #f0f0f0; + border-right:1px solid #f0f0f0; + border-top:1px solid #a0a0a0; + border-left:1px solid #a0a0a0; +} a.smallbutton { text-decoration:none; padding:1px 2px; @@ -459,8 +465,7 @@ h3#content_title span { } .info-box { background: #f7f7f7; - /*float:left; - clear:left;*/ + /*float:left;*/ } .box-title { border-bottom: solid 1px #000; |