ultimix
page_parser_1_0_0 Class Reference

Public Member Functions

 __construct ()
 validate_parameters ($Parameters, $Conditions)
 parse_parameters ($Parameters, $Conditions)
 other_macro_was_found ($TmpStartPos, $TmpEndPos, $Counter, $ParserCursor)
 handle_extra_cases ($TmpStartPos, $TmpEndPos, $Counter, $ParserCursor)
 find_parameters_end ($StringData, $MacroName, $ParserCursor)
 parse_macro ($StringData, $MacroName, $Conditions, $StartPos)
 find_next_macro ($StringData, $MacroName, $Conditions)
 get_macro_parameters ()
 get_positions ($StringData, $MacroName)
 get_next_position ($Value, $Key, $StartPos, $EndPos, $c)
 get_macro_end_position ($StringData, $MacroName)
 hide_macro ($StringData, $MacroName)
 show_macro ($StringData, $MacroName)

Data Fields

 $CachedMultyFS = false
 $String = false
 $StartPosition = false
 $EndPosition = false
 $RawMacroParameters = false
 $MacroParameters = false

Detailed Description

Class processes page's macro.

Author
Dodonov A.A.

Definition at line 28 of file page_parser.php.

Constructor & Destructor Documentation

__construct ( )

Constructor.

Author
Dodonov A.A.

Definition at line 102 of file page_parser.php.

{
try
{
$this->CachedMultyFS = get_package( 'cached_multy_fs' , 'last' , __FILE__ );
$this->String = get_package( 'string' , 'last' , __FILE__ );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}

Member Function Documentation

find_next_macro (   $StringData,
  $MacroName,
  $Conditions 
)

Function finds macro in the text.

Parameters
$StringData- Processing string.
$MacroName- Macro's name.
$Conditions- Conditions of the processing.
Returns
true if the macro was found.
Exceptions
Exception- An exception of this type is thrown.
Author
Dodonov A.A.

Definition at line 484 of file page_parser.php.

{
try
{
$this->RawMacroParameters = array();
$this->MacroParameters = false;
$StartPos = -1;
$MacroStart = chr( 123 ).$MacroName.':';
$MacroLength = strlen( $MacroStart );
for( ; ( $StartPos = strpos( $StringData , $MacroStart , $StartPos + 1 ) ) !== false ; )
{
$StartPos += $MacroLength;
$Result = $this->parse_macro( $StringData , $MacroName , $Conditions , $StartPos );
if( $Result )
{
$this->StartPosition = $StartPos - $MacroLength;
return( true );
}
}
return( false );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}
find_parameters_end (   $StringData,
  $MacroName,
  $ParserCursor 
)

Function searches paremeters end.

Parameters
$StringData- Processing string.
$MacroName- Macro's name.
$ParserCursor- Position to start from.
Returns
end of the parameters.
Exceptions
Exception- An exception of this type is thrown.
Author
Dodonov A.A.

Definition at line 369 of file page_parser.php.

{
try
{
$Counter = 1;
do
{
$TmpStartPos = strpos( $StringData , chr( 123 ) , $ParserCursor + 1 );
$TmpEndPos = strpos( $StringData , chr( 125 ) , $ParserCursor + 1 );
list( $Counter , $ParserCursor ) = $this->other_macro_was_found(
$TmpStartPos , $TmpEndPos , $Counter , $ParserCursor
);
list( $Counter , $ParserCursor ) = $this->handle_extra_cases(
$TmpStartPos , $TmpEndPos , $Counter , $ParserCursor
);
}
while( $TmpStartPos && $Counter != 0 );
return( $Counter == 0 ? $TmpEndPos : false );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}
get_macro_end_position (   $StringData,
  $MacroName 
)

Function finds macro end in the text.

Parameters
$StringData- Processing string.
$MacroName- Macro's name.
Exceptions
Exception- An exception of this type is thrown.
Author
Dodonov A.A.

Definition at line 697 of file page_parser.php.

{
try
{
$Positions = $this->get_positions( $StringData , $MacroName );
$StartPos = $this->StartPosition;
$EndPos = false;
$c = 1;
foreach( $Positions as $Key => $Value )
{
if( $Value == 'e' && $Key > $this->StartPosition )
{
list( $StartPos , $EndPos , $c ) = $this->get_next_position(
$Value , $Key , $StartPos , $EndPos , $c
);
}
}
if( $EndPos === false )
{
throw_exception( 'Block end was not found' );
}
$this->EndPosition = $EndPos;
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}
get_macro_parameters ( )

Function provides access to the macro parameters.

Returns
Macro parameters.
Exceptions
Exception- An exception of this type is thrown.
Author
Dodonov A.A.

Definition at line 534 of file page_parser.php.

{
try
{
if( $this->MacroParameters === false )
{
$this->MacroParameters = get_package_object( 'settings::settings' , 'last' , __FILE__ );
$this->MacroParameters->load_settings( $this->RawMacroParameters );
}
return( $this->MacroParameters );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}
get_next_position (   $Value,
  $Key,
  $StartPos,
  $EndPos,
  $c 
)

Function processes position.

Parameters
$Value-
$Key-
$StartPos-
$EndPos-
$c-
Returns
array( $StartPos , $EndPos , $c ).
Exceptions
Exception- An exception of this type is thrown.
Author
Dodonov A.A.

Definition at line 645 of file page_parser.php.

{
try
{
if( $StartPos === false && $Value === 's' )
{
$c++;
$StartPos = $Key;
}
elseif( $EndPos === false && $Value === 'e' && $c === 1 )
{
$EndPos = $Key;
}
elseif( $Value === 's' )
{
$c++;
}
elseif( $Value === 'e' )
{
$c--;
}
return( array( $StartPos , $EndPos , $c ) );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}
get_positions (   $StringData,
  $MacroName 
)

Function finds all candidates to be the macro's end.

Parameters
$StringData- Processing string.
$MacroName- Macro's name.
Returns
Array of positions.
Exceptions
Exception- An exception of this type is thrown.
Author
Dodonov A.A.

Definition at line 578 of file page_parser.php.

{
try
{
$Positions = array();
$StartPos = $this->StartPosition;
$EndPos = -1;
for( ; $StartPos = strpos( $StringData , chr( 123 ).$MacroName.':' , $StartPos + 1 ) ; )
{
$Positions [ $StartPos ] = 's';
}
for( ; $EndPos = strpos( $StringData , chr( 123 ).'~'.$MacroName.chr( 125 ) , $EndPos + 1 ) ; )
{
$Positions [ $EndPos ] = 'e';
}
ksort( $Positions );
return( $Positions );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}
handle_extra_cases (   $TmpStartPos,
  $TmpEndPos,
  $Counter,
  $ParserCursor 
)

Function processes extra cases.

Parameters
$TmpStartPos- Start position.
$TmpEndPos- End position.
$Counter- Counter.
$ParserCursor- Parsing cursor.
Returns
array( $Counter , $ParserCursor ).
Exceptions
Exception- An exception of this type is thrown.
Author
Dodonov A.A.

Definition at line 310 of file page_parser.php.

{
try
{
if( $TmpStartPos !== false && $TmpEndPos === false )
{
$Counter++;
$ParserCursor = $TmpStartPos;
}
if( $TmpStartPos === false && $TmpEndPos !== false )
{
$Counter--;
$ParserCursor = $TmpEndPos;
}
if( $TmpStartPos === false && $TmpEndPos === false )
{
throw( new Exception( 'Closing '.chr( 123 ).' was not found' ) );
}
return( array( $Counter , $ParserCursor ) );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}
hide_macro (   $StringData,
  $MacroName 
)

Function hides macro.

Parameters
$StringData- Processing string.
$MacroName- Macro's name.
Returns
Processed string.
Exceptions
Exception- An exception of this type is thrown.
Author
Dodonov A.A.

Definition at line 755 of file page_parser.php.

{
try
{
$this->get_macro_end_position( $StringData , $MacroName );
$StringData = substr_replace( $StringData ,
'' ,
$this->StartPosition ,
$this->EndPosition - $this->StartPosition + strlen( chr( 123 ).'~'.$MacroName.chr( 125 ) )
);
return( $StringData );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}
other_macro_was_found (   $TmpStartPos,
  $TmpEndPos,
  $Counter,
  $ParserCursor 
)

Function iterates if nested macro was found.

Parameters
$TmpStartPos
$TmpEndPos
$Counter
$ParserCursor
Returns
array( $Counter , $ParserCursor ).
Exceptions
Exception- An exception of this type is thrown.
Author
Dodonov A.A.

Definition at line 250 of file page_parser.php.

{
try
{
if( $TmpStartPos !== false && $TmpEndPos !== false )
{
if( $TmpStartPos < $TmpEndPos )
{
$ParserCursor = $TmpEndPos;
}
if( $TmpEndPos < $TmpStartPos )
{
$Counter--;
if( $Counter )$Counter++;
$ParserCursor = $TmpStartPos;
}
}
return( array( $Counter , $ParserCursor ) );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}
parse_macro (   $StringData,
  $MacroName,
  $Conditions,
  $StartPos 
)

Function tries to parse macro.

Parameters
$StringData- Processing string.
$MacroName- Macro's name.
$Conditions- Conditions of the processing.
$StartPos- Position to start from.
Returns
true if macro was parsed.
Exceptions
Exception- An exception of this type is thrown.
Author
Dodonov A.A.

Definition at line 432 of file page_parser.php.

{
try
{
$EndPos = $this->find_parameters_end( $StringData , $MacroName , $StartPos );
if( $EndPos !== false )
{
/* extracting parameters */
$Parameters = substr( $StringData , $StartPos , $EndPos - $StartPos );
return( $this->parse_parameters( $Parameters , $Conditions ) );
}
return( false );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}
parse_parameters (   $Parameters,
  $Conditions 
)

Function tries to parse macro parameters.

Parameters
$Parameters- Parameters to parse.
$Conditions- Conditions of the processing.
Returns
true if macro parameters were parsed.
Exceptions
Exception- An exception of this type is thrown.
Author
Dodonov A.A.

Definition at line 196 of file page_parser.php.

{
try
{
$Parameters = explode( ';' , $Parameters );
if( $this->validate_parameters( $Parameters , $Conditions ) )
{
$this->RawMacroParameters = $Parameters;
return( true );
}
return( false );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}
show_macro (   $StringData,
  $MacroName 
)

Function shows macro.

Parameters
$StringData- Processing string.
$MacroName- Macro's name.
Returns
Processed string.
Exceptions
Exception- An exception of this type is thrown.
Author
Dodonov A.A.

Definition at line 801 of file page_parser.php.

{
try
{
$this->get_macro_end_position( $StringData , $MacroName );
$this->RawMacroParameters = implode( ';' , $this->RawMacroParameters );
$MacroLength = strlen( chr( 123 )."$MacroName:$this->RawMacroParameters".chr( 125 ) );
$Position = $this->EndPosition - $this->StartPosition - $MacroLength;
$MacroData = substr( $StringData , $this->StartPosition + $MacroLength , $Position );
$Position = $this->EndPosition - $this->StartPosition + strlen( chr( 123 ).'~'.$MacroName.chr( 125 ) );
$StringData = substr_replace( $StringData , $MacroData , $this->StartPosition , $Position );
return( $StringData );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}
validate_parameters (   $Parameters,
  $Conditions 
)

Function tries to validate macro parameters.

Parameters
$Parameters- Parameters to validate.
$Conditions- Conditions of the processing.
Returns
true if macro parameters are valid.
Exceptions
Exception- An exception of this type is thrown.
Author
Dodonov A.A.

Definition at line 141 of file page_parser.php.

{
try
{
foreach( $Parameters as $key1 => $p )
{
$p = explode( '=' , $p );
foreach( $Conditions as $key2 => $rev )
{
if( $key2 == $p[ 0 ] )
{
$Matches = array();
$Result = preg_match( $rev , $p[ 1 ] , $Matches );
if( count( $Matches ) == 0 )
{
return( false );
}
}
}
}
return( true );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}

Field Documentation

$CachedMultyFS = false

Cached objects.

Author
Dodonov A.A.

Definition at line 41 of file page_parser.php.

$EndPosition = false

Ending block's position.

Author
Dodonov A.A.

Definition at line 66 of file page_parser.php.

$MacroParameters = false

Macro parameters.

Author
Dodonov A.A.

Definition at line 90 of file page_parser.php.

$RawMacroParameters = false

Macro parameters.

Author
Dodonov A.A.

Definition at line 78 of file page_parser.php.

$StartPosition = false

Opening block's position.

Author
Dodonov A.A.

Definition at line 54 of file page_parser.php.

$String = false

Definition at line 42 of file page_parser.php.


The documentation for this class was generated from the following file: