0)
{
// posterous api url
$url = "http://posterous.com/api/readposts?hostname=$host&num_posts=50";
// call posterous api
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 30);
$text = curl_exec($curl);
curl_close($curl);
// load the xml
$xml = simplexml_load_string($text);
if (count($xml->err) > 0)
{
// handle errors
$html = "error: " . strtolower($xml->err[msg]);
}
else if (count($xml->post) > 0)
{
// construct output
$html = "";
foreach ($xml->post as $node)
{
$url = $node->url;
$link = $node->link;
$parts = parse_url($link);
$domain = $parts["host"];
$tags = "";
foreach ($node->tag as $tag)
{
$tags .= " #$tag";
}
$date = date("Y-m-d H:i", strtotime($node->date));
$name = $node->title;
$views = $node->views;
$html .= "$date - $name ($views views) $tags
\n";
}
}
}
?>
links:
echo $html; } else { ?>enter a posterous site name to retrieve a list of post.ly links:
} ?>