87 $this->Cache =
get_package(
'cache' ,
'last' , __FILE__ );
88 $this->CachedMultyFS =
get_package(
'cached_multy_fs' ,
'last' , __FILE__ );
89 $this->ConfigSettings =
get_package_object(
'settings::settings' ,
'last' , __FILE__ );
92 'page::template_content::template_content_access' ,
'last' , __FILE__
94 $this->String =
get_package(
'string' ,
'last' , __FILE__ );
95 $this->Utilities =
get_package(
'utilities' ,
'last' , __FILE__ );
96 $this->ParsedConfig = array();
126 private function get_name( &$Config )
130 if( ( $Name = $Config->get_setting(
'macro_name' ,
false ) ) !==
false )
134 elseif( ( $Name = $Config->get_setting(
'block_name' ,
false ) ) !==
false )
138 throw(
new Exception(
'Macro name was not found' ) );
140 catch( Exception $e )
160 private function load_template_contents_configs_from_file()
164 $this->MacroScripts = $this->CachedMultyFS->get_config( __FILE__ ,
'cf_macro_scripts' );
165 $this->MacroScripts = explode(
"\n" , $this->MacroScripts );
167 foreach( $this->MacroScripts as $k => $v )
169 $this->ConfigSettings->load_settings( $v );
171 $Name = $this->get_name( $this->ConfigSettings );
173 $this->ParsedConfig[ $Name ] = $this->ConfigSettings->get_raw_settings();
176 $this->Cache->add_data(
'parsed_macro_config' , serialize( $this->ParsedConfig ) );
178 catch( Exception $e )
198 private function load_template_contents_configs()
202 if( count( $this->ParsedConfig ) == 0 )
204 if( $this->Cache->data_exists(
'parsed_macro_config' ) )
206 $this->ParsedConfig = unserialize( $this->Cache->get_data(
'parsed_macro_config' ) );
210 $this->load_template_contents_configs_from_file();
214 catch( Exception $e )
246 private function compile_macro( &$Config , &
$Settings )
250 if( $Config->get_setting(
'template' ,
false ) )
252 $Content = $this->TemplateContentAccess->get_content_ex( $Config );
256 $Package = $this->Utilities->get_package( $Config , __FILE__ );
257 $Function = $Config->get_setting(
'compilation_func' ,
false );
258 $Content = call_user_func( array( $Package , $Function ) ,
$Settings );
263 $Content = $this->String->print_record( $Content ,
$Settings->get_raw_settings() );
268 catch( Exception $e )
304 private function compile_block( &$Config , &
$Settings , $Data )
308 if( $Config->get_setting(
'template' ,
false ) )
310 $Content = $this->TemplateContentAccess->get_content_ex( $Config );
314 $Package = $this->Utilities->get_package( $Config , __FILE__ );
315 $Function = $Config->get_setting(
'compilation_func' ,
false );
316 $Content = call_user_func( array( $Package , $Function ) ,
$Settings , $Data );
321 $Content = $this->String->print_record( $Content ,
$Settings->get_raw_settings() );
326 catch( Exception $e )
362 private function compile_simple_macro( &$Config , $Str , $Changed )
366 $Name = $this->get_name( $Config );
368 if( strpos( $Str ,
'{'.$Name.
'}' ) !==
false )
370 $this->Settings->clear();
371 $this->set_default_values( $this->Settings , $Config );
372 $Content = $this->compile_macro( $Config , $this->Settings );
373 $Str = str_replace(
'{'.$Name.
'}' , $Content , $Str );
377 return( array( $Str , $Changed ) );
379 catch( Exception $e )
407 private function get_rules( &$Config )
413 if( $Config->get_setting(
'terminal_values' ,
false ) !== false )
415 $TerminalValues = explode(
',' , $Config->get_setting(
'terminal_values' ) );
417 foreach( $TerminalValues as $i => $Name )
419 $Rules[ $Name ] = TERMINAL_VALUE;
425 catch( Exception $e )
453 private function set_default_values( &
$Settings , &$Config )
457 if( $Config->get_setting(
'default_values' ,
false ) !== false )
459 $DefaultValues = explode(
',' , $Config->get_setting(
'default_values' ,
false ) );
461 foreach( $DefaultValues as $i => $DefaultValue )
463 $DefaultValue = explode(
':' , $DefaultValue );
464 $Settings->set_undefined( $DefaultValue[ 0 ] , $DefaultValue[ 1 ] );
468 catch( Exception $e )
504 private function compile_parametrized_macro( &$Config , $Str , $Changed )
508 $Name = $this->get_name( $Config );
510 $Rules = $this->get_rules( $Config );
512 for( ; $Params = $this->String->get_macro_parameters( $Str , $Name , $Rules ) ; )
514 $this->Settings->load_settings( $Params );
515 $this->set_default_values( $this->Settings , $Config );
516 $Content = $this->compile_macro( $Config , $this->Settings );
517 $Str = str_replace(
'{'.
"$Name:$Params".
'}' , $Content , $Str );
521 return( array( $Str , $Changed ) );
523 catch( Exception $e )
563 private function compile_single_type_single_block( $Name , $Str , $Params , &$Config )
567 $this->Settings->load_settings( $Params );
568 $this->set_default_values( $this->Settings , $Config );
570 $Data = $this->String->get_block_data( $Str ,
"$Name:$Params" ,
"~$Name" );
572 $Content = $this->compile_block( $Config , $this->Settings , $Data );
574 $Str = substr_replace(
575 $Str , $Content.
'{'.
"$Name:$Params".
'}' ,
576 strpos( $Str ,
'{'.
"$Name:$Params".
'}' ) , strlen(
'{'.
"$Name:$Params".
'}' )
580 return( array( $this->String->hide_block( $Str ,
"$Name:$Params" ,
"~$Name" , $Changed ) , true ) );
582 catch( Exception $e )
618 private function compile_parametrized_block( &$Config , $Str , $Changed )
622 $Name = $this->get_name( $Config );
624 $Rules = $this->get_rules( $Config );
626 for( ; $Params = $this->String->get_macro_parameters( $Str , $Name , $Rules ) ; )
628 list( $Str , $Changed ) = $this->compile_single_type_single_block(
629 $Name , $Str , $Params , $Config
633 return( array( $Str , $Changed ) );
635 catch( Exception $e )
663 private function is_macro( &$Config )
667 if( ( $Name = $Config->get_setting(
'macro_name' ,
false ) ) !==
false )
671 elseif( ( $Name = $Config->get_setting(
'block_name' ,
false ) ) !==
false )
676 throw(
new Exception(
'Undefined entity type' ) );
678 catch( Exception $e )
714 private function compile_named_macro( $Name , $Str , $Changed )
718 if( isset( $this->ParsedConfig[ $Name ] ) )
720 $this->ConfigSettings->load_raw_settings( $this->ParsedConfig[ $Name ] );
721 if( $this->is_macro( $this->ConfigSettings ) )
723 list( $Str , $Changed ) = $this->compile_simple_macro(
724 $this->ConfigSettings , $Str , $Changed
727 list( $Str , $Changed ) = $this->compile_parametrized_macro(
728 $this->ConfigSettings , $Str , $Changed
733 list( $Str , $Changed ) = $this->compile_parametrized_block(
734 $this->ConfigSettings , $Str , $Changed
738 return( array( $Str , $Changed ) );
740 catch( Exception $e )
780 $this->load_template_contents_configs();
782 $Macroes = $this->String->find_all_macro( $Str );
784 foreach( $Macroes as $i => $Name )
786 list( $Str , $Changed ) = $this->compile_named_macro( $Name , $Str , $Changed );
789 return( array( $Str , $Changed ) );
791 catch( Exception $e )
834 catch( Exception $e )