ultimix

- Main Page
- Data Structures
- Files
- Examples

- File List
- Globals

context_set.php
Go to the documentation of this file.
1 <?php
2
3 /*
4 * This source code is a part of the Ultimix Project.
5 * It is distributed under BSD license. All other third side source code (like tinyMCE) is distributed under
6 * it's own license wich could be found from the corresponding files or sources.
7 * This source code is provided "as is" without any warranties or garanties.
8 *
9 * Have a nice day!
10 *
11 * @url http://ultimix.sorceforge.net
12 *
13 * @author Alexey "gdever" Dodonov
14 */
15
26 class context_set_1_0_0{
27
38 var $CachedMultyFS = false;
39 var $CommonStateStartup = false;
40 var $ContextSetConfigs = false;
41 var $CustomStateStartup = false;
42 var $Context = false;
43 var $ContextSetSettings = false;
44 var $CustomSettings = false;
45 var $Messages = false;
46 var $PageJS = false;
47 var $Security = false;
48 var $String = false;
49 var $Trace = false;
50
61 var $Prefix;
62
73 var $Provider;
74
85 var $Contexts = array();
86
101 private function get_main_packages()
102 {
103 try
104 {
105 $this->Messages = get_package( 'page::messages' , 'last' , __FILE__ );
106 $this->PageJS = get_package( 'page::page_js' , 'last' , __FILE__ );
107 $this->Context = get_package( 'gui::context' , 'last' , __FILE__ );
108 $this->CachedMultyFS = get_package( 'cached_multy_fs' , 'last' , __FILE__ );
109 $this->Security = get_package( 'security' , 'last' , __FILE__ );
110 $this->String = get_package( 'string' , 'last' , __FILE__ );
111 $this->Trace = get_package( 'trace' , 'last' , __FILE__ );
112 }
113 catch( Exception $e )
114 {
115 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
116 }
117 }
118
133 private function get_additional_packages()
134 {
135 try
136 {
137 $this->CustomSettings = get_package_object( 'settings::settings' , 'last' , __FILE__ );
138 $this->ContextSetSettings = get_package_object( 'settings::settings' , 'last' , __FILE__ );
139 $PackageName = 'gui::context_set::context_set_markup';
140 $this->ContextSetMarkup = get_package( $PackageName , 'last' , __FILE__ );
141 }
142 catch( Exception $e )
143 {
144 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
145 }
146 }
147
162 function __construct()
163 {
164 try
165 {
166 $this->CommonStateStartup = get_package( 'gui::context_set::common_state_startup' , 'last' , __FILE__ );
167 $this->ContextSetConfigs = get_package( 'gui::context_set::context_set_configs' , 'last' , __FILE__ );
168 $this->CustomStateStartup = get_package( 'gui::context_set::custom_state_startup' , 'last' , __FILE__ );
169 $this->get_main_packages();
170 $this->get_additional_packages();
171 }
172 catch( Exception $e )
173 {
174 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
175 }
176 }
177
196 function pre_generation( $Options )
197 {
198 try
199 {
200 $Path = _get_package_relative_path_ex( 'gui::context_set' , '1.0.0' );
201 $this->PageJS->add_javascript( "{http_host}/$Path/include/js/context_set.js" );
202 }
203 catch( Exception $e )
204 {
205 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
206 }
207 }
208
223 function clear()
224 {
225 try
226 {
227 $this->Contexts = array();
228 }
229 catch( Exception $e )
230 {
231 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
232 }
233 }
234
253 function add_context( $ContextPath )
254 {
255 try
256 {
257 $this->Contexts [] = $ContextPath;
258 }
259 catch( Exception $e )
260 {
261 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
262 }
263 }
264
291 function add_contexts( &$Options , $ContextFolder , $Contexts )
292 {
293 try
294 {
295 $HintedContext = $Options->get_setting( 'context' , false );
296
297 if( $HintedContext !== false && in_array( $HintedContext , $Contexts ) )
298 {
299 $this->Trace->add_trace_string( "Hinted context : $ContextFolder/conf/$HintedContext" , COMMON );
300 $this->Contexts [] = "$ContextFolder/conf/$HintedContext";
301 }
302 else
303 {
304 $this->Trace->add_trace_string( "Hinted context : all contexts" , COMMON );
305 foreach( $Contexts as $i => $Context )
306 {
307 $this->Contexts [] = "$ContextFolder/conf/$Context";
308 }
309 }
310 }
311 catch( Exception $e )
312 {
313 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
314 }
315 }
316
343 function get_update_record( $New , $Original )
344 {
345 try
346 {
347 $Update = array();
348
349 foreach( $New as $Field => $NewValue )
350 {
351 $Field = str_replace( $this->Prefix.'_' , '' , $Field );
352
353 if( @$Original->$Field == $NewValue )
354 {
355 continue;
356 }
357 if( @$Original->$Field != $this->Security->get( $NewValue , 'unsafe_string' ) )
358 {
359 @$Update[ $Field ] = $NewValue;
360 continue;
361 }
362 }
363
364 return( $Update );
365 }
366 catch( Exception $e )
367 {
368 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
369 }
370 }
371
398 function compile_prefix( $Str , $Changed )
399 {
400 try
401 {
402 if( strpos( $Str , '{prefix}' ) !== false )
403 {
404 $Str = str_replace( '{prefix}' , $this->Prefix ,$Str );
405 $Changed = true;
406 }
407
408 return( array( $Str , $Changed ) );
409 }
410 catch( Exception $e )
411 {
412 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
413 }
414 }
415
438 function set_locations( &$Options , $AutoRedirect )
439 {
440 try
441 {
442 $AutoRedirect = intval( $Options->get_setting( 'auto_redirect' , $AutoRedirect ) );
443 $AutoRedirect = $this->Security->get_gp( 'auto_redirect' , 'integer' , $AutoRedirect );
444 if( $AutoRedirect && $this->Security->get_srv( 'HTTP_REFERER' , 'set' ) )
445 {
446 header( $_SERVER[ 'SERVER_PROTOCOL' ].' 303 See Other' );
447 if( $Options->get_setting( 'redirect_page' , false ) )
448 {
449 header( "Location: ".$Options->get_setting( 'redirect_page' ) );
450 }
451 else
452 {
453 header( "Location: ".$this->Security->get_srv( 'HTTP_REFERER' , 'raw' ) );
454 }
455 exit( 0 );
456 }
457 }
458 catch( Exception $e )
459 {
460 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
461 }
462 }
463
494 function run_execution( $Options , $Provider , $AutoRedirect = 0 )
495 {
496 try
497 {
498 $GUI = get_package( 'gui' , 'last' , __FILE__ );
499
500 if( $this->Context->execute( $Options , $Provider ) )
501 {
502 $this->set_locations( $Options , $AutoRedirect );
503
504 $GUI->set_var( 'last_context_set_execution_code' , 0 );
505 $GUI->set_var(
506 'last_context_set_execution_message' , $this->Messages->get_last_success_message()
507 );
508
509 return( true );
510 }
511
512 $GUI->set_var( 'last_context_set_execution_code' , 1 );
513 $GUI->set_var(
514 'last_context_set_execution_message' , $this->Messages->get_last_error_message()
515 );
516
517 return( false );
518 }
519 catch( Exception $e )
520 {
521 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
522 }
523 }
524
551 private function load_custom_settings( $ContextPath , &$Options )
552 {
553 try
554 {
555 $Config = $this->CachedMultyFS->file_get_contents( $ContextPath );
556 $Config = str_replace( '{prefix}' , $this->Prefix , $Config );
557 $this->CustomSettings->load_settings( $Config );
558 $this->CustomSettings->add_settings_from_object( $Options );
559 return( $Config );
560 }
561 catch( Exception $e )
562 {
563 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
564 }
565 }
566
585 function run_custom_states( &$Options )
586 {
587 try
588 {
589 $this->Trace->start_group( "custom_configs_processing" , COMMON );
590
591 foreach( $this->Contexts as $i => $ContextPath )
592 {
593 $this->Trace->add_trace_string( "Processing context $ContextPath" , COMMON );
594
595 $Config = $this->load_custom_settings( $ContextPath , $Options );
596
597 $Result = $this->CustomStateStartup->run_config_processors(
598 $this , $Config , $this->CustomSettings , $Options
599 );
600 if( $Result )
601 {
602 break;
603 }
604 }
605
606 $this->Trace->end_group();
607 }
608 catch( Exception $e )
609 {
610 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
611 }
612 }
613
632 private function load_context_set_data( &$ContextSetSettings )
633 {
634 try
635 {
636 $this->Prefix = $ContextSetSettings->get_setting( 'prefix' , '' );
637 $this->Prefix = str_replace(
638 '{functionality}' , $ContextSetSettings->get_setting( 'functionality' , '' ) ,
639 $this->Prefix
640 );
641 $this->Prefix = str_replace(
642 '{entity}' , $ContextSetSettings->get_setting( 'entity' , '' ) , $this->Prefix
643 );
644 }
645 catch( Exception $e )
646 {
647 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
648 }
649 }
650
677 private function execute_do( &$Options , $Provider , $FilePath )
678 {
679 try
680 {
681 $this->ContextSetConfigs->load_context_set_config( $this->ContextSetSettings , $Options , $FilePath );
682 $this->load_context_set_data( $this->ContextSetSettings );
683
684 if( $this->CommonStateStartup->run_common_states( $this , $Options ) === false )
685 {
686 $this->run_custom_states( $Options );
687 }
688
689 if( $this->Provider->Output !== false && $this->Provider->Output !== '' )
690 {
691 $this->Provider->Output = $this->ContextSetMarkup->compile_view(
692 $Options , $this->ContextSetSettings , $this->Provider->Output
693 );
694 }
695 }
696 catch( Exception $e )
697 {
698 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
699 }
700 }
701
728 function execute( &$Options , $Provider , $FilePath )
729 {
730 try
731 {
732 $this->Trace->start_group( "ContextSet::execute for class \"".get_class( $Provider )."\"" );
733 $this->Trace->add_trace_string( serialize( $Options->get_raw_settings() ) , COMMON );
734
735 $Options->set_setting( 'file_path' , $FilePath );
736 $this->Provider = $Provider;
737 $this->Provider->Output = false;
738
739 $this->execute_do( $Options , $Provider , $FilePath );
740
741 $this->Trace->end_group();
742 }
743 catch( Exception $e )
744 {
745 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
746 }
747 }
748
779 function compile_special_macro( &$Options , $Str , &$Changed )
780 {
781 try
782 {
783 list( $Str , $Changed ) = $this->ContextSetMarkup->compile_options( $Options , $Str , $Changed );
784
785 $Str = str_replace( '{prefix}' , $this->Prefix , $Str );
786
787 return( $Str );
788 }
789 catch( Exception $e )
790 {
791 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
792 }
793 }
794
813 function __toString()
814 {
815 try
816 {
817 return( serialize( $this->Config ) );
818 }
819 catch( Exception $e )
820 {
821 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
822 }
823 }
824 }
825 ?>