summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorpb1dft <pb1dft@ampache>2007-03-03 22:40:21 +0000
committerpb1dft <pb1dft@ampache>2007-03-03 22:40:21 +0000
commitdec762fe5d70ff85a4de4f26c25bfb4a53811805 (patch)
tree2fa53d17562f06a1e2e0eef48fae6571777dce54 /lib
parentf9e3b1360f40ada7645d6fdd0be6ee6c721269a0 (diff)
downloadampache-dec762fe5d70ff85a4de4f26c25bfb4a53811805.tar.gz
ampache-dec762fe5d70ff85a4de4f26c25bfb4a53811805.tar.bz2
ampache-dec762fe5d70ff85a4de4f26c25bfb4a53811805.zip
Changed/Added rss stuffie updated main config, Rewrote some off the statistics to use an array
Diffstat (limited to 'lib')
-rw-r--r--lib/class/user.class.php8
-rw-r--r--lib/general.lib.php49
-rw-r--r--lib/rss.php83
-rw-r--r--lib/ui.lib.php2
4 files changed, 83 insertions, 59 deletions
diff --git a/lib/class/user.class.php b/lib/class/user.class.php
index 804a5819..dfd50222 100644
--- a/lib/class/user.class.php
+++ b/lib/class/user.class.php
@@ -652,7 +652,7 @@ class User {
// The length of the longest item
$maxlen = strlen($items[0]->count);
-
+
// Go through the favs
foreach ($items as $data) {
@@ -663,11 +663,11 @@ class User {
$len++;
}
- $results[] = "<li>[$data->count] - $data->f_name</li>\n";
-
+ $item = "[$data->count] - $data->f_name";
+ $results[]->link = $item;
} // end foreach items
- return $results;
+ return $results;
} // format_favorites
diff --git a/lib/general.lib.php b/lib/general.lib.php
index f0f637b4..cb4a1dea 100644
--- a/lib/general.lib.php
+++ b/lib/general.lib.php
@@ -611,40 +611,43 @@ function get_global_popular($type) {
/* If Songs */
if ( $type == 'song' ) {
$song = new Song($r['object_id']);
- $artist = $song->get_artist_name();
- $text = "$artist - $song->title";
+ $song->format_song();
+ $text = "$song->f_artist_full - $song->title";
/* Add to array */
- $items[] = "<li> <a href=\"$web_path/song.php?action=single_song&amp;song_id=$song->id\" title=\"". scrub_out($text) ."\">" .
- scrub_out(truncate_with_ellipse($text, conf('ellipse_threshold_title')+3)) . "&nbsp;(" . $r['count'] . ")</a> </li>";
+ $song->link = "<a href=\"$web_path/song.php?action=single_song&amp;song_id=$song->id\" title=\"". scrub_out($text) ."\">" .
+ scrub_out(truncate_with_ellipse($text, conf('ellipse_threshold_title')+3)) . "&nbsp;(" . $r['count'] . ")</a>";
+ $items[] = $song;
} // if it's a song
/* If Artist */
elseif ( $type == 'artist' ) {
- $artist_obj = new Artist($r['object_id']);
- $artist_obj->format_artist();
- $artist = $artist_obj->full_name;
- $items[] = "<li> <a href=\"$web_path/artists.php?action=show&amp;artist=" . $r['object_id'] . "\" title=\"". scrub_out($artist) ."\">" .
- truncate_with_ellipse($artist, conf('ellipse_threshold_artist')+3) . "&nbsp;(" . $r['count'] . ")</a> </li>";
+ $artist = new Artist($r['object_id']);
+ $artist->format_artist();
+ $artist->link = "<a href=\"$web_path/artists.php?action=show&amp;artist=" . $r['object_id'] . "\" title=\"". scrub_out($artist->full_name) ."\">" .
+ truncate_with_ellipse($artist->full_name, conf('ellipse_threshold_artist')+3) . "&nbsp;(" . $r['count'] . ")</a>";
+ $items[] = $artist;
} // if type isn't artist
/* If Album */
elseif ( $type == 'album' ) {
$album = new Album($r['object_id']);
- $items[] = "<li> <a href=\"$web_path/albums.php?action=show&amp;album=" . $r['object_id'] . "\" title=\"". scrub_out($album->name) ."\">" .
- scrub_out(truncate_with_ellipse($album->name,conf('ellipse_threshold_album')+3)) . "&nbsp;(" . $r['count'] . ")</a> </li>";
+ $album->link = "<a href=\"$web_path/albums.php?action=show&amp;album=" . $r['object_id'] . "\" title=\"". scrub_out($album->name) ."\">" .
+ scrub_out(truncate_with_ellipse($album->name,conf('ellipse_threshold_album')+3)) . "&nbsp;(" . $r['count'] . ")</a>";
+ $items[] = $album;
} // else not album
elseif ($type == 'genre') {
$genre = new Genre($r['object_id']);
- $items[] = "<li> <a href=\"$web_path/browse.php?action=genre&amp;genre=" . $r['object_id'] . "\" title=\"" . scrub_out($genre->name) . "\">" .
- scrub_out(truncate_with_ellipse($genre->name,conf('ellipse_threshold_title')+3)) . "&nbsp;(" . $r['count'] . ")</a> </li>";
+ $genre->link = "<a href=\"$web_path/browse.php?action=genre&amp;genre=" . $r['object_id'] . "\" title=\"" . scrub_out($genre->name) . "\">" .
+ scrub_out(truncate_with_ellipse($genre->name,conf('ellipse_threshold_title')+3)) . "&nbsp;(" . $r['count'] . ")</a>";
+ $items[] = $genre;
} // end if genre
} // end foreach
- if (count($items) == 0) {
- $items[] = "<li style=\"list-style-type: none\"><span class=\"error\">" . _('Not Enough Data') . "</span></li>\n";
+/* if (count($items) == 0) {
+ $itemis[''] = "<li style=\"list-style-type: none\"><span class=\"error\">" . _('Not Enough Data') . "</span></li>\n";
}
-
+ */
return $items;
} // get_global_popular
@@ -667,20 +670,22 @@ function get_newest ($type = 'artist',$limit='') {
$db_result = mysql_query($sql, $dbh);
$items = array();
- $web_path = conf('web_path');
- while ( $item = mysql_fetch_row($db_result) ) {
+ while ($r = mysql_fetch_array($db_result)) {
if ( $type == 'artist' ) {
- $artist = new Artist($item[0]);
+ $artist = new Artist($r[0]);
$artist->format_artist();
- $items[] = "<li>" . $artist->link . "</li>\n";
+ $items[] = $artist;
+
}
elseif ( $type == 'album' ) {
- $album = new Album($item[0]);
+ $album = new Album($r[0]);
$album->format();
- $items[] = "<li>$album->f_link</li>";
+ $album->link = $album->f_link;
+ $items[] = $album;
}
}
+
return $items;
} // get_newest
diff --git a/lib/rss.php b/lib/rss.php
index a835c585..0252aa6a 100644
--- a/lib/rss.php
+++ b/lib/rss.php
@@ -31,22 +31,16 @@ function show_RSS ($type = 'artist',$username = 0) {
$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_recentlyplayed_title = "Ampache Recently Played";
$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");
@@ -68,7 +62,7 @@ switch ($type) {
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";
+ echo " <pubDate>$today</pubDate>\n";
while ( $r = @mysql_fetch_object($db_result) ) {
echo "<item>\n";
@@ -95,7 +89,7 @@ switch ($type) {
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";
+ echo " <pubDate>$today</pubDate>\n";
while ( $r = @mysql_fetch_object($db_result) ) {
echo "<item>\n";
@@ -122,7 +116,7 @@ switch ($type) {
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";
+ echo " <pubDate>$today</pubDate>\n";
while ( $r = @mysql_fetch_object($db_result) ) {
echo "<item>\n";
@@ -146,7 +140,7 @@ switch ($type) {
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";
+ echo " <pubDate>$today</pubDate>\n";
while ( $item = mysql_fetch_row($db_result) ) {
@@ -168,13 +162,11 @@ switch ($type) {
$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";
-
+ echo " <pubDate>$today</pubDate>\n";
+
while ( $item = mysql_fetch_row($db_result) ) {
echo "<item>\n";
@@ -188,42 +180,69 @@ switch ($type) {
echo "</channel>\n</rss>";
break;
- default:
+ case "recentlyplayed":
+
+ $time_unit = array('',_('seconds ago'),_('minutes ago'),_('hours ago'),_('days ago'),_('weeks ago'),_('months ago'),_('years ago'));
+ $recent = get_recently_played();
+
+ echo " <channel>\n <title>$rss_recentlyplayed_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";
+
+ foreach ( $recent as $item ){
+ $amount = intval(time() - $item['date']+2);
+ $time_place = '0';
+
+ while ($amount >= 1) {
+ $final = $amount;
+ $time_place++;
+ $amount = floor($amount/60);
+ }
- if ($username) {
- $user = get_user_from_username($username);
- $constraint = " WHERE user='" . sql_escape($user->username) . "' ";
+ $time_string = $final . ' ' . $time_unit[$time_place];
+
+ echo "<item>\n";
+ $song = new Song($item['object_id']);
+ $song->format_song();
+ $user = new User($item['user']);
+ $user->format_user();
+ echo " <title><![CDATA[$song->title]]></title>\n";
+ echo " <link>$web_path/songs.php?action=single_song&amp;song_id=".$item['object_id']."</link>\n";
+ echo " <description><![CDATA[$user->fullname played $song->title - $song->f_artist $time_string]]></description>\n";
+ echo "</item>\n";
}
+ echo "</channel>\n</rss>";
+ break;
+
- $sql = "SELECT * FROM now_playing $constraint ORDER BY start_time DESC";
-
- $db_result = mysql_query($sql, $dbh);
+ default:
+ $now_playing = get_now_playing();
$rss_song_description = $rss_description;
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";
+ echo " <pubDate>$today</pubDate>\n";
- while ($r = mysql_fetch_object($db_result)) {
- $song = new Song($r->song_id);
- $song->format_song();
+ foreach ( $now_playing as $r ){
- if (is_object($song)) {
+ $song = $r['song'];
+ $user = $r['user'];
+ $song->format_song();
$artist = $song->f_artist;
$album = $song->get_album_name();
- $text = "$artist - $song->f_title played by $r->user";
+ $text = "$artist - $song->f_title played by $user->fullname";
echo "<item> \n";
echo " <title><![CDATA[$text]]></title> \n";
echo " <image>$web_path/image.php?id=$song->album</image>\n";
echo " <link>$web_path/albums.php?action=show&amp;album=$song->album</link>\n";
- echo " <description><![CDATA[$song->f_title @ $album is played by $r->user]]></description>\n";
+ echo " <description><![CDATA[$song->f_title @ $album is played by $user->fullname]]></description>\n";
echo " <pubDate>$today</pubDate>\n";
echo "</item>\n";
- }
}
-
+
echo "</channel>\n</rss>";
break;
}
diff --git a/lib/ui.lib.php b/lib/ui.lib.php
index 8a928e3b..e86aa185 100644
--- a/lib/ui.lib.php
+++ b/lib/ui.lib.php
@@ -296,7 +296,7 @@ function show_play_selected() {
*/
function get_now_playing($filter='') {
- $sql = "SELECT song_id,user FROM now_playing ORDER BY start_time DESC";
+ $sql = "SELECT song_id,user FROM now_playing ORDER BY id DESC";
$db_results = mysql_query($sql, dbh());
$results = array();