/**
 * adds link headers as defined in the current v0.4 draft
 *
 * @link https://github.com/pubsubhubbub/PubSubHubbub/issues/2
 */
function pshb_template_redirect()
{
    // get all feeds
    $feed_urls = pshb_get_feed_urls();
    $comment_feed_urls = pshb_get_comment_feed_urls();
    // get current url
    $urls = array_unique(array_merge($feed_urls, $comment_feed_urls));
    $current_url = (is_ssl() ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
    // check if current url is one of the feed urls
    if (in_array($current_url, $urls)) {
        $hub_urls = pshb_get_pubsub_endpoints();
        // add all "hub" headers
        foreach ($hub_urls as $hub_url) {
            header('Link: <' . $hub_url . '>; rel="hub"', false);
        }
        // add the "self" header
        header('Link: <' . $current_url . '>; rel="self"', false);
    }
}
function pshb_template_redirect() {
  if ((is_comment_feed() && !is_singular())
      || (is_feed() && !is_comment_feed() && !is_archive())) {
    $hub_urls = pshb_get_pubsub_endpoints();
    foreach ($hub_urls as $hub_url) {
      header('Link: <'.$hub_url.'>; rel=hub', false);
    }
    header('Link: <'.( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'].'>; rel=self', false);
  }
}
function pshb_template_redirect()
{
    global $wp;
    $feed_urls = pshb_get_feed_urls();
    $comment_feed_urls = pshb_get_comment_feed_urls();
    $urls = array_unique(array_merge($feed_urls, $comment_feed_urls));
    $current_url = (is_ssl() ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
    if (in_array($current_url, $urls)) {
        $hub_urls = pshb_get_pubsub_endpoints();
        foreach ($hub_urls as $hub_url) {
            header('Link: <' . $hub_url . '>; rel="hub"', false);
        }
        header('Link: <' . $current_url . '>; rel="self"', false);
    }
}