Browse Source

top artits & tracks

main
n 7 years ago
parent
commit
df0f7a5186
  1. 36
      plugins/function.topartists.php
  2. 36
      plugins/function.toptracks.php
  3. 16
      templates/user-profile.tpl

36
plugins/function.topartists.php

@ -0,0 +1,36 @@
<?php
/*
* Smarty plugin
* -------------------------------------------------------------
* File: function.artisttracks.php
* Type: function
* Name: artisttracks
* Purpose: outputs an array of tracks by $artist
* -------------------------------------------------------------
*/
function smarty_function_topartists($params, $template) {
/**
* Retrieves a list of tracks
*
* @param string $artist The name of the artist (required)
* @param string $album The name of the album (optional)
* @return array artisttracks
*/
global $adodb;
$query = 'SELECT artist AS name,COUNT(artist) AS plays FROM Scrobbles WHERE time > '.strtotime("-3 month").' GROUP BY artist ORDER BY COUNT(artist) DESC LIMIT 15';
$data = $adodb->CacheGetAll(600, $query);
/*foreach($data as &$item) {
$item['trackurl'] = Server::getTrackURL($artist, null, $item['track']);
if (!$item['image']) {
$item['image'] = $default_album_image;
} else {
$item['image'] = resolve_external_url($item['image']);
}
}*/
$template->assign(topartists, $data);
}
?>

36
plugins/function.toptracks.php

@ -0,0 +1,36 @@
<?php
/*
* Smarty plugin
* -------------------------------------------------------------
* File: function.artisttracks.php
* Type: function
* Name: artisttracks
* Purpose: outputs an array of tracks by $artist
* -------------------------------------------------------------
*/
function smarty_function_toptracks($params, $template) {
/**
* Retrieves a list of tracks
*
* @param string $artist The name of the artist (required)
* @param string $album The name of the album (optional)
* @return array artisttracks
*/
global $adodb;
$query = 'SELECT artist AS artist,track AS name,count(track) AS plays FROM Scrobbles WHERE time > '.strtotime("-3 month").' GROUP BY track ORDER BY COUNT(track) DESC LIMIT 15';
$data = $adodb->CacheGetAll(600, $query);
/*foreach($data as &$item) {
$item['trackurl'] = Server::getTrackURL($artist, null, $item['track']);
if (!$item['image']) {
$item['image'] = $default_album_image;
} else {
$item['image'] = resolve_external_url($item['image']);
}
}*/
$template->assign(toptracks, $data);
}
?>

16
templates/user-profile.tpl

@ -19,6 +19,22 @@
<h3>Recent plays</h3>
{include file="tracklist.tpl" class=#table# items=$userscrobbles fimage=true fstream=true fartist=true flove=true ftime=true}
{topartists userid=$me->uniqueid limit=10}
<h3>Top Artists</h3>
<ul>
{section name=i loop=$topartists}
<li>{$topartists[i].name} {$topartists[i].plays}</li>
{/section}
</ul>
{toptracks userid=$me->uniqueid limit=10}
<h3>Top Tracks</h3>
<ul>
{section name=i loop=$toptracks}
<li>{$toptracks[i].artist} - {$toptracks[i].name} {$toptracks[i].plays}</li>
{/section}
</ul>
{if !empty($lovedArtists)}
<br />
<h3>{t name=$me->name}Free artists that %1 loves{/t}</h3>

Loading…
Cancel
Save