16 DEFINE(
'TERMINAL_VALUE' ,
"/^[\{\}]{0}[^\{\}]*$/" );
60 $this->Tags =
get_package(
'string::tags' ,
'last' , __FILE__ );
106 function hide_block( $StringData , $BlockStart , $BlockEnd , &$Changed )
110 list( $StartPos , $EndPos ) = $this->
get_block_positions( $StringData , $BlockStart , $BlockEnd );
112 if( $StartPos !==
false )
114 $StringData = substr_replace( $StringData ,
117 $EndPos - $StartPos + strlen( chr( 123 ).$BlockEnd.chr( 125 ) )
123 return( $StringData );
125 catch( Exception $e )
165 function show_block( $StringData , $BlockStart , $BlockEnd , &$Changed )
169 list( $StartPos , $EndPos ) = $this->
get_block_positions( $StringData , $BlockStart , $BlockEnd );
170 if( $StartPos !==
false )
172 $BlockData = $this->
get_block_data( $StringData , $BlockStart , $BlockEnd );
174 $StringData = substr_replace( $StringData ,
177 $EndPos - $StartPos + strlen( chr( 123 ).$BlockEnd.chr( 125 ) )
183 return( $StringData );
185 catch( Exception $e )
221 private function apply_foreach_data( $Str , $Parameters , $Data )
225 $SubTemplate = $this->
get_block_data( $Str ,
"foreach:$Parameters" ,
'~foreach' );
227 foreach( $Data as $k => $v )
230 "{foreach:$Parameters}" ,
231 $this->
print_record( $SubTemplate , $v ).
"{foreach:$Parameters}" , $Str
237 catch( Exception $e )
275 $this->Settings->load_settings( $Parameters );
276 $Var = $this->Settings->get_setting(
'var' );
279 $Str = $this->apply_foreach_data( $Str , $Parameters , $Data );
281 $Str = $this->
hide_block( $Str ,
"foreach:$Parameters" ,
'~foreach' , $Changed );
287 catch( Exception $e )
323 if( is_array( $Record ) ===
false && is_object( $Record ) ===
false )
325 throw(
new Exception(
'Invalid record was passed' ) );
330 foreach( $Record as $Field => $Value )
332 if( is_array( $Value ) || is_object( $Value ) )
338 $Str = str_replace( chr( 123 ).$Field.chr( 125 ) , $Value , $Str );
344 catch( Exception $e )
384 $StartPos = strpos( $StringData , chr( 123 ).$BlockStart.chr( 125 ) );
385 if( $StartPos ==
false )
390 if( $BlockEnd !==
false )
392 $EndPos = strpos( $StringData , chr( 123 ).$BlockEnd.chr( 125 ) );
393 if( $EndPos ==
false )
401 catch( Exception $e )
443 for( ; ( $TmpStartPos = strpos( $StringData , chr( 123 ).$Name.
':' , $StartPos + 1 ) ) !==
false ; )
446 $StartPos = $TmpEndPos = $TmpStartPos;
448 $MacroStartPos = $StartPos;
449 $ParamStartPos = $MacroStartPos + strlen( chr( 123 ).$Name.
':' );
451 $Result = $this->MacroParser->find_macro( $StringData , $TmpStartPos , $TmpEndPos ,
452 $StartPos , $Counter , $MacroStartPos , $ParamStartPos , $RegExValidators );
454 if( $Result !==
false )
462 catch( Exception $e )
502 list( $StartPos , $EndPos ) = $this->
get_block_positions( $StringData , $BlockStart , $BlockEnd );
504 if( $StartPos !==
false )
508 $StartPos + strlen( chr( 123 ).$BlockStart.chr( 125 ) ) ,
509 $EndPos - $StartPos - strlen( chr( 123 ).$BlockStart.chr( 125 ) )
512 return( $BlockData );
516 throw(
new Exception(
'An error occured while getting block data' ) );
519 catch( Exception $e )
563 $PlaceHolders = array();
566 $PlaceHolders = array();
568 preg_match(
"/\{$BlockType:([a-zA-Z0-9_]+)\}/" , $StringData , $PlaceHolders );
570 if( count( $PlaceHolders ) > 1 )
572 $StringData = $this->
hide_block( $StringData ,
"$BlockType:".$PlaceHolders[ 1 ] ,
573 "$BlockType:~".$PlaceHolders[ 1 ] , $Changed );
576 while( count( $PlaceHolders ) > 1 );
578 return( $StringData );
580 catch( Exception $e )
620 $Positions = array();
625 for( ; $StartPos = strpos( $StringData , chr( 123 ).$BlockStart.chr( 125 ) , $StartPos + 1 ) ; )
627 $Positions [ $StartPos ] =
's';
629 for( ; $EndPos = strpos( $StringData , chr( 123 ).$BlockEnd.chr( 125 ) , $EndPos + 1 ) ; )
631 $Positions [ $EndPos ] =
'e';
635 return( $Positions );
637 catch( Exception $e )
669 $StartPos = $EndPos =
false;
671 foreach( $Positions as $Key => $Value )
673 if( $StartPos ===
false && $Value ===
's' )
678 elseif( $EndPos ===
false && $Value ===
'e' && $c === 1 )
683 elseif( $Value ===
's' || $Value ===
'e' && $c > 0 )
685 $c += $Value ===
's' ? 1 : -1;
689 return( array( $StartPos , $EndPos ) );
691 catch( Exception $e )
735 if( $StartPos ===
false )
737 return( array(
false ,
false ) );
739 if( $EndPos ===
false )
741 throw(
new Exception(
'Block end was not found' ) );
744 return( array( $StartPos , $EndPos ) );
746 catch( Exception $e )
778 if( strpos( $Data[
'path' ] ,
'{http_host}/' ) === 0 )
780 $Data[
'path' ] = str_replace(
'{http_host}/' ,
'./' , $Data[
'path' ] );
783 $Data[
'path' ] = $this->Tags->compile_ultimix_tags( $Data[
'path' ] );
787 catch( Exception $e )
821 preg_match_all(
'/\{([a-zA-Z0-9_]+)/' , $Data , $Matches );
823 return( array_unique( $Matches[ 1 ] ) );
825 catch( Exception $e )