diff --git a/classes/class_lastfm.php b/classes/class_lastfm.php
new file mode 100644
index 00000000..d274ad23
--- /dev/null
+++ b/classes/class_lastfm.php
@@ -0,0 +1,117 @@
+
+define('LASTFM_API_URL', 'http://ws.audioscrobbler.com/2.0/?method=');
+
+class LastFM
+{
+ public static function get_artist_events($ArtistID, $Artist, $Limit = 15)
+ {
+ global $Cache;
+ $ArtistEvents = $Cache->get_value('artist_events_' . $ArtistID);
+ if (empty($ArtistEvents)) {
+ $ArtistEvents = self::lastfm_request("artist.getEvents", array("artist" => $Artist, "limit" => $Limit));
+ $Cache->cache_value('artist_events_' . $ArtistID, $ArtistEvents, 432000);
+ }
+ return $ArtistEvents;
+ }
+
+ public static function get_user_info($Username)
+ {
+ global $Cache;
+ $Response = $Cache->get_value('lastfm_user_info_' . $Username);
+ if (empty($Response)) {
+ $Response = self::lastfm_request("user.getInfo", array("user" => $Username));
+ $Cache->cache_value('lastfm_user_info_' . $Username, $Response, 86400);
+ }
+ return $Response;
+ }
+
+ public static function get_recent_tracks($Username, $Limit = 15)
+ {
+ global $Cache;
+ $Response = $Cache->get_value('lastfm_recent_tracks_' . $Username);
+ if (empty($Response)) {
+ $Response = self::lastfm_request("user.getRecentTracks", array("user" => $Username, "limit" => $Limit));
+ $Cache->cache_value('lastfm_recent_tracks_' . $Username, $Response, 7200);
+ }
+ return $Response;
+ }
+
+ public static function get_top_artists($Username, $Limit = 15)
+ {
+ global $Cache;
+ $Response = $Cache->get_value('lastfm_top_artists_' . $Username);
+ if (empty($Response)) {
+ $Response = self::lastfm_request("user.getTopArtists", array("user" => $Username, "limit" => $Limit));
+ $Cache->cache_value('lastfm_top_artists_' . $Username, $Response, 86400);
+ }
+ return $Response;
+ }
+
+ public static function get_top_albums($Username, $Limit = 15)
+ {
+ global $Cache;
+ $Response = $Cache->get_value('lastfm_top_albums_' . $Username);
+ if (empty($Response)) {
+ $Response = self::lastfm_request("user.getTopAlbums", array("user" => $Username, "limit" => $Limit));
+ $Cache->cache_value('lastfm_top_albums_' . $Username, $Response, 86400);
+ }
+ return $Response;
+ }
+
+ public static function get_top_tracks($Username, $Limit = 15)
+ {
+ global $Cache;
+ $Response = $Cache->get_value('lastfm_top_tracks_' . $Username);
+ if (empty($Response)) {
+ $Response = self::lastfm_request("user.getTopTracks", array("user" => $Username, "limit" => $Limit));
+ $Cache->cache_value('lastfm_top_tracks_' . $Username, $Response, 86400);
+ }
+ return $Response;
+ }
+
+ public static function compare_user_with($Username1, $Limit = 15)
+ {
+ global $Cache, $LoggedUser, $DB;
+ $DB->query("SELECT username FROM lastfm_users WHERE ID='$LoggedUser[ID]'");
+ if ($DB->record_count() > 0) {
+ list($Username2) = $DB->next_record();
+ //Make sure the usernames are in the correct order to avoid dupe cache keys.
+ if (strcasecmp($Username1, $Username2)) {
+ $Temp = $Username1;
+ $UsernameA = $Username2;
+ $Username1 = $Temp;
+ }
+ $Response = $Cache->get_value('lastfm_compare_' . $Username1 . '_' . $Username2);
+ if (empty($Response)) {
+ $Response = self::lastfm_request("tasteometer.compare", array("type1" => "user", "type2" => "user", "value1" => $Username1, "value2" => $Username2, "limit" => $Limit));
+ $Cache->cache_value('lastfm_compare_' . $Username1 . '_' . $Username2, $Response, 86400);
+ }
+ return $Response;
+ }
+ }
+
+ private static function lastfm_request($Method, $Args)
+ {
+ if (!defined('LASTFM_API_KEY')) {
+ return false;
+ }
+ $Url = LASTFM_API_URL . $Method;
+ if (is_array($Args)) {
+ foreach ($Args as $Key => $Value) {
+ $Url .= "&" . $Key . "=" . urlencode($Value);
+ }
+ $Url .= "&format=json&api_key=" . LASTFM_API_KEY;
+
+ $Curl = curl_init();
+ curl_setopt($Curl, CURLOPT_HEADER, 0);
+ curl_setopt($Curl, CURLOPT_CONNECTTIMEOUT, 30);
+ curl_setopt($Curl, CURLOPT_RETURNTRANSFER, 1);
+ curl_setopt($Curl, CURLOPT_URL, $Url);
+ $Return = curl_exec($Curl);
+ curl_close($Curl);
+ return json_decode($Return, true);
+ }
+ }
+}
+
+
diff --git a/gazelle.sql b/gazelle.sql
index 91b23c4c..89d46797 100644
--- a/gazelle.sql
+++ b/gazelle.sql
@@ -424,6 +424,12 @@ CREATE TABLE `ip_bans` (
KEY `ToIP` (`ToIP`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
+CREATE TABLE `lastfm_users` (
+ `ID` int(10) unsigned NOT NULL,
+ `Username` varchar(20) NOT NULL,
+ PRIMARY KEY (`ID`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+
CREATE TABLE `library_contest` (
`UserID` int(10) NOT NULL,
`TorrentID` int(10) NOT NULL,
diff --git a/sections/artist/concerts.php b/sections/artist/concerts.php
new file mode 100644
index 00000000..569218bc
--- /dev/null
+++ b/sections/artist/concerts.php
@@ -0,0 +1,123 @@
+
+
+
+
+ $ArtistEvents = LastFM::get_artist_events($ArtistID, $Name);
+ $Debug->log_var($ArtistEvents);
+ if ($ArtistEvents === false) { // Something went wrong
+ echo 'An error occurred when retrieving concert info.';
+ } elseif (!isset($ArtistEvents['events']['event'])) { // No upcoming events
+ echo 'This artist has no upcoming concerts.';
+ } else {
+ echo '
';
+ if (isset($ArtistEvents['events']['event'][0])) { // Multiple events
+ foreach ($ArtistEvents['events']['event'] as $Event) {
+ make_concert_link($Event);
+ }
+ } else { // Single event
+ make_concert_link($ArtistEvents['events']['event']);
+ }
+ echo '
';
+ }
+?>
+
+
+
+
+function make_concert_link($Event)
+{
+ // The event doesn't have a start date (this should never happen)
+ if ($Event['startDate'] == "") {
+ return;
+ }
+ $Date = get_date_title($Event['startDate']);
+ $ConcertTitle = $Date . " - " . $Event['venue']['name'] . " at " .
+ $Event['venue']['location']['city'] . ', ' . $Event['venue']['location']['country'];
+ $Concert = "" . $ConcertTitle . "";
+?>
+
+ =$Concert?> - [Go to Thread]
+
+}
+?>
+
+
+function get_concert_post_template($Artist, $Event)
+{
+ $With = "";
+ $EventTitle = "";
+ $Location = "";
+ $Directions = "";
+ $Website = "";
+ if (!empty($Event['venue']['website'])) {
+ $Url = $Event['venue']['website'];
+ if (strpos ($Url, '://') === false) {
+ $Url = 'http://' . $Url;
+ }
+ $EventTitle = "[url=" . $Event['venue']['website'] . "]" . $Event['venue']['name'] . "[/url]";
+ } else {
+ $EventTitle = $Event['venue']['name'];
+ }
+ if (!empty($Event['venue']['location']['street']) && !empty($Event['venue']['location']['street']) && !empty($Event['venue']['location']['street'])) {
+ $Location = $Event['venue']['location']['street'] . "\n" . $Event['venue']['location']['city'] . ", " . $Event['venue']['location']['country'];
+ }
+ if (!empty($Event['venue']['name']) && !empty($Event['venue']['city'])) {
+ $Directions = "[b]Directions:[/b] [url=https://maps.google.com/maps?f=q&q=" . urlencode($Event['venue']['name'] . "," . $Event['venue']['location']['city']) . "&ie=UTF8&om=1&iwloc=addr]Show on Map[/url]";
+ }
+ if (!empty($Event['venue']['website'])) {
+ $Url = $Event['venue']['website'];
+ if (strpos ($Url, '://') === false) {
+ $Url = 'http://' . $Url;
+ }
+ $Website = "[b]Website:[/b] " . $Url;
+ }
+ if (isset($Event['artists']['artist']) && (count($Event['artists']['artist']) == 1 && strtolower($Event['artists']['artist'][1]) == strtolower($Artist))) {
+ $i = 0;
+ $j = count($Event['artists']['artist']) - 1;
+ foreach ($Event['artists']['artist'] as $WithArtist) {
+ if ($i == $j) {
+ $With .= " and [artist]" . $WithArtist . "[/artist]";
+ } elseif ($i == 0) {
+ $With .= "[artist]" . $WithArtist . "[/artist]";
+ } else {
+ $With .= ", [artist]" . $WithArtist . "[/artist]";
+ }
+ $i++;
+ }
+ }
+ return "[align=center][size=6][artist]" . $Artist . "[/artist] at " . $EventTitle . "[/size]
+[size=4]" . $With . "
+[b]" . get_date_post($Event['startDate']) . "[/b][/size]
+
+[size=3]" . $Location . "[/align]
+
+" . $Directions . "
+" . $Website . "
+[b]Last.fm Listing:[/b] [url=" . $Event['venue']['url'] . "]Visit Last.fm[/url]
+
+[align=center]. . . . . . . . . .[/align]";
+}
+
+function get_date_title($Str)
+{
+ $Exploded = explode(' ', $Str);
+ $Date = $Exploded[2] . " " . $Exploded[1] . ", " . $Exploded[3];
+ return $Date;
+}
+
+function get_date_post($Str)
+{
+ $Exploded = explode(' ', $Str);
+ $Date = $Exploded[2] . " " . $Exploded[1] . ", " . $Exploded[3] . " (" . rtrim($Exploded[0], ',') . ")";
+ return $Date;
+}
+
+?>
diff --git a/sections/user/edit.php b/sections/user/edit.php
index ff40019e..d305f264 100644
--- a/sections/user/edit.php
+++ b/sections/user/edit.php
@@ -62,6 +62,10 @@ function checked($Checked) {
+$DB->query("SELECT username FROM lastfm_users WHERE ID = '$UserID'");
+$LastFMUsername = "";
+list($LastFMUsername) = $DB->next_record();
+
echo $Val->GenerateJS('userform');
?>
@@ -285,7 +289,12 @@ function checked($Checked) {
If changing this field, you must enter your current password in the "Current password" field before saving your changes.
-
+
+ Last.FM Username |
+
+ Your Last.FM username. Will be used to display Last.FM information on your profile which can be seen by other users.
+ |
+
Info |
diff --git a/sections/user/lastfm.php b/sections/user/lastfm.php
new file mode 100644
index 00000000..71868b24
--- /dev/null
+++ b/sections/user/lastfm.php
@@ -0,0 +1,58 @@
+
+$DB->query("SELECT username FROM lastfm_users WHERE ID = '$UserID'");
+if ($DB->record_count()) {
+ list($LastFMUsername) = $DB->next_record();
+ $LastFMInfo = LastFM::get_user_info($LastFMUsername);
+ $RecentTracks = LastFM::get_recent_tracks($LastFMUsername);
+ ?>
+
+
+ } ?>
diff --git a/sections/user/takeedit.php b/sections/user/takeedit.php
index d9cac25e..cd7866d7 100644
--- a/sections/user/takeedit.php
+++ b/sections/user/takeedit.php
@@ -229,6 +229,24 @@
$UnseededAlerts = (isset($_POST['unseededalerts']))? 1:0;
+
+$LastFMUsername = db_string($_POST['lastfm_username']);
+$OldLastFMUsername = "";
+$DB->query("SELECT username FROM lastfm_users WHERE ID = '$UserID'");
+if($DB->record_count() > 0) {
+ list($OldLastFMUsername) = $DB->next_record();
+ if($OldLastFMUsername != $LastFMUsername) {
+ if(empty($LastFMUsername)) {
+ $DB->query("DELETE FROM lastfm_users WHERE ID = '$UserID'");
+ } else {
+ $DB->query("UPDATE lastfm_users SET Username = '$LastFMUsername' WHERE ID = '$UserID'");
+ }
+ }
+}
+elseif(!empty($LastFMUsername)) {
+ $DB->query("INSERT INTO lastfm_users (ID, Username) VALUES ('$UserID', '$LastFMUsername')");
+}
+
// Information on how the user likes to download torrents is stored in cache
if($DownloadAlt != $LoggedUser['DownloadAlt']) {
$Cache->delete_value('user_'.$LoggedUser['torrent_pass']);
diff --git a/sections/user/user.php b/sections/user/user.php
index 841c5eeb..e85cb49d 100644
--- a/sections/user/user.php
+++ b/sections/user/user.php
@@ -627,6 +627,8 @@ function check_paranoia_here($Setting) {
$FirstCol = false;
}
+include(SERVER_ROOT.'/sections/user/lastfm.php');
+
// Linked accounts
diff --git a/static/functions/lastfm.js b/static/functions/lastfm.js
index 449e7fa8..96d7b80b 100644
--- a/static/functions/lastfm.js
+++ b/static/functions/lastfm.js
@@ -1,4 +1,4 @@
-//skipfile
+
(function ($) {
var TAB_COUNT = 0;
var topArtistsLoaded = false;