$version,
'key' => $key,
'file' => $file,
'archive' => $archive
);
}
function display_from_archive(
$archive_location_details,
$content_map = array(),
$get_as_raw = false)
{
$_file = new boost_archive($archive_location_details, $content_map, $get_as_raw);
$_file->render();
}
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(),
$get_as_raw = false)
{
$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;
}
}
$unzip =
UNZIP
.' -p '.escapeshellarg($this->archive_)
.' '.escapeshellarg($this->file_);
if (! $this->extractor_)
{
# File doesn't exist, or we don't know how to handle it.
$this->extractor_ = 'h404';
$this->extractor_instance_ = new h404_filter;
$this->extractor_instance_->init($this);
}
else if ($get_as_raw || $this->extractor_ == 'raw')
{
$this->_extract_raw($unzip);
$this->extractor_instance_ = new raw_filter;
//~ print "--- $unzip";
}
else
{
/* We pre-extract so we can get this like meta tag information
before we have to print it out. */
$this->content_ = $this->_extract_string($unzip);
$extractor_name = $this->extractor_.'_filter';
$this->extractor_instance_ = new $extractor_name;
$this->extractor_instance_->init($this);
if($this->preprocess_) {
$this->content_ = call_user_func($this->preprocess_, $this->content_);
}
if ($this->extractor_ == 'simple')
{
$this->extractor_instance_->content($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 is_basic()
{
return $this->extractor_ == 'basic';
}
function is_raw()
{
return $this->extractor_ == 'raw' || $this->extractor_ == 'simple';
}
function _extract_string($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 {
$this->extractor_ = 'h404';
return strstr($_SERVER['HTTP_HOST'], 'beta')
? unzip_error($exit_status) : '';
}
}
function _extract_raw($unzip)
{
header('Content-type: '.$this->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);
}
function content()
{
if ($this->extractor_instance_)
{
$this->extractor_instance_->content($this);
}
}
function render()
{
if ($this->is_basic()) {
print $this->content();
}
else if(!$this->is_raw()) {
$this->display_template();
}
}
function display_template() {
$_file = $this;
include(dirname(__FILE__)."/template.php");
}
}
class raw_filter
{
// No methods, since they shouldn't be called at the moment.
}
class text_filter
{
function init($archive)
{
$archive->title_ = htmlentities($archive->key_);
}
function content($archive)
{
print "".htmlentities($archive->key_)."
\n";
print "\n";
print htmlentities($archive->content_);
print "\n";
}
}
class cpp_filter
{
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";
}
}
class html_base_filter
{
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];
}
}
function content($archive)
{
$text = $archive->content_;
$text = preg_replace(
'@href="?http://www.boost.org/?([^"\s]*)"?@i',
'href="/${1}"',
$text );
$text = preg_replace(
'@href="?http://boost.org/?([^"\s]*)"?@i',
'href="/${1}"',
$text );
$text = preg_replace(
'@href="?(?:\.\./)+people/(.*\.htm)"?@i',
'href="/users/people/${1}l"',
$text );
$text = preg_replace(
'@href="?(?:\.\./)+(LICENSE_[^"\s]*\.txt)"?@i',
'href="/${1}"',
$text );
$text = preg_replace(
'@'));
$text = substr($text,0,strpos($text,''));
$text = str_replace('
','',$text);
$text = str_replace('