ultimix

- Main Page
- Data Structures
- Files
- Examples

- File List
- Globals

dialog_markup.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 dialog_markup_1_0_0{
27
38 var $CachedMultyFS = false;
39 var $PageJS = false;
40 var $String = false;
41 var $Utilities = false;
42
53 var $Dialogs = array();
54
69 function __construct()
70 {
71 try
72 {
73 $this->CachedMultyFS = get_package( 'cached_multy_fs' , 'last' , __FILE__ );
74 $this->PageJS = get_package( 'page::page_js' , 'last' , __FILE__ );
75 $this->String = get_package( 'string' , 'last' , __FILE__ );
76 $this->Utilities = get_package( 'utilities' , 'last' , __FILE__ );
77 }
78 catch( Exception $e )
79 {
80 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
81 }
82 }
83
106 private function get_dialog_parameters( &$Settings )
107 {
108 try
109 {
110 $id = md5( $Settings->get_setting( 'package_name' ).microtime( true ) );
111 $DataSource = $Settings->get_setting( 'data_source' , $id );
112 $Name = $Settings->get_setting( 'name' , $DataSource );
113
114 return( array( $id , $DataSource , $Name ) );
115 }
116 catch( Exception $e )
117 {
118 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
119 }
120 }
121
144 private function select_dialog_content( &$Settings )
145 {
146 try
147 {
148 list( $id , $DataSource , $Name ) = $this->get_dialog_parameters( $Settings );
149
150 $Checked = 'checked';
151 $Code = '';
152 $Records = $this->Utilities->get_records( $Settings );
153 foreach( $Records as $k => $v )
154 {
155 $PlaceHolders = array( '{checked}' , '{id}' , '{value}' , '{title}' );
156 $id = $DataSource.get_field( $v , 'id' );
157 $Data = array( $Checked , $id , get_field( $v , 'id' ) , get_field( $v , 'title' ) );
158 $Code = $this->CachedMultyFS->get_template( __FILE__ , 'select_dialog_item.tpl' );
159 $Code = str_replace( $PlaceHolders , $Data , $Code );
160 $Checked = '';
161 }
162
163 return( $Code );
164 }
165 catch( Exception $e )
166 {
167 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
168 }
169 }
170
189 function pre_generation( &$Options )
190 {
191 try
192 {
193 $Path = '{http_host}/'._get_package_relative_path_ex( 'jquery::dialog_markup' , 'last' );
194
195 $this->PageJS->add_javascript( "$Path/include/js/iframe.dialog.js" );
196 $this->PageJS->add_javascript( "$Path/include/js/jquery.dialog.js" );
197 }
198 catch( Exception $e )
199 {
200 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
201 }
202 }
203
226 function compile_select_dialog_content( &$Settings )
227 {
228 try
229 {
230 $id = $Settings->get_setting( 'id' , md5( microtime( true ) ) );
231
232 $Type = $Settings->get_setting( 'type' , 'simple' );
233 $Script = $Type == 'simple' ?
234 $this->CachedMultyFS->get_template( __FILE__ , 'simple_select_dialog.tpl' ) : '';
235
236 $Script = str_replace( '{id}' , $id , $Script );
237 $SimpleRecords = $this->select_dialog_content( $ettings );
238 $Script = str_replace( '{records}' , $SimpleRecords , $Script );
239
240 return( $Script );
241 }
242 catch( Exception $e )
243 {
244 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
245 }
246 }
247
270 function compile_select_dialog( &$Settings )
271 {
272 try
273 {
274 $DataSource = $Settings->get_setting( 'data_source' , md5( rand().microtime( true ) ) );
275 $Settings->set_setting( 'data_source' , $DataSource );
276
277 $id = $Settings->get_setting( 'id' , md5( microtime( true ) ) );
278 $Settings->set_setting( 'id' , $id );
279
280 $Code = '{select_dialog_content:'.$Settings->get_all_settings().
281 '}{dialog:selector=#'.$id.';'.$Settings->get_all_settings().
282 ';cancel=true;ok_processor=ultimix.ExtractSimpleSelectResult}';
283
284 return( $Code );
285 }
286 catch( Exception $e )
287 {
288 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
289 }
290 }
291
314 function compile_view_dialog( &$Settings )
315 {
316 try
317 {
318 $id = $Settings->get_setting( 'id' , md5( microtime( true ) ) );
319
320 $Code = '';
321 if( isset( $this->Dialogs[ $id ] ) === false )
322 {
323 $Code = $this->CachedMultyFS->get_template( __FILE__ , 'view_dialog.tpl' );
324 $Code = str_replace( '{id}' , $id , $Code );
325 $Code = str_replace( '{all_settings}' , $Settings->get_all_settings() , $Code );
326 $this->Dialogs[ $id ] = true;
327 }
328
329 return( $Code );
330 }
331 catch( Exception $e )
332 {
333 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
334 }
335 }
336
359 function compile_static_dialog( &$BlockSettings )
360 {
361 try
362 {
363 $id = $BlockSettings->get_setting( 'id' , md5( microtime( true ) ) );
364 $Script = $this->CachedMultyFS->get_template( __FILE__ , 'static_dialog.tpl' );
365 $Script = str_replace( '{id}' , $id , $Script );
366 $Script = str_replace( '{all_settings}' , $BlockSettings->get_all_settings() , $Script );
367
368 return( $Script );
369 }
370 catch( Exception $e )
371 {
372 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
373 }
374 }
375
398 function compile_iframe_dialog( &$Settings )
399 {
400 try
401 {
402 $id = $Settings->get_setting( 'id' , md5( microtime( true ) ) );
403 $Code = $this->CachedMultyFS->get_template( __FILE__ , 'iframe_dialog.tpl' );
404
405 $PlaceHolders = array( '{id}' , '{href}' , '{all_settings}' );
406 $Data = array( $id , $Settings->get_setting( 'href' ) , $Settings->get_all_settings() );
407 $Code = str_replace( $PlaceHolders , $Data , $Code );
408
409 return( $Code );
410 }
411 catch( Exception $e )
412 {
413 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
414 }
415 }
416
439 function compile_opener( &$Settings )
440 {
441 try
442 {
443 list( $Selector , $Opener )= $Settings->get_settings( 'selector,opener' );
444 $DataSource = $Settings->get_setting( 'data_source' , $Selector );
445 $DataAcceptor = $Settings->get_setting( 'data_acceptor' , '' );
446 $StatusAcceptor = $Settings->get_setting( 'status_acceptor' , '' );
447 $Validation = $Settings->get_setting( 'before_open_validation' , 'nop' );
448
449 return(
450 "{add_opener:data_source=$DataSource;data_acceptor=$DataAcceptor;status_acceptor=$StatusAcceptor;".
451 "before_open_validation=$Validation;opener=$Opener;selector=$Selector}"
452 );
453 }
454 catch( Exception $e )
455 {
456 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
457 }
458 }
459
486 private function append_add_opener_if_necessary( $Code , &$BlockSettings )
487 {
488 try
489 {
490 if( $BlockSettings->get_setting( 'opener' , '' ) != '' )
491 {
492 $Code .= $this->compile_opener( $BlockSettings );
493 }
494
495 return( $Code );
496 }
497 catch( Exception $e )
498 {
499 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
500 }
501 }
502
521 private function prepare_basic_settings( &$BlockSettings )
522 {
523 try
524 {
525 $BlockSettings->set_undefined( 'title' , '' );
526 $BlockSettings->set_undefined( 'width' , '480' );
527 $BlockSettings->set_undefined( 'height' , '320' );
528 $BlockSettings->set_undefined( 'modal' , 'true' );
529 $BlockSettings->set_undefined( 'auto_open' , 'false' );
530 $BlockSettings->set_undefined( 'close_on_escape' , 'true' );
531 $BlockSettings->set_undefined( 'resizable' , 'true' );
532 }
533 catch( Exception $e )
534 {
535 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
536 }
537 }
538
557 function prepare_data_for_dialog( &$BlockSettings )
558 {
559 try
560 {
561 $BlockSettings->get_setting( 'selector' );
562
563 $this->prepare_basic_settings( $BlockSettings );
564
565 $BlockSettings->set_undefined( 'hide_close_button' , 'false' );
566 $BlockSettings->set_undefined( 'ok_processor' , '' );
567 $BlockSettings->set_undefined( 'cancel' , 'false' );
568 $BlockSettings->set_undefined( 'on_open' , 'nop()' );
569 }
570 catch( Exception $e )
571 {
572 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
573 }
574 }
575
598 function compile_dialog( &$BlockSettings )
599 {
600 try
601 {
602 $this->prepare_data_for_dialog( $BlockSettings );
603
604 $Code = $this->CachedMultyFS->get_template( __FILE__ , 'dialog_init.tpl' );
605
606 $Data = $BlockSettings->get_raw_settings();
607
608 $Code = $this->String->print_record( $Code , $Data );
609
610 $Code = $this->append_add_opener_if_necessary( $Code , $BlockSettings );
611
612 return( $Code );
613 }
614 catch( Exception $e )
615 {
616 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
617 }
618 }
619
638 private function prepare_data_for_opener( &$BlockSettings )
639 {
640 try
641 {
642 $BlockSettings->get_setting( 'selector' );
643 $BlockSettings->get_setting( 'opener' );
644
645 $BlockSettings->set_undefined( 'before_open_validation' , 'nop' );
646 $BlockSettings->set_undefined( 'data_source' , '' );
647 $BlockSettings->set_undefined( 'data_acceptor' , '' );
648 $BlockSettings->set_undefined( 'status_acceptor' , '' );
649 }
650 catch( Exception $e )
651 {
652 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
653 }
654 }
655
678 function compile_add_opener( &$BlockSettings )
679 {
680 try
681 {
682 $this->prepare_data_for_opener( $BlockSettings );
683
684 $AddOpenerScript = $this->CachedMultyFS->get_template( __FILE__ , 'add_opener.tpl' );
685 $Data = $BlockSettings->get_raw_settings();
686 $AddOpenerScript = $this->String->print_record( $AddOpenerScript , $Data );
687
688 return( $AddOpenerScript );
689 }
690 catch( Exception $e )
691 {
692 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
693 }
694 }
695 }
696
697 ?>