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

Commit b8952982 authored by tonyb486's avatar tonyb486

Added latest gobbles to profile page

parent 113db174
......@@ -22,6 +22,7 @@
require_once($install_path . '/database.php');
require_once($install_path . "/data/sanitize.php");
require_once($install_path . "/utils/human-time.php");
/**
* Represents User data
......@@ -52,12 +53,16 @@ class User {
$this->bio = $row["bio"];
$this->location = $row["location"];
}
$this->getscrobbles(10);
}
function getgobbles($number) {
$res = $mdb2->query("SELECT "); /* stub for now */
function getscrobbles($number) {
global $mdb2;
$res = $mdb2->query("SELECT * FROM Scrobbles WHERE username = " .$mdb2->quote($this->name, "text") . " LIMIT ".$mdb2->quote($number, "integer"));
$data = $res->fetchAll(MDB2_FETCHMODE_ASSOC);
foreach($data as &$i) {
$i["timehuman"] = human_timestamp($i["time"]);
}
return $data;
}
}
......@@ -39,6 +39,7 @@ if(isset($user->name)) {
$smarty->assign("bio", $user->bio);
$smarty->assign("homepage", $user->homepage);
$smarty->assign("location", $user->location);
$smarty->assign("scrobbles", $user->getscrobbles(10));
$smarty->display("profile.tpl");
} else {
$smarty->assign("error", "User not found");
......
......@@ -42,11 +42,11 @@ html, body, #doc3,h1{margin: 0; padding: 0; font-family: Liberation Sans, Verdan
#main {
padding-left: 215px;
width: 770px;
}
h2 {
font-size: 2em;
margin-bottom: 5px;
}
.yui-b, #ft{padding: 1em;}
......
......@@ -6,4 +6,20 @@ Real Name: {$fullname} <br />
Homepage: {$homepage} <br />
Location: {$location} <br />
Bio: {$bio} <br />
<hr>
<b>Latest 10 Gobbles:</b>
<ul id="scrobbles" class="listcloud">
{section name=i loop=$scrobbles}
<li>
<dl>
<dt><a href="artist.php?artist={$scrobbles[i].artist|stripslashes|urlencode}">
{$scrobbles[i].artist|stripslashes}</a></dt>
<dd>{$scrobbles[i].track|stripslashes}<br /><small>{$scrobbles[i].timehuman}</small></dd>
</dl>
</li>
{/section}
</ul>
{include file='footer.tpl'}
<?php
/* Libre.fm -- a free network service for sharing your music listening habits
Copyright (C) 2009 Libre.fm Project
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* Humanized timestamps
*/
function human_timestamp ($unix_timestamp, $now = null) {
if (is_null($now)) {
$now = time();
}
$diff = $now - $unix_timestamp;
# ugly!
$number_to_alpha = array(
'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten',
'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen', 'twenty',
'twenty-one', 'twenty-two', 'twenty-three', 'twenty-four', 'twenty-six', 'twenty-seven', 'twenty-eight', 'twenty-nine', 'thirty',
'thirty-one', 'thirty-two', 'thirty-three', 'thirty-four', 'thirty-five', 'thirty-six', 'thirty-seven', 'thirty-eight', 'thirty-nine',
'fourty-one', 'fourty-two', 'fourty-three', 'fourty-four', 'fourty-five', 'fourty-six', 'fourty-seven', 'fourty-eight', 'fourty-nine',
'fifty-one', 'fifty-two', 'fifty-three', 'fifty-four', 'fifty-five', 'fifty-six', 'fifty-seven', 'fifty-eight', 'fifty-nine'
);
switch ($unix_timestamp) {
case ($now < $unix_timestamp):
return 'in the future (?)';
break;
case ($diff == 1):
# one second
return 'a second ago';
break;
case ($diff < 60):
# less than a minute
return $diff . ' seconds ago';
break;
case ($diff < 120):
# between a minute and two
return 'about a minute ago';
break;
case ($diff < 3600):
# less than an hour
return round($diff / 60) . ' minutes ago';
break;
case ($diff < 7200):
# between an hour and two
return 'about an hour ago';
break;
case ($diff < 86400):
# less than a day
return round($diff / 3600) . ' hours ago';
break;
case ($diff < 172800):
# less than two days
return 'about a day ago';
break;
case ($diff < 604800):
# less than a week
return round($diff / 86400) . ' days ago';
break;
case ($diff < 691200):
# a week an a day
return 'about a week ago';
break;
case ($diff < 2764800):
# less than a month
return round($diff / 691200) . ' weeks ago';
break;
case ($diff < 4579200):
# a month and three weeks
return 'about a month ago';
break;
case ($diff < 33177600);
# less than a year
return round($diff / 2764800) . ' months ago';
break;
case ($diff < 35942400):
# a year and a month
return 'about a year ago';
break;
case ($diff > 35942400):
return 'more than a year ago';
break;
}
}
?>
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