~ubuntu-branches/ubuntu/lucid/ampache/lucid

« back to all changes in this revision

Viewing changes to lib/class/xmldata.class.php

  • Committer: Bazaar Package Importer
  • Author(s): Charlie Smotherman
  • Date: 2009-07-07 07:23:35 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20090707072335-soq0jyo59mgopzd2
Tags: 3.5.1-0ubuntu1
 * New upstream release.  Summary of new features:  (LP: #377016)
   - Make the PHP error a little clearer for windows users by indicating
     that their version of PHP is < 5.3 (required for windows)
   - Fix random methods not working for Localplay
   - Fix extra space on prefixed albums (Thx ibizaman)
   - Add missing operator on tag and rating searches so they will
     work with other methods (Thx kiehnet@netscape.net)
   - Fix get_art_url() so it returns something... 
   - Fix problem with creating new playlists where it doesn't work
     but appending to an existing did. 
   - Fixed issue with url_to_song, also cleaned up the code a bit
   - Fixed issue with Random All Catalogs
   - Fixed issues with API and Tag methods not working as advertised
   - Fix endless loop in getid3() with malformed genre tags in mp3s
   - Fixed show test page always returning false on web path
   - Update Man page to adhear to newer Debian rules
   - Fixed issue with Videos being incorrectly registered with stats
     and now playing as songs. 
   - Fixed missing > in HTML for song row
 * Bumped Standards-Version to 3.8.2, no changes needed.
 * Bumped debhelper to dh 7.
   - increased debian/compat to 7.
   - debian/rules removed dh_clean -k in favor of dh_prep
 * Lintian complains of FreeMonoMedium.ttf being an embeded fonts package.
   FreeMonoMedium.ttf is actually part of the ttf-freefont package.
   - added ttf-freefont to the Depends section of debian/control.
   - added -XFreeMono-Medium to dh_install in debian/rules.
   - added FreeMono.ttf symbolic link to debian/links.
 * Lintian complains of the wrong file permissions for 
   -  /locale/base/gather-messages.sh, added -Xgather-messages.sh to 
   debian/rules, gather-messages.sh is not used by ampache proper and 
   can be safely removed.  It is only utilized by developers who are 
   creating or editing the translation files.
   -  /locale/pl_PL/LC_MESSAGES/messages.po added find and chmod rule 
   to debian/rules.
   -  /locale/pl_PL/LC_MESSAGES/messages.mo added find and chmod rule 
   to debian/rules.
   -  /docs/CHANGELOG added find and chmod rule to debian/rules.
 * Lintian complains of wrong-name-for-upstream-changelog
   -  install upstream CHANGELOG to /usr/share/ampache/www/docs
   -  added find and gzip -9 rule to debian/rules
   -  added symlink creation to debian/links to link
      /usr/share/ampache/www/docs/CHANGELOG.gz to 
      /usr/share/doc/ampache/changelog.gz  
 * Lacy Marrow has responded and has stated that he is dropping the GPL-3 
   licensing of his work and is now releasing version 5.9.5 of the 
   XSPF JukeBox under the same BSD license that the original version of XSPF 
   Music Player was released under (XSPF JukeBox is based on XSPF Music 
   Player).  So now XSPF Music Player and XSPF JukeBox are now released under
   the same BSD type license.  This closes RC Bug #526719.  Closes: #526719
   - Updated debian/copyright to refect this.
 * Added dh_installman to debian/rules so the manpage now installs correctly.
   - Added debian/ampache.manpages.
 * debian/ampache.config downgraded db_input to medium
 * debian/copyright removed (C) in favor of the word copyright.
 

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
        // This is added so that we don't pop any webservers
31
31
        private static $limit = '5000';
32
32
        private static $offset = '0'; 
 
33
        private static $type = ''; 
33
34
 
34
35
        /**
35
36
         * constructor
66
67
        } // set_limit
67
68
 
68
69
        /**
 
70
         * set_type
 
71
         * This sets the type of xmlData we are working on
 
72
         */
 
73
        public static function set_type($type) { 
 
74
 
 
75
                if (!in_array($type,array('rss','xspf','itunes'))) { return false; } 
 
76
 
 
77
                self::$type = $type; 
 
78
 
 
79
        } // set_type
 
80
 
 
81
        /**
69
82
         * error
70
83
         * This generates a standard XML Error message
71
84
         * nothing fancy here...
72
85
         */
73
86
        public static function error($code,$string) { 
74
 
 
75
87
                
76
88
                $string = self::_header() . "\t<error code=\"$code\"><![CDATA[$string]]></error>" . self::_footer(); 
77
89
                return $string; 
91
103
        } // single_string
92
104
 
93
105
        /**
 
106
         * header
 
107
         * This returns the header
 
108
         */
 
109
        public static function header() { 
 
110
 
 
111
                return self::_header(); 
 
112
 
 
113
        } // header
 
114
 
 
115
        /**
 
116
         * footer
 
117
         * This returns the footer
 
118
         */
 
119
        public static function footer() { 
 
120
 
 
121
                return self::_footer(); 
 
122
 
 
123
        } // header 
 
124
 
 
125
        /**
 
126
         * tags_string
 
127
         * This returns the formated 'tags' string for an xml document 
 
128
         */
 
129
        private static function tags_string($tags,$type,$object_id) { 
 
130
 
 
131
                $string = ''; 
 
132
 
 
133
                foreach ($tags as $tag_id=>$data) { 
 
134
                        
 
135
                        $tag = new Tag($tag_id); 
 
136
                        $string .= "\t<tag id=\"" . $tag->id . "\" count=\"" . $data['count'] . "\"><![CDATA[$tag->name]]></tag>\n";
 
137
                } 
 
138
 
 
139
                return $string; 
 
140
 
 
141
        } // tags_string
 
142
 
 
143
        /**
94
144
         * keyed_array
95
145
         * This will build an xml document from a key'd array, 
96
146
         */
103
153
                        // If it's an array, run again
104
154
                        if (is_array($value)) { 
105
155
                                $value = self::keyed_array($value,1); 
106
 
                                $string .= "\t<$key>$value</$key>\n"; 
 
156
                                $string .= "<$key>\n$value\n</$key>\n"; 
107
157
                        } 
108
158
                        else { 
109
159
                                $string .= "\t<$key><![CDATA[$value]]></$key>\n"; 
120
170
        } // keyed_array
121
171
 
122
172
        /**
 
173
         * tags
 
174
         * This returns tags to the user, in a pretty xml document with the information
 
175
         */
 
176
        public static function tags($tags) { 
 
177
 
 
178
                if (count($tags) > self::$limit) { 
 
179
                        $tags = array_splice($tags,self::$offset,self::$limit); 
 
180
                } 
 
181
 
 
182
                $string = ''; 
 
183
 
 
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" . 
 
195
                                        "</tag>\n"; 
 
196
                } // end foreach 
 
197
                
 
198
                $final = self::_header() . $string . self::_footer(); 
 
199
 
 
200
                return $final; 
 
201
 
 
202
        } // tags
 
203
 
 
204
        /**
123
205
         * artists
124
206
         * This takes an array of artists and then returns a pretty xml document with the information 
125
207
         * we want 
131
213
                } 
132
214
 
133
215
                $string = ''; 
 
216
                
 
217
                Rating::build_cache('artist',$artists); 
134
218
 
135
219
                foreach ($artists as $artist_id) { 
136
220
                        $artist = new Artist($artist_id); 
137
221
                        $artist->format(); 
138
222
 
 
223
                        $rating = new Rating($artist_id,'artist'); 
 
224
                        $tag_string = self::tags_string($artist->tags,'artist',$artist->id); 
 
225
 
139
226
                        $string .= "<artist id=\"$artist->id\">\n" . 
140
227
                                        "\t<name><![CDATA[$artist->f_full_name]]></name>\n" .  
 
228
                                        $tag_string . 
141
229
                                        "\t<albums>$artist->albums</albums>\n" . 
142
230
                                        "\t<songs>$artist->songs</songs>\n" . 
 
231
                                        "\t<preciserating>" . $rating->preciserating . "</preciserating>\n" .
 
232
                                        "\t<rating>" . $rating->rating . "</rating>\n" .
143
233
                                        "</artist>\n"; 
144
234
                } // end foreach artists
145
235
 
158
248
                if (count($albums) > self::$limit) { 
159
249
                        $albums = array_splice($albums,self::$offset,self::$limit); 
160
250
                } 
 
251
                
 
252
                Rating::build_cache('album',$albums); 
161
253
 
162
254
                foreach ($albums as $album_id) { 
163
255
                        $album = new Album($album_id); 
164
256
                        $album->format(); 
165
257
 
 
258
                        $rating = new Rating($album_id,'album'); 
 
259
 
166
260
                        // Build the Art URL, include session 
167
261
                        $art_url = Config::get('web_path') . '/image.php?id=' . $album->id . '&auth=' . scrub_out($_REQUEST['auth']);  
168
262
 
180
274
                        $string .= "\t<year>$album->year</year>\n" . 
181
275
                                        "\t<tracks>$album->song_count</tracks>\n" . 
182
276
                                        "\t<disk>$album->disk</disk>\n" . 
 
277
                                        self::tags_string($album->tags,'album',$album->id) . 
183
278
                                        "\t<art><![CDATA[$art_url]]></art>\n" . 
 
279
                                        "\t<preciserating>" . $rating->preciserating . "</preciserating>\n" .
 
280
                                        "\t<rating>" . $rating->rating . "</rating>\n" .
184
281
                                        "</album>\n"; 
185
282
                } // end foreach
186
283
 
191
288
        } // albums
192
289
 
193
290
        /**
194
 
         * genres
195
 
         * This takes an array of genre ids and returns a nice little pretty xml doc
196
 
         */
197
 
        public static function genres($genres) { 
198
 
 
199
 
                if (count($genres) > self::$limit) { 
200
 
                        $genres = array_slice($genres,self::$offset,self::$limit); 
201
 
                } 
202
 
 
203
 
                // Foreach the ids
204
 
                foreach ($genres as $genre_id) { 
205
 
                        $genre = new Genre($genre_id); 
206
 
                        $genre->format(); 
207
 
                        $song_count     = $genre->get_song_count(); 
208
 
                        $album_count    = $genre->get_album_count(); 
209
 
                        $artist_count   = $genre->get_artist_count(); 
210
 
 
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" . 
216
 
                                        "</genre>\n"; 
217
 
 
218
 
                } // end foreach
219
 
 
220
 
                $final = self::_header() . $string . self::_footer(); 
221
 
 
222
 
                return $final; 
223
 
 
224
 
        } // genres
225
 
 
226
 
        /**
227
291
         * playlists
228
292
         * This takes an array of playlist ids and then returns a nice pretty XML document
229
293
         */
244
308
                        // Build this element
245
309
                        $string .= "<playlist id=\"$playlist->id\">\n" . 
246
310
                                "\t<name><![CDATA[$playlist->name]]></name>\n" . 
247
 
                                "\t<owner><![CDATA[$playlist->f_user]]</owner>\n" . 
 
311
                                "\t<owner><![CDATA[$playlist->f_user]]></owner>\n" . 
248
312
                                "\t<items>$item_total</items>\n" . 
249
313
                                "\t<type>$playlist->type</type>\n" . 
250
314
                                "</playlist>\n";
269
333
                        $songs = array_slice($songs,self::$offset,self::$limit); 
270
334
                } 
271
335
 
 
336
                Rating::build_cache('song',$songs); 
 
337
                Stream::set_session($_REQUEST['auth']); 
 
338
 
272
339
                // Foreach the ids!
273
340
                foreach ($songs as $song_id) { 
274
341
                        $song = new Song($song_id); 
275
342
                        $song->format(); 
276
343
 
277
 
                        $art_url = Config::get('web_path') . '/image.php?id=' . $song->album . '&auth=' . scrub_out($_REQUEST['auth']);
 
344
                        $tag_string = ''; 
 
345
 
 
346
                        $tag = new Tag($song->tags['0']); 
 
347
                        $song->genre = $tag->id;
 
348
                        $song->f_genre = $tag->name; 
 
349
 
 
350
                        $tag_string = self::tags_string($song->tags,'song',$song->id); 
 
351
 
 
352
                        $rating = new Rating($song_id,'song'); 
 
353
 
 
354
                        $art_url = Album::get_art_url($song->album,$_REQUEST['auth']); 
278
355
 
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" . 
 
361
                                        $tag_string . 
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" . 
289
370
                                        "</song>\n"; 
290
371
 
291
372
                } // end foreach
297
378
        } // songs
298
379
 
299
380
        /**
 
381
         * videos
 
382
         * This builds the xml document for displaying video objects
 
383
         */
 
384
        public static function videos($videos) { 
 
385
 
 
386
                if (count($videos) > self::$limit) {
 
387
                        $videos = array_slice($videos,self::$offset,self::$limit);
 
388
                }
 
389
 
 
390
                $string = ''; 
 
391
 
 
392
                foreach ($videos as $video_id) { 
 
393
                        $video = new Video($video_id); 
 
394
                        $video->format(); 
 
395
 
 
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" .
 
403
                                        "</video>\n";
 
404
 
 
405
                } // end foreach 
 
406
 
 
407
                $final = self::_header() . $string . self::_footer(); 
 
408
 
 
409
                return $final; 
 
410
 
 
411
 
 
412
        } // videos
 
413
 
 
414
        /**
 
415
         * democratic
 
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
 
418
         */
 
419
        public static function democratic($object_ids=array()) { 
 
420
 
 
421
                if (!is_array($object_ids)) { $object_ids = array(); } 
 
422
                
 
423
                $string = ''; 
 
424
 
 
425
                foreach ($object_ids as $row_id=>$data) { 
 
426
                        $song = new $data['object_type']($data['object_id']); 
 
427
                        $song->format(); 
 
428
 
 
429
                        //FIXME: This is duplicate code and so wrong, functions need to be improved
 
430
                        $tag_string = '';
 
431
 
 
432
                        $tag = new Tag($song->tags['0']);
 
433
                        $song->genre = $tag->id;
 
434
                        $song->f_genre = $tag->name;
 
435
 
 
436
                        $tag_string = self::tags_string($song->tags,'song',$song->id);
 
437
 
 
438
                        $rating = new Rating($song_id,'song');
 
439
 
 
440
                        $art_url = Album::get_art_url($song->album,$_REQUEST['auth']);
 
441
 
 
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" .
 
447
                                        $tag_string .
 
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" .  
 
457
                                        "</song>\n";
 
458
 
 
459
                } // end foreach 
 
460
                
 
461
                $final = self::_header() . $string . self::_footer(); 
 
462
 
 
463
                return $final; 
 
464
 
 
465
        } // democratic
 
466
 
 
467
        /**
 
468
         * rss_feed
 
469
         */
 
470
        public static function rss_feed($data,$title,$description,$date) { 
 
471
 
 
472
                $string = "\t<title>$title</title>\n\t<link>" . Config::get('web_path') . "</link>\n\t" . 
 
473
                        "<pubDate>" . date("r",$date) . "</pubDate>\n"; 
 
474
 
 
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); 
 
479
                } 
 
480
 
 
481
                $final = self::_header() . $string . self::_footer(); 
 
482
 
 
483
                return $final; 
 
484
 
 
485
        } // rss_feed
 
486
 
 
487
        /**
300
488
         * _header
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
303
491
         */
304
 
        private static function _header($type='') { 
 
492
        private static function _header() { 
305
493
 
306
 
                switch ($type) { 
 
494
                switch (self::$type) { 
307
495
                        case 'xspf': 
308
 
 
 
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" .
 
502
                                                "<trackList>\n";
309
503
                        break; 
310
504
                        case 'itunes':
311
 
                        
 
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" .
 
510
                                "<dict>\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" .
 
517
                                "       <dict>\n";                      
 
518
                        break; 
 
519
                        case 'rss': 
 
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"; 
312
523
                        break; 
313
524
                        default: 
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";
315
526
                        break; 
316
527
                } // end switch 
317
528
 
323
534
         * _footer
324
535
         * this returns the footer for this document, these are pretty boring
325
536
         */
326
 
        private static function _footer($type='') { 
 
537
        private static function _footer() { 
327
538
 
328
 
                switch ($type) { 
 
539
                switch (self::$type) { 
 
540
                        case 'itunes': 
 
541
                                $footer = "\t\t</dict>\t\n</dict>\n</plist>\n";
 
542
                        break; 
 
543
                        case 'xspf': 
 
544
                                $footer = "</trackList>\n</playlist>\n"; 
 
545
                        break; 
 
546
                        case 'rss': 
 
547
                                $footer = "\n</channel>\n</rss>\n"; 
 
548
                        break; 
329
549
                        default: 
330
550
                                $footer = "\n</root>\n"; 
331
551
                        break;