From 97bcd214044e30b5078052ee0c523b63966d6833 Mon Sep 17 00:00:00 2001 From: Karl 'vollmerk' Vollmer Date: Mon, 26 May 2008 08:28:09 +0000 Subject: added direct links back in, added batch download to single artist view, removed useless cruft --- config/ampache.cfg.php.dist | 6 - docs/CHANGELOG | 8 + lib/class/access.class.php | 3 + lib/class/api.class.php | 14 +- lib/class/database_object.abstract.php | 6 +- lib/class/metadata.class.php | 149 ------- lib/class/rating.class.php | 13 +- lib/class/stream.class.php | 17 +- lib/class/vauth.class.php | 2 + lib/class/xmlrpcserver.class.php | 5 +- lib/init.php | 1 - lib/preferences.php | 2 - modules/infotools/openstrands.class.php | 725 -------------------------------- modules/plugins/OpenStrands.plugin.php | 66 --- server/stats.ajax.php | 80 +--- server/xml.server.php | 2 +- templates/show_artist.inc.php | 22 +- templates/show_song_row.inc.php | 5 +- 18 files changed, 68 insertions(+), 1058 deletions(-) delete mode 100644 lib/class/metadata.class.php delete mode 100644 modules/infotools/openstrands.class.php delete mode 100644 modules/plugins/OpenStrands.plugin.php diff --git a/config/ampache.cfg.php.dist b/config/ampache.cfg.php.dist index 73b33121..61730ea6 100644 --- a/config/ampache.cfg.php.dist +++ b/config/ampache.cfg.php.dist @@ -264,12 +264,6 @@ album_art_order = "db,id3,folder,lastfm,amazon" ; DEFAULT: true show_album_art = "true" -; MyStrands Developer ID -; This is needed for any of the OpenStrands functionality to work correctly -; this is the developer ID you obtained from http://www.mystrands.com/openstrands/overview.vm -; DEFAULT: false -;mystrands_developer_key = "" - ; Amazon Developer Key ; This is needed in order to actually use the amazon album art ; DEFAULT: false diff --git a/docs/CHANGELOG b/docs/CHANGELOG index 3f3b7082..ce7e772e 100755 --- a/docs/CHANGELOG +++ b/docs/CHANGELOG @@ -4,6 +4,14 @@ -------------------------------------------------------------------------- v.3.5-Alpha1 + - Added Batch Download to single Artist view + - Added back in the direct links on songs, requires download set + to enabled as it's essentially the same thing except with + now playing information tied to it + - Bumped API Version to 350001 and require that a version is sent + with handshake to indicate the application will work + - Removed the MyStrands plugin as did not provide good data, and does + not appear to have been used - Added Catalog Prefix config option used to determine which prefixes should not be used for sorting - Merged Browse Menu with Home diff --git a/lib/class/access.class.php b/lib/class/access.class.php index 64719141..113735ae 100644 --- a/lib/class/access.class.php +++ b/lib/class/access.class.php @@ -140,6 +140,9 @@ class Access { public static function check_function($type) { switch ($type) { + case 'download': + return Config::get('download'); + break ; case 'batch_download': if (!function_exists('gzcompress')) { debug_event('gzcompress','ZLIB Extensions not loaded, batch download disabled','3'); diff --git a/lib/class/api.class.php b/lib/class/api.class.php index 5ff54906..09cb9997 100644 --- a/lib/class/api.class.php +++ b/lib/class/api.class.php @@ -26,7 +26,7 @@ */ class Api { - public static $version = '340001'; + public static $version = '350001'; /** * constructor @@ -45,7 +45,12 @@ class Api { * can take a username, if non is passed the ACL must be non-use * specific */ - public static function handshake($timestamp,$passphrase,$ip,$username='') { + public static function handshake($timestamp,$passphrase,$ip,$username='',$version) { + + if (intval($version) < self::$version) { + debug_event('API','Login Failed version too old','1'); + return false; + } // If the timestamp is over 2hr old sucks to be them if ($timestamp < (time() - 14400)) { @@ -88,9 +93,7 @@ class Api { $token = vauth::session_create($data); // Insert the token into the streamer - $stream = new Stream(); - $stream->user_id = $client->id; - $stream->insert_session($token); + Stream::insert_session($token,$client->id); debug_event('API','Login Success, passphrase matched','1'); // We need to also get the 'last update' of the catalog information in an RFC 2822 Format @@ -122,6 +125,7 @@ class Api { } // end while debug_event('API','Login Failed, unable to match passphrase','1'); + return false; } // handhsake diff --git a/lib/class/database_object.abstract.php b/lib/class/database_object.abstract.php index 5aaf6cac..871232ea 100644 --- a/lib/class/database_object.abstract.php +++ b/lib/class/database_object.abstract.php @@ -36,10 +36,10 @@ abstract class database_object { * this checks the cache to see if the specified object is there */ public static function is_cached($index,$id) { + + $is_cached = isset(self::$object_cache[$index][$id]); - $is_array = isset(self::$object_cache[$index][$id]); - - return $is_array; + return $is_cached; } // is_cached diff --git a/lib/class/metadata.class.php b/lib/class/metadata.class.php deleted file mode 100644 index ca7da903..00000000 --- a/lib/class/metadata.class.php +++ /dev/null @@ -1,149 +0,0 @@ -array($artist->name)); - $results = $openstrands->recommend_artists($seed,$limit); - break; - } - - $objects = array(); - - foreach ($results as $item) { - switch ($type) { - case 'artist': - $data['name'] = $item['ArtistName']; - $data['uid'] = $item['__attributes']['ArtistID']; - $data['mystrands_url'] = $item['URI']; - $data['links'] = "" . get_user_icon('world_link','MyStrands Link') . ""; - - // Do a search for this artist in our instance - $artist_id = Catalog::check_artist($data['name'],1); - if ($artist_id) { - $artist = new Artist($artist_id); - $artist->format(); - $data['links'] .= "f_link\">" . get_user_icon('ampache','Ampache') . ""; - } - - $objects[] = Artist::construct_from_array($data); - break; - } // end switch on type - } // end foreach - - return $objects; - - } // recommend_similar - - /** - * find_missing_tracks - * This returns an array of song objects using the construct_from_array() that are - * not in the specified album. - */ - public static function find_missing_tracks($album_id) { - - // Build our object - $album = new Album($album_id); - $album->format(); - $objects = array(); - - // For now it's only mystrands - OpenStrands::set_auth_token(Config::get('mystrands_developer_key')); - $openstrands = new OpenStrands(Config::get('mystrands_user'),Config::get('mystrands_pass')); - - if (!$openstrands) { return false; } - - // Setup the string we're going to pass - if ($album->artist_count == '1') { $artist_name = $album->artist_name; } - else { $artist_name = "Various"; } - - $data[] = array('artist'=>$artist_name,'album'=>$album->full_name); - - // First find the album on mystrands - $result = $openstrands->match_albums($data); - - if (!$result) { return false; } - - $mystrands_id = $result['0']['__attributes']['AlbumId']; - - if (!$mystrands_id) { return false; } - - $tracks = $openstrands->lookup_album_tracks($mystrands_id,Openstrands::$alias); - - $object = array(); - - // Recurse the data we've found and check the local album - foreach ($tracks as $track) { - if (!$album->has_track($track['TrackName'])) { - $data['title'] = $track['TrackName']; - $data['track'] = $track['TrackNumber']; - $data['disc'] = $track['DiscNumber']; - $data['artist'] = $track['ArtistName']; - $data['links'] = "" . get_user_icon('world_link','MyStrands') . ""; - // If we've got a purchase URL - if ($track['UserPurchaseURI']) { - $data['links'] .= "" . get_user_icon('money',_('Buy Track from MyStrands')) . ""; - } - $objects[] = Album::construct_from_array($data); - } - } // end foreach - - return $objects; - - } // find_missing_tracks - -} // metadata - -?> diff --git a/lib/class/rating.class.php b/lib/class/rating.class.php index 086084ea..3f317187 100644 --- a/lib/class/rating.class.php +++ b/lib/class/rating.class.php @@ -68,20 +68,19 @@ class Rating extends database_object { $user_id = Dba::escape($GLOBALS['user']->id); $idlist = '(' . implode(',', $ids) . ')'; - $sql = "SELECT `rating`, `object_id` FROM `rating` WHERE `user`='$user_id' AND `object_id` IN $idlist " . + $sql = "SELECT `rating`, `object_id`,`rating`.`rating` FROM `rating` WHERE `user`='$user_id' AND `object_id` IN $idlist " . "AND `object_type`='$type'"; $db_results = Dba::query($sql); while ($row = Dba::fetch_assoc($db_results)) { - $rating[$row['id']] = $row['rating']; + $results[$row['object_id']] = intval($row['rating']); } - $user_cache_name = 'rating_' . $type . '_user'; - foreach ($ids as $id) { - parent::add_to_cache($user_cache_name,$id,intval($rating[$id])); - } // end foreach + parent::add_to_cache('rating_' . $type . '_user',$id,intval($results[$id])); + } + return true; } // build_cache @@ -92,8 +91,6 @@ class Rating extends database_object { */ public function get_user($user_id) { - $id = intval($this->id); - if (parent::is_cached('rating_' . $this->type . '_user',$id)) { return parent::get_from_cache('rating_' . $this->type . '_user',$id); } diff --git a/lib/class/stream.class.php b/lib/class/stream.class.php index 7582b9e2..dece1a7b 100644 --- a/lib/class/stream.class.php +++ b/lib/class/stream.class.php @@ -39,6 +39,9 @@ class Stream { // Generate once an object is constructed public static $session; + // Let's us tell if the session has been activated + private static $session_inserted; + /** * Constructor for the stream class takes a type and an array * of song ids @@ -69,7 +72,7 @@ class Stream { } // We're starting insert the session into session_stream - if (!$this->insert_session()) { + if (!self::insert_session()) { debug_event('stream','Session Insertion failure, aborting','3'); return false; } @@ -106,6 +109,10 @@ class Stream { */ public static function get_session() { + if (!self::$session_inserted) { + self::insert_session(self::$session); + } + return self::$session; } // get_session @@ -114,18 +121,21 @@ class Stream { * insert_session * This inserts a row into the session_stream table */ - public function insert_session($sid='') { + public static function insert_session($sid='',$uid='') { $sid = $sid ? Dba::escape($sid) : Dba::escape(self::$session); + $uid = $uid ? Dba::escape($uid) : Dba::escape($GLOBALS['user']->id); $expire = time() + Config::get('stream_length'); $sql = "INSERT INTO `session_stream` (`id`,`expire`,`user`) " . - "VALUES('$sid','$expire','$this->user_id')"; + "VALUES('$sid','$expire','$uid')"; $db_results = Dba::query($sql); if (!$db_results) { return false; } + self::$session_inserted = true; + return true; } // insert_session @@ -679,7 +689,6 @@ class Stream { } // clear_now_playing - /** * auto_init * This is called on class load it sets the session diff --git a/lib/class/vauth.class.php b/lib/class/vauth.class.php index d5ee590d..410b2155 100644 --- a/lib/class/vauth.class.php +++ b/lib/class/vauth.class.php @@ -88,6 +88,8 @@ class vauth { */ public static function write($key,$value) { + // If we'd set NO_SESSION never run this + if (NO_SESSION == 1) { return true; } $length = Config::get('session_length'); $value = Dba::escape($value); diff --git a/lib/class/xmlrpcserver.class.php b/lib/class/xmlrpcserver.class.php index fc903aaf..3801dc09 100644 --- a/lib/class/xmlrpcserver.class.php +++ b/lib/class/xmlrpcserver.class.php @@ -141,10 +141,7 @@ class xmlRpcServer { return new xmlrpcresp(0,'503','Key/IP Mis-match Access Denied'); } - $stream = new Stream(); - $stream->user_id = '-1'; - - if (!$stream->insert_session($key)) { + if (!Stream::insert_session($key,'-1')) { debug_event('XMLSERVER','Failed to create stream session','1'); return new xmlrpcresp(0,'503','Failed to Create Stream Session','1'); } diff --git a/lib/init.php b/lib/init.php index 71297258..7c6e3896 100644 --- a/lib/init.php +++ b/lib/init.php @@ -135,7 +135,6 @@ require_once $prefix . '/modules/getid3/getid3.php'; require_once $prefix . '/modules/infotools/Snoopy.class.php'; require_once $prefix . '/modules/infotools/AmazonSearchEngine.class.php'; require_once $prefix . '/modules/infotools/lastfm.class.php'; -require_once $prefix . '/modules/infotools/openstrands.class.php'; //require_once $prefix . '/modules/infotools/jamendoSearch.class.php'; /* Temp Fixes */ diff --git a/lib/preferences.php b/lib/preferences.php index 786e9a38..ad5dc3ca 100644 --- a/lib/preferences.php +++ b/lib/preferences.php @@ -59,7 +59,6 @@ function update_preferences($pref_id=0) { break; /* MD5 the LastFM & MyStrands so it's not plainTXT */ case 'lastfm_pass': - case 'mystrands_pass': /* If it's our default blanking thing then don't use it */ if ($value == '******') { unset($_REQUEST[$name]); break; } $value = md5($value); @@ -241,7 +240,6 @@ function create_preference_input($name,$value) { } // foreach themes echo "\n"; break; - case 'mystrands_pass': case 'lastfm_pass': echo ""; break; diff --git a/modules/infotools/openstrands.class.php b/modules/infotools/openstrands.class.php deleted file mode 100644 index 4410a279..00000000 --- a/modules/infotools/openstrands.class.php +++ /dev/null @@ -1,725 +0,0 @@ -user_validate($username,$password); - - if (!$auth_data) { - self::$authenticated = false; - } - else { - self::$authenticated = true; - self::$alias = $auth_data['0']['Alias']; - } - - - } // __construct - - /** - * user_validate - * This takes a username, password and returns a key'd array of the - * result data - */ - public function user_validate($username,$password) { - - $username = urlencode($username); - $password = urlencode($password); - - $xml_doc = self::run_query("/user/validate?username=$username&hexPass=$password"); - - // Set the right parent - $this->_containerTag = 'User'; - - $data = $this->run_parse($xml_doc); - - return $data; - - } // user_validate - - /** - * user_lookup_profile - * This takes a username and the md5 password and returns the users profile information - */ - public function user_lookup_profile($username,$password) { - - $username = urlencode($username); - $password = urlencode($password); - - $xml_doc = self::run_query("/user/lookup/profile?username=$username&hexPass=$password"); - - // Set the right parent - $this->_containerTag = 'User'; - - $data = $this->run_parse($xml_doc); - - return $data; - - } // user_lookup_profile - - /** - * lookup_artists - * This returns the data for a given mystrands artist (based on ID) - * If it's an array of ids pass as [] = ID, [] = ID - */ - public function lookup_artists($ids) { - - // This allows multiple artists in a single query - // so build the string if needed - if (is_array($ids)) { - foreach ($ids as $id) { - $string .= '&id=' . intval($id); - } - $string = ltrim($string,'&'); - $string = '?' . $string; - } - else { - $string = '?id=' . intval($ids); - } - - $xml_doc = self::run_query("/lookup/artists$string"); - - // Set the right parent - $this->_containerTag = 'SimpleArtist'; - - $data = $this->run_parse($xml_doc); - - return $data; - - } // lookup_artists - - /** - * lookup_albums - * This returns the data for a given mystrands album (based on ID) - * If it's an array of ids pass as [] = ID, [] = ID - * You can optionally pass an alias to this, if you do you can get - * the 'buy' links as UserPurchaseURI - */ - public function lookup_albums($ids,$alias='') { - - // This allows multiple albums in a single query, - // so build it accordingly - if (is_array($ids)) { - foreach ($ids as $id) { - $string .= '&id=' . intval($id); - } - $string = ltrim($string,'&'); - $string = '?' . $string; - } - else { - $string = '?id=' . intval($ids); - } - - // If they have passed an alias - if ($alias) { - $string .= '&alias=' . urlencode($alias); - } - - $xml_doc = self::run_query("/lookup/albums$string"); - - // Set the right parent - $this->_containerTag = 'SimpleAlbum'; - - $data = $this->run_parse($xml_doc); - - return $data; - - } // lookup_albums - - /** - * lookup_tracks - * This returns the data for a given mystrands track (based on ID) - * If it's an array of ids pass as [] = ID, [] = ID - * This can take an optional alias, if passed UserPurchaseURI will - * be returned - */ - public function lookup_tracks($ids,$alias='') { - - // This allows for multiple entires, so build accordingly - if (is_array($ids)) { - foreach ($ids as $id) { - $string .= '&id=' . intval($id); - } - $string = ltrim($string,'&'); - $string = '?' . $string; - } // end if array - else { - $string = '?id=' . intval($ids); - } - - // If they have passed an alias - if ($alias) { - $string .= '&alias=' . urlencode($alias); - } - - $xml_doc = self::run_query("/lookup/tracks$string"); - - // Set the parent - $this->_containerTag = 'SimpleTrack'; - - $data = $this->run_parse($xml_doc); - - return $data; - - } // lookup_tracks - - /** - * lookup_album_tracks - * This takes a album ID and then returns the track list for it - */ - public function lookup_album_tracks($mystrands_album_id,$alias='') { - - $mystrands_album_id = intval($mystrands_album_id); - - if ($alias) { - $alias_txt = '&alias=' . urlencode($alias); - } - - $xml_doc = self::run_query("/lookup/album/tracks?id=$mystrands_album_id$alias_txt"); - - // Set the right parent - $this->_containerTag = 'AlbumTrack'; - - $data = $this->run_parse($xml_doc); - - return $data; - - } // lookup_album_tracks - - /** - * lookup_artist_albums - * This returns a list of the albums for a given artist ID you can - * pass an optional limit and offset - */ - public function lookup_artist_albums($artist_id,$limit='',$offset='') { - - $artist_id = intval($artist_id); - - $limit = $limit ? intval($limit) : $this->limit; - $offset = $offset ? intval($offset) : '0'; - - $xml_doc = self::run_query("/lookup/artist/albums?id=$artist_id&num=$limit&skip=$offset"); - - // Set the container - $this->_containerTag = 'SimpleAlbum'; - - $data = $this->run_parse($xml_doc); - - return $data; - - } // lookup_artist_albums - - /** - * search_albums - * This searches for albums of the given name in MyStrands - */ - public function search_albums($name,$limit='',$offset='') { - - $name = urlencode($name); - - $limit = $limit ? intval($limit) : $this->limit; - $offset = $offset ? intval($offset) : '0'; - - $xml_doc = self::run_query("/search/albums?searchText=$name&num=$limit&skip=$offset"); - - // Set the right parent - $this->_containerTag = 'SimpleAlbum'; - - $data = $this->run_parse($xml_doc); - - return $data; - - } // search_albums - - /** - * search_artists - * This searches for artists of the given name in MyStrands - */ - public function search_artists($name,$limit='',$offset='') { - - $name = urlencode($name); - - $limit = $limit ? intval($limit) : $this->limit; - $offset = $offset ? intval($offset) : '0'; - - $xml_doc = self::run_query("/search/artists?searchText=$name&num=$limit&skip=$offset"); - - // Set the right parent - $this->_containerTag = 'SimpleArtist'; - - $data = $this->run_parse($xml_doc); - - return $data; - - } // search_artists - - /** - * search_tracks - * This searches for tracks on Mystrands based on the search text - */ - public function search_tracks($name,$limit='',$offset='') { - - $name = urlencode($name); - - $limit = $limit ? intval($limit) : $this->limit; - $offset = $offset ? intval($offset) : '0'; - - $xml_doc = self::run_query("/search/tracks?searchText=$name&num=$limit&skip=$offset"); - - // Set the right parent - $this->_containerTag = 'SimpleTrack'; - - $data = $this->run_parse($xml_doc); - - return $data; - - } // search_tracks - - /** - * match_artists - * This does a best choice match on the artist name(s) passed - */ - public function match_artists($values) { - - // If it's not, turn it into one! - if (!is_array($values)) { $values = array($values); } - - foreach ($values as $value) { - $artist_text .= '&name=' . urlencode($value); - } - - $artist_text = ltrim($artist_text,'&'); - $artist_text = '?' . $artist_text; - - $xml_doc = self::run_query("/match/artists$artist_text"); - - // Set the right parent - $this->_containerTag = 'SimpleArtist'; - - $data = $this->run_parse($xml_doc); - - return $data; - - } // match_artists - - /** - * match_albums - * This does its best to match on the album name with an attached artist name - * This function expects matches paris album,artist as such - * [0]['artist'] = artist name, [0]['album'] = album name - */ - public function match_albums($values) { - - // We're less forgiving here - if (!is_array($values)) { return false; } - - foreach ($values as $value) { - if (!$value['artist'] || !$value['album']) { next; } - $query_text .= '&name=' . urlencode($value['artist']) . '|' . urlencode($value['album']); - } - - $query_text = ltrim($query_text,'&'); - $query_text = '?' . $query_text; - - $xml_doc = self::run_query("/match/albums$query_text"); - - // Set the right parent - $this->_containerTag = 'SimpleAlbum'; - - $data = $this->run_parse($xml_doc); - - return $data; - - } // match_albums - - /** - * match_tracks - * This expects a trifectum of information as such - * [0]['artist'] = artist name - * [0]['album'] = album name - * [0]['track] = track - */ - public function match_tracks($values) { - - // We're not very forgiving here - if (!is_array($values)) { return false; } - - foreach ($values as $value) { - if (!$value['artist'] || !$value['album'] || !$value['track']) { next; } - $query_text .= '&name' . urlencode($value['artist']) . '|' . urlencode($value['album']) . '|' . urlencode($value['track']); - } // end foreach - - $query_text = ltrim($query_text,'&'); - $query_text = '?' . $query_text; - - $xml_doc = self::run_query("/match/tracks$query_text"); - - // Set up the parent - $this->_containerTag = 'SimpleTrack'; - - $data = $this->run_parse($xml_doc); - - return $data; - - } // match_tracks - - /** - * recommend_artists - * This generates recomendations for other artists, takes at least one artist (ID/Name) as - * as seed, filters allowed, this user is used unless another alias is passed - * $values should be ['id'][] = ID, ['id'][] = ID, ['name'][] = NAME, ['name'][] = NAME - */ - public function recommend_artists($values,$limit='',$offset='',$alias='') { - - if (!is_array($values['id'])) { $values['id'] = array(); } - if (!is_array($values['name'])) { $values['name'] = array(); } - - // Build out the ids first - foreach ($values['id'] as $id) { - $id_string .= '&id=' . intval($id); - } - // Now for z-names - foreach ($values['name'] as $name) { - $name_string .= '&name=' . urlencode($name); - } - - // Clean up remaining stuff - $filters = $this->filter; - $offset = $offset ? intval($offset) : '0'; - $limit = $limit ? intval($limit) : $this->limit; - $alias = $alias ? urlencode($alias) : urlencode(self::$alias); - - $xml_doc = self::run_query("/recommend/artists?alias=$alias$id_string$name_string&num=$limit&skip=$offset$filters"); - - $this->_containerTag = 'SimpleArtist'; - - $data = $this->run_parse($xml_doc); - - return $data; - - } // recommend_artists - - /** - * recommend_albums - * This produces recommended albums based on sets of artist|album filters allowed, this user is used unless different - * alias is passed. Values are integrity checked to the best of my lazyness - * $values should be ['id'][] = ARTISTID|ALBUMID, ['name'][] = ARTIST|ALBUM - */ - public function recommend_albums($values,$limit='',$offset='',$alias='') { - - if (!is_array($values['id'])) { $values['id'] = array(); } - if (!is_array($values['name'])) { $values['name'] = array(); } - - // Build out the ids first - foreach ($values['id'] as $id) { - if (!preg_match("/\d+\|\d+/",$id)) { next; } - $id_string .= '&id=' . intval($id); - } - // Now for z-names - foreach ($values['name'] as $name) { - // Only add stuff that's valid - if (!preg_match("/.+\|.+/",$name)) { next; } - $name_string .= '&name=' . urlencode($name); - } - - // Clean up remaining stuff - $filters = $this->filter; - $offset = $offset ? intval($offset) : '0'; - $limit = $limit ? intval($limit) : $this->limit; - $alias = $alias ? urlencode($alias) : urlencode(self::$alias); - - $xml_doc = self::run_query("/recommend/albums?alias=$alias$id_string$name_string&num=$limit&skip=$offset$filters"); - - $this->_containerTag = 'SimpleAlbum'; - - $data = $this->run_parse($xml_doc); - - return $data; - - } // recommend_albums - - /** - * recommend_tracks - * This produces recommended tracks based on sets of artist|album|track filters allowed, this user is used unless different - * alias is passed. Values are integrity checked to the best of my lazyness - * $values should be ['id'][] = ARTISTID|ALBUMID|TRACKID, ['name'][] = ARTIST|ALBUM|TRACK - */ - public function recommend_tracks($values,$limit='',$offset='',$alias='') { - - if (!is_array($values['id'])) { $values['id'] = array(); } - if (!is_array($values['name'])) { $values['name'] = array(); } - - // Build out the ids first - foreach ($values['id'] as $id) { - if (!preg_match("/\d+\|\d+\|\d+/",$id)) { next; } - $id_string .= '&id=' . intval($id); - } - // Now for z-names - foreach ($values['name'] as $name) { - // Only add stuff that's valid - if (!preg_match("/.+\|.+\|.+/",$name)) { next; } - $name_string .= '&name=' . urlencode($name); - } - - // Clean up remaining stuff - $filters = $this->filter; - $offset = $offset ? intval($offset) : '0'; - $limit = $limit ? intval($limit) : $this->limit; - $alias = $alias ? urlencode($alias) : urlencode(self::$alias); - - $xml_doc = self::run_query("/recommend/tracks?alias=$alias$id_string$name_string&num=$limit&skip=$offset$filters"); - - $this->_containerTag = 'SimpleTrack'; - - $data = $this->run_parse($xml_doc); - - return $data; - - } // recommend_tracks - - /** - * set_filter - * This builds out the filter for this object, it's a per instance filter - */ - public function set_filter($field,$fuzzy,$level,$values) { - - // Make sure they pick a sane field - switch ($field) { - case 'Artist': - case 'Album': - case 'Year': - case 'Track': - case 'Genre': - case 'PersonalTag': - case 'CommunityTag': - case 'PersonalTrackTag': - case 'CommunityTrackTag': - case 'PersonalArtistTag': - case 'CommunityArtistTag': - case 'UserHistory': - // We're good - break; - default: - return false; - break; - } // end switch on passed filed - - $level = intval($level); - - // Default to very hard - if ($level > 9 || $level < 0) { $level = 0; } - - // Clean up the fuzzyness - $fuzzy = make_bool($fuzzy); - if ($fuzzy) { $fuzzy = 'True'; } - else { $fuzzy = 'False'; } - - if (is_array($values)) { - foreach ($values as $value) { - $value_string .= $value; - } - } - else { - $value_string = $values; - } - - $filter_string = "&filter=$field,$fuzzy,$level|$value_string"; - - $this->filter .= $filter_string; - - } // set_filter - - /** - * set_auth_token - * This function should be called on load to set the auth_token, if you don't - * just hardcode it, also allows realtime switching between auth tokens - * so that users can use their own limits when querying - */ - public static function set_auth_token($token) { - - // Set it - self::$auth_token = $token; - - //FIXME: We should log this event? - - } // set_auth_token - - /** - * run_query - * This builds a URL, runs it and then returns whatever we found - */ - private static function run_query($action) { - - // Stop them if they are not authenticated - if (!self::$authenticated) { return false; } - - // Build the URL - $url = self::$base_url . $action . '&subscriberId=' . self::$auth_token; - - $contents = file_get_contents($url); - - return $contents; - - } // run_query - - /** - * run_parse - * This will create the parser, de-fudge the doc - * and set $this->results to the result data - */ - public function run_parse($xml_doc) { - - // Create the parser - $this->create_parser(); - - $this->_key = -1; - $success = xml_parse($this->_parser,$xml_doc); - - if (!$success) { - return false; - } - - xml_parser_free($this->_parser); - - $data = $this->results; - $this->results = ''; - - if (!$data) { return array(); } - - return $data; - - } // run_parse - - /** - * create_parser - * this sets up an XML Parser - */ - public function create_parser() { - $this->_parser = xml_parser_create(); - - xml_parser_set_option($this->_parser, XML_OPTION_CASE_FOLDING, false); - - xml_set_object($this->_parser, $this); - - xml_set_element_handler($this->_parser, 'start_element', 'end_element'); - - xml_set_character_data_handler($this->_parser, 'cdata'); - - } // create_parser - - /** - * start_element - * This is part of our internal XML parser - */ - function start_element($parser, $tag, $attributes) { - - // If it's our 'parent' object tag then bump the key - if ($tag == $this->_containerTag) { - $this->_key++; - // If we find attributes - if (count($attributes)) { - // If it's not already an array, make it one so merge always works - if (!isset($this->results[$this->_key][__attributes])) { - $this->results[$this->_key][__attributes] = array(); - } - $this->results[$this->_key][__attributes] = array_merge($this->results[$this->_key][__attributes],$attributes); - } // end if there are attributes - } - elseif ($this->_key >= '0') { - $this->_currentTag = $tag; - } // if key is at least 0 - - } // start_element - - function cdata($parser, $cdata) { - - $tag = $this->_currentTag; - - if (strlen($tag) AND $this->_key >= 0) { - $this->results[$this->_key][$tag] .= trim($cdata); - } - - - } // cdata - - function end_element($parser, $tag) { - - /* Zero the tag */ - $this->_currentTag = ''; - - } // end_element - -} // end openstrands - -?> diff --git a/modules/plugins/OpenStrands.plugin.php b/modules/plugins/OpenStrands.plugin.php deleted file mode 100644 index d63e9616..00000000 --- a/modules/plugins/OpenStrands.plugin.php +++ /dev/null @@ -1,66 +0,0 @@ - diff --git a/server/stats.ajax.php b/server/stats.ajax.php index c4c73d03..24af4878 100644 --- a/server/stats.ajax.php +++ b/server/stats.ajax.php @@ -1,7 +1,7 @@ _('Name'),'links'=>_('Links')); - break; - case 'album': - case 'track': - // We're good - default: - $results['rtc3514'] = '0x1'; - break 2; - } - - // Get the recommendations - $objects = metadata::recommend_similar($_REQUEST['type'],$_REQUEST['id'],'7'); - - ob_start(); - show_box_top(_('Recommendations')); - require_once Config::get('prefix') . '/templates/show_objects.inc.php'; - show_box_bottom(); - $results['additional_information'] = ob_get_contents(); - ob_end_clean(); - break; - case 'show_check_album_tracks': - ob_start(); - show_box_top(_('Find Missing Tracks')); - echo "Loading..."; - $ajax_action = Ajax::action('?page=stats&action=check_album_tracks&id=' . $_REQUEST['id'],'show_album_tracks_refresh'); Ajax::run($ajax_action); - show_box_bottom(); - $results['additional_information'] = ob_get_contents(); - ob_end_clean(); - break; - case 'check_album_tracks': - - // Set the headers - $headers = array('title'=>_('Title'),'track'=>_('Track'),'artist'=>_('Artist'),'links'=>_('Links')); - - // Ask the great and wise metadata - $objects = metadata::find_missing_tracks($_REQUEST['id']); - - if ($error = ob_get_contents()) { - ob_end_clean(); - ob_start(); - show_box_top(_('Find Missing Tracks')); - echo $error; - show_box_bottom(); - $results['additional_information'] = ob_get_contents(); - ob_end_clean(); - break; - } - ob_start(); - show_box_top(_('Find Missing Tracks')); - require_once Config::get('prefix') . '/templates/show_objects.inc.php'; - show_box_bottom(); - $results['additional_information'] = ob_get_contents(); - ob_end_clean(); - break; default: $results['rfc3514'] = '0x1'; break; diff --git a/server/xml.server.php b/server/xml.server.php index af00ec85..2f4df872 100644 --- a/server/xml.server.php +++ b/server/xml.server.php @@ -72,7 +72,7 @@ if ($_REQUEST['action'] != 'handshake') { switch ($_REQUEST['action']) { case 'handshake': // Send the data we were sent to the API class so it can be chewed on - $token = Api::handshake($_REQUEST['timestamp'],$_REQUEST['auth'],$_SERVER['REMOTE_ADDR'],$_REQUEST['user']); + $token = Api::handshake($_REQUEST['timestamp'],$_REQUEST['auth'],$_SERVER['REMOTE_ADDR'],$_REQUEST['user'],$_REQUEST['version']); if (!$token) { ob_end_clean(); diff --git a/templates/show_artist.inc.php b/templates/show_artist.inc.php index 37b9ad40..a2df6045 100644 --- a/templates/show_artist.inc.php +++ b/templates/show_artist.inc.php @@ -31,11 +31,25 @@ if (Config::get('ratings')) {