function generate_edition_atom_feed($edition_id, $include_hidden = false, $search_term = null) { // Check it exists $edition = get_post($edition_id); if (empty($edition)) { header('HTTP/1.1 404 Not Found'); exit; } pugpig_remove_wordpress_headers(); $modified = pugpig_get_page_modified($edition); if ($search_term) { $modified = time(); } if ($edition->post_status != 'publish') { if (FALSE && !pugpig_is_internal_user()) { header('HTTP/1.1 403 Forbidden'); exit; } 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); } $links = pugpig_get_edition_atom_links($edition, true); header('Content-Type: ' . feed_content_type('atom') . '; charset=' . get_option('blog_charset'), true); header('Content-Disposition: inline'); global $wp_query; $filter = ""; $regions = pugpig_get_available_region_array(); foreach (array_keys($regions) as $region) { if (isset($wp_query->query_vars[$region . "_pugpig_atom_contents_manifest"])) { $filter = $region; } } $region = ""; $d = pugpig_get_atom_container($edition_id, $include_hidden, $search_term, $links, $filter); $d->formatOutput = true; echo $d->saveXML(); }
function pugpig_add_endpoints() { $regions = pugpig_get_available_region_array(); foreach (array_merge(array(''), array_keys($regions)) as $region) { $prefix = $region ? $region . "_" : ""; $endpoint = str_replace(".", "_", $prefix . PUGPIG_ATOM_FILE_NAME); add_rewrite_tag('%' . $endpoint . '%', ''); add_rewrite_rule('editionfeed/([^/]+)/' . $prefix . PUGPIG_ATOM_FILE_NAME . '$', 'index.php?post_type=pugpig_edition&p=$matches[1]&' . $endpoint . '=true', "top"); } $endpoint = str_replace(".", "_", PUGPIG_EDITION_PACKAGE_FILE_NAME); add_rewrite_tag('%' . $endpoint . '%', ''); add_rewrite_rule('editionfeed/([^/]+)/' . PUGPIG_EDITION_PACKAGE_FILE_NAME . '$', 'index.php?post_type=pugpig_edition&p=$matches[1]&' . $endpoint . '=true', "top"); //global $wp_rewrite; //$wp_rewrite->flush_rules(); // Stop WordPress redirecting our lovely URLs and putting a / on the end if (pugpig_is_pugpig_url() || pugpig_is_pugpig_manifest() || pugpig_is_pugpig_package_xml() || pugpig_is_pugpig_edition_atom_xml()) { // Turn off the CDN rewriting for Pugpig URLS. This is needed for W3 Total Cache if (!defined('DONOTCDN')) { define('DONOTCDN', 'PUGPIG'); } if (!defined('DONOTCACHEPAGE')) { define('DONOTCACHEPAGE', 'PUGPIG'); } // Don't redirect - we don't want the slash on the end remove_filter('template_redirect', 'redirect_canonical'); // Ensure we don't get URLs to different domains for attachments add_filter('wp_get_attachment_url', 'pugpig_wp_get_attachment_url', 2); add_filter('stylesheet_directory_uri', 'pugpig_wp_get_attachment_url', 2); add_filter('template_directory_uri', 'pugpig_wp_get_attachment_url', 2); } // We need these so that WordPress strips the bits off and still matches the post add_rewrite_endpoint(PUGPIG_HTML_FILE_NAME, EP_PERMALINK | EP_ROOT | EP_SEARCH | EP_PAGES); // Adds pugpig.html as default document to permalinks add_rewrite_endpoint(PUGPIG_HTML_MANIFEST_NAME, EP_PERMALINK | EP_ROOT | EP_SEARCH | EP_PAGES); // Adds manifest to permalinks add_rewrite_endpoint(PUGPIG_EDITION_PACKAGE_FILE_NAME, EP_PERMALINK | EP_ROOT | EP_SEARCH | EP_PAGES); // Adds package files add_rewrite_endpoint(PUGPIG_ATOM_FILE_NAME, EP_PERMALINK | EP_ROOT | EP_SEARCH | EP_PAGES); // Adds ATOM XML files }