" . self::_footer(); return $string; } // 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>" . self::_footer(); return $final; } // 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 * we want */ public static function artists($artists) { if (count($artists) > self::$limit) { $artists = array_splice($artists,self::$offset,self::$limit); } $string = ''; foreach ($artists as $artist_id) { $artist = new Artist($artist_id); $artist->format(); $string .= "id\">\n" . "\tf_full_name]]>\n" . "\n"; } // end foreach artists $final = self::_header() . $string . self::_footer(); return $final; } // 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,self::$offset,self::$limit); } foreach ($albums as $album_id) { $album = new Album($album_id); $album->format(); // Build the Art URL, include session $art_url = Config::get('web_path') . '/image.php?id=' . $album->id . '&auth=' . scrub_out($_REQUEST['auth']); $string .= "id\">\n" . "\tname]]>\n"; // Do a little check for artist stuff if ($album->artist_count != 1) { $string .= "\t\n"; } else { $string .= "\tartist_id\">artist_name]]>\n"; } $string .= "\t$album->year\n" . "\t$album->song_count\n" . "\t$album->disk\n" . "\t\n" . "\n"; } // end foreach $final = self::_header() . $string . self::_footer(); return $final; } // albums /** * genres * This takes an array of genre ids and returns a nice little pretty xml doc */ public static function genres($genres) { if (count($genres) > self::$limit) { $genres = array_slice($genres,self::$offset,self::$limit); } // Foreach the ids foreach ($genres as $genre_id) { $genre = new Genre($genre_id); $genre->format(); $song_count = $genre->get_song_count(); $album_count = $genre->get_album_count(); $artist_count = $genre->get_artist_count(); $string .= "id\">\n" . "\tname]]>\n" . "\t$song_count\n" . "\t$album_count\n" . "\t$artist_count\n" . "\n"; } // end foreach $final = self::_header() . $string . self::_footer(); return $final; } // genres /** * playlists * This takes an array of playlist ids and then returns a nice pretty XML document */ public static function playlists($playlists) { if (count($playlists) > self::$limit) { $playlists = array_slice($playlists,self::$offset,self::$limit); } $string = ''; // Foreach the playlist ids foreach ($playlists as $playlist_id) { $playlist = new Playlist($playlist_id); $playlist->format(); $item_total = $playlist->get_song_count(); // Build this element $string .= "id\">\n" . "\tname]]>\n" . "\tf_user]]\n" . "\t$item_total\n" . "\t$playlist->type\n" . "\n"; } // end foreach // Build the final and then send her off $final = self::_header() . $string . self::_footer(); return $final; } // playlists /** * songs * This returns an xml document from an array of song ids spiffy isn't it! */ public static function songs($songs) { if (count($songs) > self::$limit) { $songs = array_slice($songs,self::$offset,self::$limit); } // Foreach the ids! foreach ($songs as $song_id) { $song = new Song($song_id); $song->format(); $string .= "id\">\n" . "\t<![CDATA[$song->title]]>\n" . "\tartist\">f_artist_full]]>\n" . "\talbum\">f_album_full]]>\n" . "\tgenre\">genre]]>\n" . "\t$song->track\n" . "\t\n" . "\tget_url($_REQUEST['auth']) . "]]>\n" . "\n"; } // end foreach $final = self::_header() . $string . self::_footer(); return $final; } // songs /** * _header * this returns a standard header, there are a few types * so we allow them to pass a type if they want to */ private static function _header($type='') { switch ($type) { case 'xspf': break; case 'itunes': break; default: $header = "\n\n"; break; } // end switch return $header; } // _header /** * _footer * this returns the footer for this document, these are pretty boring */ private static function _footer($type='') { switch ($type) { default: $footer = "\n\n"; break; } // end switch on type return $footer; } // _footer } // xmlData ?>