function pugpig_get_opds_container($edition_ids, $internal = false, $atom_mode = false, $newsstand_mode = false, $extra_comments = array()) { $d = new DomDocument('1.0', 'UTF-8'); $feed = $d->createElement('feed'); $feed->setAttribute('xmlns', 'http://www.w3.org/2005/Atom'); if ($newsstand_mode) { $feed->setAttribute('xmlns:news', 'http://itunes.apple.com/2011/Newsstand'); } else { $feed->setAttribute('xmlns:dcterms', 'http://purl.org/dc/terms/'); $feed->setAttribute('xmlns:opds', 'http://opds-spec.org/2010/catalog'); $feed->setAttribute('xmlns:app', 'http://www.w3.org/2007/app'); $feed->setAttribute('xmlns:at', 'http://purl.org/atompub/tombstones/1.0'); $feed->setAttribute('xmlns:pp', 'http://pugpig.com/2014/atom/'); } $comment = $atom_mode ? "Atom" : "Package"; if ($internal) { $comment .= ' Internal Feed'; } else { $comment .= ' External Feed'; } if ($newsstand_mode) { $comment .= " for Newsstand"; } $feed->appendChild($d->createComment(' ' . $comment . " - Generated: " . date(DATE_RFC822) . ' ')); foreach ($extra_comments as $extra_comment) { $feed->appendChild($d->createComment(' ' . $extra_comment . ' ')); } $feed->appendChild(newElement($d, 'id', pugpig_get_atom_tag('opds'))); _pugpig_create_xml_link($d, $feed, array('rel' => 'self', 'type' => 'application/atom+xml;profile=opds-catalog;kind=acquisition', 'href' => pugpig_self_link())); if (function_exists('pugpig_get_opds_extras')) { $extras = pugpig_get_opds_extras(); if (isset($extras['links'])) { foreach ($extras['links'] as $link) { _pugpig_create_xml_link($d, $feed, $link); } } if (!empty($extras['auth_endpoints'])) { $authorisation = $d->createElement('pp:authorisation', ''); $feed->appendChild($authorisation); foreach ($extras['auth_endpoints'] as $auth) { $authorisation = pugpig_get_authorisationprovider($d, $auth, $authorisation); } } if (isset($extras['custom_categories'])) { foreach ($extras['custom_categories'] as $scheme => $values) { _pugpig_create_atom_category($d, $feed, $scheme, $values); } } } $author = $d->createElement('author'); $author->appendChild($d->createElement('name', 'Pugpig')); $feed->appendChild($author); $feed->appendChild($d->createElement('title', 'All Issues')); $feed->appendChild($d->createElement('subtitle', $comment)); $editions = array(); $updated = 1; // 1 second into UNIX epoch (0 == current time?) foreach ($edition_ids as $key => $edition_id) { $editions[] = $edition_id; $edition_updated_atom = pugpig_get_edition_update_date(pugpig_get_edition($edition_id, true, !$atom_mode), true); $edition_updated_package = pugpig_get_edition_update_date(pugpig_get_edition($edition_id, true, !$atom_mode), false); $edition_updated = max($edition_updated_atom, $edition_updated_package); if ($edition_updated > $updated) { $updated = $edition_updated; } } $feed->appendChild(newElement($d, 'updated', pugpig_date3339($updated))); foreach ($editions as $edition) { $edition = pugpig_get_edition($edition, true, !$atom_mode); if (!$atom_mode && array_key_exists('zip', $edition) && $edition['zip'] == '' && !$edition['is_pdf']) { $feed->appendChild($d->createComment(' ' . ucfirst($edition['status']) . ' ' . pugpig_get_atom_tag($edition['key']) . ' does not have an up to date package ')); } else { $feed->appendChild(pugpig_get_opds_entry($d, $edition, $internal, $atom_mode, $newsstand_mode)); } } $d->appendChild($feed); return $d; }
function pugpig_get_opds_container($edition_ids, $internal = FALSE, $atom_mode = FALSE, $newsstand_mode = FALSE, $extra_comments = array()) { $d = new DomDocument('1.0', 'UTF-8'); $feed = $d->createElement('feed'); $feed->setAttribute('xmlns', 'http://www.w3.org/2005/Atom'); if ($newsstand_mode) { $feed->setAttribute('xmlns:news', 'http://itunes.apple.com/2011/Newsstand'); } else { $feed->setAttribute('xmlns:dcterms', 'http://purl.org/dc/terms/'); $feed->setAttribute('xmlns:opds', 'http://opds-spec.org/2010/catalog'); $feed->setAttribute('xmlns:app', 'http://www.w3.org/2007/app'); $feed->setAttribute('xmlns:at', 'http://purl.org/atompub/tombstones/1.0'); } $comment = $atom_mode ? "Atom" : "Package"; if ($internal) { $comment .= ' Internal Feed'; } else { $comment .= ' External Feed'; } if ($newsstand_mode) { $comment .= " for Newsstand"; } $feed->appendChild($d->createComment(' ' . $comment . " - Generated: " . date(DATE_RFC822) . ' ')); foreach ($extra_comments as $extra_comment) { $feed->appendChild($d->createComment(' ' . $extra_comment . ' ')); } $feed->appendChild(newElement($d, 'id', pugpig_get_atom_tag('opds'))); $link = $d->createElement('link'); $link->setAttribute('rel', 'self'); $link->setAttribute('type', 'application/atom+xml;profile=opds-catalog;kind=acquisition'); $link->setAttribute('href', pugpig_self_link()); $feed->appendChild($link); $author = $d->createElement('author'); $author->appendChild($d->createElement('name', 'Pugpig')); $feed->appendChild($author); $feed->appendChild($d->createElement('title', 'All Issues')); $feed->appendChild($d->createElement('subtitle', $comment)); $editions = array(); $updated = 1; // 1 second into UNIX epoch (0 == current time?) foreach ($edition_ids as $key => $edition_id) { $editions[] = $edition_id; $edition_updated = pugpig_get_edition_update_date(pugpig_get_edition($edition_id, TRUE, !$atom_mode), $atom_mode); if ($edition_updated > $updated) { $updated = $edition_updated; } } $feed->appendChild(newElement($d, 'updated', pugpig_date3339($updated))); foreach ($editions as $edition) { $edition = pugpig_get_edition($edition, TRUE, !$atom_mode); if (!$atom_mode && array_key_exists('zip', $edition) && $edition['zip'] == '') { $feed->appendChild($d->createComment(' ' . ucfirst($edition['status']) . ' ' . pugpig_get_atom_tag($edition['key']) . ' does not have an up to date package ')); } else { $feed->appendChild(pugpig_get_opds_entry($d, $edition, $internal, $atom_mode, $newsstand_mode)); } } $d->appendChild($feed); return $d; }