Testing the code-tag using the last.fm plugin.
function lastfm($atts) {
global $s, $c;
extract(lAtts(array(
‘label’ => ‘’,
‘labeltag’ => ‘’,
‘break’ => ‘br’,
‘wraptag’ => ‘’,
‘parent’ => ‘’,
‘posted’ => ‘’,
‘section’ => $s,
‘sticky’ => ‘’,
‘user’ => ‘’,
),$atts));
function openURL($url, $headers = null){
if (function_exists(‘curl_init’))
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data[‘html’] = curl_exec($ch);
curl_close($ch);
}
elseif (ini_get(‘allow_url_fopen’) == 1)
{
$data[‘html’] = file_get_contents($url);
}
if($headers) {$data[‘headers’] = get_headers($url, 1); }
return $data;
}
$url = “http://ws.audioscrobbler.com/1.0/user/” . $user . “/recenttracks.xml”;
$xml = openURL($url);
$info = simplexml_load_string($xml[“html”]);
// OUTPUT
$out = array();
for($i=0;$i<5;$i++){
$fm = $info->track[$i];
$out[$i] = tag($fm->artist . ‘ – ‘ . $fm->name, ‘a’, ‘ href=”’ . $fm->url . ‘”’);
}
return doLabel($label, $labeltag).doWrap($out, $wraptag, $break, $class);
}