css
11 years ago
js
11 years ago
capabilities.php
10 years ago
contact-form-template.php
10 years ago
contact-form.php
10 years ago
controller.php
11 years ago
formatting.php
10 years ago
functions.php
10 years ago
integration.php
10 years ago
mail.php
11 years ago
pipe.php
12 years ago
shortcodes.php
11 years ago
submission.php
10 years ago
upgrade.php
11 years ago
validation.php
11 years ago
validation.php
81 lines
| 1 | <?php |
| 2 | |
| 3 | class WPCF7_Validation implements ArrayAccess { |
| 4 | private $invalid_fields = array(); |
| 5 | private $container = array(); |
| 6 | |
| 7 | public function __construct() { |
| 8 | $this->container = array( |
| 9 | 'valid' => true, |
| 10 | 'reason' => array(), |
| 11 | 'idref' => array() ); |
| 12 | } |
| 13 | |
| 14 | public function invalidate( $context, $message ) { |
| 15 | if ( $context instanceof WPCF7_Shortcode ) { |
| 16 | $tag = $context; |
| 17 | } elseif ( is_array( $context ) ) { |
| 18 | $tag = new WPCF7_Shortcode( $context ); |
| 19 | } elseif ( is_string( $context ) ) { |
| 20 | $tags = wpcf7_scan_shortcode( array( 'name' => trim( $context ) ) ); |
| 21 | $tag = $tags ? new WPCF7_Shortcode( $tags[0] ) : null; |
| 22 | } |
| 23 | |
| 24 | $name = ! empty( $tag ) ? $tag->name : null; |
| 25 | |
| 26 | if ( empty( $name ) || ! wpcf7_is_name( $name ) ) { |
| 27 | return; |
| 28 | } |
| 29 | |
| 30 | if ( $this->is_valid( $name ) ) { |
| 31 | $id = $tag->get_id_option(); |
| 32 | |
| 33 | if ( empty( $id ) || ! wpcf7_is_name( $id ) ) { |
| 34 | $id = null; |
| 35 | } |
| 36 | |
| 37 | $this->invalid_fields[$name] = array( |
| 38 | 'reason' => (string) $message, |
| 39 | 'idref' => $id ); |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | public function is_valid( $name = null ) { |
| 44 | if ( ! empty( $name ) ) { |
| 45 | return ! isset( $this->invalid_fields[$name] ); |
| 46 | } else { |
| 47 | return empty( $this->invalid_fields ); |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | public function get_invalid_fields() { |
| 52 | return $this->invalid_fields; |
| 53 | } |
| 54 | |
| 55 | public function offsetSet( $offset, $value ) { |
| 56 | if ( isset( $this->container[$offset] ) ) { |
| 57 | $this->container[$offset] = $value; |
| 58 | } |
| 59 | |
| 60 | if ( 'reason' == $offset && is_array( $value ) ) { |
| 61 | foreach ( $value as $k => $v ) { |
| 62 | $this->invalidate( $k, $v ); |
| 63 | } |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | public function offsetGet( $offset ) { |
| 68 | if ( isset( $this->container[$offset] ) ) { |
| 69 | return $this->container[$offset]; |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | public function offsetExists( $offset ) { |
| 74 | return isset( $this->container[$offset] ); |
| 75 | } |
| 76 | |
| 77 | public function offsetUnset( $offset ) { |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | ?> |