From 8e9678729653489a0839c14bc23d743e1509c319 Mon Sep 17 00:00:00 2001 From: Karl 'vollmerk' Vollmer Date: Mon, 30 Jul 2007 06:21:50 +0000 Subject: added your playlists with play link to the leftbar, no way to edit them yet --- docs/CHANGELOG | 1 + lib/class/playlist.class.php | 90 ++++++++++++++++++++----------------- lib/general.lib.php | 11 ++--- lib/playlist.lib.php | 32 ------------- playlist.php | 15 ++++--- server/ajax.server.php | 7 +++ templates/show_playlist.inc.php | 34 ++++++++++++++ templates/show_playlist_box.inc.php | 47 ------------------- templates/sidebar_home.inc.php | 17 ++++++- 9 files changed, 121 insertions(+), 133 deletions(-) create mode 100644 templates/show_playlist.inc.php delete mode 100644 templates/show_playlist_box.inc.php 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 @@ 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,17 +56,28 @@ 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 = '' . $this->name . ''; + + } // 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 @@ -54,38 +54,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 "
" . _("No songs in this playlist.") . "
\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 @@ 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.inc.php b/templates/show_playlist.inc.php new file mode 100644 index 00000000..6ae2d5f1 --- /dev/null +++ b/templates/show_playlist.inc.php @@ -0,0 +1,34 @@ + +name . ' ' . _('Playlist')); ?> + + + diff --git a/templates/show_playlist_box.inc.php b/templates/show_playlist_box.inc.php deleted file mode 100644 index 1d064e3e..00000000 --- a/templates/show_playlist_box.inc.php +++ /dev/null @@ -1,47 +0,0 @@ - - - - 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 @@
-->

-
- + +
+
+id); + foreach ($playlists as $playlist_id) { + $playlist = new Playlist($playlist_id); + $playlist->format(); +?> + + + f_link; ?> + + +
-- cgit