Created
February 14, 2011 22:16
-
-
Save felixtriller/826691 to your computer and use it in GitHub Desktop.
This script fetches the latest links from Delicious and creates a WordPress post. And a little bit more.. :)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if ($_GET['key'] != '123456') | |
die('Nicht erlaubt.'); | |
$file = './delicious2wordpress.data'; | |
$read = fopen($file, 'r'); | |
$line = intval(fgets($read, 64)); | |
fclose($read); | |
if ($line > 0) { | |
$diff = $line*60*60*24*7; | |
} else { | |
$diff = 0; | |
} | |
// fetch from Delicious | |
$datestring = 'Y-m-d\TH:i:s\Z'; | |
$del['fromdt'] = date($datestring, strtotime('last Monday, UTC')-$diff); | |
$del['todt'] = date($datestring, strtotime('Sunday, 23:59:59, UTC')); | |
$del['week'] = date('W', strtotime('last Monday')); | |
$del['username'] = 'username'; | |
$del['password'] = 'password'; | |
$del['tag'] = 'publish'; | |
$del['useragent'] = 'Felix Triller - Private Delicious to WordPress Script'; | |
$del['api'] = 'https://api.del.icio.us/v1/posts/all'; | |
$del['api'] .= '?tag='.$del['tag']; | |
$del['api'] .= '&fromdt='.$del['fromdt']; | |
$del['api'] .= '&todt='.$del['todt']; | |
$curl = curl_init(); | |
curl_setopt($curl, CURLOPT_URL, $del['api']); | |
curl_setopt($curl, CURLOPT_USERPWD, $del['username'].':'.$del['password']); | |
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt($curl, CURLOPT_USERAGENT, $del['useragent']); | |
$result = curl_exec ($curl); | |
$xml = simplexml_load_string($result); | |
$count = count($xml->post); | |
if ($count < 3) { | |
$line++; | |
$read = fopen($file, 'w'); | |
fwrite($read, $line); | |
fclose($read); | |
die('Zu wenig Links ('.$count.').'); | |
} | |
$content = '<ol class="delicious_list">'.PHP_EOL; | |
foreach ($xml->post as $link) { | |
$content .= '<li>'.PHP_EOL; | |
$content .= '„<a href="'.$link['href'].'">'; | |
$content .= htmlentities($link['description'], ENT_QUOTES, 'UTF-8'); | |
$content .= '</a>“'; | |
$content .= ' — <span class="delicious_date">'; | |
$content .= date('d/m/Y', strtotime($link['time'])); | |
$content .= '</span>'; | |
if ($link['extended'] != '') | |
$content .= ' — <span class="delicious_notes">'; | |
$content .= htmlentities($link['extended'], ENT_QUOTES, 'UTF-8').PHP_EOL; | |
$content .= '</span>'; | |
$content .= '</li>'.PHP_EOL; | |
} | |
$content .= '</ol>'.PHP_EOL; | |
$content .= '<p class="delicious_link"><img src="http://felixtriller.de/wordpress/wp-content/themes/felixtriller2/images/profiles/delicious.png" alt="Delicious" width="10" height="10" /> <a href="http://delicious.com/" title="Link zu Delicious">Delicious</a> ist ein Social-Bookmarking-Service <a class="help" title="Was ist das?" href="http://de.wikipedia.org/wiki/Social_Bookmarking"><img src="http://felixtriller.de/wordpress/wp-content/themes/felixtriller2/images/icons/help.png" alt="Help" /></a>, Sie finden mich dort als <a href="http://delicious.com/felixtriller" title="felixtriller auf Delicious">felixtriller</a>.</p>'.PHP_EOL; | |
// publish to WordPress | |
require '../wordpress/wp-includes/class-IXR.php'; | |
$rpc = new IXR_Client( 'http://felixtriller.de/wordpress/xmlrpc.php' ); | |
$post['title'] = 'Delicious Links - Woche '.$del['week']; | |
$post['description'] = $content; | |
$post['categories'] = array('Delicious Links'); | |
$post['mt_keywords'] = 'delicious, links'; | |
$status = $rpc->query( | |
'metaWeblog.newPost', // Method | |
1, // Blog ID | |
'username', // Username | |
'password', // Password | |
$post, // Post struct | |
true // Publish? | |
); | |
if(!$status) { | |
echo 'Error (' . $rpc->getErrorCode() . '): '; | |
echo $rpc->getErrorMessage() . PHP_EOL; | |
exit; | |
} | |
$read = fopen($file, 'w'); | |
fwrite($read, '0'); | |
fclose($read); | |
echo $rpc->getResponse(); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment