ultimix
common_buttons.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 
27 
38  var $CachedMultyFS = false;
39  var $ContextSetConfigs = false;
40  var $PermitAlgorithms = false;
41  var $Settings = false;
42  var $Trace = false;
43 
54  var $Version = 1;
55 
70  function __construct()
71  {
72  try
73  {
74  $this->CachedMultyFS = get_package( 'cached_multy_fs' , 'last' , __FILE__ );
75  $PackageName = 'gui::context_set::context_set_configs';
76  $this->ContextSetConfigs = get_package( $PackageName , 'last' , __FILE__ );
77  $this->PermitAlgorithms = get_package( 'permit::permit_algorithms' , 'last' , __FILE__ );
78  $this->Settings = get_package_object( 'settings::settings' , 'last' , __FILE__ );
79  $this->String = get_package( 'string' , 'last' , __FILE__ );
80  $this->Trace = get_package( 'trace' , 'last' , __FILE__ );
81  }
82  catch( Exception $e )
83  {
84  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
85  }
86  }
87 
118  function get_common_button_content( &$CommonStateConfig , &$ExtOptions , $Name )
119  {
120  try
121  {
122  $PermitsFilter = $CommonStateConfig->get_setting( 'permits_filter' , 'admin' );
123  $ValidatingPermits = $CommonStateConfig->get_setting( 'permits_validation' , $PermitsFilter );
124 
125  $PermitValidationResult = $this->PermitAlgorithms->object_has_all_permits(
126  false , 'user' , $ValidatingPermits
127  );
128 
129  if( $PermitValidationResult )
130  {
131  $Path = _get_package_relative_path_ex( 'gui::context_set::common_buttons' , 'last' );
132 
133  $ButtonCode = $this->CachedMultyFS->get_template( __FILE__ , 'toolbar_'.$Name.'_button.tpl' );
134 
135  return( $ButtonCode );
136  }
137 
138  return( '' );
139  }
140  catch( Exception $e )
141  {
142  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
143  }
144  }
145 
176  function get_config( &$ContextSetConfig , &$Options , $Name )
177  {
178  try
179  {
180  $Config = $this->ContextSetConfigs->load_common_state_config(
181  $ContextSetConfig , 'common_state_config_'.$Name , 'cfcxs_'.$Name ,
182  $Options->get_setting( 'file_path' )
183  );
184 
185  return( $Config );
186  }
187  catch( Exception $e )
188  {
189  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
190  }
191  }
192 
223  function compile_search_button( &$ContextSetConfig , &$Options , $Code )
224  {
225  try
226  {
227  if( strpos( $Code , chr( 123 ).'search_button' ) === false )
228  {
229  return( $Code );
230  }
231 
232  $Config = $this->get_config( $ContextSetConfig , $Options , 'search_form' );
233 
234  $ExtOptions = false;
235 
236  $Code = str_replace(
237  '{search_button}' ,
238  $this->get_common_button_content( $Config , $ExtOptions , 'search' ) , $Code
239  );
240 
241  return( $Code );
242  }
243  catch( Exception $e )
244  {
245  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
246  }
247  }
248 
279  private function compile_button( &$Config , $Code , $ButtonName )
280  {
281  try
282  {
283  if( strpos( $Code , '{'.$ButtonName.'_button}' ) !== false )
284  {
285  $Code = str_replace( '{'.$ButtonName.'_button}' , '{'.$ButtonName.'_button:p=1}' , $Code );
286  }
287 
288  for( ; $Params = $this->String->get_macro_parameters( $Code , $ButtonName.'_button' ) ; )
289  {
290  $this->Settings->load_settings( $Params );
291 
292  $ButtonCode = $this->get_common_button_content( $Config , $this->Settings , $ButtonName );
293 
294  $Code = str_replace( '{'.$ButtonName."_button:$Params}" , $ButtonCode , $Code );
295  }
296 
297  return( $Code );
298  }
299  catch( Exception $e )
300  {
301  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
302  }
303  }
304 
335  function compile_create_button( &$ContextSetConfig , &$Options , $Code )
336  {
337  try
338  {
339  if( strpos( $Code , chr( 123 ).'create_button' ) === false )
340  {
341  return( $Code );
342  }
343 
344  $Config = $this->get_config( $ContextSetConfig , $Options , 'create_form' );
345 
346  return( $this->compile_button( $Config , $Code , 'create' ) );
347  }
348  catch( Exception $e )
349  {
350  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
351  }
352  }
353 
384  function compile_update_button( &$ContextSetConfig , &$Options , $Code )
385  {
386  try
387  {
388  if( strpos( $Code , chr( 123 ).'update_button' ) === false )
389  {
390  return( $Code );
391  }
392 
393  $Config = $this->get_config( $ContextSetConfig , $Options , 'update_form' );
394 
395  return( $this->compile_button( $Config , $Code , 'update' ) );
396  }
397  catch( Exception $e )
398  {
399  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
400  }
401  }
402 
433  function compile_copy_button( &$ContextSetConfig , &$Options , $Code )
434  {
435  try
436  {
437  if( strpos( $Code , chr( 123 ).'copy_button' ) === false )
438  {
439  return( $Code );
440  }
441 
442  $Config = $this->get_config( $ContextSetConfig , $Options , 'copy_form' );
443 
444  return( $this->compile_button( $Config , $Code , 'copy' ) );
445  }
446  catch( Exception $e )
447  {
448  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
449  }
450  }
451 
482  function compile_delete_button( &$ContextSetConfig , &$Options , $Code )
483  {
484  try
485  {
486  if( strpos( $Code , chr( 123 ).'delete_button' ) === false )
487  {
488  return( $Code );
489  }
490 
491  $Config = $this->get_config( $ContextSetConfig , $Options , 'delete_button' );
492 
493  return( $this->compile_button( $Config , $Code , 'delete' ) );
494  }
495  catch( Exception $e )
496  {
497  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
498  }
499  }
500 
531  function compile_buttons( &$ContextSetConfig , &$Options , $Str )
532  {
533  try
534  {
535  $this->Trace->start_group( 'compile_buttons' );
536 
537  $Str = $this->compile_search_button( $ContextSetConfig , $Options , $Str );
538 
539  $Str = $this->compile_create_button( $ContextSetConfig , $Options , $Str );
540 
541  $Str = $this->compile_update_button( $ContextSetConfig , $Options , $Str );
542 
543  $Str = $this->compile_copy_button( $ContextSetConfig , $Options , $Str );
544 
545  $Str = $this->compile_delete_button( $ContextSetConfig , $Options , $Str );
546 
547  $this->Trace->end_group();
548 
549  $Str = str_replace( '{prefix}' , $ContextSetConfig->get_setting( 'prefix' , '' ) , $Str );
550 
551  return( $Str );
552  }
553  catch( Exception $e )
554  {
555  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
556  }
557  }
558  }
559 
560 ?>