Zate
08-07-2007, 07:12 PM
Something that maybe someone else might find useful.
I created this to use with the RSS Features in vbulletin. It basically uses the DiggAPI to connect to Digg and grab what ever your telling it to grab, and returns that data as a RSS 2.0 feed (it even validates too I think). You can then use that in the RSS feeds in vbulletin to be posted in what ever forum you like.
Why not use the regular digg rss feeds?.. well mainly because I get more control this way, and because those feeds link to digg, not the article submitted.
So how does it work? Just copy the code below into a php file, I call mine digg.php. It takes several arguments.
container= and topic= allow you to get the data from any of the containers and topics on digg. You can find a list of what exactly they are here (http://apidoc.digg.com/Topics). The container shortname and topic shortname are what you use. Dont use both, use container OR topic.
status= allows you to choose between getting upcoming, or popular stories. Default is popular
count= this tells the script how many article to return, default is 10 maximum is 100.
sort= - this sorts the resules and can be 1 of 4 entries. More info here (http://apidoc.digg.com/ListStories) (all the way to the bottom)
so, an example? http://www.mydomain.com/digg.php?container=gaming will return the latest popular 10 in the gaming container.
So inside the code, there is user_agent and AKEY... both you need to customise.
user_agent should be Your-Site/1.0 (it just identifies your request)
AKEY is your appkey and needs to be in the form of http%3A%2F%2Fwww.yoursite.com
So here is the code, be nice if your gonna critique it, i just threw it together to scratch and itch. I plan to do it as a plugin eventually and allow tweaking all the options through the adminCP and have it post the responses itself, instead of using the vbulletin RSS system. This will allow using of more elements of the diggapi instead of just what the item tag in RSS 2.0 lets me use.
<?php
ini_set("user_agent", "Change-Me/1.0");
define("AKEY", "http%3A%2F%2Fwww.CHANGEME.com");
$url = "http://services.digg.com/stories?appkey=".AKEY; //this url works
if ($_GET['container']) {
$url = "http://services.digg.com/stories/container/". htmlentities($_GET['container'])."/";
if ($_GET['status']) {
$status = $_GET['status'];
switch($status) {
case 'upcoming' :
$url .= "upcoming";
break;
}
} else { $url .= "popular"; }
$url .= "?appkey=".AKEY;
if ($_GET['num']) {
$url .= "&count=".htmlentities($_GET['num']);
}
if ($_GET['sort']) {
$sort = htmlentities($_GET['sort']);
switch($sort) {
case 'promote_date-desc':
$url .= "&sort=".$sort;
break;
case 'promote_date-asc':
$url .= "&sort=".$sort;
break;
case 'submit_date-desc':
$url .= "&sort=".$sort;
break;
case 'submit_date-asc':
$url .= "&sort=".$sort;
break;
}
}
}
if ($_GET['topic']) {
$url = "http://services.digg.com/stories/topic/". htmlentities($_GET['topic'])."/";
if ($_GET['status']) {
$status = $_GET['status'];
$status = $_GET['status'];
switch($status) {
case 'upcoming' :
$url .= "upcoming";
break;
case 'popular' :
$url .= "popular";
break;
}
} else { $url .= "popular"; }
$url .= "?appkey=".AKEY;
if ($_GET['num']) {
$url .= "&count=".htmlentities($_GET['num']);
}
if ($_GET['sort']) {
$sort = htmlentities($_GET['sort']);
switch($sort) {
case 'promote_date-desc':
$url .= "&sort=".$sort;
break;
case 'promote_date-asc':
$url .= "&sort=".$sort;
break;
case 'submit_date-desc':
$url .= "&sort=".$sort;
break;
case 'submit_date-asc':
$url .= "&sort=".$sort;
break;
}
}
}
$data = open_url($url);
$diggData = new SimpleXMLElement($data);
$html = '<?xml version="1.0" encoding="windows-1252" ?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
<channel>
<title>Digg Proxy Feed</title>
<link>http://www.tampagamers.com/digg.php</link>
<description>Latest Articles - '.xmlencode($url).'</description>
';
foreach ($diggData->story as $story) {
$desc = $story->description;
$author = $story->user['name'];
$html .= '<item>
<title>'.xmlencode($story->title).'</title>
<link>'.xmlencode($story["link"]).'</link>
<description>'.xmlencode($desc).'</description>
<guid>'.xmlencode($story["link"]).'</guid>
<category>'.xmlencode($story->container["name"]).' - '.xmlencode($story->topic["name"]).'</category>
<dc:creator>'.xmlencode($author).'</dc:creator>
</item>
';
}
$html .= '
</channel>
</rss>';
header("Content-Type: application/rss+xml");
echo $html;
function changeencoding (&$item1, $key) {
$item1 = "&#".Ord($key).";";
}
function xmlencode ($s) {
if (empty($xmltrans)) { // do this only once
$xmltrans = get_html_translation_table(HTML_ENTITIES);
array_walk ($xmltrans, 'changeencoding');
reset ($xmltrans);
}
return strtr($s, $xmltrans);
}
function open_url($url) {
global $data;
$stream = @fopen($url, 'r');
if (!$stream) { die("There was a problem connecting to Digg.com with $url"); }
while (!feof($stream)) {
$data .= fgets($stream);
}
fclose($stream);
return $data;
}
?>
And please, if you have a way of doing something better then let me know. Feel free to use this code as you like, give me credit, or not doesnt matter.
I created this to use with the RSS Features in vbulletin. It basically uses the DiggAPI to connect to Digg and grab what ever your telling it to grab, and returns that data as a RSS 2.0 feed (it even validates too I think). You can then use that in the RSS feeds in vbulletin to be posted in what ever forum you like.
Why not use the regular digg rss feeds?.. well mainly because I get more control this way, and because those feeds link to digg, not the article submitted.
So how does it work? Just copy the code below into a php file, I call mine digg.php. It takes several arguments.
container= and topic= allow you to get the data from any of the containers and topics on digg. You can find a list of what exactly they are here (http://apidoc.digg.com/Topics). The container shortname and topic shortname are what you use. Dont use both, use container OR topic.
status= allows you to choose between getting upcoming, or popular stories. Default is popular
count= this tells the script how many article to return, default is 10 maximum is 100.
sort= - this sorts the resules and can be 1 of 4 entries. More info here (http://apidoc.digg.com/ListStories) (all the way to the bottom)
so, an example? http://www.mydomain.com/digg.php?container=gaming will return the latest popular 10 in the gaming container.
So inside the code, there is user_agent and AKEY... both you need to customise.
user_agent should be Your-Site/1.0 (it just identifies your request)
AKEY is your appkey and needs to be in the form of http%3A%2F%2Fwww.yoursite.com
So here is the code, be nice if your gonna critique it, i just threw it together to scratch and itch. I plan to do it as a plugin eventually and allow tweaking all the options through the adminCP and have it post the responses itself, instead of using the vbulletin RSS system. This will allow using of more elements of the diggapi instead of just what the item tag in RSS 2.0 lets me use.
<?php
ini_set("user_agent", "Change-Me/1.0");
define("AKEY", "http%3A%2F%2Fwww.CHANGEME.com");
$url = "http://services.digg.com/stories?appkey=".AKEY; //this url works
if ($_GET['container']) {
$url = "http://services.digg.com/stories/container/". htmlentities($_GET['container'])."/";
if ($_GET['status']) {
$status = $_GET['status'];
switch($status) {
case 'upcoming' :
$url .= "upcoming";
break;
}
} else { $url .= "popular"; }
$url .= "?appkey=".AKEY;
if ($_GET['num']) {
$url .= "&count=".htmlentities($_GET['num']);
}
if ($_GET['sort']) {
$sort = htmlentities($_GET['sort']);
switch($sort) {
case 'promote_date-desc':
$url .= "&sort=".$sort;
break;
case 'promote_date-asc':
$url .= "&sort=".$sort;
break;
case 'submit_date-desc':
$url .= "&sort=".$sort;
break;
case 'submit_date-asc':
$url .= "&sort=".$sort;
break;
}
}
}
if ($_GET['topic']) {
$url = "http://services.digg.com/stories/topic/". htmlentities($_GET['topic'])."/";
if ($_GET['status']) {
$status = $_GET['status'];
$status = $_GET['status'];
switch($status) {
case 'upcoming' :
$url .= "upcoming";
break;
case 'popular' :
$url .= "popular";
break;
}
} else { $url .= "popular"; }
$url .= "?appkey=".AKEY;
if ($_GET['num']) {
$url .= "&count=".htmlentities($_GET['num']);
}
if ($_GET['sort']) {
$sort = htmlentities($_GET['sort']);
switch($sort) {
case 'promote_date-desc':
$url .= "&sort=".$sort;
break;
case 'promote_date-asc':
$url .= "&sort=".$sort;
break;
case 'submit_date-desc':
$url .= "&sort=".$sort;
break;
case 'submit_date-asc':
$url .= "&sort=".$sort;
break;
}
}
}
$data = open_url($url);
$diggData = new SimpleXMLElement($data);
$html = '<?xml version="1.0" encoding="windows-1252" ?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
<channel>
<title>Digg Proxy Feed</title>
<link>http://www.tampagamers.com/digg.php</link>
<description>Latest Articles - '.xmlencode($url).'</description>
';
foreach ($diggData->story as $story) {
$desc = $story->description;
$author = $story->user['name'];
$html .= '<item>
<title>'.xmlencode($story->title).'</title>
<link>'.xmlencode($story["link"]).'</link>
<description>'.xmlencode($desc).'</description>
<guid>'.xmlencode($story["link"]).'</guid>
<category>'.xmlencode($story->container["name"]).' - '.xmlencode($story->topic["name"]).'</category>
<dc:creator>'.xmlencode($author).'</dc:creator>
</item>
';
}
$html .= '
</channel>
</rss>';
header("Content-Type: application/rss+xml");
echo $html;
function changeencoding (&$item1, $key) {
$item1 = "&#".Ord($key).";";
}
function xmlencode ($s) {
if (empty($xmltrans)) { // do this only once
$xmltrans = get_html_translation_table(HTML_ENTITIES);
array_walk ($xmltrans, 'changeencoding');
reset ($xmltrans);
}
return strtr($s, $xmltrans);
}
function open_url($url) {
global $data;
$stream = @fopen($url, 'r');
if (!$stream) { die("There was a problem connecting to Digg.com with $url"); }
while (!feof($stream)) {
$data .= fgets($stream);
}
fclose($stream);
return $data;
}
?>
And please, if you have a way of doing something better then let me know. Feel free to use this code as you like, give me credit, or not doesnt matter.