* http://code.google.com/p/gr2delicious * * @license http://creativecommons.org/licenses/by-nc-sa/3.0/ * @author Patrick Micka * @version 1.0 * @filesource */ error_reporting(E_ALL | E_STRICT); /** * Settings for delicious */ $deliciousApiURI = "https://api.del.icio.us/v1/"; $addPostURIPart = "posts/add?"; /** * Enter your delicious username and password */ $deliciousUser = ""; $deliciousPassword = ""; /** * LongUrl settings */ $longUrlURI = "http://api.longurl.org/v1/expand?url="; $longUrlFormat = "&format=php"; /** * User Agent for curl, so services can identify */ $curlUserAgent = "burningCat"; /** * Settings for Google Reader */ $googleReaderURI = "http://www.google.com/reader/public/atom/user/20-digit-ID-goes-here/state/com.google/broadcast"; /** * Get the contents of the rssfeed of shared items in Google Reader */ $curlGr = curl_init(); /** * Settings for the curl session */ curl_setopt($curlGr, CURLOPT_URL, $googleReaderURI); curl_setopt($curlGr, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curlGr, CURLOPT_CONNECTTIMEOUT, 0); curl_setopt($curlGr, CURLOPT_USERAGENT, $curlUserAgent); $xmlGr = curl_exec($curlGr); /** * Close the session */ curl_close($curlGr); /** * Load the xml data from Google Reader */ $xmlObjGr = simplexml_load_string($xmlGr); /** * Loop through the entries and add each entry to delicious */ foreach($xmlObjGr->entry as $futureBookmark){ $urlTitle = urlencode($futureBookmark->title); foreach($futureBookmark->link->attributes() as $key=> $value){ /** * Only links should be lookup */ if($key == "href"){ /** * Get the real url of the page (converts feedburners and url shorteners to full url */ $curlLu = curl_init(); /** * Set url for LongUrl request */ $luUrl = $longUrlURI . urlencode($value) . $longUrlFormat; /** * Settings for the curl session */ curl_setopt($curlLu, CURLOPT_URL, $luUrl); curl_setopt($curlLu, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curlLu, CURLOPT_CONNECTTIMEOUT, 1); curl_setopt($curlLu, CURLOPT_USERAGENT, $curlUserAgent); $LuArray = unserialize(curl_exec($curlLu)); /** * Close the session */ curl_close($curlLu); /** * Set the tags */ preg_match('/TAGS\((?[^)]+)\)/', $futureBookmark->content, $note_tag_matches); $tags = explode(' ', $note_tag_matches['tags']); /** * Close the session */ } } /** * Setup the curl session for delicious */ $curlDel = curl_init(); /** * Set url for adding bookmark to Delicious */ $url = $deliciousApiURI . $addPostURIPart ."&url=". $LuArray["long_url"] ."&description=". urlencode(html_entity_decode(urldecode($urlTitle))) ."&tags=". urlencode(implode(" ", $tags)); /** * Settings for the curl session */ curl_setopt($curlDel, CURLOPT_URL, $url); curl_setopt($curlDel, CURLOPT_CONNECTTIMEOUT, 5); curl_setopt($curlDel, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curlDel, CURLOPT_USERPWD, $deliciousUser .":". $deliciousPassword); curl_setopt($curlDel, CURLOPT_USERAGENT, $curlUserAgent); curl_exec($curlDel); /** * Close the session */ curl_close($curlDel); } ?>