summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xdocs/CHANGELOG1
-rw-r--r--lib/class/playlist.class.php90
-rw-r--r--lib/general.lib.php11
-rw-r--r--lib/playlist.lib.php32
-rw-r--r--playlist.php15
-rw-r--r--server/ajax.server.php7
-rw-r--r--templates/show_playlist.inc.php (renamed from templates/show_playlist_box.inc.php)23
-rw-r--r--templates/sidebar_home.inc.php17
8 files changed, 92 insertions, 104 deletions
diff --git a/docs/CHANGELOG b/docs/CHANGELOG
index 46a042c8..e36d5d51 100755
--- a/docs/CHANGELOG
+++ b/docs/CHANGELOG
@@ -4,6 +4,7 @@
--------------------------------------------------------------------------
v.3.4-Alpha2
+ - Added 'Your' playlists to leftbar with play and view links
- Fixed clear now playing
- Fixed now playing issues with Audacious 1.3.x office space style
diff --git a/lib/class/playlist.class.php b/lib/class/playlist.class.php
index a5a6fd75..f5f570ec 100644
--- a/lib/class/playlist.class.php
+++ b/lib/class/playlist.class.php
@@ -1,13 +1,13 @@
<?php
/*
- Copyright (c) 2001 - 2006 Ampache.org
+ 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
- as published by the Free Software Foundation; either version 2
- of the License, or (at your option) any later version.
+ 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
@@ -26,31 +26,28 @@
class Playlist {
/* Variables from the Datbase */
- var $id;
- var $name;
- var $user;
- var $type;
- var $date;
+ public $id;
+ public $name;
+ public $user;
+ public $type;
+ public $date;
/* Generated Elements */
- var $items = array();
-
+ public $items = array();
/**
* Constructor
* This takes a playlist_id as an optional argument and gathers the information
* if not playlist_id is passed returns false (or if it isn't found
*/
- function Playlist($playlist_id = 0) {
+ public function __construct($id) {
- if (!$playlist_id) { return false; }
-
- $this->id = intval($playlist_id);
+ $this->id = intval($id);
$info = $this->_get_info();
- $this->name = $info['name'];
- $this->user = $info['user'];
- $this->type = $info['type'];
- $this->date = $info['date'];
+
+ foreach ($info as $key=>$value) {
+ $this->$key = $value;
+ }
} // Playlist
@@ -59,18 +56,29 @@ class Playlist {
* This is an internal (private) function that gathers the information for this object from the
* playlist_id that was passed in.
*/
- function _get_info() {
+ private function _get_info() {
- $sql = "SELECT * FROM `playlist` WHERE `id`='" . sql_escape($this->id) . "'";
- $db_results = mysql_query($sql, dbh());
+ $sql = "SELECT * FROM `playlist` WHERE `id`='" . Dba::escape($this->id) . "'";
+ $db_results = Dba::query($sql);
- $results = mysql_fetch_assoc($db_results);
+ $results = Dba::fetch_assoc($db_results);
return $results;
} // _get_info
/**
+ * format
+ * This takes the current playlist object and gussies it up a little
+ * bit so it is presentable to the users
+ */
+ public function format() {
+
+ $this->f_link = '<a href="' . Config::get('web_path') . '/playlist.php?action=show_playlist&amp;playlist_id=' . $this->id . '">' . $this->name . '</a>';
+
+ } // format
+
+ /**
* get_track
* Takes a playlist_data.id and returns the current track value for said entry
*/
@@ -90,16 +98,16 @@ class Playlist {
* This returns an array of playlist songs that are in this playlist. Because the same
* song can be on the same playlist twice they are key'd by the uid from playlist_data
*/
- function get_items() {
-
- $sql = "SELECT * FROM playlist_data WHERE playlist='" . sql_escape($this->id) . "' ORDER BY track";
- $db_results = mysql_query($sql, dbh());
+ public function get_items() {
- while ($r = mysql_fetch_assoc($db_results)) {
+ $results = array();
- $key = $r['id'];
- $results[$key] = $r;
+ $sql = "SELECT * FROM `playlist_data` WHERE `playlist`='" . Dba::escape($this->id) . "' ORDER BY `track`";
+ $db_results = Dba::query($sql);
+ while ($row = Dba::fetch_assoc($db_results)) {
+ $key = $row['id'];
+ $results[$key] = $row['song'];
} // end while
return $results;
@@ -225,23 +233,25 @@ class Playlist {
} // get_song_count
/**
- * has_access
- * This takes no arguments. It looks at the currently logged in user (_SESSION)
- * This accounts for admin powers and the access on a per list basis
+ * get_users
+ * This returns the specified users playlists as an array of
+ * playlist ids
*/
- function has_access() {
+ public static function get_users($user_id) {
- // Admin always have rights
- if ($GLOBALS['user']->has_access(100)) { return true; }
+ $user_id = Dba::escape($user_id);
+ $results = array();
- // People under 25 don't get playlist access even if they created it
- if (!$GLOBALS['user']->has_access(25)) { return false; }
+ $sql = "SELECT `id` FROM `playlist` WHERE `user`='$user_id'";
+ $db_results = Dba::query($sql);
- if ($this->user == $GLOBALS['user']->id) { return true; }
+ while ($row = Dba::fetch_assoc($db_results)) {
+ $results[] = $row['id'];
+ }
- return false;
+ return $results;
- } // has_access
+ } // get_users
/**
* update_type
diff --git a/lib/general.lib.php b/lib/general.lib.php
index ea1556d3..5c724f18 100644
--- a/lib/general.lib.php
+++ b/lib/general.lib.php
@@ -164,13 +164,14 @@ function session_exists($sid,$xml_rpc=0) {
} // session_exists
-/*!
- @function extend_session
- @discussion just update the expire time
-*/
+/**
+ * extend_session
+ * just updates the expire time of the specified session this
+ * is used by the the play script after a song finishes
+ */
function extend_session($sid) {
- $new_time = time() + Config::get('local_length');
+ $new_time = time() + Config::get('session_length');
if ($_COOKIE['amp_longsess'] == '1') { $new_time = time() + 86400*364; }
diff --git a/lib/playlist.lib.php b/lib/playlist.lib.php
index 7f069a31..5889a4b6 100644
--- a/lib/playlist.lib.php
+++ b/lib/playlist.lib.php
@@ -55,38 +55,6 @@ function show_playlists() {
} // show_playlists
/**
- * show_playlist
- * This function takes a playlist object and calls show_songs after
- * runing get_items()
- */
-function show_playlist($playlist) {
-
- /* Create the Playlist */
- $song_ids = $playlist->get_items();
-
-
- show_playlist_menu();
-
- if (count($song_ids) > 0) {
- show_songs($song_ids, $playlist);
- }
- else {
- echo "<div class=\"text-box\">" . _("No songs in this playlist.") . "</div>\n";
- }
-
-} // show_playlist
-
-/**
- * show_playlist_menu
- * This shows a little pretty box that contains the playlist 'functions'
- */
-function show_playlist_menu() {
-
- require (conf('prefix') . '/templates/show_playlist_box.inc.php');
-
-} // show_playlist_menu
-
-/**
* show_playlist_edit
* This function shows the edit form for a playlist, nothing special here
*/
diff --git a/playlist.php b/playlist.php
index 840d671c..3477ec2d 100644
--- a/playlist.php
+++ b/playlist.php
@@ -1,13 +1,13 @@
<?php
/*
- Copyright (c) 2001 - 2006 Ampache.org
+ 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
- as published by the Free Software Foundation; either version 2
- of the License, or (at your option) any later version.
+ 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
@@ -24,10 +24,9 @@
* This is the playlist document, it handles all things playlist.
*/
-require_once('lib/init.php');
+require_once 'lib/init.php';
-
-show_template('header');
+show_header();
/* Get the Vars we need for later cleaned up */
$action = strtolower(scrub_in($_REQUEST['action']));
@@ -143,7 +142,9 @@ switch ($action) {
show_confirmation($title,$body,$url);
break;
case 'show_playlist':
- show_playlist($playlist);
+ $playlist = new Playlist($_REQUEST['playlist_id']);
+ $playlist->format();
+ require_once Config::get('prefix') . '/templates/show_playlist.inc.php';
break;
case 'show_import_playlist':
show_import_playlist();
diff --git a/server/ajax.server.php b/server/ajax.server.php
index 2b1fdf30..1773db9b 100644
--- a/server/ajax.server.php
+++ b/server/ajax.server.php
@@ -197,6 +197,13 @@ switch ($action) {
$GLOBALS['user']->playlist->add_object($song_id,'song');
}
break;
+ case 'playlist':
+ $playlist = new Playlist($_REQUEST['id']);
+ $songs = $playlist->get_items();
+ foreach ($songs as $song_id) {
+ $GLOBALS['user']->playlist->add_object($song_id,'song');
+ }
+ break;
case 'clear_all':
$GLOBALS['user']->playlist->clear();
break;
diff --git a/templates/show_playlist_box.inc.php b/templates/show_playlist.inc.php
index 1d064e3e..6ae2d5f1 100644
--- a/templates/show_playlist_box.inc.php
+++ b/templates/show_playlist.inc.php
@@ -1,7 +1,6 @@
<?php
/*
-
- Copyright (c) 2001 - 2006 Ampache.org
+ Copyright (c) 2001 - 2007 Ampache.org
All rights reserved.
This program is free software; you can redistribute it and/or
@@ -23,25 +22,13 @@
* This box is used for actions on the main screen and on a specific playlist page
* It changes depending on where it is
*/
-
-$web_path = conf('web_path');
-$playlist_id = scrub_out($_REQUEST['playlist_id']);
-$title = _('Playlist Actions');
+$web_path = Config::get('web_path');
?>
-<?php require (conf('prefix') . '/templates/show_box_top.inc.php'); ?>
+<?php show_box_top($playlist->name . ' ' . _('Playlist')); ?>
<ul class="text-action">
- <?php if ($_REQUEST['playlist_id']) { ?>
- <li><a href="<?php echo $web_path; ?>/playlist.php?action=edit&amp;playlist_id=<?php echo $playlist_id; ?>"><?php echo _('Edit Playlist'); ?></a></li>
<li><a href="<?php echo $web_path; ?>/playlist.php?action=normalize_tracks&amp;playlist_id=<?php echo $playlist_id; ?>"><?php echo _('Normalize Tracks'); ?></a></li>
<li><a href="<?php echo $web_path; ?>/stream.php?action=play_selected&amp;playlist_id=<?php echo $playlist_id; ?>"><?php echo _('Play This Playlist'); ?></a></li>
<li><a href="<?php echo $web_path; ?>/stream.php?action=playlist_random&amp;playlist_id=<?php echo $playlist_id; ?>"><?php echo _('Play Random'); ?></a></li>
- <li><a href="<?php echo $web_path; ?>/playlist.php?action=show_delete_playlist&amp;playlist_id=<?php echo $playlist_id; ?>"><?php echo _('Delete This Playlist'); ?></a></li>
- <?php } else { ?>
- <li><a href="<?php echo $web_path; ?>/playlist.php?action=show_import_playlist"><?php echo _('Import From File'); ?></a></li>
- <li><a href="<?php echo $web_path; ?>/playlist.php?action=new"><?php echo _('Create New Playlist'); ?></a></li>
- <?php if ($GLOBALS['user']->has_access(100)) { ?>
- <li><a href="<?php echo $web_path; ?>/playlist.php?action=prune_empty"><?php echo _('Delete Empty Playlists'); ?></a></li>
- <?php } ?>
- <?php } ?>
</ul>
-<?php require (conf('prefix') . '/templates/show_box_bottom.inc.php'); ?>
+<?php show_box_bottom(); ?>
+
diff --git a/templates/sidebar_home.inc.php b/templates/sidebar_home.inc.php
index 0e546595..336dc3c5 100644
--- a/templates/sidebar_home.inc.php
+++ b/templates/sidebar_home.inc.php
@@ -46,5 +46,18 @@
<hr />
-->
<h4><?php echo _('Playlists'); ?></h4>
-<br />
-
+<span><a href="<?php echo $web_path; ?>/playlist.php?action=show_all"><?php echo _('View All'); ?></a></span>
+<hr />
+<div style="left-padding:5px;">
+<?php
+ $playlists = Playlist::get_users($GLOBALS['user']->id);
+ foreach ($playlists as $playlist_id) {
+ $playlist = new Playlist($playlist_id);
+ $playlist->format();
+?>
+<span>
+ <?php echo Ajax::button('?action=basket&type=playlist&id=' . $playlist_id,'all',_('Play This Playlist'),'leftbar_playlist_' . $playlist_id); ?>
+ <?php echo $playlist->f_link; ?>
+</span>
+<?php } // end foreach playlist ?>
+</div>