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 (isset($_GET["newsstand"]) && $_GET["newsstand"] == 'true') {
    $newsstand_mode = true;
}
if (isset($_GET["region"])) {
    $extra_comments[] = "Region Filter: " . $_GET["region"];
}
// This might be needed for caching in the future
// $cache_key = ($internal ? "INT_" : "EXT_") . ($atom_mode ? "ATOM_" : "PACK_") . ($newsstand_mode ? "NEWS" : "OPDS");
$extra_comments[] = "Status: {$status}. Number of editions to include: " . pugpig_get_num_editions();
$editions = pugpig_get_editions($status, pugpig_get_num_editions());
$edition_ids = array();
$modified = null;
foreach ($editions as $edition) {
    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
function pugpig_get_post_modified_time_edition($modified, $post)
{
    // Get the most recent modified date of all pages in editions
    if (!empty($post) && $post->post_type == PUGPIG_EDITION_POST_TYPE) {
        $page_ids = pugpig_get_edition_array(get_post_custom($post->ID));
        foreach ($page_ids as $page_id) {
            $page = get_post($page_id);
            if ($page === null) {
                $page_modified = 0;
            } elseif ($post->post_type != PUGPIG_EDITION_POST_TYPE) {
                $page_modified = pugpig_get_page_modified($page);
            } else {
                $page_modified = strtotime($page->post_modified);
            }
            if ($page_modified > $modified) {
                $modified = $page_modified;
            }
        }
    }
    return $modified;
}
function pugpig_get_page($id, $edition_id, $content_filter = null)
{
    $post = get_post($id);
    // Just in case this item has been deleted
    if (!is_object($post) || apply_filters('pugpig_filter_page', false, $post, $content_filter)) {
        return null;
    }
    // Get the link for sharing
    // TODO: Allow post specific values in future
    // Get canonical URL for sharing (e.g. Twitter, Facebook)
    $sharing_link = apply_filters('pugpig_page_sharing_link', pugpig_get_canonical_url($post), $post);
    $status = $post->post_status;
    // We want everything except draft, pending and trashed posts in an edition
    if ($status != 'draft' && $status != 'trash' && $status != 'pending') {
        $status = 'published';
        // We expect the word 'published'
    }
    $stop_id_prefixes = false;
    $page = array('id' => pugpig_get_atom_post_id($post, $stop_id_prefixes), 'title' => pugpig_get_feed_post_title($post), 'access' => pugpig_get_atom_post_access($post), 'summary' => pugpig_get_feed_post_summary($post), 'status' => $status, 'modified' => pugpig_get_page_modified($post), 'date' => strtotime($post->post_date), 'type' => $post->post_type, 'categories' => pugpig_get_feed_post_categories($post, $content_filter), 'url' => url_create_deep_dot_url(pugpig_strip_domain(pugpig_get_html_url($post, $edition_id))), 'sharing_link' => $sharing_link, 'manifest' => url_create_deep_dot_url(pugpig_strip_domain(pugpig_get_manifest_url($post))), 'custom_categories' => pugpig_get_feed_post_custom_categories($post, $content_filter), 'links' => pugpig_get_links($post, $content_filter), 'author' => pugpig_get_feed_post_author($post));
    $level = pugpig_get_feed_post_level($post, $content_filter);
    if (!empty($level)) {
        $page['level'] = $level;
    }
    if ($stop_id_prefixes) {
        $page['id_prefix'] = '';
    }
    return $page;
}