ultimix
string_1_0_0 Class Reference

Public Member Functions

 __construct ()
 hide_block ($StringData, $BlockStart, $BlockEnd, &$Changed)
 show_block ($StringData, $BlockStart, $BlockEnd, &$Changed)
 compile_foreach ($Str, &$Record)
 print_record ($Str, &$Record)
 block_exists ($StringData, $BlockStart, $BlockEnd=false)
 get_macro_parameters ($StringData, $Name, $RegExValidators=array())
 get_block_data ($StringData, $BlockStart, $BlockEnd)
 hide_unprocessed_blocks ($StringData, $BlockType, &$Changed)
 get_all_block_positions ($StringData, $BlockStart, $BlockEnd)
 get_possible_block_positions (&$Positions)
 get_block_positions ($StringData, $BlockStart, $BlockEnd)
 clear_ultimix_tags ($Data)
 find_all_macro (&$Data)

Data Fields

 $MacroParser = false
 $Settings = false
 $Tags = false

Detailed Description

String utilities.

Author
Dodonov A.A.

Definition at line 28 of file string.php.

Constructor & Destructor Documentation

__construct ( )

Constructor.

Author
Dodonov A.A.

Definition at line 54 of file string.php.

{
try
{
$this->MacroParser = get_package_object( 'string::macro_parser' , 'last' , __FILE__ );
$this->Settings = get_package_object( 'settings::settings' , 'last' , __FILE__ );
$this->Tags = get_package( 'string::tags' , 'last' , __FILE__ );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}

Member Function Documentation

block_exists (   $StringData,
  $BlockStart,
  $BlockEnd = false 
)

Function validates block's existance.

Parameters
$StringDataProcessing data.
$BlockStart- Marker of the block's begin.
$BlockEnd- Marker of the block's end.
Returns
- true if the block exists, false otherwise.
Exceptions
ExceptionAn exception of this type is thrown.
Author
Dodonov A.A.

Definition at line 380 of file string.php.

{
try
{
$StartPos = strpos( $StringData , chr( 123 ).$BlockStart.chr( 125 ) );
if( $StartPos == false )
{
return( false );
}
if( $BlockEnd !== false )
{
$EndPos = strpos( $StringData , chr( 123 ).$BlockEnd.chr( 125 ) );
if( $EndPos == false )
{
return( false );
}
}
return( true );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}
clear_ultimix_tags (   $Data)

Function removes special tags.

Parameters
$Data- Data to process.
Returns
Data after processing.
Exceptions
ExceptionAn exception of this type is thrown.
Author
Dodonov A.A.

Definition at line 774 of file string.php.

{
try
{
if( strpos( $Data[ 'path' ] , '{http_host}/' ) === 0 )
{
$Data[ 'path' ] = str_replace( '{http_host}/' , './' , $Data[ 'path' ] );
}
$Data[ 'path' ] = $this->Tags->compile_ultimix_tags( $Data[ 'path' ] );
return( $Data );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}
compile_foreach (   $Str,
$Record 
)

Function process macro 'foreach'.

Parameters
$Str- Format template.
$Record- Outputting record.
Returns
Formatted data.
Exceptions
ExceptionAn exception of this type is thrown.
Author
Dodonov A.A.

Definition at line 269 of file string.php.

{
try
{
for( ; $Parameters = $this->get_macro_parameters( $Str , 'foreach' ) ; )
{
$this->Settings->load_settings( $Parameters );
$Var = $this->Settings->get_setting( 'var' );
$Data = get_field( $Record , $Var );
$Str = $this->apply_foreach_data( $Str , $Parameters , $Data );
$Str = $this->hide_block( $Str , "foreach:$Parameters" , '~foreach' , $Changed );
$Changed = false;
}
return( $Str );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}
find_all_macro ( $Data)

Function returns a list of macro.

Parameters
$Data- Data to process.
Returns
A list of macro.
Exceptions
ExceptionAn exception of this type is thrown.
Author
Dodonov A.A.

Definition at line 815 of file string.php.

{
try
{
$Matches = array();
preg_match_all( '/\{([a-zA-Z0-9_]+)/' , $Data , $Matches );
return( array_unique( $Matches[ 1 ] ) );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}
get_all_block_positions (   $StringData,
  $BlockStart,
  $BlockEnd 
)

Function returns positions of all blocks'es ends and beginnings.

Parameters
$StringData- Processing data.
$BlockStart- Marker of the block's begin.
$BlockEnd- Marker of the block's end.
Returns
Beginnings and ends of the block.
Exceptions
ExceptionAn exception of this type is thrown.
Author
Dodonov A.A.

Definition at line 616 of file string.php.

{
try
{
$Positions = array();
$StartPos = -1;
$EndPos = -1;
for( ; $StartPos = strpos( $StringData , chr( 123 ).$BlockStart.chr( 125 ) , $StartPos + 1 ) ; )
{
$Positions [ $StartPos ] = 's';
}
for( ; $EndPos = strpos( $StringData , chr( 123 ).$BlockEnd.chr( 125 ) , $EndPos + 1 ) ; )
{
$Positions [ $EndPos ] = 'e';
}
ksort( $Positions );
return( $Positions );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}
get_block_data (   $StringData,
  $BlockStart,
  $BlockEnd 
)

Function validates block's existance.

Parameters
$StringData- Processing data.
$BlockStart- Marker of the block's begin.
$BlockEnd- Marker of the block's end.
Returns
- true if the block exists, false otherwise.
Exceptions
ExceptionAn exception of this type is thrown.
Author
Dodonov A.A.

Definition at line 498 of file string.php.

{
try
{
list( $StartPos , $EndPos ) = $this->get_block_positions( $StringData , $BlockStart , $BlockEnd );
if( $StartPos !== false )
{
$BlockData = substr(
$StringData ,
$StartPos + strlen( chr( 123 ).$BlockStart.chr( 125 ) ) ,
$EndPos - $StartPos - strlen( chr( 123 ).$BlockStart.chr( 125 ) )
);
return( $BlockData );
}
else
{
throw( new Exception( 'An error occured while getting block data' ) );
}
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}
get_block_positions (   $StringData,
  $BlockStart,
  $BlockEnd 
)

Function returns positions of the block's end and beginning.

Parameters
$StringData- Processing data.
$BlockStart- Marker of the block's begin.
$BlockEnd- Marker of the block's end.
Returns
Begin and end of the block.
Exceptions
ExceptionAn exception of this type is thrown.
Author
Dodonov A.A.

Definition at line 727 of file string.php.

{
try
{
$Positions = $this->get_all_block_positions( $StringData , $BlockStart , $BlockEnd );
list( $StartPos , $EndPos ) = $this->get_possible_block_positions( $Positions );
if( $StartPos === false )
{
return( array( false , false ) );
}
if( $EndPos === false )
{
throw( new Exception( 'Block end was not found' ) );
}
return( array( $StartPos , $EndPos ) );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}
get_macro_parameters (   $StringData,
  $Name,
  $RegExValidators = array() 
)

Function returns macro's parameters.

Parameters
$StringData- Data to be parsed.
$Name- Macro's parameters.
$RegExValidators- Regular expressions for parameters validation.
Returns
Macro's name. If the macro was not found then false will be returned.
Exceptions
ExceptionAn exception of this type is thrown.
Author
Dodonov A.A.

Definition at line 437 of file string.php.

{
try
{
$StartPos = -1;
for( ; ( $TmpStartPos = strpos( $StringData , chr( 123 ).$Name.':' , $StartPos + 1 ) ) !== false ; )
{
$Counter = 1;
$StartPos = $TmpEndPos = $TmpStartPos;
$MacroStartPos = $StartPos;
$ParamStartPos = $MacroStartPos + strlen( chr( 123 ).$Name.':' );
$Result = $this->MacroParser->find_macro( $StringData , $TmpStartPos , $TmpEndPos ,
$StartPos , $Counter , $MacroStartPos , $ParamStartPos , $RegExValidators );
if( $Result !== false )
{
return( $Result );
}
}
return( false );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}
get_possible_block_positions ( $Positions)

Function returns possible positions of the block's end and beginning.

Parameters
$Positions- Positions of all blocks.
Returns
The beginning and the end of the block.
Exceptions
ExceptionAn exception of this type is thrown.
Author
Dodonov A.A.

Definition at line 665 of file string.php.

{
try
{
$StartPos = $EndPos = false;
$c = 0;
foreach( $Positions as $Key => $Value )
{
if( $StartPos === false && $Value === 's' )
{
$c++;
$StartPos = $Key;
}
elseif( $EndPos === false && $Value === 'e' && $c === 1 )
{
$EndPos = $Key;
break;
}
elseif( $Value === 's' || $Value === 'e' && $c > 0 )
{
$c += $Value === 's' ? 1 : -1;
}
}
return( array( $StartPos , $EndPos ) );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}
hide_block (   $StringData,
  $BlockStart,
  $BlockEnd,
$Changed 
)

Function deletes text block.

Parameters
$StringData- Processing data.
$BlockStart- Marker of the block's begin.
$BlockEnd- Marker of the block's end.
$Changed- Was the sring processed.
Returns
Processed block.
Note
All blocks will be deleted.
Exceptions
ExceptionAn exception of this type is thrown.
Author
Dodonov A.A.

Definition at line 106 of file string.php.

{
try
{
list( $StartPos , $EndPos ) = $this->get_block_positions( $StringData , $BlockStart , $BlockEnd );
if( $StartPos !== false )
{
$StringData = substr_replace( $StringData ,
'' ,
$StartPos ,
$EndPos - $StartPos + strlen( chr( 123 ).$BlockEnd.chr( 125 ) )
);
$Changed = true;
}
return( $StringData );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}
hide_unprocessed_blocks (   $StringData,
  $BlockType,
$Changed 
)

Function deletes text block.

Parameters
$StringData- Processing data.
$BlockType- Block's type.
$Changed- Was the sring processed.
Returns
Processed block.
Note
All blocks will be deleted.
Exceptions
ExceptionAn exception of this type is thrown.
Author
Dodonov A.A.

Definition at line 559 of file string.php.

{
try
{
$PlaceHolders = array();
do
{
$PlaceHolders = array();
preg_match( "/\{$BlockType:([a-zA-Z0-9_]+)\}/" , $StringData , $PlaceHolders );
if( count( $PlaceHolders ) > 1 )
{
$StringData = $this->hide_block( $StringData , "$BlockType:".$PlaceHolders[ 1 ] ,
"$BlockType:~".$PlaceHolders[ 1 ] , $Changed );
}
}
while( count( $PlaceHolders ) > 1 );
return( $StringData );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}
print_record (   $Str,
$Record 
)

Function makes a formatted output for record $Record and template.

Parameters
$Str- Format template.
$Record- Outputting record.
Returns
Formatted data.
Exceptions
ExceptionAn exception of this type is thrown.
Author
Dodonov A.A.

Definition at line 319 of file string.php.

{
try
{
if( is_array( $Record ) === false && is_object( $Record ) === false )
{
throw( new Exception( 'Invalid record was passed' ) );
}
$Str = $this->compile_foreach( $Str , $Record );
foreach( $Record as $Field => $Value )
{
if( is_array( $Value ) || is_object( $Value ) )
{
$Str = $this->print_record( $Str , $Value );
}
else
{
$Str = str_replace( chr( 123 ).$Field.chr( 125 ) , $Value , $Str );
}
}
return( $Str );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}
show_block (   $StringData,
  $BlockStart,
  $BlockEnd,
$Changed 
)

Function deletes block's bounds.

Parameters
$StringData- Processing data.
$BlockStart- Marker of the block's begin.
$BlockEnd- Marker of the block's end.
$Changed- Was the sring processed.
Returns
- Processed block.
Exceptions
ExceptionAn exception of this type is thrown.
Author
Dodonov A.A.

Definition at line 165 of file string.php.

{
try
{
list( $StartPos , $EndPos ) = $this->get_block_positions( $StringData , $BlockStart , $BlockEnd );
if( $StartPos !== false )
{
$BlockData = $this->get_block_data( $StringData , $BlockStart , $BlockEnd );
$StringData = substr_replace( $StringData ,
$BlockData ,
$StartPos ,
$EndPos - $StartPos + strlen( chr( 123 ).$BlockEnd.chr( 125 ) )
);
$Changed = true;
}
return( $StringData );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}

Field Documentation

$MacroParser = false

Cached objects.

Author
Dodonov A.A.

Definition at line 40 of file string.php.

$Settings = false

Definition at line 41 of file string.php.

$Tags = false

Definition at line 42 of file string.php.


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