From 689517e332c874ac09bb41398602622a1fc36af8 Mon Sep 17 00:00:00 2001 From: Karl 'vollmerk' Vollmer Date: Mon, 11 Jun 2007 05:16:20 +0000 Subject: fixed preferences mostly, also fixed some genre issues and other stuff I am forgetting now --- admin/catalog.php | 4 +- albums.php | 41 ++++++-------- browse.php | 2 +- genre.php | 20 ++++--- index.php | 3 +- lib/class/album.class.php | 2 +- lib/class/genre.class.php | 34 +++++------ lib/class/localplay.class.php | 18 +++--- lib/class/user.class.php | 2 +- lib/localplay.lib.php | 12 ++-- lib/preferences.php | 61 +++++++++----------- lib/ui.lib.php | 8 +-- modules/localplay/httpq.controller.php | 9 ++- modules/localplay/mpd.controller.php | 8 +-- preferences.php | 100 +++++++++++++-------------------- templates/show_genre.inc.php | 4 +- templates/show_genres.inc.php | 2 +- templates/show_preference_box.inc.php | 21 +++---- templates/show_preferences.inc.php | 52 ++--------------- templates/sidebar_preferences.inc.php | 9 ++- 20 files changed, 163 insertions(+), 249 deletions(-) diff --git a/admin/catalog.php b/admin/catalog.php index fa9b35fb..8f07f094 100644 --- a/admin/catalog.php +++ b/admin/catalog.php @@ -210,9 +210,9 @@ switch ($_REQUEST['action']) { require Config::get('prefix') . '/templates/show_add_catalog.inc.php'; break; case 'clear_now_playing': - if (conf('demo_mode')) { break; } + if (Config::get('demo_mode')) { break; } clear_now_playing(); - show_confirmation(_('Now Playing Cleared'),_('All now playing data has been cleared'),conf('web_path') . '/admin/index.php'); + show_confirmation(_('Now Playing Cleared'),_('All now playing data has been cleared'),Config::get('web_path') . '/admin/index.php'); break; case 'show_clear_stats': /* Demo Bad! */ diff --git a/albums.php b/albums.php index ac30e78b..cb9d86a2 100644 --- a/albums.php +++ b/albums.php @@ -31,15 +31,6 @@ switch ($_REQUEST['action']) { $album->clear_art(); show_confirmation(_('Album Art Cleared'),_('Album Art information has been removed from the database'),"/albums.php?action=show&album=" . $album->id); break; - case 'show': - $album = new Album($_REQUEST['album']); - $album->format(); - - require Config::get('prefix') . '/templates/show_album.inc'; - - /* Get the song ids for this album */ - $song_ids = $album->get_songs(0,$_REQUEST['artist']); - break; // Upload album art case 'upload_art': @@ -177,21 +168,7 @@ switch ($_REQUEST['action']) { show_box_bottom(); break; // Browse by Album - default: - if (strlen($_REQUEST['match']) < '1') { $match = 'a'; } - - // Setup the View Ojbect - $view = new View(); - $view->import_session_view(); - - if ($match == 'Show_all' || $match == 'Show_missing_art' || $match == 'Browse') { $chr = ''; } - else { $chr = $match; } - - require (conf('prefix') . '/templates/show_box_top.inc.php'); - show_alphabet_list('albums','albums.php',$match); - show_alphabet_form($chr,_('Show Albums starting with'),"albums.php?action=match"); - require (conf('prefix') . '/templates/show_box_bottom.inc.php'); - + case 'broken': switch($match) { case 'Show_all': $offset_limit = 99999; @@ -263,5 +240,21 @@ switch ($_REQUEST['action']) { break; } // end switch on action + +/** + * switch on view + */ +switch ($_REQUEST['action']) { + case 'show': + $album = new Album($_REQUEST['album']); + $album->format(); + + require Config::get('prefix') . '/templates/show_album.inc.php'; + + /* Get the song ids for this album */ + $song_ids = $album->get_songs(0,$_REQUEST['artist']); + break; +} // switch on view + show_footer(); ?> diff --git a/browse.php b/browse.php index 2e002936..54a99f98 100644 --- a/browse.php +++ b/browse.php @@ -36,7 +36,7 @@ require_once 'lib/init.php'; /* Display the headers and menus */ -require_once Config::get('prefix') . '/templates/header.inc.php'; +show_header(); echo '
'; switch($_REQUEST['action']) { diff --git a/genre.php b/genre.php index 2922820b..20ce70ae 100644 --- a/genre.php +++ b/genre.php @@ -1,7 +1,7 @@ get_songs(); - show_songs($songs); break; case 'show_genre': default: case 'show_albums': $genre = new Genre($_REQUEST['genre_id']); show_genre($_REQUEST['genre_id']); - $albums = $genre->get_albums(); - require (conf('prefix') . '/templates/show_albums.inc.php'); + $object_ids = $genre->get_albums(); + show_box_top(_('Albums')); + require Config::get('prefix') . '/templates/show_albums.inc.php'; + show_box_bottom(); break; case 'show_artists': $genre = new Genre($_REQUEST['genre_id']); diff --git a/index.php b/index.php index 95037390..117c0c5c 100644 --- a/index.php +++ b/index.php @@ -20,7 +20,8 @@ */ require_once 'lib/init.php'; -require_once Config::get('prefix') . '/templates/header.inc.php'; + +show_header(); $action = scrub_in($_REQUEST['action']); diff --git a/lib/class/album.class.php b/lib/class/album.class.php index 513256d6..af9cadb8 100644 --- a/lib/class/album.class.php +++ b/lib/class/album.class.php @@ -108,7 +108,7 @@ class Album { private function _get_extra_info() { $sql = "SELECT COUNT(DISTINCT(song.artist)) as artist_count,COUNT(song.id) AS song_count,artist.name AS artist_name" . - ",artist.prefix AS artist_prefix,album_data.art AS has_art,album_data.thumb AS has_thumb ". + ",artist.prefix AS artist_prefix,album_data.art AS has_art,album_data.thumb AS has_thumb, artist.id AS artist_id ". "FROM `song` " . "INNER JOIN `artist` ON `artist`.`id`=`song`.`artist` " . "LEFT JOIN `album_data` ON `album_data`.`album_id` = `song`.`album` " . diff --git a/lib/class/genre.class.php b/lib/class/genre.class.php index 7e311fda..90db7d53 100644 --- a/lib/class/genre.class.php +++ b/lib/class/genre.class.php @@ -91,34 +91,30 @@ class Genre { /** * get_album_count * Returns the number of albums that contain a song of this genre - * @package Genre - * @catagory Class */ - function get_album_count() { + public function get_album_count() { - $sql = "SELECT COUNT(DISTINCT(song.album)) FROM song WHERE genre='" . $this->id . "'"; - $db_results = mysql_query($sql, dbh()); + $sql = "SELECT COUNT(DISTINCT(song.album)) FROM `song` WHERE `genre`='" . $this->id . "'"; + $db_results = Dba::query($sql); - $total_items = mysql_fetch_array($db_results); + $total_items = Dba::fetch_row($db_results); - return $total_items[0]; + return $total_items['0']; } // get_album_count /** * get_artist_count * Returns the number of artists who have at least one song in this genre - * @package Genre - * @catagory Class */ - function get_artist_count() { + public function get_artist_count() { - $sql = "SELECT COUNT(DISTINCT(song.artist)) FROM song WHERE genre='" . $this->id . "'"; - $db_results = mysql_query($sql, dbh()); + $sql = "SELECT COUNT(DISTINCT(`song`.`artist`)) FROM `song` WHERE `genre`='" . $this->id . "'"; + $db_results = Dba::query($sql); - $total_items = mysql_fetch_array($db_results); + $total_items = Dba::fetch_row($db_results); - return $total_items[0]; + return $total_items['0']; } // get_artist_count @@ -169,15 +165,13 @@ class Genre { */ function get_albums() { - $sql = "SELECT DISTINCT(song.album) FROM song WHERE genre='" . $this->id . "'"; - $db_results = mysql_query($sql,dbh()); + $sql = "SELECT DISTINCT(`song`.`album`) FROM `song` WHERE `genre`='" . $this->id . "'"; + $db_results = Dba::query($sql); $results = array(); - while ($r = mysql_fetch_assoc($db_results)) { - $album = new Album($r['album']); - $album->format_album(); - $results[] = $album; + while ($r = Dba::fetch_row($db_results)) { + $results[] = $r['0']; } return $results; diff --git a/lib/class/localplay.class.php b/lib/class/localplay.class.php index 4c12aaef..78a3c70e 100644 --- a/lib/class/localplay.class.php +++ b/lib/class/localplay.class.php @@ -23,15 +23,15 @@ class Localplay { /* Base Variables */ - var $type; + public $type; /* Built Variables */ - var $_function_map = array(); - var $_template; - var $_preferences = array(); - var $_player; + public $_function_map = array(); + public $_template; + public $_preferences = array(); + public $_player; /** @@ -42,7 +42,6 @@ class Localplay { */ function Localplay($type) { - $this->type = $type; $this->_get_info(); @@ -57,11 +56,10 @@ class Localplay { * any failures, fatal errors will actually return something to the * gui */ - function _get_info() { + private function _get_info() { $this->_load_player(); - } // _get_info @@ -71,11 +69,11 @@ class Localplay { * Will interface with in order to make all this magical stuf work * all LocalPlay modules should be located in /modules//.class.php */ - function _load_player() { + private function _load_player() { if (!$this->type) { return false; } - $filename = conf('prefix') . '/modules/localplay/' . $this->type . '.controller.php'; + $filename = Config::get('prefix') . '/modules/localplay/' . $this->type . '.controller.php'; $include = require_once ($filename); if (!$include) { diff --git a/lib/class/user.class.php b/lib/class/user.class.php index 876b4a36..5b4b77b6 100644 --- a/lib/class/user.class.php +++ b/lib/class/user.class.php @@ -154,7 +154,7 @@ class User { ksort($type_array[$type]); $results[$type] = array ('title'=>ucwords($type),'admin'=>$admin,'prefs'=>$type_array[$type]); } // end while - + return $results; } // get_preferences diff --git a/lib/localplay.lib.php b/lib/localplay.lib.php index fb98d3fb..99b13932 100644 --- a/lib/localplay.lib.php +++ b/lib/localplay.lib.php @@ -36,10 +36,10 @@ function verify_localplay_preferences($type) { 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()); + $sql = "SELECT id FROM preferences WHERE name = '" . Dba::escape($name) . "'"; + $db_results = Dba::query($sql); - if (!mysql_num_rows($db_results)) { return false; } + if (!Dba::num_rows($db_results)) { return false; } } // end foreach preferences @@ -76,8 +76,8 @@ function insert_localplay_preferences($type) { } // end foreach preferences /* Fix everyones preferences */ - $sql = "SELECT * FROM user"; - $db_results = mysql_query($sql, dbh()); + $sql = "SELECT * FROM `user`"; + $db_results = Dba::query($sql); $temp_user = new User(); $temp_user->fix_preferences('-1'); @@ -143,7 +143,7 @@ function remove_localplay_preferences($type=0) { function get_localplay_controllers($disabled='') { /* First get a list of the files */ - $handle = opendir(conf('prefix') . '/modules/localplay'); + $handle = opendir(Config::get('prefix') . '/modules/localplay'); if (!is_resource($handle)) { debug_event('localplay','Error: Unable to read localplay controller directory','1'); diff --git a/lib/preferences.php b/lib/preferences.php index 531532cd..ac8c9e50 100644 --- a/lib/preferences.php +++ b/lib/preferences.php @@ -80,26 +80,26 @@ function clean_preference_name($name) { } // clean_preference_name -/*! - @function update_preferences - @discussion grabs the current keys that should be added - and then runs throught $_REQUEST looking for those - values and updates them for this user -*/ +/* + * update_preferences + * grabs the current keys that should be added + * and then runs throught $_REQUEST looking for those + * values and updates them for this user + */ function update_preferences($pref_id=0) { $pref_user = new User($pref_id); /* Get current keys */ - $sql = "SELECT id,name,type FROM preferences"; + $sql = "SELECT `id`,`name`,`type` FROM `preference`"; /* If it isn't the System Account's preferences */ - if ($pref_id != '-1') { $sql .= " WHERE type!='system'"; } + if ($pref_id != '-1') { $sql .= " WHERE `type` != 'system'"; } - $db_results = mysql_query($sql, dbh()); + $db_results = Dba::query($sql); // Collect the current possible keys - while ($r = mysql_fetch_assoc($db_results)) { + while ($r = Dba::fetch_assoc($db_results)) { $results[] = array('id' => $r['id'], 'name' => $r['name'],'type' => $r['type']); } // end collecting keys @@ -110,16 +110,10 @@ function update_preferences($pref_id=0) { $name = $data['name']; $apply_to_all = "check_" . $data['name']; $id = $data['id']; - $value = sql_escape(scrub_in($_REQUEST[$name])); + $value = Dba::escape(scrub_in($_REQUEST[$name])); /* Some preferences require some extra checks to be performed */ switch ($name) { - case 'theme_name': - // If the theme exists and it's different then our current one reset the colors - if (theme_exists($value) AND $pref_user->prefs['theme_name'] != $value) { - set_theme_colors($value,$pref_id); - } - break; case 'sample_rate': $value = validate_bitrate($value); break; @@ -146,28 +140,22 @@ function update_preferences($pref_id=0) { /** * update_preference * This function updates a single preference and is called by the update_preferences function - * @package Preferences - * @catagory Update */ -function update_preference($username,$name,$pref_id,$value) { +function update_preference($user_id,$name,$pref_id,$value) { $apply_check = "check_" . $name; /* First see if they are an administrator and we are applying this to everything */ if ($GLOBALS['user']->has_access(100) AND make_bool($_REQUEST[$apply_check])) { - $sql = "UPDATE user_preference SET `value`='$value' WHERE preference='$pref_id'"; - $db_results = mysql_query($sql, dbh()); - /* Reset everyones colors! */ - if ($name =='theme_name') { - set_theme_colors($value,0); - } + $sql = "UPDATE `user_preference` SET `value`='$value' WHERE `preference`='$pref_id'"; + $db_results = Dba::query($sql); return true; } /* Else make sure that the current users has the right to do this */ if (has_preference_access($name)) { - $sql = "UPDATE user_preference SET `value`='$value' WHERE preference='$pref_id' AND user='$username'"; - $db_results = mysql_query($sql, dbh()); + $sql = "UPDATE `user_preference` SET `value`='$value' WHERE `preference`='$pref_id' AND `user`='$user_id'"; + $db_results = Dba::query($sql); return true; } @@ -191,7 +179,7 @@ function has_preference_access($name) { $name = Dba::escape($name); /* Check Against the Database Row */ - $sql = "SELECT `level` FROM `preferences` " . + $sql = "SELECT `level` FROM `preference` " . "WHERE `name`='$name'"; $db_results = Dba::query($sql); @@ -208,11 +196,10 @@ function has_preference_access($name) { } //has_preference_access -/*! - @function create_preference_input - @discussion takes the key and then creates - the correct type of input for updating it -*/ +/** + * create_preference_input + * takes the key and then creates the correct type of input for updating it + */ function create_preference_input($name,$value) { $len = strlen($value); @@ -339,6 +326,11 @@ function create_preference_input($name,$value) { } // foreach themes echo "\n"; break; + case 'random_method': + echo "\n"; + break; case 'lastfm_pass': echo ""; break; @@ -523,7 +515,6 @@ function fix_all_users_prefs() { } // fix_all_users_prefs - /** * fix_preferences * This takes the preferences, explodes what needs to diff --git a/lib/ui.lib.php b/lib/ui.lib.php index 1476307a..cbf3bde0 100644 --- a/lib/ui.lib.php +++ b/lib/ui.lib.php @@ -627,26 +627,22 @@ function img_resize($image,$size,$type,$album_id) { /** * show_genres * this shows the 'many' genre form, it takes an array of genre objects and the view object - * @package Genre - * @catagory Display */ function show_genres($genres,$view) { - require (conf('prefix') . '/templates/show_genres.inc.php'); + require Config::get('prefix') . '/templates/show_genres.inc.php'; } // show_genres /** * show_genre * this shows a single genre item which is basicly just a link to the albums/artists/songs of said genre - * @package Genre - * @catagory Display */ function show_genre($genre_id) { $genre = new Genre($genre_id); - require (conf('prefix') . '/templates/show_genre.inc.php'); + require Config::get('prefix') . '/templates/show_genre.inc.php'; } // show_genre diff --git a/modules/localplay/httpq.controller.php b/modules/localplay/httpq.controller.php index b6d26445..184d6e81 100644 --- a/modules/localplay/httpq.controller.php +++ b/modules/localplay/httpq.controller.php @@ -30,20 +30,19 @@ class AmpacheHttpq { /* Constructed variables */ - var $_httpq; + private $_httpq; /** * Constructor * This returns the array map for the localplay object * REQUIRED for Localplay */ - function AmpacheHttpq() { + public function __construct() { /* Do a Require Once On the needed Libraries */ - require_once(conf('prefix') . '/modules/httpq/httpqplayer.class.php'); - - } // AmpacheHttpq + require_once Config::get('prefix') . '/modules/httpq/httpqplayer.class.php'; + } // Constructor /** * function_map diff --git a/modules/localplay/mpd.controller.php b/modules/localplay/mpd.controller.php index c002d299..c38c8a63 100644 --- a/modules/localplay/mpd.controller.php +++ b/modules/localplay/mpd.controller.php @@ -30,17 +30,17 @@ class AmpacheMpd { /* Constructed variables */ - var $_mpd; + private $_mpd; /** * Constructor * This returns the array map for the localplay object * REQUIRED for Localplay */ - function AmpacheMpd() { + public function __construct() { /* Do a Require Once On the needed Libraries */ - require_once(conf('prefix') . '/modules/mpd/mpd.class.php'); + require_once Config::get('prefix') . '/modules/mpd/mpd.class.php'; } // AmpacheMpd @@ -51,7 +51,7 @@ class AmpacheMpd { * that this player supports and their names in this local * class. This is a REQUIRED function */ - function function_map() { + public function function_map() { $map = array(); diff --git a/preferences.php b/preferences.php index 8f8423c2..a83890d2 100644 --- a/preferences.php +++ b/preferences.php @@ -24,81 +24,57 @@ require 'lib/init.php'; /* Scrub in the needed mojo */ if (!$_REQUEST['tab']) { $_REQUEST['tab'] = 'interface'; } -$user_id = scrub_in($_REQUEST['user_id']); // Switch on the action switch($_REQUEST['action']) { - case 'update_user': - /* Verify permissions */ - if (!$GLOBALS['user']->has_access(25) || Config::get('demo_mode') || - ($GLOBALS['user']->id != $user_id && !$GLOBALS['user']->has_access(100))) { - show_access_denied(); - exit(); - } - - /* Go ahead and update normal stuff */ - $this_user = new User($user_id); - $this_user->update_fullname($_REQUEST['fullname']); - $this_user->update_email($_REQUEST['email']); - - - /* Check for password change */ - if ($_REQUEST['password1'] !== $_REQUEST['password2'] && !empty($_REQUEST['password1'])) { - $GLOBALS['error']->add_error('password',_('Error: Password Does Not Match or Empty')); - break; - } - elseif (!empty($_REQUEST['password1'])) { - /* We're good change the mofo! */ - $this_user->update_password($_REQUEST['password1']); + case 'update_preferences': + if ($_REQUEST['method'] == 'admin' && !$GLOBALS['user']->has_access('100')) { + access_denied(); + exit; + } - /* Haha I'm fired... it's not an error but screw it */ - $GLOBALS['error']->add_error('password',_('Password Updated')); + /* Reset the Theme */ + if ($_REQUEST['method'] == 'admin') { + $user_id = '-1'; + $fullname = _('Server'); } + else { + $user_id = $GLOBALS['user']->id; + $fullname = $GLOBALS['user']->fullname; + } - /* Check for stats */ - if ($_REQUEST['clear_stats'] == '1') { - $this_user->delete_stats(); - } - break; - case 'update_preferences': - - /* Do the work */ + /* Update and reset preferences */ update_preferences($user_id); - - /* Reload the Preferences */ - $GLOBALS['user']->set_preferences(); - - /* Reset the conf values */ init_preferences(); - /* Reset the Theme */ - set_theme(); - default: - if (!$user_id) { $user_id = $GLOBALS['user']->id; } - $preferences = $GLOBALS['user']->get_preferences(0,$_REQUEST['tab']); + $preferences = $GLOBALS['user']->get_preferences($user_id,$_REQUEST['tab']); + break; + case 'admin': + // Make sure only admins here + if (!$GLOBALS['user']->has_access('100')) { + access_denied(); + exit; + } + $fullname= _('Server'); + $preferences = $GLOBALS['user']->get_preferences(-1,$_REQUEST['tab']); + break; + default: + $fullname = $GLOBALS['user']->fullname; + $preferences = $GLOBALS['user']->get_preferences(0,$_REQUEST['tab']); break; - } // End Switch Action -if (!$GLOBALS['user']->fullname) { - $fullname = "Site"; -} -else { - $fullname = $GLOBALS['user']->fullname; -} - - -// HEADER -require_once Config::get('prefix') . '/templates/header.inc.php'; -// HEADER - -// Set Target -$target = "/preferences.php"; - -// Show the default preferences page -require Config::get('prefix') . '/templates/show_preferences.inc.php'; +show_header(); +/** + * switch on the view + */ +switch ($_REQUEST['action']) { + default: + // Show the default preferences page + require Config::get('prefix') . '/templates/show_preferences.inc.php'; + break; +} // end switch on action -// FOOTER show_footer(); ?> diff --git a/templates/show_genre.inc.php b/templates/show_genre.inc.php index 5e9466d9..1eb1cc14 100644 --- a/templates/show_genre.inc.php +++ b/templates/show_genre.inc.php @@ -1,7 +1,7 @@ name . " " . _('Genre')); ?> [get_album_count(); ?>] diff --git a/templates/show_genres.inc.php b/templates/show_genres.inc.php index e3ae1223..bd7b0a3d 100644 --- a/templates/show_genres.inc.php +++ b/templates/show_genres.inc.php @@ -39,7 +39,7 @@ format_genre(); + $genre->format(); ?> diff --git a/templates/show_preference_box.inc.php b/templates/show_preference_box.inc.php index eedaa2b7..7fa4ae72 100644 --- a/templates/show_preference_box.inc.php +++ b/templates/show_preference_box.inc.php @@ -22,32 +22,33 @@ /* I'm cheating a little here, check to see if we want to show the * Apply to All button on this page */ -if ($GLOBALS['user']->has_access(100) AND Config::get('use_auth')) { - $show_apply_to_all = true; +if (($GLOBALS['user']->has_access(100) OR !Config::get('use_auth')) AND $_REQUEST['action'] == 'admin') { + $is_admin = true; } ?> - - - + - - + + + - + - + + diff --git a/templates/show_preferences.inc.php b/templates/show_preferences.inc.php index 22843bfb..31500393 100644 --- a/templates/show_preferences.inc.php +++ b/templates/show_preferences.inc.php @@ -23,63 +23,19 @@ * This page has a few tabs, as such we need to figure out which tab we are on * and display the information accordingly */ -$current_tab = scrub_in($_REQUEST['tab']); -if (!$current_tab) { $current_tab = 'interface'; } -// HORRIBLE HACK! -if ($_REQUEST['action'] == 'user') { $action_txt = '&action=user'; } -$link = Config::get('web_path') . $target; -/* CSS construction bs */ -$link_active = "a_" . $current_tab; -${$link_active} = "id=\"current\""; -$tab_active = "tab_" .$current_tab; -${$tab_active} = "id=\"tabactive\""; ?> - - - -has_access(100)) { ?> -[] - - - -
-
    -
  • > - > -
  • -
  • > - > -
  • -
  • > - > -
  • - -
  • > - > -
  • - -
  • > - > -
  • -
  • > - > -
  • - - -
-
-
-
+ + -    + " /> -

+has_access('100')) { ?> +

+ + + + +
+ -- cgit
+ +