<?php
class PostDataHandler implements ArrayAccess {
private $ComponentStorage;
private $POSTConfiguration;
public function __construct( $IncomingPOST ) {
global $POSTSecureLabFilter;
@ $this->POSTConfiguration = $POSTSecureLabFilter;
@ $this->ComponentStorage = $IncomingPOST;
}
public function offsetGet ( $IncomingOffset ) {
try {
if( strpos ( $IncomingOffset, "#" ) ) {
// We don't know is working a newborn developer or not, so let's check for errors.
$CurrentFilterApply = explode ( "#", $IncomingOffset, 2 );
if( $CurrentFilterApply == "nofilter") {
return $this->ComponentStorage[$CurrentFilterApply[0]];
} elseif( substr( $CurrentFilterApply[1], 0, 4 ) == "exp[" ) {
$ExArray = explode ( "exp[", $CurrentFilterApply[1] );
$ExArray = explode ( "]", $ExArray[1] );
$ExArray = explode ( "|", $ExArray[0] );
} elseif( strpos($CurrentFilterApply[1], ",") ) {
$FiltersArray = explode ( ",", $CurrentFilterApply[1] );
} else {
return SecureLabFilters::ApplyFilter( $this->ComponentStorage[$CurrentFilterApply[0]], $CurrentFilterApply[1] );
}
$AllowedExpressions = array( "num", "en", "ru", "+", "-", ".", ",", "!", "*", "'", "\"", "~", "<", ">",
"contol-base", "control-html", "@", "$", ":", ";", "/", "\\", "%", "^", "?",
"(", ")", "_", "=", "symb", "#" );
if( $FiltersArray != null or $ExArray != null ) {
if( $ExArray != null ) {
$Filter = null;
foreach( $ExArray as $KeyID => $Expression ) {
if( in_array( $Expression, $AllowedExpressions ) ) {
$Expression = strtr( $Expression, array( "en" => "A-Za-z", "num" => "0-9" ) );
$Filter .= $Expression;
}
}
preg_match_all("/[" . $Filter . "]*/", $this->ComponentStorage[$CurrentFilterApply[0]], $Match);
$ResultToReturn = "";
foreach ($Match[0] as $MatchKey => $MatchValue) {
$ResultToReturn .= $MatchValue;
}
return $ResultToReturn;
}
if( $FiltersArray ) {
$Content = $this->ComponentStorage[$CurrentFilterApply[0]];
foreach( $FiltersArray as $KeyID => $FilterID ) {
$Content = SecureLabFilters::ApplyFilter( $Content, $FilterID );
}
return $Content;
}
}
} else {
if( $IncomingOffset == null ) {
return $this->ComponentStorage;
} else {
global $_SecureLabMainClass;
if( $_SecureLabMainClass ) {
return $_SecureLabMainClass->FiltersAPI->ApplyFilter( $this->ComponentStorage[$IncomingOffset], 1 );
} else {
return SecureLabFilters::ApplyFilter( $this->ComponentStorage[$IncomingOffset], 1 );
}
}
}
} catch( Exception $ErrorMsg ) {
global $_SecureLabMainClass;
@ $_SecureLabMainClass->DumpAPI->CreateDumpEvent( array(
"ErrorReporterFile" => __FILE__,
"ErrorReporterMessage" => $ErrorMsg->getMessage(),
"ErrorOccuredObject" => __METHOD__,
"ErrorIncomingEvent" => $IncomingOffset,
"ErrorFileLine" => __LINE__
) );
}
}
public function __invoke( $Needle = null ) {
if( $Needle == "" ) {
if( empty( $this->ComponentStorage ) ) {
return true;
} else {
return false;
}
}
}
// We need to define this functions for correct work of ArrayAccess option.
public function offsetExists ( $IncomingKey ) {
if( $IncomingKey == null ) {
return $this->ComponentStorage;
} else {
return isset($this->ComponentStorage[$IncomingKey]);
}
}
public function offsetUnset ( $IncomingKey ) {
unset($this->ComponentStorage[ $IncomingKey ]);
}
public function offsetSet ($IncomingKey, $ValueToRewrite) {
try {
if( $this->POSTConfiguration["ALLOW_REWRITING_VALUES"] == 0 ) {
throw new Exception( "Rewriting of POST is disallowed, key " . $IncomingKey );
} else {
$this->ComponentStorage[ $IncomingKey ] = $ValueToRewrite;
}
} catch( Exception $ErrorMsg ) {
global $_SecureLabMainClass;
@ $_SecureLabMainClass->DumpAPI->CreateDumpEvent( array(
"ErrorReporterFile" => __FILE__,
"ErrorReporterMessage" => $ErrorMsg->getMessage(),
"ErrorOccuredObject" => __METHOD__,
"ErrorIncomingEvent" => $IncomingKey,
"ErrorFileLine" => __LINE__
) );
}
}
}
?>