diff options
Diffstat (limited to 'lib/class')
-rw-r--r-- | lib/class/access.class.php | 3 | ||||
-rw-r--r-- | lib/class/api.class.php | 14 | ||||
-rw-r--r-- | lib/class/database_object.abstract.php | 6 | ||||
-rw-r--r-- | lib/class/metadata.class.php | 149 | ||||
-rw-r--r-- | lib/class/rating.class.php | 13 | ||||
-rw-r--r-- | lib/class/stream.class.php | 17 | ||||
-rw-r--r-- | lib/class/vauth.class.php | 2 | ||||
-rw-r--r-- | lib/class/xmlrpcserver.class.php | 5 |
8 files changed, 36 insertions, 173 deletions
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 @@ -<?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. - -*/ - -/** - * metadata class - * This class is a abstraction layer for getting - * meta data for any object in Ampache, this includes - * album art, lyrics, id3tags, recommendations etc - * it makes use of Object::construct_from_array() as needed - */ -class metadata { - - /** - * constructor - * We don't use this, as its really a static class - */ - private function __construct() { - - // Rien a faire - - } // constructor - - /** - * recommend_similar - * This takes the input and returns an array of objects construct_from_array()'d - */ - public static function recommend_similar($type,$id,$limit='') { - - // 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')); - - // Make sure auth worked - if (!$openstrands) { return false; } - - switch ($type) { - case 'artist': - $artist = new Artist($id); - $seed = array('name'=>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'] = "<a target=\"_blank\" href=\"" . $item['URI'] . "\">" . get_user_icon('world_link','MyStrands Link') . "</a>"; - - // 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'] .= "<a href=\"$artist->f_link\">" . get_user_icon('ampache','Ampache') . "</a>"; - } - - $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'] = "<a target=\"_blank\" href=\"" . $track['URI'] . "\">" . get_user_icon('world_link','MyStrands') . "</a>"; - // If we've got a purchase URL - if ($track['UserPurchaseURI']) { - $data['links'] .= "<a target=\"_blank\" href=\"" . $track['UserPurchaseURI'] . "\">" . get_user_icon('money',_('Buy Track from MyStrands')) . "</a>"; - } - $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'); } |