diff options
author | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2005-12-25 10:04:27 +0000 |
---|---|---|
committer | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2005-12-25 10:04:27 +0000 |
commit | 27158141ee1a14b7d23ae8997d2c41b49fc904d9 (patch) | |
tree | 2180fff67d21ffdbab32f2105cff3c7275b6b511 /lib | |
parent | 5415c2e847032896907946c98d68a254399e4416 (diff) | |
download | ampache-27158141ee1a14b7d23ae8997d2c41b49fc904d9.tar.gz ampache-27158141ee1a14b7d23ae8997d2c41b49fc904d9.tar.bz2 ampache-27158141ee1a14b7d23ae8997d2c41b49fc904d9.zip |
initial ratings mojo, some stylesheet fixes, changed user preferences again and a db update
Diffstat (limited to 'lib')
-rw-r--r-- | lib/class/rating.class.php | 34 | ||||
-rw-r--r-- | lib/class/update.class.php | 65 | ||||
-rw-r--r-- | lib/class/user.class.php | 34 | ||||
-rw-r--r-- | lib/general.lib.php | 53 | ||||
-rw-r--r-- | lib/preferences.php | 27 | ||||
-rw-r--r-- | lib/rating.lib.php | 82 | ||||
-rw-r--r-- | lib/themes.php | 9 | ||||
-rw-r--r-- | lib/ui.lib.php | 151 |
8 files changed, 325 insertions, 130 deletions
diff --git a/lib/class/rating.class.php b/lib/class/rating.class.php index 6d5199a4..f69e2585 100644 --- a/lib/class/rating.class.php +++ b/lib/class/rating.class.php @@ -32,8 +32,7 @@ class Rating { var $type; // The type of object we want /* Generated vars */ - var $rating; // The rating as set by this user - var $average_rating; // The average rating as set by all users + var $rating; // The average rating as set by all users /** * Constructor @@ -42,19 +41,31 @@ class Rating { */ function Rating($id,$type) { + $this->id = $id; + $this->type = $type; + if (intval($id) > 1) { + $this->get_average(); + } } // Rating /** * get_user * Get the user's rating this is based off the currently logged - * in user. It sets the $this->rating and returns the value + * in user. It returns the value */ - function get_user() { + function get_user($username) { + $username = sql_escape($username); + $sql = "SELECT rating FROM ratings WHERE user='$username' AND object_id='$this->id' AND object_type='$this->type'"; + $db_results = mysql_query($sql, dbh()); + + $results = mysql_fetch_assoc($db_results); + + return $results['rating']; } // get_user @@ -67,6 +78,21 @@ class Rating { */ function get_average() { + $sql = "SELECT rating FROM ratings WHERE object_id='$this->id' AND object_type='$this->type'"; + $db_results = mysql_fetch_assoc($db_results); + + $i = 0; + + while ($r = mysql_fetch_assoc($db_results)) { + $i++; + $total = $r['rating']; + } // while we're pulling results + + $average = floor($total/$i); + + $this->rating = $average; + + return $average; } // get_average diff --git a/lib/class/update.class.php b/lib/class/update.class.php index 8ef40403..10532321 100644 --- a/lib/class/update.class.php +++ b/lib/class/update.class.php @@ -242,6 +242,12 @@ class Update { $version[] = array('version' => '332003', 'description' => $update_string); + $update_string = "- Added ID to playlist_data so that duplicate songs on the same playlist can actually work.<br />" . + "- Re-worked Preferences, again :'(, hopefully making them better.<br />" . + "- Added rating table for SoundOfEmotions Rating system.<br />"; + + $version[] = array('version' => '332004', 'description' => $update_string); + return $version; } // populate_version @@ -1221,13 +1227,70 @@ class Update { @function update_332004 @discussion adds a id to the playlist_data field because of a problem with updating the same song on the same playlist being basicly - impossible...Also re-works the indexing on the tables + impossible...Adds rating table and general clean up */ function update_332004() { $sql = "ALTER TABLE `playlist_data` ADD `id` INT( 11 ) UNSIGNED NOT NULL AUTO_INCREMENT FIRST"; $db_results = mysql_query($sql, dbh()); + /* Create the ratings table */ + $sql = " CREATE TABLE `ratings` (`id` int(11) unsigned NOT NULL auto_increment," . + " `user` varchar(128) NOT NULL default ''," . + " `object_type` enum('artist','album','song') NOT NULL default 'artist'," . + " `object_id` int(11) unsigned NOT NULL default '0'," . + " `rating` enum('00','0','1','2','3','4','5') NOT NULL default '0'," . + " PRIMARY KEY (`id`))"; + $db_results = mysql_query($sql, dbh()); + + /* Add an index for the object ID */ + $sql = "ALTER TABLE `ratings` ADD INDEX ( `object_id` ) "; + $db_results = mysql_query($sql, dbh()); + + /** + * Update the Type designation on the preference table + * possible types are + * system, theme, interface, options, streaming + * users get everything but site, admins get the whole kit and kabodle + */ + + /* Set the Theme preferences */ + $sql = "UPDATE preferences SET type='theme' WHERE name='font' OR name='bg_color1' OR name='bg_color2' " . + " OR name='base_color1' OR name='base_color2' OR name='font_color1' OR name='font_color2' " . + " OR name='font_color3' OR name='row_color1' OR name='row_color2' OR name='row_color3' " . + " OR name='error_color' OR name='theme_name' OR name='font' OR name='font_size'"; + $db_results = mysql_query($sql, dbh()); + + /* Set the Interface preferences */ + $sql = "UPDATE preferences SET type='interface' WHERE name='refresh_limit' OR name='lang' OR name='condPL' " . + " OR name='popular_threshold' OR name='ellipse_threshold_album' OR name='ellipse_threshold_artist' " . + " OR name='ellipse_threshold_title'"; + $db_results = mysql_query($sql, dbh()); + + /* Set the Options Preferences */ + $sql = "UPDATE preferences SET type='options' WHERE name='download' OR name='upload' OR name='quarantine' " . + " OR name='direct_link' OR name='upload_dir'"; + $db_results = mysql_query($sql, dbh()); + + /* Set the Streaming Preferences */ + $sql = "UPDATE preferences SET type='streaming' WHERE name='sample_rate' OR name='play_type' " . + " OR name='playlist_type'"; + $db_results = mysql_query($sql, dbh()); + + /* Get the ID */ + $sql = "SELECT id FROM preferences WHERE name='display_menu'"; + $db_results = mysql_query($sql, dbh()); + + $result = mysql_fetch_assoc($db_results); + + /* Kill the bottom menu preference as its no longer needed */ + $sql = "DELETE FROM preferences WHERE name='display_menu'"; + $db_results = mysql_query($sql, dbh()); + + /* Kill the user pref references */ + $sql = "DELETE FROM user_preference WHERE preference='" . $result['id'] . "'"; + $db_results = mysql_query($sql, dbh()); + $this->set_version('db_version','332004'); } // update_332004 diff --git a/lib/class/user.class.php b/lib/class/user.class.php index 83a778ce..0b0459a7 100644 --- a/lib/class/user.class.php +++ b/lib/class/user.class.php @@ -74,11 +74,14 @@ class User { } // get_info - /*! - @function get_preferences - @discussion gets the prefs for this specific - user and returns them as an array - */ + /** + * get_preferences + * This is a little more complicate now that we've got many types of preferences + * This funtions pulls all of them an arranges them into a spiffy little array + * []['title'] = ucased type name + * []['prefs'] = array(array('name','display','value')); + * []['admin'] = t/f value if this is an admin only section + */ function get_preferences($user_id=0) { if (!$user_id) { @@ -86,14 +89,25 @@ class User { } if (!conf('use_auth')) { $user_id = '-1'; } - + + if ($user_id != '-1') { + $user_limit = "AND preferences.type != 'system'"; + } + + $sql = "SELECT preferences.name, preferences.description, preferences.type, user_preference.value FROM preferences,user_preference " . - "WHERE user_preference.user='$user_id' AND user_preference.preference=preferences.id AND preferences.type='user'"; + "WHERE user_preference.user='$user_id' AND user_preference.preference=preferences.id $user_limit"; $db_results = mysql_query($sql, dbh()); - while ($r = mysql_fetch_object($db_results)) { - $results[] = $r; - } + /* Ok this is crapy, need to clean this up or improve the code FIXME */ + while ($r = mysql_fetch_assoc($db_results)) { + $type = $r['type']; + $admin = false; + if ($type == 'system') { $admin = true; } + $type_array[$type][] = array('name'=>$r['name'],'description'=>$r['description'],'value'=>$r['value']); + $results[$type] = array ('title'=>ucwords($type),'admin'=>$admin,'prefs'=>$type_array[$type]); + } // end while + return $results; diff --git a/lib/general.lib.php b/lib/general.lib.php index 2896fb74..09c3ad5c 100644 --- a/lib/general.lib.php +++ b/lib/general.lib.php @@ -854,5 +854,58 @@ function make_bool($string) { } // make_bool +/** + * get_languages + * This function does a dir of ./locale and pulls the names of the + * different languages installed, this means that all you have to do + * is drop one in and it will show up on the context menu. It returns + * in the form of an array of names + */ +function get_languages() { + + /* Open the locale directory */ + $handle = @opendir(conf('prefix') . '/locale'); + + if (!is_resource($handle)) { + if (conf('debug')) { + log_event($GLOBALS['user']->username,'language',"Error unable to open locale directory"); + } + } + + $results = array(); + + /* Prepend English */ + $results['en_US'] = _('English'); + + while ($file = readdir($handle)) { + + $full_file = conf('prefix') . '/locale/' . $file; + + /* Check to see if it's a directory */ + if (is_dir($full_file) AND substr($file,0,1) != '.' AND $file != 'base') { + + switch($file) { + case 'de_DE'; $name = _('German'); break; + case 'en_US'; $name = _('English'); break; + case 'en_GB'; $name = _('British English'); break; + case 'es_ES'; $name = _('Spanish'); break; + case 'fr_FR'; $name = _('French'); break; + case 'it_IT'; $name = _('Italian'); break; + case 'nl_NL'; $name = _('Dutch'); break; + case 'tr_TR'; $name = _('Turkish'); break; + case 'zh_CN'; $name = _('Simplified Chinese'); break; + default: $name = _('Unknown'); break; + } // end switch + + + $results[$file] = $name; + } + + } // end while + + return $results; + +} // get_languages + ?> diff --git a/lib/preferences.php b/lib/preferences.php index 8e7135d7..dea96529 100644 --- a/lib/preferences.php +++ b/lib/preferences.php @@ -94,7 +94,7 @@ function update_preferences($pref_id=0) { $sql = "SELECT id,name,type FROM preferences"; /* If it isn't the System Account's preferences */ - if ($pref_id != '-1') { $sql .= " WHERE type='user'"; } + if ($pref_id != '-1') { $sql .= " WHERE type!='system'"; } $db_results = mysql_query($sql, dbh()); @@ -149,8 +149,12 @@ function update_preference($username,$name,$pref_id,$value) { /* 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'"; + $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); + } return true; } @@ -190,7 +194,7 @@ function has_preference_access($name) { $level = 100; break; default: - $level = 1; + $level = 25; break; } // end switch key @@ -290,18 +294,17 @@ function create_preference_input($name,$value) { echo "</select>\n"; break; case 'lang': + $languages = get_languages(); $var_name = $value . "_lang"; ${$var_name} = "selected=\"selected\""; + echo "<select name=\"$name\">\n"; - echo "\t<option value=\"de_DE\" $de_DE_lang>" . _("German") . "</option>\n"; - echo "\t<option value=\"en_US\" $en_US_lang>" . _("English") . "</option>\n"; - echo "\t<option value=\"en_GB\" $en_GB_lang>" . _("British English") . "</option>\n"; - echo "\t<option value=\"es_ES\" $es_ES_lang>" . _("Spanish") . "</option>\n"; - echo "\t<option value=\"fr_FR\" $fr_FR_lang>" . _("French") . "</option>\n"; - echo "\t<option value=\"it_IT\" $it_IT_lang>" . _("Italian") . "</option>\n"; - echo "\t<option value=\"nl_NL\" $nl_NL_lang>" . _("Dutch") . "</option>\n"; - echo "\t<option value=\"tr_TR\" $tr_TR_lang>" . _("Turkish") . "</option>\n"; - echo "\t<option value=\"zh_CN\" $zh_CN_lang>" . _("Simplified Chinese") . "</option>\n"; + + foreach ($languages as $lang=>$name) { + $var_name = $lang . "_lang"; + + echo "\t<option value=\"$lang\" " . ${$var_name} . ">$name</option>\n"; + } // end foreach echo "</select>\n"; break; case 'theme_name': diff --git a/lib/rating.lib.php b/lib/rating.lib.php new file mode 100644 index 00000000..4f854c93 --- /dev/null +++ b/lib/rating.lib.php @@ -0,0 +1,82 @@ +<?php +/* + + Copyright 2001 - 2006 Ampache.org + All Rights Reserved + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +*/ + +/** + * show_rating + * This takes an artist id and includes the right file + */ +function show_rating($object_id,$type) { + + $rating = new Rating($object_id,$type); + + switch (conf('ratings')) { + case 'normal': + include(conf('prefix') . '/templates/show_object_rating.inc.php'); + break; + case 'flash': + include(conf('prefix') . '/templates/show_object_rating_flash.inc.php'); + break; + default: + return false; + break; + } // end flash switch + + return true; + +} // show_rating + +/** + * get_rating_name + * This takes a score and returns the name that we should use + */ +function get_rating_name($score) { + + switch ($score) { + case '0': + return _("Don't Play"); + break; + case '1': + return _("It's Pretty Bad"); + break; + case '2': + return _("It's Ok"); + break; + case '3': + return _("It's Pretty Good"); + break; + case '4': + return _("I Love It!"); + break; + case '5': + return _("It's Insane"); + break; + // I'm fired + default: + return _("Off the Charts!"); + break; + } // end switch + + return true; + +} // get_rating_name + +?> diff --git a/lib/themes.php b/lib/themes.php index bb6c180a..1c67c5a7 100644 --- a/lib/themes.php +++ b/lib/themes.php @@ -75,6 +75,13 @@ function get_theme($name) { */ function set_theme_colors($theme_name,$user_id) { + + + if (make_bool($user_id)) { + $user_sql = "`user`='$user_id' AND"; + } + + /* We assume if we've made it this far we've got the right to do it This could be dangerous but eah! */ @@ -89,7 +96,7 @@ function set_theme_colors($theme_name,$user_id) { $results = mysql_fetch_array($db_results); - $sql = "UPDATE user_preference SET `value`='" . sql_escape($color) . "' WHERE `user`='" . $user_id . "' AND " . + $sql = "UPDATE user_preference SET `value`='" . sql_escape($color) . "' WHERE $user_sql " . " preference='" . $results[0] . "'"; $db_results = mysql_query($sql, dbh()); diff --git a/lib/ui.lib.php b/lib/ui.lib.php index 6c1be64a..6c6396ca 100644 --- a/lib/ui.lib.php +++ b/lib/ui.lib.php @@ -56,47 +56,60 @@ function show_confirmation($title,$text,$next_url) { */ function set_preferences() { - get_preferences(); + init_preferences(); return true; } // set_preferences /** * get_preferences - * reads this users 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) { - /* Get System Preferences first */ - $sql = "SELECT preferences.name,user_preference.value FROM preferences,user_preference WHERE user_preference.user='0' " . - " AND user_preference.preference = preferences.id AND preferences.type='system'"; - $db_results = mysql_query($sql, dbh()); + init_preferences(); + return true; - while ($r = mysql_fetch_object($db_results)) { - $results[$r->name] = $r->value; - } // end while sys prefs +} // get_preferences + +/** + * init_preferences + * Third times the charm, why rename a function once when you can do it three times :( + * This grabs the preferences and then loads them into conf it should be run on page load + * to initialize the needed variables + */ +function init_preferences() { - conf($results, 1); - unset($results); + /* 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'"; + $db_results = mysql_query($sql, dbh()); - if (!$username) { $username = $_SESSION['userdata']['username']; } + while ($r = mysql_fetch_assoc($db_results)) { + $name = $r['name']; + $results[$name] = $r['value']; + } // end while sys prefs - $user = new User($username); + /* Now we need to allow the user to override some stuff that's been set by the above */ + $username = $_SESSION['userdata']['username']; - $sql = "SELECT preferences.name,user_preference.value FROM preferences,user_preference WHERE user_preference.user='$user->username'" . - " AND user_preference.preference=preferences.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'"; $db_results = mysql_query($sql, dbh()); - while ($r = mysql_fetch_object($db_results)) { - $results[$r->name] = $r->value; - } + while ($r = mysql_fetch_assoc($db_results)) { + $name = $r['name']; + $results[$name] = $r['value']; + } // end while - unset($results['user'], $results['id']); + conf($results,1); - conf($results, 1); + return true; -} // get_preferences +} // init_preferences /** * flip_class @@ -520,7 +533,7 @@ function get_all_ratings($rate_user,$sort_by) {; $id=$row['object_id']; $rating=$row['user_rating']; $art_image="<img border=\"0\" src=\"" . conf('web_path') . "/albumart.php?id=" . $id . "\" alt=\"Album Art\" height=\"100\" />"; - $art_link="<a href='http://24.4.10.233/ampache/albums.php?action=show&album=$id'>$art_image</a>"; + $art_link="<a href='http://" . conf('web_path') . "/ampache/albums.php?action=show&album=$id'>$art_image</a>"; $artist_name=$album->f_artist; $album_name=$album->name; if($type=="album"){ @@ -533,7 +546,7 @@ function get_all_ratings($rate_user,$sort_by) {; "</table>"); } else{ - $artistLink="<a href='http://24.4.10.233/ampache/artists.php?action=show&artist=$id'>Artist $id</a>"; + $artistLink="<a href='" . conf('web_path') . "/ampache/artists.php?action=show&artist=$id'>Artist $id</a>"; echo ("<table width=150>" . "<tr>" . "<td align=left>$artist_link<br>" . @@ -547,85 +560,6 @@ function get_all_ratings($rate_user,$sort_by) {; } // get_artist_rating() -/** - * get_artist_rating() - Implemented by SoundOfEmotion - * - * given an artist id (string) it will return: - * false: if there is no current rating - * true: if there is a rating and will then display the rating - * - */ - -function get_artist_rating($artist_id, $rate_user) { - - $artist_id = sql_escape($artist_id); - - $sql = "SELECT `user_rating` FROM ratings WHERE user='$rate_user' AND object_type='artist' AND object_id='$artist_id'"; - $db_result = mysql_query( $sql, dbh() ); - $r = mysql_fetch_row( $db_result ); - - if ( $r[0] ) { - return ($r[0]); - } - - else{ - return "NA"; - } -} // get_artist_rating() - -/** - * get_album_rating() - Implemented by SoundOfEmotion - * - * given an album id (string) it will return: - * false: if there is no current rating - * true: if there is a rating and will then display - * the rating - * - */ - -function get_album_rating($album_id, $rate_user) { - - $album_id = sql_escape($album_id); - - $sql = "SELECT `user_rating` FROM ratings WHERE user='$rate_user' AND object_type='album' AND object_id='$album_id'"; - $db_result = mysql_query( $sql, dbh() ); - $r = mysql_fetch_row( $db_result ); - - if ( $r[0] ) { - return ($r[0]); - } - - else { - return "NA"; - } -} // get_album_rating() - -/** - * get_song_rating() - Implemented by SoundOfEmotion - * - * given a song id (string) it will return: - * false: if there is no current rating - * true: if there is a rating and will then display the rating - * - */ - -function get_song_rating($song_id, $rate_user) { - - $song_id = sql_escape($song_id); - - $sql = "SELECT `user_rating` FROM ratings WHERE user='$rate_user' AND object_type='song' AND object_id='$song_id'"; - $db_result = mysql_query( $sql, dbh() ); - $r = mysql_fetch_row( $db_result ); - - if ( $r[0] ) { - return ($r[0]); - } - - else{ - return "NA"; - } -} // get_song_rating() - /* * Artist Ratings - Implemented by SoundOfEmotion * @@ -1113,4 +1047,17 @@ function get_location() { } // get_location +/** + * show_preference_box + * This shows the preference box for the preferences pages + * it takes a chunck of the crazy preference array and then displays it out + * it does not contain the <form> </form> tags + */ +function show_preference_box($preferences) { + + include (conf('prefix') . '/templates/show_preference_box.inc.php'); + +} // show_preference_box + + ?> |