first commit

This commit is contained in:
Rachit Bhargava
2023-07-21 17:12:10 -04:00
parent d0fe47dde4
commit 5d0f0734d8
14003 changed files with 2829464 additions and 0 deletions

View File

@@ -0,0 +1,39 @@
<?php
class WPCF7_SWV_DateRule extends WPCF7_SWV_Rule {
const rule_name = 'date';
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_date( $i ) ) {
return new WP_Error( 'wpcf7_invalid_date',
$this->get_property( 'error' )
);
}
}
return true;
}
public function to_array() {
return array( 'rule' => self::rule_name ) + (array) $this->properties;
}
}

View File

@@ -0,0 +1,39 @@
<?php
class WPCF7_SWV_EmailRule extends WPCF7_SWV_Rule {
const rule_name = 'email';
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_email( $i ) ) {
return new WP_Error( 'wpcf7_invalid_email',
$this->get_property( 'error' )
);
}
}
return true;
}
public function to_array() {
return array( 'rule' => self::rule_name ) + (array) $this->properties;
}
}

View File

@@ -0,0 +1,46 @@
<?php
class WPCF7_SWV_EnumRule extends WPCF7_SWV_Rule {
const rule_name = 'enum';
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( 'strval', $acceptable_values );
$acceptable_values = array_filter( $acceptable_values );
$acceptable_values = array_unique( $acceptable_values );
foreach ( $input as $i ) {
if ( ! in_array( $i, $acceptable_values, true ) ) {
return new WP_Error( 'wpcf7_invalid_enum',
$this->get_property( 'error' )
);
}
}
return true;
}
public function to_array() {
return array( 'rule' => self::rule_name ) + (array) $this->properties;
}
}

View File

@@ -0,0 +1,66 @@
<?php
class WPCF7_SWV_FileRule extends WPCF7_SWV_Rule {
const rule_name = 'file';
public function matches( $context ) {
if ( false === parent::matches( $context ) ) {
return false;
}
if ( empty( $context['file'] ) ) {
return false;
}
return true;
}
public function validate( $context ) {
$field = $this->get_property( 'field' );
$input = isset( $_FILES[$field]['name'] ) ? $_FILES[$field]['name'] : '';
$input = wpcf7_array_flatten( $input );
$input = wpcf7_exclude_blank( $input );
$acceptable_filetypes = array();
foreach ( (array) $this->get_property( 'accept' ) as $accept ) {
if ( false === strpos( $accept, '/' ) ) {
$acceptable_filetypes[] = strtolower( $accept );
} else {
foreach ( wpcf7_convert_mime_to_ext( $accept ) as $ext ) {
$acceptable_filetypes[] = sprintf(
'.%s',
strtolower( trim( $ext, ' .' ) )
);
}
}
}
$acceptable_filetypes = array_unique( $acceptable_filetypes );
foreach ( $input as $i ) {
$last_period_pos = strrpos( $i, '.' );
if ( false === $last_period_pos ) { // no period
return new WP_Error( 'wpcf7_invalid_file',
$this->get_property( 'error' )
);
}
$suffix = strtolower( substr( $i, $last_period_pos ) );
if ( ! in_array( $suffix, $acceptable_filetypes, true ) ) {
return new WP_Error( 'wpcf7_invalid_file',
$this->get_property( 'error' )
);
}
}
return true;
}
public function to_array() {
return array( 'rule' => self::rule_name ) + (array) $this->properties;
}
}

View File

@@ -0,0 +1,45 @@
<?php
class WPCF7_SWV_MaxDateRule extends WPCF7_SWV_Rule {
const rule_name = 'maxdate';
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 );
$threshold = $this->get_property( 'threshold' );
if ( ! wpcf7_is_date( $threshold ) ) {
return true;
}
foreach ( $input as $i ) {
if ( wpcf7_is_date( $i ) and $threshold < $i ) {
return new WP_Error( 'wpcf7_invalid_maxdate',
$this->get_property( 'error' )
);
}
}
return true;
}
public function to_array() {
return array( 'rule' => self::rule_name ) + (array) $this->properties;
}
}

View File

@@ -0,0 +1,43 @@
<?php
class WPCF7_SWV_MaxFileSizeRule extends WPCF7_SWV_Rule {
const rule_name = 'maxfilesize';
public function matches( $context ) {
if ( false === parent::matches( $context ) ) {
return false;
}
if ( empty( $context['file'] ) ) {
return false;
}
return true;
}
public function validate( $context ) {
$field = $this->get_property( 'field' );
$input = isset( $_FILES[$field]['size'] ) ? $_FILES[$field]['size'] : '';
$input = wpcf7_array_flatten( $input );
$input = wpcf7_exclude_blank( $input );
if ( empty( $input ) ) {
return true;
}
$threshold = $this->get_property( 'threshold' );
if ( $threshold < array_sum( $input ) ) {
return new WP_Error( 'wpcf7_invalid_maxfilesize',
$this->get_property( 'error' )
);
}
return true;
}
public function to_array() {
return array( 'rule' => self::rule_name ) + (array) $this->properties;
}
}

View File

@@ -0,0 +1,43 @@
<?php
class WPCF7_SWV_MaxItemsRule extends WPCF7_SWV_Rule {
const rule_name = 'maxitems';
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 );
$threshold = $this->get_property( 'threshold' );
if ( ! wpcf7_is_number( $threshold ) ) {
return true;
}
if ( (int) $threshold < count( $input ) ) {
return new WP_Error( 'wpcf7_invalid_maxitems',
$this->get_property( 'error' )
);
}
return true;
}
public function to_array() {
return array( 'rule' => self::rule_name ) + (array) $this->properties;
}
}

View File

@@ -0,0 +1,49 @@
<?php
class WPCF7_SWV_MaxLengthRule extends WPCF7_SWV_Rule {
const rule_name = 'maxlength';
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 );
if ( empty( $input ) ) {
return true;
}
$total = 0;
foreach ( $input as $i ) {
$total += wpcf7_count_code_units( $i );
}
$threshold = (int) $this->get_property( 'threshold' );
if ( $total <= $threshold ) {
return true;
} else {
return new WP_Error( 'wpcf7_invalid_maxlength',
$this->get_property( 'error' )
);
}
}
public function to_array() {
return array( 'rule' => self::rule_name ) + (array) $this->properties;
}
}

View File

@@ -0,0 +1,45 @@
<?php
class WPCF7_SWV_MaxNumberRule extends WPCF7_SWV_Rule {
const rule_name = 'maxnumber';
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 );
$threshold = $this->get_property( 'threshold' );
if ( ! wpcf7_is_number( $threshold ) ) {
return true;
}
foreach ( $input as $i ) {
if ( wpcf7_is_number( $i ) and (float) $threshold < (float) $i ) {
return new WP_Error( 'wpcf7_invalid_maxnumber',
$this->get_property( 'error' )
);
}
}
return true;
}
public function to_array() {
return array( 'rule' => self::rule_name ) + (array) $this->properties;
}
}

View File

@@ -0,0 +1,45 @@
<?php
class WPCF7_SWV_MinDateRule extends WPCF7_SWV_Rule {
const rule_name = 'mindate';
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 );
$threshold = $this->get_property( 'threshold' );
if ( ! wpcf7_is_date( $threshold ) ) {
return true;
}
foreach ( $input as $i ) {
if ( wpcf7_is_date( $i ) and $i < $threshold ) {
return new WP_Error( 'wpcf7_invalid_mindate',
$this->get_property( 'error' )
);
}
}
return true;
}
public function to_array() {
return array( 'rule' => self::rule_name ) + (array) $this->properties;
}
}

View File

@@ -0,0 +1,43 @@
<?php
class WPCF7_SWV_MinFileSizeRule extends WPCF7_SWV_Rule {
const rule_name = 'minfilesize';
public function matches( $context ) {
if ( false === parent::matches( $context ) ) {
return false;
}
if ( empty( $context['file'] ) ) {
return false;
}
return true;
}
public function validate( $context ) {
$field = $this->get_property( 'field' );
$input = isset( $_FILES[$field]['size'] ) ? $_FILES[$field]['size'] : '';
$input = wpcf7_array_flatten( $input );
$input = wpcf7_exclude_blank( $input );
if ( empty( $input ) ) {
return true;
}
$threshold = $this->get_property( 'threshold' );
if ( array_sum( $input ) < $threshold ) {
return new WP_Error( 'wpcf7_invalid_minfilesize',
$this->get_property( 'error' )
);
}
return true;
}
public function to_array() {
return array( 'rule' => self::rule_name ) + (array) $this->properties;
}
}

View File

@@ -0,0 +1,43 @@
<?php
class WPCF7_SWV_MinItemsRule extends WPCF7_SWV_Rule {
const rule_name = 'minitems';
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 );
$threshold = $this->get_property( 'threshold' );
if ( ! wpcf7_is_number( $threshold ) ) {
return true;
}
if ( count( $input ) < (int) $threshold ) {
return new WP_Error( 'wpcf7_invalid_minitems',
$this->get_property( 'error' )
);
}
return true;
}
public function to_array() {
return array( 'rule' => self::rule_name ) + (array) $this->properties;
}
}

View File

@@ -0,0 +1,49 @@
<?php
class WPCF7_SWV_MinLengthRule extends WPCF7_SWV_Rule {
const rule_name = 'minlength';
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 );
if ( empty( $input ) ) {
return true;
}
$total = 0;
foreach ( $input as $i ) {
$total += wpcf7_count_code_units( $i );
}
$threshold = (int) $this->get_property( 'threshold' );
if ( $threshold <= $total ) {
return true;
} else {
return new WP_Error( 'wpcf7_invalid_minlength',
$this->get_property( 'error' )
);
}
}
public function to_array() {
return array( 'rule' => self::rule_name ) + (array) $this->properties;
}
}

View File

@@ -0,0 +1,45 @@
<?php
class WPCF7_SWV_MinNumberRule extends WPCF7_SWV_Rule {
const rule_name = 'minnumber';
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 );
$threshold = $this->get_property( 'threshold' );
if ( ! wpcf7_is_number( $threshold ) ) {
return true;
}
foreach ( $input as $i ) {
if ( wpcf7_is_number( $i ) and (float) $i < (float) $threshold ) {
return new WP_Error( 'wpcf7_invalid_minnumber',
$this->get_property( 'error' )
);
}
}
return true;
}
public function to_array() {
return array( 'rule' => self::rule_name ) + (array) $this->properties;
}
}

View File

@@ -0,0 +1,39 @@
<?php
class WPCF7_SWV_NumberRule extends WPCF7_SWV_Rule {
const rule_name = 'number';
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_number( $i ) ) {
return new WP_Error( 'wpcf7_invalid_number',
$this->get_property( 'error' )
);
}
}
return true;
}
public function to_array() {
return array( 'rule' => self::rule_name ) + (array) $this->properties;
}
}

View File

@@ -0,0 +1,39 @@
<?php
class WPCF7_SWV_RequiredRule extends WPCF7_SWV_Rule {
const rule_name = 'required';
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 );
if ( empty( $input ) ) {
return new WP_Error( 'wpcf7_invalid_required',
$this->get_property( 'error' )
);
}
return true;
}
public function to_array() {
return array( 'rule' => self::rule_name ) + (array) $this->properties;
}
}

View File

@@ -0,0 +1,40 @@
<?php
class WPCF7_SWV_RequiredFileRule extends WPCF7_SWV_Rule {
const rule_name = 'requiredfile';
public function matches( $context ) {
if ( false === parent::matches( $context ) ) {
return false;
}
if ( empty( $context['file'] ) ) {
return false;
}
return true;
}
public function validate( $context ) {
$field = $this->get_property( 'field' );
$input = isset( $_FILES[$field]['tmp_name'] )
? $_FILES[$field]['tmp_name'] : '';
$input = wpcf7_array_flatten( $input );
$input = wpcf7_exclude_blank( $input );
if ( empty( $input ) ) {
return new WP_Error( 'wpcf7_invalid_requiredfile',
$this->get_property( 'error' )
);
}
return true;
}
public function to_array() {
return array( 'rule' => self::rule_name ) + (array) $this->properties;
}
}

View File

@@ -0,0 +1,39 @@
<?php
class WPCF7_SWV_TelRule extends WPCF7_SWV_Rule {
const rule_name = 'tel';
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_tel( $i ) ) {
return new WP_Error( 'wpcf7_invalid_tel',
$this->get_property( 'error' )
);
}
}
return true;
}
public function to_array() {
return array( 'rule' => self::rule_name ) + (array) $this->properties;
}
}

View File

@@ -0,0 +1,39 @@
<?php
class WPCF7_SWV_URLRule extends WPCF7_SWV_Rule {
const rule_name = 'url';
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_url( $i ) ) {
return new WP_Error( 'wpcf7_invalid_url',
$this->get_property( 'error' )
);
}
}
return true;
}
public function to_array() {
return array( 'rule' => self::rule_name ) + (array) $this->properties;
}
}