function pugpig_set_custom_post_headers()
{
    pugpig_remove_wordpress_headers();
    global $post;
    if (isset($post) && is_single()) {
        pugpig_set_cache_headers(pugpig_get_page_modified($post), pugpig_get_content_ttl());
    }
    // Set the headers for upstream auth
    $x_entitlement = pugpig_get_post_entitlement_header($post);
    if (!empty($x_entitlement)) {
        header('X-Pugpig-Entitlement: ' . $x_entitlement);
    }
}
    if (pugpig_should_keep_edition_in_feed($edition)) {
        $edition_ids[] = $edition->ID;
        $atom_timestamp = pugpig_get_page_modified($edition);
        if ($atom_mode) {
            $this_time = $atom_timestamp;
        } else {
            $package_timestamp = pugpig_get_edition_update_date(pugpig_get_edition($edition->ID), false);
            $this_time = max($package_timestamp, $atom_timestamp);
            // so cover changes etc. are picked up
        }
        if ($modified == NULL || $modified < $this_time) {
            $modified = $this_time;
        }
    }
}
pugpig_set_cache_headers($modified, $ttl);
$d = pugpig_get_opds_container($edition_ids, $internal, $atom_mode, $newsstand_mode, $extra_comments);
// Add any static OPDS entries to the feed
$entry_xml_string = pugpig_get_extra_opds_entries();
if (!empty($entry_xml_string)) {
    $fragment = $d->createDocumentFragment();
    $fragment->appendChild($d->createComment("Adding static entries from pugpig_static_entry_xml setting"));
    $ret = $fragment->appendXML($entry_xml_string);
    if (!$ret) {
        $fragment->appendChild($d->createComment("Failed to add static entries. Maybe it is not valid XML"));
    }
    $domnode = $d->getElementsByTagName('feed')->item(0);
    $domnode->appendChild($fragment);
}
$d->formatOutput = true;
$opds = $d->saveXML();
function package_edition_package_list($edition)
{
    $edition_tag = pugpig_get_full_edition_key($edition);
    $wp_ud_arr = wp_upload_dir();
    if ($edition->post_status == 'publish') {
        $cdn = get_option('pugpig_opt_cdn_domain');
    } else {
        $cdn = '';
    }
    $xml = _package_edition_package_list_xml(PUGPIG_MANIFESTPATH . 'packages/', $edition_tag, pugpig_strip_domain($wp_ud_arr['baseurl']) . '/pugpig-api/packages/', $cdn, 'string', '*', PUGPIG_ATOM_FILE_NAME);
    if (is_null($xml)) {
        header('HTTP/1.0 404 Not Found');
        echo "This page does not exist. Maybe edition {$edition_tag} has no packages.";
        exit;
    }
    pugpig_remove_wordpress_headers();
    $modified = get_edition_package_timestamp($edition->ID);
    if ($edition->post_status != 'publish') {
        header('X-Pugpig-Status: unpublished');
        pugpig_set_cache_headers($modified, 0);
    } else {
        header('X-Pugpig-Status: published');
        pugpig_set_cache_headers($modified, pugpig_get_feed_ttl());
    }
    $x_entitlement = pugpig_get_edition_entitlement_header($edition);
    if (!empty($x_entitlement)) {
        header('X-Pugpig-Entitlement: ' . $x_entitlement);
    }
    header('Content-Type: application/pugpigpkg+xml; charset=utf-8');
    header('Content-Disposition: inline');
    print $xml;
    return NULL;
}