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 @@ +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 @@ +
+
+  Upcoming Concerts + [Toggle] +
+
+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 ''; + } +?> +
+
+ +" . $ConcertTitle . ""; +?> + +
  • - [Go to Thread]
  • + + + 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 @@ +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); + ?> +
    + +
    +
    +
    + +
    + +
    + Recently Played +
      + +
    • + - - +
    • + +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + + 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;