summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorKarl 'vollmerk' Vollmer <vollmer@ampache.org>2007-05-13 00:32:57 +0000
committerKarl 'vollmerk' Vollmer <vollmer@ampache.org>2007-05-13 00:32:57 +0000
commit6eac7541290086509cf1531a48ab2734ac48081a (patch)
treea4e1350fdcf765fb8a9d85ff0c513a296fdec946 /lib
parent2939f419e15589ab9fb73c6fd197e577238c6677 (diff)
downloadampache-6eac7541290086509cf1531a48ab2734ac48081a.tar.gz
ampache-6eac7541290086509cf1531a48ab2734ac48081a.tar.bz2
ampache-6eac7541290086509cf1531a48ab2734ac48081a.zip
added in the playlist bar, and the auto-loading of a tmp playlist per session
Diffstat (limited to 'lib')
-rw-r--r--lib/class/tmpplaylist.class.php (renamed from lib/class/tmp_playlist.class.php)39
-rw-r--r--lib/class/user.class.php14
-rw-r--r--lib/gettext.php14
-rw-r--r--lib/init.php3
4 files changed, 70 insertions, 0 deletions
diff --git a/lib/class/tmp_playlist.class.php b/lib/class/tmpplaylist.class.php
index 30b66ecc..562132fc 100644
--- a/lib/class/tmp_playlist.class.php
+++ b/lib/class/tmpplaylist.class.php
@@ -74,6 +74,30 @@ class tmpPlaylist {
} // _get_info
/**
+ * get_from_session
+ * This returns a playlist object based on the session that is passed to us
+ * this is used by the load_playlist on user for the most part
+ */
+ public static function get_from_session($session_id) {
+
+ $session_id = Dba::escape($session_id);
+
+ $sql = "SELECT `id` FROM `tmp_playlist` WHERE `session`='$session_id'";
+ $db_results = Dba::query($sql);
+
+ $results = Dba::fetch_row($db_results);
+
+ if (!$results['0']) {
+ $results['0'] = tmpPlaylist::create($session_id,'user','song','0');
+ }
+
+ $playlist = new tmpPlaylist($results['0']);
+
+ return $playlist;
+
+ } // get_from_session
+
+ /**
* get_items
* This returns an array of all object_ids currently in this tmpPlaylist
*/
@@ -163,6 +187,21 @@ class tmpPlaylist {
} // get_vote_url
+ /**
+ * count_items
+ * This returns a count of the total number of tracks that are in this tmp playlist
+ */
+ public function count_items() {
+
+ $sql = "SELECT COUNT(`id`) FROM `tmp_playlist_data` WHERE `tmp_playlist_data`.`tmp_playlist`='" . $this->id . "'";
+ $db_results = Dba::query($sql);
+
+ $results = Dba::fetch_row($db_results);
+
+ return $results['0'];
+
+ } // count_items
+
/**
* create
* This function initializes a new tmpPlaylist it is assoicated with the current
diff --git a/lib/class/user.class.php b/lib/class/user.class.php
index c446e4d6..990a27ce 100644
--- a/lib/class/user.class.php
+++ b/lib/class/user.class.php
@@ -83,6 +83,20 @@ class User {
} // _get_info
/**
+ * load_playlist
+ * This is called once per page load it makes sure that this session
+ * has a tmp_playlist, creating it if it doesn't, then sets $this->playlist
+ * as a tmp_playlist object that can be fiddled with later on
+ */
+ public function load_playlist() {
+
+ $session_id = session_id();
+
+ $this->playlist = tmpPlaylist::get_from_session($session_id);
+
+ } // load_playlist
+
+ /**
* get_from_username
* This returns a built user from a username. This is a
* static function so it doesn't require an instance
diff --git a/lib/gettext.php b/lib/gettext.php
index ed929241..0052a247 100644
--- a/lib/gettext.php
+++ b/lib/gettext.php
@@ -49,5 +49,19 @@ function load_gettext() {
} // load_gettext
+/**
+ * __
+ * This function does the same as _ on the supplied
+ * string, but also does a str_replace on the supplied
+ * vars
+ */
+function __($string,$subject,$replace) {
+
+ $translated = _($string);
+ $result = str_replace($subject,$replace,$translated);
+ return $result;
+
+} // __
+
?>
diff --git a/lib/init.php b/lib/init.php
index 68a6db21..3a72f40a 100644
--- a/lib/init.php
+++ b/lib/init.php
@@ -225,6 +225,9 @@ else {
// Load the Preferences from the database
init_preferences();
+// We need to create the tmp playlist for our user
+$GLOBALS['user']->load_playlist();
+
/* Add in some variables for ajax done here because we need the user */
Config::set('ajax_url',Config::get('web_path') . '/server/ajax.server.php',1);