diff options
author | pb1dft <pb1dft@ampache> | 2006-10-27 03:54:53 +0000 |
---|---|---|
committer | pb1dft <pb1dft@ampache> | 2006-10-27 03:54:53 +0000 |
commit | d6e50fd701008d2b8cfa5ecb827ae0880c91b500 (patch) | |
tree | f12837dd5edae5be950ede7a0f8348c6cd38a671 | |
parent | bafe4061a549b3c792ce4c327bc0acf98952cec4 (diff) | |
download | ampache-d6e50fd701008d2b8cfa5ecb827ae0880c91b500.tar.gz ampache-d6e50fd701008d2b8cfa5ecb827ae0880c91b500.tar.bz2 ampache-d6e50fd701008d2b8cfa5ecb827ae0880c91b500.zip |
Reworked RSS and fixed mail statistics
-rw-r--r-- | admin/mail.php | 81 | ||||
-rwxr-xr-x | docs/CHANGELOG | 4 | ||||
-rw-r--r-- | lib/class/stats.class.php | 2 | ||||
-rw-r--r-- | lib/rss.php | 174 | ||||
-rw-r--r-- | rss.php | 3 | ||||
-rw-r--r-- | templates/header.inc | 5 | ||||
-rw-r--r-- | templates/show_mail_users.inc.php | 4 |
7 files changed, 212 insertions, 61 deletions
diff --git a/admin/mail.php b/admin/mail.php index 16088fc2..0c3ea899 100644 --- a/admin/mail.php +++ b/admin/mail.php @@ -71,15 +71,16 @@ switch ($action) { $from = $user->fullname."<".$user->email.">"; if (isset ($cat_stats)){ - /* Before we display anything make sure that they have a catalog */ $query = "SELECT * FROM catalog"; + $dbh = dbh(); $db_results = mysql_query($query, dbh()); if (!mysql_num_rows($db_results)) { $items[] = "<span align=\"center\" class=\"error\">" . _("No Catalogs Found!") . "</span><br />"; $items[] = "<a href=\"" . conf('web_path') . "/admin/catalog.php?action=show_add_catalog\">" ._("Add a Catalog") . "</a>"; show_info_box(_('Catalog Statistics'),'catalog',$items); return false; + break; } $query = "SELECT count(*) AS songs, SUM(size) AS size, SUM(time) as time FROM song"; @@ -126,7 +127,6 @@ switch ($action) { $total_size = sprintf("%.2f", $size); $size_unit = "MB"; } - $stats = _('Total Users')." ".$users[0]."\n"; $stats .= _('Connected Users')." ".$connected_users[0]."\n"; $stats .= _('Albums')." ".$albums[0]."\n"; @@ -140,59 +140,42 @@ switch ($action) { } if (isset ($pop_albums)){ - /* Select out the most popular based on object_count */ - $sql = "SELECT object_id, SUM(count) as count FROM object_count" . - " WHERE object_type = 'album'" . - " GROUP BY object_id" . - " ORDER BY count DESC LIMIT " . conf('popular_threshold'); - $db_result = mysql_query($sql,dbh()); - - while ( $r = @mysql_fetch_object($db_result) ) { - $album = new Album($r->object_id); - $palbums .= $album->name." (". $r->count.")\n"; - } - $message .= "\n\nMost Popular Albums\n\n"; + $stats = new Stats(); + $stats = $stats->get_top('10','album'); + + foreach( $stats as $r){ + $album = new Album($r[object_id]); + $palbums .= $album->name." (". $r[count].")\n"; + } $message .= "$palbums"; - } if (isset ($pop_artists)){ - /* Select out the most popular based on object_count */ - $sql = "SELECT object_id, SUM(count) as count FROM object_count" . - " WHERE object_type = 'artist'" . - " GROUP BY object_id" . - " ORDER BY count DESC LIMIT " . conf('popular_threshold'); - $db_result = mysql_query($sql,dbh()); - - while ( $r = @mysql_fetch_object($db_result) ) { - $artist = new Artist($r->object_id); - $partists .= $artist->name." (". $r->count.")\n"; - } - $message .= "\n\nMost Popular Artists\n\n"; - $message .= "$partists"; + $stats = new Stats(); + $stats = $stats->get_top('10','artist'); + foreach( $stats as $r){ + $artist = new Artist($r[object_id]); + $partists .= $artist->name." (". $r[count].")\n"; + } + $message .= "$partists"; } if (isset ($pop_songs)){ - /* Select out the most popular based on object_count */ - $sql = "SELECT object_id, SUM(count) as count FROM object_count" . - " WHERE object_type = 'song'" . - " GROUP BY object_id" . - " ORDER BY count DESC LIMIT " . conf('popular_threshold'); - $db_result = mysql_query($sql,dbh()); - - while ( $r = @mysql_fetch_object($db_result) ) { - $song = new Song($r->object_id); - $artist = $song->get_artist_name(); - $text = "$artist - $song->title"; - $psongs .= $text." (". $r->count.")\n"; - } $message .= "\n\nMost Popular Songs\n\n"; + $stats = new Stats(); + $stats = $stats->get_top('10','song'); + + foreach( $stats as $r){ + $song = new Song($r[object_id]); + $artist = $song->get_artist_name(); + $text = "$artist - $song->title"; + $psongs .= $text." (". $r[count].")\n"; + } $message .= "$psongs"; - } if (isset ($new_artists)){ @@ -200,12 +183,12 @@ switch ($action) { $sql = "SELECT DISTINCT artist FROM song ORDER BY addition_time " . "DESC LIMIT " . conf('popular_threshold'); $db_result = mysql_query($sql, dbh()); - - while ( $item = mysql_fetch_row($db_result) ) { - $artist = new Artist($item[0]); - $nartists .= $artist->name."\n"; + + while ( $item = mysql_fetch_row($db_result) ) { + $artist = new Artist($item[0]); + $nartists .= $artist->name."\n"; } - $message .= "\n\nNewest Artist Additions\n\n"; + $message .= "\n\nLatest Artist Additions\n\n"; $message .= "$nartists"; } @@ -215,12 +198,14 @@ switch ($action) { "DESC LIMIT " . conf('popular_threshold'); $db_result = mysql_query($sql, dbh()); + while ( $item = mysql_fetch_row($db_result) ) { $album = new Album($item[0]); $nalbums .= $album->name."\n"; } - $message .= "\n\nNewest Album Additions\n\n"; + $message .= "\n\nLatest Album Additions\n\n"; $message .= "$nalbums"; + } // woohoo!! diff --git a/docs/CHANGELOG b/docs/CHANGELOG index 2d10d2d1..08bf157d 100755 --- a/docs/CHANGELOG +++ b/docs/CHANGELOG @@ -4,6 +4,10 @@ -------------------------------------------------------------------------- v.3.3.3-Alpha1 + - Fixed Mail statistics. It broke down after earlier updates. + - Reworked RSS features (Thx pb1dft) + Newest and latest songs albums and artist are available + through RSS. - Reworked Stats so that they are time specific, allows for Top 10 of this week, threshold is per user configured - Added Admin Allow XXXX preferences for downsampling, streaming 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 "<rss version=\"2.0\">\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 " <channel>\n <title>$rss_popularalbum_title</title>\n"; + echo " <link>$web_path</link>\n <description>$rss_main_description</description>\n"; + echo " <copyright>$rss_main_copyright</copyright>\n"; + echo " <pubDate>$today</pubDate>\n <language>$rss_main_language</language>\n"; + + while ( $r = @mysql_fetch_object($db_result) ) { + echo "<item>\n"; + $album = new Album($r->object_id); + echo " <title><![CDATA[$album->name ($r->count)]]></title>\n"; + echo " <link>$web_path/albums.php?action=show&album=$r->object_id</link>\n"; + echo " <description><![CDATA[$album->name - $album->artist ($r->count)]]></description>\n"; + echo "</item>\n"; + } + echo "</channel>\n</rss>"; + 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 " <channel>\n <title>$rss_popularartist_title</title>\n"; + echo " <link>$web_path</link>\n <description>$rss_main_description</description>\n"; + echo " <copyright>$rss_main_copyright</copyright>\n"; + echo " <pubDate>$today</pubDate>\n <language>$rss_main_language</language>\n"; + + while ( $r = @mysql_fetch_object($db_result) ) { + echo "<item>\n"; + $artist = new Artist($r->object_id); + echo " <title><![CDATA[$artist->name ($r->count)]]></title>\n"; + echo " <link>$web_path/artists.php?action=show&artist=$r->object_id</link>\n"; + echo " <description><![CDATA[$artist->name - $artist->albums ($r->count)]]></description>\n"; + echo "</item>\n"; + } + echo "</channel>\n</rss>"; + 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 " <channel>\n <title>$rss_popularsong_title</title>\n"; + echo " <link>$web_path</link>\n <description>$rss_main_description</description>\n"; + echo " <copyright>$rss_main_copyright</copyright>\n"; + echo " <pubDate>$today</pubDate>\n <language>$rss_main_language</language>\n"; + + while ( $r = @mysql_fetch_object($db_result) ) { + echo "<item>\n"; + $song = new Song($r->object_id); + $artist = $song->get_artist_name(); + echo " <title><![CDATA[$artist - $song->title ($r->count)]]></title>\n"; + echo " <link>$web_path/song.php?action=single_song&song_id=$r->object_id</link>\n"; + echo " <description><![CDATA[$artist - $song->title ($r->count)]]></description>\n"; + echo "</item>\n"; + } + echo "</channel>\n</rss>"; + 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 " <channel>\n <title>$rss_latestartist_title</title>\n"; + echo " <link>$web_path</link>\n <description>$rss_main_description</description>\n"; + echo " <copyright>$rss_main_copyright</copyright>\n"; + echo " <pubDate>$today</pubDate>\n <language>$rss_main_language</language>\n"; + + + while ( $item = mysql_fetch_row($db_result) ) { + echo " <item>\n"; + $artist = new Artist($item[0]); + $album = new Album($item[1]); + $album->format_album(); + $artist->format_artist(); + echo " <title><![CDATA[$artist->full_name]]></title>\n"; + echo " <link>$web_path/artists.php?action=show&artist=$item[0]</link>\n"; + echo " <description><![CDATA[$artist->full_name - $album->name]]></description>\n"; + echo " </item>\n"; + } + echo " </channel>\n</rss>"; + 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 " <channel>\n <title>$rss_latestalbum_title</title>\n"; + echo " <link>$web_path</link>\n <description>$rss_main_description</description>\n"; + echo " <copyright>$rss_main_copyright</copyright>\n"; + echo " <pubDate>$today</pubDate>\n <language>$rss_main_language</language>\n"; + + + while ( $item = mysql_fetch_row($db_result) ) { + echo "<item>\n"; + $album = new Album($item[0]); + $album->format_album(); + echo " <title><![CDATA[$album->name]]></title>\n"; + echo " <link>$web_path/albums.php?action=show&album=$item[0]</link>\n"; + echo " <description><![CDATA[$album->name - $album->artist]]></description>\n"; + echo "</item>\n"; + } + echo "</channel>\n</rss>"; + 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 "<rss version=\"2.0\">"; - echo "<channel>\n<title>$rss_main_title</title>\n"; - echo "<link>$web_path</link>\n<description>$rss_main_description</description>\n"; - echo "<copyright>$rss_main_copyright</copyright>"; - echo "<pubDate>$today</pubDate>\n<language>$rss_main_language</language>\n"; + + echo " <channel>\n <title>$rss_main_title</title>\n"; + echo " <link>$web_path</link>\n <description>$rss_main_description</description>\n"; + echo " <copyright>$rss_main_copyright</copyright>\n"; + echo " <pubDate>$today</pubDate>\n <language>$rss_main_language</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 "</channel>\n</rss>"; -} // show_now_playingRSS + break; +} +} ?> @@ -28,6 +28,7 @@ if (!conf('use_rss') || conf('demo_mode')) { access_denied(); } -show_now_playingRSS($_REQUEST['username']); +#show_now_playingRSS($_REQUEST['username']); +show_RSS($_REQUEST['type']); ?> diff --git a/templates/header.inc b/templates/header.inc index 2fbf47bc..7dce86b9 100644 --- a/templates/header.inc +++ b/templates/header.inc @@ -31,6 +31,11 @@ $location = get_location(); <?php if (conf('use_rss')) { ?> <link rel="alternate" type="application/rss+xml" title="<?php echo conf('rss_main_title'); ?>" href="<?php echo $web_path; ?>/rss.php" /> +<link rel="alternate" type="application/rss+xml" title="Ampache Latest Artists Additions" href="<?php echo $web_path; ?>/rss.php?type=latestartist" /> +<link rel="alternate" type="application/rss+xml" title="Ampache Latest Albums Additions" href="<?php echo $web_path; ?>/rss.php?type=latestalbum" /> +<link rel="alternate" type="application/rss+xml" title="Ampache Most Popular Albums" href="<?php echo $web_path; ?>/rss.php?type=popularalbum" /> +<link rel="alternate" type="application/rss+xml" title="Ampache Most Popular Artists" href="<?php echo $web_path; ?>/rss.php?type=popularalbum" /> +<link rel="alternate" type="application/rss+xml" title="Ampache Most Popular Songs" href="<?php echo $web_path; ?>/rss.php?type=popularsong" /> <?php } ?> <meta http-equiv="Content-Type" content="text/html; charset=<?php echo conf('site_charset'); ?>" /> <title><?php echo conf('site_title'); ?> - <?php echo $location['title']; ?></title> diff --git a/templates/show_mail_users.inc.php b/templates/show_mail_users.inc.php index b3d34f6e..ff9740c0 100644 --- a/templates/show_mail_users.inc.php +++ b/templates/show_mail_users.inc.php @@ -49,7 +49,7 @@ </tr> <tr> - <td><?php echo _('Newest Artist Additions'); ?>:</td> + <td><?php echo _('Latest Artist Additions'); ?>:</td> <td> <input type="checkbox" name="new_artists" value="yes" /> </td> @@ -60,7 +60,7 @@ </tr> <tr> - <td><?php echo _('Newest Album Additions'); ?>:</td> + <td><?php echo _('Latest Album Additions'); ?>:</td> <td> <input type="checkbox" name="new_albums" value="yes" /> </td> |