$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
$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"));
Beispiel #2
0
 function is_authorised($edition_num, $pugpigCredsSecret)
 {
     $edition_id = get_edition_id($edition_num);
     $edition = pugpig_get_edition($edition_id);
     $free_or_draft = $edition['price'] == 'FREE' || $edition['status'] == 'draft';
     $is_packager_request = $_SERVER['HTTP_USER_AGENT'] === 'PugpigNetwork/Packager';
     $authorised = $free_or_draft || $is_packager_request;
     if (!$free_or_draft && isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW']) && isset($pugpigCredsSecret)) {
         $username = $_SERVER['PHP_AUTH_USER'];
         $password = sha1("{$edition_id}:{$username}:{$pugpigCredsSecret}");
         $authorised = $password == $_SERVER['PHP_AUTH_PW'];
     }
     return $authorised;
 }
function pugpig_get_rss_section($edition_id, $nid)
{
    // print_r('pugpig_get_rss_section(' . $edition_id . ',' . $nid . ')');
    $edition = pugpig_get_edition($edition_id, false);
    $section = pugpig_get_page($nid);
    $d = new DomDocument('1.0', 'UTF-8');
    $feed = $d->createElement('rss');
    $feed->setAttribute('version', '2.0');
    $channel = $d->createElement('channel');
    $feed->appendChild($channel);
    $channel->appendChild(newElement($d, 'title', $section['title']));
    $in_section = false;
    foreach (pugpig_get_kindle_page_array($edition) as $page) {
        if ($page['id'] == $nid && $page['level'] == 1 && !$in_section) {
            $in_section = true;
        } else {
            if ($page['level'] == 1) {
                // Bail when we hit the section higher level page
                $in_section = false;
            } elseif ($in_section) {
                $item = $d->createElement('item');
                $abs_path = pugpig_abs_link('editions/' . pugpig_get_atom_tag($edition['key']) . '/data/' . $page['id'] . '/kindle.html');
                $item->appendChild(newElement($d, 'link', $abs_path));
                $channel->appendChild($item);
            }
        }
    }
    $d->appendChild($feed);
    return $d;
}
 function is_authorised($edition_num, $pugpigCredsSecret)
 {
     $edition_id = get_edition_id($edition_num);
     $edition = pugpig_get_edition($edition_id);
     $free_or_draft = $edition['price'] == 'FREE' || $edition['status'] == 'draft';
     $is_packager_request = array_key_exists('HTTP_USER_AGENT', $_SERVER) && $_SERVER['HTTP_USER_AGENT'] === 'PugpigNetwork/Packager';
     $authorised = $free_or_draft || $is_packager_request;
     if (!$free_or_draft && isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW']) && isset($pugpigCredsSecret)) {
         $username = $_SERVER['PHP_AUTH_USER'];
         $password = sha1("{$edition_id}:{$username}:{$pugpigCredsSecret}");
         $authorised = $password == $_SERVER['PHP_AUTH_PW'];
     }
     // We can't use the Authorisation Header.
     // Try X-Akamai
     $queryname = "X-Pugpig-Akamai";
     // converted by PHP
     $headername = "X_PUGPIG_AKAMAI";
     if (isset($_SERVER["HTTP_" . $headername])) {
         $header = $_SERVER["HTTP_" . $headername];
     } elseif (isset($_REQUEST[$queryname])) {
         $header = $_REQUEST[$queryname];
     }
     if (!$authorised && !empty($header)) {
         list($ak_path, $ak_time, $ak_ip) = explode("|", $header);
         if ($ak_ip != getRequestIPAddress()) {
             echo "Akamai Header Token IP address " . getRequestIPAddress() . " does not match token {$ak_ip}<br />\n";
         } elseif ($ak_time < time()) {
             echo "Akamai Header Token expired " . (time() - $ak_time) . " seconds ago<br />\n";
         } elseif ($ak_path !== $edition_id) {
             echo "Akamai Header Token not valid for {$edition_id} (only {$ak_path})<br />\n";
         } else {
             $authorised = true;
         }
     }
     return $authorised;
 }