示例#1
0
function publish_to_hub($post_id)
{
    // we want to notify the hub for every feed
    $feed_urls = array();
    $feed_urls[] = get_bloginfo('atom_url');
    $feed_urls[] = get_bloginfo('rss_url');
    $feed_urls[] = get_bloginfo('rdf_url');
    $feed_urls[] = get_bloginfo('rss2_url');
    // remove dups (ie. they all point to feedburner)
    $feed_urls = array_unique($feed_urls);
    // get the address of the publish endpoint on the hub
    $hub_url = get_pubsub_endpoint();
    $p = new Publisher($hub_url);
    // need better error handling
    if (!$p->publish_update($feed_urls, "http_post_wp")) {
        print_r($p->last_response());
    }
    return $post_id;
}
// process form
if ($_POST['sub']) {
    $hub_url = $_POST['hub_url'];
    $topic_url = $_POST['topic_url'];
    // check that a hub url is specified
    if (!$hub_url) {
        echo "Please specify a hub url.<br /><br /><a href='publisher_example.php'>back</a>";
        exit;
    }
    // check that a topic url is specified
    if (!$topic_url) {
        echo "Please specify a topic url to publish.<br /><br /><a href='publisher_example.php'>back</a>";
        exit;
    }
    // $hub_url = "http://pubsubhubbub.appspot.com/publish";
    $p = new Publisher($hub_url);
    if ($p->publish_update($topic_url)) {
        echo "<i>{$topic_url}</i> was successfully published to <i>{$hub_url}</i><br /><br /><a href='publisher_example.php'>back</a>";
    } else {
        echo "ooops...";
        print_r($p->last_response());
    }
} else {
    // display a primitive form for testing
    echo "<form action='publisher_example.php' method='POST'>";
    echo "hub url: <input name='hub_url' type='text' value='http://pubsubhubbub.appspot.com/publish' size='50'/><br />";
    echo "topic url: <input name='topic_url' type='text' value='http://www.onlineaspect.com' size='50' /><br />";
    echo "<input name='sub' type='submit' value='Publish' /><br />";
    echo "</form>";
}
echo "</center>";