summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorKarl 'vollmerk' Vollmer <vollmer@ampache.org>2007-11-20 06:23:05 +0000
committerKarl 'vollmerk' Vollmer <vollmer@ampache.org>2007-11-20 06:23:05 +0000
commit5869da3fe58876644364941fa7216caee09adbf5 (patch)
tree66d981851a8e3d024ccd662c26cdad6612f7e6b0 /lib
parentc1829308f4207eda5fbfff668ad0fcd6e1f16143 (diff)
downloadampache-5869da3fe58876644364941fa7216caee09adbf5.tar.gz
ampache-5869da3fe58876644364941fa7216caee09adbf5.tar.bz2
ampache-5869da3fe58876644364941fa7216caee09adbf5.zip
little more work on the xml api, artists and albums now works
Diffstat (limited to 'lib')
-rw-r--r--lib/class/access.class.php2
-rw-r--r--lib/class/album.class.php7
-rw-r--r--lib/class/api.class.php10
-rw-r--r--lib/class/xmldata.class.php64
4 files changed, 71 insertions, 12 deletions
diff --git a/lib/class/access.class.php b/lib/class/access.class.php
index f0b4fbbe..c9e41512 100644
--- a/lib/class/access.class.php
+++ b/lib/class/access.class.php
@@ -333,7 +333,7 @@ class Access {
if (Dba::num_rows($db_results)) {
$time = $time + 3600;
$sql = "UPDATE `session_api` WHERE `id`='$key' SET `expire`='$time'";
- $db_results($db_results);
+ $db_results = Dba::query($sql);
return true;
}
diff --git a/lib/class/album.class.php b/lib/class/album.class.php
index cd54eccd..601b1f9b 100644
--- a/lib/class/album.class.php
+++ b/lib/class/album.class.php
@@ -209,15 +209,14 @@ class Album {
foreach ($data as $key=>$value) { $this->$key = $value; }
/* Truncate the string if it's to long */
- $this->f_name = truncate_with_ellipsis($this->name,Config::get('ellipsis_threshold_album'));
+ $this->f_name = truncate_with_ellipsis($this->name,Config::get('ellipsis_threshold_album'));
- //
- $this->f_name_link = "<a href=\"$web_path/albums.php?action=show&amp;album=" . scrub_out($this->id) . "\" title=\"" . scrub_out($this->name) . "\">" . $this->f_name;
+ $this->f_name_link = "<a href=\"$web_path/albums.php?action=show&amp;album=" . scrub_out($this->id) . "\" title=\"" . scrub_out($this->name) . "\">" . $this->f_name;
// If we've got a disk append it
if ($this->disk) {
$this->f_name_link .= " <span class=\"discnb disc" .$this->disk. "\">[" . _('Disk') . " " . $this->disk . "]</span>";
}
- $this->f_name_link .="</a>";
+ $this->f_name_link .="</a>";
$this->f_link = $this->f_name_link;
$this->f_title = $name;
diff --git a/lib/class/api.class.php b/lib/class/api.class.php
index 861b9b8d..29bc0bff 100644
--- a/lib/class/api.class.php
+++ b/lib/class/api.class.php
@@ -43,7 +43,7 @@ class Api {
* can take a username, if non is passed the ACL must be non-use
* specific
*/
- public static function handshake($timesamp,$passphrase,$ip,$username='') {
+ public static function handshake($timestamp,$passphrase,$ip,$username='') {
// First we'll filter by username and IP
if (!$username) {
@@ -56,18 +56,18 @@ class Api {
// Clean incomming variables
$user_id = Dba::escape($user_id);
- $timestampe = intval($timestamp);
+ $timestamp = intval($timestamp);
$ip = ip2int($ip);
// Run the query and return the passphrases as we'll have to mangle them
// to figure out if they match what we've got
- $sql = "SELECT * FROM `access_list` WHERE `user`='$user_id' AND `start` >= '$ip' AND `end` <= '$ip'";
+ $sql = "SELECT * FROM `access_list` WHERE `user`='$user_id' AND `start` <= '$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);
+ $md5pass = md5($timestamp . $row['key']);
if ($md5pass === $passphrase) {
// Create the Session, in this class for now needs to be moved
@@ -96,7 +96,7 @@ class Api {
"VALUES ('$token','$user_id','$agent','$level','$expire','$ip')";
$db_results = Dba::query($sql);
- if (Dba::affected_rows($db_results)) {
+ if ($db_results) {
return $token;
}
diff --git a/lib/class/xmldata.class.php b/lib/class/xmldata.class.php
index de71fbc8..655a65f3 100644
--- a/lib/class/xmldata.class.php
+++ b/lib/class/xmldata.class.php
@@ -29,6 +29,9 @@ class xmlData {
public static $version = '340001';
+ // This is added so that we don't pop any webservers
+ public static $limit = '5000';
+
/**
* constructor
* We don't use this, as its really a static class
@@ -52,18 +55,34 @@ class xmlData {
} // error
/**
+ * single_string
+ * This takes two values, first the key second the string
+ */
+ public static function single_string($key,$string) {
+
+ $final = self::_header() . "\t<$key><![CDATA[$string]]></$key>" . self::_footer();
+
+ return $final;
+
+ } // single_string
+
+ /**
* artists
* This takes an array of artists and then returns a pretty xml document with the information
* we want
*/
public static function artists($artists) {
+ if (count($artists) > self::$limit) {
+ $artists = array_splice($artists,0,self::$limit);
+ }
+
foreach ($artists as $artist_id) {
$artist = new Artist($artist_id);
$artist->format();
- $string .= "<artist id="$artist->id">\n" .
- "\t<name>$artist->f_full_name</name>\n";
+ $string .= "<artist id=\"$artist->id\">\n" .
+ "\t<name><![CDATA[$artist->f_full_name]]></name>\n" .
"</artist>\n";
} // end foreach artists
@@ -73,6 +92,47 @@ class xmlData {
} // artists
/**
+ * albums
+ * This echos out a standard albums XML document, it pays attention to the limit
+ */
+ public static function albums($albums) {
+
+ if (count($albums) > self::$limit) {
+ $albums = array_splice($albums,0,self::$limit);
+ }
+
+ foreach ($albums as $album_id) {
+ $album = new Album($album_id);
+ $album->format();
+
+ // Build the Art URL
+ $art_url = Config::get('web_path') . '/image.php?id=' . $album->id;
+
+ $string .= "<album id=\"$album->id\">\n" .
+ "\t<name><![CDATA[$album->name]]></name>\n";
+
+ // Do a little check for artist stuff
+ if ($album->artist_count != 1) {
+ $string .= "\t<artist id=\"0\"><![CDATA[Various]]></artist>\n";
+ }
+ else {
+ $string .= "\t<artist id=\"$album->artist_id\"><![CDATA[$album->artist_name]]></artist>\n";
+ }
+
+ $string .= "\t<year>$album->year</year>\n" .
+ "\t<tracks>$album->song_count</tracks>\n" .
+ "\t<disk>$album->disk</disk>\n" .
+ "\t<art>$art_url</art>\n" .
+ "</album>\n";
+ } // end foreach
+
+ $final = self::_header() . $string . self::_footer();
+
+ return $final;
+
+ } // albums
+
+ /**
* _header
* this returns a standard header, there are a few types
* so we allow them to pass a type if they want to