<?php
//-------------------------------------------------------------------------------------------------------------
class HttClass
{
var $aHtt;
//-------------------------------------------------------------------------------------------------------------
function Init( $file = "index.htt" )
{
$this->aHtt = null;
if( $this->Load($file) ) {
// Auto Replace [|FILE|]
while( ($name = $this->GetStr( "[|", "|]", $this->aHtt["HTT"] )) ) {
$value = "";
@$fp = fopen( $name, "r" );
if( $fp ) {
$value = fread( $fp, filesize($name) );
fclose( $fp );
$this->aHtt["HTT"] = str_replace( "[|" . $name . "|]", $value, $this->aHtt["HTT"] );
}
else
return false;
}
// Auto Replace [[SECTION]]
while( ($name = $this->GetStr( "[[", "]]", $this->aHtt["HTT"] )) ) {
$value = $this->GetStr( "[" . chr(47) . $name . chr(92) . "]", "[" . chr(92) . $name . chr(47) . "]", $this->aHtt["HTT"] );
$this->aHtt["HTT"] = str_replace( "[[" . $name . "]]", $value, $this->aHtt["HTT"] );
}
$this->Parse();
$this->Clear();
return true;
}
return false;
}
//-------------------------------------------------------------------------------------------------------------
function Add( $string, $section = "HTT" )
{
if( array_key_exists($section, $this->aHtt) )
$this->aHtt[$section] .= $string;
else
$this->aHtt[$section] = $string;
return true;
}
//-------------------------------------------------------------------------------------------------------------
function Replace( $search, $replace, $section = "HTT" )
{
if( array_key_exists($section, $this->aHtt) ) {
$this->aHtt[$section] = str_replace( $search, $replace, $this->aHtt[$section] );
return true;
}
return false;
}
// -------------------------------------------------------------------------------------------------------------
function Get( $section = "HTT" )
{
$value = "";
if( array_key_exists($section, $this->aHtt) )
$value = str_replace( "\r\n\r\n", "\n", $this->aHtt[$section] );
return $value;
}
//-------------------------------------------------------------------------------------------------------------
function Load( $file, $section = "HTT" )
{
@$fp = fopen( $file, "r" );
if( $fp ) {
$this->aHtt[$section] = fread( $fp, filesize($file) );
fclose( $fp );
return true;
}
return false;
}
// -------------------------------------------------------------------------------------------------------------
function Parse( $section = "HTT" )
{
if( array_key_exists($section, $this->aHtt) ) {
$htt = $this->aHtt[$section];
while( ($name = $this->GetStr( "[" . chr(47), chr(92) . "]", $htt )) ) {
if( ($value = $this->GetStr( "[" . chr(47) . $name . chr(92) . "]", "[" . chr(92) . $name . chr(47) . "]", $htt )) )
$this->aHtt[$name] = $value;
$htt = str_replace( "[" . chr(47) . $name . chr(92) . "]", "", $htt );
$htt = str_replace( "[" . chr(92) . $name . chr(47) . "]", "", $htt );
}
return true;
}
return false;
}
// -------------------------------------------------------------------------------------------------------------
function Clear( $section = "HTT" )
{
if( array_key_exists($section, $this->aHtt) ) {
$this->aHtt[$section] = "";
return true;
}
return false;
}
//-------------------------------------------------------------------------------------------------------------
function GetStr( $str_beg, $str_end, $string )
{
$beg = strpos( $string, $str_beg );
$end = strpos( $string, $str_end );
if( ($beg===false) || ($end===false) )
return "";
$beg += strlen( $str_beg );
return substr( $string, $beg, $end - $beg );
}
//-------------------------------------------------------------------------------------------------------------
}
?>