diff options
-rwxr-xr-x | docs/CHANGELOG | 4 | ||||
-rw-r--r-- | images/icon_playlist_add.png | bin | 0 -> 811 bytes | |||
-rw-r--r-- | lib/class/playlist.class.php | 38 | ||||
-rw-r--r-- | lib/preferences.php | 7 | ||||
-rw-r--r-- | server/playlist.ajax.php | 26 | ||||
-rw-r--r-- | server/stream.ajax.php | 35 | ||||
-rw-r--r-- | templates/header.inc.php | 2 | ||||
-rw-r--r-- | templates/rightbar.inc.php | 17 | ||||
-rw-r--r-- | util.php | 32 |
9 files changed, 139 insertions, 22 deletions
diff --git a/docs/CHANGELOG b/docs/CHANGELOG index ac69e5d3..9060e41f 100755 --- a/docs/CHANGELOG +++ b/docs/CHANGELOG @@ -4,6 +4,10 @@ -------------------------------------------------------------------------- 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 missing artist name on Albums of the Moment - Added simple Playlist element view, non-editable diff --git a/images/icon_playlist_add.png b/images/icon_playlist_add.png Binary files differnew file mode 100644 index 00000000..d650552d --- /dev/null +++ b/images/icon_playlist_add.png diff --git a/lib/class/playlist.class.php b/lib/class/playlist.class.php index 0daff266..62628bb7 100644 --- a/lib/class/playlist.class.php +++ b/lib/class/playlist.class.php @@ -320,30 +320,30 @@ class Playlist { * if you want to add a dyn_song you need to use the one shot function * 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 * append, rather then integrate take end track # and add it to * $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"; - $db_results = mysql_query($sql, dbh()); - $data = mysql_fetch_assoc($db_results); + $sql = "SELECT `track` FROM `playlist_data` WHERE `playlist`='" . $this->id . "' ORDER BY `track` DESC LIMIT 1"; + $db_results = Dba::query($sql); + $data = Dba::fetch_assoc($db_results); $base_track = $data['track']; foreach ($song_ids as $song_id) { /* We need the songs track */ $song = new Song($song_id); - $track = sql_escape($song->track+$base_track); - $id = sql_escape($song->id); - $pl_id = sql_escape($this->id); + $track = Dba::escape($song->track+$base_track); + $id = Dba::escape($song->id); + $pl_id = Dba::escape($this->id); /* Don't insert dead songs */ if ($id) { - $sql = "INSERT INTO playlist_data (`playlist`,`song`,`track`) " . - " VALUES ('$pl_id','$id','$track')"; - $db_results = mysql_query($sql, dbh()); + $sql = "INSERT INTO `playlist_data` (`playlist`,`object_id`,`object_type`,`track`) " . + " VALUES ('$pl_id','$id','song','$track')"; + $db_results = Dba::query($sql); } // if valid id } // end foreach songs @@ -382,22 +382,22 @@ class Playlist { * This function creates an empty playlist, gives it a name and type * Assumes $GLOBALS['user']->id as the user */ - function create($name,$type) { + public static function create($name,$type) { - $name = sql_escape($name); - $type = sql_escape($type); - $user = sql_escape($GLOBALS['user']->id); + $name = Dba::escape($name); + $type = Dba::escape($type); + $user = Dba::escape($GLOBALS['user']->id); $date = time(); - $sql = "INSERT INTO playlist (`name`,`user`,`type`,`date`) " . - " VALUES ('$name','$user','$type','$date')"; - $db_results = mysql_query($sql, dbh()); + $sql = "INSERT INTO `playlist` (`name`,`user`,`type`,`genre`,`date`) " . + " VALUES ('$name','$user','$type','0','$date')"; + $db_results = Dba::query($sql); - $insert_id = mysql_insert_id(dbh()); + $insert_id = Dba::insert_id(); return $insert_id; - } //create_paylist + } // create /** * set_items diff --git a/lib/preferences.php b/lib/preferences.php index fe404331..6ab531fc 100644 --- a/lib/preferences.php +++ b/lib/preferences.php @@ -339,10 +339,11 @@ function create_preference_input($name,$value) { echo "</select>\n"; break; case 'playlist_method': + ${$value} = ' selected="selected"'; echo "<select name=\"$name\">\n"; - echo "\t<option value=\"send\">" . _('Send on Add') . "</option>\n"; - echo "\t<option value=\"send\">" . _('Send and Clear') . "</option>\n"; - echo "\t<option value=\"default\">" . _('Default') . "</option>\n"; + echo "\t<option value=\"send\"$send>" . _('Send on Add') . "</option>\n"; + echo "\t<option value=\"send_clear\"$send_clear>" . _('Send and Clear') . "</option>\n"; + echo "\t<option value=\"default\"$default>" . _('Default') . "</option>\n"; echo "</select>\n"; break; case 'transcode': diff --git a/server/playlist.ajax.php b/server/playlist.ajax.php index f2198faa..158e7fe2 100644 --- a/server/playlist.ajax.php +++ b/server/playlist.ajax.php @@ -39,6 +39,32 @@ switch ($_REQUEST['action']) { $results['browse_content'] = ob_get_contents(); ob_end_clean(); 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: $results['rfc3514'] = '0x1'; break; diff --git a/server/stream.ajax.php b/server/stream.ajax.php new file mode 100644 index 00000000..744e0a3d --- /dev/null +++ b/server/stream.ajax.php @@ -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); +?> diff --git a/templates/header.inc.php b/templates/header.inc.php index 90f4782a..e4a95048 100644 --- a/templates/header.inc.php +++ b/templates/header.inc.php @@ -79,6 +79,8 @@ if (Config::get('use_rss')) { ?> </div> <!-- I hate IE... <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"> <?php if (Config::get('int_config_version') != Config::get('config_version') AND $GLOBALS['user']->has_access(100)) { ?> <div class="fatalerror"> diff --git a/templates/rightbar.inc.php b/templates/rightbar.inc.php index 8ff3e856..82cbebac 100644 --- a/templates/rightbar.inc.php +++ b/templates/rightbar.inc.php @@ -18,10 +18,14 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + ?> <?php show_box_top(_('Active Playlist')); ?> <ul> <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')) { ?> <li> <a href="<?php echo Config::get('web_path'); ?>/batch.php?action=tmp_playlist&id=<?php echo $GLOBALS['user']->playlist->id; ?>"> @@ -76,3 +80,16 @@ <?php echo _('Related Genre'); ?></span> </div> <?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>"; +} +?> diff --git a/util.php b/util.php new file mode 100644 index 00000000..e3760c42 --- /dev/null +++ b/util.php @@ -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); +} +?> |