function pugpig_get_edition_opds_links($edition, $relative = false)
{
    $links = array();
    if (pugpig_should_allow_search()) {
        $links[] = array('rel' => 'search', 'href' => pugpig_strip_domain(site_url() . '/editionfeed/' . $edition->ID . '/pugpig_atom_contents.manifest?q={query}'), 'title' => 'Search', 'type' => 'application/atom+xml');
    }
    $links = _pugpig_get_links('pugpig_add_edition_opds_link_items', $links, $relative, $edition);
    return $links;
}
function pugpig_catch_request()
{
    // HTML manifest
    if (pugpig_is_pugpig_manifest()) {
        if (!is_singular()) {
            header('HTTP/1.1 403 Forbidden');
            echo "Not a valid pugpig request";
            exit;
        }
        header("Content-Type: text/cache-manifest");
        $post = get_queried_object();
        if ($post->post_status != 'publish') {
            header('X-Pugpig-Status: unpublished');
        } else {
            header('X-Pugpig-Status: published');
        }
        echo pugpig_build_post_manifest_contents($post);
        exit;
    }
    // Package XML file
    if (pugpig_is_pugpig_package_xml()) {
        if (!is_singular()) {
            header('HTTP/1.1 403 Forbidden');
            echo "Not a valid package request";
            print_r($vars);
            exit;
        }
        $post = get_queried_object();
        if ($post->post_type != PUGPIG_EDITION_POST_TYPE) {
            header('HTTP/1.1 403 Forbidden');
            echo "Not a valid package XML request - object is not an edition";
            exit;
        }
        if ($post->post_status != 'publish') {
            header('X-Pugpig-Status: unpublished');
        } else {
            header('X-Pugpig-Status: published');
        }
        package_edition_package_list($post);
        exit;
    }
    if (pugpig_is_pugpig_edition_atom_xml()) {
        if (!is_singular()) {
            header('HTTP/1.1 403 Forbidden');
            echo "Not a singular valid atom feed request";
            exit;
        }
        $post = get_queried_object();
        if ($post->post_type != PUGPIG_EDITION_POST_TYPE) {
            header('HTTP/1.1 403 Forbidden');
            echo "Not a valid atom XML request - object is not an edition";
            exit;
        }
        // TODO: Think about different cache headers for searches?
        $search_term = null;
        if (isset($_GET["q"]) && !empty($_GET["q"])) {
            if (pugpig_should_allow_search()) {
                $search_term = $_GET["q"];
            }
        }
        generate_edition_atom_feed($post->ID, false, $search_term);
        exit;
    }
}