Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r64631 - in website/public_html/beta: common common/code development doc
From: daniel_james_at_[hidden]
Date: 2010-08-06 06:03:32


Author: danieljames
Date: 2010-08-06 06:01:39 EDT (Fri, 06 Aug 2010)
New Revision: 64631
URL: http://svn.boost.org/trac/boost/changeset/64631

Log:
Hack the documentation code to server from unzipped files.

This is going to break the beta documentation. But that's okay, since it's the
beta site. Hopefully it might reduce the load on the server, which is still
high.

Text files modified:
   website/public_html/beta/common/code/boost_archive.php | 126 ++++++++++++++++++++++++++++++++-------
   website/public_html/beta/common/menu-development.html | 2
   website/public_html/beta/common/menu-welcome.html | 2
   website/public_html/beta/development/testing_results.php | 1
   website/public_html/beta/doc/.htaccess | 5
   website/public_html/beta/doc/display_build.php | 2
   website/public_html/beta/doc/display_jam.php | 2
   website/public_html/beta/doc/display_libs.php | 2
   8 files changed, 112 insertions(+), 30 deletions(-)

Modified: website/public_html/beta/common/code/boost_archive.php
==============================================================================
--- website/public_html/beta/common/code/boost_archive.php (original)
+++ website/public_html/beta/common/code/boost_archive.php 2010-08-06 06:01:39 EDT (Fri, 06 Aug 2010)
@@ -10,6 +10,7 @@
     $pattern,
     $vpath,
     $archive_subdir = true,
+ $zipfile = true,
     $archive_dir = ARCHIVE_DIR,
     $archive_file_prefix = ARCHIVE_FILE_PREFIX)
 {
@@ -19,22 +20,25 @@
     $version = $path_parts[1];
     $key = $path_parts[2];
 
+ $file = ($zipfile ? '' : $archive_dir . '/');
+
     if ($archive_subdir)
     {
- $file = $archive_file_prefix . $version . '/' . $key;
+ $file = $file . $archive_file_prefix . $version . '/' . $key;
     }
     else
     {
- $file = $archive_file_prefix . $key;
+ $file = $file . $archive_file_prefix . $key;
     }
 
- $archive = str_replace('\\','/', $archive_dir . '/' . $version . '.zip');
+ $archive = $zipfile ? str_replace('\\','/', $archive_dir . '/' . $version . '.zip') : Null;
     
     return array(
         'version' => $version,
         'key' => $key,
         'file' => $file,
- 'archive' => $archive
+ 'archive' => $archive,
+ 'zipfile' => $zipfile
     );
 }
 
@@ -86,35 +90,57 @@
 
     // Check zipfile.
 
- if (!is_file($params['archive'])) {
- file_not_found($params, 'Unable to find zipfile.');
+ $check_file = $params['zipfile'] ? $params['archive'] : $params['file'];
+
+ if (!is_file($check_file)) {
+ file_not_found($params,
+ $params['zipfile'] ?
+ 'Unable to find zipfile.' :
+ 'Unable to find file.');
         return;
     }
 
     $last_modified = max(
         strtotime("Sun, 11 Jul 2010 18:55:24 +0100"),
- filemtime($params['archive']));
+ filemtime($check_file));
 
     if (!conditional_get($last_modified))
         return;
 
     // Extract the file from the zipfile
 
- $unzip =
- UNZIP
- .' -p '.escapeshellarg($params['archive'])
- .' '.escapeshellarg($params['file']);
+ if ($params['zipfile'])
+ {
+ $unzip =
+ UNZIP
+ .' -p '.escapeshellarg($params['archive'])
+ .' '.escapeshellarg($params['file']);
 
- if($extractor == 'raw') {
- display_raw_file($unzip, $type);
- return;
+ if($extractor == 'raw') {
+ display_raw_file($unzip, $type);
+ return;
+ }
+
+ // Note: this sets $params['content'] with either the content or an error
+ // message:
+ if(!extract_file($unzip, $params['content'])) {
+ file_not_found($params, $params['content']);
+ return;
+ }
     }
+ else
+ {
+ if($extractor == 'raw') {
+ display_unzipped_file($params['file'], $type);
+ return;
+ }
 
- // Note: this sets $params['content'] with either the content or an error
- // message:
- if(!extract_file($unzip, $params['content'])) {
- file_not_found($params, $params['content']);
- return;
+ // Note: this sets $params['content'] with either the content or an error
+ // message:
+ if(!extract_unzipped_file($params['file'], $params['content'])) {
+ file_not_found($params, $params['content']);
+ return;
+ }
     }
     
     if($type == 'text/html') {
@@ -159,7 +185,7 @@
     
     if(!$checked) return true;
     
- header('HTTP/1.0 304 Not Modified');
+ header($_SERVER["SERVER_PROTOCOL"].' 304 Not Modified');
     return false;
 }
 
@@ -221,6 +247,34 @@
         echo 'Error extracting file: '.unzip_error($exit_status);
 };
 
+function display_unzipped_file($file, $type) {
+ header('Content-type: '.$type);
+ switch($type) {
+ case 'image/png':
+ case 'image/gif':
+ case 'image/jpeg':
+ case 'text/css':
+ case 'application/x-javascript':
+ case 'application/pdf':
+ case 'application/xml-dtd':
+ header('Expires: '.date(DATE_RFC2822, strtotime("+1 year")));
+ header('Cache-Control: max-age=31556926'); // A year, give or take a day.
+ }
+
+ // Since we're not returning a HTTP error for non-existant files,
+ // might as well not bother checking for the file
+ if($_SERVER['REQUEST_METHOD'] == 'HEAD') return;
+
+ ## header('Content-Disposition: attachment; filename="downloaded.pdf"');
+ $file_handle = fopen($file,'rb');
+ // TODO: Check $file_handle (should be okay, because already checked for file).
+ fpassthru($file_handle);
+ $exit_status = fclose($file_handle);
+
+ // TODO: What if !$exit_status?
+};
+
+
 function extract_file($unzip, &$content) {
     $file_handle = popen($unzip,'r');
     $text = '';
@@ -239,6 +293,31 @@
     }
 }
 
+function extract_unzipped_file($file, &$content) {
+ $file_handle = fopen($file,'r');
+
+ if($file_handle === FALSE) {
+ $content = null;
+ return false;
+ }
+
+ $text = '';
+ while ($file_handle && !feof($file_handle)) {
+ $text .= fread($file_handle,8*1024);
+ }
+ $exit_status = fclose($file_handle);
+
+ if($exit_status) {
+ $content = $text;
+ return true;
+ }
+ else {
+ $content = null;
+ return false;
+ }
+}
+
+
 //
 // Filters
 //
@@ -416,9 +495,10 @@
         );
     }
 
- header("HTTP/1.0 404 Not Found");
+ header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found");
     display_template($params['template'],
- new file_not_found_render_callbacks($params['file'], $message));
+ new file_not_found_render_callbacks($params['file'],
+ $params['zipfile'] ? "Unzip error: $message" : $message));
 }
 
 class file_not_found_render_callbacks
@@ -442,7 +522,7 @@
     {
         print '<h1>404 Not Found</h1><p>File "' . $this->file . '" not found.</p>';
         if($this->message) {
- print '<p>Unzip error: '.htmlentities($this->message).'</p>';
+ print '<p>'.htmlentities($this->message).'</p>';
         }
     }
 }

Modified: website/public_html/beta/common/menu-development.html
==============================================================================
--- website/public_html/beta/common/menu-development.html (original)
+++ website/public_html/beta/common/menu-development.html 2010-08-06 06:01:39 EDT (Fri, 06 Aug 2010)
@@ -64,7 +64,7 @@
         <li><a href="/development/design_faq.html">Design FAQ <span class=
         "link">&gt;</span></a></li>
 
- <li><a href="/development/webcheck">Self Check <span class=
+ <li><a href="/development/webcheck/index.html">Self Check <span class=
         "link">&gt;</span></a></li>
       </ul>
     </li>

Modified: website/public_html/beta/common/menu-welcome.html
==============================================================================
--- website/public_html/beta/common/menu-welcome.html (original)
+++ website/public_html/beta/common/menu-welcome.html 2010-08-06 06:01:39 EDT (Fri, 06 Aug 2010)
@@ -8,7 +8,7 @@
     <li><a href="/users/download/" class="internal">Download <span class=
     "link">&gt;</span></a></li>
 
- <li>Libraries ></li>
+ <li>Libraries ></li>
 
     <li><a href="/community/groups.html">Mailing Lists <span class=
     "link">&gt;</span></a></li>

Modified: website/public_html/beta/development/testing_results.php
==============================================================================
--- website/public_html/beta/development/testing_results.php (original)
+++ website/public_html/beta/development/testing_results.php 2010-08-06 06:01:39 EDT (Fri, 06 Aug 2010)
@@ -5,6 +5,7 @@
   get_archive_location(
     '/^[\/]([^\/]+)[\/](.*)$/',$_SERVER["PATH_INFO"],
     false, // the result zips don't have the tag subdir
+ true, // stored as a zipfile
     RESULTS_DIR
   ),
   array(

Modified: website/public_html/beta/doc/.htaccess
==============================================================================
--- website/public_html/beta/doc/.htaccess (original)
+++ website/public_html/beta/doc/.htaccess 2010-08-06 06:01:39 EDT (Fri, 06 Aug 2010)
@@ -2,9 +2,10 @@
 RewriteBase /doc
 
 # Redirect to the canonical URL.
+# TODO: I think this is wrong.
 
-RewriteCond %{HTTP_HOST} ^boost\.org [NC]
-RewriteRule ^.*$ http://www\.boost\.org%{REQUEST_URI} [R=301]
+# RewriteCond %{HTTP_HOST} ^boost\.org [NC]
+# RewriteRule ^.*$ http://www\.boost\.org%{REQUEST_URI} [R=301]
 
 RewriteRule ^html(/.*)?$ libs/release/doc/html$1 [R]
 

Modified: website/public_html/beta/doc/display_build.php
==============================================================================
--- website/public_html/beta/doc/display_build.php (original)
+++ website/public_html/beta/doc/display_build.php 2010-08-06 06:01:39 EDT (Fri, 06 Aug 2010)
@@ -25,7 +25,7 @@
   get_archive_location(
     '@^[/]([^/]+)[/](.*)$@',
     $_SERVER["PATH_INFO"],
- false
+ false, false
   ),
   array(
   //~ array(version-regex,path-regex,raw|simple|text|cpp|boost_book_html|boost_libs_html,mime-type[,preprocess hook]),

Modified: website/public_html/beta/doc/display_jam.php
==============================================================================
--- website/public_html/beta/doc/display_jam.php (original)
+++ website/public_html/beta/doc/display_jam.php 2010-08-06 06:01:39 EDT (Fri, 06 Aug 2010)
@@ -2,7 +2,7 @@
 require_once(dirname(__FILE__) . '/../common/code/boost_archive.php');
 
 display_from_archive(
- get_archive_location('@^[/]([^/]+)[/](.*)$@',$_SERVER["PATH_INFO"]),
+ get_archive_location('@^[/]([^/]+)[/](.*)$@',$_SERVER["PATH_INFO"],true,false),
   array(
   //~ array(version-regex,path-regex,raw|simple|text|cpp|boost_book_html|boost_libs_html,mime-type[,preprocess hook]),
   array('@.*@','@[.](html|htm)$@i','boost_book_html','text/html'),

Modified: website/public_html/beta/doc/display_libs.php
==============================================================================
--- website/public_html/beta/doc/display_libs.php (original)
+++ website/public_html/beta/doc/display_libs.php 2010-08-06 06:01:39 EDT (Fri, 06 Aug 2010)
@@ -33,7 +33,7 @@
     return str_ireplace('</head>', $analytics.'</head>', $content);
 }
 
-$location = get_archive_location('@^[/]([^/]+)[/](.*)$@',$_SERVER["PATH_INFO"]);
+$location = get_archive_location('@^[/]([^/]+)[/](.*)$@',$_SERVER["PATH_INFO"],true,false);
 
 if (boost_future_version($location['version'])) {
     file_not_found($location['file'],


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk