summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xdocs/CHANGELOG2
-rw-r--r--images/icon_cog.pngbin0 -> 814 bytes
-rw-r--r--lib/class/random.class.php169
-rw-r--r--lib/class/stream.class.php22
-rw-r--r--lib/class/user.class.php23
-rw-r--r--lib/preferences.php4
-rw-r--r--play/index.php10
-rw-r--r--server/ajax.server.php9
-rw-r--r--stream.php10
-rw-r--r--templates/rightbar.inc.php19
10 files changed, 255 insertions, 13 deletions
diff --git a/docs/CHANGELOG b/docs/CHANGELOG
index 4da2d1b2..2cdf5f7c 100755
--- a/docs/CHANGELOG
+++ b/docs/CHANGELOG
@@ -4,6 +4,8 @@
--------------------------------------------------------------------------
v.3.4-Alpha1
+ - Added initial dyanmic playlist item support, only default
+ and genre work right now.
- Added support for Internet Radio Stations
- Updated LastFM submission formating to account for changes on
last.fm (Thx entropathy)
diff --git a/images/icon_cog.png b/images/icon_cog.png
new file mode 100644
index 00000000..04f22bad
--- /dev/null
+++ b/images/icon_cog.png
Binary files differ
diff --git a/lib/class/random.class.php b/lib/class/random.class.php
new file mode 100644
index 00000000..0a72fdf6
--- /dev/null
+++ b/lib/class/random.class.php
@@ -0,0 +1,169 @@
+<?php
+/*
+
+ Copyright 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
+ as published by the Free Software Foundation; version 2
+ of the License.
+
+ 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.
+
+*/
+
+/**
+ * Random Class
+ * All of the 'random' type events, elements, voodoo done by ampache is done
+ * by this class, there isn't a table for this class so most of it's functions
+ * are static
+ */
+class Random {
+
+ /**
+ * Constructor
+ * nothing to see here, move along
+ */
+ private function __construct($id) {
+
+ // Rien a faire
+
+ } // constructor
+
+ /**
+ * play_url
+ * This generates a random play url based on the passed type
+ * and returns it
+ */
+ public static function play_url($type) {
+
+ if (!$type = self::validate_type($type)) {
+ return false;
+ }
+
+ if (Config::get('require_session')) {
+ $session_string = '&sid=' . session_id();
+ }
+
+ $web_path = Config::get('web_path');
+
+ if (Config::get('force_http_play') OR !empty($force_http)) {
+ $port = Config::get('http_port');
+ if (preg_match("/:\d+/",$web_path)) {
+ $web_path = str_replace("https://", "http://",$web_path);
+ }
+ else {
+ $web_path = str_replace("https://", "http://",$web_path);
+ }
+ }
+
+ $uid = $GLOBALS['user']->id;
+
+ $url = $web_path . "/play/index.php?random=1&type=$type&uid=$uid$session_string";
+
+ return $url;
+
+ } // play_url
+
+ /**
+ * get_single_song
+ * This returns a single song pulled based on the passed random method
+ */
+ public static function get_single_song($type) {
+
+ if (!$type = self::validate_type($type)) {
+ return false;
+ }
+
+ $method_name = 'get_' . $type;
+
+ if (method_exists('Random',$method_name)) {
+ $song_ids = self::$method_name(1);
+ $song_id = array_pop($song_ids);
+ }
+
+ return $song_id;
+
+ } // get_single_song
+
+ /**
+ * get_default
+ * This just randomly picks a song at whim from all catalogs
+ * nothing special here...
+ */
+ public static function get_default($limit) {
+
+ $results = array();
+
+ $sql = "SELECT `id` FROM `song` ORDER BY RAND() LIMIT $limit";
+ $db_results = Dba::query($sql);
+
+ while ($row = Dba::fetch_assoc($db_results)) {
+ $results[] = $row['id'];
+ }
+
+ return $results;
+
+ } // get_default
+
+ /**
+ * get_genre
+ * This looks at the last object played by the current user and
+ * then picks a song of the same genre at random...
+ */
+ public static function get_genre($limit) {
+
+ $results = array();
+
+ // Get the last genre played by us
+ $data = $GLOBALS['user']->get_recently_played('1','genre');
+ if ($data['0']) {
+ $where_sql = " WHERE `genre`='" . $data['0'] . "' ";
+ }
+
+ $sql = "SELECT `id` FROM `song` $where_sql ORDER BY RAND() LIMIT $limit";
+ $db_results = Dba::query($sql);
+
+ while ($row = Dba::fetch_assoc($db_results)) {
+ $results[] = $row['id'];
+ }
+
+ return $results;
+
+ } // get_genre
+
+ /**
+ * validiate_type
+ * this validates the random type, this is a private function
+ */
+ private static function validate_type($type) {
+
+ switch ($type) {
+ case 'special':
+ $type = $GLOBALS['user']->prefs['random_method'];
+ break;
+ case 'genre':
+ case 'album':
+ case 'artist':
+ case 'rated':
+ break;
+ default:
+ return false;
+ break;
+ } // end switch
+
+ return $type;
+
+ } // validate_type
+
+} //end of random class
+
+?>
diff --git a/lib/class/stream.class.php b/lib/class/stream.class.php
index cbfd026d..2f5c4aee 100644
--- a/lib/class/stream.class.php
+++ b/lib/class/stream.class.php
@@ -103,13 +103,21 @@ class Stream {
header("Content-Disposition: filename=playlist.m3u");
header("Content-Type: audio/x-mpegurl;");
+ // Flip for the poping!
+ asort($this->urls);
+
/* Foreach songs */
foreach ($this->songs as $song_id) {
+ // If it's a place-holder
+ if ($song_id == '-1') {
+ echo array_pop($this->urls) . "\n";
+ continue;
+ }
$song = new Song($song_id);
if ($song->type == ".flac") { $song->type = ".ogg"; }
- if($GLOBALS['user']->prefs['play_type'] == 'downsample') {
- $ds = $GLOBALS['user']->prefs['sample_rate'];
- }
+ if ($GLOBALS['user']->prefs['play_type'] == 'downsample') {
+ $ds = $GLOBALS['user']->prefs['sample_rate'];
+ }
echo "$this->web_path/play/index.php?song=$song_id&uid=$this->user_id&sid=$this->sess&ds=$ds&stupidwinamp=." . $song->type . "\n";
} // end foreach
@@ -133,8 +141,16 @@ class Stream {
header("Content-Type: audio/x-mpegurl;");
echo "#EXTM3U\n";
+ // Flip for the popping
+ asort($this->urls);
+
// Foreach the songs in this stream object
foreach ($this->songs as $song_id) {
+ if ($song_id == '-1') {
+ echo "#EXTINF: URL-Add\n";
+ echo array_pop($this->urls) . "\n";
+ continue;
+ }
$song = new Song($song_id);
$song->format();
diff --git a/lib/class/user.class.php b/lib/class/user.class.php
index d6c6ae69..7d76e059 100644
--- a/lib/class/user.class.php
+++ b/lib/class/user.class.php
@@ -929,6 +929,27 @@ class User {
} // get_user_validation
/**
+ * get_recently_played
+ * This gets the recently played items for this user respecting
+ * the limit passed
+ */
+ public function get_recently_played($limit,$type='') {
+
+ if (!$type) { $type = 'song'; }
+
+ $sql = "SELECT * FROM `object_count` WHERE `object_type`='$type' AND `user`='$this->id' " .
+ "ORDER BY `date` DESC LIMIT $limit";
+ $db_results = Dba::query($sql);
+
+ while ($row = Dba::fetch_assoc($db_results)) {
+ $results[] = $row['object_id'];
+ }
+
+ return $results;
+
+ } // get_recently_played
+
+ /**
* get_recent
* This returns users by thier last login date
*/
@@ -1005,7 +1026,7 @@ class User {
function is_xmlrpc() {
/* If we aren't using XML-RPC return true */
- if (!conf('xml_rpc')) {
+ if (!Config::get('xml_rpc')) {
return false;
}
diff --git a/lib/preferences.php b/lib/preferences.php
index 485f2bf0..b54d8cf7 100644
--- a/lib/preferences.php
+++ b/lib/preferences.php
@@ -325,7 +325,9 @@ function create_preference_input($name,$value) {
break;
case 'random_method':
echo "<select name=\"$name\">\n";
- echo "\t<option value=\"genre\">" . _('Similar Genre') . "</option>";
+ echo "\t<option value=\"default\">" . _('Default') . "</option>";
+ echo "\t<option value=\"album\">" . _('Related Album') . "</option>";
+ echo "\t<option value=\"genre\">" . _('Related Genre') . "</option>";
echo "</select>\n";
break;
case 'lastfm_pass':
diff --git a/play/index.php b/play/index.php
index 7520fc5a..65cdf8e4 100644
--- a/play/index.php
+++ b/play/index.php
@@ -37,9 +37,10 @@ $sid = scrub_in($_REQUEST['sid']);
/* This is specifically for tmp playlist requests */
$tmp_id = scrub_in($_REQUEST['tmp_id']);
+$random = scrub_in($_REQUEST['random']);
/* First things first, if we don't have a uid/song_id stop here */
-if (empty($song_id) && empty($tmp_id)) {
+if (empty($song_id) && empty($tmp_id) && empty($random)) {
debug_event('no_song',"Error: No Song UID Specified, nothing to play",'2');
exit;
}
@@ -117,6 +118,13 @@ if ($tmp_id) {
$song_id = $tmp_playlist->get_next_object();
}
+/**
+ * if we are doing random let's pull the random object
+ */
+if ($random) {
+ $song_id = Random::get_single_song($_REQUEST['type']);
+}
+
/* Base Checks passed create the song object */
$song = new Song($song_id);
$song->format();
diff --git a/server/ajax.server.php b/server/ajax.server.php
index 56edeca7..28736115 100644
--- a/server/ajax.server.php
+++ b/server/ajax.server.php
@@ -193,6 +193,9 @@ switch ($action) {
$GLOBALS['user']->playlist->add_object($object->id,'radio');
}
break;
+ case 'dynamic':
+ $GLOBALS['user']->playlist->add_object('0','special');
+ break;
default:
case 'song':
$GLOBALS['user']->playlist->add_object($_REQUEST['id']);
@@ -220,7 +223,11 @@ switch ($action) {
$results['np_data'] = ob_get_contents();
ob_clean();
$data = get_recently_played();
- if (count($data)) { require_once Config::get('prefix') . '/templates/show_recently_played.inc.php'; }
+ if (count($data)) {
+ show_box_top(_('Recently Played'));
+ require_once Config::get('prefix') . '/templates/show_recently_played.inc.php';
+ show_box_bottom();
+ }
$results['recently_played'] = ob_get_contents();
ob_end_clean();
echo xml_from_array($results);
diff --git a/stream.php b/stream.php
index 76670a82..24e8d5d6 100644
--- a/stream.php
+++ b/stream.php
@@ -60,11 +60,19 @@ switch ($_REQUEST['action']) {
case 'radio':
$radio = new Radio($object_data['0']);
$urls[] = $radio->url;
+ $song_ids[] = '-1';
break;
case 'song':
- default:
$song_ids[] = $object_data['0'];
break;
+ default:
+ $random_url = Random::play_url($object_data['1']);
+ // If there's something to actually add
+ if ($random_url) {
+ $urls[] = $random_url;
+ $song_ids[] = '-1';
+ }
+ break;
} // end switch on type
} // end foreach
diff --git a/templates/rightbar.inc.php b/templates/rightbar.inc.php
index 8f2a125e..6dbdabe0 100644
--- a/templates/rightbar.inc.php
+++ b/templates/rightbar.inc.php
@@ -29,17 +29,26 @@
</a>
</li>
<?php } ?>
- <li><span onclick="ajaxPut('<?php echo Config::get('ajax_url'); ?>?action=basket&amp;type=clear_all');return true;">
- <?php echo get_user_icon('delete',_('Clear Playlist')); ?>
- </span></li>
+ <li>
+ <?php echo Ajax::button('?action=basket&type=dynamic','cog',_('Add Dynamic Item'),'rightbar_dynamic_playlist'); ?>
+ </li>
+ <li>
+ <?php echo Ajax::button('?action=basket&type=clear_all','delete',_('Clear Playlist'),'rightbar_clear_playlist'); ?>
+ </li>
</ul>
<div id="current_playlist">
<table cellpadding="0" cellspacing="0">
<?php
+ //FIXME :: this feels kludgy
$objects = $GLOBALS['user']->playlist->get_items();
foreach ($objects as $uid=>$object_data) {
- $object = new $object_data['1']($object_data['0']);
- $object->format();
+ if ($object_data['1'] == 'special') {
+ $object->f_link = _('Dynamic Playlist Item');
+ }
+ else {
+ $object = new $object_data['1']($object_data['0']);
+ $object->format();
+ }
?>
<tr class="<?php echo flip_class(); ?>">
<td>