display.php 7.63 KB
Newer Older
mattl's avatar
mattl committed
1
<?php
jurgbohn's avatar
jurgbohn committed
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/* 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/>.

*/

mattl's avatar
mattl committed
21 22 23 24
header('Content-type: text/html; charset=utf-8');
require_once('database.php');
require_once('utils/human-time.php');
?>
mattl's avatar
mattl committed
25 26 27 28
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
 "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
mattl's avatar
mattl committed
29
   <title>Libre.fm &mdash; discover new music</title>
30 31 32
   <link rel="stylesheet" href="/reset-fonts-grids.css" type="text/css">
   <link rel="stylesheet" href="/base.css" type="text/css">
   <link rel="stylesheet" href="/librefm.css" type="text/css">
mattl's avatar
mattl committed
33 34
</head>
<body>
mattl's avatar
mattl committed
35 36 37 38 39 40 41 42 43 44 45
<div id="doc2" class="yui-t7">
   <div id="hd" role="navigation"><h1><a href="/">Header</a></h1>

     <ul>
       <li><a href="https://savannah.nongnu.org/svn/?group=librefm">Code</a></li>
       <li><a href="http://blog.libre.fm/">Blog</a></li>
       <li><a href="http://ideas.libre.fm/">Wiki</a></li>
       <li><a href="http://lists.autonomo.us/mailman/listinfo/libre-fm">List</a></li>
       <li><a href="https://savannah.nongnu.org/bugs/?group=librefm">Bugs</a></li>
       <li id="login"><a href="http://alpha.libre.fm/login.php">Log in</a></li>
     </ul>
46

mattl's avatar
mattl committed
47 48 49
   </div>
   <div id="bd" role="main">
   <div id="coolio">
Daniel Watkins's avatar
Daniel Watkins committed
50
	<div class="yui-g">
51
	  <a href="http://alpha.libre.fm/"><img src="http://alpha.libre.fm/themes/librefm/images/topblocksmall.png" alt="" /></a>
mattl's avatar
mattl committed
52 53 54 55
	</div>
<div class="yui-gc">
    <div class="yui-u first" id="content">
    <div style="padding: 10px;">
56
		<?php
mattl's avatar
mattl committed
57

58 59 60
$req_user	= urldecode($_GET["u"]);
$req_artist	= urldecode($_GET["a"]);
$req_track	= urldecode($_GET["t"]);
mattl's avatar
mattl committed
61 62


63 64 65
if ($req_user) {
//			echo "SELECT username, artist, track, time FROM Scrobbles WHERE username = '" . $mdb2->quote($req_user, 'text') . "' ORDER BY time DESC LIMIT 100";
			$res = $mdb2->query("SELECT username, artist, track, time FROM Scrobbles WHERE username = " . $mdb2->quote($req_user, 'text') . " ORDER BY time DESC LIMIT 100");
66

mattl's avatar
mattl committed
67
			echo "<h2>" . $req_user . "'s most recent listening data</h2>";
mattl's avatar
mattl committed
68 69 70

} elseif ($req_artist) {

71
			$res = $mdb2->query("SELECT username, artist, track, time FROM Scrobbles WHERE artist = '" . $mdb2->quote($req_artist, 'text') ."' ORDER BY time DESC LIMIT 100");
72

mattl's avatar
mattl committed
73
			echo "<h2>Last 100 Tracks by " . $req_artist . "</h2>";
74

mattl's avatar
mattl committed
75 76
} elseif ($req_track) {

77
			$res = $mdb2->query("SELECT username, artist, track, time FROM Scrobbles WHERE track = '" . $mdb2->quote($req_track, 'text') . "' ORDER BY time DESC LIMIT 100");
78

mattl's avatar
mattl committed
79
			echo "<h2>Last 100 plays of " . $req_track . "</h2>";
80

mattl's avatar
mattl committed
81 82
} elseif (!$res) {

mattl's avatar
mattl committed
83
			$res = $mdb2->query("SELECT username, artist, track, time FROM Scrobbles ORDER BY time DESC LIMIT 10");
mattl's avatar
mattl committed
84

mattl's avatar
mattl committed
85
			echo "<h2>Last 10 tracks received</h2>";
mattl's avatar
mattl committed
86

mattl's avatar
mattl committed
87 88
}

mattl's avatar
mattl committed
89 90 91 92
?>

		<table>
			<tr><th>User</th><th>Artist</th><th>Track</th><th>Time</th></tr>
93

mattl's avatar
mattl committed
94 95
<?php

96 97 98
			if(PEAR::isError($res)) {
				die($res->getMessage());
			}
clint's avatar
clint committed
99
			$i = 0;
100
			while($row = $res->fetchRow(MDB2_FETCHMODE_ASSOC)) {
clint's avatar
clint committed
101
			$i++;
mattl's avatar
mattl committed
102
				echo ($i % 2 == 0) ? "<tr class=\"even\">" : "<tr class=\"odd\">";
103
				foreach($row as $field => $value) {
mattl's avatar
mattl committed
104
					if($field == "username"){
105
					$value = "<a href=\"/user/" . $value . "\">$value</a>";}
106
					if($field == "time") {
107
						$value = '<abbr title=\'' . strftime('%c', $value) . '\'>' . human_timestamp($value) . '</abbr>';
108
					}
109
					echo "<td>". strip_tags(stripslashes($value)) . "</td>";
110
				}
clint's avatar
clint committed
111
				echo "</tr>\n";
112 113 114 115
			}

		?>
		</table>
116

mattl's avatar
mattl committed
117 118 119 120
    </div></div>
    <div class="yui-u" id="sidebar">
    <div style="padding: 10px;">

121 122 123 124 125 126 127
		<h2>Statistics</h2>

		<?php
			$res = $mdb2->query("SELECT COUNT(*) as total from Scrobbles");
			if(PEAR::isError($res)) {
				die($res->getMessage());
			}
clint's avatar
ouch  
clint committed
128
			$row = $res->fetchRow(MDB2_FETCHMODE_ASSOC);
clint's avatar
clint committed
129
			echo "<p>" . stripslashes($row["total"]) . " gobbles.</p>";
130 131 132 133 134

			$res = $mdb2->query("SELECT COUNT(*) as total from Track");
			if(PEAR::isError($res)) {
				die($res->getMessage());
			}
clint's avatar
clint committed
135 136
			$row = $res->fetchRow(MDB2_FETCHMODE_ASSOC);
			echo "<p>" . stripslashes($row["total"]) . " tracks.</p>";
clint's avatar
clint committed
137 138 139 140 141 142 143 144

			$res = $mdb2->query("SELECT COUNT(*) as total from Users");
			if(PEAR::isError($res)) {
				die($res->getMessage());
			}
			$row = $res->fetchRow(MDB2_FETCHMODE_ASSOC);
			echo "<p>" . stripslashes($row["total"]) . " users.</p>";

145
		?>
mattl's avatar
mattl committed
146

mattl's avatar
mattl committed
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
		<h2>Now Playing?</h2>

		<?php
			$res = $mdb2->query("SELECT username, artist, track, client, ClientCodes.name, ClientCodes.url from Now_Playing LEFT OUTER JOIN Scrobble_Sessions ON Now_Playing.sessionid=Scrobble_Sessions.sessionid LEFT OUTER JOIN ClientCodes ON Scrobble_Sessions.client=ClientCodes.code ORDER BY Now_Playing.expires DESC LIMIT 10");
			if(PEAR::isError($res)) {
				die($res->getMessage());
			}
			while($row = $res->fetchRow(MDB2_FETCHMODE_ASSOC)) {
				if($row["name"] == "") {
				  $client = strip_tags(stripslashes($row["client"])) . "(unknown, please tell us what this is)";
				} else {
				  $client = "<a href=\"" . strip_tags(stripslashes($row["url"])) . "\">" . strip_tags(stripslashes($row["name"])) . "</a>";
				}
				echo "<p>" . strip_tags(stripslashes($row["username"])) . " is listening to " . strip_tags(stripslashes($row["track"])) . " by " . strip_tags(stripslashes($row["artist"])) . " with " . $client . "</p>";
			}
		?>

mattl's avatar
mattl committed
164

165

mattl's avatar
mattl committed
166 167 168 169 170 171 172 173 174 175
    </div></div>
</div></div>
<div class="yui-g" id="artists">

  <strong><a href="http://libre.fm/contact/">Talk to us</a></strong> if you're in a band, represent a
  label or music service, we'd like to talk ideas and
  possibilities. While our intention is eventually provide download
  and streaming services for freely-licensed music, we are also
  interested in linking all bands to respectable DRM-free music
  services.
176

mattl's avatar
mattl committed
177
</div>
mattl's avatar
mattl committed
178 179 180
<div class="yui-g">
    <div class="yui-u first" id="links">
This site handles <em>gobble</em> and <em>now playing</em>
mattl's avatar
mattl committed
181 182 183 184 185
submissions from client applications and offers access to our web
services API. If you just want to use <a
href="http://libre.fm">libre.fm</a> then you probably want to
visit the <a href="http://libre.fm">main site</a>, but if you're
a developer then here are some useful stats to help you see
mattl's avatar
mattl committed
186 187 188 189 190 191
what's happening.
</div>
    <div class="yui-u" id="moarlinks">
<a href="http://www.gnu.org/licenses/agpl.html">GNU Affero General Public License v3 or later</a>. Source: <a href="http://svn.savannah.gnu.org/viewvc/trunk/gobbler/?root=librefm">http://svn.savannah.gnu.org/viewvc/trunk/gobbler/?root=librefm</a>
</div>
</div>
mattl's avatar
mattl committed
192

mattl's avatar
mattl committed
193 194 195 196 197 198 199 200 201 202 203 204
	</div>
   <div id="ft" role="navigation">

     <ul>
       <li class="copy">&copy; 2009 Libre.fm Project</li>
       <li><a href="http://libre.fm/contributors/">Contributors</a></li>
       <li><a href="http://libre.fm/licensing/">Licensing information</a></li>
       <li><a href="http://libre.fm/developer/">Developers</a></li>
       <li><a href="http://libre.fm/api/">API</a></li>
       <li><a href="http://libre.fm/download/">Download</a></li>
     </ul>

mattl's avatar
mattl committed
205 206 207 208 209
     <ul>
     <li><a href="http://foocorp.org">A FooCorp thing</a></li>
     <li><a href="http://autonomo.us/">autonomo.us</a></li>
     </ul>

mattl's avatar
mattl committed
210
     <p><img src="http://libre.fm/i/cc-by-sa.png" alt="Attribution-ShareAlike 3.0" /></p>
mattl's avatar
mattl committed
211

212
<p><a href="/data">Data dumps are here</a></p>
mattl's avatar
mattl committed
213

mattl's avatar
mattl committed
214
   </div>
mattl's avatar
mattl committed
215 216 217
</div>
</body>
</html>
mattl's avatar
mattl committed
218