From 67cbb218cd89ac6be9d1d55ca3799080daac1f5a Mon Sep 17 00:00:00 2001 From: Karl 'vollmerk' Vollmer Date: Thu, 22 Nov 2007 17:44:10 +0000 Subject: renamed xml-rpc acl to rpc, added default mime type of image/jpg and added config options for batch download to the fs, no garbage collection for non-completed downloads yet. --- lib/class/access.class.php | 13 +++++++---- lib/class/album.class.php | 3 +++ lib/class/api.class.php | 10 ++++++++- lib/class/xmldata.class.php | 53 ++++++++++++++++++++++++++++++++++++++++----- 4 files changed, 68 insertions(+), 11 deletions(-) (limited to 'lib/class') diff --git a/lib/class/access.class.php b/lib/class/access.class.php index c9e41512..59289c7c 100644 --- a/lib/class/access.class.php +++ b/lib/class/access.class.php @@ -183,10 +183,11 @@ class Access { $sql = "SELECT `id` FROM `access_list`" . " WHERE `start` <= '$ip' AND `end` >= '$ip' AND `type`='xml-rpc' AND `level` >= '$level'"; break; + case 'rpc': case 'xml-rpc': $sql = "SELECT `id` FROM `access_list`" . " WHERE `start` <= '$ip' AND `end` >= '$ip'" . - " AND `key` = '$key' AND `level` >= '$level' AND `type`='xml-rpc'"; + " AND `key` = '$key' AND `level` >= '$level' AND (`type`='xml-rpc' OR `type`='rpc')"; break; case 'network': case 'interface': @@ -221,11 +222,14 @@ class Access { public static function validate_type($type) { switch($type) { - case 'xml-rpc': + case 'rpc': case 'interface': case 'network': return $type; break; + case 'xml-rpc': + return 'rpc'; + break; default: return 'stream'; break; @@ -297,8 +301,9 @@ class Access { public function get_type_name() { switch ($this->type) { - case 'xml-rpc': - return 'XML-RPC'; + case 'xml-rpc': + case 'rpc': + return 'RPC'; break; case 'network': return 'Local Network Definition'; diff --git a/lib/class/album.class.php b/lib/class/album.class.php index 601b1f9b..bbacf852 100644 --- a/lib/class/album.class.php +++ b/lib/class/album.class.php @@ -751,6 +751,9 @@ class Album { } } // if we have PHP:GD + // Default to image/jpg as a guess if there is no passed mime type + $mime = $mime ? $mime : 'image/jpg'; + // Push the image into the database $sql = "REPLACE INTO `album_data` SET `art` = '" . Dba::escape($image) . "'," . " `art_mime` = '" . Dba::escape($mime) . "'" . diff --git a/lib/class/api.class.php b/lib/class/api.class.php index 1ebc86e8..592ae953 100644 --- a/lib/class/api.class.php +++ b/lib/class/api.class.php @@ -26,6 +26,8 @@ */ class Api { + public static $version = '340001'; + /** * constructor * This really isn't anything to do here, so it's private @@ -45,6 +47,11 @@ class Api { */ public static function handshake($timestamp,$passphrase,$ip,$username='') { + // If the timestamp is over 2hr old sucks to be them +// if ($timestamp < (time() - 7200)) { +// return 'Timestamp too old, try again'; +// } + // First we'll filter by username and IP if (!$username) { $user_id = '-1'; @@ -76,7 +83,8 @@ class Api { // Create the Session, in this class for now needs to be moved $token = self::create_session($row['level'],$ip,$user_id); debug_event('API','Login Success, passphrase matched','1'); - return $token; + + return array('auth'=>$token,'api'=>self::$version); } // match } // end while diff --git a/lib/class/xmldata.class.php b/lib/class/xmldata.class.php index c9d49a3f..ac776635 100644 --- a/lib/class/xmldata.class.php +++ b/lib/class/xmldata.class.php @@ -27,10 +27,9 @@ */ class xmlData { - public static $version = '340001'; - // This is added so that we don't pop any webservers public static $limit = '5000'; + private static $offset = '0'; /** * constructor @@ -42,6 +41,17 @@ class xmlData { } // constructor + /** + * set_offset + * This takes an int and changes the offset + */ + public static function set_offset($offset) { + + $offset = intval($offset); + self::$offset = $offset; + + } // set_offset + /** * error * This generates a standard XML Error message @@ -66,6 +76,35 @@ class xmlData { } // single_string + /** + * keyed_array + * This will build an xml document from a key'd array, + */ + public static function keyed_array($array,$callback='') { + + $string = ''; + + // Foreach it + foreach ($array as $key=>$value) { + // If it's an array, run again + if (is_array($value)) { + $value = self::keyed_array($value,1); + $string .= "\t<$key>$value\n"; + } + else { + $string .= "\t<$key>\n"; + } + + } // end foreach + + if (!$callback) { + $string = self::_header() . $string . self::_footer(); + } + + return $string; + + } // keyed_array + /** * artists * This takes an array of artists and then returns a pretty xml document with the information @@ -74,9 +113,11 @@ class xmlData { public static function artists($artists) { if (count($artists) > self::$limit) { - $artists = array_splice($artists,0,self::$limit); + $artists = array_splice($artists,self::$offset,self::$limit); } + $string = ''; + foreach ($artists as $artist_id) { $artist = new Artist($artist_id); $artist->format(); @@ -98,7 +139,7 @@ class xmlData { public static function albums($albums) { if (count($albums) > self::$limit) { - $albums = array_splice($albums,0,self::$limit); + $albums = array_splice($albums,self::$offset,self::$limit); } foreach ($albums as $album_id) { @@ -139,7 +180,7 @@ class xmlData { public static function genres($genres) { if (count($genres) > self::$limit) { - $genres = array_slice($genres,0,self::$limit); + $genres = array_slice($genres,self::$offset,self::$limit); } // Foreach the ids @@ -172,7 +213,7 @@ class xmlData { public static function songs($songs) { if (count($songs) > self::$limit) { - $songs = array_slice($songs,0,self::$limit); + $songs = array_slice($songs,self::$offset,self::$limit); } // Foreach the ids! -- cgit