174
* This returns tags to the user, in a pretty xml document with the information
176
public static function tags($tags) {
178
if (count($tags) > self::$limit) {
179
$tags = array_splice($tags,self::$offset,self::$limit);
184
foreach ($tags as $tag_id) {
185
$tag = new Tag($tag_id);
186
$counts = $tag->count();
187
$string .= "<tag id=\"$tag_id\">\n" .
188
"\t<name><![CDATA[$tag->name]]></name>\n" .
189
"\t<albums>" . intval($counts['album']) . "</albums>\n" .
190
"\t<artists>" . intval($counts['artist']) . "</artists>\n" .
191
"\t<songs>" . intval($counts['songs']) . "</songs>\n" .
192
"\t<videos>" . intval($counts['video']) . "</videos>\n" .
193
"\t<playlists>" . intval($count['playlist']) . "</playlists>\n" .
194
"\t<stream>" . intval($count['live_stream']) . "</stream>\n" .
198
$final = self::_header() . $string . self::_footer();
124
206
* This takes an array of artists and then returns a pretty xml document with the information
195
* This takes an array of genre ids and returns a nice little pretty xml doc
197
public static function genres($genres) {
199
if (count($genres) > self::$limit) {
200
$genres = array_slice($genres,self::$offset,self::$limit);
204
foreach ($genres as $genre_id) {
205
$genre = new Genre($genre_id);
207
$song_count = $genre->get_song_count();
208
$album_count = $genre->get_album_count();
209
$artist_count = $genre->get_artist_count();
211
$string .= "<genre id=\"$genre->id\">\n" .
212
"\t<name><![CDATA[$genre->name]]></name>\n" .
213
"\t<songs>$song_count</songs>\n" .
214
"\t<albums>$album_count</albums>\n" .
215
"\t<artists>$artist_count</artists>\n" .
220
$final = self::_header() . $string . self::_footer();
228
292
* This takes an array of playlist ids and then returns a nice pretty XML document
269
333
$songs = array_slice($songs,self::$offset,self::$limit);
336
Rating::build_cache('song',$songs);
337
Stream::set_session($_REQUEST['auth']);
272
339
// Foreach the ids!
273
340
foreach ($songs as $song_id) {
274
341
$song = new Song($song_id);
277
$art_url = Config::get('web_path') . '/image.php?id=' . $song->album . '&auth=' . scrub_out($_REQUEST['auth']);
346
$tag = new Tag($song->tags['0']);
347
$song->genre = $tag->id;
348
$song->f_genre = $tag->name;
350
$tag_string = self::tags_string($song->tags,'song',$song->id);
352
$rating = new Rating($song_id,'song');
354
$art_url = Album::get_art_url($song->album,$_REQUEST['auth']);
279
356
$string .= "<song id=\"$song->id\">\n" .
280
357
"\t<title><![CDATA[$song->title]]></title>\n" .
281
358
"\t<artist id=\"$song->artist\"><![CDATA[$song->f_artist_full]]></artist>\n" .
282
359
"\t<album id=\"$song->album\"><![CDATA[$song->f_album_full]]></album>\n" .
283
"\t<genre id=\"$song->genre\"><![CDATA[$song->genre]]></genre>\n" .
360
"\t<genre id=\"$song->genre\"><![CDATA[$song->f_genre]]></genre>\n" .
284
362
"\t<track>$song->track</track>\n" .
285
363
"\t<time>$song->time</time>\n" .
286
"\t<url><![CDATA[" . $song->get_url($_REQUEST['auth']) . "]]></url>\n" .
364
"\t<mime>$song->mime</mime>\n" .
365
"\t<url><![CDATA[" . Song::play_url($song->id) . "]]></url>\n" .
287
366
"\t<size>$song->size</size>\n" .
288
367
"\t<art><![CDATA[" . $art_url . "]]></art>\n" .
368
"\t<preciserating>" . $rating->preciserating . "</preciserating>\n" .
369
"\t<rating>" . $rating->rating . "</rating>\n" .
382
* This builds the xml document for displaying video objects
384
public static function videos($videos) {
386
if (count($videos) > self::$limit) {
387
$videos = array_slice($videos,self::$offset,self::$limit);
392
foreach ($videos as $video_id) {
393
$video = new Video($video_id);
396
$string .= "<video id=\"$video->id\">\n" .
397
"\t<title><![CDATA[$video->title]]></title>\n" .
398
"\t<mime><![CDATA[$video->mime]]></mime>\n" .
399
"\t<resolution>$video->f_resolution</resolution>\n" .
400
"\t<size>$video->size</size>\n" .
401
self::tags_string($video->tags,'video',$video->id) .
402
"\t<url><![CDATA[" . Video::play_url($video->id) . "]]></url>\n" .
407
$final = self::_header() . $string . self::_footer();
416
* This handles creating an xml document for democratic items, this can be a little complicated
417
* due to the votes and all of that
419
public static function democratic($object_ids=array()) {
421
if (!is_array($object_ids)) { $object_ids = array(); }
425
foreach ($object_ids as $row_id=>$data) {
426
$song = new $data['object_type']($data['object_id']);
429
//FIXME: This is duplicate code and so wrong, functions need to be improved
432
$tag = new Tag($song->tags['0']);
433
$song->genre = $tag->id;
434
$song->f_genre = $tag->name;
436
$tag_string = self::tags_string($song->tags,'song',$song->id);
438
$rating = new Rating($song_id,'song');
440
$art_url = Album::get_art_url($song->album,$_REQUEST['auth']);
442
$string .= "<song id=\"$song->id\">\n" .
443
"\t<title><![CDATA[$song->title]]></title>\n" .
444
"\t<artist id=\"$song->artist\"><![CDATA[$song->f_artist_full]]></artist>\n" .
445
"\t<album id=\"$song->album\"><![CDATA[$song->f_album_full]]></album>\n" .
446
"\t<genre id=\"$song->genre\"><![CDATA[$song->f_genre]]></genre>\n" .
448
"\t<track>$song->track</track>\n" .
449
"\t<time>$song->time</time>\n" .
450
"\t<mime>$song->mime</mime>\n" .
451
"\t<url><![CDATA[" . Song::play_url($song->id) . "]]></url>\n" .
452
"\t<size>$song->size</size>\n" .
453
"\t<art><![CDATA[" . $art_url . "]]></art>\n" .
454
"\t<preciserating>" . $rating->preciserating . "</preciserating>\n" .
455
"\t<rating>" . $rating->rating . "</rating>\n" .
456
"\t<vote>" . $democratic->get_vote($row_id) . "</vote>\n" .
461
$final = self::_header() . $string . self::_footer();
470
public static function rss_feed($data,$title,$description,$date) {
472
$string = "\t<title>$title</title>\n\t<link>" . Config::get('web_path') . "</link>\n\t" .
473
"<pubDate>" . date("r",$date) . "</pubDate>\n";
475
// Pass it to the keyed array xml function
476
foreach ($data as $item) {
477
// We need to enclose it in an item tag
478
$string .= self::keyed_array(array('item'=>$item),1);
481
$final = self::_header() . $string . self::_footer();
301
489
* this returns a standard header, there are a few types
302
490
* so we allow them to pass a type if they want to
304
private static function _header($type='') {
492
private static function _header() {
494
switch (self::$type) {
496
$header = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n" .
497
"<playlist version = \"1\" xmlns=\"http://xspf.org/ns/0/\">\n " .
498
"<title>Ampache XSPF Playlist</title>\n" .
499
"<creator>" . scrub_out(Config::get('site_title')) . "</creator>\n" .
500
"<annotation>" . scrub_out(Config::get('site_title')) . "</annotation>\n" .
501
"<info>". Config::get('web_path') ."</info>\n" .
505
$header = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" .
506
"<!-- XML Generated by Ampache v." . Config::get('version') . " -->\n";
507
"<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\"\n" .
508
"\"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n" .
509
"<plist version=\"1.0\">\n" .
511
" <key>Major Version</key><integer>1</integer>\n" .
512
" <key>Minor Version</key><integer>1</integer>\n" .
513
" <key>Application Version</key><string>7.0.2</string>\n" .
514
" <key>Features</key><integer>1</integer>\n" .
515
" <key>Show Content Ratings</key><true/>\n" .
516
" <key>Tracks</key>\n" .
520
$header = "<?xml version=\"1.0\" encoding=\"" . Config::get('site_charset') . "\" ?>\n " .
521
"<!-- RSS Generated by Ampache v." . Config::get('version') . " on " . date("r",time()) . "-->\n" .
522
"<rss version=\"2.0\">\n<channel>\n";
314
$header = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n<root>\n";
525
$header = "<?xml version=\"1.0\" encoding=\"" . Config::get('site_charset') . "\" ?>\n<root>\n";