1
0
Fork 0
mirror of https://github.com/Yetangitu/ampache synced 2025-10-03 09:49:30 +02:00

some work on the rss feed stuff

This commit is contained in:
Karl 'vollmerk' Vollmer 2008-12-06 18:47:09 +00:00
parent 286840fbcc
commit 287a46f11e
5 changed files with 72 additions and 16 deletions

View file

@ -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

View file

@ -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>$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
@ -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 = "<?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;

View file

@ -208,9 +208,6 @@ switch ($type) {
}
echo "</channel>\n</rss>";
break;
default:
$now_playing = get_now_playing();
$rss_song_description = $rss_description;

View file

@ -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;

View file

@ -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':
@ -37,6 +43,7 @@ switch ($_REQUEST['action']) {
default:
break;
} // end data collection