ultimix
context_utilities.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 $Messages = false;
39  var $Security = false;
40  var $SecurityValidator = false;
41  var $Trace = false;
42 
57  function __construct()
58  {
59  try
60  {
61  $this->Messages = get_package( 'page::messages' , 'last' , __FILE__ );
62  $this->Security = get_package( 'security' , 'last' , __FILE__ );
63  $this->SecurityValidator = get_package( 'security::security_validator' , 'last' , __FILE__ );
64  $this->Trace = get_package( 'trace' , 'last' , __FILE__ );
65  }
66  catch( Exception $e )
67  {
68  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
69  }
70  }
71 
90  function compile_no_permits( $Validation )
91  {
92  try
93  {
94  $this->Messages->add_error_message( 'no_permits' );
95  $this->Trace->add_trace_string(
96  "{lang:permits_validation_not_passed} : $Validation" , COMMON
97  );
98  $this->Trace->add_trace_string( "GET : ".wordwrap( serialize( $_GET ) ) , COMMON );
99  $this->Trace->add_trace_string( "POST : ".wordwrap( serialize( $_POST ) ) , COMMON );
100  }
101  catch( Exception $e )
102  {
103  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
104  }
105  }
106 
129  function get_section( &$Config , $SectionName , $Default = '_throw_exception' )
130  {
131  try
132  {
133  if( isset( $Config[ $SectionName ] ) )
134  {
135  return( $Config[ $SectionName ] );
136  }
137  else
138  {
139  if( $Default == '_throw_exception' )
140  {
141  throw(
142  new Exception(
143  "Section \"$SectionName\" was not found in config ".wordwrap( serialize( $Config ) )
144  )
145  );
146  }
147  return( $Default );
148  }
149  }
150  catch( Exception $e )
151  {
152  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
153  }
154  }
155 
182  function section_exists( &$Config , $SectionName )
183  {
184  try
185  {
186  if( $Config === false )
187  {
188  throw( new Exception( 'Config was not set' ) );
189  }
190 
191  if( isset( $Config[ $SectionName ] ) )
192  {
193  $this->Trace->add_trace_string( "{lang:section_was_found} : $SectionName" , COMMON );
194  }
195  else
196  {
197  $this->Trace->add_trace_string( "{lang:section_was_not_found} : $SectionName" , COMMON );
198  }
199 
200  return( isset( $Config[ $SectionName ] ) );
201  }
202  catch( Exception $e )
203  {
204  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
205  }
206  }
207 
222  private function compile_global_success_message()
223  {
224  try
225  {
226  if( $this->section_exists( $this->Config , 'global_success_message' ) )
227  {
228  $SuccessMessage = $this->get_section( $this->Config , 'global_success_message' );
229 
230  if( $this->Security->get_s( 'direct_controller' , 'integer' , 0 ) == 0 )
231  {
232  $this->Security->reset_s( 'success_message' , $SuccessMessage );
233  }
234  $this->Messages->add_success_message( $SuccessMessage );
235  }
236  }
237  catch( Exception $e )
238  {
239  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
240  }
241  }
242 
265  private function get_success_message( &$Options )
266  {
267  try
268  {
269  $SuccessMessage = false;
270 
271  if( $Options->get_setting( 'success_message' , false ) !== false )
272  {
273  $SuccessMessage = $Options->get_setting( 'success_message' );
274  }
275  elseif( $this->section_exists( $this->Config , 'success_message' ) )
276  {
277  $SuccessMessage = $this->get_section( $this->Config , 'success_message' );
278  }
279 
280  return( $SuccessMessage );
281  }
282  catch( Exception $e )
283  {
284  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
285  }
286  }
287 
306  function compile_success_messages( &$Options )
307  {
308  try
309  {
310  $SuccessMessage = $this->get_success_message( $Options );
311 
312  if( $SuccessMessage !== false )
313  {
314  if( $this->Security->get_s( 'direct_controller' , 'integer' , 0 ) === 0 )
315  {
316  $PageName = $this->Security->get_gp( 'page_name' , 'command' );
317 
318  $this->Security->reset_s( "$PageName:success_message" , $SuccessMessage );
319  }
320 
321  $this->Messages->add_success_message( $SuccessMessage );
322  }
323 
324  $this->compile_global_success_message();
325  }
326  catch( Exception $e )
327  {
328  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
329  }
330  }
331 
350  private function print_get_post_filter_trace( $Filter )
351  {
352  try
353  {
354  $this->Trace->add_trace_string( "{lang:get_post_filter_not_passed} : $Filter" , COMMON );
355  $this->Trace->add_trace_string( "GET : ".wordwrap( serialize( $_GET ) ) , COMMON );
356  $this->Trace->add_trace_string( "POST : ".wordwrap( serialize( $_POST ) ) , COMMON );
357  }
358  catch( Exception $e )
359  {
360  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
361  }
362  }
363 
390  function compile_get_post_filter( &$Config , &$Options )
391  {
392  try
393  {
394  if( $this->section_exists( $Config , 'get_post_filter' ) == false )
395  {
396  return( true );
397  }
398 
399  $Filter = $this->get_section( $Config , 'get_post_filter' );
400 
401  $this->Trace->add_trace_string( "{lang:get_post_filter} : $Filter" , COMMON );
402 
403  if( $this->SecurityValidator->validate_fields( $Filter ) === false )
404  {
405  $this->print_get_post_filter_trace( $Filter );
406  return( false );
407  }
408  return( true );
409  }
410  catch( Exception $e )
411  {
412  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
413  }
414  }
415 
438  function compile_get_post_validation( &$Config , &$Options )
439  {
440  try
441  {
442  if( $this->section_exists( $Config , 'get_post_validation' ) )
443  {
444  $GetPostValidation = $this->get_section( $Config , 'get_post_validation' );
445 
446  return( $this->SecurityValidator->validate_fields( $GetPostValidation ) );
447  }
448 
449  return( true );
450  }
451  catch( Exception $e )
452  {
453  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
454  }
455  }
456 
475  function get_custom_validation_object( &$Config )
476  {
477  try
478  {
479  $Name = $this->get_section( $Config , 'custom_validation_package_name' , false );
480 
481  if( $Name !== false )
482  {
483  $Version = $this->get_section( $Config , 'custom_validation_package_version' , 'last' );
484 
485  $ValidationObject = get_package( $Name , $Version , __FILE__ );
486  }
487  else
488  {
489  $ValidationObject = $Owner;
490  }
491 
492  return( $ValidationObject );
493  }
494  catch( Exception $e )
495  {
496  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
497  }
498  }
499  }
500 
501 ?>