From 13dd43450a56bd72067b6f2350f5d188c5c7e254 Mon Sep 17 00:00:00 2001 From: Karl 'vollmerk' Vollmer Date: Mon, 23 Apr 2007 20:33:57 +0000 Subject: fixed up part of single album view, show songs is all gone, working on replacement browse method --- albums.php | 23 ++----- lib/class/access.class.php | 42 ++++++++++--- lib/class/album.class.php | 33 ++-------- lib/class/rating.class.php | 12 ++-- lib/class/user.class.php | 26 ++++---- lib/general.lib.php | 25 +------- lib/preferences.php | 8 +-- lib/rating.lib.php | 2 +- lib/themes.php | 23 +++---- lib/ui.lib.php | 2 +- login.php | 2 +- play/index.php | 6 +- preferences.php | 22 +++---- stream.php | 4 +- templates/show_album.inc | 32 ++++------ templates/show_object_rating.inc.php | 6 +- templates/show_preference_box.inc.php | 10 +--- templates/show_preferences.inc | 109 ---------------------------------- templates/show_preferences.inc.php | 96 ++++++++++++++++++++++++++++++ 19 files changed, 209 insertions(+), 274 deletions(-) delete mode 100644 templates/show_preferences.inc create mode 100644 templates/show_preferences.inc.php diff --git a/albums.php b/albums.php index 4fc1f31c..b920737e 100644 --- a/albums.php +++ b/albums.php @@ -21,23 +21,10 @@ require_once 'lib/init.php'; -show_template('header'); - -// We'll set any input parameters here -if(!isset($_REQUEST['match'])) { $_REQUEST['match'] = "Browse"; } -if(isset($_REQUEST['match'])) $match = scrub_in($_REQUEST['match']); -if(isset($_REQUEST['album'])) $album = scrub_in($_REQUEST['album']); -if(isset($_REQUEST['artist'])) $artist = scrub_in($_REQUEST['artist']); -$_REQUEST['artist_id'] = scrub_in($_REQUEST['artist_id']); -$min_album_size = conf('min_object_count'); -if ($min_album_size == '') { - $min_album_size = '0'; -} - -$action = scrub_in($_REQUEST['action']); +require_once Config::get('prefix') . '/templates/header.inc.php'; /* Switch on Action */ -switch ($action) { +switch ($_REQUEST['action']) { case 'clear_art': if (!$GLOBALS['user']->has_access('75')) { access_denied(); } $album = new Album($_REQUEST['album_id']); @@ -48,12 +35,10 @@ switch ($action) { $album = new Album($_REQUEST['album']); $album->format(); - require (conf('prefix') . '/templates/show_album.inc'); + require Config::get('prefix') . '/templates/show_album.inc'; /* Get the song ids for this album */ - $song_ids = $album->get_song_ids($_REQUEST['artist']); - - show_songs($song_ids,0,$album); + $song_ids = $album->get_songs(0,$_REQUEST['artist']); break; // Upload album art case 'upload_art': diff --git a/lib/class/access.class.php b/lib/class/access.class.php index fc01adfb..dae463de 100644 --- a/lib/class/access.class.php +++ b/lib/class/access.class.php @@ -144,26 +144,50 @@ class Access { $db_results = mysql_query($sql, dbh()); } // delete + + /** + * check_function + * This checks if a specific functionality is enabled + * it takes a type only + */ + public static function check_function($type) { + + switch ($type) { + case 'batch_download': + if (!function_exists('gzcompress')) { + debug_event('gzcompress','ZLIB Extensions not loaded, batch download disabled','3'); + return false; + } + if (Config::get('allow_zip_download') AND $GLOBALS['user']->has_access(25)) { + return $GLOBALS['user']->prefs['download']; + } + break; + default: + return false; + break; + } // end switch + + } // check_function /** - * check + * check_network * This takes a type, ip, user, level and key * and then returns true or false if they have access to this * the IP is passed as a dotted quad */ - public static function check($type,$ip,$user,$level,$key='') { + public static function check_network($type,$ip,$user,$level,$key='') { // They aren't using access control // lets just keep on trucking - if (!conf('access_control')) { + if (!Config::get('access_control')) { return true; } // Clean incomming variables $ip = ip2int($ip); - $user = sql_escape($user); - $key = sql_escape($key); - $level = sql_escape($level); + $user = Dba::escape($user); + $key = Dba::escape($key); + $level = Dba::escape($level); switch ($type) { /* This is here because we want to at least check IP before even creating the xml-rpc server @@ -190,10 +214,10 @@ class Access { break; } // end switch on type - $db_results = mysql_query($sql, dbh()); + $db_results = Dba::query($sql); // Yah they have access they can use the mojo - if (mysql_fetch_row($db_results)) { + if (Dba::fetch_row($db_results)) { return true; } @@ -202,7 +226,7 @@ class Access { return false; } - } // check + } // check_network /** * validate_type diff --git a/lib/class/album.class.php b/lib/class/album.class.php index 5e44af8b..72abfab4 100644 --- a/lib/class/album.class.php +++ b/lib/class/album.class.php @@ -97,11 +97,15 @@ class Album { * get_songs * gets the songs for this album */ - public function get_songs($limit = 0) { + public function get_songs($limit = 0,$artist='') { $results = array(); + + if ($artist) { + $artist_sql = "AND `artist`='" . Dba::escape($artist) . "'"; + } - $sql = "SELECT `id` FROM `song` WHERE `album`='$this->id' ORDER BY `track`, `title`"; + $sql = "SELECT `id` FROM `song` WHERE `album`='$this->id' $artist_sql ORDER BY `track`, `title`"; if ($limit) { $sql .= " LIMIT $limit"; } $db_results = Dba::query($sql); @@ -113,31 +117,6 @@ class Album { } // get_songs - /** - * get_song_ids - * This returns an array of the song id's that are on this album. This is used by the - * show_songs function and can be pased and artist if you so desire to limit it to that - */ - function get_song_ids($artist='') { - - /* If they pass an artist then constrain it based on the artist as well */ - if ($artist) { - $artist_sql = " AND artist='" . sql_escape($artist) . "'"; - } - - $sql = "SELECT id FROM song WHERE album='" . sql_escape($this->id) . "' $artist_sql ORDER BY track"; - $db_results = mysql_query($sql, dbh()); - - $results = array(); - - while ($r = mysql_fetch_assoc($db_results)) { - $results[] = $r['id']; - } - - return $results; - - } // get_song_ids - /** * format * This is the format function for this object. It sets cleaned up diff --git a/lib/class/rating.class.php b/lib/class/rating.class.php index 32a85253..43200f90 100644 --- a/lib/class/rating.class.php +++ b/lib/class/rating.class.php @@ -41,7 +41,7 @@ class Rating { function Rating($id,$type) { $this->id = intval($id); - $this->type = sql_escape($type); + $this->type = Dba::escape($type); // Check for the users rating if ($rating = $this->get_user($GLOBALS['user']->id)) { @@ -62,12 +62,12 @@ class Rating { */ function get_user($user_id) { - $user_id = sql_escape($user_id); + $user_id = Dba::escape($user_id); $sql = "SELECT rating FROM ratings WHERE user='$user_id' AND object_id='$this->id' AND object_type='$this->type'"; - $db_results = mysql_query($sql, dbh()); + $db_results = Dba::query($sql); - $results = mysql_fetch_assoc($db_results); + $results = Dba::fetch_assoc($db_results); return $results['rating']; @@ -83,11 +83,11 @@ class Rating { function get_average() { $sql = "SELECT user_rating as rating FROM ratings WHERE object_id='$this->id' AND object_type='$this->type'"; - $db_results = mysql_query($sql, dbh()); + $db_results = Dba::query($sql); $i = 0; - while ($r = mysql_fetch_assoc($db_results)) { + while ($r = Dba::fetch_assoc($db_results)) { $i++; $total += $r['rating']; } // while we're pulling results diff --git a/lib/class/user.class.php b/lib/class/user.class.php index e50b6bb8..d678ad1c 100644 --- a/lib/class/user.class.php +++ b/lib/class/user.class.php @@ -111,36 +111,36 @@ class User { * []['admin'] = t/f value if this is an admin only section */ function get_preferences($user_id=0,$type=0) { - - if (!$user_id) { - $user_id = $this->id; - } + + // Fill out the user id + $user_id = $user_id ? Dba::escape($user_id) : Dba::escape($this->id); - if (!conf('use_auth')) { $user_id = '-1'; } + if (!Config::get('use_auth')) { $user_id = '-1'; } if ($user_id != '-1') { $user_limit = "AND preferences.catagory != 'system'"; } - + if ($type != '0') { - $user_limit = "AND preferences.catagory = '" . sql_escape($type) . "'"; + $user_limit = "AND preferences.catagory = '" . Dba::escape($type) . "'"; } - $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 ORDER BY id"; - $db_results = mysql_query($sql, dbh()); + $sql = "SELECT preferences.name, preferences.description, preferences.catagory, user_preference.value " . + "FROM preferences RIGHT JOIN user_preference ON user_preference.preference=preferences.id " . + "WHERE user_preference.user='$user_id' $user_limit"; + $db_results = Dba::query($sql); /* Ok this is crapy, need to clean this up or improve the code FIXME */ - while ($r = mysql_fetch_assoc($db_results)) { + while ($r = Dba::fetch_assoc($db_results)) { $type = $r['catagory']; $admin = false; if ($type == 'system') { $admin = true; } - $type_array[$type][] = array('name'=>$r['name'],'description'=>$r['description'],'value'=>$r['value']); + $type_array[$type][$r['name']] = array('name'=>$r['name'],'description'=>$r['description'],'value'=>$r['value']); + 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/general.lib.php b/lib/general.lib.php index bff578a1..ff641e6f 100644 --- a/lib/general.lib.php +++ b/lib/general.lib.php @@ -278,27 +278,6 @@ function scrub_in($str) { } } // scrub_in -/*! - @function batch_ok() - @discussion return boolean if user can batch download - //FIXME: This needs to be fixed, it shouldn't be an independent function - //FIXME: It should reference a central one maybe the access object? -*/ -function batch_ok( ) { - - /* Also make sure that they have ZLIB */ - if (!function_exists('gzcompress')) { return false; } - - // i check this before showing any link - // should make it easy to tie to a new pref if you choose to add it - if (conf('allow_zip_download') AND $GLOBALS['user']->has_access(25)) { - return( $GLOBALS['user']->prefs['download'] ); - } // if allowed zip downloads - - return false; - -} // batch_ok - /*! @function set_memory_limit @discussion this function attempts to change the @@ -664,7 +643,7 @@ function make_bool($string) { function get_languages() { /* Open the locale directory */ - $handle = @opendir(conf('prefix') . '/locale'); + $handle = @opendir(Config::get('prefix') . '/locale'); if (!is_resource($handle)) { debug_event('language','Error unable to open locale directory','1'); @@ -677,7 +656,7 @@ function get_languages() { while ($file = readdir($handle)) { - $full_file = conf('prefix') . '/locale/' . $file; + $full_file = Config::get('prefix') . '/locale/' . $file; /* Check to see if it's a directory */ if (is_dir($full_file) AND substr($file,0,1) != '.' AND $file != 'base') { diff --git a/lib/preferences.php b/lib/preferences.php index 7e8cc62c..5fb1a696 100644 --- a/lib/preferences.php +++ b/lib/preferences.php @@ -268,16 +268,16 @@ function create_preference_input($name,$value) { else { $is_stream = "selected=\"selected\""; } echo " - -    - - " /> - - - - diff --git a/templates/show_preferences.inc.php b/templates/show_preferences.inc.php new file mode 100644 index 00000000..22843bfb --- /dev/null +++ b/templates/show_preferences.inc.php @@ -0,0 +1,96 @@ + + + + +has_access(100)) { ?> +[] + + + +
+ +
+
+
+ + + +    + + " /> + +
+
+ -- cgit