Skip to content

Instantly share code, notes, and snippets.

@justinkelly
Created July 19, 2010 03:43
Show Gist options
  • Save justinkelly/480987 to your computer and use it in GitHub Desktop.
Save justinkelly/480987 to your computer and use it in GitHub Desktop.
Pinboard.in & Delicious to RSS script
<?php
/** Config section - start **/
$bookmark_user = "--your-username-";
$bookmark_pass = "--your-password";
$bookmark_service = "pinboard.in"; // pinboard.in or delicious.com/del.icio.us
/** Config section - end **/
$url = "https://" . $bookmark_user . ":" . $bookmark_pass . "@api." . $bookmark_service . "/v1/posts/all";
$local_file = $bookmark_service . "." . $bookmark_user . ".xml";
/** Functions - start **/
function cURLcheckBasicFunctions()
{
if( !function_exists("curl_init") &&
!function_exists("curl_setopt") &&
!function_exists("curl_exec") &&
!function_exists("curl_close") ) return false;
else return true;
}
/*
* Returns string status information.
* Can be changed to int or bool return types.
*/
function cURLdownload($url, $file)
{
if( !cURLcheckBasicFunctions() ) return "UNAVAILABLE: cURL Basic Functions";
$ch = curl_init();
if($ch)
{
$fp = fopen($file, "w");
if($fp)
{
if( !curl_setopt($ch, CURLOPT_URL, $url) )
{
fclose($fp); // to match fopen()
curl_close($ch); // to match curl_init()
return "FAIL: curl_setopt(CURLOPT_URL)";
}
if( !curl_setopt($ch, CURLOPT_FILE, $fp) ) return "FAIL: curl_setopt(CURLOPT_FILE)";
if( !curl_setopt($ch, CURLOPT_HEADER, 0) ) return "FAIL: curl_setopt(CURLOPT_HEADER)";
if( !curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0) ) return "FAIL: curl_setopt(CURLOPT_SSL_VERIFYPEER)";
if( !curl_exec($ch) ) return "FAIL: curl_exec()";
curl_close($ch);
fclose($fp);
return "SUCCESS: $file [$url]";
}
else return "FAIL: fopen()";
}
else return "FAIL: curl_init()";
}
//strip crap from xml to amke rss all happy
function XMLClean($string) {
return preg_replace('/&(?![A-Za-z0-9#]{1,7};)/','&amp;',$string);
}
/** Functions - end **/
//get teh file
cURLdownload($url, $local_file);
//set the rss header
header("Content-Type: application/rss+xml; charset=ISO-8859-1");
$rssfeed = '<?xml version="1.0" encoding="ISO-8859-1"?>';
$rssfeed .= '<rss version="2.0">';
$rssfeed .= '<channel>';
$rssfeed .= '<title>Pinboard.in links</title>';
$rssfeed .= '<link>http://blog.justin.kelly.org.au/pinboardindeliciouscom-chrome-bookmark-syncin</link>';
$rssfeed .= '<description>Pinboard.in links as rss</description>';
$rssfeed .= '<language>en-us</language>';
#$rssfeed .= '<copyright>Copyright (C) 2009 mywebsite.com</copyright>';
//get the xml and convert to rsss items
$xml = simplexml_load_file($bookmark_service . "." . $bookmark_user . ".xml");
foreach($xml->post as $posts)
{
$rssfeed .= '<item>';
$rssfeed .= '<title>' . XMLClean($posts['description']) . ' | ' . XMLClean($posts['tag']) .'</title>';
$rssfeed .= '<description>' . XMLClean($posts['extended']) . '</description>';
$rssfeed .= '<link>' . XMLClean($posts['href']) . '</link>';
$rssfeed .= '<guid>' . XMLClean($posts['href']) . '</guid>';
$rssfeed .= '<pubDate>' . date("D, d M Y H:i:s O", strtotime($posts['time'])) . '</pubDate>';
$rssfeed .= '</item>';
}
$rssfeed .= '</channel>';
$rssfeed .= '</rss>';
echo $rssfeed;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment