Exemplo n.º 1
0
 function get_edition_data($edition_num, $is_package)
 {
     $num_editions = get_number_of_editions();
     $edition_key = get_edition_id($edition_num);
     $edition_date = add_date(time(), $edition_num);
     $modified = add_date_timestamp(time(), $edition_num);
     $cycle = $edition_num % 10 + 1;
     // http response
     $http_responses = array(200, 404, 401, 403, 500);
     $http_reponses_index = $num_editions - 10 - $edition_num;
     $http_status = 0;
     if ($http_reponses_index >= 0 && $http_reponses_index < count($http_responses)) {
         $http_status = $http_responses[$http_reponses_index];
     }
     $is_timeout = $http_reponses_index == count($http_responses);
     $is_broken = $is_timeout || $http_status > 0;
     // edition flags
     $is_published = $edition_num % 3;
     $is_paid = !$is_broken && $edition_num % 7;
     $is_vampire = $edition_num == $num_editions - 20;
     $is_deleted = $is_vampire && rand(0, 1) == 1;
     // strings
     $price = $is_paid ? 'PAID' : 'FREE';
     $status = $is_published ? 'published' : 'draft';
     // url
     if ($http_status == 0) {
         if ($is_timeout) {
             $url = '../auth_test/responses/timeout.php';
         } else {
             $query = empty($_SERVER['QUERY_STRING']) ? '' : '?' . $_SERVER['QUERY_STRING'];
             $url = "edition/{$edition_num}/" . ($is_package ? 'package.xml' : 'content.xml') . $query;
         }
     } else {
         $url = "../auth_test/responses/{$http_status}.php";
         // todo: fix relative path, so we can find authtest from custom content
     }
     $http_status_summary = array(200 => 'All lies. I return a fake 200 code.', 404 => 'Not Found. I return a 404 code.', 401 => 'Unauthorized. I return a 401 code.', 403 => 'Forbidden. I return a 403 code.', 500 => 'Broken. I return a 500 code.');
     // summary
     $always_updates = $edition_num % 9 == 0;
     $long_ttl = $edition_num % 27 == 0;
     $summary = "You really should read edition {$edition_num}. It's the best {$status} ever. ";
     if ($is_published) {
         $summary .= "It is {$price}. ";
     } else {
         $summary .= "All draft editions are treated as free. ";
     }
     if ($always_updates) {
         $summary .= "And it ALWAYS updates. ";
     }
     if ($long_ttl) {
         $summary .= "I have a long 5 minute TTL on the Atom and Package feeds. ";
     }
     if ($is_vampire) {
         $summary .= "I get deleted and then raise from the dead. ";
     }
     if ($http_status > 0) {
         $summary = $http_status_summary[$http_status] . ' ' . $summary;
     }
     if ($is_timeout) {
         $summary = 'Timeout. I take 60 seconds.' . ' ' . $summary;
     }
     // pages
     $pages = array();
     $num_pages = get_number_of_pages($edition_num);
     for ($page_num = 1; $page_num <= $num_pages; $page_num++) {
         $pages[] = get_page_id($edition_num, $page_num);
     }
     return array('key' => $edition_key, 'date' => $edition_date, 'title' => ($is_broken ? 'Broken Test ' : '') . ($is_vampire ? "Vampire " : "") . "Edition Number {$edition_num}", 'modified' => !$always_updates ? $modified : time(), 'packaged' => !$always_updates ? $modified : time(), 'ttl' => $long_ttl ? 300 : 0, 'status' => $status, 'price' => $price, 'thumbnail' => "http://lorempixel.com/600/800/abstract/{$cycle}/Issue-{$edition_num}-{$edition_date}/", 'newsstand_cover_art_icon_source' => "http://dummyimage.com/768x1024/000000/ffffff.png?text=Newstand+Cover+768x1024+Issue+{$edition_num}/", 'summary' => $summary, 'tombstone' => $is_deleted, 'url_type' => $is_package ? 'application/pugpigpkg+xml' : 'application/atom+xml', 'url' => $url, 'newsstand_summary' => 'This is a longer summary that can appear in Newsstand. ' . $summary, 'page_ids' => $pages);
 }
 function get_edition_data($edition_num, $is_package)
 {
     $title_parts = array();
     $title_owner_prefix = empty($_SERVER['PHP_AUTH_USER']) ? '' : $_SERVER['PHP_AUTH_USER'] . '\'s ';
     if (!empty($title_owner_prefix)) {
         $title_parts[] = $title_owner_prefix;
     }
     $num_editions = get_number_of_editions();
     $edition_key = get_edition_id($edition_num);
     $edition_date = add_date(time(), $edition_num);
     $modified = add_date_timestamp(time(), $edition_num);
     $cycle = $edition_num % 10 + 1;
     // http response
     $http_responses = array(200, 404, 401, 403, 500);
     $http_reponses_index = $num_editions - 10 - $edition_num;
     $http_status = 0;
     if ($http_reponses_index >= 0 && $http_reponses_index < count($http_responses)) {
         $http_status = $http_responses[$http_reponses_index];
     }
     $is_timeout = $http_reponses_index == count($http_responses);
     $is_broken = $is_timeout || $http_status > 0;
     if ($is_broken) {
         $title_parts[] = 'Broken Test';
     }
     // edition flags
     $is_published = $edition_num % 3;
     $is_paid = !$is_broken && $edition_num % 7;
     $is_vampire = $edition_num == $num_editions - 20;
     if ($is_broken) {
         $title_parts[] = 'Vampire';
     }
     $is_deleted = $is_vampire && rand(0, 1) == 1;
     // strings
     $price = $is_paid ? 'PAID' : 'FREE';
     $status = $is_published ? 'published' : 'draft';
     // url
     if ($http_status == 0) {
         if ($is_timeout) {
             $url = '../auth_test/responses/timeout.php';
         } else {
             $query = empty($_SERVER['QUERY_STRING']) ? '' : '?' . $_SERVER['QUERY_STRING'];
             $url = "edition/{$edition_key}/" . ($is_package ? 'package.xml' : 'content.xml') . $query;
         }
     } else {
         $url = "../auth_test/responses/{$http_status}.php";
         // todo: fix relative path, so we can find authtest from custom content
     }
     $http_status_summary = array(200 => 'All lies. I return a fake 200 code.', 404 => 'Not Found. I return a 404 code.', 401 => 'Unauthorized. I return a 401 code.', 403 => 'Forbidden. I return a 403 code.', 500 => 'Broken. I return a 500 code.');
     // summary
     $always_updates = $edition_num % 9 == 0;
     $long_ttl = $edition_num % 27 == 0;
     $summary = "You really should read edition {$edition_num}. It's the best {$status} ever. ";
     if ($is_published) {
         $summary .= "It is {$price}. ";
     } else {
         $summary .= "All draft editions are treated as free. ";
     }
     if ($always_updates) {
         $summary .= "And it ALWAYS updates. ";
     }
     if ($long_ttl) {
         $summary .= "I have a long 5 minute TTL on the Atom and Package feeds. ";
     }
     if ($is_vampire) {
         $summary .= "I get deleted and then raise from the dead. ";
     }
     if ($http_status > 0) {
         $summary = $http_status_summary[$http_status] . ' ' . $summary;
     }
     if ($is_timeout) {
         $summary = 'Timeout. I take 60 seconds.' . ' ' . $summary;
     }
     // categories
     $custom_categories = array();
     if ($is_package) {
         $size = 0;
         $parts = get_package_parts($edition_num);
         foreach ($parts as $part_name => $part_info) {
             $size += filesize($part_info['path']);
         }
         $custom_categories['download_size'] = pugpig_bytestosize($size, 0);
     }
     // pages
     $pages = array();
     $num_pages = get_number_of_pages($edition_num);
     for ($page_num = 1; $page_num <= $num_pages; $page_num++) {
         $pages[] = get_page_id($edition_num, $page_num);
     }
     $subtitles = array(null, ' ', null, ' ', "Edition {$edition_num} Sub Title", null, ' ', null, ' ', "This is the stupidly long subtitle for Edition {$edition_num} which isn't going to fit even on an iPad in portrait, especially since all this extra text was added to make this an even longer stupidly long subtitle.");
     $subtitle = $subtitles[$edition_num % count($subtitles)];
     if ($subtitle != null) {
         $custom_categories['subtitle'] = $subtitle;
     }
     // pane model
     $pane_models = array(null, 'scrolling', 'horizontal', 'vertical');
     $pane_model_granularity = 4;
     $pane_model = $pane_models[$edition_num / $pane_model_granularity % count($pane_models)];
     if ($pane_model === null) {
         $summary .= 'With no pane model.';
     } else {
         $custom_categories['pane_model'] = $pane_model;
         $summary .= 'With ' . ucwords($pane_model) . ' pane model.';
     }
     $title_parts[] = "Edition Number {$edition_num}";
     $title_parts = array_filter($title_parts);
     $title = join(' ', $title_parts);
     return array('key' => $edition_key, 'date' => $edition_date, 'title' => $title, 'modified' => !$always_updates ? $modified : time(), 'packaged' => !$always_updates ? $modified : time(), 'ttl' => $long_ttl ? 300 : 0, 'status' => $status, 'price' => $price, 'thumbnail' => "http://lorempixel.com/600/800/abstract/{$cycle}/Issue-{$edition_num}-{$edition_date}/", 'newsstand_cover_art_icon_source' => "http://dummyimage.com/768x1024/000000/ffffff.png?text=Newstand+Cover+768x1024+Issue+{$edition_num}/", 'summary' => $summary, 'tombstone' => $is_deleted, 'url_type' => $is_package ? 'application/pugpigpkg+xml' : 'application/atom+xml', 'url' => $url, 'newsstand_summary' => 'This is a longer summary that can appear in Newsstand. ' . $summary, 'page_ids' => $pages, 'custom_categories' => $custom_categories);
 }