function get_all_atom_edition_ids()
 {
     $ids = array();
     $num_editions = get_number_of_editions();
     $edition_num = $num_editions;
     $start_num = get_edition_start_num();
     do {
         $ids[] = get_edition_id($edition_num);
     } while (--$edition_num >= $start_num);
     return $ids;
 }
  <body>
    <h1><?php 
print $title;
?>
</h1>
<?php 
$force = array_key_exists('force', $_GET);
if ($force) {
    print "<h2>Forcing re-building existing packages...</h2>";
}
$scheme = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off' ? 'https' : 'http';
$root = $scheme . '://' . $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT'] . '/';
print "<ul>";
for ($edition_num = get_number_of_editions(); $edition_num > 0; $edition_num--) {
    $server_root = $scheme . '://' . $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT'];
    $edition_id = urlencode(get_edition_id($edition_num));
    $save_root = urlencode(get_package_dir($edition_num));
    $relative_path = urlencode(ltrim($_SERVER['SCRIPT_NAME'] . '/edition/' . $edition_id, '/'));
    $scheme = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off' ? 'https' : 'http';
    $atom = urlencode($server_root . $_SERVER['SCRIPT_NAME'] . '/edition/' . $edition_id . '/content.xml');
    $package_url = $server_root . CONTENT_TEST_PATH . 'build-package.php?edition_id=' . $edition_id . '&save_root=' . $save_root . '&atom=' . $atom . '&relative_path=' . $relative_path;
    $package_xml_exists = pugpig_get_edition_package_exists($edition_num);
    print "<li>{$edition_id}... (<a href=\"{$package_url}\">build url</a>) ";
    if ($package_xml_exists) {
        print "<span class=\"exists\">already exists</span>";
    } else {
        print "<span class=\"notexists\">does not exist</span>";
    }
    print " - ";
    if ($package_xml_exists && !$force) {
        _print_immediately("skipping");
 function get_page_data($edition_num, $page_num)
 {
     $num_pages = get_number_of_pages($edition_num);
     return array('id' => get_edition_id($edition_num) . '.' . str_pad($edition_num, 4, "0", STR_PAD_LEFT), 'title' => "Page Number {$page_num}", 'categories' => array("Section " . ceil($page_num / ($num_pages / 5))), 'summary' => "Page Number {$page_num} is really interesting", 'status' => 'published', 'url' => "page-{$page_num}.html", 'manifest' => "page-{$page_num}.manifest", 'sharing_link' => 'http://pugpig.com');
 }
 function get_all_atom_edition_ids()
 {
     $ids = array();
     $start_num = get_edition_start_num();
     $end_num = get_number_of_editions() + $start_num - 1;
     $edition_num = $start_num;
     do {
         if (pugpig_get_edition_package_exists($edition_num)) {
             $ids[] = get_edition_id($edition_num);
         }
     } while ($edition_num++ < $end_num);
     return $ids;
 }
Example #5
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 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;
 }