diff options
author | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2008-03-17 03:29:49 +0000 |
---|---|---|
committer | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2008-03-17 03:29:49 +0000 |
commit | bcc834d7fdabd0f52873a4f7696e065e3cf0f281 (patch) | |
tree | e28de4e85f40aaabae0a9263bc37346a8666e915 | |
parent | 27437304248e6d8fd44c2b997673ea112e08afa8 (diff) | |
download | ampache-bcc834d7fdabd0f52873a4f7696e065e3cf0f281.tar.gz ampache-bcc834d7fdabd0f52873a4f7696e065e3cf0f281.tar.bz2 ampache-bcc834d7fdabd0f52873a4f7696e065e3cf0f281.zip |
flush out the democratic mojo, make the cooldown work
-rwxr-xr-x | docs/CHANGELOG | 1 | ||||
-rw-r--r-- | lib/class/democratic.class.php | 27 | ||||
-rw-r--r-- | lib/class/stats.class.php | 27 | ||||
-rw-r--r-- | lib/class/update.class.php | 2 | ||||
-rw-r--r-- | modules/validatemail/validateEmail.php | 3 | ||||
-rw-r--r-- | play/index.php | 23 |
6 files changed, 76 insertions, 7 deletions
diff --git a/docs/CHANGELOG b/docs/CHANGELOG index 5c352d3a..83c089c7 100755 --- a/docs/CHANGELOG +++ b/docs/CHANGELOG @@ -4,6 +4,7 @@ -------------------------------------------------------------------------- v.3.4-Beta2 + - Added Cooldown Functionality to Democratic Play - Added /bin/fix_filenames.inc for correcting filenames with invalid chars - Removed album art add on Verify now that there is a distinct diff --git a/lib/class/democratic.class.php b/lib/class/democratic.class.php index cebb3272..e91abb45 100644 --- a/lib/class/democratic.class.php +++ b/lib/class/democratic.class.php @@ -26,6 +26,13 @@ */ class Democratic extends tmpPlaylist { + public $name; + public $cooldown; + public $level; + public $user; + public $primary; + public $base_playlist; + // Build local, buy local public $tmp_playlist; @@ -248,7 +255,7 @@ class Democratic extends tmpPlaylist { // We have to get all because of the pysco sorting $items = self::get_items(); - if (count($items)) { + if (count($items) > $offset) { $array = array_slice($items,$offset,1); $item = array_shift($array); $results['object_id'] = $item['0']; @@ -283,7 +290,7 @@ class Democratic extends tmpPlaylist { $object_id = Dba::escape($object_id); $object_type = $object_type ? Dba::escape($object_type) : 'song'; - $tmp_id = Dba::escape($this->id); + $tmp_id = Dba::escape($this->tmp_playlist); $sql = "SELECT `tmp_playlist_data`.`id` FROM `tmp_playlist_data` WHERE `object_type`='$object_type' AND " . "`tmp_playlist`='$tmp_id' AND `object_id`='$object_id'"; @@ -296,6 +303,22 @@ class Democratic extends tmpPlaylist { } // get_uid_from_object_id /** + * get_cool_songs + * This returns all of the song_ids for songs that have happened within the last 'cooldown' + * for this user. + */ + public function get_cool_songs() { + + // Convert cooldown time to a timestamp in the past + $cool_time = time() - ($this->cooldown * 60); + + $song_ids = Stats::get_object_history($GLOBALS['user']->id,$cool_time); + + return $song_ids; + + } // get_cool_songs + + /** * vote * This function is called by users to vote on a system wide playlist * This adds the specified objects to the tmp_playlist and adds a 'vote' diff --git a/lib/class/stats.class.php b/lib/class/stats.class.php index 0c8a69cd..9f5cfdae 100644 --- a/lib/class/stats.class.php +++ b/lib/class/stats.class.php @@ -90,6 +90,33 @@ class Stats { } // get_last_song /** + * get_object_history + * This returns the objects that have happened for $user_id sometime after $time + * used primarly by the democratic cooldown code + */ + public static function get_object_history($user_id='',$time) { + + $user_id = $user_id ? $user_id : $GLOBALS['user']->id; + + $user_id = Dba::escape($user_id); + + $time = Dba::escape($time); + + $sql = "SELECT * FROM `object_count` WHERE `user`='$user_id' AND `object_type`='song' AND `date`>='$time' " . + "ORDER BY `date` DESC"; + $db_results = Dba::query($sql); + + $results = array(); + + while ($row = Dba::fetch_assoc($db_results)) { + $results[] = $row['object_id']; + } + + return $results; + + } // get_object_history + + /** * get_top * This returns the top X for type Y from the * last conf('stats_threshold') days diff --git a/lib/class/update.class.php b/lib/class/update.class.php index 4d21c958..7127f1d5 100644 --- a/lib/class/update.class.php +++ b/lib/class/update.class.php @@ -267,7 +267,7 @@ class Update { '- Alter tmp_playlist to account for Democratic changes.<br />' . '- Cleared Existing Democratic playlists due to changes.<br />'; -// $version[] = array('version' => '340016','description'=>$update_string); + $version[] = array('version' => '340016','description'=>$update_string); return $version; diff --git a/modules/validatemail/validateEmail.php b/modules/validatemail/validateEmail.php index f6337806..3d460143 100644 --- a/modules/validatemail/validateEmail.php +++ b/modules/validatemail/validateEmail.php @@ -276,6 +276,7 @@ function validateEmail ( $email, $verbose=0 ) { // check that an MX record exists for Top-Level domain // If it exists, start our email address checking + if (function_exists('checkdnsrr')) { if ( checkdnsrr ( $domain, "MX" ) ) { // Okay -- we've got a valid DNS reverse record. @@ -618,6 +619,8 @@ function validateEmail ( $email, $verbose=0 ) { $return[0] = false; $return[1] = "554 No DNS reverse record found for $domain"; } // end checkdnsrr test + + } // if function doesn't exist } // end walking through each domain possibility diff --git a/play/index.php b/play/index.php index 77f34f67..4aaf6465 100644 --- a/play/index.php +++ b/play/index.php @@ -1,7 +1,7 @@ <?php /* - Copyright (c) 2001 - 2007 Ampache.org + Copyright (c) 2001 - 2008 Ampache.org All rights reserved. This program is free software; you can redistribute it and/or @@ -104,9 +104,24 @@ if (Config::get('access_control')) { if ($demo_id) { $democratic = new Democratic($demo_id); $democratic->set_parent(); - /* This takes into account votes etc and removes the */ - $song_id = $democratic->get_next_object(); -} + + // If there is a cooldown we need to make sure this song isn't a repeat + if (!$democratic->cooldown) { + /* This takes into account votes etc and removes the */ + $song_id = $democratic->get_next_object(); + } + else { + // Pull history + $song_id = $democratic->get_next_object($song_cool_check); + $song_ids = $democratic->get_cool_songs(); + while (in_array($song_id,$song_ids)) { + $song_cool_check++; + $song_id = $democratic->get_next_object($song_cool_check); + if ($song_cool_check >= '5') { break; } + } + + } // end if we've got a cooldown +} // if democratic ID passed /** * if we are doing random let's pull the random object |