From d6e50fd701008d2b8cfa5ecb827ae0880c91b500 Mon Sep 17 00:00:00 2001 From: pb1dft Date: Fri, 27 Oct 2006 03:54:53 +0000 Subject: Reworked RSS and fixed mail statistics --- lib/class/stats.class.php | 2 +- lib/rss.php | 174 +++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 166 insertions(+), 10 deletions(-) (limited to 'lib') diff --git a/lib/class/stats.class.php b/lib/class/stats.class.php index 745232b9..057d2534 100644 --- a/lib/class/stats.class.php +++ b/lib/class/stats.class.php @@ -114,7 +114,7 @@ class Stats { " WHERE object_type='$type' AND date >= '$date' AND user = '$user'" . " GROUP BY object_id ORDER BY `count` DESC LIMIT $count"; $db_results = mysql_query($sql, dbh()); - + $results = array(); while ($r = mysql_fetch_assoc($db_results)) { diff --git a/lib/rss.php b/lib/rss.php index f4973f29..5a0c3615 100644 --- a/lib/rss.php +++ b/lib/rss.php @@ -24,17 +24,171 @@ @discussion creates a RSS fead for the now playing information */ -function show_now_playingRSS ($username=0) { -header ("Content-Type: application/xml"); +function show_RSS ($type = 'artist',$username = 0) { + header ("Content-Type: application/xml"); $dbh = dbh(); $web_path = conf('web_path'); $rss_main_title = conf('rss_main_title'); +/* Commented out vollmer wanted it fixed. + $rss_latestartist_title = conf('rss_latestartist_title'); + $rss_latestalbum_title = conf('rss_latestalbum_title'); + $rss_popularartist_title = conf('rss_popularartist_title'); + $rss_popularalbum_title = conf('rss_popularalbum_title'); + $rss_popularsong_title = conf('rss_popularsong_title'); +*/ + $rss_latestartist_title = "Ampache Latest Artists"; + $rss_latestalbum_title = "Ampache Latest Albums"; + $rss_popularartist_title = "Ampache Most Popular Artists"; + $rss_popularalbum_title = "Ampache Most Popular Albums"; + $rss_popularsong_title = "Ampache Most Popular Songs"; + $rss_main_description = conf('rss_main_description'); $rss_main_copyright = conf('rss_main_copyright'); $rss_main_language = conf('rss_main_language'); $rss_description = conf('rss_song_description'); + $today = date("d-m-Y"); + + echo "\n"; + + +switch ($type) { + case "popularalbum": + + $date = time() - (86400*7); + + /* Select Top objects counting by # of rows */ + $sql = "SELECT object_id,COUNT(id) AS `count` FROM object_count" . + " WHERE object_type='album' AND date >= '$date'" . + " GROUP BY object_id ORDER BY `count` DESC LIMIT 10"; + + $db_result = mysql_query($sql, $dbh); + + echo " \n $rss_popularalbum_title\n"; + echo " $web_path\n $rss_main_description\n"; + echo " $rss_main_copyright\n"; + echo " $today\n $rss_main_language\n"; + + while ( $r = @mysql_fetch_object($db_result) ) { + echo "\n"; + $album = new Album($r->object_id); + echo " <![CDATA[$album->name ($r->count)]]>\n"; + echo " $web_path/albums.php?action=show&album=$r->object_id\n"; + echo " name - $album->artist ($r->count)]]>\n"; + echo "\n"; + } + echo "\n"; + break; + + case "popularartist"; + + $date = time() - (86400*7); + + /* Select Top objects counting by # of rows */ + $sql = "SELECT object_id,COUNT(id) AS `count` FROM object_count" . + " WHERE object_type='artist' AND date >= '$date'" . + " GROUP BY object_id ORDER BY `count` DESC LIMIT 10"; + + $db_result = mysql_query($sql, $dbh); + + echo " \n $rss_popularartist_title\n"; + echo " $web_path\n $rss_main_description\n"; + echo " $rss_main_copyright\n"; + echo " $today\n $rss_main_language\n"; + + while ( $r = @mysql_fetch_object($db_result) ) { + echo "\n"; + $artist = new Artist($r->object_id); + echo " <![CDATA[$artist->name ($r->count)]]>\n"; + echo " $web_path/artists.php?action=show&artist=$r->object_id\n"; + echo " name - $artist->albums ($r->count)]]>\n"; + echo "\n"; + } + echo "\n"; + break; + + case "popularsong"; + + $date = time() - (86400*7); + + /* Select Top objects counting by # of rows */ + $sql = "SELECT object_id,COUNT(id) AS `count` FROM object_count" . + " WHERE object_type='song' AND date >= '$date'" . + " GROUP BY object_id ORDER BY `count` DESC LIMIT 10"; + + $db_result = mysql_query($sql, $dbh); + + echo " \n $rss_popularsong_title\n"; + echo " $web_path\n $rss_main_description\n"; + echo " $rss_main_copyright\n"; + echo " $today\n $rss_main_language\n"; + + while ( $r = @mysql_fetch_object($db_result) ) { + echo "\n"; + $song = new Song($r->object_id); + $artist = $song->get_artist_name(); + echo " <![CDATA[$artist - $song->title ($r->count)]]>\n"; + echo " $web_path/song.php?action=single_song&song_id=$r->object_id\n"; + echo " title ($r->count)]]>\n"; + echo "\n"; + } + echo "\n"; + break; + + case "latestartist": + + $sql = "SELECT DISTINCT artist,album FROM song ORDER BY addition_time DESC LIMIT 10"; + $db_result = mysql_query($sql, $dbh); + + $items = array(); + + echo " \n $rss_latestartist_title\n"; + echo " $web_path\n $rss_main_description\n"; + echo " $rss_main_copyright\n"; + echo " $today\n $rss_main_language\n"; + + + while ( $item = mysql_fetch_row($db_result) ) { + echo " \n"; + $artist = new Artist($item[0]); + $album = new Album($item[1]); + $album->format_album(); + $artist->format_artist(); + echo " <![CDATA[$artist->full_name]]>\n"; + echo " $web_path/artists.php?action=show&artist=$item[0]\n"; + echo " full_name - $album->name]]>\n"; + echo " \n"; + } + echo " \n"; + break; + + case "latestalbum": + + $sql = "SELECT DISTINCT album FROM song ORDER BY addition_time DESC LIMIT 10"; + $db_result = mysql_query($sql, $dbh); + + $items = array(); + + echo " \n $rss_latestalbum_title\n"; + echo " $web_path\n $rss_main_description\n"; + echo " $rss_main_copyright\n"; + echo " $today\n $rss_main_language\n"; + + + while ( $item = mysql_fetch_row($db_result) ) { + echo "\n"; + $album = new Album($item[0]); + $album->format_album(); + echo " <![CDATA[$album->name]]>\n"; + echo " $web_path/albums.php?action=show&album=$item[0]\n"; + echo " name - $album->artist]]>\n"; + echo "\n"; + } + echo "\n"; + break; + + default: if ($username) { $user = get_user_from_username($username); @@ -44,13 +198,13 @@ header ("Content-Type: application/xml"); $sql = "SELECT * FROM now_playing $constraint ORDER BY start_time DESC"; $db_result = mysql_query($sql, $dbh); - $today = date("d-m-Y"); + $rss_song_description = $rss_description; - echo ""; - echo "\n$rss_main_title\n"; - echo "$web_path\n$rss_main_description\n"; - echo "$rss_main_copyright"; - echo "$today\n$rss_main_language\n"; + + echo " \n $rss_main_title\n"; + echo " $web_path\n $rss_main_description\n"; + echo " $rss_main_copyright\n"; + echo " $today\n $rss_main_language\n"; while ($r = mysql_fetch_object($db_result)) { $song = new Song($r->song_id); @@ -71,5 +225,7 @@ header ("Content-Type: application/xml"); } echo "\n"; -} // show_now_playingRSS + break; +} +} ?> -- cgit