[BETA] last.fm API Integration (Compatible with 2.0b4; 1.1.x WITH modification)

Started by Malpercio, January 01, 2009, 02:02:33 PM

Previous topic - Next topic

Malpercio

Alright, so, for the past week or so, when I've had the time, I've been working on getting the last.fm [nofollow] API integrated with my developing forum, which is running SMF 2.0b4. I got it up and running, and currently, all it does is show what the user is currently listening to in the sidebar next to each of their posts. I have a friend who is running 1.1.7, and we successfully integrated this modification into his system as well. It is a fairly simple process. I will explain the steps that need to be taken to install it into each system, and attach a .txt file with the proper code snippets that need to be inserted.

SMF 2.0 Beta 4

Prep:

  • Grab a last.fm [nofollow] API key here [nofollow]. (Note: This requires a last.fm [nofollow] account.)
  • Activate custom profile fields.
  • Create a field named last.fm [nofollow]
Installation:

  • Download the .txt file.
  • Insert first portion into any and all index.template.php files.
  • Insert second portion into any and all Display.template.php files, being sure to replace "TABLEPREFIX_" and "APIKEY".
SMF 1.1.x

Prep:

  • Grab a last.fm [nofollow] API key here [nofollow]. (Note: This requires a last.fm [nofollow] account.)
  • Install the Custom Profile Field Mod
  • Create a new profile field, call it last.fm [nofollow], and be sure that the field ID is set to "last"! (without quotes!)
Installation:

  • Download the .txt file.
  • Insert first portion into any and all index.template.php files.
  • Insert second portion into any and all Display.template.php files, being sure to replace "TABLEPREFIX_" and "APIKEY".



Now, as far as I know, the database query should work across all configurations, as long as you replace "TABLEPREFIX_" with your prefix. I noticed that both SMF 2.0b4 and 1.1.7 running the Custom Profile Field mod writes the data into the "themes" table, therefore making the query, in general, global.

If you have any questions, please, feel free to ask, and I will try my hardest to help you.

PLEASE NOTE! This is a BETA, so you are implementing this code AT YOUR OWN RISK. However, I don't think there are any changes made that aren't reversible, so you should be alright.

I have plans to eventually make this a package, as soon as I get everything figured out, and I would like to further implement the last.fm [nofollow] API into the board system, as there are may features available. If you have any feature requests/suggestions, feel free to let me know!


Sabre™

Interesting, I dont need this at the moment, but will keep an eye on this for maybe a future project.

Good job mate, and thanks for sharing :)
Do NOT give admin and/or ftp details to just anybody, see if they are trust worthy first!!  Do your homework ;)


Malpercio

Thanks, no problem, I wasn't really sure how necessary it would be, I just thought I'd share it with the rest of the community.

Özgür

Thank you Malpercio. I used this tip for ultimate profile. this is very nice but i change something.

              
$lastuser = @mysql_result(mysql_query("SELECT value FROM smf_themes WHERE variable='last' AND id_member='" .  $context['member']['id'] . "'"),0);

$emptyornot = empty($lastuser);
if( $emptyornot != 1)
{
echo '<img src="http://imagegen.last.fm/rednorm2/recenttracks/',$lastuser,'.png" alt="" />';
}
  

And this is work fine. Again thank you =)
        
So Long

Malpercio

Quote from: Özgür | ЯocKayseri on January 04, 2009, 09:43:35 PM
Thank you Malpercio. I used this tip for ultimate profile. this is very nice but i change something.

              
$lastuser = @mysql_result(mysql_query("SELECT value FROM smf_themes WHERE variable='last' AND id_member='" .  $context['member']['id'] . "'"),0);

$emptyornot = empty($lastuser);
if( $emptyornot != 1)
{
echo '<img src="http://imagegen.last.fm/rednorm2/recenttracks/',$lastuser,'.png" alt="" />';
}
  

Again thank you =)
        

Oh, I see what you did, you're using a image sort of thing instead of using the text, gotcha. I might actually take that idea and somehow implement it as an option, if you don't mind.

But thanks for using my script! If you really like it, please spread the word!

Özgür

I like that script. but my server is not support file_get_contents("$webaddress");. so i can't use that script :( . Therefore i used image.
So Long

Malpercio

Hmm... You might be able to request your hosting service to activate that particular function in PHP, I don't see why they wouldn't activate it for you. Talk to them, and maybe you could get something figured out!

Özgür

No. They say ; "we not open this function but security bla bla bla.." :( But i change something and work fine.
(thanks Badboy http://www.simplemachines.org/community/index.php?topic=284291.0)

i add display.template bellow

function curl_get_file_contents($URL)
{
$c = curl_init();
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_URL, $URL);
$contents = curl_exec($c);
curl_close($c);

if ($contents) return $contents;
else return FALSE;
}


and change file_get_contents to curl_get_file_contents. and work. =)
So Long

Malpercio

Oh, I see, that's not a bad idea...

Perhaps I should toss that in the index.template.php with the other defined function, because I would think it would make the script that much easier for others to use.

Advertisement: