From 287a46f11e429ff8a11bc646afaeadce122425c6 Mon Sep 17 00:00:00 2001 From: Karl 'vollmerk' Vollmer Date: Sat, 6 Dec 2008 18:47:09 +0000 Subject: some work on the rss feed stuff --- lib/class/rss.class.php | 32 +++++++++++++++++++++++--------- lib/class/xmldata.class.php | 44 +++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 64 insertions(+), 12 deletions(-) (limited to 'lib/class') 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,24 +27,38 @@ */ 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 @@ -65,6 +66,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 @@ -280,6 +293,23 @@ class xmlData { } // songs + /** + * rss_feed + */ + public static function rss_feed($data,$title,$description,$date) { + + $string = "\t$title\n\t" . Config::get('web_path') . "\n\t" . + "$date\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 @@ -287,15 +317,20 @@ class xmlData { */ private static function _header($type='') { - switch ($type) { + switch (self::$type) { case 'xspf': break; case 'itunes': + break; + case 'rss': + $header = "\n " . + "