ultimix

- Main Page
- Data Structures
- Files
- Examples

- File List
- Globals

settings_view.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 settings_view_1_0_0{
27
38 var $CachedMultyFS = false;
39 var $DBSettings = false;
40 var $PackageSettings = false;
41 var $PageComposerUtilities = false;
42 var $Security = false;
43 var $Settings = false;
44 var $String = false;
45
56 var $Output = false;
57
68 function __construct()
69 {
70 try
71 {
72 $this->CachedMultyFS = get_package( 'cached_multy_fs' , 'last' , __FILE__ );
73 $this->DBSettings = get_package( 'settings::db_settings' , 'last' , __FILE__ );
74 $this->PackageSettings = get_package( 'settings::package_settings' , 'last' , __FILE__ );
75 $this->PageComposerUtilities = get_package( 'page::page_composer_utilities' , 'last' , __FILE__ );
76 $this->Security = get_package( 'security' , 'last' , __FILE__ );
77 $this->Settings = get_package_object( 'settings::settings' , 'last' , __FILE__ );
78 $this->String = get_package( 'string' , 'last' , __FILE__ );
79 }
80 catch( Exception $e )
81 {
82 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
83 }
84 }
85
108 function get_db_setting( &$Manifest )
109 {
110 try
111 {
112 $SettingName = $Manifest->get_setting( 'setting_name' );
113 $DefaultValue = $Manifest->get_setting( 'default_value' , '' );
114
115 $SettingValue = $this->DBSettings->get_setting( $SettingName , $DefaultValue );
116
117 $SettingValue = $this->Security->get( $SettingValue , 'script' );
118
119 return( array( $SettingName , $SettingValue , $Manifest->get_setting( 'label' ) ) );
120 }
121 catch( Exception $e )
122 {
123 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
124 }
125 }
126
149 function get_package_setting( &$Manifest )
150 {
151 try
152 {
153 $PackageName = $Manifest->get_setting( 'package_name' );
154 $PackageVersion = $Manifest->get_setting( 'package_version' , 'last' );
155 list( $ConfigFileName , $SettingName ) = $Manifest->get_settings( 'config_file_name,setting_name' );
156 $DefaultValue = $Manifest->get_setting( 'default_value' , '' );
157
158 $SettingValue = $this->PackageSettings->get_package_setting(
159 $PackageName , $PackageVersion , $ConfigFileName , $SettingName , $DefaultValue
160 );
161
162 $SettingValue = $this->Security->get( $SettingValue , 'script' );
163
164 return( array( $SettingName , $SettingValue , $Manifest->get_setting( 'label' ) ) );
165 }
166 catch( Exception $e )
167 {
168 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
169 }
170 }
171
194 function get_setting( &$Manifest )
195 {
196 try
197 {
198 $PackageName = $Manifest->get_setting( 'package_name' , false );
199
200 if( $PackageName === false )
201 {
202 return( $this->get_db_setting( $Manifest ) );
203 }
204 else
205 {
206 return( $this->get_package_setting( $Manifest ) );
207 }
208 }
209 catch( Exception $e )
210 {
211 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
212 }
213 }
214
245 function compile_input_setting( $SettingName , $SettingValue , $Label )
246 {
247 try
248 {
249 $Template = $this->CachedMultyFS->get_template( __FILE__ , 'input_setting.tpl' );
250
251 $PlaceHolders = array( '{name}' , '{value}' , '{label}' );
252 $Data = array( $SettingName , $SettingValue , $Label );
253
254 $Template = str_replace( $PlaceHolders , $Data , $Template );
255
256 return( $Template );
257 }
258 catch( Exception $e )
259 {
260 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
261 }
262 }
263
294 function compile_checkbox_setting( $SettingName , $SettingValue , $Label )
295 {
296 try
297 {
298 $Template = $this->CachedMultyFS->get_template( __FILE__ , 'checkbox_setting.tpl' );
299
300 $PlaceHolders = array( '{name}' , '{value}' , '{label}' );
301 $Data = array( $SettingName , intval( $SettingValue ) ? 'checked' : '' , $Label );
302
303 $Template = str_replace( $PlaceHolders , $Data , $Template );
304
305 return( $Template );
306 }
307 catch( Exception $e )
308 {
309 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
310 }
311 }
312
343 function compile_textarea_setting( $SettingName , $SettingValue , $Label )
344 {
345 try
346 {
347 $Template = $this->CachedMultyFS->get_template( __FILE__ , 'textarea_setting.tpl' );
348
349 $PlaceHolders = array( '{name}' , '{value}' , '{label}' );
350 $Data = array( $SettingName , $SettingValue , $Label );
351
352 $Template = str_replace( $PlaceHolders , $Data , $Template );
353
354 return( $Template );
355 }
356 catch( Exception $e )
357 {
358 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
359 }
360 }
361
392 private function compile_controllers( $SettingName , $SettingValue , $Label )
393 {
394 try
395 {
396 switch( $this->Settings->get_setting( 'type' , 'input' ) )
397 {
398 case( 'input' ):
399 return( $this->compile_input_setting( $SettingName , $SettingValue , $Label ) );
400 case( 'checkbox' ):
401 return( $this->compile_checkbox_setting( $SettingName , $SettingValue , $Label ) );
402 case( 'textarea' ):
403 return( $this->compile_textarea_setting( $SettingName , $SettingValue , $Label ) );
404 default:
405 $this->PageComposerUtilities->add_error_message( 'illegal_setting_type' );
406 return( '' );
407 }
408 }
409 catch( Exception $e )
410 {
411 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
412 }
413 }
414
437 function compile_config_line( $ConfigLine )
438 {
439 try
440 {
441 $this->Settings->load_settings( $ConfigLine );
442
443 list( $SettingName , $SettingValue , $Label ) = $this->get_setting( $this->Settings );
444
445 return( $this->compile_controllers( $SettingName , $SettingValue , $Label ) );
446 }
447 catch( Exception $e )
448 {
449 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
450 }
451 }
452
475 private function compile_settings_form( $FormName , $ConfigPath )
476 {
477 try
478 {
479 $this->Output = $this->CachedMultyFS->get_template( __FILE__ , 'settings_form_header.tpl' );
480 $this->Output = str_replace( '{name}' , $FormName , $this->Output );
481
482 $Config = $this->CachedMultyFS->file_get_contents( $ConfigPath , 'exploded' );
483 foreach( $Config as $i => $ConfigLine )
484 {
485 $this->Output .= $this->compile_config_line( $ConfigLine );
486 }
487
488 $this->Output .= $this->CachedMultyFS->get_template( __FILE__ , 'settings_form_footer.tpl' );
489 }
490 catch( Exception $e )
491 {
492 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
493 }
494 }
495
514 function settings_form( $Options )
515 {
516 try
517 {
518 $FormName = $Options->get_setting( 'form_name' );
519
520 $ConfigPath = dirname( __FILE__ )."/conf/cf_$FormName";
521 if( $this->CachedMultyFS->file_exists( $ConfigPath ) )
522 {
523 $this->compile_settings_form( $FormName , $ConfigPath );
524 }
525 else
526 {
527 $this->Output = '{lang:tab_manifest_was_not_found}';
528 }
529 }
530 catch( Exception $e )
531 {
532 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
533 }
534 }
535
558 function view( $Options )
559 {
560 try
561 {
562 $ContextSet = get_package( 'gui::context_set' , 'last' , __FILE__ );
563
564 $ContextSet->add_context( dirname( __FILE__ ).'/conf/cfcx_settings_form' );
565
566 if( $ContextSet->execute( $Options , $this ) )return( $this->Output );
567
568 return( '' );
569 }
570 catch( Exception $e )
571 {
572 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
573 }
574 }
575
598 function compile_settings( &$Settings )
599 {
600 try
601 {
602 return(
603 $this->PackageSettings->get_package_setting(
604 $Settings->get_setting( 'package_name' ) ,
605 $Settings->get_setting( 'package_version' , 'last' ) ,
606 $Settings->get_setting( 'config_file_name' ) ,
607 $Settings->get_setting( 'name' ) , $Settings->get_setting( 'default' , '' )
608 )
609 );
610 }
611 catch( Exception $e )
612 {
613 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
614 }
615 }
616
639 function compile_db_settings( &$Settings )
640 {
641 try
642 {
643 $SettingName = $Settings->get_setting( 'name' );
644 $DefaultValue = $Settings->get_setting( 'default' , '' );
645
646 return( $this->DBSettings->get_setting( $SettingName , $DefaultValue ) );
647 }
648 catch( Exception $e )
649 {
650 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
651 }
652 }
653 }
654
655 ?>