1
0
Fork 0
mirror of https://github.com/Yetangitu/ampache synced 2025-10-03 17:59:21 +02:00

added ability to save playlists based on the active playlist, fixed the send on add playlist preference, send and clear still does not work, but its progress

This commit is contained in:
Karl 'vollmerk' Vollmer 2007-09-03 07:23:10 +00:00
parent eeeece05db
commit 32180a41a1
9 changed files with 139 additions and 22 deletions

View file

@ -4,6 +4,10 @@
-------------------------------------------------------------------------- --------------------------------------------------------------------------
v.3.4-Alpha2 v.3.4-Alpha2
- Added ability to delete songs from a saved playlist
- Added ability to create a new playlist based on active playlist
- Fixed the Playlist Method 'Send on Add' so that it works, the
'Send and Clear' is still broken
- Fixed Advanced random - Fixed Advanced random
- Fixed missing artist name on Albums of the Moment - Fixed missing artist name on Albums of the Moment
- Added simple Playlist element view, non-editable - Added simple Playlist element view, non-editable

Binary file not shown.

After

Width:  |  Height:  |  Size: 811 B

View file

@ -320,30 +320,30 @@ class Playlist {
* if you want to add a dyn_song you need to use the one shot function * if you want to add a dyn_song you need to use the one shot function
* add_dyn_song * add_dyn_song
*/ */
function add_songs($song_ids=array()) { public function add_songs($song_ids=array()) {
/* We need to pull the current 'end' track and then use that to /* We need to pull the current 'end' track and then use that to
* append, rather then integrate take end track # and add it to * append, rather then integrate take end track # and add it to
* $song->track add one to make sure it really is 'next' * $song->track add one to make sure it really is 'next'
*/ */
$sql = "SELECT `track` FROM playlist_data WHERE `playlist`='" . $this->id . "' ORDER BY `track` DESC LIMIT 1"; $sql = "SELECT `track` FROM `playlist_data` WHERE `playlist`='" . $this->id . "' ORDER BY `track` DESC LIMIT 1";
$db_results = mysql_query($sql, dbh()); $db_results = Dba::query($sql);
$data = mysql_fetch_assoc($db_results); $data = Dba::fetch_assoc($db_results);
$base_track = $data['track']; $base_track = $data['track'];
foreach ($song_ids as $song_id) { foreach ($song_ids as $song_id) {
/* We need the songs track */ /* We need the songs track */
$song = new Song($song_id); $song = new Song($song_id);
$track = sql_escape($song->track+$base_track); $track = Dba::escape($song->track+$base_track);
$id = sql_escape($song->id); $id = Dba::escape($song->id);
$pl_id = sql_escape($this->id); $pl_id = Dba::escape($this->id);
/* Don't insert dead songs */ /* Don't insert dead songs */
if ($id) { if ($id) {
$sql = "INSERT INTO playlist_data (`playlist`,`song`,`track`) " . $sql = "INSERT INTO `playlist_data` (`playlist`,`object_id`,`object_type`,`track`) " .
" VALUES ('$pl_id','$id','$track')"; " VALUES ('$pl_id','$id','song','$track')";
$db_results = mysql_query($sql, dbh()); $db_results = Dba::query($sql);
} // if valid id } // if valid id
} // end foreach songs } // end foreach songs
@ -382,22 +382,22 @@ class Playlist {
* This function creates an empty playlist, gives it a name and type * This function creates an empty playlist, gives it a name and type
* Assumes $GLOBALS['user']->id as the user * Assumes $GLOBALS['user']->id as the user
*/ */
function create($name,$type) { public static function create($name,$type) {
$name = sql_escape($name); $name = Dba::escape($name);
$type = sql_escape($type); $type = Dba::escape($type);
$user = sql_escape($GLOBALS['user']->id); $user = Dba::escape($GLOBALS['user']->id);
$date = time(); $date = time();
$sql = "INSERT INTO playlist (`name`,`user`,`type`,`date`) " . $sql = "INSERT INTO `playlist` (`name`,`user`,`type`,`genre`,`date`) " .
" VALUES ('$name','$user','$type','$date')"; " VALUES ('$name','$user','$type','0','$date')";
$db_results = mysql_query($sql, dbh()); $db_results = Dba::query($sql);
$insert_id = mysql_insert_id(dbh()); $insert_id = Dba::insert_id();
return $insert_id; return $insert_id;
} //create_paylist } // create
/** /**
* set_items * set_items

View file

@ -339,10 +339,11 @@ function create_preference_input($name,$value) {
echo "</select>\n"; echo "</select>\n";
break; break;
case 'playlist_method': case 'playlist_method':
${$value} = ' selected="selected"';
echo "<select name=\"$name\">\n"; echo "<select name=\"$name\">\n";
echo "\t<option value=\"send\">" . _('Send on Add') . "</option>\n"; echo "\t<option value=\"send\"$send>" . _('Send on Add') . "</option>\n";
echo "\t<option value=\"send\">" . _('Send and Clear') . "</option>\n"; echo "\t<option value=\"send_clear\"$send_clear>" . _('Send and Clear') . "</option>\n";
echo "\t<option value=\"default\">" . _('Default') . "</option>\n"; echo "\t<option value=\"default\"$default>" . _('Default') . "</option>\n";
echo "</select>\n"; echo "</select>\n";
break; break;
case 'transcode': case 'transcode':

View file

@ -39,6 +39,32 @@ switch ($_REQUEST['action']) {
$results['browse_content'] = ob_get_contents(); $results['browse_content'] = ob_get_contents();
ob_end_clean(); ob_end_clean();
break; break;
case 'create':
// Pull the current active playlist items
$objects = $GLOBALS['user']->playlist->get_items();
$name = $GLOBALS['user']->username . ' - ' . date("d/m/Y H:i:s",time());
// generate the new playlist
$playlist_id = Playlist::create($name,'public');
$playlist = new Playlist($playlist_id);
// Itterate through and add them to our new playlist
foreach ($objects as $uid=>$object_data) {
// For now only allow songs on here, we'll change this later
if ($object_data['1'] == 'song') {
$songs[] = $object_data['0'];
}
} // object_data
// Add our new songs
$playlist->add_songs($songs);
$playlist->format();
ob_start();
require_once Config::get('prefix') . '/templates/show_playlist.inc.php';
$results['content'] = ob_get_contents();
ob_end_clean();
break;
default: default:
$results['rfc3514'] = '0x1'; $results['rfc3514'] = '0x1';
break; break;

35
server/stream.ajax.php Normal file
View file

@ -0,0 +1,35 @@
<?php
/*
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.
*/
/**
* Sub-Ajax page, requires AJAX_INCLUDE as one
*/
if (AJAX_INCLUDE != '1') { exit; }
switch ($_REQUEST['action']) {
default:
$results['rfc3514'] = '0x1';
break;
} // switch on action;
// We always do this
echo xml_from_array($results);
?>

View file

@ -79,6 +79,8 @@ if (Config::get('use_rss')) { ?>
</div> </div>
<!-- I hate IE... <!-- I hate IE...
<table class="smeg-ie" width="100%"><tr><td> --> <table class="smeg-ie" width="100%"><tr><td> -->
<!-- Tiny little iframe, used to cheat the system -->
<iframe id="util_iframe" style="display:none;" src="<?php echo Config::get('web_path'); ?>/util.php"></iframe>
<div id="content"> <div id="content">
<?php if (Config::get('int_config_version') != Config::get('config_version') AND $GLOBALS['user']->has_access(100)) { ?> <?php if (Config::get('int_config_version') != Config::get('config_version') AND $GLOBALS['user']->has_access(100)) { ?>
<div class="fatalerror"> <div class="fatalerror">

View file

@ -18,10 +18,14 @@
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/ */
?> ?>
<?php show_box_top(_('Active Playlist')); ?> <?php show_box_top(_('Active Playlist')); ?>
<ul> <ul>
<li><a href="<?php echo Config::get('web_path'); ?>/stream.php?action=basket"><?php echo get_user_icon('all'); ?></a></li> <li><a href="<?php echo Config::get('web_path'); ?>/stream.php?action=basket"><?php echo get_user_icon('all'); ?></a></li>
<li>
<?php echo Ajax::button('?page=playlist&action=create','playlist_add',_('Save as Playlist'),'rightbar_create_playlist'); ?>
</li>
<?php if (Access::check_function('batch_download')) { ?> <?php if (Access::check_function('batch_download')) { ?>
<li> <li>
<a href="<?php echo Config::get('web_path'); ?>/batch.php?action=tmp_playlist&amp;id=<?php echo $GLOBALS['user']->playlist->id; ?>"> <a href="<?php echo Config::get('web_path'); ?>/batch.php?action=tmp_playlist&amp;id=<?php echo $GLOBALS['user']->playlist->id; ?>">
@ -76,3 +80,16 @@
<?php echo _('Related Genre'); ?></span> <?php echo _('Related Genre'); ?></span>
</div> </div>
<?php show_box_bottom(); ?> <?php show_box_bottom(); ?>
<?php
// We do a little magic here to force a iframe reload depending on preference
// We do this last because we want it to load, and we want to know if there is anything
// to even pass
if ($GLOBALS['user']->prefs['playlist_method'] != 'default' AND AJAX_INCLUDE == '1' AND count($objects)) {
// Set the target
$_SESSION['iframe']['target'] = Config::get('web_path') . '/stream.php?action=basket';
echo "<script type=\"text/javascript\">";
echo "document.getElementById('util_iframe').contentWindow.location.reload(true);";
echo "</script>";
}
?>

32
util.php Normal file
View file

@ -0,0 +1,32 @@
<?php
/*
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.
*/
require_once 'lib/init.php';
// This is a little bit of a special file, it takes the
// content of $_SESSION['iframe']['target'] and does a header
// redirect to that spot!
if (isset($_SESSION['iframe']['target'])) {
$target = $_SESSION['iframe']['target'];
unset($_SESSION['iframe']['target']);
header("Location: " . $target);
}
?>