From 2b55e30467f5ccdf9324b0377c419c5681f4c215 Mon Sep 17 00:00:00 2001 From: Karl 'vollmerk' Vollmer Date: Sat, 8 Apr 2006 05:58:05 +0000 Subject: 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! --- lib/class/localplay.class.php | 119 +++++++++++++++++++-- lib/class/stream.class.php | 32 +++--- lib/class/update.class.php | 123 ++++++++++++++++++++++ lib/class/user.class.php | 16 +-- lib/localplay.lib.php | 238 ++++++++++++++++++++++++++++++++++++++++++ lib/mpd.php | 142 ------------------------- lib/preferences.php | 73 +++++++++---- lib/ui.lib.php | 46 +++----- 8 files changed, 561 insertions(+), 228 deletions(-) create mode 100644 lib/localplay.lib.php delete mode 100644 lib/mpd.php (limited to 'lib') 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()); diff --git a/lib/localplay.lib.php b/lib/localplay.lib.php new file mode 100644 index 00000000..c0ef6e32 --- /dev/null +++ b/lib/localplay.lib.php @@ -0,0 +1,238 @@ +type == ".flac") { $song->type = ".ogg"; } + if ($GLOBALS['user']->prefs['play_type'] == 'downsample') { + $ds = $GLOBALS['user']->prefs['sample_rate']; + } + $song_url = conf('web_path') . "/play/index.php?song=$song_id&uid=" . $_SESSION['userdata']['username'] . "&sid=$sess_id&ds=$ds&name=." . $song->type; + if (is_null( $myMpd->PlAdd($song_url) ) ) { + $log_line = _("Error") . ": " . _("Could not add") . ": " . $song_url . " : " . $myMpd->errStr; + echo "$log_line
\n"; + if (conf('debug')) { log_event($GLOBALS['user']->username,'add',$log_line); } + } // if it's null + } // if we want urls + else { + $song = new Song( $song_id ); + $song_filename = $song->get_rel_path(); + if( is_null( $myMpd->PLAdd( $song_filename ) ) ) { + $log_line = _("Error") . ": " . _("Could not add") . ": " . $song_filename . " : " . $myMpd->errStr; + echo "$log_line
\n"; + if (conf('debug')) { log_event($_SESSION['userdata']['username'],'add',$log_line); } + } // end if it's null + // We still need to count if they use the file method + else { + $GLOBALS['user']->update_stats( $song_id ); + } // end else + + } // end else not url method + } // end foreach + +} // addToPlaylist + +/*! + @function show_mpd_control + @discussion shows the mpd controls +*/ +function show_mpd_control() { + + $_REQUEST['action'] = 'show_control'; + require (conf('prefix').'/amp-mpd.php'); + + +} // show_mpd_control + +/** + * show_mpd_pl + * Shows the MPD playlist + * @package Local Play + * @catagory MPD + */ +function show_mpd_pl() { + + $myMpd = init_mpd(); + + require (conf('prefix').'/templates/show_mpdpl.inc'); +} // show_mpd_pl + +/** + * mpd_redirect + * Redriect mojo + * @package Local Play + * @catagory MPD + * @param $page is the URL after conf('web_path') . '/' + */ +function mpd_redirect( $page = 'mpd.php' ) { + if (conf('localplay_menu')) { + header ("Location: " . conf('web_path') . '/' . $page); + } + else { + header ("Location: " . conf('web_path')); + } +} // mpd_redirect + +/** + * verify_localplay_prefrences + * This takes a type of localplay and then + * Verifys that the preferences have all been + * inserted into the database if they haven't been + * Then it returns false + */ +function verify_localplay_preferences($type) { + + /* Load the locaplay module of said type */ + $localplay = new Localplay($type); + + $preferences = $localplay->get_preferences(); + + foreach ($preferences as $preference) { + $name = 'localplay_' . $type . '_' . $preference['name']; + /* check for an existing record */ + $sql = "SELECT id FROM preferences WHERE name = '" . sql_escape($name) . "'"; + $db_results = mysql_query($sql, dbh()); + + if (!mysql_num_rows($db_results)) { return false; } + + } // end foreach preferences + + return true; + +} // verify_localplay_preferences + + +/** + * insert_locaplay_preferences + * This takes a controller type and inserts the preferences + * Into the database, it is able to handle existing preferences + * It checks before inserting... + */ +function insert_localplay_preferences($type) { + + /* We can't assume the connect so let's just + * create it then get the preferences + */ + $localplay = new Localplay($type); + + $preferences = $localplay->get_preferences(); + + foreach ($preferences as $preference) { + $name = 'localplay_' . $type . '_' . $preference['name']; + /* Check for an existing record */ + $sql = "SELECT id FROM preferences WHERE name = '" . sql_escape($name) . "'"; + $db_results = mysql_query($sql, dbh()); + + if (mysql_num_rows($db_results)) { continue; } + + insert_preference($name,$preference['description'],$preference['default'],'25',$preference['type'],'streaming'); + + } // end foreach preferences + + /* Fix everyones preferences */ + $sql = "SELECT * FROM user"; + $db_results = mysql_query($sql, dbh()); + + $temp_user = new User(); + $temp_user->fix_preferences('-1'); + + while ($r = mysql_fetch_assoc($db_results)) { + $temp_user->fix_preferences($r['username']); + } // end while + + return true; + +} // insert_localplay_preferences + + +/** + * get_localplay_controllers + * This returns an array of the localplay controllers filenames + * as well as a 'semi-cleaned' name + */ +function get_localplay_controllers() { + + /* First get a list of the files */ + $handle = opendir(conf('prefix') . '/modules/localplay'); + + if (!is_resource($handle)) { + debug_event('localplay','Error: Unable to read localplay controller directory','1'); + } + + $results = array(); + + while ($file = readdir($handle)) { + + if (substr($file,-14,14) != 'controller.php') { continue; } + + /* Make sure it isn't a subdir */ + if (!is_dir($file)) { + /* Get the base name, then get everything before .controller.php */ + $filename = basename($file,'.controller.php'); + $results[] = $filename; + } + } // end while + + return $results; + +} // get_localplay_controllers + + +/** + * This function stores the Localplay object + * It checks to see what access level you have + * and creates the localplay object based on that + * @package Local Play + */ +function init_localplay($reload=0) { + + static $localplay; + + if ($GLOBALS['user']->prefs['localplay_level'] == '0') { return false; } + + if ($GLOBALS['user']->prefs['localplay_level'] == '1' AND !is_object($localplay)) { + $localplay = new Localplay(conf('localplay_controller')); + $localplay->connect(); + } + + if ($GLOBALS['user']->prefs['localplay_level'] == '2' AND !is_object($localplay)) { + $localplay = new Localplay($GLOBALS['user']->prefs['localplay_controller']); + $localplay->connect(); + } + + return $localplay; + +} // function init_localplay + +?> diff --git a/lib/mpd.php b/lib/mpd.php deleted file mode 100644 index 26053267..00000000 --- a/lib/mpd.php +++ /dev/null @@ -1,142 +0,0 @@ -type == ".flac") { $song->type = ".ogg"; } - if ($GLOBALS['user']->prefs['play_type'] == 'downsample') { - $ds = $GLOBALS['user']->prefs['sample_rate']; - } - $song_url = conf('web_path') . "/play/index.php?song=$song_id&uid=" . $_SESSION['userdata']['username'] . "&sid=$sess_id&ds=$ds&name=." . $song->type; - if (is_null( $myMpd->PlAdd($song_url) ) ) { - $log_line = _("Error") . ": " . _("Could not add") . ": " . $song_url . " : " . $myMpd->errStr; - echo "$log_line
\n"; - if (conf('debug')) { log_event($GLOBALS['user']->username,'add',$log_line); } - } // if it's null - } // if we want urls - else { - $song = new Song( $song_id ); - $song_filename = $song->get_rel_path(); - if( is_null( $myMpd->PLAdd( $song_filename ) ) ) { - $log_line = _("Error") . ": " . _("Could not add") . ": " . $song_filename . " : " . $myMpd->errStr; - echo "$log_line
\n"; - if (conf('debug')) { log_event($_SESSION['userdata']['username'],'add',$log_line); } - } // end if it's null - // We still need to count if they use the file method - else { - $GLOBALS['user']->update_stats( $song_id ); - } // end else - - } // end else not url method - } // end foreach - -} // addToPlaylist - -/*! - @function show_mpd_control - @discussion shows the mpd controls -*/ -function show_mpd_control() { - - $_REQUEST['action'] = 'show_control'; - require (conf('prefix').'/amp-mpd.php'); - - -} // show_mpd_control - -/** - * show_mpd_pl - * Shows the MPD playlist - * @package Local Play - * @catagory MPD - */ -function show_mpd_pl() { - - $myMpd = init_mpd(); - - require (conf('prefix').'/templates/show_mpdpl.inc'); -} // show_mpd_pl - -/** - * mpd_redirect - * Redriect mojo - * @package Local Play - * @catagory MPD - * @param $page is the URL after conf('web_path') . '/' - */ -function mpd_redirect( $page = 'mpd.php' ) { - if (conf('localplay_menu')) { - header ("Location: " . conf('web_path') . '/' . $page); - } - else { - header ("Location: " . conf('web_path')); - } -} // mpd_redirect - - -/** - * Init MPD - This is originally from /amp-mpd.php - * This initializes MPD if it is the playback method. - * It checks to see if a global variable called myMpd is an object - * if it's not then it attempt to create one and return it - * @package Local Play - * @catagory MPD - */ -function init_mpd() { - - static $myMpd; - - if (!conf('allow_mpd_playback')) { return false; } - - if (!is_object($myMpd)) { - $myMpd = new mpd(conf('mpd_host'),conf('mpd_port')); - } - - if (!$myMpd->connected AND is_object($myMpd)) { - // Attempt to reconnect - $myMpd->Connect(); - } - - if (!$myMpd->connected) { - if (conf('debug')) { - log_event ($_SESSION['userdata']['username'],' connection_failed ',"Error: unable to connect to ". conf('mpd_host') . " on port " . conf('mpd_port') . " ".$myMpd->errStr); - } - return false; - } - - return $myMpd; - -} // function init_mpd() - -?> diff --git a/lib/preferences.php b/lib/preferences.php index 970a099f..66996e40 100644 --- a/lib/preferences.php +++ b/lib/preferences.php @@ -258,32 +258,17 @@ function create_preference_input($name,$value) { echo "\n"; break; case 'play_type': - if ($value == 'local_play') { $is_local = "selected=\"selected\""; } - elseif ($value == 'icecast2') { $is_ice = "selected=\"selected\""; } - elseif ($value == 'downsample') { $is_down = "selected=\"selected\""; } - elseif ($value == 'mpd') { $is_mpd = "selected=\"selected\""; } - elseif ($value == 'slim') { $is_slim = "selected=\"selected\""; } + if ($value == 'downsample') { $is_down = 'selected="selected"'; } + elseif ($value == 'localplay') { $is_local = 'selected="selected"'; } else { $is_stream = "selected=\"selected\""; } echo "\n"; break; case 'playlist_type': @@ -311,6 +296,25 @@ function create_preference_input($name,$value) { } // end foreach echo "\n"; break; + case 'localplay_controller': + $controllers = get_localplay_controllers(); + echo "\n"; + break; + case 'localplay_level': + if ($GLOBALS['user']->prefs['localplay_level'] == '2') { $is_full = 'selected="selected"'; } + elseif ($GLOBALS['user']->prefs['localplay_level'] == '1') { $is_global = 'selected="selected"'; } + echo "\n"; + break; case 'theme_name': $themes = get_themes(); echo "\n"; - break; + break; case 'quarantine_dir': case 'upload_dir': if (!$GLOBALS['user']->has_access(100)) { @@ -352,4 +356,31 @@ function get_preference_id($name) { } // get_preference_id +/** + * insert_preference + * This creates a new preference record in the + * preferences table this is used by the modules + */ +function insert_preference($name,$description,$default,$level,$type,$catagory) { + + /* Clean the incomming variables */ + $name = sql_escape($name); + $description = sql_escape($description); + $default = sql_escape($default); + $level = sql_escape($level); + $type = sql_escape($type); + $catagory = sql_escape($catagory); + + + /* Form the sql statement */ + $sql = "INSERT INTO preferences (`name`,`description`,`value`,`type`,`level`,`catagory`) VALUES " . + " ('$name','$description','$default','$type','$level','$catagory')"; + $db_results = mysql_query($sql, dbh()); + + if ($db_results) { return true; } + + return false; + +} // insert_preference + ?> diff --git a/lib/ui.lib.php b/lib/ui.lib.php index dec697ae..2bed47c6 100644 --- a/lib/ui.lib.php +++ b/lib/ui.lib.php @@ -49,32 +49,6 @@ function show_confirmation($title,$text,$next_url,$cancel=0) { } // show_confirmation -/** - * set_preferences - * legacy function... - * @todo Remove References - * @deprecated - */ -function set_preferences() { - - init_preferences(); - return true; - -} // set_preferences - -/** - * get_preferences - * WTF was I thinking, this should be set or ini not get.. it doesn't get anything.. sigh anyway I'll - * leave this be for now. - * @deprecated - */ -function get_preferences($username=0) { - - init_preferences(); - return true; - -} // get_preferences - /** * init_preferences * Third times the charm, why rename a function once when you can do it three times :( @@ -86,7 +60,7 @@ function init_preferences() { /* Get Global Preferences */ $sql = "SELECT preferences.name,user_preference.value FROM preferences,user_preference WHERE user_preference.user='-1' " . - " AND user_preference.preference = preferences.id AND preferences.type='system'"; + " AND user_preference.preference = preferences.id AND preferences.catagory='system'"; $db_results = mysql_query($sql, dbh()); while ($r = mysql_fetch_assoc($db_results)) { @@ -95,10 +69,13 @@ function init_preferences() { } // end while sys prefs /* Now we need to allow the user to override some stuff that's been set by the above */ - $username = $_SESSION['userdata']['username']; + $user_id = '-1'; + if ($GLOBALS['user']->username) { + $user_id = sql_escape($GLOBALS['user']->id); + } - $sql = "SELECT preferences.name,user_preference.value FROM preferences,user_preference WHERE user_preference.user='$username' " . - " AND user_preference.preference = preferences.id AND preferences.type != 'system'"; + $sql = "SELECT preferences.name,user_preference.value FROM preferences,user_preference WHERE user_preference.user='$user_id' " . + " AND user_preference.preference = preferences.id AND preferences.catagory != 'system'"; $db_results = mysql_query($sql, dbh()); while ($r = mysql_fetch_assoc($db_results)) { @@ -106,6 +83,11 @@ function init_preferences() { $results[$name] = $r['value']; } // end while + /* Set the Theme mojo */ + if (strlen($results['theme_name']) > 0) { + $results['theme_path'] = '/themes/' . $results['theme_name']; + } + conf($results,1); return true; @@ -444,7 +426,7 @@ function get_now_playing() { $np_user = new User($r['user']); $results[] = array('song'=>$song,'user'=>$np_user); } // end while - +/* $myMpd = init_mpd(); if (is_object($myMpd) AND conf('mpd_method') == 'file') { @@ -465,7 +447,7 @@ function get_now_playing() { } // end while } // end if we have a MPD object - +*/ return $results; -- cgit