rebase on oct-10-2023

This commit is contained in:
Rachit Bhargava
2023-10-10 17:23:21 -04:00
parent d37566ffb6
commit d096058d7d
4789 changed files with 254611 additions and 307223 deletions

File diff suppressed because one or more lines are too long

View File

@@ -33,7 +33,4 @@ class WPCF7_SWV_DateRule extends WPCF7_SWV_Rule {
return true;
}
public function to_array() {
return array( 'rule' => self::rule_name ) + (array) $this->properties;
}
}

View File

@@ -0,0 +1,48 @@
<?php
class WPCF7_SWV_DayofweekRule extends WPCF7_SWV_Rule {
const rule_name = 'dayofweek';
public function matches( $context ) {
if ( false === parent::matches( $context ) ) {
return false;
}
if ( empty( $context['text'] ) ) {
return false;
}
return true;
}
public function validate( $context ) {
$field = $this->get_property( 'field' );
$input = isset( $_POST[$field] ) ? $_POST[$field] : '';
$input = wpcf7_array_flatten( $input );
$input = wpcf7_exclude_blank( $input );
$acceptable_values = (array) $this->get_property( 'accept' );
$acceptable_values = array_map( 'intval', $acceptable_values );
$acceptable_values = array_filter( $acceptable_values );
$acceptable_values = array_unique( $acceptable_values );
foreach ( $input as $i ) {
if ( wpcf7_is_date( $i ) ) {
$datetime = date_create_immutable( $i, wp_timezone() );
$dow = (int) $datetime->format( 'N' );
if ( ! in_array( $dow, $acceptable_values, true ) ) {
return new WP_Error( 'wpcf7_invalid_dayofweek',
$this->get_property( 'error' )
);
}
}
}
return true;
}
}

View File

@@ -33,7 +33,4 @@ class WPCF7_SWV_EmailRule extends WPCF7_SWV_Rule {
return true;
}
public function to_array() {
return array( 'rule' => self::rule_name ) + (array) $this->properties;
}
}

View File

@@ -40,7 +40,4 @@ class WPCF7_SWV_EnumRule extends WPCF7_SWV_Rule {
return true;
}
public function to_array() {
return array( 'rule' => self::rule_name ) + (array) $this->properties;
}
}

View File

@@ -60,7 +60,4 @@ class WPCF7_SWV_FileRule extends WPCF7_SWV_Rule {
return true;
}
public function to_array() {
return array( 'rule' => self::rule_name ) + (array) $this->properties;
}
}

View File

@@ -39,7 +39,4 @@ class WPCF7_SWV_MaxDateRule extends WPCF7_SWV_Rule {
return true;
}
public function to_array() {
return array( 'rule' => self::rule_name ) + (array) $this->properties;
}
}

View File

@@ -37,7 +37,4 @@ class WPCF7_SWV_MaxFileSizeRule extends WPCF7_SWV_Rule {
return true;
}
public function to_array() {
return array( 'rule' => self::rule_name ) + (array) $this->properties;
}
}

View File

@@ -37,7 +37,4 @@ class WPCF7_SWV_MaxItemsRule extends WPCF7_SWV_Rule {
return true;
}
public function to_array() {
return array( 'rule' => self::rule_name ) + (array) $this->properties;
}
}

View File

@@ -43,7 +43,4 @@ class WPCF7_SWV_MaxLengthRule extends WPCF7_SWV_Rule {
}
}
public function to_array() {
return array( 'rule' => self::rule_name ) + (array) $this->properties;
}
}

View File

@@ -39,7 +39,4 @@ class WPCF7_SWV_MaxNumberRule extends WPCF7_SWV_Rule {
return true;
}
public function to_array() {
return array( 'rule' => self::rule_name ) + (array) $this->properties;
}
}

View File

@@ -39,7 +39,4 @@ class WPCF7_SWV_MinDateRule extends WPCF7_SWV_Rule {
return true;
}
public function to_array() {
return array( 'rule' => self::rule_name ) + (array) $this->properties;
}
}

View File

@@ -37,7 +37,4 @@ class WPCF7_SWV_MinFileSizeRule extends WPCF7_SWV_Rule {
return true;
}
public function to_array() {
return array( 'rule' => self::rule_name ) + (array) $this->properties;
}
}

View File

@@ -37,7 +37,4 @@ class WPCF7_SWV_MinItemsRule extends WPCF7_SWV_Rule {
return true;
}
public function to_array() {
return array( 'rule' => self::rule_name ) + (array) $this->properties;
}
}

View File

@@ -43,7 +43,4 @@ class WPCF7_SWV_MinLengthRule extends WPCF7_SWV_Rule {
}
}
public function to_array() {
return array( 'rule' => self::rule_name ) + (array) $this->properties;
}
}

View File

@@ -39,7 +39,4 @@ class WPCF7_SWV_MinNumberRule extends WPCF7_SWV_Rule {
return true;
}
public function to_array() {
return array( 'rule' => self::rule_name ) + (array) $this->properties;
}
}

View File

@@ -33,7 +33,4 @@ class WPCF7_SWV_NumberRule extends WPCF7_SWV_Rule {
return true;
}
public function to_array() {
return array( 'rule' => self::rule_name ) + (array) $this->properties;
}
}

View File

@@ -33,7 +33,4 @@ class WPCF7_SWV_RequiredRule extends WPCF7_SWV_Rule {
return true;
}
public function to_array() {
return array( 'rule' => self::rule_name ) + (array) $this->properties;
}
}

View File

@@ -34,7 +34,4 @@ class WPCF7_SWV_RequiredFileRule extends WPCF7_SWV_Rule {
return true;
}
public function to_array() {
return array( 'rule' => self::rule_name ) + (array) $this->properties;
}
}

View File

@@ -33,7 +33,4 @@ class WPCF7_SWV_TelRule extends WPCF7_SWV_Rule {
return true;
}
public function to_array() {
return array( 'rule' => self::rule_name ) + (array) $this->properties;
}
}

View File

@@ -0,0 +1,36 @@
<?php
class WPCF7_SWV_TimeRule extends WPCF7_SWV_Rule {
const rule_name = 'time';
public function matches( $context ) {
if ( false === parent::matches( $context ) ) {
return false;
}
if ( empty( $context['text'] ) ) {
return false;
}
return true;
}
public function validate( $context ) {
$field = $this->get_property( 'field' );
$input = isset( $_POST[$field] ) ? $_POST[$field] : '';
$input = wpcf7_array_flatten( $input );
$input = wpcf7_exclude_blank( $input );
foreach ( $input as $i ) {
if ( ! wpcf7_is_time( $i ) ) {
return new WP_Error( 'wpcf7_invalid_time',
$this->get_property( 'error' )
);
}
}
return true;
}
}

View File

@@ -33,7 +33,4 @@ class WPCF7_SWV_URLRule extends WPCF7_SWV_Rule {
return true;
}
public function to_array() {
return array( 'rule' => self::rule_name ) + (array) $this->properties;
}
}

View File

@@ -19,8 +19,10 @@ function wpcf7_swv_available_rules() {
'tel' => 'WPCF7_SWV_TelRule',
'number' => 'WPCF7_SWV_NumberRule',
'date' => 'WPCF7_SWV_DateRule',
'time' => 'WPCF7_SWV_TimeRule',
'file' => 'WPCF7_SWV_FileRule',
'enum' => 'WPCF7_SWV_EnumRule',
'dayofweek' => 'WPCF7_SWV_DayofweekRule',
'minitems' => 'WPCF7_SWV_MinItemsRule',
'maxitems' => 'WPCF7_SWV_MaxItemsRule',
'minlength' => 'WPCF7_SWV_MinLengthRule',
@@ -168,7 +170,13 @@ abstract class WPCF7_SWV_Rule {
* @return array Array of properties.
*/
public function to_array() {
return (array) $this->properties;
$properties = (array) $this->properties;
if ( defined( 'static::rule_name' ) and static::rule_name ) {
$properties = array( 'rule' => static::rule_name ) + $properties;
}
return $properties;
}
@@ -276,7 +284,7 @@ abstract class WPCF7_SWV_CompositeRule extends WPCF7_SWV_Rule {
*/
class WPCF7_SWV_Schema extends WPCF7_SWV_CompositeRule {
const version = 'Contact Form 7 SWV Schema 2022-10';
const version = 'Contact Form 7 SWV Schema 2023-07';
public function __construct( $properties = '' ) {
$this->properties = wp_parse_args( $properties, array(