From f4d94f034e6ca26d37244028d8ccb08ddbab0e8c Mon Sep 17 00:00:00 2001 From: Karl 'vollmerk' Vollmer Date: Mon, 19 Nov 2007 07:40:48 +0000 Subject: some inital work on an api for amarok, tweaked stream class a bit, think theres still a bug with some playlist methods, also need to confirm problem with IE --- lib/class/access.class.php | 27 ++++++++++++ lib/class/api.class.php | 68 +++++++++++++++++++++++++++++ lib/class/update.class.php | 29 +++++++++++++ lib/class/xmldata.class.php | 44 +++++++++++++++++++ server/stream.ajax.php | 2 +- server/xml.server.php | 103 +++++--------------------------------------- 6 files changed, 179 insertions(+), 94 deletions(-) create mode 100644 lib/class/api.class.php create mode 100644 lib/class/xmldata.class.php diff --git a/lib/class/access.class.php b/lib/class/access.class.php index e814ade6..379ee626 100644 --- a/lib/class/access.class.php +++ b/lib/class/access.class.php @@ -314,6 +314,33 @@ class Access { } // get_type_name + /** + * session_exists + * This checks to see if the specified session of the specified type + * exists, it also provides an array of key'd data that may be required + * based on the type + */ + public static function session_exists($data,$key,$type) { + + // Switch on the type they pass + switch ($type) { + case 'api': + + break; + case 'stream': + + break; + case 'interface': + + break; + default: + return false; + break; + } // type + + + } // session_exists + } //end of access class ?> diff --git a/lib/class/api.class.php b/lib/class/api.class.php new file mode 100644 index 00000000..fd34ff93 --- /dev/null +++ b/lib/class/api.class.php @@ -0,0 +1,68 @@ += '$ip' AND `end` <= '$ip'"; + $db_results = Dba::query($sql); + + while ($row = Dba::fetch_assoc($db_results)) { + + // Combine and MD5 this mofo + $md5pass = md5($timestamp . $row); + + } // end while + + } // handhsake + +} // API class +?> diff --git a/lib/class/update.class.php b/lib/class/update.class.php index e7b3a03c..2db1a0e2 100644 --- a/lib/class/update.class.php +++ b/lib/class/update.class.php @@ -238,6 +238,12 @@ class Update { '- Change wording on Localplay preferences.
'; $version[] = array('version' => '340010','description'=>$update_string); + $update_string = '- Adjusted Tables to new democratic play methods.
' . + '- Added api session table, will eventually recombine.
'; + + //$version[] = array('version' => '340011','description'=>$update_string); + + return $version; } // populate_version @@ -979,5 +985,28 @@ class Update { } // update_340010 + /** + * update_340011 + * This updates the democratic play stuff so that can handle a little more complext mojo + * It also adds yet another table to the db to handle the sessions for API access. Eventually + * should combine all of the session tables, but I'll do that later + */ + public static function update_340011() { + + // First add the new table for the new session stuff + $sql = "CREATE TABLE `session_api` ( " . + "`id` VARCHAR( 64 ) NOT NULL , " . + "`user` INT( 11 ) UNSIGNED NOT NULL , " . + "`agent` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL , " . + "`level` INT( 11 ) UNSIGNED NOT NULL DEFAULT '0', " . + "`expire` INT( 11 ) UNSIGNED NOT NULL , " . + "`ip` INT( 11 ) UNSIGNED NULL , " . + "PRIMARY KEY ( `id` ) " . + ") ENGINE = MYISAM"; + $db_results = Dba::query($sql); + + + } // 340011 + } // end update class ?> diff --git a/lib/class/xmldata.class.php b/lib/class/xmldata.class.php new file mode 100644 index 00000000..16eaeaeb --- /dev/null +++ b/lib/class/xmldata.class.php @@ -0,0 +1,44 @@ + diff --git a/server/stream.ajax.php b/server/stream.ajax.php index 7996b676..c3f58ac4 100644 --- a/server/stream.ajax.php +++ b/server/stream.ajax.php @@ -37,7 +37,7 @@ switch ($_REQUEST['action']) { break; case 'basket': // We need to set the basket up! - $_SESSION['iframe']['target'] = Config::get('web_path') . '/stream.php?action=basket'; + $_SESSION['iframe']['target'] = Config::get('web_path') . '/stream.php?action=basket&playlist_method=' . scrub_out($_REQUEST['playlist_method']); $results['rfc3514'] = ''; break; default: diff --git a/server/xml.server.php b/server/xml.server.php index b42b8ea4..484c874c 100644 --- a/server/xml.server.php +++ b/server/xml.server.php @@ -1,7 +1,7 @@ format_artist(); - $results[] = array('id'=>$artist->id,'name'=>$artist->full_name); - } // end while results - - $xml_doc = xml_from_array($results); - echo $xml_doc; - break; - case 'get_albums': - $sql = "SELECT id FROM album ORDER BY name"; - $db_results = mysql_query($sql,dbh()); - - while ($r = mysql_fetch_assoc($db_results)) { - $album = new Album($r['id']); - $results[] = array('id'=>$r['id'],'year'=>$album->year,'name'=>$album->name); - } // end while results - - $xml_doc = xml_from_array($results); - echo $xml_doc; - break; - case 'get_genres': - $sql = "SELECT id FROM genre ORDER BY name"; - $db_results = mysql_query($sql,dbh()); - - while ($r = mysql_fetch_assoc($db_results)) { - $genre = new Genre($r['id']); - $results[] = array('id'=>$r['id'],'name'=>$genre->name); - } - - $xml_doc = xml_from_array($results); - echo $xml_doc; - break; - /* Return results of a quick search */ - case 'search': - /* We need search string */ - $_REQUEST['s_all'] = $_REQUEST['search_string']; - if (strlen($_REQUEST['s_all']) < 1) { break; } - $data = run_search($_REQUEST); - /* Unfortuantly these are song objects, which are not good for - * xml.. turn it into an array - */ - foreach ($data as $song) { - $genre = $song->get_genre_name(); - $artist = $song->get_artist_name(); - $album = $song->get_album_name(); - $results[] = array('id'=>$song->id, - 'title'=>$song->title, - 'genre'=>$genre, - 'artist'=>$artist, - 'album'=>$album); - } // end foreach song +switch ($_REQUEST['action']) { + case 'handshake': - $xml_doc = xml_from_array($results); - echo $xml_doc; + // Send the data we were sent to the API class so it can be chewed on - break; - /* This takes a object_id/object_type and returns the correct PLAY url for it */ - case 'play_url': - /* We need the type and id */ - $object_type = scrub_in($_REQUEST['object_type']); - $object_id = scrub_in($_REQUEST['object_id']); - - switch ($object_type) { - case 'song': - $song = new Song($object_id); - $url = $song->get_url($_REQUEST['sessid']); - $results[] = $url; - break; - default: - // Rien a faire - break; - } // end switch on object_type - - $xml_doc = xml_from_array($results); - echo $xml_doc; - - break; - /* This allows you to login via the xml mojo */ - case 'login': - - - break; + break; default: // Rien a faire break; -- cgit