diff options
-rw-r--r-- | lib/class/rss.class.php | 32 | ||||
-rw-r--r-- | lib/class/xmldata.class.php | 44 | ||||
-rw-r--r-- | lib/rss.php | 3 | ||||
-rw-r--r-- | lib/stream.lib.php | 2 | ||||
-rw-r--r-- | rss.php | 7 |
5 files changed, 72 insertions, 16 deletions
diff --git a/lib/class/rss.class.php b/lib/class/rss.class.php index 17d3b154..21362131 100644 --- a/lib/class/rss.class.php +++ b/lib/class/rss.class.php @@ -27,25 +27,39 @@ */ class RSS { - private static $types = array('nowplaying', - 'latestartist', - 'latestalbum', - 'popularalbum', - 'popularartist', - 'popularsong', - 'recentlyplayed'); + public $type; + public $data; /** * Constructor * This takes a flagged.id and then pulls in the information for said flag entry */ - public function __construct() { + public function __construct($type) { - // Nothing here for now + if (!RSS::valid_type($type)) { + $type = 'now_playing'; + } } // constructor /** + * validate_type + * this returns a valid type for an rss feed, if the specified type is invalid it returns a default value + */ + public static function validate_type($type) { + + $valid_types = array('now_playing','recently_played','latest_album','latest_artist','latest_song', + 'popular_song','popular_album','popular_artist'); + + if (!in_array($type,$valid_types)) { + return 'now_playing'; + } + + return $type; + + } // validate_type + + /** * get_display * This dumps out some html and an icon for the type of rss that we specify */ diff --git a/lib/class/xmldata.class.php b/lib/class/xmldata.class.php index 1fc7bc2e..cae0fa04 100644 --- a/lib/class/xmldata.class.php +++ b/lib/class/xmldata.class.php @@ -30,6 +30,7 @@ class xmlData { // This is added so that we don't pop any webservers private static $limit = '5000'; private static $offset = '0'; + private static $type = ''; /** * constructor @@ -66,6 +67,18 @@ class xmlData { } // set_limit /** + * set_type + * This sets the type of xmlData we are working on + */ + public static function set_type($type) { + + if (!in_array($type,array('rss','xspf','itunes'))) { return false; } + + self::$type = $type; + + } // set_type + + /** * error * This generates a standard XML Error message * nothing fancy here... @@ -281,21 +294,43 @@ class xmlData { } // songs /** + * rss_feed + */ + public static function rss_feed($data,$title,$description,$date) { + + $string = "\t<title>$title</title>\n\t<link>" . Config::get('web_path') . "</link>\n\t" . + "<pubDate>$date</pubDate>\n"; + + // Pass it to the keyed array xml function + $string .= self::keyed_array($data); + + $final = self::_header() . $string . self::_footer(); + + return $final; + + } // rss_feed + + /** * _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) { + switch (self::$type) { case 'xspf': break; case 'itunes': break; + case 'rss': + $header = "<?xml version=\"1.0\" encoding=\"" . Config::get('site_charset') . "\" ?>\n " . + "<!-- RSS Generated by Ampache v." . Config::get('version') . " on " . date("r",time()) . "\n" . + "<rss version=\"2.0\">\n\t<channel>\n"; + break; default: - $header = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n<root>\n"; + $header = "<?xml version=\"1.0\" encoding=\"" . Config::get('site_charset') . "\" ?>\n<root>\n"; break; } // end switch @@ -309,7 +344,10 @@ class xmlData { */ private static function _footer($type='') { - switch ($type) { + switch (self::$type) { + case 'rss': + $footer = "\n\t<channel>\n</rss>\n"; + break; default: $footer = "\n</root>\n"; break; diff --git a/lib/rss.php b/lib/rss.php index 805d4d11..4c2b58d7 100644 --- a/lib/rss.php +++ b/lib/rss.php @@ -208,9 +208,6 @@ switch ($type) { } echo "</channel>\n</rss>"; break; - - - default: $now_playing = get_now_playing(); $rss_song_description = $rss_description; diff --git a/lib/stream.lib.php b/lib/stream.lib.php index de3adde1..b0f4d609 100644 --- a/lib/stream.lib.php +++ b/lib/stream.lib.php @@ -53,7 +53,7 @@ function get_now_playing($filter='') { $song = new Song($r['song_id']); $song->format(); $np_user = new User($r['user']); - $results[] = array('song'=>$song,'user'=>$np_user,'agent'=>$r['agent']); + $results[] = array('song'=>$song,'user'=>$np_user,'agent'=>$r['agent'],'expire'=>$r['expire']); } // end while return $results; @@ -28,6 +28,12 @@ if (!Config::get('use_rss') || Config::get('demo_mode')) { exit; } +// Add in our base hearder defining the content type +header("Content-Type: application/xml; charset=" . Config::get('site_charset')); +header("Content-Disposition: attachment; filename=rss.xml"); + +// This is always going to be an rss feed, so make sure our header and footers are correct +xmlData::set_type('rss'); switch ($_REQUEST['action']) { case 'user': @@ -36,6 +42,7 @@ switch ($_REQUEST['action']) { case 'catalog_add': default: + break; } // end data collection |