Empty commit

This commit is contained in:
Git 2013-01-02 08:00:26 +00:00
parent 1fed668f74
commit f6023f377e
8 changed files with 335 additions and 2 deletions

117
classes/class_lastfm.php Normal file
View File

@ -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);
}
}
}

View File

@ -424,6 +424,12 @@ CREATE TABLE `ip_bans` (
KEY `ToIP` (`ToIP`) KEY `ToIP` (`ToIP`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1; ) 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` ( CREATE TABLE `library_contest` (
`UserID` int(10) NOT NULL, `UserID` int(10) NOT NULL,
`TorrentID` int(10) NOT NULL, `TorrentID` int(10) NOT NULL,

View File

@ -0,0 +1,123 @@
<div class="box">
<div id="concerts" class="head">
<a href="#">&uarr;</a>&nbsp;<strong>Upcoming Concerts</strong>
<a href="#" onclick="$('#concertsbody').toggle(); return false;">[Toggle]</a>
</div>
<div id="concertsbody">
<?
$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 '<ul>';
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 '</ul>';
}
?>
</div>
</div>
<?
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 = "<a href='" . $Event['url'] . "'>" . $ConcertTitle . "</a>";
?>
<form class="hidden" action="" id="concert<?=$Event['id']?>" method="post">
<input type="hidden" name="action" value="concert_thread"/>
<input type="hidden" name="concert_title" value="<?="[Concert] " . display_str($Name) . " - " . $ConcertTitle?>"/>
<input type="hidden" name="concert_id" value="<?=$Event['id']?>"/>
<input type="hidden" name="concert_template" value="<?=get_concert_post_template($Name, $Event)?>"/>
</form>
<li><?=$Concert?> - <a href="#" onclick="$('#concert<?=$Event['id']?>').raw().submit(); return false;">[Go to Thread]</a></li>
<?
}
?>
<?
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;
}
?>

View File

@ -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'); echo $Val->GenerateJS('userform');
?> ?>
<div class="thin"> <div class="thin">
@ -285,7 +289,12 @@ function checked($Checked) {
<p class="min_padding">If changing this field, you must enter your current password in the "Current password" field before saving your changes.</p> <p class="min_padding">If changing this field, you must enter your current password in the "Current password" field before saving your changes.</p>
</td> </td>
</tr> </tr>
<!-- --> <tr>
<td class="label"><strong>Last.FM Username</strong></td>
<td><input type="text" size="50" name="lastfm_username" id="lastfm_username" value="<?=display_str($LastFMUsername)?>" />
<p class="min_padding">Your Last.FM username. Will be used to display Last.FM information on your profile which can be seen by other users.</p>
</td>
</tr>
<tr> <tr>
<td class="label"><strong>Info</strong></td> <td class="label"><strong>Info</strong></td>

58
sections/user/lastfm.php Normal file
View File

@ -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);
?>
<div class="box">
<div class="head">
<span style="float:left;">Last.FM
<span id="tabs" class="tabs">
<a href="#" style="font-weight: bold;">[Info]</a>
<a href="#">[Top Artists]</a>
<a href="#">[Top Albums]</a>
<a href="#">[Top Tracks]</a>
<a href="#">[Tasteometer]</a>
</span>
</span>
<span style="float:right;"><a href="#" onclick="$('#lastfm_div').toggle(); this.innerHTML=(this.innerHTML=='(Hide)'?'(Show)':'(Hide)'); return false;">(Hide)</a></span>&nbsp;
</div>
<div class="pad" id="lastfm_div">
<div id="contents_div">
<div id="tab_0_contents">
<div class="lastfm_user_info">
<strong><a id="lastfm_username" href="<?=$LastFMInfo['user']['url']?>"><?=$LastFMInfo['user']['name']?></a></strong>
<br/>Number of plays: <?=$LastFMInfo['user']['playcount']?>
<br/>Playlists: <?=$LastFMInfo['user']['playlists']?>
</div>
<br/>
<div class="lastfm_recent_tracks">
<strong>Recently Played</strong>
<ul class="nobullet">
<?
foreach ($RecentTracks['recenttracks']['track'] as $Track) {
?>
<li>
<a href="torrents.php?searchstr=<?=$Track['artist']['#text']?>"><?=$Track['artist']['#text']?></a> - <a href="<?=$Track['url']?>"><?=$Track['name']?></a> - <a href="torrents.php?searchstr=<?=$Track['album']['#text']?>"><?=$Track['album']['#text']?></a>
</li>
<?
}
?>
</ul>
</div>
</div>
<div id="tab_1_contents">
</div>
<div id="tab_2_contents">
</div>
<div id="tab_3_contents">
</div>
<div id="tab_4_contents">
</div>
</div>
</div>
</div>
<? } ?>

View File

@ -229,6 +229,24 @@
$UnseededAlerts = (isset($_POST['unseededalerts']))? 1:0; $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 // Information on how the user likes to download torrents is stored in cache
if($DownloadAlt != $LoggedUser['DownloadAlt']) { if($DownloadAlt != $LoggedUser['DownloadAlt']) {
$Cache->delete_value('user_'.$LoggedUser['torrent_pass']); $Cache->delete_value('user_'.$LoggedUser['torrent_pass']);

View File

@ -627,6 +627,8 @@ function check_paranoia_here($Setting) {
$FirstCol = false; $FirstCol = false;
} }
include(SERVER_ROOT.'/sections/user/lastfm.php');
// Linked accounts // Linked accounts

View File

@ -1,4 +1,4 @@
//skipfile
(function ($) { (function ($) {
var TAB_COUNT = 0; var TAB_COUNT = 0;
var topArtistsLoaded = false; var topArtistsLoaded = false;