'alphanumeric' , // 'alpha' => 'alphabetic' , // 'cntrl' => 'control' , // 'digit' => 'numeric' , // 'graph' => 'non-blank, printable' , // 'lower' => 'lowercase' , // 'print' => 'printable' , // 'punct' => 'punctuation' , // 'space' => 'space' , // 'upper' => 'uppercase' , // 'xdigit' => 'hex digit' // // // "filter_var()" based... // 'boolean' // 'email' // 'ip' // 'url' // // // Great Kiwi based #1... // 'empty' - String is an empty string (no chars at all). // Eg: "" // '!empty' - String is an non-empty string (contains one or more // (possibly blank) chars. // Eg: " ", " ", "abc", " the quick brown fox " // 'blank' - String contains one or more blank chars. // Eg: " " // '!blank' - String contains at least one non-blank char. // Eg: " hello " // // // Great Kiwi based #2... // ... // // --- // // RETURNS // On SUCCESS // TRUE or FALSE // // On FAILURE // $error_message STRING // ------------------------------------------------------------------------- // ========================================================================= // Init. // ========================================================================= $ns = __NAMESPACE__ ; $fn = __FUNCTION__ ; // ========================================================================= // Check the PHP TYPE CRITERIA... // ========================================================================= if ( is_string( $php_type_criteria ) ) { // --------------------------------------------------------------------- if ( $php_type_criteria !== '' ) { // ----------------------------------------------------------------- // Here we should have (eg):- // "int" value must be a PHP INT // "int|string" value must be either an INT or a STRING // ----------------------------------------------------------------- $is_xxx = array( 'array' , 'bool' , 'callable' , 'double' , 'float' , 'int' , 'integer' , 'long' , 'null' , 'numeric' , 'object' , 'real' , 'resource' , 'scalar' , 'string' ) ; // ----------------------------------------------------------------- $groups = explode( '|' , $php_type_criteria ) ; // ----------------------------------------------------------------- $value_matches_criteria = FALSE ; // ----------------------------------------------------------------- foreach ( $groups as $this_xxx ) { // ------------------------------------------------------------- if ( ! in_array( $this_xxx , $is_xxx , TRUE ) ) { $safe_xxx = htmlentities( $this_xxx ) ; return << 1 ) { // --------------------------------------------------------------------- if ( count( $groups ) > 2 ) { return << FILTER_VALIDATE_BOOLEAN , 'email' => FILTER_VALIDATE_EMAIL , 'ip' => FILTER_VALIDATE_IP , 'url' => FILTER_VALIDATE_URL ) ; // ------------------------------------------------------------------------- $groups = explode( '|' , $string_criteria ) ; // ------------------------------------------------------------------------- $regex = '/^(.)*\{(.)*\}$/' ; // ------------------------------------------------------------------------- $match_found = FALSE ; // ------------------------------------------------------------------------- foreach ( $groups as $this_xxx ) { // ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: // Allow the user to put some white space in the criteria string... // ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: $this_xxx = trim( $this_xxx ) ; //\greatKiwi_byFernTec_adSwapper_local_v0x1x210_testDebug\pr( $this_xxx ) ; // ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: // Analyse and strip the min/max string length thing (if there is // one)... // ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: $number_matches = preg_match( $regex , $this_xxx , $matches ) ; // preg_match() returns 1 if the pattern // matches given subject, 0 if it does not, or // FALSE if an error occurred. // --------------------------------------------------------------------- if ( $number_matches === FALSE ) { return << $max ) ) { continue ; } // ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: // Process the "xxx" proper... // ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: //\greatKiwi_byFernTec_adSwapper_local_v0x1x210_testDebug\pr( $this_xxx ) ; // ===================================================================== // ctype_xxx() based... // ===================================================================== if ( in_array( $this_xxx , $ctype_xxx , TRUE ) ) { // ----------------------------------------------------------------- if ( strlen( value ) < 1 ) { continue ; } // ----------------------------------------------------------------- $fn = '\ctype_' . $this_xxx ; // ----------------------------------------------------------------- if ( $fn( $value ) ) { $match_found = TRUE ; break ; } // ----------------------------------------------------------------- continue ; // ----------------------------------------------------------------- } // ===================================================================== // filter_var() based... // ===================================================================== // ------------------------------------------------------------------------- // mixed filter_var ( mixed $variable [, int $filter = FILTER_DEFAULT [, mixed $options ]] ) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // // variable // Value to filter. // // filter // The ID of the filter to apply. The Types of filters manual page // lists the available filters. // // If omitted, FILTER_DEFAULT will be used, which is equivalent to // FILTER_UNSAFE_RAW. This will result in no filtering taking place by // default. // // options // Associative array of options or bitwise disjunction of flags. If // filter accepts options, flags can be provided in "flags" field of // array. For the "callback" filter, callable type should be passed. // The callback must accept one argument, the value to be filtered, and // return the value after filtering/sanitizing it. // // RETURN VALUES // Returns the filtered data, or FALSE if the filter fails. // ------------------------------------------------------------------------- // ------------------------------------------------------------------------- // VALIDATE FILTERS // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // ID FILTER_VALIDATE_BOOLEAN // Name "boolean" // Options default // Flags FILTER_NULL_ON_FAILURE // Description // Returns TRUE for "1", "true", "on" and "yes". Returns FALSE // otherwise. // // If FILTER_NULL_ON_FAILURE is set, FALSE is returned only for "0", // "false", "off", "no", and "", and NULL is returned for all // non-boolean values. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // ID FILTER_VALIDATE_EMAIL // Name "validate_email" // Options default // Flags // Description // Validates value as e-mail. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // ID FILTER_VALIDATE_IP // Name "validate_ip" // Options default // Flags FILTER_FLAG_IPV4, // FILTER_FLAG_IPV6, // FILTER_FLAG_NO_PRIV_RANGE, // FILTER_FLAG_NO_RES_RANGE // Description // Validates value as IP address, optionally only IPv4 or IPv6 or not // from private or reserved ranges. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // ID FILTER_VALIDATE_REGEXP // Name "validate_regexp" // Options default, regexp // Flags // Description // Validates value against regexp, a Perl-compatible regular // expression. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // ID FILTER_VALIDATE_URL // Name "validate_url" // Options default // Flags FILTER_FLAG_PATH_REQUIRED, // FILTER_FLAG_QUERY_REQUIRED // Description // Validates value as URL (according to ยป // http://www.faqs.org/rfcs/rfc2396), optionally with required // components. Beware a valid URL may not specify the HTTP protocol // http:// so further validation may be required to determine the URL // uses an expected protocol, e.g. ssh:// or mailto:. Note that the // function will only find ASCII URLs to be valid; internationalized // domain names (containing non-ASCII characters) will fail. // ------------------------------------------------------------------------- if ( array_key_exists( $this_xxx , $filter_var_xxx ) ) { // ----------------------------------------------------------------- if ( strlen( $value ) < 1 && $this_xxx !== 'boolean' ) { continue ; } // ----------------------------------------------------------------- $result = \filter_var( $value , $filter_var_xxx[ $this_xxx ] ) ; //\greatKiwi_byFernTec_adSwapper_local_v0x1x210_testDebug\pr( $result ) ; // ----------------------------------------------------------------- if ( $result !== FALSE ) { $match_found = TRUE ; break ; } // ----------------------------------------------------------------- continue ; // ----------------------------------------------------------------- } // ===================================================================== // Great Kiwi based #1... // ===================================================================== // --------------------------------------------------------------------- // 'empty' - String is an empty string (no chars at all). // Eg: "" // // '!empty' - String is an non-empty string (contains one or more // (possibly blank) chars. // Eg: " ", " ", "abc", " the quick brown fox " // // 'blank' - String contains one or more blank chars. // Eg: " " // // '!blank' - String contains at least one non-blank char. // Eg: " hello " // --------------------------------------------------------------------- if ( $this_xxx === 'empty' ) { if ( $value === '' ) { $match_found = TRUE ; break ; } } elseif ( $this_xxx === '!empty' ) { if ( $value !== '' ) { $match_found = TRUE ; break ; } } elseif ( $this_xxx === 'blank' ) { if ( $value !== '' && trim( $value ) === '' ) { $match_found = TRUE ; break ; } } elseif ( $this_xxx === '!blank' ) { if ( trim( $value ) !== '' ) { $match_found = TRUE ; break ; } } // ===================================================================== // Great Kiwi based #2... // ===================================================================== // TODO!!! // ===================================================================== // Plugin Specific String Validators // ===================================================================== // ------------------------------------------------------------------------- // \greatKiwi_byFernTec_adSwapper_local_v0x1x210_pluginSpecificDataValidation\ // get_plugin_specific_string_validators( // $core_plugapp_dirs // ) // - - - - - - - - - - - - - - - - - - - // RETURNS // On SUCCESS // // $plugin_specific_string_validators = array( // 'validator-name-1' => 'validator_function_name_1' // 'validator-name-2' => 'validator_function_name_2' // ... // 'validator-name-N' => 'validator_function_name_N' // ) // // Where each validator function is like:- // // function ( $value_to_be_tested ) { ... } // // And returns:- // On SUCCESS // TRUE or FALSE // // On FAILURE // $error_message STRING // // On FAILURE // $error_message STRING // ------------------------------------------------------------------------- // ------------------------------------------------------------------------- // \greatKiwi_byFernTec_adSwapper_local_v0x1x210_pluginSpecificDataValidation\ // get_plugin_specific_string_validators( // $core_plugapp_dirs // ) // - - - - - - - - - - - - - - - - - - - // RETURNS // On SUCCESS // // $plugin_specific_stringdata_validation = array( // 'validator-name-1' => 'validator_function_name_1' // 'validator-name-2' => 'validator_function_name_2' // ... // 'validator-name-N' => 'validator_function_name_N' // ) // // Where each validator function is like:- // // function ( $value_to_be_tested ) { ... } // // And returns:- // On SUCCESS // TRUE or FALSE // // On FAILURE // $error_message STRING // // On FAILURE // $error_message STRING // ------------------------------------------------------------------------- if ( is_array( $plugin_specific_string_validators ) && array_key_exists( $this_xxx , $plugin_specific_string_validators ) ) { // ----------------------------------------------------------------- $validator_function_name = $plugin_specific_string_validators[ $this_xxx ] ; // ----------------------------------------------------------------- $result = $validator_function_name( $value ) ; // ----------------------------------------------------------------- if ( is_string( $result ) ) { return $result ; } // ----------------------------------------------------------------- if ( $result === TRUE ) { $match_found = TRUE ; break ; } // ----------------------------------------------------------------- } // ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: // Repeat with the next group (if there is one)... // ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: } // ========================================================================= // SUCCESS! // ========================================================================= return $match_found ; // ========================================================================= // That's that! // ========================================================================= } // ============================================================================= // validate_data_array() // ============================================================================= function validate_data_array( $array_to_check , $required_members , $optional_members , $plugin_specific_string_validators = array() ) { // ------------------------------------------------------------------------- // \greatKiwi_byFernTec_adSwapper_local_v0x1x210_dataValidation\ // validate_data_array( // $array_to_check , // $required_members , // $optional_members , // $plugin_specific_string_validators = array() // ) // - - - - - - - - - - - - - // Routine to check an array of name => value pairs. // // Performs some basic checking of those pairs. On the assumption that // the caller will perform some more detailed checking if the quick // validity check performed by this routine succeeds. // // --- // // The input parameters should be like:- // // $array_to_check = array( // 'field_name_1' => , // 'field_name_2' => , // ... => // 'field_name_N' => // ) // // $required_members = array( // 'field_name_1' => array( // 'php_type_criteria' => "xxx" , // 'string_criteria' => "yyy" , // 'error_message' => "zzz" // ) , // 'field_name_2' => array( // 'php_type_criteria' => "xxx" , // 'string_criteria' => "yyy" , // 'error_message' => "zzz" // ) , // ... => ... // 'field_name_N' => array( // 'php_type_criteria' => "xxx" , // 'string_criteria' => "yyy" , // 'error_message' => "zzz" // ) // ) // // $optional_members = array( // 'field_name_1' => array( // 'php_type_criteria' => "xxx" , // 'string_criteria' => "yyy" , // 'error_message' => "zzz" // ) , // 'field_name_2' => array( // 'php_type_criteria' => "xxx" , // 'string_criteria' => "yyy" , // 'error_message' => "zzz" // ) , // ... => ... // 'field_name_N' => array( // 'php_type_criteria' => "xxx" , // 'string_criteria' => "yyy" , // 'error_message' => "zzz" // ) // ) // // --- // // See:- // \greatKiwi_byFernTec_adSwapper_local_v0x1x210_dataArrayValidation\ // question_valid() // // for the format of the:- // "php_type_criteria" // and; // "string_criteria" // strings. // // --- // // "error_message" is OPTIONAL. If NOT specified:- // "" // // is used. // // NOTE! // ===== // The "error_message" (if there is one) will be inserted to the returned // $error_message, as follows:- // // return <<" () // Detected in:  \\{$ns}\\{$fn}() // EOT; // // --- // // RETURNS // On SUCCESS // TRUE // // On FAILURE // $error_message STRING // ------------------------------------------------------------------------- // ========================================================================= // Init. // ========================================================================= $ns = __NAMESPACE__ ; $fn = __FUNCTION__ ; // ========================================================================= // Is $array_to_check an array ? // ========================================================================= if ( ! is_array( $array_to_check ) ) { return <<Bad "array_to_check" (not an array) Detected in:  \\{$ns}\\{$fn}() EOT; } // ========================================================================= // Is $required_members an array ? // ========================================================================= if ( ! is_array( $required_members ) ) { return <<Bad "required_members" (not an array) Detected in:  \\{$ns}\\{$fn}() EOT; } // ========================================================================= // Check the REQUIRED members... // ========================================================================= foreach ( $required_members as $required_field_name => $required_field_data ) { // --------------------------------------------------------------------- if ( ! array_key_exists( $required_field_name , $array_to_check ) ) { return <<No "{$required_field_name}" Detected in:  \\{$ns}\\{$fn}() EOT; } // --------------------------------------------------------------------- if ( ! is_array( $required_field_data ) ) { return <<Bad "required_field_data" (array expected) Detected in:  \\{$ns}\\{$fn}() EOT; } // --------------------------------------------------------------------- if ( ! array_key_exists( 'php_type_criteria' , $required_field_data ) ) { return <<Bad "required_field_data" (no "php_type_criteria") Detected in:  \\{$ns}\\{$fn}() EOT; } // --------------------------------------------------------------------- if ( ! array_key_exists( 'string_criteria' , $required_field_data ) ) { return <<Bad "required_field_data" (no "string_criteria") Detected in:  \\{$ns}\\{$fn}() EOT; } // --------------------------------------------------------------------- $result = question_valid( $required_field_data['php_type_criteria'] , $required_field_data['string_criteria'] , $array_to_check[ $required_field_name ] , $plugin_specific_string_validators ) ; // --------------------------------------------------------------------- if ( is_string( $result ) ) { return $result ; } // --------------------------------------------------------------------- if ( $result !== TRUE ) { if ( array_key_exists( 'error_message' , $required_field_data ) ) { $msg = trim( $required_field_data['error_message'] ) ; } else { $msg = '' ; } if ( $msg !== '' ) { $msg = chr(32) . '(' . $msg . ')' ; } return <<Bad "optional_members" (not an array) Detected in:  \\{$ns}\\{$fn}() EOT; } // ========================================================================= // Check the OPTIONAL members... // ========================================================================= foreach ( $optional_members as $optional_field_name => $optional_field_data ) { // --------------------------------------------------------------------- if ( ! array_key_exists( $optional_field_name , $array_to_check ) ) { continue ; } // --------------------------------------------------------------------- if ( ! is_array( $optional_field_data ) ) { return <<Bad "optional_field_data" (array expected) Detected in:  \\{$ns}\\{$fn}() EOT; } // --------------------------------------------------------------------- if ( ! array_key_exists( 'php_type_criteria' , $optional_field_data ) ) { return <<Bad "optional_field_data" (no "php_type_criteria") Detected in:  \\{$ns}\\{$fn}() EOT; } // --------------------------------------------------------------------- if ( ! array_key_exists( 'string_criteria' , $optional_field_data ) ) { return <<Bad "optional_field_data" (no "string_criteria") Detected in:  \\{$ns}\\{$fn}() EOT; } // --------------------------------------------------------------------- $result = question_valid( $optional_field_data['php_type_criteria'] , $optional_field_data['string_criteria'] , $array_to_check[ $optional_field_name ] , $plugin_specific_string_validators ) ; // --------------------------------------------------------------------- if ( is_string( $result ) ) { return $result ; } // --------------------------------------------------------------------- if ( $result !== TRUE ) { if ( array_key_exists( 'error_message' , $optional_field_data ) ) { $msg = trim( $optional_field_data['error_message'] ) ; } else { $msg = '' ; } if ( $msg !== '' ) { $msg = chr(32) . '(' . $msg . ')' ; } return << $value ) { // --------------------------------------------------------------------- if ( ! array_key_exists( $name , $required_members ) && ! array_key_exists( $name , $optional_members ) ) { return <<