diff options
-rw-r--r-- | democratic.php (renamed from tv.php) | 0 | ||||
-rw-r--r-- | download/index.php | 6 | ||||
-rw-r--r-- | lib/class/tmp_playlist.class.php | 203 | ||||
-rw-r--r-- | lib/class/update.class.php | 22 | ||||
-rw-r--r-- | play/index.php | 20 |
5 files changed, 138 insertions, 113 deletions
diff --git a/download/index.php b/download/index.php index d390d778..ff4b0e9e 100644 --- a/download/index.php +++ b/download/index.php @@ -1,7 +1,7 @@ <?php /* - Copyright (c) 2001 - 2006 Ampache.org + Copyright (c) 2001 - 2007 Ampache.org All rights reserved. This program is free software; you can redistribute it and/or @@ -25,8 +25,8 @@ Special thanks to the Horde project for their Browser class that makes this so easy. */ -require('../lib/init.php'); -require(conf('prefix') . '/modules/horde/Browser.php'); +require '../lib/init.php'; +require Config::get('prefix') . '/modules/horde/Browser.php'; $browser = new Browser(); diff --git a/lib/class/tmp_playlist.class.php b/lib/class/tmp_playlist.class.php index cc5f1b39..30b66ecc 100644 --- a/lib/class/tmp_playlist.class.php +++ b/lib/class/tmp_playlist.class.php @@ -1,7 +1,7 @@ <?php /* - Copyright (c) 2001 - 2006 Ampache.org + Copyright (c) 2001 - 2007 Ampache.org All rights reserved. This program is free software; you can redistribute it and/or @@ -18,6 +18,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + /** * TempPlaylist Class * This class handles the temporary playlists in ampache, it handles the @@ -27,51 +28,46 @@ class tmpPlaylist { /* Variables from the Datbase */ - var $id; - var $session; - var $type; - var $object_type; - var $base_playlist; + public $id; + public $session; + public $type; + public $object_type; + public $base_playlist; /* Generated Elements */ - var $items = array(); - + public $items = array(); /** * Constructor * This takes a playlist_id as an optional argument and gathers the information * if not playlist_id is passed returns false (or if it isn't found */ - function tmpPlaylist($playlist_id='') { + public function __construct($playlist_id='') { if (!$playlist_id) { return false; } $this->id = intval($playlist_id); $info = $this->_get_info(); - /* If we get something back */ - if (count($info)) { - $this->session = $info['session']; - $this->type = $info['type']; - $this->object_type = $info['object_type']; - $this->base_playlist = $info['base_playlist']; + foreach ($info as $key=>$value) { + $this->$key = $value; } return true; - } // tmpPlaylist + } // __construct /** * _get_info * This is an internal (private) function that gathers the information for this object from the * playlist_id that was passed in. */ - function _get_info() { + private function _get_info() { - $sql = "SELECT * FROM tmp_playlist WHERE id='" . sql_escape($this->id) . "'"; - $db_results = mysql_query($sql, dbh()); + $sql = "SELECT * FROM `tmp_playlist` WHERE `id`='" . Dba::escape($this->id) . "'"; + $db_results = Dba::query($sql); - $results = mysql_fetch_assoc($db_results); + $results = Dba::fetch_assoc($db_results); return $results; @@ -81,25 +77,25 @@ class tmpPlaylist { * get_items * This returns an array of all object_ids currently in this tmpPlaylist */ - function get_items() { + public function get_items() { $order = 'ORDER BY id ASC'; if ($this->type == 'vote') { $order = "GROUP BY tmp_playlist_data.id ORDER BY `count` DESC, user_vote.date ASC"; $vote_select = ", COUNT(user_vote.user) AS `count`"; - $vote_join = "LEFT JOIN user_vote ON user_vote.object_id=tmp_playlist_data.id"; + $vote_join = "INNER JOIN user_vote ON user_vote.object_id=tmp_playlist_data.id"; } /* Select all objects from this playlist */ $sql = "SELECT tmp_playlist_data.id, tmp_playlist_data.object_id $vote_select FROM tmp_playlist_data $vote_join " . - "WHERE tmp_playlist_data.tmp_playlist='" . sql_escape($this->id) . "' $order"; - $db_results = mysql_query($sql, dbh()); + "WHERE tmp_playlist_data.tmp_playlist='" . Dba::escape($this->id) . "' $order"; + $db_results = Dba::query($sql); /* Define the array */ $items = array(); - while ($results = mysql_fetch_assoc($db_results)) { + while ($results = Dba::fetch_assoc($db_results)) { $key = $results['id']; $items[$key] = $results['object_id']; } @@ -114,9 +110,9 @@ class tmpPlaylist { * will just be the top entry, but if there is a base_playlist and no * items in the playlist then it returns a random entry from the base_playlist */ - function get_next_object() { + public function get_next_object() { - $tmp_id = sql_escape($this->id); + $tmp_id = Dba::escape($this->id); $order = " ORDER BY tmp_playlist_data.id DESC"; /* Check for an item on the playlist, account for voting */ @@ -124,14 +120,14 @@ class tmpPlaylist { /* Add conditions for voting */ $vote_select = ", COUNT(user_vote.user) AS `count`"; $order = " GROUP BY tmp_playlist_data.id ORDER BY `count` DESC, user_vote.date ASC"; - $vote_join = "LEFT JOIN user_vote ON user_vote.object_id=tmp_playlist_data.id"; + $vote_join = "INNER JOIN user_vote ON user_vote.object_id=tmp_playlist_data.id"; } $sql = "SELECT tmp_playlist_data.object_id $vote_select FROM tmp_playlist_data $vote_join " . "WHERE tmp_playlist_data.tmp_playlist = '$tmp_id' $order LIMIT 1"; - $db_results = mysql_query($sql, dbh()); + $db_results = Dba::query($sql); - $results = mysql_fetch_assoc($db_results); + $results = Dba::fetch_assoc($db_results); /* If nothing was found and this is a voting playlist then get from base_playlist */ if ($this->type == 'vote' AND !$results) { @@ -145,8 +141,8 @@ class tmpPlaylist { } else { $sql = "SELECT id as `object_id` FROM song WHERE enabled='1' ORDER BY RAND() LIMIT 1"; - $db_results = mysql_query($sql, dbh()); - $results = mysql_fetch_assoc($db_results); + $db_results = Dba::query($sql); + $results = Dba::fetch_assoc($db_results); } } @@ -158,9 +154,9 @@ class tmpPlaylist { * get_vote_url * This returns the special play URL for democratic play, only open to ADMINs */ - function get_vote_url() { + public function get_vote_url() { - $link = conf('web_path') . '/play/index.php?tmp_id=' . scrub_out($this->id) . + $link = Config::get('web_path') . '/play/index.php?tmp_id=' . scrub_out($this->id) . '&sid=' . scrub_out(session_id()) . '&uid=' . scrub_out($GLOBALS['user']->id); return $link; @@ -172,24 +168,24 @@ class tmpPlaylist { * This function initializes a new tmpPlaylist it is assoicated with the current * session rather then a user, as you could have same user multiple locations */ - function create($sessid,$type,$object_type,$base_playlist) { + public static function create($sessid,$type,$object_type,$base_playlist) { - $sessid = sql_escape($sessid); - $type = sql_escape($type); - $object_type = sql_escape($object_type); - $base_playlist = sql_escape($base_playlist); + $sessid = Dba::escape($sessid); + $type = Dba::escape($type); + $object_type = Dba::escape($object_type); + $base_playlist = Dba::escape($base_playlist); - $sql = "INSERT INTO tmp_playlist (`session`,`type`,`object_type`,`base_playlist`) " . + $sql = "INSERT INTO `tmp_playlist` (`session`,`type`,`object_type`,`base_playlist`) " . " VALUES ('$sessid','$type','$object_type','$base_playlist')"; - $db_results = mysql_query($sql, dbh()); + $db_results = Dba::query($sql); - $id = mysql_insert_id(dbh()); + $id = Dba::insert_id(); /* Prune dead tmp_playlists */ - $this->prune_playlists(); + self::prune_playlists(); /* Clean any other playlists assoicated with this session */ - $this->delete($sessid,$id); + self::delete($sessid,$id); return $id; @@ -199,13 +195,13 @@ class tmpPlaylist { * update_playlist * This updates the base_playlist on this tmp_playlist */ - function update_playlist($playlist_id) { + public function update_playlist($playlist_id) { - $playlist_id = sql_escape($playlist_id); - $tmp_id = sql_escape($this->id); + $playlist_id = Dba::escape($playlist_id); + $tmp_id = Dba::escape($this->id); - $sql = "UPDATE tmp_playlist SET tmp_playlist.base_playlist='$playlist_id' WHERE id='$tmp_id'"; - $db_results = mysql_query($sql,dbh()); + $sql = "UPDATE `tmp_playlist` SET tmp_playlist.base_playlist='$playlist_id' WHERE `id`='$tmp_id'"; + $db_results = Dba::query($sql); return true; @@ -216,16 +212,16 @@ class tmpPlaylist { * This deletes any other tmp_playlists assoicated with this * session */ - function delete($sessid,$id) { + public static function delete($sessid,$id) { - $sessid = sql_escape($sessid); - $id = sql_escape($id); + $sessid = Dba::escape($sessid); + $id = Dba::escape($id); - $sql = "DELETE FROM tmp_playlist WHERE session='$sessid' AND id != '$id'"; - $db_results = mysql_query($sql,dbh()); + $sql = "DELETE FROM `tmp_playlist` WHERE `session`='$sessid' AND `id` != '$id'"; + $db_results = Dba::query($sql); /* Remove assoicated tracks */ - $this->prune_tracks(); + self::prune_tracks(); return true; @@ -235,13 +231,13 @@ class tmpPlaylist { * prune_playlists * This deletes and playlists that don't have an assoicated session */ - function prune_playlists() { + public static function prune_playlists() { /* Just delete if no matching session row */ - $sql = "DELETE FROM tmp_playlist USING tmp_playlist " . + $sql = "DELETE FROM `tmp_playlist` USING `tmp_playlist` " . "LEFT JOIN session ON session.id=tmp_playlist.session " . "WHERE session.id IS NULL AND tmp_playlist.session != '-1'"; - $db_results = mysql_query($sql,dbh()); + $db_results = Dba::query($sql); return true; @@ -251,17 +247,17 @@ class tmpPlaylist { * prune_tracks * This prunes tracks that don't have playlists or don't have votes */ - function prune_tracks() { + public static function prune_tracks() { $sql = "DELETE FROM tmp_playlist_data USING tmp_playlist_data " . "LEFT JOIN tmp_playlist ON tmp_playlist_data.tmp_playlist=tmp_playlist.id " . "WHERE tmp_playlist.id IS NULL"; - $db_results = mysql_query($sql,dbh()); + $db_results = Dba::query($sql); $sql = "DELETE FROM tmp_playlist_data USING tmp_playlist_data " . "LEFT JOIN user_vote ON tmp_playlist_data.id=user_vote.object_id " . "WHERE user_vote.object_id IS NULL"; - $db_results = mysql_query($sql,dbh()); + $db_results = Dba::query($sql); return true; @@ -271,14 +267,14 @@ class tmpPlaylist { * add_object * This adds the object of $this->object_type to this tmp playlist */ - function add_object($object_id) { + public function add_object($object_id) { - $object_id = sql_escape($object_id); - $playlist_id = sql_escape($this->id); + $object_id = Dba::escape($object_id); + $playlist_id = Dba::escape($this->id); - $sql = "INSERT INTO tmp_playlist_data (`object_id`,`tmp_playlist`) " . + $sql = "INSERT INTO `tmp_playlist_data` (`object_id`,`tmp_playlist`) " . " VALUES ('$object_id','$playlist_id')"; - $db_results = mysql_query($sql, dbh()); + $db_results = Dba::query($sql); return true; @@ -291,7 +287,7 @@ class tmpPlaylist { * by this user, naturally it checks to make sure that the user hasn't * already voted on any of these objects */ - function vote($items) { + public function vote($items) { /* Itterate through the objects if no vote, add to playlist and vote */ foreach ($items as $object_id) { @@ -300,36 +296,35 @@ class tmpPlaylist { } } // end foreach - } // vote /** * add_vote * This takes a object id and user and actually inserts the row */ - function add_vote($object_id,$tmp_playlist) { + public function add_vote($object_id,$tmp_playlist) { - $object_id = sql_escape($object_id); - $tmp_playlist = sql_escape($tmp_playlist); + $object_id = Dba::escape($object_id); + $tmp_playlist = Dba::escape($tmp_playlist); /* If it's on the playlist just vote */ $sql = "SELECT id FROM tmp_playlist_data " . "WHERE tmp_playlist_data.object_id='$object_id'"; - $db_results = mysql_query($sql, dbh()); + $db_results = Dba::query($sql); /* If it's not there, add it and pull ID */ - if (!$results = mysql_fetch_assoc($db_results)) { + if (!$results = Dba::fetch_assoc($db_results)) { $sql = "INSERT INTO tmp_playlist_data (`tmp_playlist`,`object_id`) " . "VALUES ('$tmp_playlist','$object_id')"; - $db_results = mysql_query($sql, dbh()); - $results['id'] = mysql_insert_id(dbh()); + $db_results = Dba::query($sql); + $results['id'] = Dba::insert_id(); } /* Vote! */ $time = time(); $sql = "INSERT INTO user_vote (`user`,`object_id`,`date`) " . - "VALUES ('" . sql_escape($GLOBALS['user']->id) . "','" . $results['id'] . "','$time')"; - $db_results = mysql_query($sql, dbh()); + "VALUES ('" . Dba::escape($GLOBALS['user']->id) . "','" . $results['id'] . "','$time')"; + $db_results = Dba::query($sql); return true; @@ -339,20 +334,20 @@ class tmpPlaylist { * has_vote * This checks to see if the current user has already voted on this object */ - function has_vote($object_id) { + public function has_vote($object_id) { - $tmp_id = sql_escape($this->id); + $tmp_id = Dba::escape($this->id); /* Query vote table */ - $sql = "SELECT tmp_playlist_data.id FROM user_vote " . + $sql = "SELECT tmp_playlist_data.id FROM `user_vote` " . "INNER JOIN tmp_playlist_data ON tmp_playlist_data.id=user_vote.object_id " . - "WHERE user_vote.user='" . sql_escape($GLOBALS['user']->id) . "' " . - "AND tmp_playlist_data.object_id='" . sql_escape($object_id) . "' " . + "WHERE user_vote.user='" . Dba::escape($GLOBALS['user']->id) . "' " . + "AND tmp_playlist_data.object_id='" . Dba::escape($object_id) . "' " . "AND tmp_playlist_data.tmp_playlist='$tmp_id'"; - $db_results = mysql_query($sql, dbh()); + $db_results = Dba::query($sql); /* If we find row, they've voted!! */ - if (mysql_num_rows($db_results)) { + if (Dba::num_rows($db_results)) { return true; } @@ -364,15 +359,15 @@ class tmpPlaylist { * get_vote * This returns the current count for a specific song on this tmp_playlist */ - function get_vote($object_id) { + public function get_vote($object_id) { - $object_id = sql_escape($object_id); + $object_id = Dba::escape($object_id); $sql = "SELECT COUNT(`user`) AS `count` FROM user_vote " . " WHERE object_id='$object_id'"; - $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['count']; @@ -383,7 +378,7 @@ class tmpPlaylist { * This checks to see if this playlist is a voting playlist * and if it is active */ - function vote_active() { + public function vote_active() { /* Going to do a little more here later */ if ($this->type == 'vote') { return true; } @@ -398,18 +393,18 @@ class tmpPlaylist { * As that's what we'll have most the time, no need to check if they've got an existing * vote for this, just remove anything that is there */ - function remove_vote($object_id) { + public function remove_vote($object_id) { - $object_id = sql_escape($object_id); - $user_id = sql_escape($GLOBALS['user']->id); + $object_id = Dba::escape($object_id); + $user_id = Dba::escape($GLOBALS['user']->id); $sql = "DELETE FROM user_vote USING user_vote INNER JOIN tmp_playlist_data ON tmp_playlist_data.id=user_vote.object_id " . "WHERE user='$user_id' AND tmp_playlist_data.object_id='$object_id' " . - "AND tmp_playlist_data.tmp_playlist='" . sql_escape($this->id) . "'"; - $db_results = mysql_query($sql,dbh()); + "AND tmp_playlist_data.tmp_playlist='" . Dba::escape($this->id) . "'"; + $db_results = Dba::query($sql); /* Clean up anything that has no votes */ - $this->prune_tracks(); + self::prune_tracks(); return true; @@ -420,22 +415,22 @@ class tmpPlaylist { * This deletes a track and any assoicated votes, we only check for * votes if it's vote playlist, id is a object_id */ - function delete_track($id) { + public function delete_track($id) { - $id = sql_escape($id); - $tmp_id = sql_escape($this->id); + $id = Dba::escape($id); + $tmp_id = Dba::escape($this->id); /* delete the track its self */ $sql = "DELETE FROM tmp_playlist_data " . " WHERE tmp_playlist='$tmp_id' AND object_id='$id'"; - $db_results = mysql_query($sql,dbh()); + $db_results = Dba::query($sql); /* If this is a voting playlit prune votes */ if ($this->type == 'vote') { $sql = "DELETE FROM user_vote USING user_vote " . "LEFT JOIN tmp_playlist_data ON user_vote.object_id = tmp_playlist_data.id " . "WHERE tmp_playlist_data.id IS NULL"; - $db_results = mysql_query($sql,dbh()); + $db_results = Dba::query($sql); } return true; @@ -447,18 +442,18 @@ class tmpPlaylist { * This is really just a wrapper function, it clears the entire playlist * including all votes etc. */ - function clear_playlist() { + public function clear_playlist() { - $tmp_id = sql_escape($this->id); + $tmp_id = Dba::escape($this->id); /* Clear all votes then prune */ $sql = "DELETE FROM user_vote USING user_vote " . "LEFT JOIN tmp_playlist_data ON user_vote.object_id = tmp_playlist_data.id " . "WHERE tmp_playlist_data.tmp_playlist='$tmp_id'"; - $db_results = mysql_query($sql,dbh()); + $db_results = Dba::query($sql); // Prune! - $this->prune_tracks(); + self::prune_tracks(); return true; diff --git a/lib/class/update.class.php b/lib/class/update.class.php index 55d32d31..27bc8fb5 100644 --- a/lib/class/update.class.php +++ b/lib/class/update.class.php @@ -193,7 +193,8 @@ class Update { $update_string = '- Moved Art from the Album table into album_data to improve performance.<br />' . '- Made some minor changes to song table to reduce size of each row.<br />' . - '- Moved song_ext_data to song_data to match album_data pattern.<br />'; + '- Moved song_ext_data to song_data to match album_data pattern.<br />' . + '- Added Playlist Method and Rate Limit Preferences.<br />'; $version[] = array('version' => '340003','description' => $update_string); @@ -612,6 +613,25 @@ class Update { $sql = "ALTER TABLE `user` DROP `offset_limit`"; $db_results = Dba::query($sql); + /* Add the rate_limit preference */ + $sql = "INSERT INTO `preferences` (`name`,`value`,`description`,`level`,`type`,`catagory`) " . + "VALUES ('rate_limit','8192','Rate Limit','100','integer','streaming')"; + $db_results = Dba::query($sql); + + /* Add the playlist_method preference and remove it from the user table */ + $sql = "INSERT INTO `preferences` (`name`,`value`,`description`,`level`,`type`,`catagory`) " . + "VALUES ('playlist_method','50','Playlist Method','5','string','streaming')"; + $db_results = Dba::query($sql); + + $sql = "SELECT `id` FROM `user`"; + $db_results = Dba::query($sql); + + User::fix_preferences('-1'); + + while ($r = Dba::fetch_assoc($db_results)) { + User::fix_preferences($r['id']); + } + self::set_version('db_version','340003'); } // update_340003 diff --git a/play/index.php b/play/index.php index 895a5de3..0df5a879 100644 --- a/play/index.php +++ b/play/index.php @@ -45,7 +45,7 @@ if (empty($song_id) && empty($tmp_id)) { } if (!isset($uid)) { - debug_event('no_usre','Error: No User specified','2'); + debug_event('no_user','Error: No User specified','2'); exit; } @@ -82,8 +82,8 @@ if (Config::get('demo_mode') || (!$GLOBALS['user']->has_access('25') && !$xml_rp that they have enough access to play this mojo */ if (Config::get('access_control')) { - if (!Access::check_network('stream',$_SERVER['REMOTE_ADDR'],$GLOBALS['user']->username,'25') AND - !Access::check_network('network',$_SERVER['REMOTE_ADDR'],$GLOBALS['user']->username,'25')) { + if (!Access::check_network('stream',$_SERVER['REMOTE_ADDR'],$GLOBALS['user']->id,'25') AND + !Access::check_network('network',$_SERVER['REMOTE_ADDR'],$GLOBALS['user']->id,'25')) { debug_event('access_denied', "Streaming Access Denied: " . $_SERVER['REMOTE_ADDR'] . " does not have stream level access",'3'); access_denied(); exit; @@ -196,7 +196,7 @@ if (Config::get('track_user_ip')) { /* If access control is on and they aren't local, downsample! */ if (Config::get('access_control') AND Config::get('downsample_remote')) { - if (Access::check_network('network',$_SERVER['REMOTE_ADDR'],$GLOBALS['user']->username,'25')) { + if (Access::check_network('network',$_SERVER['REMOTE_ADDR'],$GLOBALS['user']->id,'25')) { $not_local = true; } } // if access_control @@ -244,9 +244,19 @@ else { */ $bytesStreamed = $start; $minBytesStreamed = $song->size / 2; + +// We need to check to see if they are rate limited +$chunk_size = '8192'; + +if ($GLOBALS['user']->prefs['rate_limit'] > 0) { + $chunk_size = $GLOBALS['user']->prefs['rate_limit']; +} + +// Actually do the streaming while (!feof($fp) && (connection_status() == 0)) { - $buf = fread($fp, 8192); + $buf = fread($fp, $chunk_size); print($buf); + if ($GLOBALS['user']->prefs['rate_limit'] > 0) { slepp (1); } $bytesStreamed += strlen($buf); } |