Changeset 45289
- Timestamp:
- 05/11/08 18:51:37 (2 months ago)
- Files:
-
- lastfm-rps/tags/0.8 (copied) (copied from lastfm-rps/trunk)
- lastfm-rps/tags/0.8/images (added)
- lastfm-rps/tags/0.8/images/logo_lastfm_black.png (added)
- lastfm-rps/tags/0.8/images/logo_lastfm_crimson.png (added)
- lastfm-rps/tags/0.8/images/logo_lastfm_gray.png (added)
- lastfm-rps/tags/0.8/images/logo_lastfm_white.png (added)
- lastfm-rps/tags/0.8/lastfm.css (copied) (copied from lastfm-rps/trunk/lastfm.css) (1 diff)
- lastfm-rps/tags/0.8/lastfm.php (copied) (copied from lastfm-rps/trunk/lastfm.php) (14 diffs)
- lastfm-rps/tags/0.8/noart.gif (copied) (copied from lastfm-rps/trunk/noart.gif)
- lastfm-rps/tags/0.8/readme.txt (copied) (copied from lastfm-rps/trunk/readme.txt) (1 diff)
- lastfm-rps/tags/0.8/screenshot-1.png (copied) (copied from lastfm-rps/trunk/screenshot-1.png)
- lastfm-rps/tags/0.8/simplexml.class.php (copied) (copied from lastfm-rps/trunk/simplexml.class.php)
- lastfm-rps/trunk/lastfm.css (modified) (1 diff)
- lastfm-rps/trunk/lastfm.php (modified) (14 diffs)
- lastfm-rps/trunk/readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
lastfm-rps/tags/0.8/lastfm.css
r45072 r45289 1 #lastfm_recent {width:220px;padding:0;margin:0;margin-bottom:10px;} 2 #lastfm_recent li {width:220px;padding:2px;margin:0 0 0 0;min-height:52px;background:none;border:0px !important;} 3 #lastfm_recent li p.lastfm_recent_image {padding:0;margin:0px;display:block;} 1 #lastfm_recent {padding:0;margin:0;margin-bottom:10px;display:block;} 2 #lastfm_recent li {padding:2px;margin-bottom:2px;height:52px;background:none #fff;border:0px;} 3 #lastfm_recent li a.lastfm_recent_title {font-size:12px;} 4 #lastfm_recent li span.lastfm_recent_date {padding:0;margin:0;font-size:11px;color:gray;} 5 #lastfm_recent li span.lastfm_recent_artist a {padding:0;margin:0;font-size:11px;color:brown;} 6 #lastfm_recent li p {padding:0;margin:0;} 7 #lastfm_recent li p.lastfm_recent_image {padding:0px;margin:1px 1px;} 8 #lastfm_recent li p.lastfm_recent_image a {border:0px;} 9 #lastfm_recent li p.lastfm_recent_image img {padding:0px;margin:0px;width:50px !important;height:50px;border:0px !important;} 10 .lastfm_recent_recent {background:#eef !important;border:1px solid #eee !important;} 4 11 .lastfm-recent-left {float:left;} 12 .lastfm-recent-left img {margin-right:3px !important} 5 13 .lastfm-recent-right {float:right;} 6 #lastfm_recent li p.lastfm_recent_image img {padding:0;margin:0px;width:50px !important;height:50px; !important}7 #lastfm_recent li p {padding:0;margin:0;}8 #lastfm_recent li a.lastfm_recent_title {margin-left:5px;}9 #lastfm_ recent li span.lastfm_recent_date {margin-left:5px;padding:0;margin:1;font-size:11px;color:gray;}10 #lastfm_recent li span.lastfm_recent_artist {margin-left:5px;padding:0;margin:1;font-size:11px;color:brown;}11 .lastfm_ recent_recent {background:#eee !important;margin-bottom:2px;}14 .lastfm_recent_realname {font-size:12px;} 15 .lastfm_recent_logo {width:62px;height:24px;float:right;margin:0;padding:0;padding-right:3px;} 16 #lastfm_recent_userbadge {padding:0 5px 5px;margin:0;margin-bottom:10px;display:block;font-size:11px;} 17 #lastfm_user_image {width:80px;height:80px;margin:0,padding:0;} 18 #lastfm_recent_userbadge img {padding:0;border-color:white;} 19 .lastfm_badge_content {float:right;margin:0;padding:0;padding-left:3px;width:57%;} lastfm-rps/tags/0.8/lastfm.php
r45073 r45289 4 4 * Plugin URI: http://www.tahapaksu.com/wordpress/lastfm-wordpress-plugin 5 5 * Description: Display Recently Played Songs and Album Art from Last.fm. Just activate the plugin, Add a widget it Design->Widgets and insert your last.fm username in widget settings. 6 * Version: 0. 76 * Version: 0.8 7 7 * License: Free to Use 8 8 * Author: Taha Paksu … … 12 12 13 13 include "simplexml.class.php"; 14 15 16 function lastfm_recent_badge($user,$settings=""){ 17 if(!is_array($settings)){ 18 $settings = array( "showavatar" => true, 19 "showrealname" => true, 20 "showgender" => true, 21 "showage" => true, 22 "showcountry" => true, 23 "showregister" => true, 24 "showtrackcount" => true 25 ); 26 } 27 extract($settings); 28 $sx = new simplexml; 29 $feed = $sx->xml_load_file("http://ws.audioscrobbler.com/1.0/user/".$user."/profile.xml"); 30 echo '<div id="lastfm_recent_userbadge">'; 31 if($showrealname) 32 echo '<p class="lastfm_badge_content"><a href="'. $feed->url.'" class="lastfm_recent_realname">'.$feed->realname.'</a><br />'; 33 else 34 echo '<a href="'. $feed->url.'" class="lastfm_recent_realname">'.$user.'</a><br />'; 35 36 echo '<img src="'.$feed->icon.'" style="margin-top:2px;"> '; 37 $type=explode("/",$feed->icon); 38 $type=explode("_",$type[5]); 39 switch($type[1]){ 40 case "user.gif": echo "User";break; 41 case "staff.gif": echo "Last.fm Staff";break; 42 case "subscriber.gif" : echo "Subscriber";break; 43 case "moderator.gif" : echo "Global Moderator";break; 44 default: echo "";break; 45 } 46 echo "<br />"; 47 if ($showgender) 48 switch($feed->gender){ 49 case "m": echo "Male ,";break; 50 case "f": echo "Female ,";break; 51 default: echo "";break; 52 } 53 if($showage) echo ($feed->age)?$feed->age.", ":""; 54 if($showcountry) echo ($feed->country)?"<a href='http://www.last.fm/place/".$feed->country."' target='_blank'>".$feed->country."</a>":""; 55 echo "<br />"; 56 $date = $feed->registered->content(); 57 if($showregister) echo "Registered : " . $date->scalar . "<br />"; 58 if($showtrackcount) echo "Tracks Played : " . $feed->playcount; 59 echo "</p>"; 60 if($showavatar) 61 echo '<a href="'.$feed->url.'"><img src="'. $feed->avatar.'" id="lastfm_user_image"></a>'; 62 echo "</div>"; 63 } 14 64 15 65 function image_exists($url, $user='', $pass='', $referer='') { … … 62 112 function img_replace($i){ 63 113 if(substr($i,0,34)=="http://userserve-ak.last.fm/serve/"){ 64 $i = explode("/",$i); 65 $i[4] = "50"; 66 return implode("/",$i); 67 }else 68 return $i; 69 } 70 71 function get_artist_art($artist){ 72 $plugindir = get_option('siteurl') . '/wp-content/plugins/' . dirname(plugin_basename(__FILE__)); 73 $url = "http://ws.audioscrobbler.com/1.0/artist/". rawurlencode(utf8_encode($artist))."/similar.xml"; 114 $i = explode("/",$i); 115 $i[4] = "50"; 116 return implode("/",$i); 117 }elseif($i=="http://cdn.last.fm/depth/catalogue/noimage/cover_med.gif"){ 118 return "http://cdn.last.fm/depth/catalogue/noimage/cover_small.gif"; 119 }elseif($i=="http://cdn.last.fm/depth/catalogue/noimage/cover_large.gif"){ 120 return "http://cdn.last.fm/depth/catalogue/noimage/cover_small.gif"; 121 }else{ 122 $replace = array("130x130","160x160"); 123 $with = "50x50"; 124 return str_replace($replace,$with,$i); 125 } 126 } 127 128 129 130 if(!function_exists('htmlspecialchars_decode')){ 131 function htmlspecialchars_decode($string,$style=ENT_COMPAT) 132 { 133 $translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS,$style)); 134 if($style === ENT_QUOTES){ $translation['''] = '\''; } 135 return strtr($string,$translation); 136 } 137 } 138 139 function get_album_art($album,$artist){ 140 $replace = array(" ","&","/"); 141 $with = array("%20","%26","%2F"); 142 $plugindir = get_option('siteurl') . '/wp-content/plugins/' . dirname(plugin_basename(__FILE__)); 143 $artist = rawurlencode(utf8_encode(str_replace($replace,$with,$artist))); 144 $album = rawurlencode(utf8_encode(str_replace($replace,$with,$album))); 145 $url = "http://ws.audioscrobbler.com/1.0/album/".$artist."/".$album."/info.xml"; 74 146 $sx = new simplexml; 75 147 unset($feed); 76 148 $feed = $sx->xml_load_file($url); 77 $attr = $feed->attributes(); 78 if($attr->picture) return img_replace($attr->picture); 79 return $plugindir."/noart.gif"; 80 } 81 82 83 function get_album_art($album,$artist){ 84 $plugindir = get_option('siteurl') . '/wp-content/plugins/' . dirname(plugin_basename(__FILE__)); 85 $url = "http://ws.audioscrobbler.com/1.0/album/".rawurlencode(utf8_encode($artist))."/".rawurlencode(utf8_encode($album))."/info.xml"; 149 unset($sx); 150 if(!is_object($feed)) get_va_album_art($artist,$album); 151 if(image_exists($feed->coverart->small)) return img_replace($feed->coverart->small); 152 if(image_exists($feed->coverart->medium)) return img_replace($feed->coverart->medium); 153 if(image_exists($feed->coverart->large)) return img_replace($feed->coverart->large); 154 return get_va_album_art($artist,$album); 155 } 156 157 function get_artist_art($artist,$album=""){ 158 $artist = str_replace("%2F","%252F",urlencode($artist)); 159 $plugindir = get_option('siteurl') . '/wp-content/plugins/' . dirname(plugin_basename(__FILE__)); 160 $url = "http://ws.audioscrobbler.com/1.0/artist/".$artist."/similar.xml"; 86 161 $sx = new simplexml; 87 162 unset($feed); 88 163 $feed = $sx->xml_load_file($url); 164 if(!is_object($feed)) return $plugindir."/noart.gif"; 165 $attr = $feed->attributes(); 166 if(($attr->picture)&&($attr->picture!="http://cdn.last.fm/depth/catalogue/noimage/noartist_140px.jpg")) 167 return img_replace($attr->picture); 168 return $plugindir."/noart.gif"; 169 } 170 171 function get_va_album_art($artist,$album){ 172 $plugindir = get_option('siteurl') . '/wp-content/plugins/' . dirname(plugin_basename(__FILE__)); 173 $url = "http://ws.audioscrobbler.com/1.0/album/VA/". $album."/info.xml"; 174 $sx = new simplexml; 175 unset($feed); 176 $feed = $sx->xml_load_file($url); 177 if(!is_object($feed)) return get_artist_art($artist); 89 178 if(image_exists($feed->coverart->small)) return img_replace($feed->coverart->small); 90 179 if(image_exists($feed->coverart->medium)) return img_replace($feed->coverart->medium); … … 92 181 return get_artist_art($artist); 93 182 } 183 184 94 185 95 186 function lastfm_datediff($date,$ret = 0,$serversec,$recentdisplayed){ … … 123 214 } 124 215 125 126 function lastfm_recent($user,$size,$timediff,$position="left",$text){ 216 function lastfm_extract_artist_link($string){ 217 $artist = split("_",$string); 218 return $artist[0]; 219 } 220 221 function lastfm_recent($user,$size,$timediff,$position="left",$text,$showbadge=true,$badgepos="top",$badgeoptions=""){ 127 222 $plugindir = get_option('siteurl') . '/wp-content/plugins/' . dirname(plugin_basename(__FILE__)); 128 223 if(!$_SESSION["lastfm_wp_head_exists"]) echo '<style type="text/css">@import url("'.$plugindir.'/lastfm.css");</style>'."\n"; … … 132 227 $feed = $sx->xml_load_file($url); 133 228 $recentdisplayed=false; 229 echo "<div>"; 134 230 if(!is_object($feed)) 135 231 lastfm_recent_death("This username does not exist, or the feed service is down."); … … 137 233 lastfm_recent_death("This user has not played any songs yet."); 138 234 elseif(is_object($feed->track)){ 235 if($showbadge&&$badgepos=="top") lastfm_recent_badge($user,$badgeoptions); 139 236 echo "<ul id=\"lastfm_recent\">"; 140 237 $artist = $feed->track->artist->content(); … … 149 246 $albumimage = get_album_art(stripslashes($album->scalar),stripslashes($artist->scalar)); 150 247 }else{ 151 $albumimage = get_artist_art(stripslashes($artist->scalar)); 248 $replace = array(" ","&","/"); 249 $with = array("%20","%26","%2F"); 250 $artist = rawurlencode(utf8_encode(str_replace($replace,$with,stripslashes($artist)))); 251 $album = rawurlencode(utf8_encode(str_replace($replace,$with,stripslashes($album)))); 252 $albumimage = get_va_album_art($artist,$album); 152 253 } 153 254 echo '<li class="'.$newclass.'">'; … … 158 259 echo '</a></p>'; 159 260 echo '<a href="'.$feed->track->url.'" class="lastfm_recent_title">'.stripslashes(lastfm_recent_capitalize($feed->track->name)).'</a><br />'; 160 echo '<span class="lastfm_recent_artist"> '.stripslashes($artist->scalar).'</span><br />';261 echo '<span class="lastfm_recent_artist"><a href="'.lastfm_extract_artist_link($feed->track->url).'" class="lastfm_recent_title">'.stripslashes($artist->scalar).'</a></span><br />'; 161 262 echo '<span class="lastfm_recent_date">'.lastfm_datediff($date->uts,false,$timediff,$recentdisplayed).'</span>'; 162 263 echo '</li>'; 163 264 echo "</ul>"; 265 if($showbadge&&$badgepos=="bottom") lastfm_recent_badge($user,$badgeoptions); 164 266 }else{ 165 267 $k=0; 268 if($showbadge&&$badgepos=="top") lastfm_recent_badge($user,$badgeoptions); 166 269 echo "<ul id=\"lastfm_recent\">"; 167 270 foreach($feed->track as $track){ … … 186 289 echo '</a></p>'; 187 290 echo '<a href="'.$track->url.'" class="lastfm_recent_title">'.stripslashes(lastfm_recent_capitalize($track->name)).'</a><br />'; 188 echo '<span class="lastfm_recent_artist"> '.stripslashes($artist->scalar).'</span><br />';291 echo '<span class="lastfm_recent_artist"><a href="'.lastfm_extract_artist_link($track->url).'" class="lastfm_recent_title">'.stripslashes($artist->scalar).'</a></span><br />'; 189 292 echo '<span class="lastfm_recent_date">'.lastfm_datediff($date->uts,false,$timediff,$recentdisplayed).'</span>'; 190 293 echo '</li>'; … … 194 297 } 195 298 echo "</ul>"; 299 if($showbadge&&$badgepos=="bottom") lastfm_recent_badge($user,$badgeoptions); 196 300 } 197 301 echo "<div id='lastfm_recent_comment'>" . stripslashes(htmlspecialchars_decode($text)) . "</div>"; 198 302 echo "<!--# Last.fm Recently Played Songs Plugin by Taha Paksu -->"; 303 echo "</div>"; 199 304 } 200 305 … … 207 312 208 313 314 function lastfm_recent_control() 315 { 316 $options = get_option("lastfm_recent"); 317 318 if (!is_array( $options )) 319 { 320 $badgeoptions = array( "showavatar" => true, 321 "showrealname" => true, 322 "showgender" => true, 323 "showage" => true, 324 "showcountry" => true, 325 "showregister" => true, 326 "showtrackcount" => true 327 ); 328 $options = array( 329 'user' => '', 330 'title' => 'Last.fm RPS', 331 'size' => 10, 332 'serversec' => 0, 333 'position' => 'left', 334 'text' => '', 335 'showbadge' => true, 336 'badgeposition' => 'top', 337 'badgeoptions' => $badgeoptions, 338 'color' => "black" 339 ); 340 } 341 342 if ($_POST['lastfm_recent_submit']) 343 { 344 $options['user'] = htmlspecialchars($_POST['lastfm_recent_user']); 345 $options['title'] = htmlspecialchars($_POST['lastfm_recent_title']); 346 $options['color'] = htmlspecialchars($_POST['lastfm_recent_color']); 347 $options['size'] = htmlspecialchars($_POST['lastfm_recent_size']); 348 $options['position'] = htmlspecialchars($_POST['lastfm_recent_position']); 349 $options['serversec'] = htmlspecialchars($_POST['lastfm_recent_serverdiff']); 350 $options['text'] = htmlspecialchars($_POST['lastfm_recent_text']); 351 $options['showbadge'] = $_POST['lastfm_recent_showbadge']; 352 $options['badgeposition'] = $_POST['lastfm_recent_badgeposition']; 353 $badgeoptions = array( 354 "showavatar" => $_POST['lastfm_recent_showavatar'], 355 "showrealname" => $_POST['lastfm_recent_showrealname'], 356 "showgender" => $_POST['lastfm_recent_showgender'], 357 "showage" => $_POST['lastfm_recent_showage'], 358 "showcountry" => $_POST['lastfm_recent_showcountry'], 359 "showregister" => $_POST['lastfm_recent_showregister'], 360 "showtrackcount" => $_POST['lastfm_recent_showtrackcount'] 361 ); 362 $options['badgeoptions'] = $badgeoptions; 363 update_option("lastfm_recent", $options); 364 } 365 366 ?> 367 <p> 368 <TABLE> 369 <TR> 370 <TD width="100px">Widget Title: </TD> 371 <TD><input type="text" id="lastfm_recent_title" name="lastfm_recent_title" value="<?php echo $options['title'];?>" /></TD> 372 </TR> 373 <TR> 374 <TD width="100px">Logo Color: </TD> 375 <TD><select name="lastfm_recent_color"> 376 <option value="crimson" <?php if("crimson"==$options["color"]) echo "selected";?>>crimson</option> 377 <option value="black" <?php if("black"==$options["color"]) echo "selected";?>>black</option> 378 <option value="gray" <?php if("gray"==$options["color"]) echo "selected";?>>gray</option> 379 <option value="white" <?php if("white"==$options["color"]) echo "selected";?>>white</option> 380 </select></TD> 381 </TR> 382 <TR> 383 <TD>Last.fm Username:</TD> 384 <TD><input type="text" id="lastfm_recent_user" name="lastfm_recent_user" value="<?php echo $options['user'];?>" /><input type="hidden" id="lastfm_recent_submit" name="lastfm_recent_submit" value="1" /></TD> 385 </TR> 386 <TR> 387 <TD>List size: </TD> 388 <TD><select name="lastfm_recent_size"><?php for($i=1;$i<11;$i++){ ?><option value="<?=$i?>" <?php if($i==$options["size"]) echo "selected";?>><?=$i?></option><?php }?></select></TD> 389 </TR> 390 <TR> 391 <TD>Image Position: </TD> 392 <TD><select name="lastfm_recent_position"> 393 <option value="left" <?php if("left"==$options["position"]) echo "selected";?>>left</option> 394 <option value="right" <?php if("right"==$options["position"]) echo "selected";?>>right</option> 395 </select> 396 </TD> 397 </TR> 398 <TR> 399 <TD>Show Badge? </TD> 400 <TD><input type="checkbox" <?php echo ($options["showbadge"])?"checked":"";?> name="lastfm_recent_showbadge" /> 401 </TD> 402 </TR> 403 <TR> 404 <TD>Badge Position:</TD> 405 <TD><select name="lastfm_recent_badgeposition"> 406 <option value="top" <?php if("top"==$options["badgeposition"]) echo "selected";?>>top</option> 407 <option value="bottom" <?php if("bottom"==$options["badgeposition"]) echo "selected";?>>bottom</option> 408 </select> 409 </TD> 410 </TR> 411 <TR> 412 <TD valign="top">Badge Options: </TD> 413 <TD> 414 <?php $badgeoptions = $options["badgeoptions"];?> 415 <input type="checkbox" <?php echo ($badgeoptions["showavatar"])?"checked":"";?> name="lastfm_recent_showavatar" />Show Picture<br /> 416 <input type="checkbox" <?php echo ($badgeoptions["showrealname"])?"checked":"";?> name="lastfm_recent_showrealname" />Show Real Name<br /> 417 <input type="checkbox" <?php echo ($badgeoptions["showgender"])?"checked":"";?> name="lastfm_recent_showgender" />Show Gender<br /> 418 <input type="checkbox" <?php echo ($badgeoptions["showage"])?"checked":"";?> name="lastfm_recent_showage" />Show Age<br /> 419 <input type="checkbox" <?php echo ($badgeoptions["showcountry"])?"checked":"";?> name="lastfm_recent_showcountry" />Show Country<br /> 420 <input type="checkbox" <?php echo ($badgeoptions["showregister"])?"checked":"";?> name="lastfm_recent_showregister" />Show Registration Date<br /> 421 <input type="checkbox" <?php echo ($badgeoptions["showtrackcount"])?"checked":"";?> name="lastfm_recent_showtrackcount" />Show Track Count<br /> 422 </TD> 423 </TR> 424 <TR> 425 <TD valign=top>Server time difference: </TD> 426 <TD><input type="text" id="lastfm_recent_user" name="lastfm_recent_serverdiff" value="<?php echo $options['serversec'];?>" /><br /> <small>Date difference in seconds with your server and local time (Now is <?php echo date("H:i:s",time());?> for your server)</small></TD> 427 </TR> 428 <TR> 429 <TD valign=top>Optional Text: </TD> 430 <TD><textarea name="lastfm_recent_text" rows=5 cols=25><?php echo stripslashes($options["text"])?></textarea><br> 431 <small>Optional text to be displayed at bottom of the widget. You can use html.</small> 432 </TD> 433 </TR> 434 </TABLE> 435 436 </p> 437 <?php 438 } 439 440 function lastfm_recent_sidebar($user=false,$size=10,$serversec=0,$position="left",$text=false){ 441 if(!$user){ 442 lastfm_recent_death("Username not set. Please check your code."); 443 }else{ 444 lastfm_recent($user,$size,$serversec,$position,$text,$showbadge="false"); 445 } 446 } 447 209 448 function lastfm_recent_widget($args) { 210 449 extract($args); 450 $plugindir = get_option('siteurl') . '/wp-content/plugins/' . dirname(plugin_basename(__FILE__)); 211 451 $options = get_option("lastfm_recent"); 212 452 if (!is_array( $options )) … … 217 457 'serversec' => 0, 218 458 'position' => 'left', 219 'text' => '' 459 'text' => '', 460 'showbadge' =>true, 461 'badgeposition' => 'top', 462 'badgeoptions' => '' 220 463 ); 221 464 } … … 223 466 if(!$options["position"]) $options["position"]="left"; 224 467 echo $before_widget; 225 echo $before_title;226 echo $options['title'];227 echo $after_title;468 echo "<h3>"; 469 echo "<span class='png lastfm_recent_logo'><img src='".$plugindir."/images/logo_lastfm_".$options["color"].".png'></span><span>".$options['title']."</span>"; 470 echo "</h3>"; 228 471 if(!$options["user"]){ 229 472 lastfm_recent_death("Widget options not set. Please go to Admin->Design->Widgets to adjust the settings."); 230 473 }else 231 lastfm_recent($options["user"],$options["size"],$options['serversec'],$options["position"],$options["text"] );474 lastfm_recent($options["user"],$options["size"],$options['serversec'],$options["position"],$options["text"],$options["showbadge"],$options["badgeposition"],$options["badgeoptions"]); 232 475 echo $after_widget; 233 476 } 234 477 235 function lastfm_recent_control()236 {237 $options = get_option("lastfm_recent");238 239 if (!is_array( $options ))240 {241 $options = array(242 'user' => '',243 'title' => 'Last.fm RPS',244 'size' => 10,245 'serversec' => 0,246 'position' => 'left',247 'text' => ''248 );249 }250 251 if ($_POST['lastfm_recent_submit'])252 {253 $options['user'] = htmlspecialchars($_POST['lastfm_recent_user']);254 $options['title'] = htmlspecialchars($_POST['lastfm_recent_title']);255 $options['size'] = htmlspecialchars($_POST['lastfm_recent_size']);256 $options['position'] = htmlspecialchars($_POST['lastfm_recent_position']);257 $options['serversec'] = htmlspecialchars($_POST['lastfm_recent_serverdiff']);258 $options['text'] = htmlspecialchars($_POST['lastfm_recent_text']);259 update_option("lastfm_recent", $options);260 }261 262 ?>263 <p>264 <TABLE>265 <TR>266 <TD>Widget Title: </TD>267 <TD><input type="text" id="lastfm_recent_title" name="lastfm_recent_title" value="<?php echo $options['title'];?>" /></TD>268 </TR>269 <TR>270 <TD>Last.fm Username:</TD>271 <TD><input type="text" id="lastfm_recent_user" name="lastfm_recent_user" value="<?php echo $options['user'];?>" /><input type="hidden" id="lastfm_recent_submit" name="lastfm_recent_submit" value="1" /></TD>272 </TR>273 <TR>274 <TD>List size: </TD>275 <TD><select name="lastfm_recent_size"><?php for($i=1;$i<11;$i++){ ?><option value="<?=$i?>" <?php if($i==$options["size"]) echo "selected";?>><?=$i?></option><?php }?></TD>276 </TR>277 <TR>278 <TD>Image Position: </TD>279 <TD><select name="lastfm_recent_position">280 <option value="left" <?php if("left"==$options["position"]) echo "selected";?>>left</option>281 <option value="right" <?php if("right"==$options["position"]) echo "selected";?>>right</option>282 </TD>283 </TR>284 <TR>285 <TD valign=top>Server time difference: </TD>286 <TD><input type="text" id="lastfm_recent_user" name="lastfm_recent_serverdiff" value="<?php echo $options['serversec'];?>" /><br /> <small>Date difference in seconds with your server and local time (Now is <?php echo date("H:i:s",time());?> for your server)</small></TD>287 </TR>288 <TR>289 <TD valign=top>Optional Text: </TD>290 <TD><textarea name="lastfm_recent_text" rows=5 cols=30><?php echo stripslashes($options["text"])?></textarea><br>291 <small>Optional text to be displayed at bottom of the widget. You can use html.</small>292 </TD>293 </TR>294 </TABLE>295 296 </p>297 <?php298 }299 300 function lastfm_recent_sidebar($user=false,$size=10,$serversec=0,$position="left",$text=false){301 if(!$user){302 lastfm_recent_death("Username not set. Please check your code.");303 }else{304 lastfm_recent($user,$size,$serversec,$position,$text);305 }306 }307 478 308 479 309 480 function lastfm_recent_init() 310 481 { 482 register_widget_control( 'Last.fm RPS', 'lastfm_recent_control', 500, 500 ); 311 483 register_sidebar_widget(__('Last.fm RPS'), 'lastfm_recent_widget'); 312 register_widget_control( 'Last.fm RPS', 'lastfm_recent_control', 300, 200 );313 484 } 314 485 add_action("plugins_loaded", "lastfm_recent_init"); lastfm-rps/tags/0.8/readme.txt
r45072 r45289 69 69 * Added artist images support. Now it shows artist images when it can't find the album image. 70 70 71 == The changes in 0.8 == 72 * Added Various Artists album image support 73 * Added last.fm badge option 74 * Improved options page 75 * Added last.fm logos (you should use one) 76 77 78 71 79 == Frequently Asked Questions == 72 80 lastfm-rps/trunk/lastfm.css
r45072 r45289 1 #lastfm_recent {width:220px;padding:0;margin:0;margin-bottom:10px;} 2 #lastfm_recent li {width:220px;padding:2px;margin:0 0 0 0;min-height:52px;background:none;border:0px !important;} 3 #lastfm_recent li p.lastfm_recent_image {padding:0;margin:0px;display:block;} 1 #lastfm_recent {padding:0;margin:0;margin-bottom:10px;display:block;} 2 #lastfm_recent li {padding:2px;margin-bottom:2px;height:52px;background:none #fff;border:0px;} 3 #lastfm_recent li a.lastfm_recent_title {font-size:12px;} 4 #lastfm_recent li span.lastfm_recent_date {padding:0;margin:0;font-size:11px;color:gray;} 5 #lastfm_recent li span.lastfm_recent_artist a {padding:0;margin:0;font-size:11px;color:brown;} 6 #lastfm_recent li p {padding:0;margin:0;} 7 #lastfm_recent li p.lastfm_recent_image {padding:0px;margin:1px 1px;} 8 #lastfm_recent li p.lastfm_recent_image a {border:0px;} 9 #lastfm_recent li p.lastfm_recent_image img {padding:0px;margin:0px;width:50px !important;height:50px;border:0px !important;} 10 .lastfm_recent_recent {background:#eef !important;border:1px solid #eee !important;} 4 11 .lastfm-recent-left {float:left;} 12 .lastfm-recent-left img {margin-right:3px !important} 5 13 .lastfm-recent-right {float:right;} 6 #lastfm_recent li p.lastfm_recent_image img {padding:0;margin:0px;width:50px !important;height:50px; !important}7 #lastfm_recent li p {padding:0;margin:0;}8 #lastfm_recent li a.lastfm_recent_title {margin-left:5px;}9 #lastfm_ recent li span.lastfm_recent_date {margin-left:5px;padding:0;margin:1;font-size:11px;color:gray;}10 #lastfm_recent li span.lastfm_recent_artist {margin-left:5px;padding:0;margin:1;font-size:11px;color:brown;}11 .lastfm_ recent_recent {background:#eee !important;margin-bottom:2px;}14 .lastfm_recent_realname {font-size:12px;} 15 .lastfm_recent_logo {width:62px;height:24px;float:right;margin:0;padding:0;padding-right:3px;} 16 #lastfm_recent_userbadge {padding:0 5px 5px;margin:0;margin-bottom:10px;display:block;font-size:11px;} 17 #lastfm_user_image {width:80px;height:80px;margin:0,padding:0;} 18 #lastfm_recent_userbadge img {padding:0;border-color:white;} 19 .lastfm_badge_content {float:right;margin:0;padding:0;padding-left:3px;width:57%;} lastfm-rps/trunk/lastfm.php
r45073 r45289 4 4 * Plugin URI: http://www.tahapaksu.com/wordpress/lastfm-wordpress-plugin 5 5 * Description: Display Recently Played Songs and Album Art from Last.fm. Just activate the plugin, Add a widget it Design->Widgets and insert your last.fm username in widget settings. 6 * Version: 0. 76 * Version: 0.8 7 7 * License: Free to Use 8 8 * Author: Taha Paksu … … 12 12 13 13 include "simplexml.class.php"; 14 15 16 function lastfm_recent_badge($user,$settings=""){ 17 if(!is_array($settings)){ 18 $settings = array( "showavatar" => true, 19 "showrealname" => true, 20 "showgender" => true, 21 "showage" => true, 22 "showcountry" => true, 23 "showregister" => true, 24 "showtrackcount" => true 25 ); 26 } 27 extract($settings); 28 $sx = new simplexml; 29 $feed = $sx->xml_load_file("http://ws.audioscrobbler.com/1.0/user/".$user."/profile.xml"); 30 echo '<div id="lastfm_recent_userbadge">'; 31 if($showrealname) 32 echo '<p class="lastfm_badge_content"><a href="'. $feed->url.'" class="lastfm_recent_realname">'.$feed->realname.'</a><br />'; 33 else 34 echo '<a href="'. $feed->url.'" class="lastfm_recent_realname">'.$user.'</a><br />'; 35 36 echo '<img src="'.$feed->icon.'" style="margin-top:2px;"> '; 37 $type=explode("/",$feed->icon); 38 $type=explode("_",$type[5]); 39 switch($type[1]){ 40 case "user.gif": echo "User";break; 41 case "staff.gif": echo "Last.fm Staff";break; 42 case "subscriber.gif" : echo "Subscriber";break; 43 case "moderator.gif" : echo "Global Moderator";break; 44 default: echo "";break; 45 } 46 echo "<br />"; 47 if ($showgender) 48 switch($feed->gender){ 49 case "m": echo "Male ,";break; 50 case "f": echo "Female ,";break; 51 default: echo "";break; 52 } 53 if($showage) echo ($feed->age)?$feed->age.", ":""; 54 if($showcountry) echo ($feed->country)?"<a href='http://www.last.fm/place/".$feed->country."' target='_blank'>".$feed->country."</a>":""; 55 echo "<br />"; 56 $date = $feed->registered->content(); 57 if($showregister) echo "Registered : " . $date->scalar . "<br />"; 58 if($showtrackcount) echo "Tracks Played : " . $feed->playcount; 59 echo "</p>"; 60 if($showavatar) 61 echo '<a href="'.$feed->url.'"><img src="'. $feed->avatar.'" id="lastfm_user_image"></a>'; 62 echo "</div>"; 63 } 14 64 15 65 function image_exists($url, $user='', $pass='', $referer='') { … … 62 112 function img_replace($i){ 63 113 if(substr($i,0,34)=="http://userserve-ak.last.fm/serve/"){ 64 $i = explode("/",$i); 65 $i[4] = "50"; 66 return implode("/",$i); 67 }else 68 return $i; 69 } 70 71 function get_artist_art($artist){ 72 $plugindir = get_option('siteurl') . '/wp-content/plugins/' . dirname(plugin_basename(__FILE__)); 73 $url = "http://ws.audioscrobbler.com/1.0/artist/". rawurlencode(utf8_encode($artist))."/similar.xml"; 114 $i = explode("/",$i); 115 $i[4] = "50"; 116 return implode("/",$i); 117 }elseif($i=="http://cdn.last.fm/depth/catalogue/noimage/cover_med.gif"){ 118 return "http://cdn.last.fm/depth/catalogue/noimage/cover_small.gif"; 119 }elseif($i=="http://cdn.last.fm/depth/catalogue/noimage/cover_large.gif"){ 120 return "http://cdn.last.fm/depth/catalogue/noimage/cover_small.gif"; 121 }else{ 122 $replace = array("130x130","160x160"); 123 $with = "50x50"; 124 return str_replace($replace,$with,$i); 125 } 126 } 127 128 129 130 if(!function_exists('htmlspecialchars_decode')){ 131 function htmlspecialchars_decode($string,$style=ENT_COMPAT) 132 { 133 $translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS,$style)); 134 if($style === ENT_QUOTES){ $translation['''] = '\''; } 135 return strtr($string,$translation); 136 } 137 } 138 139 function get_album_art($album,$artist){ 140 $replace = array(" ","&","/"); 141 $with = array("%20","%26","%2F"); 142 $plugindir = get_option('siteurl') . '/wp-content/plugins/' . dirname(plugin_basename(__FILE__)); 143 $artist = rawurlencode(utf8_encode(str_replace($replace,$with,$artist))); 144 $album = rawurlencode(utf8_encode(str_replace($replace,$with,$album))); 145 $url = "http://ws.audioscrobbler.com/1.0/album/".$artist."/".$album."/info.xml"; 74 146 $sx = new simplexml; 75 147 unset($feed); 76 148 $feed = $sx->xml_load_file($url); 77 $attr = $feed->attributes(); 78 if($attr->picture) return img_replace($attr->picture); 79 return $plugindir."/noart.gif"; 80 } 81 82 83 function get_album_art($album,$artist){ 84 $plugindir = get_option('siteurl') . '/wp-content/plugins/' . dirname(plugin_basename(__FILE__)); 85 $url = "http://ws.audioscrobbler.com/1.0/album/".rawurlencode(utf8_encode($artist))."/".rawurlencode(utf8_encode($album))."/info.xml"; 149 unset($sx); 150 if(!is_object($feed)) get_va_album_art($artist,$album); 151 if(image_exists($feed->coverart->small)) return img_replace($feed->coverart->small); 152 if(image_exists($feed->coverart->medium)) return img_replace($feed->coverart->medium); 153 if(image_exists($feed->coverart->large)) return img_replace($feed->coverart->large); 154 return get_va_album_art($artist,$album); 155 } 156 157 function get_artist_art($artist,$album=""){ 158 $artist = str_replace("%2F","%252F",urlencode($artist)); 159 $plugindir = get_option('siteurl') . '/wp-content/plugins/' . dirname(plugin_basename(__FILE__)); 160 $url = "http://ws.audioscrobbler.com/1.0/artist/".$artist."/similar.xml"; 86 161 $sx = new simplexml; 87 162 unset($feed); 88 163 $feed = $sx->xml_load_file($url); 164 if(!is_object($feed)) return $plugindir."/noart.gif"; 165 $attr = $feed->attributes(); 166 if(($attr->picture)&&($attr->picture!="http://cdn.last.fm/depth/catalogue/noimage/noartist_140px.jpg")) 167 return img_replace($attr->picture); 168 return $plugindir."/noart.gif"; 169 } 170 171 function get_va_album_art($artist,$album){ 172 $plugindir = get_option('siteurl') . '/wp-content/plugins/' . dirname(plugin_basename(__FILE__)); 173 $url = "http://ws.audioscrobbler.com/1.0/album/VA/". $album."/info.xml"; 174 $sx = new simplexml; 175 unset($feed); 176 $feed = $sx->xml_load_file($url); 177 if(!is_object($feed)) return get_artist_art($artist); 89 178 if(image_exists($feed->coverart->small)) return img_replace($feed->coverart->small); 90 179 if(image_exists($feed->coverart->medium)) return img_replace($feed->coverart->medium); … … 92 181 return get_artist_art($artist); 93 182 } 183 184 94 185 95 186 function lastfm_datediff($date,$ret = 0,$serversec,$recentdisplayed){ … … 123 214 } 124 215 125 126 function lastfm_recent($user,$size,$timediff,$position="left",$text){ 216 function lastfm_extract_artist_link($string){ 217 $artist = split("_",$string); 218 return $artist[0]; 219 } 220 221 function lastfm_recent($user,$size,$timediff,$position="left",$text,$showbadge=true,$badgepos="top",$badgeoptions=""){ 127 222 $plugindir = get_option('siteurl') . '/wp-content/plugins/' . dirname(plugin_basename(__FILE__)); 128 223 if(!$_SESSION["lastfm_wp_head_exists"]) echo '<style type="text/css">@import url("'.$plugindir.'/lastfm.css");</style>'."\n"; … … 132 227 $feed = $sx->xml_load_file($url); 133 228 $recentdisplayed=false; 229 echo "<div>"; 134 230 if(!is_object($feed)) 135 231 lastfm_recent_death("This username does not exist, or the feed service is down."); … … 137 233 lastfm_recent_death("This user has not played any songs yet."); 138 234 elseif(is_object($feed->track)){ 235 if($showbadge&&$badgepos=="top") lastfm_recent_badge($user,$badgeoptions); 139 236 echo "<ul id=\"lastfm_recent\">"; 140 237 $artist = $feed->track->artist->content(); … … 149 246 $albumimage = get_album_art(stripslashes($album->scalar),stripslashes($artist->scalar)); 150 247 }else{ 151 $albumimage = get_artist_art(stripslashes($artist->scalar)); 248 $replace = array(" ","&","/"); 249 $with = array("%20","%26","%2F"); 250 $artist = rawurlencode(utf8_encode(str_replace($replace,$with,stripslashes($artist)))); 251 $album = rawurlencode(utf8_encode(str_replace($replace,$with,stripslashes($album)))); 252 $albumimage = get_va_album_art($artist,$album); 152 253 } 153 254 echo '<li class="'.$newclass.'">'; … … 158 259 echo '</a></p>'; 159 260 echo '<a href="'.$feed->track->url.'" class="lastfm_recent_title">'.stripslashes(lastfm_recent_capitalize($feed->track->name)).'</a><br />'; 160 echo '<span class="lastfm_recent_artist"> '.stripslashes($artist->scalar).'</span><br />';261 echo '<span class="lastfm_recent_artist"><a href="'.lastfm_extract_artist_link($feed->track->url).'" class="lastfm_recent_title">'.stripslashes($artist->scalar).'</a></span><br />'; 161 262 echo '<span class="lastfm_recent_date">'.lastfm_datediff($date->uts,false,$timediff,$recentdisplayed).'</span>'; 162 263 echo '</li>'; 163 264 echo "</ul>"; 265 if($showbadge&&$badgepos=="bottom") lastfm_recent_badge($user,$badgeoptions); 164 266 }else{ 165 267 $k=0; 268 if($showbadge&&$badgepos=="top") lastfm_recent_badge($user,$badgeoptions); 166 269 echo "<ul id=\"lastfm_recent\">"; 167 270 foreach($feed->track as $track){ … … 186 289 echo '</a></p>'; 187 290 echo '<a href="'.$track->url.'" class="lastfm_recent_title">'.stripslashes(lastfm_recent_capitalize($track->name)).'</a><br />'; 188 echo '<span class="lastfm_recent_artist"> '.stripslashes($artist->scalar).'</span><br />';291 echo '<span class="lastfm_recent_artist"><a href="'.lastfm_extract_artist_link($track->url).'" class="lastfm_recent_title">'.stripslashes($artist->scalar).'</a></span><br />'; 189 292 echo '<span class="lastfm_recent_date">'.lastfm_datediff($date->uts,false,$timediff,$recentdisplayed).'</span>'; 190 293 echo '</li>'; … … 194 297 } 195 298 echo "</ul>"; 299 if($showbadge&&$badgepos=="bottom") lastfm_recent_badge($user,$badgeoptions); 196 300 } 197 301 echo "<div id='lastfm_recent_comment'>" . stripslashes(htmlspecialchars_decode($text)) . "</div>"; 198 302 echo "<!--# Last.fm Recently Played Songs Plugin by Taha Paksu -->"; 303 echo "</div>"; 199 304 } 200 305 … … 207 312 208 313 314 function lastfm_recent_control() 315 { 316 $options = get_option("lastfm_recent"); 317 318 if (!is_array( $options )) 319 { 320 $badgeoptions = array( "showavatar" => true, 321 "showrealname" => true, 322 "showgender" => true, 323 "showage" => true, 324 "showcountry" => true, 325 "showregister" => true, 326 "showtrackcount" => true 327 ); 328 $options = array( 329 'user' => '', 330 'title' => 'Last.fm RPS', 331 'size' => 10, 332 'serversec' => 0, 333 'position' => 'left', 334 'text' => '', 335 'showbadge' => true, 336 'badgeposition' => 'top', 337 'badgeoptions' => $badgeoptions, 338 'color' => "black" 339 ); 340 } 341 342 if ($_POST['lastfm_recent_submit']) 343 { 344 $options['user'] = htmlspecialchars($_POST['lastfm_recent_user']); 345 $options['title'] = htmlspecialchars($_POST['lastfm_recent_title']); 346 $options['color'] = htmlspecialchars($_POST['lastfm_recent_color']); 347 $options['size'] = htmlspecialchars($_POST['lastfm_recent_size']); 348 $options['position'] = htmlspecialchars($_POST['lastfm_recent_position']); 349 $options['serversec'] = htmlspecialchars($_POST['lastfm_recent_serverdiff']); 350 $options['text'] = htmlspecialchars($_POST['lastfm_recent_text']); 351 $options['showbadge'] = $_POST['lastfm_recent_showbadge']; 352 $options['badgeposition'] = $_POST['lastfm_recent_badgeposition']; 353 $badgeoptions = array( 354 "showavatar" => $_POST['lastfm_recent_showavatar'], 355 "showrealname" => $_POST['lastfm_recent_showrealname'], 356 "showgender" => $_POST['lastfm_recent_showgender'], 357 "showage" => $_POST['lastfm_recent_showage'], 358 "showcountry" => $_POST['lastfm_recent_showcountry'], 359 "showregister" => $_POST['lastfm_recent_showregister'], 360 "showtrackcount" => $_POST['lastfm_recent_showtrackcount'] 361 ); 362 $options['badgeoptions'] = $badgeoptions; 363 update_option("lastfm_recent", $options); 364 } 365 366 ?> 367 <p> 368 <TABLE> 369 <TR> 370 <TD width="100px">Widget Title: </TD> 371
