ultimix
custom_validations.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 $UserAlgorithms = false;
41 
56  function __construct()
57  {
58  try
59  {
60  $this->Messages = get_package( 'page::messages' , 'last' , __FILE__ );
61  $this->Security = get_package( 'security' , 'last' , __FILE__ );
62  $this->UserAlgorithms = get_package( 'user::user_algorithms' , 'last' , __FILE__ );
63  }
64  catch( Exception $e )
65  {
66  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
67  }
68  }
69 
93  {
94  try
95  {
96  $Result = $this->UserAlgorithms->user_exists( $this->Security->get_gp( $Pair[ 1 ] , 'string' ) );
97 
98  if( $Result === false )
99  {
100  $this->Messages->add_error_message( 'user_does_not_exist' );
101  }
102 
103  return( $Result );
104  }
105  catch( Exception $e )
106  {
107  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
108  }
109  }
110 
134  {
135  try
136  {
137  $Result = $this->UserAlgorithms->user_exists( $this->Security->get_gp( $Pair[ 1 ] , 'string' ) );
138 
139  if( $Result !== false )
140  {
141  $this->Messages->add_error_message( 'user_already_exists' );
142  }
143 
144  return( $Result );
145  }
146  catch( Exception $e )
147  {
148  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
149  }
150  }
151 
175  {
176  try
177  {
178  $PageAccess = get_package( 'page::page_access' , 'last' , __FILE__ );
179 
180  if( $PageAccess->get_page_description( $this->Security->get_gp( $Pair[ 1 ] , 'string' ) ) !== false )
181  {
182  return( true );
183  }
184 
185  return( false );
186  }
187  catch( Exception $e )
188  {
189  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
190  }
191  }
192 
216  {
217  try
218  {
219  $PageAccess = get_package( 'page::page_access' , 'last' , __FILE__ );
220 
221  if( $PageAccess->get_page_description( $this->Security->get_gp( $Pair[ 1 ] , 'string' ) ) === false )
222  {
223  return( false );
224  }
225 
226  return( true );
227  }
228  catch( Exception $e )
229  {
230  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
231  }
232  }
233 
256  function custom_validation_captcha( $Pair )
257  {
258  try
259  {
260  $Security = get_package( 'security' , 'last' , __FILE__ );
261  $Captcha = get_package( 'captcha' , 'last' , __FILE__ );
262 
263  $Result = $Captcha->validate_captcha( $Security->get_p( 'captcha' , 'command' , rand() ) , $Options );
264 
265  if( $Result === false )
266  {
267  $this->Messages->add_error_message( 'captcha_error' );
268  }
269 
270  return( $Result );
271  }
272  catch( Exception $e )
273  {
274  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
275  }
276  }
277 
300  private function validations( $Pair )
301  {
302  try
303  {
304  switch( $Pair[ 0 ] )
305  {
306  case( 'login_exists' ):return( $this->custom_validation_login_exists( $Pair ) );
307  case( 'login_does_not_exist' ):return( $this->custom_validation_login_does_not_exist( $Pair ) );
308  case( 'page_exists' ):return( $this->custom_validation_page_exists( $Pair ) );
309  case( 'page_does_not_exist' ):return( $this->custom_validation_page_does_not_exist( $Pair ) );
310  case( 'captcha' ):return( $this->custom_validation_captcha( $Pair ) );
311 
312  default:throw( new Exception( 'Undefined predicate '.$Pair[ 0 ] ) );
313  }
314  }
315  catch( Exception $e )
316  {
317  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
318  }
319  }
320 
347  function custom_validation( $ValidationScript , $Options )
348  {
349  try
350  {
351  $ValidationScript = explode( ";" , $ValidationScript );
352 
353  foreach( $ValidationScript as $vs )
354  {
355  $Pair = explode( ':' , $vs );
356 
357  if( $this->validations( $Pair ) === false )
358  {
359  return( false );
360  }
361  }
362 
363  return( true );
364  }
365  catch( Exception $e )
366  {
367  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
368  }
369  }
370  }
371 
372 ?>