예제 #1
0
 function display_from_archive()
 {
     // Set default values
     $pattern = $this->get_param('pattern', '@^[/]([^/]+)[/](.*)$@');
     $archive_dir = $this->get_param('archive_dir', STATIC_DIR);
     $archive_file_prefix = $this->get_param('archive_file_prefix', ARCHIVE_FILE_PREFIX);
     // Get the archive location.
     $path_parts = array();
     preg_match($pattern, $_SERVER["PATH_INFO"], $path_parts);
     $zipfile_name = $path_parts[1];
     $path_in_zipfile = $archive_file_prefix . $path_parts[2];
     $archive_file = str_replace('\\', '/', $archive_dir . '/' . $zipfile_name . '.zip');
     // Check file exists.
     if (!is_readable($archive_file)) {
         BoostWeb::error_404($path_in_zipfile, 'Unable to find zipfile.');
         return;
     }
     // Choose mime type to use
     // TODO: Better way to support mime type? Built in PHP functions
     //       appear to require the actual file, could automatically
     //       grab an updated list from:
     //       http://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types
     $mime_types = array('png' => 'image/png', 'gif' => 'image/gif', 'jpg' => 'image/jpeg', 'jpeg' => 'image/jpeg', 'jpe' => 'image/jpeg', 'svg' => 'image/svg+xml', 'css' => 'text/css', 'js' => 'application/x-javascript', 'pdf' => 'application/pdf', 'html' => 'text/html', 'htm' => 'text/html', 'dtd' => 'application/xml-dtd', 'json' => 'application/json');
     $extension = pathinfo($path_in_zipfile, PATHINFO_EXTENSION);
     $type = array_key_exists($extension, $mime_types) ? $mime_types[$extension] : 'text/plain';
     // Handle ETags and Last-Modified HTTP headers.
     // Output raw files.
     if (!BoostWeb::http_headers($type, filemtime($archive_file))) {
         return;
     }
     $this->display_raw_file($archive_file, $path_in_zipfile);
 }
예제 #2
0
        $this->option_link(isset($category['title']) ? $category['title'] : $name, 'view', 'category_' . $name);
    }
}
// Page variables
$library_page = new LibraryPage($_GET, BoostLibraries::load());
if (BoostVersion::page()->is_numbered_release() && $library_page->libs->latest_version && BoostVersion::page()->compare($library_page->libs->latest_version) > 0) {
    BoostWeb::error_404($_SERVER['REQUEST_URI']);
    return;
}
// To avoid confusion, only show this page when there is actual documentation.
// TODO: Maybe for versions without documentation, could display the list
//       with no links.
// TODO: This duplicates the BoostDocumentation object in display_libs.
$archive = new BoostDocumentation(array('fix_dir' => dirname(__FILE__) . '/fixes', 'archive_dir' => STATIC_DIR, 'use_http_expire_date' => true));
if (!is_dir($archive->documentation_dir())) {
    BoostWeb::error_404($_SERVER['REQUEST_URI']);
    return;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
  <title><?php 
echo html_encode($library_page->title());
?>
</title>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <link rel="icon" href="/favicon.ico" type="image/ico" />
  <link rel="stylesheet" type="text/css" href="/style-v2/section-doc.css" />
 function display_from_archive($content_map = array())
 {
     extract($this->documenation_path_details());
     // Set default values
     $fix_dir = $this->get_param('fix_dir');
     $use_http_expire_date = $this->get_param('use_http_expire_date', false);
     $file = false;
     if ($fix_dir) {
         $fix_path = "{$fix_dir}/{$version_dir}/{$path}";
         if (is_file($fix_path) || is_dir($fix_path) && is_file("{$fix_path}/index.html")) {
             $file = $fix_path;
         }
     }
     if (!$file) {
         $file = $archive_dir . '/';
         $file = $file . $version_dir . '/' . $path;
     }
     // Only use a permanent redirect for releases (beta or full).
     $redirect_status_code = $version && $version->is_numbered_release() ? 301 : 302;
     // Calculate expiry date if requested.
     $expires = null;
     if ($use_http_expire_date) {
         if (!$version) {
             $expires = "+1 week";
         } else {
             $compare_version = BoostVersion::from($version)->compare(BoostVersion::current());
             $expires = $compare_version === -1 ? "+1 year" : ($compare_version === 0 ? "+1 week" : "+1 day");
         }
     }
     // Last modified date
     if (!is_readable($file)) {
         BoostWeb::error_404($file, 'Unable to find file.');
         return;
     }
     $last_modified = max(strtotime(BOOST_DOCS_MODIFIED_DATE), filemtime(dirname(__FILE__) . '/boost.php'), filemtime($file));
     // Check file exists.
     if (is_dir($file)) {
         if (substr($file, -1) != '/') {
             $redirect = BoostUrl::resolve(basename($file) . '/');
             header("Location: {$redirect}", TRUE, $redirect_status_code);
             return;
         }
         $found_file = NULL;
         if (is_readable("{$file}/index.html")) {
             $found_file = 'index.html';
         } else {
             if (is_readable("{$file}/index.htm")) {
                 $found_file = 'index.htm';
             }
         }
         if ($found_file) {
             $file = $file . $found_file;
             $path = $path . $found_file;
         } else {
             if (!BoostWeb::http_headers('text/html', $last_modified, $expires)) {
                 return;
             }
             $data = new BoostFilterData();
             $data->version = $version;
             $data->path = $path;
             $data->archive_dir = $archive_dir;
             $data->fix_dir = $fix_dir;
             $display_dir = new BoostDisplayDir($data);
             return $display_dir->display($file);
         }
     }
     // Choose filter to use
     $info_map = array_merge($content_map, array(array('', '@[.](txt|py|rst|jam|v2|bat|sh|xml|xsl|toyxml)$@i', 'text', 'text/plain'), array('', '@[.](qbk|quickbook)$@i', 'qbk', 'text/plain'), array('', '@[.](c|h|cpp|hpp)$@i', 'cpp', 'text/plain'), array('', '@[.]png$@i', 'raw', 'image/png'), array('', '@[.]gif$@i', 'raw', 'image/gif'), array('', '@[.](jpg|jpeg|jpe)$@i', 'raw', 'image/jpeg'), array('', '@[.]svg$@i', 'raw', 'image/svg+xml'), array('', '@[.]css$@i', 'raw', 'text/css'), array('', '@[.]js$@i', 'raw', 'application/x-javascript'), array('', '@[.]pdf$@i', 'raw', 'application/pdf'), array('', '@[.](html|htm)$@i', 'raw', 'text/html'), array('', '@(/|^)(Jamroot|Jamfile|ChangeLog|configure)$@i', 'text', 'text/plain'), array('', '@[.]dtd$@i', 'raw', 'application/xml-dtd'), array('', '@[.]json$@i', 'raw', 'application/json')));
     $preprocess = null;
     $extractor = null;
     $type = null;
     foreach ($info_map as $i) {
         if (preg_match($i[1], $path)) {
             if ($i[0]) {
                 $min_version = BoostVersion::from($i[0]);
                 if ($min_version->compare(BoostVersion::page()) > 0) {
                     // This is after the current version.
                     continue;
                 }
             }
             $extractor = $i[2];
             $type = $i[3];
             $preprocess = isset($i[4]) ? $i[4] : NULL;
             break;
         }
     }
     if (!$extractor) {
         if (strpos($_SERVER['HTTP_HOST'], 'www.boost.org') === false) {
             BoostWeb::error_404($file, 'No extractor found for filename.');
         } else {
             BoostWeb::error_404($file);
         }
         return;
     }
     // Handle ETags and Last-Modified HTTP headers.
     // Output raw files.
     if ($extractor == 'raw') {
         if (!BoostWeb::http_headers($type, $last_modified, $expires)) {
             return;
         }
         if ($_SERVER['REQUEST_METHOD'] != 'HEAD') {
             readfile($file);
         }
     } else {
         // Read file from hard drive
         $content = file_get_contents($file);
         // Check if the file contains a redirect.
         if ($type == 'text/html') {
             if ($redirect = detect_redirect($content)) {
                 BoostWeb::http_headers('text/html', null, "+1 day");
                 header("Location: {$redirect}", TRUE, $redirect_status_code);
                 if ($_SERVER['REQUEST_METHOD'] != 'HEAD') {
                     echo $content;
                 }
                 return;
             }
         }
         if (!BoostWeb::http_headers('text/html', $last_modified, $expires)) {
             return;
         }
         // Finally process the file and display it.
         if ($_SERVER['REQUEST_METHOD'] != 'HEAD') {
             if ($preprocess) {
                 $content = call_user_func($preprocess, $content);
             }
             $data = new BoostFilterData();
             $data->version = $version;
             $data->path = $path;
             $data->content = $content;
             $data->archive_dir = $archive_dir;
             $data->fix_dir = $fix_dir;
             echo_filtered($extractor, $data);
         }
     }
 }