Monday 27 May 2013
Facebook StumbleUpon Twitter Google+ Pin It

Displaying Recent Stumbles (From StumbleUpon)

StumbleUpon is a funky web 2.0 community where it recommends websites you may be interested in based on other people similar interests. Unfortunately they do not have an API for easy integration. Luckily though, they do offer RSS Feeds for user’s activity. Here is the code you need to show your recent stumbles:
12345678910111213141516171819202122232425262728293031
<?php
/*
function – recent_stumbles(string $username [, string $type= NULL [, int $limit = 5]])
$username – The stumbleupon username, such as rogem002
$type – Default: NULL – What you want to limit your rss to show. Can be NULL, blog, comments, favorites or reviews
$limit – Default: 5 – how many tweets you wish to show, must be numeric.
*/
function recent_stumbles($username, $type=NULL, $limit=5){
if(!is_numeric($limit)){$limit = 5;}
if($type !== NULL && $type !== 'blog' && $type !== 'comments' && $type !== 'favorites' && $type !== 'reviews'){$type = NULL;}
$xml = simplexml_load_file('http://rss.stumbleupon.com/user/'.urlencode($username).'/'.$type);
$items_count= count($xml->channel->item);
if($items_count < $limit){$limit = $items_count;}
$i = 0;
$return .= '<ul>';
while($i < $limit){
$return .= '
<li title="'.$xml->channel->item[$i]->title.'"><!– '.$xml->channel->item[$i]->pubDate.' –>
<a href="'.$xml->channel->item[$i]->link.'" title="'.$xml->channel->item[$i]->title.'"><img src="'.$xml->channel->item[$i]->enclosure["url"].'" alt="'.$xml->channel->item[$i]->title.'" border="0" />
'.$xml->channel->item[$i]->title.'</a></li>
';
$i++;
}
$return .= '</ul>';
return $return;
}
echo recent_stumbles('Parthiv2412', 'favorites', 5);

No comments: