$version, 'key' => $key, 'file' => $file, 'archive' => $archive ); } function display_from_archive( $archive_location_details, $content_map = array(), $extractor = null) { $_file = new boost_archive($archive_location_details, $content_map, $extractor); } class boost_archive { var $version_ = NULL; var $key_ = NULL; var $file_ = NULL; var $archive_ = NULL; var $extractor_ = NULL; var $extractor_instance_ = NULL; var $type_ = NULL; var $preprocess_ = NULL; var $title_ = NULL; var $charset_ = NULL; var $content_ = NULL; function boost_archive( $archive_location_details, $content_map = array(), $extractor = null) { $this->version_ = $archive_location_details['version']; $this->key_ = $archive_location_details['key']; $this->file_ = $archive_location_details['file']; $this->archive_ = $archive_location_details['archive']; $info_map = array_merge($content_map, array( array('@.*@','@[.](txt|py|rst|jam|v2|bat|sh|xml|qbk)$@i','text','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('@.*@','@[.]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)$@i','text','text/plain'), array('@.*@','@[.]dtd$@i','raw','application/xml-dtd'), )); foreach ($info_map as $i) { if (preg_match($i[1],$this->key_)) { $this->extractor_ = $i[2]; $this->type_ = $i[3]; $this->preprocess_ = isset($i[4]) ? $i[4] : NULL; break; } } if ($extractor) $this->extractor_ = $extractor; if (!$this->extractor_) $this->extractor_ = 'h404'; $extractor_name = $this->extractor_.'_filter'; $this->extractor_instance_ = new $extractor_name; $unzip = UNZIP .' -p '.escapeshellarg($this->archive_) .' '.escapeshellarg($this->file_); // Note: this can change $this->extractor_instance_: $this->content_ = $this->extractor_instance_->extract($this, $unzip); $this->extractor_instance_->init($this); if ($this->extractor_ != 'h404' && $this->extractor_ != 'raw' && $this->preprocess_) { $this->content_ = call_user_func($this->preprocess_, $this->content_); } $this->extractor_instance_->render($this); } function content_head() { $charset = $this->charset_ ? $this->charset_ : 'us-ascii'; $title = $this->title_ ? 'Boost C++ Libraries - '.$this->title_ : 'Boost C++ Libraries'; print << ${title} HTML; } function content() { if ($this->extractor_instance_) { $this->extractor_instance_->content($this); } } function display_template() { $_file = $this; include(dirname(__FILE__)."/template.php"); } } class filter_base { function extract($archive, $unzip) {} function init($archive) {} function content($archive) {} function render($archive) {} }; class raw_filter extends filter_base { function extract($archive, $unzip) { header('Content-type: '.$archive->type_); ## header('Content-Disposition: attachment; filename="downloaded.pdf"'); $file_handle = popen($unzip,'rb'); fpassthru($file_handle); $exit_status = pclose($file_handle); // Don't display errors for a corrupt zip file, as we seemd to // be getting them for legitimate files. if($exit_status > 3) echo 'Error extracting file: '.unzip_error($exit_status); } }; class extract_filter_base extends filter_base { function extract($archive, $unzip) { $file_handle = popen($unzip,'r'); $text = ''; while ($file_handle && !feof($file_handle)) { $text .= fread($file_handle,8*1024); } $exit_status = pclose($file_handle); if($exit_status == 0) { return $text; } else { $archive->extractor_ = 'h404'; $archive->extractor_instance_ = new h404_filter; return strstr($_SERVER['HTTP_HOST'], 'beta') ? unzip_error($exit_status) : ''; } } }; class text_filter extends extract_filter_base { function init($archive) { $archive->title_ = htmlentities($archive->key_); } function content($archive) { print "

".htmlentities($archive->key_)."

\n"; print "
\n";
        print htmlentities($archive->content_);
        print "
\n"; } function render($archive) { $archive->display_template(); } } class cpp_filter extends extract_filter_base { function init($archive) { $archive->title_ = htmlentities($archive->key_); } function content($archive) { $text = htmlentities($archive->content_); print "

".htmlentities($archive->key_)."

\n"; print "
\n";
        $root = dirname(preg_replace('@([^/]+/)@','../',$archive->key_));
        $text = preg_replace(
            '@(#[ ]*include[ ]+<)(boost[^&]+)@Ssm',
            '${1}${2}',
            $text );
        $text = preg_replace(
            '@(#[ ]*include[ ]+")(boost[^&]+)@Ssm',
            '${1}${2}',
            $text );
        print $text;
        print "
\n"; } function render($archive) { $archive->display_template(); } } class html_base_filter extends extract_filter_base { function init($archive) { preg_match('@text/html; charset=([^\s"\']+)@i',$archive->content_,$charset); if (isset($charset[1])) { $archive->charset_ = $charset[1]; } preg_match('@([^<]+)@i',$archive->content_,$title); if (isset($title[1])) { $archive->title_ = $title[1]; } } } class boost_book_html_filter extends html_base_filter { function init($archive) { parent::init($archive); } function content($archive) { $text = prepare_html($archive->content_); $text = substr($text,strpos($text,'
')); $text = substr($text,0,strpos($text,'')); $text = str_replace('
','',$text); $text = str_replace('','
',$text); $text = str_replace('','
',$text); $text = preg_replace( '@[\s]+(border|cellpadding|cellspacing|width|height|valign|frame|rules|naturalsizeflag|background)=[^\s>]+@i', '', $text ); /* */ for ($i = 0; $i < 8; $i++) { $text = preg_replace( '@([^@Ssm', '${2}', $text ); } /* */ print $text; } function render($archive) { $archive->display_template(); } } class boost_libs_filter extends html_base_filter { function init($archive) { parent::init($archive); } function content($archive) { return $archive->content_; } function render($archive) { $text = extract_html_body($archive->content_); if($text) { $text = prepare_html($text); $text = remove_html_banner($text); $text = prepare_themed_html($text); $archive->content_ = $text; $archive->display_template(); } else { print $archive->content_; } } } class boost_frame1_filter extends html_base_filter { function init($archive) { parent::init($archive); } function content($archive) { $text = prepare_html($archive->content_); $text = substr($text,strpos($text,'
')); $text = substr($text,0,strpos($text,'')); for ($i = 0; $i < 8; $i++) { $text = preg_replace( '@(.*)@Ssm', '${2}', $text ); } $text = str_replace('
','',$text); $text = str_replace('
','
',$text); $text = preg_replace( '@[\s]+(border|cellpadding|cellspacing|width|height|valign|frame|rules|naturalsizeflag|background)=[^\s>]+@i', '', $text ); print $text; } function render($archive) { $archive->display_template(); } } class simple_filter extends html_base_filter { function init($archive) { } function content($archive) { print prepare_html($archive->content_); } function render($archive) { $this->content($archive); } } class basic_filter extends html_base_filter { function init($archive) { } function content($archive) { $text = prepare_html($archive->content_); $text = remove_html_banner($text); $is_xhtml = preg_match('@]*xhtml@i', $text); $tag_end = $is_xhtml ? '/>' : '>'; $sections = preg_split('@(|]*>)@i',$text,-1,PREG_SPLIT_DELIM_CAPTURE); $body_index = 0; $index = 0; foreach($sections as $section) { if(stripos($section, '@i',$text,$table_end,PREG_OFFSET_CAPTURE); if (isset($table_begin[0]) && isset($table_end[0])) { $table_contents_start = $table_begin[0][1] + strlen($table_begin[0][0]); $table_contents = substr($text, $table_contents_start, $table_end[0][1] - $table_contents_start); if(strpos($table_contents, 'boost.png') !== FALSE) { preg_match('@]*>?([^<]*<(h[12]|p).*?)@is', $table_contents, $table_contents_header, PREG_OFFSET_CAPTURE); $head = substr($text, 0, $table_begin[0][1]); $header = isset($table_contents_header[1]) ? $table_contents_header[1][0] : ''; $tail = substr($text, $table_end[0][1] + strlen($table_end[0][0])); $tail = preg_replace('@^\s*\s*@', '', $tail); $text = $head.$header.$tail; return $text; } } $parts = preg_split('@(?=<(p|blockquote))@', $text, 2); $header = $parts[0]; $content = $parts[1]; $header = preg_replace('@(\s*)]*src="(\.\.\/)*boost\.png"[^>]*>@', '$1', $header); $header = preg_replace('@]*src="(\.\.\/)*boost\.png"[^>]*>\s*<[hb]r.*?>@', '', $header); return $header.$content; } function prepare_themed_html($text) { $text = preg_replace( '@(]+>[\s]*)?]*>([\s]*)?@i', '', $text ); $text = preg_replace( '@]*>@i', '', $text ); $text = preg_replace( '@]*>@i', '', $text ); /* Remove certain attributes */ $text = preg_replace( '@[\s]+(border|cellpadding|cellspacing|width|height|valign|align|frame|rules|naturalsizeflag|background)=("[^"]*"?|\'[^\']*\'?|[^\s/>]+)@i', '', $text ); $text = preg_replace( '@]*@i', ']*>@i', '', $text ); $text = preg_replace( '@<([^\s]+)[\s]+>@i', '<${1}>', $text ); $text = _preg_replace_bounds( '@
[\s]*(
)@i','@(
)[\s]*
@i', '${1}','${1}', $text ); $text = _preg_replace_bounds( '@
[\s]*(

)@i','@(

)[\s]*
@i', '${1}','${1}', $text ); $text = _preg_replace_bounds( '@
[\s]*()@i','@(
)[\s]*
@i', '${1}','${1}', $text ); $text = _preg_replace_bounds( '@
[\s]*
  • @i','@
  • [\s]*
    @i', '
    • ','
    ', $text ); $text = _preg_replace_bounds( '@(?:
    [\s]*)+

    @i','@

    (?:[\s]*
    )+@i', '

    ','

    ', $text ); $text = preg_replace( '@(]+[\s]*>)[\s]*(${2}', $text ); $text = preg_replace( '@([\s]+[\s]+[\s]+[\s]+[\s]+[\s]+)
    .*_arr.*.*.*
    @i', '${1}
    ', $text ); $text = preg_replace( '@([\s]+[\s]+@i', '
    ${1}>', $text ); $text = preg_replace( '@
    ([\s]+[\s]+)@i', '
    ${1}', $text ); $text = preg_replace( '@src=".*theme/u_arr\.gif"@i', 'src="/gfx/space.png" class="up_image"', $text ); $text = preg_replace( '@src=".*theme/l_arr\.gif"@i', 'src="/gfx/space.png" class="prev_image"', $text ); $text = preg_replace( '@src=".*theme/r_arr\.gif"@i', 'src="/gfx/space.png" class="next_image"', $text ); $text = preg_replace( '@src=".*theme/u_arr_disabled\.gif"@i', 'src="/gfx/space.png" class="up_image_disabled"', $text ); $text = preg_replace( '@src=".*theme/l_arr_disabled\.gif"@i', 'src="/gfx/space.png" class="prev_image_disabled"', $text ); $text = preg_replace( '@src=".*theme/r_arr_disabled\.gif"@i', 'src="/gfx/space.png" class="next_image_disabled"', $text ); $text = preg_replace( '@src=".*theme/note\.gif"@i', 'src="/gfx/space.png" class="note_image"', $text ); $text = preg_replace( '@src=".*theme/alert\.gif"@i', 'src="/gfx/space.png" class="caution_image"', $text ); $text = preg_replace( '@src=".*theme/bulb\.gif"@i', 'src="/gfx/space.png" class="tip_image"', $text ); $text = preg_replace( '@@i', '', $text ); $text = preg_replace( '@(@i', '${1} class="inline">', $text ); return $text; } // Return a readable error message for unzip exit state. function unzip_error($exit_status) { switch($exit_status) { case 0: return 'No error.'; case 1: return 'One or more warning errors were encountered.'; case 2: return 'A generic error in the zipfile format was detected.'; case 3: return 'A severe error in the zipfile format was detected.'; case 4: return 'Unzip was unable to allocate memory for one or more buffers during program initialization.'; case 5: return 'Unzip was unable to allocate memory or unable to obtain a tty to read the decryption password(s).'; case 6: return 'Unzip was unable to allocate memory during decompression to disk.'; case 7: return 'Unzip was unable to allocate memory during in-memory decompression.'; case 9: return 'The specified zipfile was not found.'; case 10: return 'Invalid options were specified on the command line.'; case 11: return 'No matching files were found.'; case 50: return 'The disk is (or was) full during extraction.'; case 51: return 'The end of the ZIP archive was encountered prematurely.'; case 80: return 'The user aborted unzip prematurely with control-C (or similar).'; case 81: return 'Testing or extraction of one or more files failed due to unsupported compression methods or unsupported decryption.'; case 82: return 'No files were found due to bad decryption password(s).'; default: return 'Unknown unzip error code: ' + $exit_status; } } ?>