We are no longer offering accounts on this server. Consider https://gitlab.freedesktop.org/ as a place to host projects.

Commit db5ab01a authored by tonyb486's avatar tonyb486

Made tag cloud happy again

parent 433cba41
......@@ -30,50 +30,27 @@ class TagCloud {
* @param float $max_font_size maximum font size (px, em, %, etc)
* @return array tagcloud
*/
#function __construct($table, $field, $limit = 40, $sizes = 6, $max_font_size = 3, $username = null) {
function __construct($table, $field, $limit = 40, $username = null) {
static function generateTagCloud($table, $field, $limit = 40, $username = null) {
global $mdb2;
if (!is_string($field)) return false;
if (!is_string($field)) return false;
if (!is_string($table)) return false;
if (!is_integer($limit)) return false;
# if (!is_integer($sizes)) return false;
# if (!is_numeric($max_font_size)) return false;
global $mdb2;
$sizes = array('xx-large', 'x-large', 'large', 'medium', 'small', 'x-small', 'xx-small');
$query = "SELECT $field, count(*) AS count FROM $table";
$query .= (!is_null($username)) ? ' WHERE username = ' . $mdb2->quote($username, 'text') : null;
$query .= " GROUP BY $field ORDER BY count DESC LIMIT $limit";
$res = $mdb2->query($query);
if (!$res->numRows()) {
return false;
return false;
} else {
$this->tagcloud = $res->FetchAll(MDB2_FETCHMODE_ASSOC);
$this->min = end($this->tagcloud);
$this->max = reset($this->tagcloud);
# scramble results
shuffle($this->tagcloud);
# creates a range of possible font sizes
# $range_of_sizes = range(0, $max_font_size, round($max_font_size / $sizes));
$range_of_sizes = array('xx-small', 'x-small', 'small', 'medium', 'large', 'x-large', 'xx-large');
foreach ($this->tagcloud as $row => &$data) {
# gets a size from range_of_sizes
$data['size'] = $range_of_sizes[floor(((count($range_of_sizes) - 1) * $data['count']) / $this->max['count'])];
$data[$field] = stripslashes($data[$field]);
}
$res = null;
unset($res);
$data = $res->fetchAll(MDB2_FETCHMODE_ASSOC);
foreach($data as $count => &$i) {
$i['size'] = $sizes[(int) ($count/(count($data)/7))];
}
sort($data);
return $data;
}
}
function __destruct() {
unset($this->max, $this->min, $range_of_sizes, $data, $this->tagcloud);
}
}
?>
......@@ -87,26 +87,6 @@ class User {
}
/**
* Get a user's top artists
*
* @return An array of artists for the top 40 artists
* with a percent field, which represents each
* artists position in the cloud.
*/
function getTagCloud() {
global $mdb2;
$res = $mdb2->query(" SELECT artist, count(artist) AS count FROM Scrobbles WHERE "
. 'username = ' . $mdb2->quote($this->name, 'text')
. " GROUP BY artist ORDER BY count DESC LIMIT 40");
$data= $res->fetchAll(MDB2_FETCHMODE_ASSOC);
foreach($data as $count => &$i) {
$i['percent'] = (int) ($count/(count($data)/5)+1);
}
sort($data);
return $data;
}
/**
* Get a user's now-playing tracks
*
......
......@@ -25,8 +25,8 @@ require_once('data/sanitize.php');
require_once('data/Server.php');
require_once('data/TagCloud.php');
$tagcloud = new TagCloud('Scrobbles', 'artist');
$smarty->assign('tagcloud', $tagcloud->tagcloud);
$smarty->assign('tagcloud', TagCloud::GenerateTagCloud('Scrobbles', 'artist'));
$smarty->assign('recenttracks', Server::getRecentScrobbles(20));
$smarty->assign('nowplaying', Server::getNowPlaying(10));
$smarty->assign('welcome', true);
......
......@@ -32,7 +32,6 @@ if(!isset($_GET['user']) && $logged_in == false) {
}
$user = new User($_GET['user']);
$user_tagcloud = new TagCloud('Scrobbles', 'artist', 40, $_GET['user']);
if(isset($user->name)) {
$smarty->assign('user', $user->name);
......@@ -45,7 +44,7 @@ if(isset($user->name)) {
$smarty->assign('userlevel', $user->userlevel);
$smarty->assign('avatar', $user->getAvatar());
$smarty->assign('nowplaying', $user->getNowPlaying(10));
$smarty->assign('user_tagcloud', $user_tagcloud->tagcloud);
$smarty->assign('user_tagcloud', TagCloud::GenerateTagCloud('Scrobbles', 'artist', 40, $user->name));
$smarty->assign('profile', true);
$smarty->display('profile.tpl');
} else {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment