summaryrefslogtreecommitdiffstats
path: root/lib/class
diff options
context:
space:
mode:
authorKarl 'vollmerk' Vollmer <vollmer@ampache.org>2006-04-08 05:58:05 +0000
committerKarl 'vollmerk' Vollmer <vollmer@ampache.org>2006-04-08 05:58:05 +0000
commit2b55e30467f5ccdf9324b0377c419c5681f4c215 (patch)
tree16c2f63178ff762a673face6abb7fe584b680b36 /lib/class
parent941afedab85ffd77a83188ca09a888e0603fae72 (diff)
downloadampache-2b55e30467f5ccdf9324b0377c419c5681f4c215.tar.gz
ampache-2b55e30467f5ccdf9324b0377c419c5681f4c215.tar.bz2
ampache-2b55e30467f5ccdf9324b0377c419c5681f4c215.zip
This update includes a full rewrite of the Localplay code, only update
to this version if you don't care about losing a lot of functionality while I am still finishing it up. Also the only working localplay method is currently MPD. UPDATE AT YOUR OWN RISK!
Diffstat (limited to 'lib/class')
-rw-r--r--lib/class/localplay.class.php119
-rw-r--r--lib/class/stream.class.php32
-rw-r--r--lib/class/update.class.php123
-rw-r--r--lib/class/user.class.php16
4 files changed, 257 insertions, 33 deletions
diff --git a/lib/class/localplay.class.php b/lib/class/localplay.class.php
index 69b48cdf..232e9158 100644
--- a/lib/class/localplay.class.php
+++ b/lib/class/localplay.class.php
@@ -47,10 +47,6 @@ class Localplay {
$this->_get_info();
- /* Test for a connection */
- $this->connect();
-
-
} // Localplay
@@ -103,7 +99,7 @@ class Localplay {
/* Check the function map, if it's got a value it must
* be possible
*/
- if (strlen($this->_function_map) > 0) { return true; }
+ if (strlen($this->_function_map[$function_name]) > 0) { return true; }
return false;
@@ -120,15 +116,18 @@ class Localplay {
* be function names that are called on the action in question
*/
function _map_functions($data) {
-
+
/* Required Functions */
$this->_function_map['add'] = $data['add'];
$this->_function_map['delete'] = $data['delete'];
$this->_function_map['play'] = $data['play'];
$this->_function_map['stop'] = $data['stop'];
+ $this->_function_map['get'] = $data['get'];
$this->_function_map['connect'] = $data['connect'];
/* Recommended Functions */
+ $this->_function_map['status'] = $data['status'];
+ $this->_function_map['pause'] = $data['pause'];
$this->_function_map['next'] = $data['next'];
$this->_function_map['prev'] = $data['prev'];
$this->_function_map['get_playlist'] = $data['get_playlist'];
@@ -205,10 +204,118 @@ class Localplay {
/* Call the Function Specified in the Function Map */
+ $function = $this->_function_map['add'];
+ if (!$this->_player->$function($songs)) {
+ debug_event('localplay','Error Unable to add songs, check ' . $this->type . ' controller','1');
+ return false;
+ }
+
+
+ return true;
} // add
+ /**
+ * status
+ * This returns current information about the state of the player
+ * There is an expected array format
+ */
+ function status() {
+
+ $function = $this->_function_map['status'];
+
+ $data = $this->_player->$function();
+
+ if (!count($data)) {
+ debug_event('localplay','Error Unable to get status, check ' . $this->type . ' controller','1');
+ return false;
+ }
+
+ return $data;
+
+ } // status
+
+ /**
+ * get
+ * This calls the get function of the player and then returns
+ * the array of current songs for display or whatever
+ */
+ function get() {
+
+ $function = $this->_function_map['get'];
+
+ $data = $this->_player->$function();
+
+ if (!count($data)) {
+ debug_event('localplay','Error Unable to get song info, check ' . $this->type . ' controller','1');
+ return false;
+ }
+
+ return $data;
+
+ } // get
+
+ /**
+ * next
+ * This isn't a required function, it tells the daemon to go to the next
+ * song
+ */
+ function next() {
+
+ $function = $this->_function_map['next'];
+
+ if (!$this->_player->$function()) {
+ debug_event('localplay','Error: Unable to skip to next song, check ' . $this->type . ' controller','1');
+ return false;
+ }
+
+ return true;
+
+ } // next
+
+ /**
+ * prev
+ * This isn't a required function, it tells the daemon to go the the previous
+ * song
+ */
+ function prev() {
+
+ $function = $this->_function_map['prev'];
+
+ if (!$this->_player->$function()) {
+ debug_event('localplay','Error: Unable to skip to previous song, check ' . $this->type . ' controller','1');
+ return false;
+ }
+
+ return true;
+
+ } // prev
+
+ /**
+ * get_preferences
+ * This functions returns an array of the preferences that the localplay
+ * controller needs in order to actually work
+ */
+ function get_preferences() {
+
+ $preferences = $this->_player->preferences();
+
+ return $preferences;
+
+ } // get_preferences
+
+ /**
+ * delete
+ * This removes songs from the players playlist as defined get function
+ */
+ function delete($songs) {
+
+
+
+ } // delete
+
+
} //end localplay class
?>
diff --git a/lib/class/stream.class.php b/lib/class/stream.class.php
index 9bf5b7f1..f30c348d 100644
--- a/lib/class/stream.class.php
+++ b/lib/class/stream.class.php
@@ -232,25 +232,19 @@ class Stream {
} // create_icecast2
- /*!
- @function create_local_play
- @discussion pushes out localplay mojo
- */
- function create_local_play() {
-
- foreach($this->songs as $song_id) {
- $song = new Song($song_id);
- $song->format_song();
- $song_name = $song->f_artist_full . " - " . $song->title . "." . $song->type;
- $url = escapeshellarg("$this->web_path/play/?song=$song_id&uid=$this->user_id&sid=$this->sess&name=" . rawurlencode($song_name));
- $localplay_add = conf('localplay_add');
- $localplay_add = str_replace("%URL%", $url, $localplay_add);
- if (conf('debug')) {
- log_event($_SESSION['userdata']['username'],"localplay","Exec: $localplay_add");
- }
- exec($localplay_add);
- header("Location: " . conf('web_path') . "/index.php");
- }
+ /**
+ * create_localplay
+ * This calls the Localplay API and attempts to
+ * add, and then start playback
+ */
+ function create_localplay() {
+
+ $localplay = init_localplay();
+ $localplay->connect();
+ $localplay->add($this->songs);
+ $localplay->play();
+
+ header("Location: " . return_referer());
} // create_localplay
diff --git a/lib/class/update.class.php b/lib/class/update.class.php
index 318b9a9d..1fb90350 100644
--- a/lib/class/update.class.php
+++ b/lib/class/update.class.php
@@ -271,6 +271,11 @@ class Update {
$version[] = array('version' => '332009','description' => $update_string);
+ $update_string = '- Reconfigure preferences to account for the new Localplay API, this also removes some preferences' .
+ ' from the web interface, see /test.php for any setting you may be missing';
+
+ $version[] = array('version' => '332010','description' => $update_string);
+
return $version;
} // populate_version
@@ -1466,5 +1471,123 @@ class Update {
} // update_332009
+ /**
+ * update_332010
+ * This update changes the preferences table yet again... :(
+ */
+ function update_332010() {
+
+ /* Drop the Locked option */
+ $sql = "ALTER TABLE `preferences` DROP `locked`";
+ $db_results = mysql_query($sql, dbh());
+
+ /* Add the New catagory field */
+ $sql = "ALTER TABLE `preferences` ADD `catagory` VARCHAR( 128 ) NOT NULL AFTER `type`";
+ $db_results = mysql_query($sql, dbh());
+
+ /* Grab all of the Types and populate it into the catagory */
+ $sql = "SELECT id,type FROM preferences";
+ $db_results = mysql_query($sql, dbh());
+
+ while ($r = mysql_fetch_assoc($db_results)) {
+ $key = $r['id'];
+ $results[$key] = $r['type'];
+ }
+
+ foreach ($results as $key=>$catagory) {
+
+ $sql = "UPDATE preferences SET catagory='" . $catagory . "' WHERE id='$key'";
+ $db_results = mysql_query($sql, dbh());
+
+ } // foreach preferences
+
+ /* Drop the Refresh Limit Option */
+ $sql = "DELETE FROM preferences WHERE name='refresh_limit'";
+ $db_results = mysql_query($sql, dbh());
+
+ /* Drop the Local Length */
+ $sql = "DELETE FROM preferences WHERE name='local_length'";
+ $db_results = mysql_query($sql, dbh());
+
+ /* Drop The cache limits */
+ $sql = "DELETE FROM preferences WHERE name='album_cache_limit'";
+ $db_results = mysql_query($sql, dbh());
+
+ $sql = "DELETE FROM preferences WHERE name='artist_cache_limit'";
+ $db_results = mysql_query($sql, dbh());
+
+ $sql = "DELETE FROM preferences WHERE name='condPL'";
+ $db_results = mysql_query($sql, dbh());
+
+ /* Insert the new Localplay Level */
+ $sql = "INSERT INTO preferences (`name`,`value`,`description`,`level`,`type`,`catagory`) " .
+ " VALUES ('localplay_level','0','Localplay Access Level','100','special','streaming')";
+ $db_results = mysql_query($sql, dbh());
+
+ /* Inser the new Localplay Controller */
+ $sql = "INSERT INTO preferences (`name`,`value`,`description`,`level`,`type`,`catagory`) " .
+ " VALUES ('localplay_controller','0','Localplay Type','100','special','streaming')";
+ $db_results = mysql_query($sql, dbh());
+
+ /* Set the Types for everything */
+ $types['download'] = 'boolean';
+ $types['upload'] = 'boolean';
+ $types['quarantine'] = 'boolean';
+ $types['popular_threshold'] = 'integer';
+ $types['font'] = 'string';
+ $types['bg_color1'] = 'string';
+ $types['bg_color2'] = 'string';
+ $types['base_color1'] = 'string';
+ $types['base_color2'] = 'string';
+ $types['font_color1'] = 'string';
+ $types['font_color2'] = 'string';
+ $types['font_color3'] = 'string';
+ $types['row_color1'] = 'string';
+ $types['row_color2'] = 'string';
+ $types['row_color3'] = 'string';
+ $types['error_color'] = 'string';
+ $types['font_size'] = 'integer';
+ $types['upload_dir'] = 'string';
+ $types['sample_rate'] = 'string';
+ $types['site_title'] = 'string';
+ $types['lock_songs'] = 'boolean';
+ $types['force_http_play'] = 'boolean';
+ $types['http_port'] = 'integer';
+ $types['catalog_echo_count'] = 'integer';
+ $types['play_type'] = 'special';
+ $types['direct_link'] = 'boolean';
+ $types['lang'] = 'special';
+ $types['playlist_type'] = 'special';
+ $types['theme_name'] = 'special';
+ $types['ellipse_threshold_album'] = 'integer';
+ $types['ellipse_threshold_artist'] = 'integer';
+ $types['ellipse_threshold_title'] = 'integer';
+ $types['quarantine_dir'] = 'string';
+ $types['localplay_level'] = 'special';
+ $types['localplay_controller'] = 'special';
+
+ /* Now we need to insert this crap */
+ foreach ($types as $key=>$type) {
+
+ $sql = "UPDATE preferences SET type='$type' WHERE name='$key'";
+ $db_results = mysql_query($sql, dbh());
+
+ } // foreach types
+
+ /* Fix every users preferences */
+ $sql = "SELECT * FROM user";
+ $db_results = mysql_query($sql, dbh());
+
+ $user = new User();
+ $user->fix_preferences('-1');
+
+ while ($r = mysql_fetch_assoc($db_results)) {
+ $user->fix_preferences($r['username']);
+ } // while results
+
+ $this->set_version('db_version','332010');
+
+ } // update_332010
+
} // end update class
?>
diff --git a/lib/class/user.class.php b/lib/class/user.class.php
index e4567ef0..5e28d2b5 100644
--- a/lib/class/user.class.php
+++ b/lib/class/user.class.php
@@ -98,21 +98,21 @@ class User {
if (!conf('use_auth')) { $user_id = '-1'; }
if ($user_id != '-1') {
- $user_limit = "AND preferences.type != 'system'";
+ $user_limit = "AND preferences.catagory != 'system'";
}
if ($type != '0') {
- $user_limit = "AND preferences.type = '" . sql_escape($type) . "'";
+ $user_limit = "AND preferences.catagory = '" . sql_escape($type) . "'";
}
- $sql = "SELECT preferences.name, preferences.description, preferences.type, user_preference.value FROM preferences,user_preference " .
+ $sql = "SELECT preferences.name, preferences.description, preferences.catagory, user_preference.value FROM preferences,user_preference " .
"WHERE user_preference.user='$user_id' AND user_preference.preference=preferences.id $user_limit";
$db_results = mysql_query($sql, dbh());
/* Ok this is crapy, need to clean this up or improve the code FIXME */
while ($r = mysql_fetch_assoc($db_results)) {
- $type = $r['type'];
+ $type = $r['catagory'];
$admin = false;
if ($type == 'system') { $admin = true; }
$type_array[$type][] = array('name'=>$r['name'],'description'=>$r['description'],'value'=>$r['value']);
@@ -131,7 +131,7 @@ class User {
*/
function set_preferences() {
- $sql = "SELECT preferences.name,user_preference.value FROM preferences,user_preference WHERE user_preference.user='$this->username' " .
+ $sql = "SELECT preferences.name,user_preference.value FROM preferences,user_preference WHERE user_preference.user='$this->id' " .
"AND user_preference.preference=preferences.id AND preferences.type != 'system'";
$db_results = mysql_query($sql, dbh());
@@ -274,7 +274,7 @@ class User {
} // update_preference
/**
- * add_preference
+ * legacy_add_preference
* adds a new preference
* @package User
* @catagory Class
@@ -640,7 +640,7 @@ class User {
*/
if ($user_id != '-1') {
$sql = "SELECT user_preference.preference,user_preference.value FROM user_preference,preferences " .
- "WHERE user_preference.preference = preferences.id AND user_preference.user='-1' AND preferences.type !='system'";
+ "WHERE user_preference.preference = preferences.id AND user_preference.user='-1' AND preferences.catagory !='system'";
$db_results = mysql_query($sql, dbh());
while ($r = mysql_fetch_object($db_results)) {
$zero_results[$r->preference] = $r->value;
@@ -650,7 +650,7 @@ class User {
$sql = "SELECT * FROM preferences";
if ($user_id != '-1') {
- $sql .= " WHERE type !='system'";
+ $sql .= " WHERE catagory !='system'";
}
$db_results = mysql_query($sql, dbh());