summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/class/ampacherss.class.php167
-rw-r--r--lib/class/rss.class.php79
-rw-r--r--lib/class/xmldata.class.php17
-rw-r--r--lib/stream.lib.php3
-rw-r--r--rss.php19
-rw-r--r--templates/show_now_playing.inc.php2
-rw-r--r--templates/show_recently_played.inc.php2
7 files changed, 184 insertions, 105 deletions
diff --git a/lib/class/ampacherss.class.php b/lib/class/ampacherss.class.php
new file mode 100644
index 00000000..69684f82
--- /dev/null
+++ b/lib/class/ampacherss.class.php
@@ -0,0 +1,167 @@
+<?php
+/*
+
+ Copyright Ampache.org
+ All Rights Reserved
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; version 2
+ of the License.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+*/
+
+/**
+ * AmpacheRSS Class
+ * This is not currently used by the stable version of ampache, really here for future use and
+ * due to the fact it was back-ported from /trunk
+ */
+class AmpacheRSS {
+
+ private $type;
+ public $data;
+
+ /**
+ * Constructor
+ * This takes a flagged.id and then pulls in the information for said flag entry
+ */
+ public function __construct($type) {
+
+ $this->type = self::validate_type($type);
+
+ } // constructor
+
+ /**
+ * get_xml
+ * This returns the xmldocument for the current rss type, it calls a sub function that gathers the data
+ * and then uses the xmlDATA class to build the document
+ */
+ public function get_xml() {
+
+ // Function call name
+ $data_function = 'load_' . $this->type;
+ $pub_date_function = 'pubdate_' . $this->type;
+
+ $data = call_user_func(array('AmpacheRSS',$data_function));
+ $pub_date = call_user_func(array('AmpacheRSS',$pub_date_function));
+
+ xmlData::set_type('rss');
+ $xml_document = xmlData::rss_feed($data,$this->get_title(),$this->get_description(),$pub_date);
+
+ return $xml_document;
+
+ } // get_xml
+
+ /**
+ * get_title
+ * This returns the standardized title for the rss feed based on this->type
+ */
+ public function get_title() {
+
+ $titles = array('now_playing'=>_('Now Playing'),
+ 'recently_played'=>_('Recently Played'),
+ 'latest_album'=>_('Newest Albums'),
+ 'latest_artist'=>_('Newest Artists'));
+
+ return $titles[$this->type];
+
+ } // get_title
+
+ /**
+ * get_description
+ * This returns the standardized description for the rss feed based on this->type
+ */
+ public function get_description() {
+
+ //FIXME: For now don't do any kind of translating
+ return 'Ampache RSS Feeds';
+
+ } // get_description
+
+ /**
+ * 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
+ */
+ public static function get_display($type='nowplaying') {
+
+ // Default to now playing
+ $type = self::validate_type($type);
+
+ $string = '<a href="' . Config::get('web_path') . '/rss.php?type=' . $type . '">' . get_user_icon('feed',_('RSS Feed')) . '</a>';
+
+ return $string;
+
+ } // get_display
+
+ // type specific functions below, these are called semi-dynamically based on the current type //
+
+ /**
+ * load_now_playing
+ * This loads in the now playing information. This is just the raw data with key=>value pairs that could be turned
+ * into an xml document if we so wished
+ */
+ public static function load_now_playing() {
+
+ $data = get_now_playing();
+
+ $results = array();
+
+ foreach ($data as $element) {
+ $song = $element['song'];
+ $client = $element['user'];
+ $xml_array = array('title'=>$song->f_title . ' - ' . $song->f_artist . ' - ' . $song->f_album,
+ 'link'=>$song->link,
+ 'description'=>$song->title . ' - ' . $song->f_artist_full . ' - ' . $song->f_album_full,
+ 'comments'=>$client->fullname . ' - ' . $element['agent'],
+ 'pubDate'=>date("r",$element['expire'])
+ );
+ $results[] = $xml_array;
+ } // end foreach
+
+ return $results;
+
+ } // load_now_playing
+
+ /**
+ * pubdate_now_playing
+ * this is the pub date we should use for the now playing information,
+ * this is a little specific as it uses the 'newest' expire we can find
+ */
+ public static function pubdate_now_playing() {
+
+ // Little redundent, should be fixed by an improvement in the get_now_playing stuff
+ $data = get_now_playing();
+
+ $element = array_shift($data);
+
+ return $element['expire'];
+
+ } // pubdate_now_playing
+
+} // end AmpacheRSS class
diff --git a/lib/class/rss.class.php b/lib/class/rss.class.php
deleted file mode 100644
index 21362131..00000000
--- a/lib/class/rss.class.php
+++ /dev/null
@@ -1,79 +0,0 @@
-<?php
-/*
-
- Copyright Ampache.org
- All Rights Reserved
-
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License
- as published by the Free Software Foundation; version 2
- of the License.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-
-*/
-
-/**
- * RSS Class
- * This is not currently used by the stable version of ampache, really here for future use and
- * due to the fact it was back-ported from /trunk
- */
-class RSS {
-
- public $type;
- public $data;
-
- /**
- * Constructor
- * This takes a flagged.id and then pulls in the information for said flag entry
- */
- public function __construct($type) {
-
- 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
- */
- public static function get_display($type='nowplaying') {
-
- // Default to now playing
- if (!in_array($type,self::$types)) {
- $type = 'nowplaying';
- }
-
- $string = '<a href="' . Config::get('web_path') . '/rss.php?type=' . $type . '">' . get_user_icon('feed',_('RSS Feed')) . '</a>';
-
- return $string;
-
- } // get_display
-
-} // end RSS class
diff --git a/lib/class/xmldata.class.php b/lib/class/xmldata.class.php
index cae0fa04..1b478df7 100644
--- a/lib/class/xmldata.class.php
+++ b/lib/class/xmldata.class.php
@@ -299,10 +299,13 @@ class xmlData {
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";
+ "<pubDate>" . date("r",$date) . "</pubDate>\n";
// Pass it to the keyed array xml function
- $string .= self::keyed_array($data);
+ foreach ($data as $item) {
+ // We need to enclose it in an item tag
+ $string .= self::keyed_array(array('item'=>$item),1);
+ }
$final = self::_header() . $string . self::_footer();
@@ -315,7 +318,7 @@ class xmlData {
* 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='') {
+ private static function _header() {
switch (self::$type) {
case 'xspf':
@@ -326,8 +329,8 @@ class xmlData {
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";
+ "<!-- RSS Generated by Ampache v." . Config::get('version') . " on " . date("r",time()) . "-->\n" .
+ "<rss version=\"2.0\">\n<channel>\n";
break;
default:
$header = "<?xml version=\"1.0\" encoding=\"" . Config::get('site_charset') . "\" ?>\n<root>\n";
@@ -342,11 +345,11 @@ class xmlData {
* _footer
* this returns the footer for this document, these are pretty boring
*/
- private static function _footer($type='') {
+ private static function _footer() {
switch (self::$type) {
case 'rss':
- $footer = "\n\t<channel>\n</rss>\n";
+ $footer = "\n</channel>\n</rss>\n";
break;
default:
$footer = "\n</root>\n";
diff --git a/lib/stream.lib.php b/lib/stream.lib.php
index b0f4d609..8cc92d50 100644
--- a/lib/stream.lib.php
+++ b/lib/stream.lib.php
@@ -41,7 +41,8 @@ function show_now_playing() {
*/
function get_now_playing($filter='') {
- $sql = "SELECT `session_stream`.`agent`,`now_playing`.`song_id`,`now_playing`.`user` FROM `now_playing` " .
+ $sql = "SELECT `session_stream`.`agent`,`now_playing`.`song_id`,`now_playing`.`user`,`now_playing`.`expire` " .
+ "FROM `now_playing` " .
"LEFT JOIN `session_stream` ON `session_stream`.`id`=`now_playing`.`id` " .
"ORDER BY `now_playing`.`expire` DESC";
$db_results = Dba::query($sql);
diff --git a/rss.php b/rss.php
index 6ccace13..329b5282 100644
--- a/rss.php
+++ b/rss.php
@@ -30,23 +30,10 @@ if (!Config::get('use_rss') || Config::get('demo_mode')) {
// 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');
+$rss = new AmpacheRSS($_REQUEST['type']);
+echo $rss->get_xml();
-switch ($_REQUEST['action']) {
- case 'user':
-
- break;
- case 'catalog_add':
-
- default:
-
-
- break;
-} // end data collection
-
-show_RSS($_REQUEST['type'],$_REQUEST['username']);
+//show_RSS($_REQUEST['type'],$_REQUEST['username']);
?>
diff --git a/templates/show_now_playing.inc.php b/templates/show_now_playing.inc.php
index d489c274..a1ee87a7 100644
--- a/templates/show_now_playing.inc.php
+++ b/templates/show_now_playing.inc.php
@@ -28,7 +28,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
if (count($results)) {
-$link = Config::get('use_rss') ? ' ' . RSS::get_display('nowplaying') : '';
+$link = Config::get('use_rss') ? ' ' . AmpacheRSS::get_display('nowplaying') : '';
?>
<?php show_box_top(_('Now Playing') . $link); ?>
<div class="np_row">
diff --git a/templates/show_recently_played.inc.php b/templates/show_recently_played.inc.php
index 25ca1396..a638a24d 100644
--- a/templates/show_recently_played.inc.php
+++ b/templates/show_recently_played.inc.php
@@ -21,7 +21,7 @@
/* Define the time places starting at 0 */
$time_unit = array('',_('seconds ago'),_('minutes ago'),_('hours ago'),_('days ago'),_('weeks ago'),_('months ago'),_('years ago'));
-$link = Config::get('use_rss') ? ' ' . RSS::get_display('recentlyplayed') : '';
+$link = Config::get('use_rss') ? ' ' . AmpacheRSS::get_display('recentlyplayed') : '';
show_box_top(_('Recently Played') . $link);
?>
<table class="tabledata" cellpadding="0" cellspacing="0">