diff options
author | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2007-07-23 06:08:14 +0000 |
---|---|---|
committer | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2007-07-23 06:08:14 +0000 |
commit | 216e691dfa53a28af8beca7aad2bf0ffb71dba2c (patch) | |
tree | 8b371e856d8107832a724f1ee0ad42f270435d0a /lib/class | |
parent | 84eca6a3d59fc591a7e28b3d7e0c11746dc837fc (diff) | |
download | ampache-216e691dfa53a28af8beca7aad2bf0ffb71dba2c.tar.gz ampache-216e691dfa53a28af8beca7aad2bf0ffb71dba2c.tar.bz2 ampache-216e691dfa53a28af8beca7aad2bf0ffb71dba2c.zip |
- Added Live Stream (Internet Radio) support
- New Database Update corrects some issues and makes internet radio possible
- Fixed ratings
- Added new Transcode preference, doesn't do anything yet
- New "Radio Stations" browse type
Diffstat (limited to 'lib/class')
-rw-r--r-- | lib/class/browse.class.php | 24 | ||||
-rw-r--r-- | lib/class/catalog.class.php | 35 | ||||
-rw-r--r-- | lib/class/genre.class.php | 2 | ||||
-rw-r--r-- | lib/class/radio.class.php | 148 | ||||
-rw-r--r-- | lib/class/rating.class.php | 17 | ||||
-rw-r--r-- | lib/class/tmpplaylist.class.php | 22 | ||||
-rw-r--r-- | lib/class/update.class.php | 43 |
7 files changed, 265 insertions, 26 deletions
diff --git a/lib/class/browse.class.php b/lib/class/browse.class.php index b4c2361a..e86b6786 100644 --- a/lib/class/browse.class.php +++ b/lib/class/browse.class.php @@ -89,6 +89,7 @@ class Browse { case 'album': case 'artist': case 'genre': + case 'live_stream': $_SESSION['browse']['type'] = $type; break; default: @@ -170,6 +171,9 @@ class Browse { case 'user': $sql = "SELECT `user`.`id` FROM `user` "; break; + case 'live_stream': + $sql = "SELECT `live_stream`.`id` FROM `live_stream` "; + break; case 'song': default: $sql = "SELECT `song`.`id` FROM `song` "; @@ -233,8 +237,7 @@ class Browse { break; } // end list of sqlable filters } // if it is a song - - if ($_SESSION['browse']['type'] == 'album') { + elseif ($_SESSION['browse']['type'] == 'album') { switch($filter) { case 'alpha_match': $filter_sql = " `album`.`name` LIKE '" . Dba::escape($value) . "%' AND "; @@ -247,7 +250,7 @@ class Browse { break; } } // end album - if ($_SESSION['browse']['type'] == 'artist') { + elseif ($_SESSION['browse']['type'] == 'artist') { switch($filter) { case 'alpha_match': $filter_sql = " `artist`.`name` LIKE '" . Dba::escape($value) . "%' AND "; @@ -257,6 +260,16 @@ class Browse { break; } // end filter } // end artist + elseif ($_SESSION['browse']['type'] == 'live_stream') { + switch ($filter) { + case 'alpha_match': + $filter_sql = " `live_stream`.`name` LIKE '" . Dba::escape($value) . "%' AND "; + break; + default: + // Rien a faire + break; + } // end filter + } // end live_stream return $filter_sql; @@ -339,6 +352,11 @@ class Browse { require_once Config::get('prefix') . '/templates/show_artists.inc.php'; show_box_bottom(); break; + case 'live_stream': + show_box_top(_('Radion Stations')); + require_once Config::get('prefix') . '/templates/show_live_streams.inc.php'; + show_box_bottom(); + break; default: // Rien a faire break; diff --git a/lib/class/catalog.class.php b/lib/class/catalog.class.php index 7e598e00..c337dec4 100644 --- a/lib/class/catalog.class.php +++ b/lib/class/catalog.class.php @@ -1288,7 +1288,9 @@ class Catalog { echo "update_txt('" . $count ."','clean_count_" . $this->id . "');"; echo "</script>\n"; show_box_top(); - echo "<b>" . _('Catalog Clean Done') . " [" . count($dead_files) . "] " . _('files removed') . "</b><br />\n"; + echo "<strong>" . _('Catalog Clean Done') . " [" . count($dead_files) . "] " . _('files removed') . "</strong><br />\n"; + echo "<strong>" . _('Optimizing Tables') . "...</strong><br />\n"; + self::optimize_tables(); show_box_bottom(); flush(); @@ -1419,7 +1421,8 @@ class Catalog { */ public static function clean_ext_info($catalog_id) { - $sql = "DELETE FROM song_ext_data USING song_ext_data LEFT JOIN song ON song.id = song_ext_data.song_id WHERE song.id IS NULL"; + $sql = "DELETE FROM `song_data` USING `song_data` LEFT JOIN `song` ON `song`.`id` = `song_data`.`song_id` " . + "WHERE `song`.`id` IS NULL"; $db_results = Dba::query($sql); } // clean_ext_info @@ -1451,19 +1454,19 @@ class Catalog { $db_results = Dba::query($sql); // Delete Song Ratings information - $sql = "DELETE FROM ratings USING ratings LEFT JOIN song ON song.id=ratings.object_id WHERE object_type='song' AND song.id IS NULL"; + $sql = "DELETE FROM rating USING rating LEFT JOIN song ON song.id=rating.object_id WHERE object_type='song' AND song.id IS NULL"; $db_results = Dba::query($sql); // Delete Genre Ratings Information - $sql = "DELETE FROM ratings USING ratings LEFT JOIN genre ON genre.id=ratings.object_id WHERE object_type='genre' AND genre.id IS NULL"; + $sql = "DELETE FROM rating USING rating LEFT JOIN genre ON genre.id=rating.object_id WHERE object_type='genre' AND genre.id IS NULL"; $db_results = Dba::query($sql); // Delete Album Rating Information - $sql = "DELETE FROM ratings USING ratings LEFT JOIN album ON album.id=ratings.object_id WHERE object_type='album' AND album.id IS NULL"; + $sql = "DELETE FROM rating USING rating LEFT JOIN album ON album.id=rating.object_id WHERE object_type='album' AND album.id IS NULL"; $db_results = Dba::query($sql); // Delete Artist Rating Information - $sql = "DELETE FROM ratings USING ratings LEFT JOIN artist ON artist.id=ratings.object_id WHERE object_type='artist' AND artist.id IS NULL"; + $sql = "DELETE FROM rating USING rating LEFT JOIN artist ON artist.id=rating.object_id WHERE object_type='artist' AND artist.id IS NULL"; $db_results = Dba::query($sql); } // clean_stats @@ -1597,6 +1600,26 @@ class Catalog { } // clean /** + * optimize_tables + * This runs an optomize on the tables and updates the stats to improve join speed + * this can be slow, but is a good idea to do from time to time. This is incase the dba + * isn't doing it... which we're going to assume they aren't + */ + public static function optimize_tables() { + + $sql = "OPTIMIZE TABLE `song_data`,`song`,`rating`,`catalog`,`session`,`object_count`,`album`,`album_data`" . + ",`artist`,`ip_history`,`genre`,`flagged`,`now_playing`,`user_preference`,`tags`,`tag_map`,`tmp_playlist`" . + ",`tmp_playlist_data`,`playlist`,`playlist_data`"; + $db_results = Dba::query($sql); + + $sql = "ANALYZE TABLE `song_data`,`song`,`rating`,`catalog`,`session`,`object_count`,`album`,`album_data`" . + ",`artist`,`ip_history`,`genre`,`flagged`,`now_playing`,`user_preference`,`tags`,`tag_map`,`tmp_playlist`" . + ",`tmp_playlist_data`,`playlist`,`playlist_data`"; + $db_results = Dba::query($sql); + + } // optimize_tables; + + /** * check_artist * $artist checks if there then return id else insert and return id */ diff --git a/lib/class/genre.class.php b/lib/class/genre.class.php index c0780591..64a44b96 100644 --- a/lib/class/genre.class.php +++ b/lib/class/genre.class.php @@ -65,7 +65,7 @@ class Genre { */ public function format() { - $this->link = "<a href=\"" . Config::get('web_path') . "/genre.php?action=show_genre&genre_id=" . $this->id . "\">" . scrub_out($this->name) . "</a>"; + $this->f_link = "<a href=\"" . Config::get('web_path') . "/genre.php?action=show_genre&genre_id=" . $this->id . "\">" . scrub_out($this->name) . "</a>"; $this->play_link = Config::get('web_path') . '/song.php?action=genre&genre=' . $this->id; $this->random_link = Config::get('web_path') . '/song.php?action=random_genre&genre=' . $this->id; diff --git a/lib/class/radio.class.php b/lib/class/radio.class.php new file mode 100644 index 00000000..108f0c16 --- /dev/null +++ b/lib/class/radio.class.php @@ -0,0 +1,148 @@ +<?php +/* + + Copyright 2001 - 2007 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; version 2 + of the License. + + 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. + +*/ + +/** + * Radio Class + * This handles the internet radio stuff, that is inserted into live_stream + * this can include podcasts or what-have-you + */ +class Radio { + + /* DB based variables */ + public $id; + public $name; + public $site_url; + public $url; + public $frequency; + public $call_sign; + public $genre; + public $catalog; + + /** + * Constructor + * This takes a flagged.id and then pulls in the information for said flag entry + */ + public function __construct($id) { + + $this->id = intval($id); + + if (!$this->id) { return false; } + + $info = $this->_get_info(); + + // Set the vars + foreach ($info as $key=>$value) { + $this->$key = $value; + } + + } // constructor + + /** + * _get_info + * Private function for getting the information for this object from the database + */ + private function _get_info() { + + $id = Dba::escape($this->id); + + $sql = "SELECT * FROM `live_stream` WHERE `id`='$id'"; + $db_results = Dba::query($sql); + + $results = Dba::fetch_assoc($db_results); + + return $results; + + } // _get_info + + /** + * format + * This takes the normal data from the database and makes it pretty + * for the users, the new variables are put in f_??? and f_???_link + */ + public function format() { + + // Default link used on the rightbar + $this->f_link = "<a href=\"$this->url\">$this->name</a>"; + + $this->f_name_link = "<a target=\"_blank\" href=\"$this->site_url\">$this->name</a>"; + $this->f_callsign = scrub_out($this->call_sign); + $this->f_frequency = scrub_out($this->frequency); + + $genre = new Genre($this->genre); + $genre->format(); + $this->f_genre = $genre->f_link; + + return true; + + } // format + + /** + * create + * This is a static function that takes a key'd array for input + * and if everything is good creates the object. + */ + public static function create($data) { + + // Make sure we've got a name + if (!strlen($data['name'])) { + Error::add('name','Name Required'); + } + + if (!preg_match("/^https?:\/\/.+/",$data['url'])) { + Error::add('url','Invalid URL must be http:// or https://'); + } + + // Make sure it's a real genre + $genre = new Genre($data['genre']); + if (!$genre->name) { + Error::add('genre','Invalid Genre'); + } + + // Make sure it's a real catalog + $catalog = new Catalog($data['catalog']); + if (!$catalog->name) { + Error::add('catalog','Invalid Catalog'); + } + + if (Error::$state) { return false; } + + // Clean up the input + $name = Dba::escape($data['name']); + $site_url = Dba::escape($data['site_url']); + $url = Dba::escape($data['url']); + $genre = $genre->id; + $catalog = $catalog->id; + $frequency = Dba::escape($data['frequency']); + $call_sign = Dba::escape($data['call_sign']); + + // If we've made it this far everything must be ok... I hope + $sql = "INSERT INTO `live_stream` (`name`,`site_url`,`url`,`genre`,`catalog`,`frequency`,`call_sign`) " . + "VALUES ('$name','$site_url','$url','$genre','$catalog','$frequency','$call_sign')"; + $db_results = Dba::query($sql); + + return $db_results; + + } // create + +} //end of radio class + +?> diff --git a/lib/class/rating.class.php b/lib/class/rating.class.php index 349f01d0..1ddd842a 100644 --- a/lib/class/rating.class.php +++ b/lib/class/rating.class.php @@ -64,12 +64,12 @@ class Rating { $user_id = Dba::escape($user_id); - $sql = "SELECT `rating` FROM `rating` WHERE `user`='$user_id' AND `object_id`='$this->id' AND `object_type`='$this->type'"; + $sql = "SELECT `score` FROM `rating` WHERE `user`='$user_id' AND `object_id`='$this->id' AND `object_type`='$this->type'"; $db_results = Dba::query($sql); $results = Dba::fetch_assoc($db_results); - return $results['rating']; + return $results['score']; } // get_user @@ -82,14 +82,14 @@ class Rating { */ public function get_average() { - $sql = "SELECT `rating` FROM `rating` WHERE `object_id`='$this->id' AND `object_type`='$this->type'"; + $sql = "SELECT `score` FROM `rating` WHERE `object_id`='$this->id' AND `object_type`='$this->type'"; $db_results = Dba::query($sql); $i = 0; while ($r = Dba::fetch_assoc($db_results)) { $i++; - $total += $r['rating']; + $total += $r['score']; } // while we're pulling results if ($total > 0) { @@ -123,11 +123,11 @@ class Rating { $db_results = Dba::query($sql); if ($existing = Dba::fetch_assoc($db_results)) { - $sql = "UPDATE `rating` SET `rating`='$score' WHERE `id`='" . $existing['id'] . "'"; + $sql = "UPDATE `rating` SET `score`='$score' WHERE `id`='" . $existing['id'] . "'"; $db_results = Dba::query($sql); } else { - $sql = "INSERT INTO `rating` (`object_id`,`object_type`,`rating`,`user`) VALUES " . + $sql = "INSERT INTO `rating` (`object_id`,`object_type`,`score`,`user`) VALUES " . " ('$this->id','$this->type','$score','" . $GLOBALS['user']->id . "')"; $db_results = Dba::query($sql); } @@ -157,7 +157,12 @@ class Rating { */ public static function show_static ($object_id,$type) { + // If there aren't ratings don't return anything + if (!Config::get('ratings')) { return false; } + + $rating = new Rating($object_id,$type); + require Config::get('prefix') . '/templates/show_static_object_rating.inc.php'; } // show_static diff --git a/lib/class/tmpplaylist.class.php b/lib/class/tmpplaylist.class.php index ab55ec58..8d037179 100644 --- a/lib/class/tmpplaylist.class.php +++ b/lib/class/tmpplaylist.class.php @@ -121,7 +121,9 @@ class tmpPlaylist { /** * get_items - * This returns an array of all object_ids currently in this tmpPlaylist + * This returns an array of all object_ids currently in this tmpPlaylist. This + * has gotten a little more complicated because of type, the values are an array + * 0 being ID 1 being TYPE */ public function get_items() { @@ -134,7 +136,8 @@ class tmpPlaylist { } /* 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 " . + $sql = "SELECT tmp_playlist_data.object_type, tmp_playlist_data.id, tmp_playlist_data.object_id $vote_select " . + "FROM tmp_playlist_data $vote_join " . "WHERE tmp_playlist_data.tmp_playlist='" . Dba::escape($this->id) . "' $order"; $db_results = Dba::query($sql); @@ -143,7 +146,7 @@ class tmpPlaylist { while ($results = Dba::fetch_assoc($db_results)) { $key = $results['id']; - $items[$key] = $results['object_id']; + $items[$key] = array($results['object_id'],$results['object_type']); } return $items; @@ -343,14 +346,16 @@ class tmpPlaylist { /** * add_object * This adds the object of $this->object_type to this tmp playlist + * it takes an optional type, default is song */ - public function add_object($object_id) { + public function add_object($object_id,$object_type) { $object_id = Dba::escape($object_id); $playlist_id = Dba::escape($this->id); + $object_type = $object_type ? Dba::escape($object_type) : 'song'; - $sql = "INSERT INTO `tmp_playlist_data` (`object_id`,`tmp_playlist`) " . - " VALUES ('$object_id','$playlist_id')"; + $sql = "INSERT INTO `tmp_playlist_data` (`object_id`,`tmp_playlist`,`object_type`) " . + " VALUES ('$object_id','$playlist_id','$object_type')"; $db_results = Dba::query($sql); return true; @@ -495,11 +500,10 @@ class tmpPlaylist { public function delete_track($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'"; + $sql = "DELETE FROM `tmp_playlist_data` " . + " WHERE `id`='$id'"; $db_results = Dba::query($sql); /* If this is a voting playlit prune votes */ diff --git a/lib/class/update.class.php b/lib/class/update.class.php index 6b51527c..5f3874d2 100644 --- a/lib/class/update.class.php +++ b/lib/class/update.class.php @@ -204,6 +204,12 @@ class Update { $version[] = array('version' => '340004','description' => $update_string); + $update_string = '- Altered Ratings table so the fields make more sense.<br />' . + '- Moved Random Method to Playlist catagory.<br />' . + '- Added Transcode Method to Streaming.<br />'; + + $version[] = array('version' => '340005','description' => $update_string); + return $version; } // populate_version @@ -710,14 +716,49 @@ class Update { } // update_340004 - /** * update_340005 * This update fixes the preferences types */ public static function update_340005() { + // Turn user_rating into a tinyint and call it score + $sql = "ALTER TABLE `rating` CHANGE `user_rating` `score` TINYINT( 4 ) UNSIGNED NOT NULL DEFAULT '0'"; + $db_results = Dba::query($sql); + $sql = "UPDATE `preference` SET `catagory`='playlist' WHERE `name`='random_method'"; + $db_results = Dba::query($sql); + + $sql = "INSERT INTO `preference` (`name`,`value`,`description`,`level`,`type`,`catagory`) " . + "VALUES ('transcode','default','Transcoding','25','string','streaming')"; + $db_results = Dba::query($sql); + + /* We need to check for playlist_method here because I fubar'd an earlier update */ + $sql = "SELECT * FROM `preference` WHERE `name`='playlist_method'"; + $db_results = Dba::query($sql); + if (!Dba::num_rows($db_results)) { + /* Add the playlist_method preference and remove it from the user table */ + $sql = "INSERT INTO `preference` (`name`,`value`,`description`,`level`,`type`,`catagory`) " . + "VALUES ('playlist_method','default','Playlist Method','5','string','playlist')"; + $db_results = Dba::query($sql); + } + + // Add in the object_type to the tmpplaylist data table so that we can have non-songs in there + $sql = "ALTER TABLE `tmp_playlist_data` ADD `object_type` VARCHAR( 32 ) NULL AFTER `tmp_playlist`"; + $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','340005'); + + return true; } // update_340005 |